From: Peizhao Ou Date: Sat, 9 Dec 2017 16:57:27 +0000 (-0800) Subject: Fixes misc test cases X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1621e9e488395f489590c3fc497c28382fb17fd1;p=libcds.git Fixes misc test cases --- diff --git a/test/stress/misc/deque_driver.cpp b/test/stress/misc/deque_driver.cpp index da84edb4..e49b4a7a 100644 --- a/test/stress/misc/deque_driver.cpp +++ b/test/stress/misc/deque_driver.cpp @@ -54,15 +54,15 @@ protected: } } } - // while (true) { - // int res = deque->take(); - // if (res != EMPTY) { - // sums[index] += res; - // succ_counts[index]++; - // } else { - // break; - // } - // } + while (true) { + int res = deque->take(); + if (res != EMPTY) { + sums[index] += res; + succ_counts[index]++; + } else { + break; + } + } } }; @@ -103,10 +103,13 @@ TEST_F(ChaseLevDequeTest, DequePushPopTake) { received_sum += sums[i]; overall_count += succ_counts[i]; } - cout << "Sum of push: " << push_sum << "\n"; - cout << "Received sum:" << received_sum << "\n"; - cout << "overall_count:" << overall_count << "\n"; - cout << "push_count=" << push_count << "\n"; + if (overall_count != push_count || received_sum != push_sum) { + cout << "Incorrect deque\n"; + cout << "Push sum: " << push_sum << "\n"; + cout << "Received sum:" << received_sum << "\n"; + cout << "Push count=" << push_count << "\n"; + cout << "Received count:" << overall_count << "\n"; + } } } // namespace diff --git a/test/stress/misc/mcslock_driver.cpp b/test/stress/misc/mcslock_driver.cpp index 1435e971..2a2091b9 100644 --- a/test/stress/misc/mcslock_driver.cpp +++ b/test/stress/misc/mcslock_driver.cpp @@ -27,11 +27,10 @@ protected: static void Thread() { cds_others::mcs_mutex::guard g(my_mutex); - x = 1; my_mutex->unlock(&g); for (ullong i = 0; i < s_nMCSLockPassCount; i++) { my_mutex->lock(&g); - x = i; + x++; my_mutex->unlock(&g); } my_mutex->lock(&g); @@ -43,14 +42,17 @@ cds_others::mcs_mutex *MCSLockTest::my_mutex; TEST_F(MCSLockTest, BasicLockUnlock) { my_mutex = new cds_others::mcs_mutex(); + x = 0; std::thread *threads = new std::thread[s_nMCSLockThreadCount]; for (int i = 0; i < s_nMCSLockThreadCount; i++) { threads[i] = std::thread(Thread); } - for (int i = 0; i < s_nMCSLockThreadCount; i++) { threads[i].join(); } + if (x != s_nMCSLockPassCount * s_nMCSLockThreadCount) { + cout << "MCS lock incorrect\n"; + } } } // namespace diff --git a/test/stress/misc/rwlock_driver.cpp b/test/stress/misc/rwlock_driver.cpp index 7d0084d9..2c61d440 100644 --- a/test/stress/misc/rwlock_driver.cpp +++ b/test/stress/misc/rwlock_driver.cpp @@ -46,11 +46,11 @@ protected: if (!rwlock->write_trylock()) { rwlock->write_lock(); } - x += 1; + x++; rwlock->write_unlock(); } else { rwlock->write_lock(); - x += 1; + x++; rwlock->write_unlock(); } } @@ -65,7 +65,7 @@ RWLock *RWLockTest::rwlock; TEST_F(RWLockTest, BasicLockUnlock) { rwlock = new RWLock(); int num_threads = s_nRWLockThreadCount; - for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) { + for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) { std::thread *threads = new std::thread[num_threads]; for (size_t i = 0; i < num_threads; i++) { threads[i] = std::thread(ReaderWriterThread, write_percentage); diff --git a/test/stress/misc/spinlock_driver.cpp b/test/stress/misc/spinlock_driver.cpp index b1b0e95c..a811db23 100644 --- a/test/stress/misc/spinlock_driver.cpp +++ b/test/stress/misc/spinlock_driver.cpp @@ -24,17 +24,16 @@ static size_t s_nTicketLockPassCount = 4000000; #define TASK(lock_type, lock_ptr, pass_cnt) \ static void Thread##lock_type() { \ for (int i = 0; i < pass_cnt; i++) { \ - for (int j = 0; j < pass_cnt; j++) { \ - lock_ptr->lock(); \ - x = i + j; \ - lock_ptr->unlock(); \ - } \ + lock_ptr->lock(); \ + x++; \ + lock_ptr->unlock(); \ } \ } -#define LOCK_TEST(lock_type, lock_ptr) \ +#define LOCK_TEST(lock_type, lock_ptr, pass_cnt) \ TEST_F(SpinLockTest, lock_type) { \ lock_ptr = new lock_type(); \ + x = 0; \ std::thread *threads = new std::thread[s_nSpinLockThreadCount]; \ for (int i = 0; i < s_nSpinLockThreadCount; i++) { \ threads[i] = std::thread(Thread##lock_type); \ @@ -42,6 +41,9 @@ static size_t s_nTicketLockPassCount = 4000000; for (int i = 0; i < s_nSpinLockThreadCount; i++) { \ threads[i].join(); \ } \ + if (x != s_nSpinLockThreadCount * pass_cnt) { \ + cout << "Incorrect " << #lock_type << "\n"; \ + } \ } class SpinLockTest : public cds_test::stress_fixture { @@ -71,9 +73,9 @@ SpinLock *SpinLockTest::spin_mutex; Reentrant32 *SpinLockTest::reentrant_mutex32; Reentrant64 *SpinLockTest::reentrant_mutex64; -LOCK_TEST(TicketLock, ticket_mutex) -LOCK_TEST(SpinLock, spin_mutex) -LOCK_TEST(Reentrant32, reentrant_mutex32) -LOCK_TEST(Reentrant64, reentrant_mutex64) +LOCK_TEST(TicketLock, ticket_mutex, s_nTicketLockPassCount) +LOCK_TEST(SpinLock, spin_mutex, s_nSpinLockPassCount) +LOCK_TEST(Reentrant32, reentrant_mutex32, s_nSpinLockPassCount) +LOCK_TEST(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount) } // namespace