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 7ef8daddbfe488a137b8acd0e84e0f72160431b4..ea69fd4fd7aac62c5af8f27283f544d3e0f07a20 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 4fc584d192feffef769c0234a2dfb3eb15946a25..a17484ebc1b199053107b5d11b79087def8960b9 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 d0b83cb6670bb55d2679df0c285b0a39cae615a2..576193f542936be1ffecd74b62ac5cfaf590016e 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 2d46103c1047871c9b38386444ce3ad0dc794587..0066f901641e178c53ed95d10c102fbd1358d2a1 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 aee9463ab7821bf2f6f6830fbfb5feaad21472af..ab9ca0a7aca4d61949edbb6fd62a6c23147fce14 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 21313b3fa9a75424b7533e0914aecf8d684256ee..3a7d865dc050fdefbc3b795f163c37829b32e93d 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 99a48153e39e9210df053e234f73f557e375e953..6dce8121dfe241c7f6071ba4e0b59bfefa5aca1c 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 f999c9ed85c2198715dd389810d9817e335f58f7..a632e17a21eb0223ca53a4662e6c47e8fbfdf0ec 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