testsuite_allocator.h (allocation_tracker): To tracker_allocator_counter.

2006-10-03  Benjamin Kosnik  <bkoz@redhat.com>

	* testsuite/util/testsuite_allocator.h (allocation_tracker): To
	tracker_allocator_counter.
	(allocation_tracker::allocationTotal): To get_allocation_count.
	(allocation_tracker::deallocationTotal): To get_deallocation_count.
	(allocation_tracker::constructCount): To get_construct_count.
	(allocation_tracker::destructCount): To get_destruct_count.	
	(allocation_tracker::resetCounts): To reset.
	(tracker_alloc): To tracker_allocator.
	* testsuite/util/performance/mem: Remove.
	* testsuite/util/performance/mem/mem_track_allocator_base.hpp: Remove.
	* testsuite/util/performance/mem/mem_track_allocator.hpp: Remove.
	* testsuite/27_io/basic_stringbuf/4.cc: Adjust for new names
	or includes.
	* testsuite/ext/hash_set/check_construct_destroy.cc: Same.
	* testsuite/ext/slist/check_construct_destroy.cc: Same.
	* testsuite/performance/ext/pb_ds/
	hash_random_int_erase_mem_usage.cc: Same.
	* testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage.hpp
	* testsuite/performance/ext/pb_ds/
	priority_queue_text_pop_mem_usage.cc: Same.
	* testsuite/23_containers/vector/capacity/2.cc: Same.
	* testsuite/23_containers/vector/cons/4.cc: Same.
	* testsuite/23_containers/vector/check_construct_destroy.cc: Same.
	* testsuite/23_containers/deque/cons/2.cc: Same.
	* testsuite/23_containers/deque/check_construct_destroy.cc: Same.
	* testsuite/23_containers/list/check_construct_destroy.cc: Same.
	* testsuite/23_containers/set/check_construct_destroy.cc: Same.
	* testsuite/util/testsuite_allocator.h
	* testsuite/util/performance/priority_queue/mem_usage/pop_test.hpp
	* testsuite/util/performance/assoc/mem_usage/multimap_insert_test.hpp
	* testsuite/util/performance/assoc/mem_usage/erase_test.hpp
	* testsuite/util/testsuite_allocator.cc: Same.

From-SVN: r117408
This commit is contained in:
Benjamin Kosnik 2006-10-03 17:01:57 +00:00 committed by Benjamin Kosnik
parent c0a699675b
commit 9f9900dbb6
21 changed files with 244 additions and 506 deletions

View File

@ -1,3 +1,38 @@
2006-10-03 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/util/testsuite_allocator.h (allocation_tracker): To
tracker_allocator_counter.
(allocation_tracker::allocationTotal): To get_allocation_count.
(allocation_tracker::deallocationTotal): To get_deallocation_count.
(allocation_tracker::constructCount): To get_construct_count.
(allocation_tracker::destructCount): To get_destruct_count.
(allocation_tracker::resetCounts): To reset.
(tracker_alloc): To tracker_allocator.
* testsuite/util/performance/mem: Remove.
* testsuite/util/performance/mem/mem_track_allocator_base.hpp: Remove.
* testsuite/util/performance/mem/mem_track_allocator.hpp: Remove.
* testsuite/27_io/basic_stringbuf/4.cc: Adjust for new names
or includes.
* testsuite/ext/hash_set/check_construct_destroy.cc: Same.
* testsuite/ext/slist/check_construct_destroy.cc: Same.
* testsuite/performance/ext/pb_ds/
hash_random_int_erase_mem_usage.cc: Same.
* testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage.hpp
* testsuite/performance/ext/pb_ds/
priority_queue_text_pop_mem_usage.cc: Same.
* testsuite/23_containers/vector/capacity/2.cc: Same.
* testsuite/23_containers/vector/cons/4.cc: Same.
* testsuite/23_containers/vector/check_construct_destroy.cc: Same.
* testsuite/23_containers/deque/cons/2.cc: Same.
* testsuite/23_containers/deque/check_construct_destroy.cc: Same.
* testsuite/23_containers/list/check_construct_destroy.cc: Same.
* testsuite/23_containers/set/check_construct_destroy.cc: Same.
* testsuite/util/testsuite_allocator.h
* testsuite/util/performance/priority_queue/mem_usage/pop_test.hpp
* testsuite/util/performance/assoc/mem_usage/multimap_insert_test.hpp
* testsuite/util/performance/assoc/mem_usage/erase_test.hpp
* testsuite/util/testsuite_allocator.cc: Same.
2006-10-03 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/util/native_type/priority_queue/native_pq_tag.hpp: Remove.

View File

