15 #include "absl/time/clock.h"
17 #include "absl/base/config.h"
18 #if defined(ABSL_HAVE_ALARM)
21 #elif defined(__linux__) || defined(__APPLE__)
22 #error all known Linux and Apple targets have alarm
25 #include "gtest/gtest.h"
26 #include "absl/time/time.h"
38 enum class AlarmPolicy { kWithoutAlarm, kWithAlarm };
40 #if defined(ABSL_HAVE_ALARM)
41 bool alarm_handler_invoked =
false;
43 void AlarmHandler(
int signo) {
45 alarm_handler_invoked =
true;
54 AlarmPolicy alarm_policy,
int* attempts) {
57 #if defined(ABSL_HAVE_ALARM)
58 sig_t old_alarm = SIG_DFL;
59 if (alarm_policy == AlarmPolicy::kWithAlarm) {
60 alarm_handler_invoked =
false;
61 old_alarm =
signal(SIGALRM, AlarmHandler);
65 EXPECT_EQ(alarm_policy, AlarmPolicy::kWithoutAlarm);
71 #if defined(ABSL_HAVE_ALARM)
72 if (alarm_policy == AlarmPolicy::kWithAlarm) {
73 signal(SIGALRM, old_alarm);
74 if (!alarm_handler_invoked)
continue;
77 if (lower_bound <= actual && actual <= upper_bound) {
88 AlarmPolicy alarm_policy) {
92 if (SleepForBounded(
d, lower_bound, upper_bound,
timeout, alarm_policy,
97 <<
"SleepFor(" <<
d <<
") did not return within [" << lower_bound
98 <<
":" << upper_bound <<
"] in " << attempts <<
" attempt"
99 << (attempts == 1 ?
"" :
"s") <<
" over " <<
timeout
100 << (alarm_policy == AlarmPolicy::kWithAlarm ?
" with" :
" without")
111 AlarmPolicy::kWithoutAlarm));
112 #if defined(ABSL_HAVE_ALARM)
114 AlarmPolicy::kWithAlarm));