[libcxx-commits] [libcxx] f8013a3 - [libcxx] [test] Make the condvar wait_for tests a bit more understandable. NFC.

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 2 00:56:28 PDT 2021


Author: Martin Storsjö
Date: 2021-04-02T10:46:15+03:00
New Revision: f8013a35b6fb02ad35008c373f7b06a24b5dd8e4

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

LOG: [libcxx] [test] Make the condvar wait_for tests a bit more understandable. NFC.

This was requested in the review of D99175; rename the "runs"
variable to clarify what it means wrt the test, and move updating of
it to the main function to clarify its behaviour wrt the two runs
further.

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

Added: 
    

Modified: 
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
index a69ecfc1343c4..e0b9736c65b37 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
@@ -33,7 +33,7 @@ std::mutex mut;
 int test1 = 0;
 int test2 = 0;
 
-int runs = 0;
+bool expect_timeout = false;
 
 void f()
 {
@@ -51,7 +51,7 @@ void f()
         if (d <= milliseconds(0)) break;
     } while (test2 == 0 && cv.wait_for(lk, d) == std::cv_status::no_timeout);
     Clock::time_point t1 = Clock::now();
-    if (runs == 0)
+    if (!expect_timeout)
     {
         assert(t1 - t0 < milliseconds(250));
         assert(test2 != 0);
@@ -61,7 +61,6 @@ void f()
         assert(t1 - t0 - milliseconds(250) < milliseconds(50));
         assert(test2 == 0);
     }
-    ++runs;
 }
 
 int main(int, char**)
@@ -80,6 +79,7 @@ int main(int, char**)
     }
     test1 = 0;
     test2 = 0;
+    expect_timeout = true;
     {
         std::unique_lock<std::mutex> lk(mut);
         std::thread t = support::make_test_thread(f);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
index 0b5ef2cf10d7e..bbd93f22f5964 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
@@ -36,7 +36,7 @@ L0 m0;
 int test1 = 0;
 int test2 = 0;
 
-int runs = 0;
+bool expect_timeout = false;
 
 void f()
 {
@@ -54,7 +54,7 @@ void f()
         if (d <= milliseconds(0)) break;
     } while (test2 == 0 && cv.wait_for(lk, d) == std::cv_status::no_timeout);
     Clock::time_point t1 = Clock::now();
-    if (runs == 0)
+    if (!expect_timeout)
     {
         assert(t1 - t0 < milliseconds(250));
         assert(test2 != 0);
@@ -64,7 +64,6 @@ void f()
         assert(t1 - t0 - milliseconds(250) < milliseconds(50));
         assert(test2 == 0);
     }
-    ++runs;
 }
 
 int main(int, char**)
@@ -83,6 +82,7 @@ int main(int, char**)
     }
     test1 = 0;
     test2 = 0;
+    expect_timeout = true;
     {
         L1 lk(m0);
         std::thread t = support::make_test_thread(f);


        


More information about the libcxx-commits mailing list