Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
91d2d4f6
authored
Feb 01, 2015
by
Tobias Fuchs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
containers_cpp: extended unit tests for MP/MC queue by checks for relative order
parent
72dd5ed2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
21 deletions
+62
-21
containers_cpp/test/main.cc
+3
-2
containers_cpp/test/queue_test-inl.h
+0
-0
containers_cpp/test/queue_test.h
+59
-19
No files found.
containers_cpp/test/main.cc
View file @
91d2d4f6
...
@@ -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
>
>
);
...
...
containers_cpp/test/queue_test-inl.h
View file @
91d2d4f6
This diff is collapsed.
Click to expand it.
containers_cpp/test/queue_test.h
View file @
91d2d4f6
...
@@ -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
QueueTest
MultipleProducerMultipleConsumer
_Pre
();
void
QueueTest
OrderMPMC
_Pre
();
void
QueueTest
MultipleProducerMultipleConsumer
_Post
();
void
QueueTest
OrderMPMC
_Post
();
void
QueueTest
MultipleProducerMultipleConsumer_
ThreadMethod
();
void
QueueTest
OrderMPMC_Producer
ThreadMethod
();
void
QueueTest
SingleProducedSingleConsumer_Pre
();
void
QueueTest
OrderMPMC_ConsumerThreadMethod
();
void
QueueTestSingleProduce
dSingleConsumer_Post
();
void
QueueTestSingleProduce
rSingleConsumer_Pre
();
void
QueueTestSingleProduce
dSingleConsumer_ThreadMethod
();
void
QueueTestSingleProduce
rSingleConsumer_Post
();
void
QueueTestSingle
ThreadEnqueueDequeue
_ThreadMethod
();
void
QueueTestSingle
ProducerSingleConsumer
_ThreadMethod
();
void
QueueTestSingleThreadEnqueueDequeue_Pre
();
void
QueueTestSingleThreadEnqueueDequeue_Pre
();
void
QueueTestSingleThreadEnqueueDequeue_Post
();
void
QueueTestSingleThreadEnqueueDequeue_Post
();
void
QueueTestSingleThreadEnqueueDequeue_ThreadMethod
();
public
:
public
:
QueueTest
();
QueueTest
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment