--- /dev/null
+#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