[libcxx-commits] [libcxx] a675c1d - [libcxx testing] Remove ALLOW_RETRIES from lock_guard tests

David Zarzycki via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 18 04:45:03 PDT 2020


Author: David Zarzycki
Date: 2020-05-18T07:44:16-04:00
New Revision: a675c1dee483129611794f37e0867f565181827b

URL: https://github.com/llvm/llvm-project/commit/a675c1dee483129611794f37e0867f565181827b
DIFF: https://github.com/llvm/llvm-project/commit/a675c1dee483129611794f37e0867f565181827b.diff

LOG: [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.

Added: 
    

Modified: 
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
index e42c16b31fcb..fcd883743eba 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
@@ -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;
 }

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp
index fc2230591aea..71a72ffd050e 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp
@@ -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;


        


More information about the libcxx-commits mailing list