int test_hash_rw_populate_hash(void) { struct lfht_test_node *node; if (!init_populate) return 0; printf("Starting rw test\n"); URCU_TLS(rand_lookup) = urcu_get_thread_id() ^ time(NULL); if ((add_unique || add_replace) && init_populate * 10 > init_pool_size) { printf("WARNING: required to populate %lu nodes (-k), but random " "pool is quite small (%lu values) and we are in add_unique (-u) or add_replace (-s) mode. Try with a " "larger random pool (-p option). This may take a while...\n", init_populate, init_pool_size); } while (URCU_TLS(nr_add) < init_populate) { struct cds_lfht_node *ret_node = NULL; node = malloc(sizeof(struct lfht_test_node)); lfht_test_node_init(node, (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % init_pool_size) + init_pool_offset), sizeof(void *)); rcu_read_lock(); if (add_unique) { ret_node = cds_lfht_add_unique(test_ht, test_hash(node->key, node->key_len, TEST_HASH_SEED), test_match, node->key, &node->node); } else { if (add_replace) ret_node = cds_lfht_add_replace(test_ht, test_hash(node->key, node->key_len, TEST_HASH_SEED), test_match, node->key, &node->node); else cds_lfht_add(test_ht, test_hash(node->key, node->key_len, TEST_HASH_SEED), &node->node); } rcu_read_unlock(); if (add_unique && ret_node != &node->node) { free(node); URCU_TLS(nr_addexist)++; } else { if (add_replace && ret_node) { call_rcu(&to_test_node(ret_node)->head, free_node_cb); URCU_TLS(nr_addexist)++; } else { URCU_TLS(nr_add)++; } } URCU_TLS(nr_writes)++; } return 0; }
void test_main(void) { test_hash(&nettle_sha1, SDATA(""), SHEX("DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709")); test_hash(&nettle_sha1, SDATA("a"), SHEX("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8")); test_hash(&nettle_sha1, SDATA("abc"), SHEX("A9993E364706816A BA3E25717850C26C 9CD0D89D")); test_hash(&nettle_sha1, SDATA("abcdefghijklmnopqrstuvwxyz"), SHEX("32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89")); test_hash(&nettle_sha1, SDATA("message digest"), SHEX("C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3")); test_hash(&nettle_sha1, SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789"), SHEX("761C457BF73B14D2 7E9E9265C46F4B4D DA11F940")); test_hash(&nettle_sha1, SDATA("1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890"), SHEX("50ABF5706A150990 A08B2C5EA40FA0E5 85554732")); /* Additional test vector, from Daniel Kahn Gillmor */ test_hash(&nettle_sha1, SDATA("38"), SHEX("5b384ce32d8cdef02bc3a139d4cac0a22bb029e8")); }
int main() { test_hash_rpmqal(); test_hash(); return 0; }
int main(int argc, char *argv[]) { test_hash(); printf("Hello, world\n"); return 0; }
int main( int argc, char **argv, char **env ) { plan(28); test_hash(); test_hash_methods(); return done(); }
int main() { try { test_hash(); } catch (const std::exception& e) { std::cout << e.what() << std::endl; return 1; } return 0; }
int main(int argc, char **argv) { int ret = 0; ret |= test_hash(); ret |= test_log(); ret |= test_math(); return ret; }
int main() { if (test_salt_int(6)==0 && test_salt_max(31)==0 && test_salt(12)==0 && test_hash()==0 && test_international_chars(12)==0) { std::cout << "Success" << std::endl; return EXIT_SUCCESS; } else { std::cerr << "Fail " << std::endl; return EXIT_FAILURE; } }
int main() { test_hash(); test_hash_resize(); test_load_int(); test_load_str(); test_hash_update(); test_hash_delete(); test_hash_delete_1(); return 0; }
void otama_test_variant(void) { OTAMA_TEST_NAME; test_convert(); test_to_string(); test_array(); test_hash(); }
void TestApp::test_sha256() { Console::write_line(" Header: sha256.h"); Console::write_line(" Class: SHA256"); // Using http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA256.pdf for test data SHA256 sha256; sha256.add("abc", 3); sha256.calculate(); test_hash(sha256, "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD"); sha256.add("a", 1); sha256.add("b", 1); sha256.add("c", 1); sha256.calculate(); test_hash(sha256, "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD"); const char *test_str1 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; sha256.add(test_str1, strlen(test_str1)); sha256.calculate(); test_hash(sha256, "248D6A61D20638B8E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1"); // Using wikipedia http://en.wikipedia.org/wiki/Hmac test data char *test_str9a = ""; char *test_str9b = ""; sha256.set_hmac(test_str9a, strlen(test_str9a)); sha256.add(test_str9b, strlen(test_str9b)); sha256.calculate(); test_hash(sha256, "B613679A0814D9EC772F95D778C35FC5FF1697C493715653C6C712144292C5AD"); char *test_str10a = "key"; char *test_str10b = "The quick brown fox jumps over the lazy dog"; sha256.set_hmac(test_str10a, strlen(test_str10a)); sha256.add(test_str10b, strlen(test_str10b)); sha256.calculate(); test_hash(sha256, "F7BC83F430538424B13298E6AA6FB143EF4D59A14946175997479DBC2D1A3CD8"); }
void TestApp::test_sha512() { Console::write_line(" Header: sha512.h"); Console::write_line(" Class: SHA512"); // Using http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512.pdf for test data SHA512 sha512; sha512.add("abc", 3); sha512.calculate(); test_hash(sha512, "DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F"); sha512.add("a", 1); sha512.add("b", 1); sha512.add("c", 1); sha512.calculate(); test_hash(sha512, "DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F"); const char *test_str1 = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; sha512.add(test_str1, strlen(test_str1)); sha512.calculate(); test_hash(sha512, "8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7FA17299AEADB6889018501D289E4900F7E4331B99DEC4B5433AC7D329EEB6DD26545E96E55B874BE909"); // Using wikipedia http://en.wikipedia.org/wiki/Hmac test data char *test_str9a = ""; char *test_str9b = ""; sha512.set_hmac(test_str9a, strlen(test_str9a)); sha512.add(test_str9b, strlen(test_str9b)); sha512.calculate(); test_hash(sha512, "B936CEE86C9F87AA5D3C6F2E84CB5A4239A5FE50480A6EC66B70AB5B1F4AC6730C6C515421B327EC1D69402E53DFB49AD7381EB067B338FD7B0CB22247225D47"); char *test_str10a = "key"; char *test_str10b = "The quick brown fox jumps over the lazy dog"; sha512.set_hmac(test_str10a, strlen(test_str10a)); sha512.add(test_str10b, strlen(test_str10b)); sha512.calculate(); test_hash(sha512, "B42AF09057BAC1E2D41708E48A902E09B5FF7F12AB428A4FE86653C73DD248FB82F948A549F7B791A5B41915EE4D1EC3935357E4E2317250D0372AFA2EBEEB3A"); }
void TestApp::test_sha224() { Console::write_line(" Header: sha224.h"); Console::write_line(" Class: SHA224"); // Using http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA224.pdf for test data SHA224 sha224; sha224.add("abc", 3); sha224.calculate(); test_hash(sha224, "23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7"); sha224.add("a", 1); sha224.add("b", 1); sha224.add("c", 1); sha224.calculate(); test_hash(sha224, "23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7"); const char *test_str1 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; sha224.add(test_str1, strlen(test_str1)); sha224.calculate(); test_hash(sha224, "75388B16512776CC5DBA5DA1FD890150B0C6455CB4F58B1952522525"); }
void TestApp::test_sha512_224() { Console::write_line(" Header: sha512_224.h"); Console::write_line(" Class: SHA512_224"); // Using http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_224.pdf for test data SHA512_224 sha512_224; sha512_224.add("abc", 3); sha512_224.calculate(); test_hash(sha512_224, "4634270F707B6A54DAAE7530460842E20E37ED265CEEE9A43E8924AA"); sha512_224.add("a", 1); sha512_224.add("b", 1); sha512_224.add("c", 1); sha512_224.calculate(); test_hash(sha512_224, "4634270F707B6A54DAAE7530460842E20E37ED265CEEE9A43E8924AA"); const char *test_str1 = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; sha512_224.add(test_str1, strlen(test_str1)); sha512_224.calculate(); test_hash(sha512_224, "23FEC5BB94D60B23308192640B0C453335D664734FE40E7268674AF9"); }
void runTests() { // Memory Tests test_allocator(); test_hash(); // System Tests test_sexpr(); //test_lisp(); test_maths(); test_property(); test_string(); test_input(); //test_collision(); }
int main() { if (test_replace()==0 && test_replace_any()==0 && test_trim_left()==0 && test_trim_right()==0 && test_trim()==0 && test_str2hex()==0 && test_split()==0 && test_split_first()==0 && test_split_second()==0 && test_vexec()==0 && test_json_set()==0 && test_hash()==0 && test_random()==0 && test_local()==0 ) { std::cout << "Success" << std::endl; return EXIT_SUCCESS; } else { std::cerr << "Fail" << std::endl; return EXIT_FAILURE; } }
void test_procedure() { if (!uci.engine_initialized) init_engine(position); assert(test_bitscan()); assert(test_bittwiddles()); assert(test_fen()); assert(test_genmove()); assert(test_make_unmake()); assert(test_hash()); assert(test_eval()); assert(test_capture_gen()); assert(test_check_gen()); assert(test_alt_move_gen()); assert(test_see()); assert(test_position()); assert(test_hash_table()); assert(test_ep_capture()); assert(test_book()); test_search(); }
int main(int argc, char *argv[]) { struct dn_heap h; int i, n, n2, n3; test_hash(); return 0; /* n = elements, n2 = cycles */ n = (argc > 1) ? atoi(argv[1]) : 0; if (n <= 0 || n > 1000000) n = 100; n2 = (argc > 2) ? atoi(argv[2]) : 0; if (n2 <= 0) n = 1000000; n3 = (argc > 3) ? atoi(argv[3]) : 0; bzero(&h, sizeof(h)); heap_init(&h, n, -1); while (n2-- > 0) { uint64_t prevk = 0; for (i=0; i < n; i++) heap_insert(&h, n3 ? n-i: random(), (void *)(100+i)); for (i=0; h.elements > 0; i++) { uint64_t k = h.p[0].key; if (k < prevk) panic("wrong sequence\n"); prevk = k; if (0) printf("%d key %llu, val %p\n", i, h.p[0].key, h.p[0].object); heap_extract(&h, NULL); } } return 0; }
int test_main(void) { test_hash(&nettle_md5, 0, "", H("D41D8CD98F00B204 E9800998ECF8427E")); test_hash(&nettle_md5, 1, "a", H("0CC175B9C0F1B6A8 31C399E269772661")); test_hash(&nettle_md5, 3, "abc", H("900150983cd24fb0 D6963F7D28E17F72")); test_hash(&nettle_md5, 14, "message digest", H("F96B697D7CB7938D 525A2F31AAF161D0")); test_hash(&nettle_md5, 26, "abcdefghijklmnopqrstuvwxyz", H("C3FCD3D76192E400 7DFB496CCA67E13B")); test_hash(&nettle_md5, 62, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789", H("D174AB98D277D9F5 A5611C2C9F419D9F")); test_hash(&nettle_md5, 80, "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890", H("57EDF4A22BE3C955 AC49DA2E2107B67A")); /* Additional test vector, from Daniel Kahn Gillmor */ test_hash(&nettle_md5, LDATA("38"), H("a5771bce93e200c3 6f7cd9dfd0e5deaa")); /* Collisions, reported by Xiaoyun Wang1, Dengguo Feng2, Xuejia Lai3, Hongbo Yu1, http://eprint.iacr.org/2004/199. */ #define M0 \ /* vv */ \ "d131dd02 c5e6eec4 693d9a06 98aff95c 2fcab5 87 12467eab 4004583e b8fb7f89" \ "55ad3406 09f4b302 83e48883 25 71 415a 085125e8 f7cdc99f d91dbd f2 80373c5b" \ /* ^^ ^^ */ #define M1 \ /* vv */ \ "d131dd02 c5e6eec4 693d9a06 98aff95c 2fcab5 07 12467eab 4004583e b8fb7f89" \ "55ad3406 09f4b302 83e48883 25 f1 415a 085125e8 f7cdc99f d91dbd 72 80373c5b" \ /* ^^ ^^ */ #define N0 \ /* vv */ \ "960b1dd1 dc417b9c e4d897f4 5a6555d5 35739a c7 f0ebfd0c 3029f166 d109b18f" \ "75277f79 30d55ceb 22e8adba 79 cc 155c ed74cbdd 5fc5d36d b19b0a d8 35cca7e3" \ /* ^^ ^^ */ #define N1 \ /* vv */ \ "960b1dd1 dc417b9c e4d897f4 5a6555d5 35739a 47 f0ebfd0c 3029f166 d109b18f" \ "75277f79 30d55ceb 22e8adba 79 4c 155c ed74cbdd 5fc5d36d b19b0a 58 35cca7e3" \ /* ^^ ^^ */ /* Note: The checksum in the paper, 1f160396 efc71ff4 bcff659f bf9d0fa3, is incorrect. */ #define H0 "a4c0d35c 95a63a80 5915367d cfe6b751" #define N2 \ /* vv */ \ "d8823e31 56348f5b ae6dacd4 36c919c6 dd53e2 b4 87da03fd 02396306 d248cda0" \ "e99f3342 0f577ee8 ce54b670 80 a8 0d1e c69821bc b6a88393 96f965 2b 6ff72a70" \ /* ^^ ^^ */ #define N3 \ /* vv */ \ "d8823e31 56348f5b ae6dacd4 36c919c6 dd53e2 34 87da03fd 02396306 d248cda0" \ "e99f3342 0f577ee8 ce54b670 80 28 0d1e c69821bc b6a88393 96f965 ab 6ff72a70" \ /* ^^ ^^ */ /* Note: Also different from the checksum in the paper */ #define H1 "79054025 255fb1a2 6e4bc422 aef54eb4" test_hash(&nettle_md5, HL(M0 N0), H(H0)); test_hash(&nettle_md5, HL(M1 N1), H(H0)); test_hash(&nettle_md5, HL(M0 N2), H(H1)); test_hash(&nettle_md5, HL(M1 N3), H(H1)); SUCCESS(); }
int main() { #if 1 printf("sizeof(tu_string) == %d\n", sizeof(tu_string)); array<tu_string> storage; storage.resize(2); tu_string& a = storage[0]; tu_string& b = storage[1]; a = "test1"; printf("&a = 0x%X, &b = 0x%X\n", int(&a), int(&b)); printf("%s\n", a.c_str()); assert(a == "test1"); assert(a.length() == 5); a += "2"; assert(a == "test12"); a += "this is some more text"; assert(a.length() == 28); assert(a[2] == 's'); assert(a[3] == 't'); assert(a[4] == '1'); assert(a[5] == '2'); assert(a[7] == 'h'); assert(a[28] == 0); assert(b.length() == 0); assert(b[0] == 0); assert(b.c_str()[0] == 0); tu_string c = a + b; assert(c.length() == a.length()); c.resize(2); assert(c == "te"); assert(c == tu_string("te")); assert(tu_string("fourscore and sevent") == "fourscore and sevent"); b = "#sacrificial lamb"; // Test growing & shrinking. a = ""; for (int i = 0; i < 1000; i++) { assert(a.length() == i); if (i == 8) { assert(a == "01234567"); } else if (i == 27) { assert(a == "012345678901234567890123456"); } a.resize(a.length() + 1); a[a.length() - 1] = '0' + (i % 10); } {for (int i = 999; i >= 0; i--) { a.resize(a.length() - 1); assert(a.length() == i); if (i == 8) { assert(a == "01234567"); } else if (i == 27) { assert(a == "012345678901234567890123456"); } }} // Test larger shrinking across heap/local boundary. a = "this is a string longer than 16 characters"; a = "short"; // Test larger expand across heap/local boundary. a = "another longer string..."; assert(b == "#sacrificial lamb"); test_hash(); test_stringi(); test_stringi_hash(); test_unicode(); // TODO: unit tests for array<>, string_hash<> #endif test_hash_speed(); return 0; }
int main(void) { test_hash(10007, 191, 1000); }
void selftest(void) { fprintf(stdlog, "selftest:\n"); fflush(stdlog); printf("Self test...\n"); /* large file check */ if (sizeof(off_t) < sizeof(uint64_t)) { /* LCOV_EXCL_START */ fprintf(stderr, "Missing support for large files\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } test_hash(); test_crc32c(); test_tommy(); if (raid_selftest() != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed SELF test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_sort() != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed SORT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_insert() != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed INSERT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_combo() != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed COMBO test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed GEN Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed REC Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed GEN Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed REC Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Failed GEN Cauchy test sigle data disk\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } }
int main(int argc, char **argv) { for (size_t i = 0; i < 128; i++) { test_class(PN_OBJECT, i); test_class(PN_VOID, i); test_class(&noop_class, i); } for (size_t i = 0; i < 128; i++) { test_new(i, PN_OBJECT); test_new(i, &noop_class); } test_finalize(); test_free(); test_hashcode(); test_compare(); for (int i = 0; i < 1024; i++) { test_refcounting(i); } for (size_t i = 0; i < 4; i++) { test_list(i); } for (size_t i = 0; i < 4; i++) { test_list_refcount(i); } test_list_index(); test_map(); test_map_links(); test_hash(); test_string(NULL); test_string(""); test_string("this is a test"); test_string("012345678910111213151617181920212223242526272829303132333435363" "738394041424344454647484950515253545556575859606162636465666768"); test_string("this has an embedded \000 in it"); test_stringn("this has an embedded \000 in it", 28); test_string_format(); test_string_addf(); test_build_list(); test_build_map(); test_build_map_odd(); for (int i = 0; i < 64; i++) { test_map_iteration(i); } test_list_inspect(); test_map_inspect(); test_list_compare(); test_iterator(); for (int seed = 0; seed < 64; seed++) { for (int size = 1; size <= 64; size++) { test_heap(seed, size); } } return 0; }
int main() { #if 1 printf("sizeof(tu_string) == %d\n", sizeof(tu_string)); swf_array<tu_string> storage; storage.resize(2); tu_string& a = storage[0]; tu_string& b = storage[1]; a = "test1"; printf("&a = 0x%X, &b = 0x%X\n", int(&a), int(&b)); printf("%s\n", a.c_str()); assert(a == "test1"); assert(a.length() == 5); a += "2"; assert(a == "test12"); a += "this is some more text"; assert(a.length() == 28); assert(a[2] == 's'); assert(a[3] == 't'); assert(a[4] == '1'); assert(a[5] == '2'); assert(a[7] == 'h'); assert(a[28] == 0); assert(b.length() == 0); assert(b[0] == 0); assert(b.c_str()[0] == 0); tu_string c = a + b; assert(c.length() == a.length()); c.resize(2); assert(c == "te"); assert(c == tu_string("te")); assert(tu_string("fourscore and sevent") == "fourscore and sevent"); b = "#sacrificial lamb"; // Test growing & shrinking. a = ""; for (int i = 0; i < 1000; i++) { assert(a.length() == i); if (i == 8) { assert(a == "01234567"); } else if (i == 27) { assert(a == "012345678901234567890123456"); } a.resize(a.length() + 1); a[a.length() - 1] = '0' + (i % 10); } {for (int i = 999; i >= 0; i--) { a.resize(a.length() - 1); assert(a.length() == i); if (i == 8) { assert(a == "01234567"); } else if (i == 27) { assert(a == "012345678901234567890123456"); } }} // Test larger shrinking across heap/local boundary. a = "this is a string longer than 16 characters"; a = "short"; // Test larger expand across heap/local boundary. a = "another longer string..."; assert(b == "#sacrificial lamb"); // Test erase() a = "abcdef"; a.erase(3, 1); assert(a == "abcef"); a = "abcdefghijklmnopqrst"; a.erase(12, 6); assert(a == "abcdefghijklst"); // Test insert() a = "abcdef"; a.insert(3, 'z'); assert(a == "abczdef"); a = "abcdefghijklmn"; a.insert(12, 'y'); a.insert(13, 'z'); assert(a == "abcdefghijklyzmn"); // Test operator+=(tu_string) a = "abcdef"; b = "ghijklmnopqrst"; a += b; assert(a == "abcdefghijklmnopqrst"); // Test operator+(const char*) a = "abcdef"; b = "ghi"; assert(a + b == "abcdefghi"); // Test operator<(const char*) a = "abc"; assert(a < "def"); assert(a < "abd"); assert(!(a < "aab")); assert(!(a < "aa")); assert(!(a < "aabz")); assert(a < "abcd"); // Test operator<(const tu_string&) a = "abc"; assert(a < tu_string("def")); assert(a < tu_string("abd")); assert(!(a < tu_string("aab"))); assert(!(a < tu_string("aa"))); assert(!(a < tu_string("aabz"))); assert(a < tu_string("abcd")); // Test that we can store strings with embedded \0's. a = "abc"; a += '\0'; assert(a.length() == 4); a += "def"; assert(a.length() == 7); assert(a[4] == 'd'); assert(a[5] == 'e'); assert(a[6] == 'f'); assert(a[7] == 0); // Test that we can upsize strings with embedded \0's a = "abc"; a += '\0'; a += "def"; b = a; assert(a == b); assert(b.length() == 7); a = a + b; assert(a.length() == 14); assert(a == (b + b)); assert(a > b); a = a + b; assert(a.size() == 21); assert(a == (b + b + b)); assert(a > b); // Test that we can downsize strings with embedded \0's a = "abc"; a += '\0'; a += "def"; assert(a.length() == 7); b = a + a + a; assert(b.length() == 21); b.resize(14); assert(b.length() == 14); assert(b == (a + a)); b.erase(3, 1); assert(b.size() == 13); assert(b == tu_string("abcdef") + a); // Test strings that are nothing but \0's. a = ""; b = ""; for (int i = 0; i < 100; i++) { a += '\0'; assert(a.length() == i + 1); assert(a > b); b += '\0'; assert(b.length() == i + 1); assert(a == b); assert((a + b).length() == 2 * (i + 1)); } test_hash(); test_stringi(); test_stringi_hash(); test_unicode(); // TODO: unit tests for swf_array<>, string_hash<> #endif test_hash_speed(); printf("OK\n"); return 0; }
int main(){ test_hash(); return 0;}
void *test_hash_rw_thr_writer(void *_count) { struct lfht_test_node *node; struct cds_lfht_node *ret_node; struct cds_lfht_iter iter; struct wr_count *count = _count; int ret; printf_verbose("thread_begin %s, tid %lu\n", "writer", urcu_get_thread_id()); URCU_TLS(rand_lookup) = urcu_get_thread_id() ^ time(NULL); set_affinity(); rcu_register_thread(); while (!test_go) { } cmm_smp_mb(); for (;;) { if ((addremove == AR_ADD || add_only) || (addremove == AR_RANDOM && rand_r(&URCU_TLS(rand_lookup)) & 1)) { node = malloc(sizeof(struct lfht_test_node)); lfht_test_node_init(node, (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset), sizeof(void *)); rcu_read_lock(); if (add_unique) { ret_node = cds_lfht_add_unique(test_ht, test_hash(node->key, node->key_len, TEST_HASH_SEED), test_match, node->key, &node->node); } else { if (add_replace) ret_node = cds_lfht_add_replace(test_ht, test_hash(node->key, node->key_len, TEST_HASH_SEED), test_match, node->key, &node->node); else cds_lfht_add(test_ht, test_hash(node->key, node->key_len, TEST_HASH_SEED), &node->node); } rcu_read_unlock(); if (add_unique && ret_node != &node->node) { free(node); URCU_TLS(nr_addexist)++; } else { if (add_replace && ret_node) { call_rcu(&to_test_node(ret_node)->head, free_node_cb); URCU_TLS(nr_addexist)++; } else { URCU_TLS(nr_add)++; } } } else { /* May delete */ rcu_read_lock(); cds_lfht_test_lookup(test_ht, (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset), sizeof(void *), &iter); ret = cds_lfht_del(test_ht, cds_lfht_iter_get_node(&iter)); rcu_read_unlock(); if (ret == 0) { node = cds_lfht_iter_get_test_node(&iter); call_rcu(&node->head, free_node_cb); URCU_TLS(nr_del)++; } else URCU_TLS(nr_delnoent)++; } #if 0 //if (URCU_TLS(nr_writes) % 100000 == 0) { if (URCU_TLS(nr_writes) % 1000 == 0) { rcu_read_lock(); if (rand_r(&URCU_TLS(rand_lookup)) & 1) { ht_resize(test_ht, 1); } else { ht_resize(test_ht, -1); } rcu_read_unlock(); } #endif //0 URCU_TLS(nr_writes)++; if (caa_unlikely(!test_duration_write())) break; if (caa_unlikely(wdelay)) loop_sleep(wdelay); if (caa_unlikely((URCU_TLS(nr_writes) & ((1 << 10) - 1)) == 0)) rcu_quiescent_state(); } rcu_unregister_thread(); printf_verbose("thread_end %s, tid %lu\n", "writer", urcu_get_thread_id()); printf_verbose("info tid %lu: nr_add %lu, nr_addexist %lu, nr_del %lu, " "nr_delnoent %lu\n", urcu_get_thread_id(), URCU_TLS(nr_add), URCU_TLS(nr_addexist), URCU_TLS(nr_del), URCU_TLS(nr_delnoent)); count->update_ops = URCU_TLS(nr_writes); count->add = URCU_TLS(nr_add); count->add_exist = URCU_TLS(nr_addexist); count->remove = URCU_TLS(nr_del); return ((void*)2); }