summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities/memory/default.allocator
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2014-12-22 22:38:59 +0000
committerEric Fiselier <eric@efcs.ca>2014-12-22 22:38:59 +0000
commit2cbc654d93bc9f1f3e6dd59166c7e1f8750738d1 (patch)
treeab539fa3fe99f12333428aa427c6c41cdf28e5e7 /libcxx/test/std/utilities/memory/default.allocator
parentbad65c3b708accec8c6e85346dabc7967cb3d7ca (diff)
downloadbcm5719-llvm-2cbc654d93bc9f1f3e6dd59166c7e1f8750738d1.tar.gz
bcm5719-llvm-2cbc654d93bc9f1f3e6dd59166c7e1f8750738d1.zip
[libcxx] Consolidate new/delete replacement in tests and disable it when using sanitizers.
Summary: MSAN and ASAN also replace new/delete which leads to a link error in these tests. Currently they are unsupported but I think it would be useful if these tests could run with sanitizers. This patch creates a support header that consolidates the new/delete replacement functionality and checking. When we are using sanitizers new and delete are no longer replaced and the checks always return true. Reviewers: mclow.lists, danalbert, jroelofs, EricWF Reviewed By: EricWF Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6562 llvm-svn: 224741
Diffstat (limited to 'libcxx/test/std/utilities/memory/default.allocator')
-rw-r--r--libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp33
-rw-r--r--libcxx/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp59
2 files changed, 33 insertions, 59 deletions
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
index a4a84e877dc..253515e3db3 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
@@ -12,27 +12,10 @@
// allocator:
// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
-// UNSUPPORTED: asan, msan
-
#include <memory>
-#include <new>
-#include <cstdlib>
#include <cassert>
-int new_called = 0;
-
-void* operator new(std::size_t s) throw(std::bad_alloc)
-{
- ++new_called;
- assert(s == 3 * sizeof(int));
- return std::malloc(s);
-}
-
-void operator delete(void* p) throw()
-{
- --new_called;
- std::free(p);
-}
+#include "count_new.hpp"
int A_constructed = 0;
@@ -47,19 +30,23 @@ struct A
int main()
{
std::allocator<A> a;
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A_constructed == 0);
+ globalMemCounter.last_new_size = 0;
A* ap = a.allocate(3);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
assert(A_constructed == 0);
a.deallocate(ap, 3);
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A_constructed == 0);
+ globalMemCounter.last_new_size = 0;
A* ap2 = a.allocate(3, (const void*)5);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
assert(A_constructed == 0);
a.deallocate(ap2, 3);
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A_constructed == 0);
}
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp
index b9a174973f2..d0a870e6069 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp
@@ -12,27 +12,10 @@
// allocator:
// template <class... Args> void construct(pointer p, Args&&... args);
-// UNSUPPORTED: asan, msan
-
#include <memory>
-#include <new>
-#include <cstdlib>
#include <cassert>
-int new_called = 0;
-
-void* operator new(std::size_t s) throw(std::bad_alloc)
-{
- ++new_called;
- assert(s == 3 * sizeof(int));
- return std::malloc(s);
-}
-
-void operator delete(void* p) throw()
-{
- --new_called;
- std::free(p);
-}
+#include "count_new.hpp"
int A_constructed = 0;
@@ -80,76 +63,80 @@ int main()
{
{
std::allocator<A> a;
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A_constructed == 0);
+ globalMemCounter.last_new_size = 0;
A* ap = a.allocate(3);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
assert(A_constructed == 0);
a.construct(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 1);
a.destroy(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 0);
a.construct(ap, A());
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 1);
a.destroy(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 0);
a.construct(ap, 5);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 1);
a.destroy(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 0);
a.construct(ap, 5, (int*)0);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 1);
a.destroy(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(A_constructed == 0);
a.deallocate(ap, 3);
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A_constructed == 0);
}
{
std::allocator<move_only> a;
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
assert(move_only_constructed == 0);
+ globalMemCounter.last_new_size = 0;
move_only* ap = a.allocate(3);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
+ assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
assert(move_only_constructed == 0);
a.construct(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(move_only_constructed == 1);
a.destroy(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(move_only_constructed == 0);
a.construct(ap, move_only());
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(move_only_constructed == 1);
a.destroy(ap);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
assert(move_only_constructed == 0);
a.deallocate(ap, 3);
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
assert(move_only_constructed == 0);
}
}
OpenPOWER on IntegriCloud