diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
| commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
| tree | 13f237c02db4d1894ab06884d1b739344766bede /test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class | |
| parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
Notes
Diffstat (limited to 'test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class')
7 files changed, 129 insertions, 38 deletions
diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp index 62bb736837ea..2818bd617542 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp +++ b/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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp index 8fc6299f1b8f..77a9107de923 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp +++ b/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 !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp index ab20241895ba..320a268ae77d 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp +++ b/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,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 !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#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 +68,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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp index 9c2d8c9c8e5c..3d5604d886cb 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_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,6 +32,13 @@ typedef Clock::duration duration; typedef std::chrono::milliseconds ms; typedef std::chrono::nanoseconds ns; + +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(200); +#else +ms Tolerance = ms(200 * 5); +#endif + void f() { time_point t0 = Clock::now(); @@ -41,7 +50,7 @@ void f() time_point t1 = Clock::now(); m.unlock_shared(); ns d = t1 - t0 - ms(250); - assert(d < ms(200)); // within 200ms + assert(d < Tolerance); // within tolerance } int main() diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp index 35444112a5da..4cdb5873f9a1 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp +++ b/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,34 @@ 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 !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#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 +70,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 +80,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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp index 4e0f19de07ce..f7ddbaeef498 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp +++ b/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,34 @@ 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 !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#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 +70,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 +80,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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp index aa90cf71502f..1560af2c9ecc 100644 --- a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp @@ -32,23 +32,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 !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#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 +68,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(); } |
