[libcxx] r246055 - Refactor flaky shared_mutex tests

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 12:04:40 PDT 2015


Author: ericwf
Date: Wed Aug 26 14:04:40 2015
New Revision: 246055

URL: http://llvm.org/viewvc/llvm-project?rev=246055&view=rev
Log:
Refactor flaky shared_mutex tests

Modified:
    libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp
    libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp
    libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp
    libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp

Modified: libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp?rev=246055&r1=246054&r2=246055&view=diff
==============================================================================
--- libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp (original)
+++ libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp Wed Aug 26 14:04:40 2015
@@ -6,6 +6,8 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: c++98, c++03, c++11, c++14
 
 // <shared_mutex>
 
@@ -15,15 +17,9 @@
 
 #include <shared_mutex>
 
-#include "test_macros.h"
-
 int main()
 {
-#if TEST_STD_VER > 14
     std::shared_mutex m0;
     std::shared_mutex m1;
-    m1 = m0;
-#else
-#   error
-#endif
+    m1 = m0; // expected-error {{overload resolution selected deleted operator '='}}
 }

Modified: libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp?rev=246055&r1=246054&r2=246055&view=diff
==============================================================================
--- libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp (original)
+++ libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp Wed Aug 26 14:04:40 2015
@@ -6,6 +6,8 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: c++98, c++03, c++11, c++14
 
 // <shared_mutex>
 
@@ -15,14 +17,8 @@
 
 #include <shared_mutex>
 
-#include "test_macros.h"
-
 int main()
 {
-#if TEST_STD_VER > 14
     std::shared_mutex m0;
-    std::shared_mutex m1(m0);
-#else
-#   error
-#endif
+    std::shared_mutex m1(m0); // expected-error {{call to deleted constructor of 'std::shared_mutex'}}
 }

Modified: libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp?rev=246055&r1=246054&r2=246055&view=diff
==============================================================================
--- libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp (original)
+++ libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp Wed Aug 26 14:04:40 2015
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "test_macros.h"
 
 std::shared_mutex m;
 
@@ -30,21 +31,32 @@ typedef Clock::duration duration;
 typedef std::chrono::milliseconds ms;
 typedef std::chrono::nanoseconds ns;
 
+ms WaitTime = ms(250);
+
+// Thread sanitizer causes more overhead and will sometimes cause this test
+// to fail. To prevent this we give Thread sanitizer more time to complete the
+// test.
+#if !TEST_HAS_FEATURE(thread_sanitizer)
+ms Tolerance = ms(50);
+#else
+ms Tolerance = ms(100);
+#endif
+
 void f()
 {
     time_point t0 = Clock::now();
     m.lock();
     time_point t1 = Clock::now();
     m.unlock();
-    ns d = t1 - t0 - ms(250);
-    assert(d < ms(50));  // within 50ms
+    ns d = t1 - t0 - WaitTime;
+    assert(d < Tolerance);  // within tolerance
 }
 
 int main()
 {
     m.lock();
     std::thread t(f);
-    std::this_thread::sleep_for(ms(250));
+    std::this_thread::sleep_for(WaitTime);
     m.unlock();
     t.join();
 }

Modified: libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp?rev=246055&r1=246054&r2=246055&view=diff
==============================================================================
--- libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp (original)
+++ libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp Wed Aug 26 14:04:40 2015
@@ -22,6 +22,8 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "test_macros.h"
+
 std::shared_mutex m;
 
 typedef std::chrono::system_clock Clock;
@@ -30,14 +32,25 @@ typedef Clock::duration duration;
 typedef std::chrono::milliseconds ms;
 typedef std::chrono::nanoseconds ns;
 
+ms WaitTime = ms(250);
+
+// Thread sanitizer causes more overhead and will sometimes cause this test
+// to fail. To prevent this we give Thread sanitizer more time to complete the
+// test.
+#if !TEST_HAS_FEATURE(thread_sanitizer)
+ms Tolerance = ms(50);
+#else
+ms Tolerance = ms(100);
+#endif
+
 void f()
 {
     time_point t0 = Clock::now();
     m.lock_shared();
     time_point t1 = Clock::now();
     m.unlock_shared();
-    ns d = t1 - t0 - ms(250);
-    assert(d < ms(50));  // within 50ms
+    ns d = t1 - t0 - WaitTime;
+    assert(d < Tolerance);  // within tolerance
 }
 
 void g()
@@ -47,7 +60,7 @@ void g()
     time_point t1 = Clock::now();
     m.unlock_shared();
     ns d = t1 - t0;
-    assert(d < ms(50));  // within 50ms
+    assert(d < Tolerance);  // within tolerance
 }
 
 
@@ -57,7 +70,7 @@ int main()
     std::vector<std::thread> v;
     for (int i = 0; i < 5; ++i)
         v.push_back(std::thread(f));
-    std::this_thread::sleep_for(ms(250));
+    std::this_thread::sleep_for(WaitTime);
     m.unlock();
     for (auto& t : v)
         t.join();
@@ -65,7 +78,7 @@ int main()
     for (auto& t : v)
         t = std::thread(g);
     std::thread q(f);
-    std::this_thread::sleep_for(ms(250));
+    std::this_thread::sleep_for(WaitTime);
     m.unlock_shared();
     for (auto& t : v)
         t.join();




More information about the cfe-commits mailing list