[libcxx-commits] [libcxx] 0e8f5e4 - [libcxx] [test] Skip alloc counter checks for operations within the libc++ DLL

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 30 23:26:47 PDT 2021


Author: Martin Storsjö
Date: 2021-05-01T09:26:23+03:00
New Revision: 0e8f5e4a6864839d2292ec1ddfe48b6178c01f85

URL: https://github.com/llvm/llvm-project/commit/0e8f5e4a6864839d2292ec1ddfe48b6178c01f85
DIFF: https://github.com/llvm/llvm-project/commit/0e8f5e4a6864839d2292ec1ddfe48b6178c01f85.diff

LOG: [libcxx] [test] Skip alloc counter checks for operations within the libc++ DLL

If libc++ is built as a DLL, calls to operator new within the DLL aren't
overridden if a user provides their own operator in calling code.
Therefore, the alloc counter doesn't pick up on allocations done within
std::string, so skip that check if running on windows. (Technically,
we could keep the checks if running on windows when not built as a DLL,
but trying to keep the conditionals simple.)

Differential Revision: https://reviews.llvm.org/D100219

Added: 
    

Modified: 
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.concat.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
    libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
    libcxx/test/support/test_macros.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
index 201cb99e6481a..10f0cf44fcbb2 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
@@ -11,8 +11,6 @@
 // These tests require locale for non-char paths
 // UNSUPPORTED: libcpp-has-no-localization
 
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // <filesystem>
 
 // class path
@@ -197,6 +195,9 @@ void doAppendSourceAllocTest(AppendOperatorTestcase const& TC)
   // required.
   // On Windows, the append method is more complex and uses intermediate
   // path objects, which causes extra allocations.
+  // In DLL builds on Windows, the overridden operator new won't pick up
+  // allocations done within the DLL, so the RequireAllocationGuard below
+  // won't necessarily see allocations in the cases where they're expected.
 #ifdef _WIN32
   bool DisableAllocations = false;
 #else
@@ -208,6 +209,7 @@ void doAppendSourceAllocTest(AppendOperatorTestcase const& TC)
     {
       RequireAllocationGuard  g; // requires 1 or more allocations occur by default
       if (DisableAllocations) g.requireExactly(0);
+      else TEST_ONLY_WIN32_DLL(g.requireAtLeast(0));
       LHS /= RHS;
     }
     assert(PathEq(LHS, E));
@@ -219,6 +221,7 @@ void doAppendSourceAllocTest(AppendOperatorTestcase const& TC)
     {
       RequireAllocationGuard g;
       if (DisableAllocations) g.requireExactly(0);
+      else TEST_ONLY_WIN32_DLL(g.requireAtLeast(0));
       LHS.append(RHS, REnd);
     }
     assert(PathEq(LHS, E));

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
index 144966c690a4a..c13469fd30d17 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/move.pass.cpp
@@ -8,8 +8,6 @@
 
 // UNSUPPORTED: c++03
 
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // <filesystem>
 
 // class path
