From db8a5fd8647293c00603970282d0b195bb4ed13a Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 26 Aug 2015 19:04:40 +0000 Subject: [PATCH] Refactor flaky shared_mutex tests git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@246055 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../thread.shared_mutex.class/assign.fail.cpp | 10 +++----- .../thread.shared_mutex.class/copy.fail.cpp | 10 +++----- .../thread.shared_mutex.class/lock.pass.cpp | 18 ++++++++++++--- .../lock_shared.pass.cpp | 23 +++++++++++++++---- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp index 7bcb2d61..5c67a34a 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp @@ -6,6 +6,8 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++98, c++03, c++11, c++14 // @@ -15,15 +17,9 @@ #include -#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 '='}} } diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp index af064aee..c7cac604 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp @@ -6,6 +6,8 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++98, c++03, c++11, c++14 // @@ -15,14 +17,8 @@ #include -#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'}} } diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp index 9bf7a79e..62cdf8e3 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp @@ -21,6 +21,7 @@ #include #include +#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(); } diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp index 3ffa9e2d..b8df2552 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp @@ -22,6 +22,8 @@ #include #include +#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 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();