Skip to content

Commit

Permalink
Protect lock tests under libcpp-no-exceptions
Browse files Browse the repository at this point in the history
Skip tests that expect an exception to be thrown.

Differential Revision: https://reviews.llvm.org/D26184

llvm-svn: 285695
  • Loading branch information
Roger Ferrer Ibanez committed Nov 1, 2016
1 parent 05ce4ca commit 60d6ef6
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 18 deletions.
Expand Up @@ -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
Expand All @@ -23,6 +22,8 @@
#include <mutex>
#include <cassert>

#include "test_macros.h"

class L0
{
bool locked_;
Expand Down Expand Up @@ -78,12 +79,12 @@ class L2

void lock()
{
throw 1;
TEST_THROW(1);
}

bool try_lock()
{
throw 1;
TEST_THROW(1);
return locked_;
}

Expand Down Expand Up @@ -115,6 +116,7 @@ int main()
assert(l0.locked());
assert(l1.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L0 l0;
L2 l1;
Expand Down Expand Up @@ -185,6 +187,7 @@ int main()
assert(!l1.locked());
}
}
#endif
#ifndef _LIBCPP_HAS_NO_VARIADICS
{
L0 l0;
Expand All @@ -195,6 +198,7 @@ int main()
assert(l1.locked());
assert(l2.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L2 l0;
L2 l1;
Expand All @@ -211,6 +215,7 @@ int main()
assert(!l2.locked());
}
}
#endif
{
L0 l0;
L0 l1;
Expand Down Expand Up @@ -238,6 +243,7 @@ int main()
assert(l1.locked());
assert(l2.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L0 l0;
L0 l1;
Expand Down Expand Up @@ -382,6 +388,7 @@ int main()
assert(!l2.locked());
}
}
#endif // TEST_HAS_NO_EXCEPTIONS
{
L0 l0;
L0 l1;
Expand Down Expand Up @@ -437,6 +444,7 @@ int main()
assert(l2.locked());
assert(l3.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L0 l0;
L0 l1;
Expand Down Expand Up @@ -509,5 +517,6 @@ int main()
assert(!l3.locked());
}
}
#endif // TEST_HAS_NO_EXCEPTIONS
#endif // _LIBCPP_HAS_NO_VARIADICS
}
Expand Up @@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
//
// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads

// <mutex>
Expand All @@ -18,6 +17,8 @@
#include <mutex>
#include <cassert>

#include "test_macros.h"

class L0
{
bool locked_;
Expand Down Expand Up @@ -63,7 +64,7 @@ class L2

bool try_lock()
{
throw 1;
TEST_THROW(1);
return locked_;
}

Expand Down Expand Up @@ -95,6 +96,7 @@ int main()
assert(!l0.locked());
assert(!l1.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L0 l0;
L2 l1;
Expand Down Expand Up @@ -123,6 +125,7 @@ int main()
assert(!l1.locked());
}
}
#endif
#ifndef _LIBCPP_HAS_NO_VARIADICS
{
L0 l0;
Expand All @@ -142,6 +145,7 @@ int main()
assert(!l1.locked());
assert(!l2.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L2 l0;
L2 l1;
Expand All @@ -167,6 +171,7 @@ int main()
assert(!l1.locked());
assert(!l2.locked());
}
#endif
{
L0 l0;
L0 l1;
Expand Down Expand Up @@ -194,6 +199,7 @@ int main()
assert(!l1.locked());
assert(!l2.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L0 l0;
L0 l1;
Expand Down Expand Up @@ -242,6 +248,7 @@ int main()
assert(!l2.locked());
}
}
#endif
{
L1 l0;
L1 l1;
Expand Down Expand Up @@ -269,6 +276,7 @@ int main()
assert(!l1.locked());
assert(!l2.locked());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
L1 l0;
L1 l1;
Expand Down Expand Up @@ -458,6 +466,7 @@ int main()
assert(!l2.locked());
}
}
#endif // TEST_HAS_NO_EXCEPTIONS
{
L0 l0;
L0 l1;
Expand Down
Expand Up @@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
//
// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads
// UNSUPPORTED: c++98, c++03, c++11

Expand Down Expand Up @@ -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();
Expand All @@ -63,8 +63,10 @@ void f()
{
assert(e.code().value() == EDEADLK);
}
#endif
lk.unlock();
lk.release();
#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
lk.lock();
Expand All @@ -74,6 +76,7 @@ void f()
{
assert(e.code().value() == EPERM);
}
#endif
}

int main()
Expand Down
Expand Up @@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
//
// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads
// UNSUPPORTED: c++98, c++03, c++11

Expand All @@ -20,6 +19,8 @@
#include <shared_mutex>
#include <cassert>

#include "test_macros.h"

bool try_lock_called = false;

struct mutex
Expand All @@ -36,11 +37,11 @@ mutex m;

int main()
{

std::shared_lock<mutex> 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();
Expand All @@ -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();
Expand All @@ -64,4 +67,5 @@ int main()
{
assert(e.code().value() == EPERM);
}
#endif
}
Expand Up @@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
//
// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads
// UNSUPPORTED: c++98, c++03, c++11

Expand All @@ -21,6 +20,8 @@
#include <shared_mutex>
#include <cassert>

#include "test_macros.h"

bool try_lock_for_called = false;

typedef std::chrono::milliseconds ms;
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -68,4 +72,5 @@ int main()
{
assert(e.code().value() == EPERM);
}
#endif
}
Expand Up @@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
//
// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads
// UNSUPPORTED: c++98, c++03, c++11

Expand All @@ -21,6 +20,8 @@
#include <shared_mutex>
#include <cassert>

#include "test_macros.h"

bool try_lock_until_called = false;

struct mutex
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -68,4 +72,5 @@ int main()
{
assert(e.code().value() == EPERM);
}
#endif
}

0 comments on commit 60d6ef6

Please sign in to comment.