X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=test%2Fmap_test2.c;h=f8e0abd85b7f3958df026007b017c78db3d40729;hp=9fc6fe3297d14f3d50d19b71236f5ec91ed5193a;hb=75b0d2f02f548b3a1e4daba8b0d55eea2fb24e92;hpb=a03cf3b0c40e6c3b8b4877b49a64288cb3fcb919 diff --git a/test/map_test2.c b/test/map_test2.c index 9fc6fe3..f8e0abd 100644 --- a/test/map_test2.c +++ b/test/map_test2.c @@ -132,13 +132,15 @@ void basic_test (CuTest* tc) { } void *add_remove_worker (void *arg) { + nbd_thread_init(); + worker_data_t *wd = (worker_data_t *)arg; map_t *map = wd->map; CuTest* tc = wd->tc; int d = wd->id; - int iters = 10000; + int iters = (map_type_ == &MAP_IMPL_LL ? 10000 : 100000); - SYNC_ADD(wd->wait, -1); + (void)SYNC_ADD(wd->wait, -1); do { } while (*wd->wait); // wait for all workers to be ready map_key_t key; @@ -180,8 +182,7 @@ void concurrent_add_remove_test (CuTest* tc) { pthread_t thread[2]; worker_data_t wd[2]; - static const int num_threads = 2; - volatile int wait = num_threads; + volatile int wait = 2; #ifdef TEST_STRING_KEYS map_t *map = map_alloc(map_type_, &DATATYPE_NSTRING); #else @@ -193,23 +194,23 @@ void concurrent_add_remove_test (CuTest* tc) { // In 2 threads, add & remove even & odd elements concurrently int i; - for (i = 0; i < num_threads; ++i) { + for (i = 0; i < 2; ++i) { wd[i].id = i; wd[i].tc = tc; wd[i].map = map; wd[i].wait = &wait; - int rc = nbd_thread_create(thread + i, i, add_remove_worker, wd + i); + int rc = pthread_create(thread + i, NULL, add_remove_worker, wd + i); if (rc != 0) { perror("nbd_thread_create"); return; } } - for (i = 0; i < num_threads; ++i) { + for (i = 0; i < 2; ++i) { pthread_join(thread[i], NULL); } gettimeofday(&tv2, NULL); int ms = (int)(1000000*(tv2.tv_sec - tv1.tv_sec) + tv2.tv_usec - tv1.tv_usec) / 1000; - map_print(map); - printf("Th:%d Time:%dms\n", num_threads, ms); + map_print(map, FALSE); + printf("Time:%dms\n", ms); fflush(stdout); // In the end, all members should be removed @@ -316,10 +317,10 @@ void big_iteration_test (CuTest* tc) { } int main (void) { + nbd_thread_init(); + lwt_set_trace_level("r0m3l2t0"); - lwt_set_trace_level("l3"); - - static const map_impl_t *map_types[] = { &ll_map_impl, &sl_map_impl, &ht_map_impl }; + static const map_impl_t *map_types[] = { &MAP_IMPL_LL, &MAP_IMPL_SL, &MAP_IMPL_HT }; for (int i = 0; i < sizeof(map_types)/sizeof(*map_types); ++i) { map_type_ = map_types[i]; @@ -328,9 +329,9 @@ int main (void) { CuSuite* suite = CuSuiteNew(); SUITE_ADD_TEST(suite, concurrent_add_remove_test); - SUITE_ADD_TEST(suite, basic_test); - SUITE_ADD_TEST(suite, basic_iteration_test); - SUITE_ADD_TEST(suite, big_iteration_test); +// SUITE_ADD_TEST(suite, basic_test); +// SUITE_ADD_TEST(suite, basic_iteration_test); +// SUITE_ADD_TEST(suite, big_iteration_test); CuSuiteRun(suite); CuSuiteDetails(suite, output);