Adds sanity check for parallel map tests
authorPeizhao Ou <peizhaoo@uci.edu>
Fri, 9 Feb 2018 22:43:13 +0000 (14:43 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Fri, 9 Feb 2018 22:43:13 +0000 (14:43 -0800)
test/junction_parallel_driver.cpp

index dd1bda2..a2c4126 100644 (file)
@@ -54,7 +54,9 @@ protected:
     GetConfigNonZeroExpected(LeapfrogPassCount, 850000000);
   }
 
-  template <typename Map> static void run_test(Map* map, size_t pass_count) {
+  template <typename Map>
+  static void run_test(Map* map, size_t pass_count, size_t* inserted_num,
+                       size_t* deleted_num) {
     auto qsbrContext = junction::DefaultQSBR.createContext();
 
     std::random_device rd;
@@ -63,6 +65,7 @@ protected:
 
     unsigned action_index = 0;
     size_t nInsertedNum = 0;
+    size_t nDeletedNum = 0;
     size_t nFindSuccess = 0;
     size_t nOperations = 0;
 
@@ -78,7 +81,9 @@ protected:
           break;
         }
         case do_delete: {
-          map_delete(map, key);
+          if (map_delete(map, key)) {
+            nDeletedNum++;
+          }
           break;
         }
         case do_find: {
@@ -99,6 +104,8 @@ protected:
     }
     junction::DefaultQSBR.update(qsbrContext);
     junction::DefaultQSBR.destroyContext(qsbrContext);
+    *inserted_num = nInsertedNum;
+    *deleted_num = nDeletedNum;
   }
 };
 
@@ -117,13 +124,21 @@ size_t JunctionMapInsDelFindTest_Parallel::s_nLinearPassCount;
 size_t JunctionMapInsDelFindTest_Parallel::s_nLeapfrogPassCount;
 
 #define JunctionThreading(map_type, pass_count)                                \
-  std::unique_ptr<std::thread[]> threads(new std::thread[s_nThreadCount]);       \
-  for (size_t i = 0; i < s_nThreadCount; i++) {                                  \
-    threads[i] = std::thread(run_test<map_type>, map.get(), pass_count);       \
+  std::unique_ptr<std::thread[]> threads(new std::thread[s_nThreadCount]);     \
+  std::unique_ptr<size_t[]> inserted_nums(new size_t[s_nThreadCount]);         \
+  std::unique_ptr<size_t[]> deleted_nums(new size_t[s_nThreadCount]);          \
+  for (size_t i = 0; i < s_nThreadCount; i++) {                                \
+    threads[i] = std::thread(run_test<map_type>, map.get(), pass_count,        \
+                             &inserted_nums[i], &deleted_nums[i]);             \
   }                                                                            \
-  for (size_t i = 0; i < s_nThreadCount; i++) {                                  \
+  size_t inserted_sum = 0;                                                     \
+  size_t deleted_sum = 0;                                                      \
+  for (size_t i = 0; i < s_nThreadCount; i++) {                                \
     threads[i].join();                                                         \
-  }
+    inserted_sum += inserted_nums[i];                                          \
+    deleted_sum += deleted_nums[i];                                            \
+  }                                                                            \
+  EXPECT_LE(deleted_sum, inserted_sum);
 
 TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapCrude) {
   std::unique_ptr<CrudeMap> map(new CrudeMap(s_nCrudeMapCapacity));