Refactors sequential misc test cases
authorPeizhao Ou <peizhaoo@uci.edu>
Tue, 30 Jan 2018 00:38:41 +0000 (16:38 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Tue, 30 Jan 2018 00:38:41 +0000 (16:38 -0800)
test/stress/sequential/CMakeLists.txt
test/stress/sequential/sequential-misc/deque_driver.cpp
test/stress/sequential/sequential-misc/mcslock_driver.cpp
test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp
test/stress/sequential/sequential-misc/rwlock_driver.cpp
test/stress/sequential/sequential-misc/seqlock_driver.cpp
test/stress/sequential/sequential-misc/spinlock_driver.cpp
test/stress/sequential/test.cpp

index 7ef8dad..ea69fd4 100644 (file)
@@ -20,6 +20,7 @@ add_executable(${PACKAGE_NAME} ${CDSSTRESS_STACK_SOURCES})
 target_link_libraries(${PACKAGE_NAME} ${CDS_TEST_LIBRARIES} ${CDSSTRESS_FRAMEWORK_LIBRARY})
 
 add_executable(mytest test.cpp ../main.cpp)
+#add_executable(mytest test.cpp )
 target_link_libraries(mytest ${CDS_TEST_LIBRARIES} ${CDSSTRESS_FRAMEWORK_LIBRARY})
 
 add_test(NAME ${PACKAGE_NAME} COMMAND ${PACKAGE_NAME} WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
index 4fc584d..a17484e 100644 (file)
@@ -18,7 +18,6 @@ static size_t s_nDequeMainPassCount = 100000000;
 
 class ChaseLevDequeTest : public cds_test::stress_fixture {
 protected:
-  static Deque *deque;
   static atomic_int terminate_stealer;
   static ullong *sums;
   static ullong *succ_counts;
@@ -31,42 +30,6 @@ protected:
     GetConfig(DequeStealerThreadCount);
     GetConfig(DequeMainPassCount);
   }
-
-  static void StealerThread(int index) {
-    while (!terminate_stealer.load(memory_order_relaxed)) {
-      int res = deque->steal();
-      if (res != EMPTY && res != ABORT) {
-        sums[index] += res;
-        succ_counts[index]++;
-      }
-    }
-  }
-
-  static void MainThread(int index, int push_percentage) {
-    for (ullong i = 0; i < s_nDequeMainPassCount; i++) {
-      if ((::rand() % 100) < push_percentage) {
-        int item = ::rand() % 100;
-        deque->push(item);
-        push_sum += item;
-        push_count++;
-      } else {
-        int res = deque->take();
-        if (res != EMPTY) {
-          sums[index] += res;
-          succ_counts[index]++;
-        }
-      }
-    }
-    while (true) {
-      int res = deque->take();
-      if (res != EMPTY) {
-        sums[index] += res;
-        succ_counts[index]++;
-      } else {
-        break;
-      }
-    }
-  }
 };
 
 atomic_int ChaseLevDequeTest::terminate_stealer;
@@ -74,7 +37,6 @@ ullong *ChaseLevDequeTest::sums;
 ullong *ChaseLevDequeTest::succ_counts;
 ullong ChaseLevDequeTest::push_count;
 ullong ChaseLevDequeTest::push_sum;
-Deque *ChaseLevDequeTest::deque;
 
 TEST_F(ChaseLevDequeTest, ChaseLevDeque_push_take) {
   std::unique_ptr<Deque> deque(new Deque());
index d0b83cb..576193f 100644 (file)
@@ -18,32 +18,19 @@ static size_t s_nMCSLockPassCount = 3000000;
 class MCSLockTest : public cds_test::stress_fixture {
 protected:
   static ullong x;
-  static cds_others::mcs_mutex *my_mutex;
 
   static void SetUpTestCase() {
     cds_test::config const &cfg = get_config("SequentialMisc");
     GetConfig(MCSLockPassCount);
     GetConfig(MCSLockThreadCount);
   }
-
-  static void Thread() {
-    cds_others::mcs_mutex::guard g(my_mutex);
-    my_mutex->unlock(&g);
-    for (ullong i = 0; i < s_nMCSLockPassCount; i++) {
-      my_mutex->lock(&g);
-      x++;
-      my_mutex->unlock(&g);
-    }
-    my_mutex->lock(&g);
-  }
 };
 
 ullong MCSLockTest::x;
-cds_others::mcs_mutex *MCSLockTest::my_mutex;
 
 TEST_F(MCSLockTest, MCSLock) {
-  my_mutex = new cds_others::mcs_mutex();
-  cds_others::mcs_mutex::guard g(my_mutex);
+  std::unique_ptr<cds_others::mcs_mutex> my_mutex(new cds_others::mcs_mutex());
+  cds_others::mcs_mutex::guard g(my_mutex.get());
   my_mutex->unlock(&g);
   for (size_t i = 0; i < s_nMCSLockPassCount; i++) {
     my_mutex->lock(&g);
index 2d46103..0066f90 100644 (file)
@@ -25,7 +25,8 @@ protected:
   }
 
   void test() {
-    rigtorp::MPMCQueue<size_t> q(s_nRigtorpMPMCQueueCapacity);
+    std::unique_ptr<rigtorp::MPMCQueue<size_t>> q(
+        new rigtorp::MPMCQueue<size_t>(s_nRigtorpMPMCQueueCapacity));
     size_t nNo = 0;
     size_t pop_sum = 0;
 
@@ -33,13 +34,13 @@ protected:
       size_t curr_push_count = std::min(s_nRigtorpMPMCQueuePassCount - nNo,
                                         s_nRigtorpMPMCQueueEnqueueStride);
       for (size_t i = 0; i < curr_push_count; i++) {
-        q.push(nNo);
+        q->push(nNo);
         ++nNo;
       }
 
       for (size_t i = 0; i < curr_push_count; i++) {
         size_t res;
-        q.pop(res);
+        q->pop(res);
         pop_sum += res;
       }
     }
index aee9463..ab9ca0a 100644 (file)
@@ -20,7 +20,6 @@ class RWLockTest : public cds_test::stress_fixture {
 protected:
   static size_t sum;
   static size_t x;
-  static RWLock *rwlock;
 
   static void SetUpTestCase() {
     cds_test::config const &cfg = get_config("SequentialMisc");
@@ -28,7 +27,7 @@ protected:
     GetConfig(RWLockPassCount);
   }
 
-  static void ReaderWriterThread(int write_percentage) {
+  static void ReaderWriterThread(RWLock *rwlock, int write_percentage) {
     for (size_t i = 0; i < s_nRWLockPassCount; i++) {
       if (rand(100) < write_percentage) {
         if (rwlock->read_can_lock()) {
@@ -61,12 +60,11 @@ protected:
 
 size_t RWLockTest::x;
 size_t RWLockTest::sum;
-RWLock *RWLockTest::rwlock;
 
 TEST_F(RWLockTest, ReadWriteLock) {
-  rwlock = new RWLock();
+  std::unique_ptr<RWLock> rwlock(new RWLock());
   for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) {
-    ReaderWriterThread(write_percentage);
+    ReaderWriterThread(rwlock.get(), write_percentage);
   }
 }
 
index 21313b3..3a7d865 100644 (file)
@@ -20,7 +20,6 @@ static size_t s_nSeqLockPassCount = 2000000;
 class SeqLockTest : public cds_test::stress_fixture {
 protected:
   static size_t sum;
-  static SeqLock *seqlock;
 
   static void SetUpTestCase() {
     cds_test::config const &cfg = get_config("SequentialMisc");
@@ -28,7 +27,7 @@ protected:
     GetConfig(SeqLockPassCount);
   }
 
-  static void ReaderWriterThread(int write_percentage) {
+  static void ReaderWriterThread(SeqLock *seqlock, int write_percentage) {
     for (size_t i = 0; i < s_nSeqLockPassCount; i++) {
       if (rand(100) < write_percentage) {
         sum += seqlock->read();
@@ -40,12 +39,11 @@ protected:
 };
 
 size_t SeqLockTest::sum;
-SeqLock *SeqLockTest::seqlock;
 
 TEST_F(SeqLockTest, SeqLock) {
-  seqlock = new SeqLock();
+  std::unique_ptr<SeqLock> seqlock(new SeqLock());
   for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) {
-    ReaderWriterThread(write_percentage);
+    ReaderWriterThread(seqlock.get(), write_percentage);
   }
 }
 
index 99a4815..6dce812 100644 (file)
@@ -23,7 +23,7 @@ static size_t s_nSpinLockPassCount = 2500000000;
 static size_t s_nTicketLockPassCount = 4000000;
 
 #define TASK(lock_type, lock_ptr, pass_cnt)                                    \
-  static void Thread##lock_type() {                                            \
+  static void Thread##lock_type(lock_type *lock_ptr) {                         \
     for (size_t i = 0; i < pass_cnt; i++) {                                    \
       lock_ptr->lock();                                                        \
       x++;                                                                     \
@@ -33,9 +33,9 @@ static size_t s_nTicketLockPassCount = 4000000;
 
 #define LOCK_TEST(lock_type, lock_ptr, pass_cnt)                               \
   TEST_F(SpinLockTest, lock_type) {                                            \
-    lock_ptr = new lock_type();                                                \
+    std::unique_ptr<lock_type> lock_ptr(new lock_type());                      \
     x = 0;                                                                     \
-    Thread##lock_type();                                                       \
+    Thread##lock_type(lock_ptr.get());                                         \
   }
 
 class SpinLockTest : public cds_test::stress_fixture {
index f999c9e..a632e17 100644 (file)
@@ -33,7 +33,9 @@
 */
 
 #include "../misc/common.h"
+#include "../stack/stack_type.h"
 #include <cds/sync/spinlock.h>
+#include <cds/misc/RigtorpSPSCQueue.h>
 
 namespace {
 
@@ -41,12 +43,28 @@ class sequential_test : public cds_test::stress_fixture {
 
 };
 
+atomics::atomic<int> x;
+atomics::atomic<int> y;
+typedef cds::sync::spin SpinLock;
+SpinLock l;
+
+struct value_type {
+  size_t num;
+};
+
+typedef stack::Types<value_type>::Treiber_HP stack_type;
+stack_type stack;
+rigtorp::SPSCQueue<size_t> q(10);
+
 TEST_F(sequential_test, TEST) {
-  typedef cds::sync::spin SpinLock;
-  SpinLock l;
-  l.lock();
-  std::cout << "TEST\n";
-  l.unlock();
+//  l.lock();
+//  l.unlock();
+//  y.store(1, atomics::memory_order_relaxed);
+//  value_type v = {1};
+//  stack.push(v);
+//  stack.pop(v);
+
+  q.push(1);
 }
 
 } // namespace