2 #include "libtest_tests_internal.h"
4 /***** private prototypes *****/
5 static int key_compare_function( void const *new_value, void const *value_in_tree );
11 /****************************************************************************/
12 #pragma warning( disable : 4100 )
14 void libtest_tests_btree_au_fail_and_overwrite_on_existing_key( struct lfds710_list_asu_state *list_of_logical_processors, struct libshared_memory_state *ms, enum lfds710_misc_validity *dvs )
16 enum lfds710_btree_au_insert_result
19 struct lfds710_btree_au_element
24 struct lfds710_btree_au_state
30 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
31 LFDS710_PAL_ASSERT( ms != NULL );
32 LFDS710_PAL_ASSERT( dvs != NULL );
34 /* TRD : the random_adds tests with fail and overwrite don't (can't, not in a performant manner)
35 test that the fail and/or overwrite of user data has *actually* happened - they use the
36 return value from the link function call, rather than empirically observing the final
39 as such, we now have a couple of single threaded tests where we check that the user data
40 value really is being modified (or not modified, as the case may be)
43 // internal_display_test_name( "Fail and overwrite on existing key" );
45 *dvs = LFDS710_MISC_VALIDITY_VALID;
47 /* TRD : so, we make a tree which is fail on existing
48 add one element, with a known user data
49 we then try to add the same key again, with a different user data
50 the call should fail, and then we get the element by its key
51 and check its user data is unchanged
52 (and confirm the failed link returned the correct existing_baue)
53 that's the first test done
56 lfds710_btree_au_init_valid_on_current_logical_core( &baus, key_compare_function, LFDS710_BTREE_AU_EXISTING_KEY_FAIL, NULL );
58 LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT( baue_one, 0 );
59 LFDS710_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_one, 1 );
60 alr = lfds710_btree_au_insert( &baus, &baue_one, NULL );
62 if( alr != LFDS710_BTREE_AU_INSERT_RESULT_SUCCESS )
63 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
65 LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT( baue_two, 0 );
66 LFDS710_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_two, 2 );
67 alr = lfds710_btree_au_insert( &baus, &baue_two, &existing_baue );
69 if( alr != LFDS710_BTREE_AU_INSERT_RESULT_FAILURE_EXISTING_KEY )
70 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
72 if( existing_baue != &baue_one )
73 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
75 value = LFDS710_BTREE_AU_GET_VALUE_FROM_ELEMENT( *existing_baue );
77 if( (void *) (lfds710_pal_uint_t) value != (void *) (lfds710_pal_uint_t) 1 )
78 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
80 lfds710_btree_au_cleanup( &baus, NULL );
82 /* TRD : second test, make a tree which is overwrite on existing
83 add one element, with a known user data
84 we then try to add the same key again, with a different user data
85 the call should succeed, and then we get the element by its key
86 and check its user data is changed
87 (and confirm the failed link returned the correct existing_baue)
88 that's the secondtest done
91 lfds710_btree_au_init_valid_on_current_logical_core( &baus, key_compare_function, LFDS710_BTREE_AU_EXISTING_KEY_OVERWRITE, NULL );
93 LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT( baue_one, 0 );
94 LFDS710_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_one, 1 );
95 alr = lfds710_btree_au_insert( &baus, &baue_one, NULL );
97 if( alr != LFDS710_BTREE_AU_INSERT_RESULT_SUCCESS )
98 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
100 LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT( baue_two, 0 );
101 LFDS710_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_two, 2 );
102 alr = lfds710_btree_au_insert( &baus, &baue_two, NULL );
104 if( alr != LFDS710_BTREE_AU_INSERT_RESULT_SUCCESS_OVERWRITE )
105 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
107 lfds710_btree_au_cleanup( &baus, NULL );
112 #pragma warning( default : 4100 )
118 /****************************************************************************/
119 static int key_compare_function( void const *new_key, void const *key_in_tree )
124 // TRD : key_new can be any value in its range
125 // TRD : key_in_tree can be any value in its range
127 if( (lfds710_pal_uint_t) new_key < (lfds710_pal_uint_t) key_in_tree )
130 if( (lfds710_pal_uint_t) new_key > (lfds710_pal_uint_t) key_in_tree )