diff options
author | Dean Deng <deandeng@google.com> | 2020-10-16 14:30:19 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-10-16 14:32:49 -0700 |
commit | 4ddb58f6efb3b0bfcce40f8d126973701db89c4b (patch) | |
tree | 4d9f4f2586b8c49a49bc9ba660c0d2efee188ea3 /test/util/timer_util.cc | |
parent | dffa4c66909f034429e933f204cd49655c3e224f (diff) |
Use POSIX interval timers in flock test.
ualarm(2) is obsolete. Move IntervalTimer into a test util, where it can be
used by flock tests.
These tests were flaky with TSAN, probably because it slowed the tests down
enough that the alarm was expiring before flock() was called. Use an interval
timer so that even if we miss the first alarm (or more), flock() is still
guaranteed to be interrupted.
PiperOrigin-RevId: 337578751
Diffstat (limited to 'test/util/timer_util.cc')
-rw-r--r-- | test/util/timer_util.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/util/timer_util.cc b/test/util/timer_util.cc index 43a26b0d3..75cfc4f40 100644 --- a/test/util/timer_util.cc +++ b/test/util/timer_util.cc @@ -23,5 +23,23 @@ absl::Time Now(clockid_t id) { return absl::TimeFromTimespec(now); } +#ifdef __linux__ + +PosixErrorOr<IntervalTimer> TimerCreate(clockid_t clockid, + const struct sigevent& sev) { + int timerid; + int ret = syscall(SYS_timer_create, clockid, &sev, &timerid); + if (ret < 0) { + return PosixError(errno, "timer_create"); + } + if (ret > 0) { + return PosixError(EINVAL, "timer_create should never return positive"); + } + MaybeSave(); + return IntervalTimer(timerid); +} + +#endif // __linux__ + } // namespace testing } // namespace gvisor |