[libcxx-commits] [libcxx] 4a79296 - Move more tests to globalMemCounter and reset.
Dan Albert via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 12 17:26:45 PDT 2020
Author: Dan Albert
Date: 2020-03-12T17:26:31-07:00
New Revision: 4a792965de08fb69652370625f1aec2e87111313
URL: https://github.com/llvm/llvm-project/commit/4a792965de08fb69652370625f1aec2e87111313
DIFF: https://github.com/llvm/llvm-project/commit/4a792965de08fb69652370625f1aec2e87111313.diff
LOG: Move more tests to globalMemCounter and reset.
Summary:
Android's libc uses new/delete internally and these are counted, so
the counter needs to be reset to zero at the start of the test.
Reviewers: EricWF, mclow.lists, #libc, ldionne
Reviewed By: #libc, ldionne
Subscribers: dexonsmith, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D76091
Added:
Modified:
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
index 4d90aa9a3fe0..8d7349202673 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
@@ -17,24 +17,9 @@
#include <cassert>
#include <limits>
+#include "count_new.h"
#include "test_macros.h"
-int new_called = 0;
-
-void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
-{
- ++new_called;
- void* ret = std::malloc(s);
- if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
- return ret;
-}
-
-void operator delete(void* p) TEST_NOEXCEPT
-{
- --new_called;
- std::free(p);
-}
-
int A_constructed = 0;
struct A
@@ -45,15 +30,17 @@ struct A
int main(int, char**)
{
+ globalMemCounter.reset();
+ assert(globalMemCounter.checkOutstandingNewEq(0));
A *ap = new (std::nothrow) A[3];
DoNotOptimize(ap);
assert(ap);
assert(A_constructed == 3);
- assert(new_called);
+ assert(globalMemCounter.checkOutstandingNewNotEq(0));
delete [] ap;
DoNotOptimize(ap);
assert(A_constructed == 0);
- assert(!new_called);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
return 0;
}
diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
index e705fc3b499f..cbe6577747ea 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
@@ -18,24 +18,9 @@
#include <cassert>
#include <limits>
+#include "count_new.h"
#include "test_macros.h"
-int new_called = 0;
-
-void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
-{
- ++new_called;
- void* ret = std::malloc(s);
- if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
- return ret;
-}
-
-void operator delete(void* p) TEST_NOEXCEPT
-{
- --new_called;
- std::free(p);
-}
-
int A_constructed = 0;
struct A
@@ -46,15 +31,17 @@ struct A
int main(int, char**)
{
+ globalMemCounter.reset();
+ assert(globalMemCounter.checkOutstandingNewEq(0));
A *ap = new A[3];
DoNotOptimize(ap);
assert(ap);
assert(A_constructed == 3);
- assert(new_called == 1);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
delete [] ap;
DoNotOptimize(ap);
assert(A_constructed == 0);
- assert(new_called == 0);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
return 0;
}
diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
index 1f186d8b3d17..daaf21c1847c 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
@@ -17,24 +17,9 @@
#include <cassert>
#include <limits>
+#include "count_new.h"
#include "test_macros.h"
-int new_called = 0;
-
-void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
-{
- ++new_called;
- void* ret = std::malloc(s);
- if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
- return ret;
-}
-
-void operator delete(void* p) TEST_NOEXCEPT
-{
- --new_called;
- std::free(p);
-}
-
bool A_constructed = false;
struct A
@@ -45,15 +30,17 @@ struct A
int main(int, char**)
{
+ globalMemCounter.reset();
+ assert(globalMemCounter.checkOutstandingNewEq(0));
A *ap = new (std::nothrow) A;
DoNotOptimize(ap);
assert(ap);
assert(A_constructed);
- assert(new_called);
+ assert(globalMemCounter.checkOutstandingNewNotEq(0));
delete ap;
DoNotOptimize(ap);
assert(!A_constructed);
- assert(!new_called);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
return 0;
}
diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
index 4854c2fb7761..f02e4a6e01f9 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
@@ -16,24 +16,9 @@
#include <cassert>
#include <limits>
+#include "count_new.h"
#include "test_macros.h"
-int new_called = 0;
-
-void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
-{
- ++new_called;
- void* ret = std::malloc(s);
- if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
- return ret;
-}
-
-void operator delete(void* p) TEST_NOEXCEPT
-{
- --new_called;
- std::free(p);
-}
-
bool A_constructed = false;
struct A
@@ -44,15 +29,17 @@ struct A
int main(int, char**)
{
+ globalMemCounter.reset();
+ assert(globalMemCounter.checkOutstandingNewEq(0));
A *ap = new A;
DoNotOptimize(ap);
assert(ap);
assert(A_constructed);
- assert(new_called);
+ assert(globalMemCounter.checkOutstandingNewEq(1));
delete ap;
DoNotOptimize(ap);
assert(!A_constructed);
- assert(!new_called);
+ assert(globalMemCounter.checkOutstandingNewEq(0));
return 0;
}
diff --git a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
index bb69ef1d2400..40f8ae299206 100644
--- a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
+++ b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
@@ -28,6 +28,7 @@
int main(int, char**)
{
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
typedef std::codecvt_utf16<wchar_t> C;
diff --git a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
index 4fc4201ee178..08f98fa2999a 100644
--- a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
+++ b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
@@ -28,6 +28,7 @@
int main(int, char**)
{
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
typedef std::codecvt_utf8<wchar_t> C;
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
index f879afb7a2f2..bf6355d17d15 100644
--- a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
@@ -23,6 +23,7 @@
int main(int, char**)
{
+ globalMemCounter.reset();
typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B;
#if TEST_STD_VER > 11
static_assert(!std::is_convertible<std::streambuf*, B>::value, "");
diff --git a/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp b/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
index 68c0438abb7c..8a908b58271c 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
@@ -66,6 +66,7 @@ std::locale::id my_facet::id;
int main(int, char**)
{
{
+ globalMemCounter.reset();
{
std::locale loc;
std::locale loc2(loc, new my_facet);
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
index cf3477ff5544..9393da08964d 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
@@ -59,6 +59,7 @@ int h(int) {return 1;}
int main(int, char**)
{
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f1 = A(1);
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
index 5944f5900ee0..7cb220d993af 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
@@ -62,6 +62,7 @@ struct LValueCallable {
int main(int, char**)
{
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f = A();
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
index 26178551edb3..75471326b370 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
@@ -65,6 +65,7 @@ struct LValueCallable {
int main(int, char**)
{
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f;
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
index d97b699ea96a..05c52a1c2a28 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
@@ -49,6 +49,7 @@ int g2(int, int) { return 2; }
int g3(int, int, int) { return 3; }
int main(int, char**) {
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f = A();
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
index b756e7ecef92..1251e62f4bab 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
@@ -52,6 +52,7 @@ int g(int) {return 0;}
int main(int, char**)
{
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f = A();
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
index 16d9f05622d3..264b0fe7ca4e 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
@@ -50,6 +50,7 @@ int g(int) {return 0;}
int main(int, char**)
{
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f = A();
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
index f034eb71e4d7..eedba02a9c26 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
@@ -60,6 +60,7 @@ int g2(int, int) { return 2; }
int g3(int, int, int) { return 3; }
int main(int, char**) {
+ globalMemCounter.reset();
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f1 = A(1);
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
index 8dd984dcddee..e403ea6fc102 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
@@ -54,6 +54,7 @@ struct PrivateBase : private std::enable_shared_from_this<PrivateBase> {
int main(int, char**)
{
+ globalMemCounter.reset();
{ // https://bugs.llvm.org/show_bug.cgi?id=18843
std::shared_ptr<T const> t1(new T);
std::shared_ptr<T const> t2(std::make_shared<T>());
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
index 4a5ae751bc40..826862f66c74 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
@@ -37,6 +37,7 @@ int A::count = 0;
int main(int, char**)
{
+ globalMemCounter.reset();
A* ptr = new A;
globalMemCounter.throw_after = 0;
try
diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
index fd33ce9cb9ea..6506890aa353 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
@@ -37,6 +37,7 @@ int A::count = 0;
int main(int, char**)
{
+ globalMemCounter.reset();
A* ptr = new A;
assert(A::count == 1);
globalMemCounter.throw_after = 0;
More information about the libcxx-commits
mailing list