@ -34,11 +34,11 @@ using namespace __gnu_test;
int main()
{
typedef std::deque<int, tracker_alloc<int> > Container;
typedef std::deque<int, tracker_allocator<int> > Container;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c;
ok = check_construct_destroy("empty container", 0, 0) && ok;
@ -46,7 +46,7 @@ int main()
ok = check_construct_destroy("empty container", 0, 0) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", 10, 0) && ok;
@ -55,7 +55,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin(), arr10[0]);
ok = check_construct_destroy("Insert element", 1, 0) && ok;
}
@ -63,7 +63,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin() + 5, arr10, arr10+3);
ok = check_construct_destroy("Insert short range", 3, 0) && ok;
}
@ -71,7 +71,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin() + 7, arr10, arr10+10);
ok = check_construct_destroy("Insert long range", 10, 0) && ok;
}

View File

@ -27,8 +27,8 @@
#include <testsuite_hooks.h>
using __gnu_test::copy_tracker;
using __gnu_test::allocation_tracker;
using __gnu_test::tracker_alloc;
using __gnu_test::tracker_allocator_counter;
using __gnu_test::tracker_allocator;
using __gnu_test::copy_constructor;
using __gnu_test::assignment_operator;
using __gnu_test::counter;
@ -445,11 +445,11 @@ test_default_ctor_exception_safety()
{
// setup
typedef copy_tracker T;
typedef std::deque<T, tracker_alloc<T> > X;
typedef std::deque<T, tracker_allocator<T> > X;
T::reset();
copy_constructor::throw_on(3);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// test
try
@ -462,7 +462,7 @@ test_default_ctor_exception_safety()
}
// assert postconditions
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
}
@ -473,9 +473,9 @@ test_copy_ctor_exception_safety()
{
// setup
typedef copy_tracker T;
typedef std::deque<T, tracker_alloc<T> > X;
typedef std::deque<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(7);
T::reset();
@ -494,7 +494,7 @@ test_copy_ctor_exception_safety()
}
// assert postconditions
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
}

View File

@ -35,11 +35,11 @@ using namespace __gnu_test;
int main()
{
typedef std::list<int, tracker_alloc<int> > Container;
typedef std::list<int, tracker_allocator<int> > Container;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c;
ok = check_construct_destroy("empty container", 0, 0) && ok;
@ -47,7 +47,7 @@ int main()
ok = check_construct_destroy("empty container", 0, 0) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", 10, 0) && ok;
@ -56,7 +56,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin(), arr10[0]);
ok = check_construct_destroy("Insert element", 1, 0) && ok;
}
@ -64,7 +64,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
Container::iterator i5 = c.begin();
std::advance(i5, 5);
c.insert(i5, arr10, arr10+3);
@ -74,7 +74,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
Container::iterator i7 = c.begin();
std::advance(i7, 5);
c.insert(i7, arr10, arr10+10);

View File

@ -36,12 +36,12 @@ using namespace __gnu_test;
int main()
{
typedef std::set<int, std::less<int>, tracker_alloc<int> > Container;
typedef std::set<int, std::less<int>, tracker_allocator<int> > Container;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
const int arr10a[10] = { 31, 23, 82, 46, 13, 17, 30, 71, 22, 51 };
bool ok = true;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c;
ok = check_construct_destroy("empty container", 0, 0) && ok;
@ -49,7 +49,7 @@ int main()
ok = check_construct_destroy("empty container", 0, 0) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", 10, 0) && ok;
@ -58,7 +58,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(arr10a[0]);
ok = check_construct_destroy("Insert element", 1, 0) && ok;
}
@ -66,7 +66,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(arr10a, arr10a+3);
ok = check_construct_destroy("Insert short range", 3, 0) && ok;
}
@ -74,7 +74,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(arr10a, arr10a+10);
ok = check_construct_destroy("Insert long range", 10, 0) && ok;
}

View File

@ -27,8 +27,8 @@
#include <testsuite_hooks.h>
using __gnu_test::copy_tracker;
using __gnu_test::allocation_tracker;
using __gnu_test::tracker_alloc;
using __gnu_test::tracker_allocator_counter;
using __gnu_test::tracker_allocator;
using __gnu_test::copy_constructor;
using __gnu_test::assignment_operator;
using __gnu_test::destructor;
@ -39,9 +39,9 @@ test_reserve()
{
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(3);
const X::size_type old_size = a.size();
@ -59,7 +59,7 @@ test_reserve()
VERIFY(destructor::count() <= old_size);
}
// check for memory leaks
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
}
// Verifies that reserve() with reallocation offers the strong
@ -69,9 +69,9 @@ test_reserve_exception_guarantee()
{
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(7);
const X::size_type old_size __attribute__((unused)) = a.size();
@ -92,7 +92,7 @@ test_reserve_exception_guarantee()
VERIFY(old_capacity == a.capacity());
VERIFY(copy_constructor::count() == destructor::count()+1);
}
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
}
int main()

