public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3401] libstdc++: Fix tests relying on operator new/delete overload
@ 2023-08-23 4:37 Francois Dumont
0 siblings, 0 replies; only message in thread
From: Francois Dumont @ 2023-08-23 4:37 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:2aa8ebc0a606c2b26a4297beb65127080f42e365
commit r14-3401-g2aa8ebc0a606c2b26a4297beb65127080f42e365
Author: François Dumont <fdumont@gcc.gnu.org>
Date: Mon Aug 21 07:02:06 2023 +0200
libstdc++: Fix tests relying on operator new/delete overload
Fix tests that are checking for an expected allocation plan. They are failing if
an allocation is taking place outside the test main.
libstdc++-v3/ChangeLog
* testsuite/util/replacement_memory_operators.h
(counter::scope): New, capture and reset counter count at construction and
restore it at destruction.
(counter::check_new): Add scope instantiation.
* testsuite/23_containers/unordered_map/96088.cc (main):
Add counter::scope instantiation.
* testsuite/23_containers/unordered_multimap/96088.cc (main): Likewise.
* testsuite/23_containers/unordered_multiset/96088.cc (main): Likewise.
* testsuite/23_containers/unordered_set/96088.cc (main): Likewise.
* testsuite/ext/malloc_allocator/deallocate_local.cc (main): Likewise.
* testsuite/ext/new_allocator/deallocate_local.cc (main): Likewise.
* testsuite/ext/throw_allocator/deallocate_local.cc (main): Likewise.
* testsuite/ext/pool_allocator/allocate_chunk.cc (started): New global.
(operator new(size_t)): Check started.
(main): Set/Unset started.
* testsuite/17_intro/no_library_allocation.cc: New test case.
Diff:
---
.../testsuite/17_intro/no_library_allocation.cc | 8 ++++++++
.../testsuite/23_containers/unordered_map/96088.cc | 1 +
.../23_containers/unordered_multimap/96088.cc | 1 +
.../23_containers/unordered_multiset/96088.cc | 1 +
.../testsuite/23_containers/unordered_set/96088.cc | 1 +
.../ext/malloc_allocator/deallocate_local.cc | 2 ++
.../ext/new_allocator/deallocate_local.cc | 2 ++
.../testsuite/ext/pool_allocator/allocate_chunk.cc | 23 ++++++++++++++++++----
.../ext/throw_allocator/deallocate_local.cc | 1 +
.../testsuite/util/replacement_memory_operators.h | 20 +++++++++++++++++++
10 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/libstdc++-v3/testsuite/17_intro/no_library_allocation.cc b/libstdc++-v3/testsuite/17_intro/no_library_allocation.cc
new file mode 100644
index 000000000000..278d4757c939
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/no_library_allocation.cc
@@ -0,0 +1,8 @@
+#include <testsuite_hooks.h>
+#include <replacement_memory_operators.h>
+
+int main()
+{
+ VERIFY( __gnu_test::counter::count() == 0 );
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
index c6d50c20fbf6..cdf00c93d80e 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
@@ -268,6 +268,7 @@ test03()
int
main()
{
+ __gnu_test::counter::scope s;
test01();
test02();
test11();
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc
index 214bc91a559a..d8b9a40c1746 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/96088.cc
@@ -61,6 +61,7 @@ test02()
int
main()
{
+ __gnu_test::counter::scope s;
test01();
test02();
return 0;
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc
index 838ce8d5bc53..db17cda0ddd8 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/96088.cc
@@ -61,6 +61,7 @@ test02()
int
main()
{
+ __gnu_test::counter::scope s;
test01();
test02();
return 0;
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc
index 0f7dce2b38c5..831f2aa1210c 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc
@@ -269,6 +269,7 @@ test03()
int
main()
{
+ __gnu_test::counter::scope s;
test01();
test02();
test11();
diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc
index 79b583bd716c..29eb4032ad9b 100644
--- a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc
+++ b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc
@@ -27,6 +27,7 @@ typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
int main()
{
+ __gnu_test::counter::scope s;
{
string_t s;
s += "bayou bend";
@@ -34,5 +35,6 @@ int main()
if (__gnu_test::counter::count() != 0)
throw std::runtime_error("count not zero");
+
return 0;
}
diff --git a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc
index fcde46e6e10c..e4a94604f438 100644
--- a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc
+++ b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc
@@ -27,6 +27,7 @@ typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
int main()
{
+ __gnu_test::counter::scope s;
{
string_t s;
s += "bayou bend";
@@ -34,5 +35,6 @@ int main()
if (__gnu_test::counter::count() != 0)
throw std::runtime_error("count not zero");
+
return 0;
}
diff --git a/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc b/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc
index 17f8e3c7dcbc..b11b450bf9e3 100644
--- a/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc
+++ b/libstdc++-v3/testsuite/ext/pool_allocator/allocate_chunk.cc
@@ -32,16 +32,29 @@ struct big
char c[64];
};
+bool started = false;
+
void*
operator new(size_t n) THROW(std::bad_alloc)
{
- static bool first = true;
- if (!first)
- throw std::bad_alloc();
- first = false;
+ if (started)
+ {
+ static bool first = true;
+ if (!first)
+ throw std::bad_alloc();
+ first = false;
+ }
+
return std::malloc(n);
}
+void
+operator delete(void* p) throw()
+{
+ if (p)
+ std::free(p);
+}
+
// http://gcc.gnu.org/ml/libstdc++/2004-10/msg00098.html
void test01()
{
@@ -59,5 +72,7 @@ void test01()
int main()
{
+ started = true;
test01();
+ started = false;
}
diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc
index c6fd3538b825..2a675e8b6b47 100644
--- a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc
+++ b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc
@@ -30,6 +30,7 @@ typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
int main()
{
+ __gnu_test::counter::scope s;
{
string_t s;
s += "bayou bend";
diff --git a/libstdc++-v3/testsuite/util/replacement_memory_operators.h b/libstdc++-v3/testsuite/util/replacement_memory_operators.h
index 6b1b3a82364c..6f19fbb8f6f6 100644
--- a/libstdc++-v3/testsuite/util/replacement_memory_operators.h
+++ b/libstdc++-v3/testsuite/util/replacement_memory_operators.h
@@ -75,12 +75,32 @@ namespace __gnu_test
counter& cntr = get();
cntr._M_increments = cntr._M_decrements = 0;
}
+
+ struct scope
+ {
+ scope() : _M_count(counter::count())
+ { counter::get()._M_count = 0; }
+ ~scope()
+ { counter::get()._M_count = _M_count; }
+
+ private:
+ std::size_t _M_count;
+
+#if __cplusplus >= 201103L
+ scope(const scope&) = delete;
+ scope& operator=(const scope&) = delete;
+#else
+ scope(const scope&);
+ scope& operator=(const scope&);
+#endif
+ };
};
template<typename Alloc, bool uses_global_new>
bool
check_new(Alloc a = Alloc())
{
+ __gnu_test::counter::scope s;
__gnu_test::counter::exceptions(false);
(void) a.allocate(10);
const bool __b((__gnu_test::counter::count() > 0) == uses_global_new);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-08-23 4:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23 4:37 [gcc r14-3401] libstdc++: Fix tests relying on operator new/delete overload Francois Dumont
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).