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
025ef7c9
authored
9 years ago
by
Christian Kern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed codestyle, added some documentation, fixed unsigned/signed warnings
parent
92f0f25b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
17 deletions
+35
-17
mtapi_c/test/embb_mtapi_test_id_pool.cc
+12
-11
mtapi_c/test/embb_mtapi_test_id_pool.h
+23
-6
No files found.
mtapi_c/test/embb_mtapi_test_id_pool.cc
View file @
025ef7c9
...
@@ -33,7 +33,7 @@ IdPoolTest::IdPoolTest() {
...
@@ -33,7 +33,7 @@ IdPoolTest::IdPoolTest() {
Post
(
&
IdPoolTest
::
TestBasicPost
,
this
);
Post
(
&
IdPoolTest
::
TestBasicPost
,
this
);
CreateUnit
(
"mtapi id pool test concurrent"
).
CreateUnit
(
"mtapi id pool test concurrent"
).
Add
(
&
IdPoolTest
::
TestParallel
,
this
,
CONCURRENT_ACCESSORS_ID_POOL
_2
Add
(
&
IdPoolTest
::
TestParallel
,
this
,
concurrent_accessors_id_pool
_2
,
20
).
,
20
).
Post
(
&
IdPoolTest
::
TestParallelPost
,
this
).
Post
(
&
IdPoolTest
::
TestParallelPost
,
this
).
Pre
(
&
IdPoolTest
::
TestParallelPre
,
this
);
Pre
(
&
IdPoolTest
::
TestParallelPre
,
this
);
...
@@ -43,33 +43,33 @@ void IdPoolTest::TestParallel() {
...
@@ -43,33 +43,33 @@ void IdPoolTest::TestParallel() {
// allocate ID_ELEMENTS_PER_ACCESSOR elements. Each test thread is
// allocate ID_ELEMENTS_PER_ACCESSOR elements. Each test thread is
// guaranteed to be able to allocate this amount of elements.
// guaranteed to be able to allocate this amount of elements.
TestAllocateDeallocateNElementsFromPool
(
id_pool_parallel
,
TestAllocateDeallocateNElementsFromPool
(
id_pool_parallel
,
ID_ELEMENTS_PER_ACCESSOR
);
id_elements_per_accessor
);
}
}
void
IdPoolTest
::
TestParallelPre
()
{
void
IdPoolTest
::
TestParallelPre
()
{
// create second id pool with CONCURRENT_ACCESSORS_ID_POOL_2*
// create second id pool with CONCURRENT_ACCESSORS_ID_POOL_2*
// ID_ELEMENTS_PER_ACCESSOR elements
// ID_ELEMENTS_PER_ACCESSOR elements
embb_mtapi_id_pool_initialize
(
&
id_pool_parallel
,
embb_mtapi_id_pool_initialize
(
&
id_pool_parallel
,
CONCURRENT_ACCESSORS_ID_POOL_2
*
ID_ELEMENTS_PER_ACCESSOR
);
concurrent_accessors_id_pool_2
*
id_elements_per_accessor
);
}
}
void
IdPoolTest
::
TestParallelPost
()
{
void
IdPoolTest
::
TestParallelPost
()
{
// after the parallel tests, try to again allocate and deallocate all
// after the parallel tests, try to again allocate and deallocate all
// elements sequentially.
// elements sequentially.
TestAllocateDeallocateNElementsFromPool
(
id_pool_parallel
,
TestAllocateDeallocateNElementsFromPool
(
id_pool_parallel
,
CONCURRENT_ACCESSORS_ID_POOL_2
*
ID_ELEMENTS_PER_ACCESSOR
,
true
);
concurrent_accessors_id_pool_2
*
id_elements_per_accessor
,
true
);
// finalize pool
// finalize pool
embb_mtapi_id_pool_finalize
(
&
id_pool_parallel
);
embb_mtapi_id_pool_finalize
(
&
id_pool_parallel
);
}
}
void
IdPoolTest
::
TestBasic
()
{
void
IdPoolTest
::
TestBasic
()
{
TestAllocateDeallocateNElementsFromPool
(
id_pool
,
ID_POOL_SIZE
_1
,
true
);
TestAllocateDeallocateNElementsFromPool
(
id_pool
,
id_pool_size
_1
,
true
);
}
}
void
IdPoolTest
::
TestBasicPre
()
{
void
IdPoolTest
::
TestBasicPre
()
{
// create id pool with ID_POOL_SIZE_1 elements
// create id pool with ID_POOL_SIZE_1 elements
embb_mtapi_id_pool_initialize
(
&
id_pool
,
ID_POOL_SIZE
_1
);
embb_mtapi_id_pool_initialize
(
&
id_pool
,
id_pool_size
_1
);
}
}
void
IdPoolTest
::
TestBasicPost
()
{
void
IdPoolTest
::
TestBasicPost
()
{
...
@@ -81,16 +81,16 @@ void IdPoolTest::TestAllocateDeallocateNElementsFromPool(
...
@@ -81,16 +81,16 @@ void IdPoolTest::TestAllocateDeallocateNElementsFromPool(
embb_mtapi_id_pool_t
&
pool
,
embb_mtapi_id_pool_t
&
pool
,
int
count_elements
,
int
count_elements
,
bool
empty_check
)
{
bool
empty_check
)
{
std
::
vector
<
int
>
allocated
;
std
::
vector
<
unsigned
int
>
allocated
;
for
(
int
i
=
0
;
i
!=
count_elements
;
++
i
)
{
for
(
int
i
=
0
;
i
!=
count_elements
;
++
i
)
{
allocated
.
push_back
(
embb_mtapi_id_pool_allocate
(
&
pool
));
allocated
.
push_back
(
embb_mtapi_id_pool_allocate
(
&
pool
));
}
}
// the allocated elements should be disjunctive, and never invalid element
// the allocated elements should be disjunctive, and never invalid element
for
(
int
x
=
0
;
x
!=
allocated
.
size
();
++
x
)
{
for
(
unsigned
int
x
=
0
;
x
!=
allocated
.
size
();
++
x
)
{
PT_ASSERT
(
allocated
[
x
]
!=
EMBB_MTAPI_IDPOOL_INVALID_ID
);
PT_ASSERT
(
allocated
[
x
]
!=
EMBB_MTAPI_IDPOOL_INVALID_ID
);
for
(
int
y
=
0
;
y
!=
allocated
.
size
();
++
y
)
{
for
(
unsigned
int
y
=
0
;
y
!=
allocated
.
size
();
++
y
)
{
if
(
x
==
y
)
{
if
(
x
==
y
)
{
continue
;
continue
;
}
}
...
@@ -103,7 +103,7 @@ void IdPoolTest::TestAllocateDeallocateNElementsFromPool(
...
@@ -103,7 +103,7 @@ void IdPoolTest::TestAllocateDeallocateNElementsFromPool(
if
(
empty_check
)
{
if
(
empty_check
)
{
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
{
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
{
PT_ASSERT_EQ
(
embb_mtapi_id_pool_allocate
(
&
pool
),
PT_ASSERT_EQ
(
embb_mtapi_id_pool_allocate
(
&
pool
),
EMBB_MTAPI_IDPOOL_INVALID_ID
static_cast
<
unsigned
int
>
(
EMBB_MTAPI_IDPOOL_INVALID_ID
)
)
)
}
}
}
}
...
@@ -112,7 +112,8 @@ void IdPoolTest::TestAllocateDeallocateNElementsFromPool(
...
@@ -112,7 +112,8 @@ void IdPoolTest::TestAllocateDeallocateNElementsFromPool(
::
std
::
random_shuffle
(
allocated
.
begin
(),
allocated
.
end
());
::
std
::
random_shuffle
(
allocated
.
begin
(),
allocated
.
end
());
for
(
int
i
=
0
;
i
!=
count_elements
;
++
i
)
{
for
(
int
i
=
0
;
i
!=
count_elements
;
++
i
)
{
embb_mtapi_id_pool_deallocate
(
&
pool
,
allocated
[
i
]);
embb_mtapi_id_pool_deallocate
(
&
pool
,
allocated
[
static_cast
<
unsigned
int
>
(
i
)]);
}
}
}
}
This diff is collapsed.
Click to expand it.
mtapi_c/test/embb_mtapi_test_id_pool.h
View file @
025ef7c9
...
@@ -33,22 +33,39 @@
...
@@ -33,22 +33,39 @@
// for shuffling a vector
// for shuffling a vector
#include <algorithm>
#include <algorithm>
#define ID_POOL_SIZE_1 100
#define CONCURRENT_ACCESSORS_ID_POOL_2 10
#define ID_ELEMENTS_PER_ACCESSOR 10
class
IdPoolTest
:
public
partest
::
TestCase
{
class
IdPoolTest
:
public
partest
::
TestCase
{
public
:
public
:
embb_mtapi_id_pool_t
id_pool
;
embb_mtapi_id_pool_t
id_pool
;
embb_mtapi_id_pool_t
id_pool_parallel
;
embb_mtapi_id_pool_t
id_pool_parallel
;
IdPoolTest
();
IdPoolTest
();
private
:
private
:
static
const
unsigned
int
id_pool_size_1
=
100
;
static
const
unsigned
int
concurrent_accessors_id_pool_2
=
10
;
static
const
unsigned
int
id_elements_per_accessor
=
10
;
/**
* We create a pool of size number_accessors*elements_per_accessor, so
* at each time we can guarantee each thread to be able to allocate
* elements_per_accessor elements.
* We create number_accessor threads, where each thread iteratively
* allocates and frees elements_per_accessor elements, which in each case
* has to be successful. Additionally, the sanity checks from the basic tests
* are repeated. The TestParallelPost function also repeats all
* sequential tests.
*/
void
TestParallel
();
void
TestParallel
();
void
TestParallelPre
();
void
TestParallelPre
();
void
TestParallelPost
();
void
TestParallelPost
();
/**
* Create a pool of size N. We repeatedly allocate and free N elements, check
* if the pool always returns disjunctive ids and check that the pool never
* returns the invalid element, if the pool is not empty. Check that the
* invalid element is returned if the pool is empty.
*/
void
TestBasic
();
void
TestBasic
();
void
TestBasicPre
();
void
TestBasicPre
();
void
TestBasicPost
();
void
TestBasicPost
();
...
...
This diff is collapsed.
Click to expand it.
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