X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=src%2Ftestston.c;h=014a58cdd16485113c3f32ded5a2860661ec3c19;hp=32910b0bc2806c3ce715f8e236ececf534e0dfe2;hb=16091722cd675ef3e48a56c22fc827eb5cde352e;hpb=30e125e6bcfa71297ef4d592b0c80346f5688a1d diff --git a/src/testston.c b/src/testston.c index 32910b0..014a58c 100644 --- a/src/testston.c +++ b/src/testston.c @@ -36,9 +36,10 @@ int main(int argc, char* argv[]) size_t i; size_t elements; uint16_t columns; + int fail; printf("up2pow [5] = [%i]\n",ston_up2pow(5)); - for (i = 0; i < 255; i += 7) + for (i = 0; i < 77; i += 7) printf("trailing0 [%X] = [%x]\n",(uint32_t)i,ston_trailing0(i)); columns = 2; @@ -69,41 +70,184 @@ int main(int argc, char* argv[]) elements = 20; ht = ston_ht32_new(columns,elements,0,malloc); check_ht(ht); - printf("Filling hashtable with entries\n"); + printf("Filling hashtable with %i entries\n", (int)elements); for(key = 0xCEED; elements--; key *= 7) { val[0] = key; for(i = 1; i < columns; i++) val[i] = i * key; ston_ht32_insertx(ht,key,val,0,columns); } - printf("Reading entries\n"); elements = 20; + printf("Reading entries: "); + fail = 0; for(key = 0xCEED; elements--; key *= 7) { htval = ston_ht32_row(ht,key); - printf("[%s%x"CLRC"]",(*htval == key) ? GREEN : RED,*htval); + if (*htval != key) + fail++; for(i = 1; i < columns; i++) - printf("[%s%x"CLRC"]",(htval[i] == (uint32_t)(i * key)) ? GREEN : RED,htval[i]); - putchar('\n'); + if (htval[i] != (uint32_t)(i * key)) + fail++; } + if (fail) + printf(RED"FAIL"CLRC"(%i)\n", fail); + else + printf(GREEN"PASS"CLRCN); int max_capacity = ston_up2pow(20 << 1) - 20; - printf("Overfilling hashtable with %i entries\n", max_capacity); int cap = max_capacity; + printf("Overfilling hashtable with %i entries\n", max_capacity); for(key = 0xCEED2; cap--; key *= 13) { val[0] = key; for(i = 1; i < columns; i++) val[i] = key * -i; ston_ht32_insertx(ht,key,val,0,columns); } - printf("Reading entries\n"); + printf("Reading entries: "); cap = max_capacity; + fail = 0; for(key = 0xCEED2; cap--; key *= 13) { htval = ston_ht32_row(ht,key); - printf("[%s%x"CLRC"]",(*htval == key) ? GREEN : RED,*htval); + if (*htval != key) + fail++; + for(i = 1; i < columns; i++) + if (htval[i] != (uint32_t)(key * -i)) + fail++; + } + if (fail) + printf(RED"FAIL"CLRC"(%i)\n", fail); + else + printf(GREEN"PASS"CLRCN); + + cap = 20; + printf("Post-capacity insertion of %i\n",cap); + for (key = 0xCEED3; cap--; key *= 23) + { val[0] = key; + for(i = 1; i < columns; i++) + val[i] = key * -i; + size_t count = ston_ht32_insertx(ht,key,val,0,columns); + printf("Insertion %2i wrote %i bytes: %s"CLRCN, (int)cap, (int) count, + (count == 0) ? GREEN"PASS" : RED"FAIL"); + } + + + printf("Refilling hashtable with %i entries\n", max_capacity); + cap = max_capacity; + for(key = 0xCEED2; cap--; key *= 13) + { val[0] = key; for(i = 1; i < columns; i++) - printf("[%s%x"CLRC"]",(htval[i] == (uint32_t)(key * -i)) ? GREEN : RED,htval[i]); - printf("\n"); + val[i] = key * i; + ston_ht32_insertx(ht,key,val,0,columns); } + printf("Reading entries: "); + cap = max_capacity; + fail = 0; + for(key = 0xCEED2; cap--; key *= 13) + { htval = ston_ht32_row(ht,key); + if (*htval != key) + fail ++; + for (i = 1; i < columns; i++) + if (htval[i] != (uint32_t)(key * i)) + fail++; + } + if (fail) + printf(RED"FAIL"CLRC"(%i)\n", fail); + else + printf(GREEN"PASS"CLRCN); free(ht); + + + printf("\n--------- DHT ----------\n\n"); + + ston_dht dht; + elements = 50; + columns = 6; + dht = ston_dht32_new(columns, elements, 0, malloc, free); + check_ht(dht); + elements = 50000; + printf("Filling Dynamic hashtable with %i entries\n", (int)elements); + for(key = 0xCEED; elements--; key *= 7) + { val[0] = key; + for(i = 1; i < columns; i++) + val[i] = i * key; + ston_dht32_insertx(dht,key,val,0,columns); + } + elements = 50000; + printf("Reading entries: "); + fail = 0; + for(key = 0xCEED; elements--; key *= 7) + { htval = ston_dht32_row(dht,key); + if (*htval != key) + fail++; + for(i = 1; i < columns; i++) + if (htval[i] != (uint32_t)(i * key)) + fail++; + } + if (fail) + printf(RED"FAIL"CLRC"(%i)\n", fail); + else + printf(GREEN"PASS"CLRCN); + max_capacity = (ston_up2pow(50 << 1) * (ston_dht_pagemax(dht) - ston_dht_pagestart(dht))) - 50000; + cap = max_capacity; + printf("Overfilling hashtable with %i entries\n", max_capacity); + for(key = 0xCEED2; cap--; key *= 13) + { val[0] = key; + for(i = 1; i < columns; i++) + val[i] = key * -i; + ston_dht32_insertx(dht,key,val,0,columns); + } + printf("Reading entries: "); + cap = max_capacity; + fail = 0; + for(key = 0xCEED2; cap--; key *= 13) + { htval = ston_dht32_row(dht,key); + if (*htval != key) + fail++; + for(i = 1; i < columns; i++) + if (htval[i] != (uint32_t)(key * -i)) + fail++; + } + if (fail) + printf(RED"FAIL"CLRC"(%i)\n", fail); + else + printf(GREEN"PASS"CLRCN); + + cap = 20; + printf("Post-capacity insertion of %i\n",cap); + for (key = 0xCEED3; cap--; key *= 23) + { val[0] = key; + for(i = 1; i < columns; i++) + val[i] = key * -i; + size_t count = ston_dht32_insertx(dht,key,val,0,columns); + printf("Insertion %2i wrote %i bytes: %s"CLRCN, (int)cap, (int) count, + (count == 0) ? GREEN"PASS" : RED"FAIL"); + } + + + printf("Refilling hashtable with %i entries\n", max_capacity); + cap = max_capacity; + for(key = 0xCEED2; cap--; key *= 13) + { val[0] = key; + for(i = 1; i < columns; i++) + val[i] = key * i; + ston_dht32_insertx(dht,key,val,0,columns); + } + printf("Reading entries: "); + cap = max_capacity; + fail = 0; + for(key = 0xCEED2; cap--; key *= 13) + { htval = ston_dht32_row(dht,key); + if (*htval != key) + fail ++; + for (i = 1; i < columns; i++) + if (htval[i] != (uint32_t)(key * i)) + fail++; + } + if (fail) + printf(RED"FAIL"CLRC"(%i)\n", fail); + else + printf(GREEN"PASS"CLRCN); + + ston_dht32_free(dht); + return 0; }