]> pd.if.org Git - nbds/blobdiff - test/map_test2.c
work in progress
[nbds] / test / map_test2.c
index f9444ca0077999c18a1f58f2dea19283219112c9..f8e0abd85b7f3958df026007b017c78db3d40729 100644 (file)
@@ -20,6 +20,7 @@
 #include "hashtable.h"
 #include "lwt.h"
 #include "mem.h"
+#include "rcu.h"
 
 #define ASSERT_EQUAL(x, y) CuAssertIntEquals(tc, x, y)
 
@@ -131,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;
@@ -179,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
@@ -192,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
@@ -315,11 +317,10 @@ void big_iteration_test (CuTest* tc) {
 }
 
 int main (void) {
+    nbd_thread_init();
+    lwt_set_trace_level("r0m3l2t0");
 
-    nbd_init();
-    lwt_set_trace_level("h3");
-
-    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];
 
@@ -327,10 +328,10 @@ int main (void) {
         CuString *output = CuStringNew();
         CuSuite* suite = CuSuiteNew();
 
-        SUITE_ADD_TEST(suite, basic_test);
-        SUITE_ADD_TEST(suite, basic_iteration_test);
-        SUITE_ADD_TEST(suite, big_iteration_test);
         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);
 
         CuSuiteRun(suite);
         CuSuiteDetails(suite, output);