Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Leibner
dune-common
Commits
a48d0c7c
Commit
a48d0c7c
authored
19 years ago
by
Markus Blatt
Browse files
Options
Downloads
Patches
Plain Diff
Added test for pool allocator.
[[Imported from SVN: r1988]]
parent
2106fc72
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/test/.gitignore
+1
-0
1 addition, 0 deletions
common/test/.gitignore
common/test/Makefile.am
+4
-1
4 additions, 1 deletion
common/test/Makefile.am
common/test/poolallocatortest.cc
+143
-0
143 additions, 0 deletions
common/test/poolallocatortest.cc
with
148 additions
and
1 deletion
common/test/.gitignore
+
1
−
0
View file @
a48d0c7c
...
...
@@ -12,6 +12,7 @@ sllisttest
tuplestest
settest
fmatrixtest
poolallocatertest
*.gcda
*.gcno
gmon.out
\ No newline at end of file
This diff is collapsed.
Click to expand it.
common/test/Makefile.am
+
4
−
1
View file @
a48d0c7c
# $Id$
TESTPROGS
=
parsetest test-stack arraylisttest smartpointertest
\
sllisttest iteratorfacadetest tuplestest fmatrixtest
sllisttest iteratorfacadetest tuplestest fmatrixtest
\
poolallocatortest
# which tests to run
TESTS
=
$(
TESTPROGS
)
...
...
@@ -31,3 +32,5 @@ iteratorfacadetest_SOURCES = iteratorfacadetest.cc iteratorfacadetest.hh \
iteratortest.hh
fmatrixtest_SOURCES
=
fmatrixtest.cc
poolallocatortest_SOURCES
=
poolallocatortest.cc
This diff is collapsed.
Click to expand it.
common/test/poolallocatortest.cc
0 → 100644
+
143
−
0
View file @
a48d0c7c
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include
<dune/common/poolallocator.hh>
#include
<dune/common/alignment.hh>
#include
<dune/common/fmatrix.hh>
using
namespace
Dune
;
struct
UnAligned
{
char
t
;
char
s
;
char
k
;
};
template
<
std
::
size_t
size
,
typename
T
>
int
testPool
()
{
int
ret
=
0
;
Pool
<
T
,
size
>
pool
;
int
elements
=
Pool
<
T
,
size
>::
elements
;
//int poolSize = Pool<T,size>::size;
//int chunkSize = Pool<T,size>::chunkSize;
//int alignedSize = Pool<T,size>::alignedSize;
char
**
fields
=
new
char
*
[
10
];
unsigned
long
*
oelements
=
new
unsigned
long
[
10
*
elements
];
typedef
typename
Pool
<
T
,
size
>::
Chunk
Chunk
;
//Fill 10 chunks
for
(
int
chunk
=
0
;
chunk
<
10
;
++
chunk
)
{
//std::cout<< std::endl<<"Chunk "<<chunk<<" ";
//fields[chunk] = new char[333];
unsigned
long
element
=
reinterpret_cast
<
unsigned
long
>
(
pool
.
allocate
());
void
*
celement
=
reinterpret_cast
<
void
*>
(
element
);
//std::cout << element<<" "<< celement<<", "<<std::endl;
Chunk
*
currentChunk
=
pool
.
chunks_
;
assert
(
element
==
reinterpret_cast
<
unsigned
long
>
(
currentChunk
->
memory_
));
unsigned
long
end
=
reinterpret_cast
<
unsigned
long
>
(
currentChunk
->
chunk_
)
+
Pool
<
T
,
size
>::
chunkSize
;
if
(
element
<
reinterpret_cast
<
unsigned
long
>
(
currentChunk
->
chunk_
))
{
std
::
cerr
<<
" buffer overflow during first alloc: "
<<
reinterpret_cast
<
unsigned
long
>
(
currentChunk
->
chunk_
)
<<
">"
<<
element
<<
"+"
<<
sizeof
(
T
)
<<
std
::
endl
;
return
++
ret
;
}
if
(
end
<
element
+
sizeof
(
T
))
{
std
::
cerr
<<
" buffer overflow during first alloc: "
<<
end
<<
"<"
<<
element
<<
"+"
<<
sizeof
(
T
)
<<
std
::
endl
;
return
++
ret
;
}
oelements
[
chunk
*
elements
]
=
element
;
for
(
int
i
=
1
;
i
<
elements
;
i
++
)
{
element
=
reinterpret_cast
<
unsigned
long
>
(
pool
.
allocate
());
celement
=
reinterpret_cast
<
void
*>
(
element
);
// std::cout << element<<" "<<celement<<", "<<std::endl;
if
(
element
<
reinterpret_cast
<
unsigned
long
>
(
currentChunk
->
chunk_
))
{
std
::
cerr
<<
" buffer overflow during first alloc: "
<<
reinterpret_cast
<
unsigned
long
>
(
currentChunk
->
chunk_
)
<<
">"
<<
element
<<
"+"
<<
sizeof
(
T
)
<<
std
::
endl
;
return
++
ret
;
}
if
(
end
<
element
+
sizeof
(
T
))
{
std
::
cerr
<<
" buffer overflow during "
<<
i
<<
" alloc: "
<<
end
<<
"<"
<<
element
+
sizeof
(
T
)
<<
std
::
endl
;
return
++
ret
;
}
if
(
oelements
[
chunk
*
elements
+
i
-
1
]
+
sizeof
(
T
)
>
element
)
{
std
::
cerr
<<
"allocated elements overlap!"
<<
std
::
endl
;
return
++
ret
;
}
oelements
[
chunk
*
elements
+
i
]
=
element
;
}
}
//for(int chunk=0; chunk < 10; ++chunk)
//delete[] fields[chunk];
delete
[]
fields
;
delete
[]
oelements
;
return
ret
;
}
template
<
typename
T
>
int
testPool
()
{
const
std
::
size_t
size
=
sizeof
(
T
)
>=
2
?
sizeof
(
T
)
-
2
:
0
;
int
ret
=
0
;
std
::
cout
<<
"Checking "
<<
typeid
(
T
).
name
()
<<
" sizeof="
<<
sizeof
(
T
)
<<
" with size "
<<
size
<<
" alignment="
<<
AlignmentOf
<
T
>::
value
<<
std
::
endl
;
std
::
cout
<<
"size="
<<
0
<<
std
::
endl
;
ret
+=
testPool
<
0
,
T
>
();
std
::
cout
<<
"size="
<<
size
<<
std
::
endl
;
ret
+=
testPool
<
size
,
T
>
();
std
::
cout
<<
"size="
<<
5
*
size
<<
std
::
endl
;
ret
+=
testPool
<
5
*
size
,
T
>
();
std
::
cout
<<
"size="
<<
11
*
size
<<
std
::
endl
;
ret
+=
testPool
<
11
*
size
,
T
>
();
std
::
cout
<<
"size="
<<
size
<<
std
::
endl
;
ret
+=
testPool
<
33
*
size
,
T
>
();
std
::
cout
<<
"size="
<<
33
*
size
<<
std
::
endl
;
return
ret
;
}
int
main
(
int
argc
,
char
**
argv
)
{
int
ret
=
0
;
/*
ret += testPool<int>();
ret+= testPool<double>();
ret+= testPool<char>();
ret += testPool<Dune::FieldMatrix<double,10,10> >();
*/
std
::
cout
<<
AlignmentOf
<
UnAligned
>::
value
<<
" "
<<
sizeof
(
UnAligned
)
<<
std
::
endl
;
ret
+=
testPool
<
UnAligned
>
();
return
ret
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment