[libcxx testing] Remove ALLOW_RETRIES from lock_guard tests

These two tests were clumsily using time measurements to determine
whether std::lock_guard was working correctly. In practice, this
approach merely verified that the underlying lock properly waits.

Now these two tests verify that lock is acquired, not dropped
prematurely, and finally, actually dropped at the end of the scope.
This commit is contained in:
David Zarzycki 2020-05-18 07:39:12 -04:00
parent 87b235db63
commit a675c1dee4
2 changed files with 14 additions and 52 deletions

View File

@ -8,8 +8,6 @@
//
// UNSUPPORTED: libcpp-has-no-threads
// ALLOW_RETRIES: 2
// <mutex>
// template <class Mutex> class lock_guard;
@ -17,7 +15,6 @@
// lock_guard(mutex_type& m, adopt_lock_t);
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
@ -25,32 +22,16 @@
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
int main()
{
time_point t0 = Clock::now();
time_point t1;
{
{
m.lock();
std::lock_guard<std::mutex> lg(m, std::adopt_lock);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
assert(d < ms(50)); // within 50ms
}
assert(m.try_lock() == false);
}
int main(int, char**)
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
m.lock();
m.unlock();
return 0;
}

View File

@ -8,8 +8,6 @@
//
// UNSUPPORTED: libcpp-has-no-threads
// ALLOW_RETRIES: 2
// <mutex>
// template <class Mutex> class lock_guard;
@ -20,7 +18,6 @@
// -> lock_guard<_Mutex>; // C++17
#include <mutex>
#include <thread>
#include <cstdlib>
#include <cassert>
@ -28,35 +25,19 @@
std::mutex m;
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;
typedef std::chrono::nanoseconds ns;
void f()
int main()
{
time_point t0 = Clock::now();
time_point t1;
{
{
std::lock_guard<std::mutex> lg(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
assert(d < ms(200)); // within 200ms
}
assert(m.try_lock() == false);
}
int main(int, char**)
{
m.lock();
std::thread t(f);
std::this_thread::sleep_for(ms(250));
m.unlock();
t.join();
m.lock();
m.unlock();
#ifdef __cpp_deduction_guides
std::lock_guard lg(m);
static_assert((std::is_same<decltype(lg), std::lock_guard<decltype(m)>>::value), "" );
std::lock_guard lg(m);
static_assert((std::is_same<decltype(lg), std::lock_guard<decltype(m)>>::value), "" );
#endif
return 0;