aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crowe <mac@mcrowe.com>2019-09-04 22:43:20 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2019-09-04 23:43:20 +0100
commit76e0dd66c87720a8a82a6d5f44ba4d8f63a51b1d (patch)
tree07d85350cadbc5a5a6b194b5e04f48dfbd6897a3
parent9eb730b8391794c7d451c7fde661b18ccacfbc3a (diff)
downloadgcc-76e0dd66c87720a8a82a6d5f44ba4d8f63a51b1d.zip
gcc-76e0dd66c87720a8a82a6d5f44ba4d8f63a51b1d.tar.gz
gcc-76e0dd66c87720a8a82a6d5f44ba4d8f63a51b1d.tar.bz2
Add user-defined clock to libstdc++ condition_variable tests
2019-09-04 Mike Crowe <mac@mcrowe.com> * testsuite/30_threads/condition_variable/members/2.cc (test01): Parameterise so that test can be run against an arbitrary clock. (main): Test using std::chrono::steady_clock and a user-defined clock in addition to the previous std::chrono::system_clock. * testsuite/30_threads/condition_variable_any/members/2.cc: Likewise. From-SVN: r275389
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc39
-rw-r--r--libstdc++-v3/testsuite/30_threads/condition_variable_any/members/2.cc30
3 files changed, 69 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index b130f0f..678706d 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2019-09-04 Mike Crowe <mac@mcrowe.com>
+
+ * testsuite/30_threads/condition_variable/members/2.cc (test01):
+ Parameterise so that test can be run against an arbitrary clock.
+ (main): Test using std::chrono::steady_clock and a user-defined
+ clock in addition to the previous std::chrono::system_clock.
+ * testsuite/30_threads/condition_variable_any/members/2.cc: Likewise.
+
2019-09-03 Ulrich Weigand <uweigand@de.ibm.com>
* crossconfig.m4: Remove references to spu.
diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc b/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
index 0ecb09d..cbac3fa 100644
--- a/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
+++ b/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
@@ -26,6 +26,7 @@
#include <system_error>
#include <testsuite_hooks.h>
+template <typename ClockType>
void test01()
{
try
@@ -35,10 +36,10 @@ void test01()
std::mutex m;
std::unique_lock<std::mutex> l(m);
- auto then = std::chrono::steady_clock::now();
+ auto then = ClockType::now();
std::cv_status result = c1.wait_until(l, then + ms);
VERIFY( result == std::cv_status::timeout );
- VERIFY( (std::chrono::steady_clock::now() - then) >= ms );
+ VERIFY( (ClockType::now() - then) >= ms );
VERIFY( l.owns_lock() );
}
catch (const std::system_error& e)
@@ -102,9 +103,39 @@ void test01_alternate_clock()
}
}
+/* User defined clock that ticks in two-thousandths of a second
+ forty-two minutes ahead of steady_clock. */
+struct user_defined_clock
+{
+ typedef std::chrono::steady_clock::rep rep;
+ typedef std::ratio<1, 2000> period;
+ typedef std::chrono::duration<rep, period> duration;
+ typedef std::chrono::time_point<user_defined_clock> time_point;
+
+ static constexpr bool is_steady = true;
+
+ static time_point now() noexcept
+ {
+ using namespace std::chrono;
+ const auto steady_since_epoch = steady_clock::now().time_since_epoch();
+ const auto user_since_epoch = duration_cast<duration>(steady_since_epoch);
+ return time_point(user_since_epoch + minutes(42));
+ }
+};
+
+/*
+It's not possible for this test to automatically ensure that the
+system_clock test cases result in a wait on CLOCK_REALTIME and steady_clock
+test cases result in a wait on CLOCK_MONOTONIC. It's recommended to run the
+test under strace(1) and check whether the expected futex calls are made by
+glibc. See https://gcc.gnu.org/ml/libstdc++/2019-09/msg00022.html for
+instructions.
+*/
+
int main()
{
- test01();
+ test01<std::chrono::steady_clock>();
+ test01<std::chrono::system_clock>();
+ test01<user_defined_clock>();
test01_alternate_clock();
- return 0;
}
diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/members/2.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/members/2.cc
index e6fbc44..897fa86 100644
--- a/libstdc++-v3/testsuite/30_threads/condition_variable_any/members/2.cc
+++ b/libstdc++-v3/testsuite/30_threads/condition_variable_any/members/2.cc
@@ -51,6 +51,7 @@ struct Mutex
};
+template <typename ClockType>
void test01()
{
try
@@ -60,10 +61,10 @@ void test01()
Mutex m;
m.lock();
- auto then = std::chrono::steady_clock::now();
+ auto then = ClockType::now();
std::cv_status result = c1.wait_until(m, then + ms);
VERIFY( result == std::cv_status::timeout );
- VERIFY( (std::chrono::steady_clock::now() - then) >= ms );
+ VERIFY( (ClockType::now() - then) >= ms );
VERIFY( m.locked );
}
catch (const std::system_error& e)
@@ -76,8 +77,29 @@ void test01()
}
}
+/* User defined clock that ticks in two-thousandths of a second
+ forty-two minutes ahead of steady_clock. */
+struct user_defined_clock
+{
+ typedef std::chrono::steady_clock::rep rep;
+ typedef std::ratio<1, 2000> period;
+ typedef std::chrono::duration<rep, period> duration;
+ typedef std::chrono::time_point<user_defined_clock> time_point;
+
+ static constexpr bool is_steady = true;
+
+ static time_point now() noexcept
+ {
+ using namespace std::chrono;
+ const auto steady_since_epoch = steady_clock::now().time_since_epoch();
+ const auto user_since_epoch = duration_cast<duration>(steady_since_epoch);
+ return time_point(user_since_epoch + minutes(42));
+ }
+};
+
int main()
{
- test01();
- return 0;
+ test01<std::chrono::steady_clock>();
+ test01<std::chrono::system_clock>();
+ test01<user_defined_clock>();
}