Rewrites barrier driver
authorPeizhao Ou <peizhaoo@uci.edu>
Mon, 12 Mar 2018 23:33:59 +0000 (16:33 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Mon, 12 Mar 2018 23:33:59 +0000 (16:33 -0700)
test/stress/misc/barrier_driver.cpp

index e7878fdc3d734d859aa784c27ee20bcc8e60f490..8dfc41dc8fef3502d23642845f4b8e312dc10157 100644 (file)
@@ -6,6 +6,7 @@
 #include <cds_test/stress_test.h>
 #include <iostream>
 #include <memory>
 #include <cds_test/stress_test.h>
 #include <iostream>
 #include <memory>
+#include <vector>
 #include <thread>
 
 using namespace std;
 #include <thread>
 
 using namespace std;
@@ -14,7 +15,7 @@ namespace {
 
 typedef cds_others::SpinBarrier Barrier;
 
 
 typedef cds_others::SpinBarrier Barrier;
 
-static size_t s_nBarrierThreadCount = 4;
+static size_t s_nBarrierThreadCount = 2;
 static size_t s_nBarrierPassCount = 100000000;
 
 class BarrierTest : public cds_test::stress_fixture {
 static size_t s_nBarrierPassCount = 100000000;
 
 class BarrierTest : public cds_test::stress_fixture {
@@ -28,14 +29,8 @@ protected:
     GetConfig(BarrierThreadCount);
   }
 
     GetConfig(BarrierThreadCount);
   }
 
-  static void TearDownTestCase() {
-    if (count != s_nBarrierPassCount) {
-      cout << "Incorrect" << endl;
-    }
-  }
-
   static void Thread() {
   static void Thread() {
-    for (ullong i = 0; i < s_nBarrierPassCount; i++) {
+    for (size_t i = 0; i < s_nBarrierPassCount; i++) {
       if (barrier->wait()) {
         count++;
       }
       if (barrier->wait()) {
         count++;
       }
@@ -48,14 +43,16 @@ size_t BarrierTest::count;
 
 TEST_F(BarrierTest, Wait) {
   barrier = new Barrier(s_nBarrierThreadCount);
 
 TEST_F(BarrierTest, Wait) {
   barrier = new Barrier(s_nBarrierThreadCount);
-  std::unique_ptr<std::thread[]> threads(new std::thread[s_nBarrierThreadCount]);
+  std::vector<std::thread> threads;
   for (size_t i = 0; i < s_nBarrierThreadCount; i++) {
   for (size_t i = 0; i < s_nBarrierThreadCount; i++) {
-    threads[i] = std::thread(Thread);
+    threads.push_back(std::thread(Thread));
   }
 
   for (size_t i = 0; i < s_nBarrierThreadCount; i++) {
     threads[i].join();
   }
   }
 
   for (size_t i = 0; i < s_nBarrierThreadCount; i++) {
     threads[i].join();
   }
+  EXPECT_EQ(count, s_nBarrierPassCount);
+  delete barrier;
 }
 
 } // namespace
 }
 
 } // namespace