View File

@ -34,11 +34,11 @@ using namespace __gnu_test;
int main()
{
typedef std::vector<int, tracker_alloc<int> > Container;
typedef std::vector<int, tracker_allocator<int> > Container;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c;
ok = check_construct_destroy("empty container", 0, 0) && ok;
@ -46,7 +46,7 @@ int main()
ok = check_construct_destroy("empty container", 0, 0) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", 10, 0) && ok;
@ -56,7 +56,7 @@ int main()
{
Container c(arr10, arr10 + 10);
c.reserve(100);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin(), arr10[0]);
ok = check_construct_destroy("Insert element", 1, 0) && ok;
}
@ -65,7 +65,7 @@ int main()
{
Container c(arr10, arr10 + 10);
c.reserve(100);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin() + 5, arr10, arr10+3);
ok = check_construct_destroy("Insert short range", 3, 0) && ok;
}
@ -74,7 +74,7 @@ int main()
{
Container c(arr10, arr10 + 10);
c.reserve(100);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin() + 7, arr10, arr10+10);
ok = check_construct_destroy("Insert long range", 10, 0) && ok;
}

View File

@ -26,8 +26,8 @@
#include <testsuite_hooks.h>
using __gnu_test::copy_tracker;
using __gnu_test::allocation_tracker;
using __gnu_test::tracker_alloc;
using __gnu_test::tracker_allocator_counter;
using __gnu_test::tracker_allocator;
using __gnu_test::copy_constructor;
using __gnu_test::assignment_operator;
@ -42,11 +42,11 @@ test_default_ctor_exception_gurantee()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
copy_tracker::reset();
copy_constructor::throw_on(3);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// run test
try
@ -59,7 +59,7 @@ test_default_ctor_exception_gurantee()
}
// assert postconditions
VERIFY( allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal() );
VERIFY( tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count() );
// teardown
}
@ -74,9 +74,9 @@ test_copy_ctor_exception_gurantee()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(7);
copy_tracker::reset();
@ -94,11 +94,11 @@ test_copy_ctor_exception_gurantee()
}
// assert postconditions
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
// operator=()
@ -113,12 +113,12 @@ test_assignment_operator_1()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
X r(9);
X a(r.size() - 2);
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// preconditions
VERIFY(r.size() > a.size());
@ -128,11 +128,11 @@ test_assignment_operator_1()
// assert postconditions
VERIFY(r == a);
VERIFY(allocation_tracker::allocationTotal() == 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -141,13 +141,13 @@ test_assignment_operator_2()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
X r(1);
r.reserve(17);
X a(r.size() + 7);
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// preconditions
VERIFY(r.size() < a.size());
@ -158,11 +158,11 @@ test_assignment_operator_2()
// assert postconditions
VERIFY(r == a);
VERIFY(allocation_tracker::allocationTotal() == 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -171,9 +171,9 @@ test_assignment_operator_3()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X r(1);
X a(r.capacity() + 7);
@ -188,11 +188,11 @@ test_assignment_operator_3()
// assert postconditions
VERIFY(r == a);
}
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -201,9 +201,9 @@ test_assignment_operator_3_exception_guarantee()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X r(1);
X a(r.capacity() + 7);
@ -225,11 +225,11 @@ test_assignment_operator_3_exception_guarantee()
}
// assert postconditions
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
// fill assign()
@ -246,7 +246,7 @@ test_fill_assign_1()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
X a(7);
X::size_type old_size = a.size();
@ -254,18 +254,18 @@ test_fill_assign_1()
const T t;
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// run test
a.assign(new_size, t);
// assert postconditions
VERIFY(a.size() == new_size);
VERIFY(allocation_tracker::allocationTotal() == 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -274,7 +274,7 @@ test_fill_assign_2()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
X a(7);
a.reserve(11);
@ -284,7 +284,7 @@ test_fill_assign_2()
const T t;
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// assert preconditions
VERIFY(old_size < new_size);
@ -295,11 +295,11 @@ test_fill_assign_2()
// assert postconditions
VERIFY(a.size() == new_size);
VERIFY(allocation_tracker::allocationTotal() == 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -308,9 +308,9 @@ test_fill_assign_3()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(7);
X::size_type old_capacity = a.capacity();
@ -329,12 +329,12 @@ test_fill_assign_3()
VERIFY(a.size() == new_size);
}
VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -343,9 +343,9 @@ test_fill_assign_3_exception_guarantee()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(7);
X::size_type old_size = a.size();
@ -374,12 +374,12 @@ test_fill_assign_3_exception_guarantee()
VERIFY(a.capacity() == old_capacity);
}
VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -388,7 +388,7 @@ test_fill_assign_4()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
X a(7);
X::size_type old_size = a.size();
@ -396,18 +396,18 @@ test_fill_assign_4()
X::size_type new_value = 117;
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// run test
a.assign(new_size, new_value);
// assert postconditions
VERIFY(a.size() == new_size);
VERIFY(allocation_tracker::allocationTotal() == 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
// range assign()
@ -432,13 +432,13 @@ test_range_assign_2()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
X a(7);
X b(3);
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// assert preconditions
VERIFY(b.size() < a.capacity());
@ -449,11 +449,11 @@ test_range_assign_2()
// assert postconditions
VERIFY(a.size() == b.size());
VERIFY(a == b);
VERIFY(allocation_tracker::allocationTotal() == 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -462,14 +462,14 @@ test_range_assign_3()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
X a(7);
a.reserve(a.size() + 7);
X b(a.size() + 3);
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
// assert preconditions
VERIFY(a.size() < b.size());
@ -481,11 +481,11 @@ test_range_assign_3()
// assert postconditions
VERIFY(a.size() == b.size());
VERIFY(a == b);
VERIFY(allocation_tracker::allocationTotal() == 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -494,9 +494,9 @@ test_range_assign_4()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(7);
X b(a.capacity() + 7);
@ -513,12 +513,12 @@ test_range_assign_4()
VERIFY(a.size() == b.size());
VERIFY(a == b);
}
VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}
void
@ -527,9 +527,9 @@ test_range_assign_4_exception_guarantee()
// setup
bool test __attribute__((unused)) = true;
typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
typedef std::vector<T, tracker_allocator<T> > X;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
X a(7);
X b(a.capacity() + 7);
@ -552,12 +552,12 @@ test_range_assign_4_exception_guarantee()
}
// assert postconditions
VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
// teardown
copy_tracker::reset();
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
}

