[libcxx-commits] [PATCH] D99768: [libcxx] [test] Make the condvar wait_for tests a bit more understandable. NFC.
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Apr 1 13:56:35 PDT 2021
mstorsjo created this revision.
mstorsjo added a reviewer: Quuxplusone.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.
This was requested in the review of D99175 <https://reviews.llvm.org/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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99768
Files:
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
Index: libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
+++ libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
@@ -36,7 +36,7 @@
int test1 = 0;
int test2 = 0;
-int runs = 0;
+bool expect_timeout = false;
void f()
{
@@ -54,7 +54,7 @@
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 @@
assert(t1 - t0 - milliseconds(250) < milliseconds(50));
assert(test2 == 0);
}
- ++runs;
}
int main(int, char**)
@@ -83,6 +82,7 @@
}
test1 = 0;
test2 = 0;
+ expect_timeout = true;
{
L1 lk(m0);
std::thread t = support::make_test_thread(f);
Index: libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
+++ libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
@@ -33,7 +33,7 @@
int test1 = 0;
int test2 = 0;
-int runs = 0;
+bool expect_timeout = false;
void f()
{
@@ -51,7 +51,7 @@
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 @@
assert(t1 - t0 - milliseconds(250) < milliseconds(50));
assert(test2 == 0);
}
- ++runs;
}
int main(int, char**)
@@ -80,6 +79,7 @@
}
test1 = 0;
test2 = 0;
+ expect_timeout = true;
{
std::unique_lock<std::mutex> lk(mut);
std::thread t = support::make_test_thread(f);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99768.334822.patch
Type: text/x-patch
Size: 2196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210401/7a2122ab/attachment.bin>
More information about the libcxx-commits
mailing list