From: Peizhao Ou Date: Fri, 26 Jan 2018 19:46:57 +0000 (-0800) Subject: Adds RigtorpSPSC test case X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d88faec0c6284c315cc288452212c0dc8b853a77;p=libcds.git Adds RigtorpSPSC test case --- diff --git a/test/stress/sequential/sequential-misc/CMakeLists.txt b/test/stress/sequential/sequential-misc/CMakeLists.txt index ae61a313..15646c61 100644 --- a/test/stress/sequential/sequential-misc/CMakeLists.txt +++ b/test/stress/sequential/sequential-misc/CMakeLists.txt @@ -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 diff --git a/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp b/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp index 1038fde8..2d46103c 100644 --- a/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp +++ b/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp @@ -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 index 00000000..0fee1798 --- /dev/null +++ b/test/stress/sequential/sequential-misc/rigtorp_spsc_driver.cpp @@ -0,0 +1,62 @@ +#include "common.h" +#include +#include +#include +#include + +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 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