From 1f48dc23069fbf0d1cae4a57e105a5da84532f3c Mon Sep 17 00:00:00 2001 From: lucapegolotti Date: Tue, 15 Mar 2016 11:02:41 +0100 Subject: [PATCH] Enable assertions in Release mode and improve function consistency in main.cc --- linearizability_tester/main.cc | 43 ++++++++++++++++++++++++------------------- linearizability_tester/src/sequential_data_structures.h | 1 - linearizability_tester/src/tests.h | 1 - 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/linearizability_tester/main.cc b/linearizability_tester/main.cc index ceafb33..b513493 100644 --- a/linearizability_tester/main.cc +++ b/linearizability_tester/main.cc @@ -2,6 +2,12 @@ * Main script that applies the linearizability tester on embb data structures. */ +// Enable assertions even in Release mode +#ifdef NDEBUG +#undef NDEBUG +#include +#endif + #include #include #include @@ -51,7 +57,7 @@ static void embb_worker_stack( } } -// Each thread executes quasi randomly operations (TryEqneueu, TryDequeue) +// Each thread executes quasi randomly operations (TryEnqueue, TryDequeue) // on the concurrent data structure and construct the history. template static void embb_worker_queue( @@ -94,7 +100,7 @@ static void embb_worker_queue( // Creates the history and apply the tester on it template -static void embb_experiment_stack(bool is_linearizable) +static void embb_experiment_stack() { constexpr std::chrono::hours max_duration{ 1 }; constexpr std::size_t N = 560000U; @@ -106,12 +112,11 @@ static void embb_experiment_stack(bool is_linearizable) ConcurrentLog> concurrent_log{ 2U * log_size }; S concurrent_stack(N); - if (!is_linearizable) - { - bool ok = concurrent_stack.TryPush(5); - assert(ok); - } - + // Check if push and pop operations are possible + char value; + assert(concurrent_stack.TryPush(5)); + assert(concurrent_stack.TryPop(value)); + // create history start_threads(number_of_threads, embb_worker_stack, std::cref(worker_configuration), std::ref(concurrent_log), std::ref(concurrent_stack)); @@ -130,7 +135,8 @@ static void embb_experiment_stack(bool is_linearizable) LinearizabilityTester, Option::LRU_CACHE> tester{ log_copy.info(), max_duration }; tester.check(result); - assert(result.is_timeout() || result.is_linearizable() == is_linearizable); + // If structure is not linearizabile break run using assertion + assert(result.is_timeout() || result.is_linearizable()); } end = std::chrono::system_clock::now(); seconds = std::chrono::duration_cast(end - start); @@ -141,7 +147,7 @@ static void embb_experiment_stack(bool is_linearizable) // Creates the history and apply the tester on it template -static void embb_experiment_queue(bool is_linearizable) +static void embb_experiment_queue() { constexpr std::chrono::hours max_duration{ 1 }; constexpr std::size_t N = 560000U; @@ -154,11 +160,10 @@ static void embb_experiment_queue(bool is_linearizable) ConcurrentLog> concurrent_log{ 2U * log_size }; S concurrent_queue(N); - if (!is_linearizable) - { - bool ok = concurrent_queue.TryEnqueue(5); - assert(ok); - } + // check if enqueue and dequeue operations are possible + char value; + assert(concurrent_queue.TryEnqueue(5)); + assert(concurrent_queue.TryDequeue(value)); // create history start_threads(number_of_threads, embb_worker_queue, std::cref(worker_configuration), @@ -176,7 +181,8 @@ static void embb_experiment_queue(bool is_linearizable) assert(log_copy.number_of_entries() == number_of_entries); LinearizabilityTester, Option::LRU_CACHE> tester{ log_copy.info(), max_duration }; tester.check(result); - assert(result.is_timeout() || result.is_linearizable() == is_linearizable); + // If structure is not linearizabile break run using assertion + assert(result.is_timeout() || result.is_linearizable()); } end = std::chrono::system_clock::now(); seconds = std::chrono::duration_cast(end - start); @@ -191,14 +197,13 @@ int main() // Test functions and structures in linearizability_tester.h and sequential_data_structures.h run_tests(); - embb::base::Thread::SetThreadsMaxCount(255); std::cout << "Linearizability test on LockFreeMPMCQueue" << std::endl; - embb_experiment_queue>(true); + embb_experiment_queue>(); std::cout << "Linearizability test on LockFreeStack" << std::endl; - embb_experiment_stack>(true); + embb_experiment_stack>(); return 0; } diff --git a/linearizability_tester/src/sequential_data_structures.h b/linearizability_tester/src/sequential_data_structures.h index 3da8a10..3e06d8f 100755 --- a/linearizability_tester/src/sequential_data_structures.h +++ b/linearizability_tester/src/sequential_data_structures.h @@ -314,7 +314,6 @@ class Stack if (m_vector.size() < value + 1U) m_vector.resize(value + 1U); - assert(value < m_vector.size()); NodePtr& node_ptr = m_vector[value]; if (node_ptr == nullptr) diff --git a/linearizability_tester/src/tests.h b/linearizability_tester/src/tests.h index 7b4700a..bf096de 100755 --- a/linearizability_tester/src/tests.h +++ b/linearizability_tester/src/tests.h @@ -2039,7 +2039,6 @@ void run_tests(){ test_state_set_op(); test_state_stack(); test_state_stack_op(); - test_state_queue(); test_state_queue_op(); -- libgit2 0.26.0