Adds RigtorpSPSC test case
authorPeizhao Ou <peizhaoo@uci.edu>
Fri, 26 Jan 2018 19:46:57 +0000 (11:46 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Fri, 26 Jan 2018 19:46:57 +0000 (11:46 -0800)
test/stress/sequential/sequential-misc/CMakeLists.txt
test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp
test/stress/sequential/sequential-misc/rigtorp_spsc_driver.cpp [new file with mode: 0644]

index ae61a31..15646c6 100644 (file)
@@ -2,6 +2,7 @@ set(PACKAGE_NAME stress-sequential-misc)
 
 set(CDSSTRESS_STACK_SOURCES
     main.cpp
+    rigtorp_spsc_driver.cpp
     rigtorp_mpmc_driver.cpp
     deque_driver.cpp
     spinlock_driver.cpp
index 1038fde..2d46103 100644 (file)
@@ -46,10 +46,7 @@ protected:
 
     size_t supposed_sum =
         s_nRigtorpMPMCQueuePassCount * (s_nRigtorpMPMCQueuePassCount - 1) / 2;
-    if (pop_sum != supposed_sum) {
-      std::cout << "Sequential rigtorpMPMC queue pop sum: " << pop_sum
-                << " != " << supposed_sum << "\n";
-    }
+    EXPECT_EQ(pop_sum, supposed_sum);
   }
 };
 
diff --git a/test/stress/sequential/sequential-misc/rigtorp_spsc_driver.cpp b/test/stress/sequential/sequential-misc/rigtorp_spsc_driver.cpp
new file mode 100644 (file)
index 0000000..0fee179
--- /dev/null
@@ -0,0 +1,62 @@
+#include "common.h"
+#include <cds/misc/RigtorpSPSCQueue.h>
+#include <cds_test/stress_test.h>
+#include <ctime>
+#include <iostream>
+
+using namespace std;
+
+namespace {
+
+class rigtorpSPSCQueueTest : public cds_test::stress_fixture {
+protected:
+  static size_t s_nRigtorpSPSCQueuePassCount;
+  static size_t s_nRigtorpSPSCQueueEnqueueStride;
+  static size_t s_nRigtorpSPSCQueueCapacity;
+
+  static void SetUpTestCase() {
+    cds_test::config const &cfg = get_config("SequentialMisc");
+    GetConfigExpected(RigtorpSPSCQueuePassCount, 10000);
+    GetConfigExpected(RigtorpSPSCQueueEnqueueStride, 1024);
+    GetConfigExpected(RigtorpSPSCQueueCapacity, 2048);
+    if (s_nRigtorpSPSCQueueCapacity <= s_nRigtorpSPSCQueueEnqueueStride) {
+      s_nRigtorpSPSCQueueCapacity = 2 * s_nRigtorpSPSCQueueEnqueueStride;
+    }
+  }
+
+  void test() {
+    rigtorp::SPSCQueue<size_t> q(s_nRigtorpSPSCQueueCapacity);
+    size_t nNo = 0;
+    size_t push_sum = 0;
+    size_t pop_sum = 0;
+
+    while (nNo < s_nRigtorpSPSCQueuePassCount) {
+      size_t curr_push_count = std::min(s_nRigtorpSPSCQueuePassCount - nNo,
+                                        s_nRigtorpSPSCQueueEnqueueStride);
+      for (size_t i = 0; i < curr_push_count; i++) {
+        q.push(nNo);
+        push_sum += nNo;
+        ++nNo;
+      }
+
+      size_t* res = nullptr;
+      while ((res = q.front())) {
+        pop_sum += *res;
+        q.pop();
+      }
+      EXPECT_EQ(pop_sum, push_sum);
+      push_sum = 0;
+      pop_sum = 0;
+    }
+  }
+};
+
+size_t rigtorpSPSCQueueTest::s_nRigtorpSPSCQueuePassCount;
+size_t rigtorpSPSCQueueTest::s_nRigtorpSPSCQueueEnqueueStride;
+size_t rigtorpSPSCQueueTest::s_nRigtorpSPSCQueueCapacity;
+
+TEST_F(rigtorpSPSCQueueTest, PushPop) {
+  test();
+}
+
+} // namespace