diff options
6 files changed, 123 insertions, 37 deletions
diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp index 62bb736837e..2818bd61754 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp @@ -21,6 +21,8 @@ #include <cstdlib> #include <cassert> +#include "test_macros.h" + std::shared_timed_mutex m; typedef std::chrono::system_clock Clock; @@ -29,6 +31,19 @@ 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(); diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp index 8fc6299f1b8..63d3f850fd5 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp @@ -22,6 +22,8 @@ #include <cstdlib> #include <cassert> +#include "test_macros.h" + std::shared_timed_mutex m; typedef std::chrono::system_clock Clock; @@ -30,14 +32,27 @@ 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 +62,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 +72,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 +80,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(); diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp index ab20241895b..f4525a4f441 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp @@ -22,6 +22,8 @@ #include <cstdlib> #include <cassert> +#include "test_macros.h" + std::shared_timed_mutex m; typedef std::chrono::steady_clock Clock; @@ -30,23 +32,36 @@ 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 f1() { time_point t0 = Clock::now(); - assert(m.try_lock_for(ms(300)) == true); + assert(m.try_lock_for(WaitTime + Tolerance) == true); 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 } void f2() { time_point t0 = Clock::now(); - assert(m.try_lock_for(ms(250)) == false); + assert(m.try_lock_for(WaitTime) == false); time_point t1 = Clock::now(); - ns d = t1 - t0 - ms(250); - assert(d < ms(50)); // within 50ms + ns d = t1 - t0 - WaitTime; + assert(d < Tolerance); // within tolerance } int main() @@ -54,14 +69,14 @@ int main() { m.lock(); std::thread t(f1); - std::this_thread::sleep_for(ms(250)); + std::this_thread::sleep_for(WaitTime); m.unlock(); t.join(); } { m.lock(); std::thread t(f2); - std::this_thread::sleep_for(ms(300)); + std::this_thread::sleep_for(WaitTime + Tolerance); m.unlock(); t.join(); } diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp index 35444112a5d..6066af50e65 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp @@ -23,6 +23,8 @@ #include <cstdlib> #include <cassert> +#include "test_macros.h" + std::shared_timed_mutex m; typedef std::chrono::steady_clock Clock; @@ -31,23 +33,35 @@ 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 f1() { time_point t0 = Clock::now(); - assert(m.try_lock_shared_for(ms(300)) == true); + assert(m.try_lock_shared_for(WaitTime + Tolerance) == true); 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 50ms } void f2() { time_point t0 = Clock::now(); - assert(m.try_lock_shared_for(ms(250)) == false); + assert(m.try_lock_shared_for(WaitTime) == false); time_point t1 = Clock::now(); - ns d = t1 - t0 - ms(250); - assert(d < ms(50)); // within 50ms + ns d = t1 - t0 - WaitTime; + assert(d < Tolerance); // within 50ms } int main() @@ -57,7 +71,7 @@ int main() std::vector<std::thread> v; for (int i = 0; i < 5; ++i) v.push_back(std::thread(f1)); - std::this_thread::sleep_for(ms(250)); + std::this_thread::sleep_for(WaitTime); m.unlock(); for (auto& t : v) t.join(); @@ -67,7 +81,7 @@ int main() std::vector<std::thread> v; for (int i = 0; i < 5; ++i) v.push_back(std::thread(f2)); - std::this_thread::sleep_for(ms(300)); + std::this_thread::sleep_for(WaitTime + Tolerance); m.unlock(); for (auto& t : v) t.join(); diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp index 4e0f19de07c..64164abbe96 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp @@ -23,6 +23,8 @@ #include <cstdlib> #include <cassert> +#include "test_macros.h" + std::shared_timed_mutex m; typedef std::chrono::steady_clock Clock; @@ -31,23 +33,35 @@ 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 f1() { time_point t0 = Clock::now(); - assert(m.try_lock_shared_until(Clock::now() + ms(300)) == true); + assert(m.try_lock_shared_until(Clock::now() + WaitTime + Tolerance) == true); 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 50ms } void f2() { time_point t0 = Clock::now(); - assert(m.try_lock_shared_until(Clock::now() + ms(250)) == false); + assert(m.try_lock_shared_until(Clock::now() + WaitTime) == false); time_point t1 = Clock::now(); - ns d = t1 - t0 - ms(250); - assert(d < ms(50)); // within 50ms + ns d = t1 - t0 - WaitTime; + assert(d < Tolerance); // within tolerance } int main() @@ -57,7 +71,7 @@ int main() std::vector<std::thread> v; for (int i = 0; i < 5; ++i) v.push_back(std::thread(f1)); - std::this_thread::sleep_for(ms(250)); + std::this_thread::sleep_for(WaitTime); m.unlock(); for (auto& t : v) t.join(); @@ -67,7 +81,7 @@ int main() std::vector<std::thread> v; for (int i = 0; i < 5; ++i) v.push_back(std::thread(f2)); - std::this_thread::sleep_for(ms(300)); + std::this_thread::sleep_for(WaitTime + Tolerance); m.unlock(); for (auto& t : v) t.join(); diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp index aa90cf71502..60ad2f5e06e 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp @@ -32,23 +32,36 @@ 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 f1() { time_point t0 = Clock::now(); - assert(m.try_lock_until(Clock::now() + ms(300)) == true); + assert(m.try_lock_until(Clock::now() + WaitTime + Tolerance) == true); 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 } void f2() { time_point t0 = Clock::now(); - assert(m.try_lock_until(Clock::now() + ms(250)) == false); + assert(m.try_lock_until(Clock::now() + WaitTime) == false); time_point t1 = Clock::now(); - ns d = t1 - t0 - ms(250); - assert(d < ms(50)); // within 50ms + ns d = t1 - t0 - WaitTime; + assert(d < Tolerance); // within tolerance } int main() @@ -56,14 +69,14 @@ int main() { m.lock(); std::thread t(f1); - std::this_thread::sleep_for(ms(250)); + std::this_thread::sleep_for(WaitTime); m.unlock(); t.join(); } { m.lock(); std::thread t(f2); - std::this_thread::sleep_for(ms(300)); + std::this_thread::sleep_for(WaitTime + Tolerance); m.unlock(); t.join(); } |