/** test with long sequence of adds, removes and updates, and lookups */ static void test_long_table(struct lruhash* table) { /* assuming it all fits in the hastable, this check will work */ testdata_t* ref[HASHTESTMAX * 100]; size_t i; memset(ref, 0, sizeof(ref)); /* test assumption */ if(0) log_info(" size %d x %d < %d", (int)test_slabhash_sizefunc(NULL, NULL), (int)HASHTESTMAX, (int)table->space_max); unit_assert( test_slabhash_sizefunc(NULL, NULL)*HASHTESTMAX < table->space_max); if(0) lruhash_status(table, "unit test", 1); srandom(48); for(i=0; i<1000; i++) { /* what to do? */ if(i == 500) { lruhash_clear(table); memset(ref, 0, sizeof(ref)); continue; } switch(random() % 4) { case 0: case 3: testadd(table, ref); break; case 1: testremove(table, ref); break; case 2: testlookup(table, ref); break; default: unit_assert(0); } if(0) lruhash_status(table, "unit test", 1); check_table(table); unit_assert( table->num <= HASHTESTMAX ); } /* test more, but 'ref' assumption does not hold anymore */ for(i=0; i<1000; i++) { /* what to do? */ switch(random() % 4) { case 0: case 3: testadd_unlim(table, ref); break; case 1: testremove_unlim(table, ref); break; case 2: testlookup_unlim(table, ref); break; default: unit_assert(0); } if(0) lruhash_status(table, "unlim", 1); check_table(table); } }
static void test_long_table(struct lruhash* table) { testdata *ref[MAXHASH * 100]; size_t i; memset(ref, 0, sizeof(ref)); unit_assert(sizefunc(NULL, NULL)*MAXHASH < table->space_max); srandom(48); for(i = 0; i < 1000; i++) { if(i == 500) { lruhash_clear(table); memset(ref, 0, sizeof(ref)); continue; } switch(random() % 4) { case 0: case 3: testadd(table, ref); break; case 1: testremove(table, ref); break; case 2: testlookup(table, ref); break; default: unit_assert(0); } check_table(table); unit_assert(table->num <= MAXHASH); } }
void slabhash_clear(struct slabhash* sl) { size_t i; if(!sl) return; for(i=0; i<sl->size; i++) lruhash_clear(sl->array[i]); }