#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <deque>
#include <vector>
#include <set>
#include <list>
#include <rpa/platforms.h>
#include <rpa/architectures/posix.h>
#include <rpa/algorithms/transform.h>
#include <rpa/testing.h>
Classes | |
class | ObjT |
class | tst_nobuf< ThrTree > |
Test without output buffer, but with a mutex to protect the output. More... | |
class | tst_unbounded_noall< ThrTree > |
In t12, tests with unbounded buffers, without allocator. More... | |
class | tst_unbounded_alloc< ThrTree, IterBuf > |
Test with an unbounded output buffer. More... | |
class | tst_bounded_noall< ThrTree > |
In t12, tests with limited buffers, without allocator. More... | |
class | tst_bounded_alloc< ThrTree, IterBuf > |
In t12, tests with limited buffers, with buffers allocator. More... | |
Defines | |
#define | NB_THR 5 |
General purpose macros. | |
#define | TST_BUF_SZ 30 |
The size of fixed-size buffers. | |
#define | NB_SAMPLES ( ( 1 << 16 ) * TST_RATIO ) |
Typedefs | |
typedef list< ObjT > | ListObjT |
typedef back_insert_iterator< ListObjT > | BackInsT |
Functions | |
static ObjT | Char2Obj (const char *aStr) |
template<class ThrTree> | |
tst_nobuf< ThrTree > | make_nobuf (const ThrTree &aThrTree) |
template<class ThrTree> | |
tst_unbounded_noall< ThrTree > | make_unbounded_noall (const ThrTree &aThrTree) |
In t12, helper for tests with unbounded buffers, without allocator. | |
template<class ThrTree, class IterBuf> | |
tst_unbounded_alloc< ThrTree, IterBuf > | make_unbounded_alloc (const ThrTree &aThrTree, IterBuf aIterBuf) |
template<class ThrTree> | |
tst_bounded_noall< ThrTree > | make_bounded_noall (const ThrTree &aThrTree, size_t aBufSz) |
In t12, helper for tests with limited buffers, without allocator. | |
template<class ThrTree, class IterBuf> | |
tst_bounded_alloc< ThrTree, IterBuf > | make_bounded_alloc (const ThrTree &aThrTree, size_t aBufSz, IterBuf aIterBuf) |
In t12, helper function for tests with limited buffers, with buffers allocator. | |
template<class Functor> | |
static void | Cmp (int aArgC, const char *const *aArgV, Functor aFunc) |
list< vector< ObjT > > | myLstVecBuf (NB_THR) |
vector< list< ObjT > > | myVecLstBuf (NB_THR) |
template<class ThrTree> | |
static void | mainInternMtx (int aArgC, const char *const *aArgV, size_t aBufSz, ThrTree aThrTree) |
Tests the various output sequences configurations. | |
static void | mainIntern (int aArgC, const char *const *aArgV, size_t aBufSz) |
int | main (int aArgC, const char **aArgV) |
Loops on internal data and on the command line. | |
Variables | |
static rpa::thread_crea | myCreaThr [NB_THR] |
static rpa::testing_thread | myPosixThr [NB_THR] |
rpa::testing_mutex | myMtx |
ObjT | myArrArrBuf [NB_THR][TST_BUF_SZ] |
deque< ObjT > | myArrDeqBuf [NB_THR] |
static char | myStr [NB_SAMPLES][RPA_INT_STR] |
These input data are global because they are too big for the stack. | |
static char * | myPtr [NB_SAMPLES] |
#define NB_SAMPLES ( ( 1 << 16 ) * TST_RATIO ) |
Multiplied by two at each loop. The extra ratio is for adjusting the time taken by tests.
#define NB_THR 5 |
General purpose macros.
Our thread pool. The threads are 'create'-d by the algorithm. A excessively big number of thread is used, for testing purpose. On Cygwin, it does not work by default with thousand threads.
#define TST_BUF_SZ 30 |
The size of fixed-size buffers.
static ObjT Char2Obj | ( | const char * | aStr | ) | [static] |
Instead of using a functor like for most tests, here, we use a plain function pointer.
static void Cmp | ( | int | aArgC, | |
const char *const * | aArgV, | |||
Functor | aFunc | |||
) | [static] |
Tries with various input container types. The expected maximum number of object copies should not depend on the kind of input. Therefore, the test value is the same for all.
int main | ( | int | aArgC, | |
const char ** | aArgV | |||
) |
Loops on internal data and on the command line.
Setup a buffer of random strings.
Tries the algorithm with various sizes, much smaller and much bigger than the number of threads and the size of buffers. The number is multiplied by sixteen at each loop.
Different buffer sizes
static void mainIntern | ( | int | aArgC, | |
const char *const * | aArgV, | |||
size_t | aBufSz | |||
) | [static] |
Run the tests with several mutex for the input :
Intentionaly try a zero number of threads. With zero threads, it must work in plain sequential mode.
static void mainInternMtx | ( | int | aArgC, | |
const char *const * | aArgV, | |||
size_t | aBufSz, | |||
ThrTree | aThrTree | |||
) | [static] |
Tests the various output sequences configurations.
Unlimited size buffer
Bounded buffer.
Without output buffer.
tst_bounded_alloc< ThrTree, IterBuf > make_bounded_alloc | ( | const ThrTree & | aThrTree, | |
size_t | aBufSz, | |||
IterBuf | aIterBuf | |||
) |
In t12, helper function for tests with limited buffers, with buffers allocator.
tst_bounded_noall< ThrTree > make_bounded_noall | ( | const ThrTree & | aThrTree, | |
size_t | aBufSz | |||
) |
In t12, helper for tests with limited buffers, without allocator.
tst_nobuf< ThrTree > make_nobuf | ( | const ThrTree & | aThrTree | ) |
tst_unbounded_alloc< ThrTree, IterBuf > make_unbounded_alloc | ( | const ThrTree & | aThrTree, | |
IterBuf | aIterBuf | |||
) |
tst_unbounded_noall< ThrTree > make_unbounded_noall | ( | const ThrTree & | aThrTree | ) |
In t12, helper for tests with unbounded buffers, without allocator.
list< vector< ObjT > > myLstVecBuf | ( | NB_THR | ) |
vector< list< ObjT > > myVecLstBuf | ( | NB_THR | ) |
ObjT myArrArrBuf[NB_THR][TST_BUF_SZ] |
Different types of buffer allocators are used. We try not to use typedefs, to make code samples lighter and shorter.
deque< ObjT > myArrDeqBuf[NB_THR] |
rpa::thread_crea myCreaThr[NB_THR] [static] |
rpa::testing_thread myPosixThr[NB_THR] [static] |
In debug compilation mode, or in sequential compilation mode (that is if RPA_PARALLEL is not set), this is a fake thread. Otherwise, probably a pthread because implemented on most platforms.
char* myPtr[NB_SAMPLES] [static] |
char myStr[NB_SAMPLES][RPA_INT_STR] [static] |
These input data are global because they are too big for the stack.