15 #include "absl/time/clock.h"
17 #include "absl/base/config.h"
18 #if defined(ABSL_HAVE_ALARM)
23 typedef void (*sig_t)(
int);
25 #elif defined(__linux__) || defined(__APPLE__)
26 #error all known Linux and Apple targets have alarm
29 #include "gtest/gtest.h"
30 #include "absl/time/time.h"
42 enum class AlarmPolicy { kWithoutAlarm, kWithAlarm };
44 #if defined(ABSL_HAVE_ALARM)
45 bool alarm_handler_invoked =
false;
47 void AlarmHandler(
int signo) {
49 alarm_handler_invoked =
true;
58 AlarmPolicy alarm_policy,
int* attempts) {
61 #if defined(ABSL_HAVE_ALARM)
62 sig_t old_alarm = SIG_DFL;
63 if (alarm_policy == AlarmPolicy::kWithAlarm) {
64 alarm_handler_invoked =
false;
65 old_alarm =
signal(SIGALRM, AlarmHandler);
69 EXPECT_EQ(alarm_policy, AlarmPolicy::kWithoutAlarm);
75 #if defined(ABSL_HAVE_ALARM)
76 if (alarm_policy == AlarmPolicy::kWithAlarm) {
77 signal(SIGALRM, old_alarm);
78 if (!alarm_handler_invoked)
continue;
81 if (lower_bound <= actual && actual <= upper_bound) {
92 AlarmPolicy alarm_policy) {
96 if (SleepForBounded(
d, lower_bound, upper_bound,
timeout, alarm_policy,
101 <<
"SleepFor(" <<
d <<
") did not return within [" << lower_bound
102 <<
":" << upper_bound <<
"] in " << attempts <<
" attempt"
103 << (attempts == 1 ?
"" :
"s") <<
" over " <<
timeout
104 << (alarm_policy == AlarmPolicy::kWithAlarm ?
" with" :
" without")
115 AlarmPolicy::kWithoutAlarm));
116 #if defined(ABSL_HAVE_ALARM)
118 AlarmPolicy::kWithAlarm));