View File

@ -31,7 +31,7 @@
namespace std
{
using __gnu_test::pod_char;
typedef __gnu_test::tracker_alloc<char> alloc_type;
typedef __gnu_test::tracker_allocator<char> alloc_type;
template class basic_stringbuf<char, char_traits<char>, alloc_type>;
} // test

View File

@ -37,7 +37,7 @@ using namespace __gnu_test;
int main()
{
typedef __gnu_cxx::hash_set<int, __gnu_cxx::hash<int>, std::equal_to<int>,
tracker_alloc<int> >
tracker_allocator<int> >
Container;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
@ -46,7 +46,7 @@ int main()
int buckets;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c;
buckets = c.bucket_count();
@ -55,14 +55,14 @@ int main()
ok = check_construct_destroy("empty container", buckets, buckets) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", buckets+10, 0) && ok;
}
ok = check_construct_destroy("Construct from range", buckets+10, buckets+10) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
c.insert(arr10a[0]);
@ -70,7 +70,7 @@ int main()
}
ok = check_construct_destroy("Insert element", buckets+11, buckets+11) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
c.insert(arr10a, arr10a+3);
@ -78,7 +78,7 @@ int main()
}
ok = check_construct_destroy("Insert short range", buckets+13, buckets+13) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
c.insert(arr10a, arr10a+10);

View File

