From 60d6ef63a4e30bbba038d67849fa786314f670f6 Mon Sep 17 00:00:00 2001 From: Roger Ferrer Ibanez Date: Tue, 1 Nov 2016 15:00:16 +0000 Subject: [PATCH] Protect lock tests under libcpp-no-exceptions Skip tests that expect an exception to be thrown. Differential Revision: https://reviews.llvm.org/D26184 llvm-svn: 285695 --- .../thread.mutex/thread.lock.algorithm/lock.pass.cpp | 15 ++++++++++++--- .../thread.mutex/thread.lock.algorithm/try_lock.pass.cpp | 13 +++++++++++-- .../thread.lock.shared.locking/lock.pass.cpp | 5 ++++- .../thread.lock.shared.locking/try_lock.pass.cpp | 8 ++++++-- .../thread.lock.shared.locking/try_lock_for.pass.cpp | 7 ++++++- .../thread.lock.shared.locking/try_lock_until.pass.cpp | 7 ++++++- .../thread.lock.shared.locking/unlock.pass.cpp | 7 ++++++- .../thread.lock.unique.locking/lock.pass.cpp | 7 ++++++- .../thread.lock.unique.locking/try_lock.pass.cpp | 7 ++++++- .../thread.lock.unique.locking/try_lock_for.pass.cpp | 7 ++++++- .../thread.lock.unique.locking/try_lock_until.pass.cpp | 7 ++++++- .../thread.lock.unique.locking/unlock.pass.cpp | 7 ++++++- .../thread.once/thread.once.callonce/call_once.pass.cpp | 7 +++++-- 13 files changed, 86 insertions(+), 18 deletions(-) diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp index 9e20144..46d04cd 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // This test hangs forever when built against libstdc++. In order to allow @@ -23,6 +22,8 @@ #include #include +#include "test_macros.h" + class L0 { bool locked_; @@ -78,12 +79,12 @@ public: void lock() { - throw 1; + TEST_THROW(1); } bool try_lock() { - throw 1; + TEST_THROW(1); return locked_; } @@ -115,6 +116,7 @@ int main() assert(l0.locked()); assert(l1.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L0 l0; L2 l1; @@ -185,6 +187,7 @@ int main() assert(!l1.locked()); } } +#endif #ifndef _LIBCPP_HAS_NO_VARIADICS { L0 l0; @@ -195,6 +198,7 @@ int main() assert(l1.locked()); assert(l2.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L2 l0; L2 l1; @@ -211,6 +215,7 @@ int main() assert(!l2.locked()); } } +#endif { L0 l0; L0 l1; @@ -238,6 +243,7 @@ int main() assert(l1.locked()); assert(l2.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L0 l0; L0 l1; @@ -382,6 +388,7 @@ int main() assert(!l2.locked()); } } +#endif // TEST_HAS_NO_EXCEPTIONS { L0 l0; L0 l1; @@ -437,6 +444,7 @@ int main() assert(l2.locked()); assert(l3.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L0 l0; L0 l1; @@ -509,5 +517,6 @@ int main() assert(!l3.locked()); } } +#endif // TEST_HAS_NO_EXCEPTIONS #endif // _LIBCPP_HAS_NO_VARIADICS } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp index 8889408..fb563cb 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // @@ -18,6 +17,8 @@ #include #include +#include "test_macros.h" + class L0 { bool locked_; @@ -63,7 +64,7 @@ public: bool try_lock() { - throw 1; + TEST_THROW(1); return locked_; } @@ -95,6 +96,7 @@ int main() assert(!l0.locked()); assert(!l1.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L0 l0; L2 l1; @@ -123,6 +125,7 @@ int main() assert(!l1.locked()); } } +#endif #ifndef _LIBCPP_HAS_NO_VARIADICS { L0 l0; @@ -142,6 +145,7 @@ int main() assert(!l1.locked()); assert(!l2.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L2 l0; L2 l1; @@ -167,6 +171,7 @@ int main() assert(!l1.locked()); assert(!l2.locked()); } +#endif { L0 l0; L0 l1; @@ -194,6 +199,7 @@ int main() assert(!l1.locked()); assert(!l2.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L0 l0; L0 l1; @@ -242,6 +248,7 @@ int main() assert(!l2.locked()); } } +#endif { L1 l0; L1 l1; @@ -269,6 +276,7 @@ int main() assert(!l1.locked()); assert(!l2.locked()); } +#ifndef TEST_HAS_NO_EXCEPTIONS { L1 l0; L1 l1; @@ -458,6 +466,7 @@ int main() assert(!l2.locked()); } } +#endif // TEST_HAS_NO_EXCEPTIONS { L0 l0; L0 l1; diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp index 5c3513c..25d78ab 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // UNSUPPORTED: c++98, c++03, c++11 @@ -54,6 +53,7 @@ void f() assert(lk.owns_lock() == true); ns d = t1 - t0 - WaitTime; assert(d < Tolerance); // within tolerance +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.lock(); @@ -63,8 +63,10 @@ void f() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.lock(); @@ -74,6 +76,7 @@ void f() { assert(e.code().value() == EPERM); } +#endif } int main() diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp index 01693c7..947b1ad 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // UNSUPPORTED: c++98, c++03, c++11 @@ -20,6 +19,8 @@ #include #include +#include "test_macros.h" + bool try_lock_called = false; struct mutex @@ -36,11 +37,11 @@ mutex m; int main() { - std::shared_lock lk(m, std::defer_lock); assert(lk.try_lock() == true); assert(try_lock_called == true); assert(lk.owns_lock() == true); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock(); @@ -50,11 +51,13 @@ int main() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); assert(lk.try_lock() == false); assert(try_lock_called == false); assert(lk.owns_lock() == false); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock(); @@ -64,4 +67,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp index 852a94e..5cb8054 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // UNSUPPORTED: c++98, c++03, c++11 @@ -21,6 +20,8 @@ #include #include +#include "test_macros.h" + bool try_lock_for_called = false; typedef std::chrono::milliseconds ms; @@ -45,6 +46,7 @@ int main() assert(lk.try_lock_for(ms(5)) == true); assert(try_lock_for_called == true); assert(lk.owns_lock() == true); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_for(ms(5)); @@ -54,11 +56,13 @@ int main() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); assert(lk.try_lock_for(ms(5)) == false); assert(try_lock_for_called == false); assert(lk.owns_lock() == false); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_for(ms(5)); @@ -68,4 +72,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp index 31574af..3ba4128 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // UNSUPPORTED: c++98, c++03, c++11 @@ -21,6 +20,8 @@ #include #include +#include "test_macros.h" + bool try_lock_until_called = false; struct mutex @@ -45,6 +46,7 @@ int main() assert(lk.try_lock_until(Clock::now()) == true); assert(try_lock_until_called == true); assert(lk.owns_lock() == true); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_until(Clock::now()); @@ -54,11 +56,13 @@ int main() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); assert(lk.try_lock_until(Clock::now()) == false); assert(try_lock_until_called == false); assert(lk.owns_lock() == false); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_until(Clock::now()); @@ -68,4 +72,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp index 6a7385e..903b53a 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // UNSUPPORTED: c++98, c++03, c++11 @@ -20,6 +19,8 @@ #include #include +#include "test_macros.h" + bool unlock_called = false; struct mutex @@ -36,6 +37,7 @@ int main() lk.unlock(); assert(unlock_called == true); assert(lk.owns_lock() == false); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.unlock(); @@ -45,7 +47,9 @@ int main() { assert(e.code().value() == EPERM); } +#endif lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.unlock(); @@ -55,4 +59,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp index 6ce3376..cb5c559 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // @@ -21,6 +20,8 @@ #include #include +#include "test_macros.h" + std::mutex m; typedef std::chrono::system_clock Clock; @@ -38,6 +39,7 @@ void f() assert(lk.owns_lock() == true); ns d = t1 - t0 - ms(250); assert(d < ms(25)); // within 25ms +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.lock(); @@ -47,8 +49,10 @@ void f() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.lock(); @@ -58,6 +62,7 @@ void f() { assert(e.code().value() == EPERM); } +#endif } int main() diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp index 27d0562d..709c569 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // @@ -19,6 +18,8 @@ #include #include +#include "test_macros.h" + bool try_lock_called = false; struct mutex @@ -39,6 +40,7 @@ int main() assert(lk.try_lock() == true); assert(try_lock_called == true); assert(lk.owns_lock() == true); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock(); @@ -48,11 +50,13 @@ int main() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); assert(lk.try_lock() == false); assert(try_lock_called == false); assert(lk.owns_lock() == false); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock(); @@ -62,4 +66,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp index 6f0a721..6c98178 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // @@ -20,6 +19,8 @@ #include #include +#include "test_macros.h" + bool try_lock_for_called = false; typedef std::chrono::milliseconds ms; @@ -44,6 +45,7 @@ int main() assert(lk.try_lock_for(ms(5)) == true); assert(try_lock_for_called == true); assert(lk.owns_lock() == true); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_for(ms(5)); @@ -53,11 +55,13 @@ int main() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); assert(lk.try_lock_for(ms(5)) == false); assert(try_lock_for_called == false); assert(lk.owns_lock() == false); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_for(ms(5)); @@ -67,4 +71,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp index b7e8724..57231b2 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // @@ -20,6 +19,8 @@ #include #include +#include "test_macros.h" + bool try_lock_until_called = false; struct mutex @@ -44,6 +45,7 @@ int main() assert(lk.try_lock_until(Clock::now()) == true); assert(try_lock_until_called == true); assert(lk.owns_lock() == true); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_until(Clock::now()); @@ -53,11 +55,13 @@ int main() { assert(e.code().value() == EDEADLK); } +#endif lk.unlock(); assert(lk.try_lock_until(Clock::now()) == false); assert(try_lock_until_called == false); assert(lk.owns_lock() == false); lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.try_lock_until(Clock::now()); @@ -67,4 +71,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp index 62497c9..124ff55 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // @@ -19,6 +18,8 @@ #include #include +#include "test_macros.h" + bool unlock_called = false; struct mutex @@ -35,6 +36,7 @@ int main() lk.unlock(); assert(unlock_called == true); assert(lk.owns_lock() == false); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.unlock(); @@ -44,7 +46,9 @@ int main() { assert(e.code().value() == EPERM); } +#endif lk.release(); +#ifndef TEST_HAS_NO_EXCEPTIONS try { lk.unlock(); @@ -54,4 +58,5 @@ int main() { assert(e.code().value() == EPERM); } +#endif } diff --git a/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp index 71b054f..138b657 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// // -// XFAIL: libcpp-no-exceptions // UNSUPPORTED: libcpp-has-no-threads // @@ -50,12 +49,13 @@ void init3() ++init3_called; std::this_thread::sleep_for(ms(250)); if (init3_called == 1) - throw 1; + TEST_THROW(1); ++init3_completed; } void f3() { +#ifndef TEST_HAS_NO_EXCEPTIONS try { std::call_once(flg3, init3); @@ -63,6 +63,7 @@ void f3() catch (...) { } +#endif } #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -197,6 +198,7 @@ int main() t1.join(); assert(init0_called == 1); } +#ifndef TEST_HAS_NO_EXCEPTIONS // check basic exception safety { std::thread t0(f3); @@ -206,6 +208,7 @@ int main() assert(init3_called == 2); assert(init3_completed == 1); } +#endif // check deadlock avoidance { std::thread t0(f41); -- 2.7.4