@@ -30,7 +28,9 @@ int main(int, char**) {
   assert(globalMemCounter.checkOutstandingNewEq(0));
   const std::string s("we really really really really really really really "
                       "really really long string so that we allocate");
-  assert(globalMemCounter.checkOutstandingNewEq(1));
+  // On windows, the operator new from count_new.h can't override the default
+  // operator for calls within the libc++ DLL.
+  TEST_NOT_WIN32_DLL(assert(globalMemCounter.checkOutstandingNewEq(1)));
   const fs::path::string_type ps(s.begin(), s.end());
   path p(s);
   {

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.concat.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.concat.pass.cpp
index c09d60d28e2c2..b57ee21a7cea8 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.concat.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.concat.pass.cpp
@@ -11,8 +11,6 @@
 // These tests require locale for non-char paths
 // UNSUPPORTED: libcpp-has-no-localization
 
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // <filesystem>
 
 // class path
@@ -142,6 +140,10 @@ void doConcatSourceAllocTest(ConcatOperatorTestcase const& TC)
   // code_cvt conversions.
   // For the path native type, no allocations will be performed because no
   // conversion is required.
+
+  // In DLL builds on Windows, the overridden operator new won't pick up
+  // allocations done within the DLL, so the RequireAllocationGuard below
+  // won't necessarily see allocations in the cases where they're expected.
   bool DisableAllocations = std::is_same<CharT, path::value_type>::value;
   {
     path LHS(L); PathReserve(LHS, ReserveSize);
@@ -149,6 +151,7 @@ void doConcatSourceAllocTest(ConcatOperatorTestcase const& TC)
     {
       RequireAllocationGuard  g; // requires 1 or more allocations occur by default
       if (DisableAllocations) g.requireExactly(0);
+      else TEST_ONLY_WIN32_DLL(g.requireAtLeast(0));
       LHS += RHS;
     }
     assert(LHS == E);
@@ -160,6 +163,7 @@ void doConcatSourceAllocTest(ConcatOperatorTestcase const& TC)
     {
       RequireAllocationGuard g;
       if (DisableAllocations) g.requireExactly(0);
+      else TEST_ONLY_WIN32_DLL(g.requireAtLeast(0));
       LHS.concat(RHS, REnd);
     }
     assert(LHS == E);

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
index bf63f702305ed..f0d324b2f8601 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.construct/move.pass.cpp
@@ -8,8 +8,6 @@
 
 // UNSUPPORTED: c++03
 
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // <filesystem>
 
 // class path
@@ -30,7 +28,9 @@ int main(int, char**) {
   assert(globalMemCounter.checkOutstandingNewEq(0));
   const std::string s("we really really really really really really really "
                       "really really long string so that we allocate");
-  assert(globalMemCounter.checkOutstandingNewEq(1));
+  // On windows, the operator new from count_new.h can't override the default
+  // operator for calls within the libc++ DLL.
+  TEST_NOT_WIN32_DLL(assert(globalMemCounter.checkOutstandingNewEq(1)));
   const fs::path::string_type ps(s.begin(), s.end());
   path p(s);
   {

diff  --git a/libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp b/libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp
index b5fe59b0d9d68..0533bb8c20b32 100644
--- a/libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp
@@ -12,8 +12,6 @@
 
 // ~ctype();
 
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 #include <locale>
 #include <cassert>
 
@@ -39,7 +37,9 @@ int main(int, char**)
             new std::ctype<char>(new std::ctype<char>::mask[256], true));
         assert(globalMemCounter.checkDeleteArrayCalledEq(0));
     }
-    assert(globalMemCounter.checkDeleteArrayCalledEq(1));
+    // On windows, the operator new from count_new.h can't override the default
+    // operator for calls within the libc++ DLL.
+    TEST_NOT_WIN32_DLL(assert(globalMemCounter.checkDeleteArrayCalledEq(1)));
 
   return 0;
 }

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
index 02f19a0b11a04..6dfe1ceffb19c 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -8,8 +8,6 @@
 //
 // UNSUPPORTED: libcpp-has-no-threads
 
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 // <thread>
 
 // class thread
@@ -138,7 +136,7 @@ void test_throwing_new_during_thread_creation() {
     for (int i=0; i <= numAllocs; ++i) {
         throw_one = i;
         f_run = false;
-        unsigned old_outstanding = outstanding_new;
+        TEST_NOT_WIN32_DLL(unsigned old_outstanding = outstanding_new);
         try {
             std::thread t(f);
             assert(i == numAllocs); // Only final iteration will not throw.
@@ -148,7 +146,9 @@ void test_throwing_new_during_thread_creation() {
             assert(i < numAllocs);
             assert(!f_run); // (2.2)
         }
-        assert(old_outstanding == outstanding_new); // (2.3)
+        // In DLL builds on Windows, the overridden operators new/delete won't
+        // override calls from within the DLL, so this won't match.
+        TEST_NOT_WIN32_DLL(assert(old_outstanding == outstanding_new)); // (2.3)
     }
     f_run = false;
     throw_one = 0xFFF;

diff  --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index c39e79b93744e..4bd3d55c5da47 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -382,6 +382,14 @@ inline void DoNotOptimize(Tp const& value) {
 #define TEST_NOT_WIN32(...) __VA_ARGS__
 #endif
 
+#if defined(_WIN32) && !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
+#define TEST_NOT_WIN32_DLL(...) ((void)0)
+#define TEST_ONLY_WIN32_DLL(...) __VA_ARGS__
+#else
+#define TEST_NOT_WIN32_DLL(...) __VA_ARGS__
+#define TEST_ONLY_WIN32_DLL(...) ((void)0)
+#endif
+
 #ifdef _WIN32
 #define TEST_WIN_NO_FILESYSTEM_PERMS_NONE
 #endif


        


More information about the libcxx-commits mailing list