Commit 91d2d4f6 by Tobias Fuchs

containers_cpp: extended unit tests for MP/MC queue by checks for relative order

parent 72dd5ed2
...@@ -56,10 +56,11 @@ PT_MAIN("Data Structures C++") { ...@@ -56,10 +56,11 @@ PT_MAIN("Data Structures C++") {
PT_RUN(embb::containers::test::HazardPointerTest); PT_RUN(embb::containers::test::HazardPointerTest);
PT_RUN(embb::containers::test::QueueTest< PT_RUN(embb::containers::test::QueueTest<
embb::containers::WaitFreeSPSCQueue<int> >); embb::containers::WaitFreeSPSCQueue< ::std::pair<size_t COMMA int> > >);
PT_RUN(embb::containers::test::QueueTest< PT_RUN(embb::containers::test::QueueTest<
embb::containers::LockFreeMPMCQueue<int> COMMA true COMMA true >); embb::containers::LockFreeMPMCQueue< ::std::pair<size_t COMMA int> >
COMMA true COMMA true >);
PT_RUN(embb::containers::test::StackTest< PT_RUN(embb::containers::test::StackTest<
embb::containers::LockFreeStack<int> >); embb::containers::LockFreeStack<int> >);
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
#define CONTAINERS_CPP_TEST_QUEUE_TEST_H_ #define CONTAINERS_CPP_TEST_QUEUE_TEST_H_
#include <vector> #include <vector>
#include <utility>
#include <partest/partest.h> #include <partest/partest.h>
#include <embb/base/duration.h> #include <embb/base/duration.h>
#include <embb/containers/wait_free_spsc_queue.h>
namespace embb { namespace embb {
namespace containers { namespace containers {
...@@ -39,35 +39,75 @@ template<typename Queue_t, ...@@ -39,35 +39,75 @@ template<typename Queue_t,
bool MultipleProducers = false, bool MultipleProducers = false,
bool MultipleConsumers = false> bool MultipleConsumers = false>
class QueueTest : public partest::TestCase { class QueueTest : public partest::TestCase {
public:
typedef ::std::pair<size_t, int> element_t;
private:
/// Minimum number of elements enqueued by every producer
/// in MP/MC unit test. Must be a multiple of 8.
static const int MIN_ENQ_ELEMENTS = 120;
static const int MIN_TOTAL_PRODUCE_CONSUME_COUNT = 1000;
private:
class Consumer {
private:
Queue_t * q;
int n_producers;
int n_producer_elements;
::std::vector<unsigned char> consumer_tally;
::std::vector<int> sequence_number;
public:
Consumer(Queue_t * const queue, int numProducers, int numProducerElements);
void Run();
const ::std::vector<unsigned char> & Tally() const {
return consumer_tally;
}
};
class Producer {
private:
Queue_t * q;
size_t producer_id;
int n_producer_elements;
public:
Producer(Queue_t * const queue, size_t id, int numProducerElements) :
q(queue),
producer_id(id),
n_producer_elements(numProducerElements) {}
void Run();
};
private: private:
static const int QUEUE_SIZE = 100;
static const int TOTAL_PRODUCE_CONSUME_COUNT = 10000;
int n_threads; int n_threads;
int n_queue_size;
int n_total_produce_consume_count;
embb::base::Atomic<int> thread_selector_producer; embb::base::Atomic<int> thread_selector_producer;
embb::base::Atomic<int> produce_count; embb::base::Atomic<int> produce_count;
std::vector<int> consumed_elements; ::std::vector<element_t> consumed_elements;
std::vector<int> produced_elements; ::std::vector<element_t> produced_elements;
::std::vector<Consumer> consumers;
::std::vector<Producer> producers;
//for multiple p/c // for multiple p/c
int n_iterations; int n_producers;
int n_queue_elements_per_thread; int n_consumers;
int n_queue_elements; embb::base::Atomic<size_t> next_producer_id;
std::vector<int> expected_queue_elements; embb::base::Atomic<size_t> next_consumer_id;
std::vector<int>* thread_local_vectors; /// Number of elements enqueued by every producer, depending
embb::base::Atomic<int> queueSize; /// on number of iterations for regression tests.
int n_producer_elements;
int consume_count; int consume_count;
Queue_t* queue; Queue_t* queue;
void QueueTestMultipleProducerMultipleConsumer_Pre(); void QueueTestOrderMPMC_Pre();
void QueueTestMultipleProducerMultipleConsumer_Post(); void QueueTestOrderMPMC_Post();
void QueueTestMultipleProducerMultipleConsumer_ThreadMethod(); void QueueTestOrderMPMC_ProducerThreadMethod();
void QueueTestSingleProducedSingleConsumer_Pre(); void QueueTestOrderMPMC_ConsumerThreadMethod();
void QueueTestSingleProducedSingleConsumer_Post(); void QueueTestSingleProducerSingleConsumer_Pre();
void QueueTestSingleProducedSingleConsumer_ThreadMethod(); void QueueTestSingleProducerSingleConsumer_Post();
void QueueTestSingleThreadEnqueueDequeue_ThreadMethod(); void QueueTestSingleProducerSingleConsumer_ThreadMethod();
void QueueTestSingleThreadEnqueueDequeue_Pre(); void QueueTestSingleThreadEnqueueDequeue_Pre();
void QueueTestSingleThreadEnqueueDequeue_Post(); void QueueTestSingleThreadEnqueueDequeue_Post();
void QueueTestSingleThreadEnqueueDequeue_ThreadMethod();
public: public:
QueueTest(); QueueTest();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment