2 #include "libtest_tests_internal.h"
7 struct lfds710_btree_au_element
14 /***** private prototypes *****/
15 static int key_compare_function( void const *new_key, void const *existing_key );
16 static void key_hash_function( void const *key, lfds710_pal_uint_t *hash );
22 /****************************************************************************/
23 #pragma warning( disable : 4100 )
25 void libtest_tests_hash_a_iterate( struct lfds710_list_asu_state *list_of_logical_processors, struct libshared_memory_state *ms, enum lfds710_misc_validity *dvs )
31 struct lfds710_hash_a_element
34 struct lfds710_hash_a_iterate
37 struct lfds710_hash_a_state
40 struct lfds710_hash_a_element
43 struct lfds710_btree_au_state
50 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
51 LFDS710_PAL_ASSERT( ms != NULL );
52 LFDS710_PAL_ASSERT( dvs != NULL );
54 /* TRD : single-threaded test
55 we create a single hash_a
56 we populate with 1000 elements
57 where key and value is the number of the element (e.g. 0 to 999)
58 we then allocate 1000 counters, init to 0
60 we increment each element as we see it in the iterate
61 if any are missing or seen more than once, problemo!
63 we do this once with a table of 10, to ensure each table has (or almost certainly has) something in
64 and then a second tiem with a table of 10000, to ensure some empty tables exist
67 *dvs = LFDS710_MISC_VALIDITY_VALID;
69 counter_array = libshared_memory_alloc_from_unknown_node( ms, sizeof(lfds710_pal_uint_t) * 1000, sizeof(lfds710_pal_uint_t) );
70 element_array = libshared_memory_alloc_from_unknown_node( ms, sizeof(struct lfds710_hash_a_element) * 1000, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
71 baus = libshared_memory_alloc_from_unknown_node( ms, sizeof(struct lfds710_btree_au_state) * 10, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
72 baus_thousand = libshared_memory_alloc_from_unknown_node( ms, sizeof(struct lfds710_btree_au_state) * 1000, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
74 // TRD : first time around
75 lfds710_hash_a_init_valid_on_current_logical_core( &has, baus, 10, key_compare_function, key_hash_function, LFDS710_HASH_A_EXISTING_KEY_FAIL, NULL );
77 for( loop = 0 ; loop < 1000 ; loop++ )
79 LFDS710_HASH_A_SET_KEY_IN_ELEMENT( *(element_array+loop), loop );
80 LFDS710_HASH_A_SET_VALUE_IN_ELEMENT( *(element_array+loop), loop );
81 lfds710_hash_a_insert( &has, element_array+loop, NULL );
84 for( loop = 0 ; loop < 1000 ; loop++ )
85 *(counter_array+loop) = 0;
87 lfds710_hash_a_iterate_init( &has, &hai );
89 while( *dvs == LFDS710_MISC_VALIDITY_VALID and lfds710_hash_a_iterate(&hai, &hae) )
91 value = LFDS710_HASH_A_GET_VALUE_FROM_ELEMENT( *hae );
92 ( *(counter_array + (lfds710_pal_uint_t) value) )++;
95 if( *dvs == LFDS710_MISC_VALIDITY_VALID )
96 for( loop = 0 ; loop < 1000 ; loop++ )
98 if( *(counter_array+loop) > 1 )
99 *dvs = LFDS710_MISC_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
101 if( *(counter_array+loop) == 0 )
102 *dvs = LFDS710_MISC_VALIDITY_INVALID_MISSING_ELEMENTS;
105 lfds710_hash_a_cleanup( &has, NULL );
107 // TRD : second time around
108 if( *dvs == LFDS710_MISC_VALIDITY_VALID )
110 lfds710_hash_a_init_valid_on_current_logical_core( &has, baus_thousand, 10000, key_compare_function, key_hash_function, LFDS710_HASH_A_EXISTING_KEY_FAIL, NULL );
112 for( loop = 0 ; loop < 1000 ; loop++ )
114 LFDS710_HASH_A_SET_KEY_IN_ELEMENT( *(element_array+loop), loop );
115 LFDS710_HASH_A_SET_VALUE_IN_ELEMENT( *(element_array+loop), loop );
116 lfds710_hash_a_insert( &has, element_array+loop, NULL );
119 for( loop = 0 ; loop < 1000 ; loop++ )
120 *(counter_array+loop) = 0;
122 lfds710_hash_a_iterate_init( &has, &hai );
124 while( *dvs == LFDS710_MISC_VALIDITY_VALID and lfds710_hash_a_iterate(&hai, &hae) )
126 value = LFDS710_HASH_A_GET_VALUE_FROM_ELEMENT( *hae );
127 ( *(counter_array + (lfds710_pal_uint_t) value ) )++;
130 if( *dvs == LFDS710_MISC_VALIDITY_VALID )
131 for( loop = 0 ; loop < 1000 ; loop++ )
133 if( *(counter_array+loop) > 1 )
134 *dvs = LFDS710_MISC_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
136 if( *(counter_array+loop) == 0 )
137 *dvs = LFDS710_MISC_VALIDITY_INVALID_MISSING_ELEMENTS;
140 lfds710_hash_a_cleanup( &has, NULL );
146 #pragma warning( default : 4100 )
152 /****************************************************************************/
153 static int key_compare_function( void const *new_key, void const *existing_key )
158 // TRD : new_key can be NULL (i.e. 0)
159 // TRD : existing_key can be NULL (i.e. 0)
161 if( (lfds710_pal_uint_t) new_key < (lfds710_pal_uint_t) existing_key )
164 if( (lfds710_pal_uint_t) new_key > (lfds710_pal_uint_t) existing_key )
174 /****************************************************************************/
175 static void key_hash_function( void const *key, lfds710_pal_uint_t *hash )
177 // TRD : key can be NULL
178 LFDS710_PAL_ASSERT( hash != NULL );
182 /* TRD : this function iterates over the user data
183 and we are using the void pointer AS user data
184 so here we need to pass in the addy of value
187 LFDS710_HASH_A_HASH_FUNCTION( (void *) &key, sizeof(lfds710_pal_uint_t), *hash );