@ -35,11 +35,11 @@ using namespace __gnu_test;
int main()
{
typedef __gnu_cxx::slist<int, tracker_alloc<int> > Container;
typedef __gnu_cxx::slist<int, tracker_allocator<int> > Container;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c;
ok = check_construct_destroy("empty container", 0, 0) && ok;
@ -47,7 +47,7 @@ int main()
ok = check_construct_destroy("empty container", 0, 0) && ok;
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
{
Container c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", 10, 0) && ok;
@ -56,7 +56,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
c.insert(c.begin(), arr10[0]);
ok = check_construct_destroy("Insert element", 1, 0) && ok;
}
@ -64,7 +64,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
Container::iterator i5 = c.begin();
std::advance(i5, 5);
c.insert(i5, arr10, arr10+3);
@ -74,7 +74,7 @@ int main()
{
Container c(arr10, arr10 + 10);
allocation_tracker::resetCounts();
tracker_allocator_counter::reset();
Container::iterator i7 = c.begin();
std::advance(i7, 5);
c.insert(i7, arr10, arr10+10);

View File

@ -45,12 +45,12 @@
*/
#include <ext/typelist.h>
#include <testsuite_allocator.h>
#include <performance/io/xml_formatter.hpp>
#include <io/verified_cmd_line_input.hpp>
#include <rng/twister_rand_gen.hpp>
#include <common_type/assoc/common_type.hpp>
#include <performance/assoc/mem_usage/erase_test.hpp>
#include <performance/mem/mem_track_allocator.hpp>
#include <iostream>
#include <vector>
#include <functional>
@ -85,7 +85,7 @@ main(int argc, char* a_p_argv[])
vec_t::const_iterator b = a_v.begin();
erase_test<vec_t::const_iterator> tst(b, vn, vs, vm);
typedef mem_track_allocator<char> alloc_t;
typedef __gnu_test::tracker_allocator<char> alloc_t;
{
typedef hash_common_types<int, pb_ds::null_mapped_type, int_hash, std::equal_to<int>, alloc_t>::performance_tl tl_t;

View File

@ -44,7 +44,10 @@
* Contains test for inserting text words.
*/
#include <iostream>
#include <vector>
#include <ext/typelist.h>
#include <testsuite_allocator.h>
#include <io/text_populate.hpp>
#include <performance/io/xml_formatter.hpp>
#include <native_type/assoc/native_hash_multimap.hpp>
@ -54,10 +57,7 @@
#include <common_type/assoc/common_type.hpp>
#include <performance/assoc/mem_usage/multimap_insert_test.hpp>
#include <performance/assoc/multimap_common_type.hpp>
#include <performance/mem/mem_track_allocator.hpp>
#include <hash_fn/string_hash_fn.hpp>
#include <iostream>
#include <vector>
void
usage();
@ -86,7 +86,7 @@ main(int argc, char* a_p_argv[])
init_vec_t a_v_init(prm);
distinct_text_populate(f_name, a_v_init);
typedef mem_track_allocator<char> alloc_t;
typedef __gnu_test::tracker_allocator<char> alloc_t;
typedef std::basic_string<char, std::char_traits<char>, alloc_t> string_t;
typedef std::vector<std::pair<string_t, int> > vec_t;
vec_t a_v;

View File

@ -44,16 +44,16 @@
* Contains test for finding text.
*/
#include <iostream>
#include <vector>
#include <ext/typelist.h>
#include <testsuite_allocator.h>
#include <performance/io/xml_formatter.hpp>
#include <io/verified_cmd_line_input.hpp>
#include <common_type/priority_queue/common_type.hpp>
#include <performance/priority_queue/mem_usage/pop_test.hpp>
#include <io/text_populate.hpp>
#include <native_type/priority_queue/native_priority_queue.hpp>
#include <performance/mem/mem_track_allocator.hpp>
#include <iostream>
#include <vector>
void
usage();
@ -70,10 +70,11 @@ main(int argc, char* a_p_argv[])
try
{
xml_test_performance_formatter fmt("Size", "Memory (bytes)");
typedef __gnu_test::tracker_allocator<char> callocator_type;
typedef __gnu_test::tracker_allocator<char> sallocator_type;
typedef std::basic_string<char, std::char_traits<char>, callocator_type> string_t;
typedef std::basic_string<char, std::char_traits<char>, mem_track_allocator<char> > string_t;
typedef std::vector<std::pair< string_t, char> > vec_t;
typedef std::vector<std::pair<string_t, char> > vec_t;
vec_t a_v(vm);
text_populate(f_name, a_v);
@ -81,18 +82,18 @@ main(int argc, char* a_p_argv[])
vec_t::const_iterator b = a_v.begin();
test_t tst(b, vn, vs, vm);
{
typedef pq_common_types<string_t, std::less<string_t>, mem_track_allocator<char> >::performance_tl pq_tl_t;
typedef pq_common_types<string_t, std::less<string_t>, callocator_type>::performance_tl pq_tl_t;
pq_tl_t tl;
__gnu_cxx::typelist::apply(tst, tl);
}
{
typedef native_priority_queue<string_t, true, std::less<string_t>, mem_track_allocator<string_t> > native_pq_t;
typedef native_priority_queue<string_t, true, std::less<string_t>, sallocator_type> native_pq_t;
tst(native_pq_t());
}
{
typedef native_priority_queue<string_t, false, std::less<string_t>, mem_track_allocator<string_t> > native_pq_t;
typedef native_priority_queue<string_t, false, std::less<string_t>, sallocator_type> native_pq_t;
tst(native_pq_t());
}
}

View File

@ -47,11 +47,11 @@
#ifndef PB_DS_ERASE_TEST_HPP
#define PB_DS_ERASE_TEST_HPP
#include <iterator>
#include <testsuite_allocator.h>
#include <ext/pb_ds/detail/type_utils.hpp>
#include <performance/mem/mem_track_allocator.hpp>
#include <performance/io/xml_formatter.hpp>
#include <common_type/assoc/string_form.hpp>
#include <iterator>
namespace pb_ds
{
@ -96,14 +96,14 @@ namespace pb_ds
It ins_it_e = m_ins_b;
std::advance(ins_it_e, ins_size);
mem_track_allocator<char> alloc;
const size_t init_mem = alloc.get_total();
__gnu_test::tracker_allocator<char> alloc;
const size_t init_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
Cntnr cntnr(ins_it_b, ins_it_e);
while (cntnr.size() > 1)
cntnr.erase(*cntnr.begin());
const size_t final_mem = alloc.get_total();
const size_t final_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
assert(final_mem > init_mem);
const size_t delta_mem = final_mem - init_mem;
res_set_fmt.add_res(ins_size, static_cast<double>(delta_mem));

View File

@ -47,11 +47,11 @@
#ifndef PB_DS_MULTIMAP_INSERT_TEST_HPP
#define PB_DS_MULTIMAP_INSERT_TEST_HPP
#include <iterator>
#include <ext/pb_ds/detail/type_utils.hpp>
#include <performance/mem/mem_track_allocator.hpp>
#include <testsuite_allocator.h>
#include <performance/io/xml_formatter.hpp>
#include <common_type/assoc/string_form.hpp>
#include <iterator>
namespace pb_ds
{
@ -116,12 +116,12 @@ namespace pb_ds
multimap_insert_test<It, Native>::
insert(Cntnr, It ins_it_b, It ins_it_e, pb_ds::detail::true_type)
{
mem_track_allocator<char> alloc;
const size_t init_mem = alloc.get_total();
__gnu_test::tracker_allocator<char> alloc;
const size_t init_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
Cntnr cntnr;
for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
cntnr.insert((typename Cntnr::const_reference)(*ins_it));
const size_t final_mem = alloc.get_total();
const size_t final_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
assert(final_mem > init_mem);
return (final_mem - init_mem);
}
@ -132,12 +132,12 @@ namespace pb_ds
multimap_insert_test<It, Native>::
insert(Cntnr, It ins_it_b, It ins_it_e, pb_ds::detail::false_type)
{
mem_track_allocator<char> alloc;
const size_t init_mem = alloc.get_total();
__gnu_test::tracker_allocator<char> alloc;
const size_t init_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
Cntnr cntnr;
for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
cntnr[ins_it->first].insert(ins_it->second);
const size_t final_mem = alloc.get_total();
const size_t final_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
assert(final_mem > init_mem);
return (final_mem - init_mem);
}

View File

@ -1,189 +0,0 @@
// -*- C++ -*-
// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software
// Foundation; either version 2, or (at your option) any later
// version.
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, USA.
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
// Permission to use, copy, modify, sell, and distribute this software
// is hereby granted without fee, provided that the above copyright
// notice appears in all copies, and that both that copyright notice
// and this permission notice appear in supporting documentation. None
// of the above authors, nor IBM Haifa Research Laboratories, make any
// representation about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
/**
* @file mem_track_allocator.hpp
* Contains a memory-tracking allocator used for tests.
*/
#ifndef PB_DS_MEM_TRACK_ALLOCATOR_HPP
#define PB_DS_MEM_TRACK_ALLOCATOR_HPP
#include <performance/mem/mem_track_allocator_base.hpp>
namespace pb_ds
{
namespace test
{
#define PB_DS_CLASS_T_DEC \
template<typename T>
#define PB_DS_CLASS_C_DEC \
mem_track_allocator< \
T>
template<typename T>
class mem_track_allocator : public detail::mem_track_allocator_base
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template<typename U>
struct rebind
{
typedef mem_track_allocator<U> other;
};
mem_track_allocator() throw();
mem_track_allocator(const PB_DS_CLASS_C_DEC& ) throw();
template <class U>
mem_track_allocator(const mem_track_allocator<U>& ) throw();
~mem_track_allocator() throw();
size_type
max_size() const throw();
pointer
allocate(size_type num, std::allocator<void>::const_pointer hint = 0);
void
construct(pointer p, const T& r_val);
void
destroy(pointer p);
void
deallocate(pointer p, size_type num);
};
PB_DS_CLASS_T_DEC
bool
operator==(const PB_DS_CLASS_C_DEC& , const PB_DS_CLASS_C_DEC& )
{
return true;
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
mem_track_allocator() throw()
{ }
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
mem_track_allocator(const PB_DS_CLASS_C_DEC& ) throw()
{ }
PB_DS_CLASS_T_DEC
template<typename U>
PB_DS_CLASS_C_DEC::
mem_track_allocator(const mem_track_allocator<U>& ) throw()
{ }
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
~mem_track_allocator() throw()
{ }
PB_DS_CLASS_T_DEC
typename PB_DS_CLASS_C_DEC::size_type
PB_DS_CLASS_C_DEC::
max_size() const throw()
{
return (std::allocator<T>().max_size());
}
PB_DS_CLASS_T_DEC
typename PB_DS_CLASS_C_DEC::pointer
PB_DS_CLASS_C_DEC::
allocate(size_type num, std::allocator<void>::const_pointer hint/*= 0*/)
{
T* const a_t = std::allocator<T>().allocate(num, hint);
inc(sizeof(T)* num);
return (a_t);
}
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
construct(pointer p, const T& r_val)
{
return (std::allocator<T>().construct(p, r_val));
}
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
destroy(pointer p)
{
std::allocator<T>().destroy(p);
}
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
deallocate(pointer p, size_type num)
{
std::allocator<T>().deallocate(p, num);
dec(sizeof(T)* num);
}
#undef PB_DS_CLASS_T_DEC
#undef PB_DS_CLASS_C_DEC
} // namespace test
} // namespace pb_ds
#endif // #ifndef PB_DS_MEM_TRACK_ALLOCATOR_HPP

View File

@ -1,116 +0,0 @@
// -*- C++ -*-
// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software
// Foundation; either version 2, or (at your option) any later
// version.
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, USA.
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
// Permission to use, copy, modify, sell, and distribute this software
// is hereby granted without fee, provided that the above copyright
// notice appears in all copies, and that both that copyright notice
// and this permission notice appear in supporting documentation. None
// of the above authors, nor IBM Haifa Research Laboratories, make any
// representation about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
/**
* @file mem_track_allocator_base.hpp
* Contains a base for a memory-tracking allocator used for tests.
*/
#ifndef PB_DS_MEM_TRACK_ALLOCATOR_BASE_HPP
#define PB_DS_MEM_TRACK_ALLOCATOR_BASE_HPP
#include <cassert>
namespace pb_ds
{
namespace test
{
namespace detail
{
struct total_holder
{
total_holder() : m_total(0)
{ }
size_t m_total;
};
class mem_track_allocator_base
{
public:
static void
inc(size_t size);
static void
dec(size_t size);
static size_t
get_total();
private:
static total_holder s_total_holder;
};
total_holder mem_track_allocator_base::s_total_holder;
void
mem_track_allocator_base::
inc(size_t size)
{
s_total_holder.m_total += size;
}
void
mem_track_allocator_base::
dec(size_t size)
{
assert(s_total_holder.m_total >= size);
s_total_holder.m_total -= size;
}
size_t
mem_track_allocator_base::
get_total()
{
return (s_total_holder.m_total);
}
} // namespace detail
} // namespace test
} // namespace pb_ds
#endif // #ifndef PB_DS_MEM_TRACK_ALLOCATOR_BASE_HPP

View File

@ -47,11 +47,11 @@
#ifndef PB_DS_POP_TEST_HPP
#define PB_DS_POP_TEST_HPP
#include <iterator>
#include <testsuite_allocator.h>
#include <ext/pb_ds/detail/type_utils.hpp>
#include <performance/mem/mem_track_allocator.hpp>
#include <performance/io/xml_formatter.hpp>
#include <common_type/priority_queue/string_form.hpp>
#include <iterator>
namespace pb_ds
{
@ -95,9 +95,9 @@ namespace pb_ds
It ins_it_e = m_ins_b;
std::advance(ins_it_e, ins_size);
mem_track_allocator<char> alloc;
__gnu_test::tracker_allocator<char> alloc;
const size_t init_mem = alloc.get_total();
const size_t init_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
Cntnr cntnr;
for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
cntnr.push(ins_it->first);
@ -105,7 +105,7 @@ namespace pb_ds
while (cntnr.size() > 1)
cntnr.pop();
const size_t final_mem = alloc.get_total();
const size_t final_mem = alloc.get_allocation_count() - alloc.get_deallocation_count();
assert(final_mem > init_mem);
const size_t delta_mem = final_mem - init_mem;
res_set_fmt.add_res(ins_size, static_cast<double>(delta_mem));

View File

@ -33,28 +33,33 @@
namespace __gnu_test
{
allocation_tracker::size_type allocation_tracker::allocationTotal_ = 0;
allocation_tracker::size_type allocation_tracker::deallocationTotal_ = 0;
int allocation_tracker::constructCount_ = 0;
int allocation_tracker::destructCount_ = 0;
typedef tracker_allocator_counter counter_type;
counter_type::size_type
counter_type::allocationCount_ = 0;
counter_type::size_type
counter_type::deallocationCount_ = 0;
int counter_type::constructCount_ = 0;
int counter_type::destructCount_ = 0;
bool
check_construct_destroy(const char* tag, int expected_c, int expected_d)
{
if (allocation_tracker::constructCount() == expected_c &&
allocation_tracker::destructCount() == expected_d)
return true;
else {
std::cerr << tag << ": "
<< " construct = " << allocation_tracker::constructCount()
<< " (should be " << expected_c << "),"
<< " destroy = " << allocation_tracker::destructCount()
<< " (should be " << expected_d << ")"
<< std::endl;
return false;
}
bool ret = true;
if (counter_type::get_construct_count() != expected_c
|| counter_type::get_destruct_count() != expected_d)
{
std::cerr << tag << ": "
<< " construct = " << counter_type::get_construct_count()
<< " (should be " << expected_c << "),"
<< " destroy = " << counter_type::get_destruct_count()
<< " (should be " << expected_d << ")"
<< std::endl;
ret = false;
}
return ret;
}
}; // namespace __cxx_test

View File

@ -36,7 +36,6 @@
#define _GLIBCXX_TESTSUITE_ALLOCATOR_H
#include <cstddef>
#include <limits>
#include <tr1/unordered_map>
#include <cassert>
@ -48,7 +47,7 @@ namespace
namespace __gnu_test
{
class allocation_tracker
class tracker_allocator_counter
{
public:
typedef std::size_t size_type;
@ -56,7 +55,7 @@ namespace __gnu_test
static void*
allocate(size_type blocksize)
{
allocationTotal_ += blocksize;
allocationCount_ += blocksize;
return ::operator new(blocksize);
}
@ -70,43 +69,46 @@ namespace __gnu_test
deallocate(void* p, size_type blocksize)
{
::operator delete(p);
deallocationTotal_ += blocksize;
deallocationCount_ += blocksize;
}
static size_type
allocationTotal() { return allocationTotal_; }
get_allocation_count() { return allocationCount_; }
static size_type
deallocationTotal() { return deallocationTotal_; }
get_deallocation_count() { return deallocationCount_; }
static int
constructCount() { return constructCount_; }
get_construct_count() { return constructCount_; }
static int
destructCount() { return destructCount_; }
get_destruct_count() { return destructCount_; }
static void
resetCounts()
reset()
{
allocationTotal_ = 0;
deallocationTotal_ = 0;
allocationCount_ = 0;
deallocationCount_ = 0;
constructCount_ = 0;
destructCount_ = 0;
destructCount_ = 0;
}
private:
static size_type allocationTotal_;
static size_type deallocationTotal_;
static size_type allocationCount_;
static size_type deallocationCount_;
static int constructCount_;
static int destructCount_;
};
// A simple basic allocator that just forwards to the
// allocation_tracker to fulfill memory requests. This class is
// templated on the target object type, but tracker isn't.
// tracker_allocator_counter to fulfill memory requests. This class
// is templated on the target object type, but tracker isn't.
template<class T>
class tracker_alloc
class tracker_allocator
{
private:
typedef tracker_allocator_counter counter_type;
public:
typedef T value_type;
typedef T* pointer;
@ -116,7 +118,7 @@ namespace __gnu_test
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
template<class U> struct rebind { typedef tracker_alloc<U> other; };
template<class U> struct rebind { typedef tracker_allocator<U> other; };
pointer
address(reference value) const
@ -126,56 +128,56 @@ namespace __gnu_test
address(const_reference value) const
{ return &value; }
tracker_alloc() throw()
tracker_allocator() throw()
{ }
tracker_alloc(const tracker_alloc&) throw()
tracker_allocator(const tracker_allocator&) throw()
{ }
template<class U>
tracker_alloc(const tracker_alloc<U>&) throw()
tracker_allocator(const tracker_allocator<U>&) throw()
{ }
~tracker_alloc() throw()
~tracker_allocator() throw()
{ }
size_type
max_size() const throw()
{ return std::numeric_limits<std::size_t>::max() / sizeof(T); }
{ return size_type(-1) / sizeof(T); }
pointer
allocate(size_type n, const void* = 0)
{
return static_cast<pointer>(allocation_tracker::allocate(n * sizeof(T)));
}
{ return static_cast<pointer>(counter_type::allocate(n * sizeof(T))); }
void
construct(pointer p, const T& value)
{
new (p) T(value);
allocation_tracker::construct();
counter_type::construct();
}
void
destroy(pointer p)
{
p->~T();
allocation_tracker::destroy();
counter_type::destroy();
}
void
deallocate(pointer p, size_type num)
{ allocation_tracker::deallocate(p, num * sizeof(T)); }
{ counter_type::deallocate(p, num * sizeof(T)); }
};
template<class T1, class T2>
bool
operator==(const tracker_alloc<T1>&, const tracker_alloc<T2>&) throw()
operator==(const tracker_allocator<T1>&,
const tracker_allocator<T2>&) throw()
{ return true; }
template<class T1, class T2>
bool
operator!=(const tracker_alloc<T1>&, const tracker_alloc<T2>&) throw()
operator!=(const tracker_allocator<T1>&,
const tracker_allocator<T2>&) throw()
{ return false; }
bool
@ -331,7 +333,7 @@ namespace __gnu_test
size_type
max_size() const throw()
{ return size_t(-1) / sizeof(Tp); }
{ return size_type(-1) / sizeof(Tp); }
void
construct(pointer p, const Tp& val)