public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-1162] libstdc++: Fix tests for COW std::string [PR 96088]
Date: Wed,  2 Jun 2021 12:33:51 +0000 (GMT)	[thread overview]
Message-ID: <20210602123351.548693857804@sourceware.org> (raw)

https://gcc.gnu.org/g:81eab204a56dcd8acb1ca5d7df277437ca07b51a

commit r12-1162-g81eab204a56dcd8acb1ca5d7df277437ca07b51a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jun 2 12:33:38 2021 +0100

    libstdc++: Fix tests for COW std::string [PR 96088]
    
    The expected number of allocations is different when copying COW
    strings.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/96088
            * testsuite/23_containers/unordered_map/96088.cc: Adjust
            expected number of allocations.
            * testsuite/23_containers/unordered_set/96088.cc: Likewise.

Diff:
---
 .../testsuite/23_containers/unordered_map/96088.cc | 22 +++++++++++++++-------
 .../testsuite/23_containers/unordered_set/96088.cc | 22 +++++++++++++++-------
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
index e552b04f8c8..83ca1c0afd6 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/96088.cc
@@ -222,7 +222,8 @@ test03()
   std::vector<std::pair<std::string, int>> v;
   v.insert(v.end(), lst.begin(), lst.end());
 
-  auto __offset = __gnu_test::counter::count();
+  const auto origin = __gnu_test::counter::count();
+
   {
     __gnu_test::counter::reset();
     std::unordered_map<std::string, int,
@@ -231,15 +232,19 @@ test03()
     um.insert(v.begin(), v.end());
     VERIFY( um.size() == 1 );
 
-    VERIFY( __gnu_test::counter::count() - __offset == 3 );
-    VERIFY( __gnu_test::counter::get()._M_increments == 3 );
+    // Allocate array of buckets, a node, and the std::string (unless COW).
+    constexpr std::size_t increments = _GLIBCXX_USE_CXX11_ABI ? 3 : 2;
+
+    VERIFY( __gnu_test::counter::count() == origin + increments );
+    VERIFY( __gnu_test::counter::get()._M_increments == increments );
 
     um.insert(v.begin(), v.end());
     VERIFY( um.size() == 1 );
 
-    VERIFY( __gnu_test::counter::count() - __offset == 3 );
-    VERIFY( __gnu_test::counter::get()._M_increments == 3 );
+    VERIFY( __gnu_test::counter::count() == origin + increments );
+    VERIFY( __gnu_test::counter::get()._M_increments == increments );
   }
+  VERIFY( __gnu_test::counter::count() == origin );
 
   {
     __gnu_test::counter::reset();
@@ -250,8 +255,11 @@ test03()
 	      std::make_move_iterator(v.end()));
     VERIFY( um.size() == 1 );
 
-    VERIFY( __gnu_test::counter::count() - __offset == 2 );
-    VERIFY( __gnu_test::counter::get()._M_increments == 2 );
+    // Allocate array of buckets and a node. String is moved.
+    constexpr std::size_t increments = 2;
+
+    VERIFY( __gnu_test::counter::count() == origin + increments );
+    VERIFY( __gnu_test::counter::get()._M_increments == increments );
   }
 }
 
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc
index efb2f9eb6b1..83d5475c677 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/96088.cc
@@ -223,7 +223,8 @@ test03()
   std::vector<std::string> v;
   v.insert(v.end(), lst.begin(), lst.end());
 
-  auto __offset = __gnu_test::counter::count();
+  const auto origin = __gnu_test::counter::count();
+
   {
     __gnu_test::counter::reset();
     std::unordered_set<std::string,
@@ -232,15 +233,19 @@ test03()
     us.insert(v.begin(), v.end());
     VERIFY( us.size() == 1 );
 
-    VERIFY( __gnu_test::counter::count() - __offset == 3 );
-    VERIFY( __gnu_test::counter::get()._M_increments == 3 );
+    // Allocate array of buckets, a node, and the std::string (unless COW).
+    constexpr std::size_t increments = _GLIBCXX_USE_CXX11_ABI ? 3 : 2;
+
+    VERIFY( __gnu_test::counter::count() == origin + increments );
+    VERIFY( __gnu_test::counter::get()._M_increments == increments );
 
     us.insert(v.begin(), v.end());
     VERIFY( us.size() == 1 );
 
-    VERIFY( __gnu_test::counter::count() - __offset == 3 );
-    VERIFY( __gnu_test::counter::get()._M_increments == 3 );
+    VERIFY( __gnu_test::counter::count() == origin + increments );
+    VERIFY( __gnu_test::counter::get()._M_increments == increments );
   }
+  VERIFY( __gnu_test::counter::count() == origin );
 
   {
     __gnu_test::counter::reset();
@@ -251,8 +256,11 @@ test03()
 	      std::make_move_iterator(v.end()));
     VERIFY( us.size() == 1 );
 
-    VERIFY( __gnu_test::counter::count() - __offset == 2 );
-    VERIFY( __gnu_test::counter::get()._M_increments == 2 );
+    // Allocate array of buckets and a node. String is moved.
+    constexpr std::size_t increments = 2;
+
+    VERIFY( __gnu_test::counter::count() == origin + increments );
+    VERIFY( __gnu_test::counter::get()._M_increments == increments );
   }
 }


                 reply	other threads:[~2021-06-02 12:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210602123351.548693857804@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).