From: Peizhao Ou Date: Tue, 30 Jan 2018 00:38:41 +0000 (-0800) Subject: Refactors sequential misc test cases X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=6ec1165b0c929f8b4c7d4f7a0ff79a4126b4947e;hp=28eb2ae5ccef5f6871c1a82df7e969d333a33d02 Refactors sequential misc test cases --- diff --git a/test/stress/sequential/CMakeLists.txt b/test/stress/sequential/CMakeLists.txt index 7ef8dadd..ea69fd4f 100644 --- a/test/stress/sequential/CMakeLists.txt +++ b/test/stress/sequential/CMakeLists.txt @@ -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}) diff --git a/test/stress/sequential/sequential-misc/deque_driver.cpp b/test/stress/sequential/sequential-misc/deque_driver.cpp index 4fc584d1..a17484eb 100644 --- a/test/stress/sequential/sequential-misc/deque_driver.cpp +++ b/test/stress/sequential/sequential-misc/deque_driver.cpp @@ -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(new Deque()); diff --git a/test/stress/sequential/sequential-misc/mcslock_driver.cpp b/test/stress/sequential/sequential-misc/mcslock_driver.cpp index d0b83cb6..576193f5 100644 --- a/test/stress/sequential/sequential-misc/mcslock_driver.cpp +++ b/test/stress/sequential/sequential-misc/mcslock_driver.cpp @@ -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 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); diff --git a/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp b/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp index 2d46103c..0066f901 100644 --- a/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp +++ b/test/stress/sequential/sequential-misc/rigtorp_mpmc_driver.cpp @@ -25,7 +25,8 @@ protected: } void test() { - rigtorp::MPMCQueue q(s_nRigtorpMPMCQueueCapacity); + std::unique_ptr> q( + new rigtorp::MPMCQueue(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; } } diff --git a/test/stress/sequential/sequential-misc/rwlock_driver.cpp b/test/stress/sequential/sequential-misc/rwlock_driver.cpp index aee9463a..ab9ca0a7 100644 --- a/test/stress/sequential/sequential-misc/rwlock_driver.cpp +++ b/test/stress/sequential/sequential-misc/rwlock_driver.cpp @@ -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(new RWLock()); for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) { - ReaderWriterThread(write_percentage); + ReaderWriterThread(rwlock.get(), write_percentage); } } diff --git a/test/stress/sequential/sequential-misc/seqlock_driver.cpp b/test/stress/sequential/sequential-misc/seqlock_driver.cpp index 21313b3f..3a7d865d 100644 --- a/test/stress/sequential/sequential-misc/seqlock_driver.cpp +++ b/test/stress/sequential/sequential-misc/seqlock_driver.cpp @@ -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(new SeqLock()); for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) { - ReaderWriterThread(write_percentage); + ReaderWriterThread(seqlock.get(), write_percentage); } } diff --git a/test/stress/sequential/sequential-misc/spinlock_driver.cpp b/test/stress/sequential/sequential-misc/spinlock_driver.cpp index 99a48153..6dce8121 100644 --- a/test/stress/sequential/sequential-misc/spinlock_driver.cpp +++ b/test/stress/sequential/sequential-misc/spinlock_driver.cpp @@ -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_ptr(new lock_type()); \ x = 0; \ - Thread##lock_type(); \ + Thread##lock_type(lock_ptr.get()); \ } class SpinLockTest : public cds_test::stress_fixture { diff --git a/test/stress/sequential/test.cpp b/test/stress/sequential/test.cpp index f999c9ed..a632e17a 100644 --- a/test/stress/sequential/test.cpp +++ b/test/stress/sequential/test.cpp @@ -33,7 +33,9 @@ */ #include "../misc/common.h" +#include "../stack/stack_type.h" #include +#include namespace { @@ -41,12 +43,28 @@ class sequential_test : public cds_test::stress_fixture { }; +atomics::atomic x; +atomics::atomic y; +typedef cds::sync::spin SpinLock; +SpinLock l; + +struct value_type { + size_t num; +}; + +typedef stack::Types::Treiber_HP stack_type; +stack_type stack; +rigtorp::SPSCQueue 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