X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_hash.c;h=accf3c1ab1ff76a0e37b876da268ba690122e916;hb=495913bfaec0ff19107f0cc903ba1d6eade03709;hp=3578cc9b2b121bb57dd916dd1a3d3811e86cd420;hpb=18ca7a5b5573e511a66f118ec863df82a6d247e4;p=urcu.git diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c index 3578cc9..accf3c1 100644 --- a/tests/test_urcu_hash.c +++ b/tests/test_urcu_hash.c @@ -23,6 +23,65 @@ #define _GNU_SOURCE #include "test_urcu_hash.h" +enum test_hash { + TEST_HASH_RW, + TEST_HASH_UNIQUE, +}; + +struct test_hash_cb { + void (*sigusr1)(int signo); + void (*sigusr2)(int signo); + void *(*thr_reader)(void *_count); + void *(*thr_writer)(void *_count); + int (*populate_hash)(void); +}; + +static +struct test_hash_cb test_hash_cb[] = { + [TEST_HASH_RW] = { + test_hash_rw_sigusr1_handler, + test_hash_rw_sigusr2_handler, + test_hash_rw_thr_reader, + test_hash_rw_thr_writer, + test_hash_rw_populate_hash, + }, + [TEST_HASH_UNIQUE] = { + test_hash_unique_sigusr1_handler, + test_hash_unique_sigusr2_handler, + test_hash_unique_thr_reader, + test_hash_unique_thr_writer, + test_hash_unique_populate_hash, + }, + +}; + +static enum test_hash test_choice = TEST_HASH_RW; + +void (*get_sigusr1_cb(void))(int) +{ + return test_hash_cb[test_choice].sigusr1; +} + +void (*get_sigusr2_cb(void))(int) +{ + return test_hash_cb[test_choice].sigusr2; +} + +void *(*get_thr_reader_cb(void))(void *) +{ + return test_hash_cb[test_choice].thr_reader; +} + +void *(*get_thr_writer_cb(void))(void *) +{ + return test_hash_cb[test_choice].thr_writer; +} + +int (*get_populate_hash_cb(void))(void) +{ + return test_hash_cb[test_choice].populate_hash; +} + unsigned int __thread rand_lookup; unsigned long __thread nr_add; unsigned long __thread nr_addexist; @@ -55,6 +114,7 @@ unsigned long init_pool_size = DEFAULT_RAND_POOL, lookup_pool_size = DEFAULT_RAND_POOL, write_pool_size = DEFAULT_RAND_POOL; int validate_lookup; +unsigned long nr_hash_chains; /* 0: normal table, other: number of hash chains */ int count_pipe[2]; @@ -230,6 +290,8 @@ printf(" [not -u nor -s] Add entries (supports redundant keys).\n"); printf(" [-N size] Write pool size.\n"); printf(" [-O size] Init pool size.\n"); printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n"); + printf(" [-U] Uniqueness test.\n"); + printf(" [-C] Number of hash chains.\n"); printf("\n\n"); } @@ -393,7 +455,12 @@ int main(int argc, char **argv) case 'V': validate_lookup = 1; break; - + case 'U': + test_choice = TEST_HASH_UNIQUE; + break; + case 'C': + nr_hash_chains = atol(argv[++i]); + break; } } @@ -422,7 +489,7 @@ int main(int argc, char **argv) perror("sigemptyset"); return -1; } - act.sa_handler = test_hash_rw_sigusr1_handler; + act.sa_handler = get_sigusr1_cb(); act.sa_flags = SA_RESTART; ret = sigaction(SIGUSR1, &act, NULL); if (ret == -1) { @@ -442,7 +509,7 @@ int main(int argc, char **argv) if (err != 0) exit(1); - act.sa_handler = test_hash_rw_sigusr2_handler; + act.sa_handler = get_sigusr2_cb(); act.sa_flags = SA_RESTART; ret = sigaction(SIGUSR2, &act, NULL); if (ret == -1) { @@ -466,6 +533,8 @@ int main(int argc, char **argv) lookup_pool_offset, lookup_pool_size); printf_verbose("Update pool size offset %lu size %lu.\n", write_pool_offset, write_pool_size); + printf_verbose("Number of hash chains: %lu.\n", + nr_hash_chains); printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", "main", pthread_self(), (unsigned long)gettid()); @@ -497,7 +566,7 @@ int main(int argc, char **argv) * thread from the point of view of resize. */ rcu_register_thread(); - ret = test_hash_rw_populate_hash(); + ret = (get_populate_hash_cb())(); assert(!ret); rcu_thread_offline(); @@ -506,14 +575,14 @@ int main(int argc, char **argv) for (i = 0; i < nr_readers; i++) { err = pthread_create(&tid_reader[i], - NULL, test_hash_rw_thr_reader, + NULL, get_thr_reader_cb(), &count_reader[i]); if (err != 0) exit(1); } for (i = 0; i < nr_writers; i++) { err = pthread_create(&tid_writer[i], - NULL, test_hash_rw_thr_writer, + NULL, get_thr_writer_cb(), &count_writer[i]); if (err != 0) exit(1);