From bc82918ca28737fc934c33b69e13bb2efb28d89e Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 3 Dec 2006 10:52:38 +0000 Subject: Make the timer test reliable by using nanosleep() instead of sleep(), since sleep() may use signals and interfere with SIGALRM, and also cannot be resumed if interrupted by a signal. (refs #3, refs #9). --- test/common/testcommon.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'test/common') diff --git a/test/common/testcommon.cpp b/test/common/testcommon.cpp index 04d93bb2..bac26ff3 100644 --- a/test/common/testcommon.cpp +++ b/test/common/testcommon.cpp @@ -9,7 +9,9 @@ #include "Box.h" +#include #include +#include #include "Test.h" #include "Configuration.h" @@ -134,6 +136,15 @@ ConfigurationVerify verify = 0 }; +void safe_sleep(int seconds) +{ + struct timespec ts; + ts.tv_sec = seconds; + ts.tv_nsec = 0; + while (nanosleep(&ts, &ts) == -1 && errno == EINTR) + { /* sleep again */ } +} + int test(int argc, const char *argv[]) { // Test self-deleting temporary file streams @@ -254,13 +265,13 @@ int test(int argc, const char *argv[]) TEST_THAT(!t2.HasExpired()); TEST_THAT(!t3.HasExpired()); - sleep(1); + safe_sleep(1); TEST_THAT(!t0.HasExpired()); TEST_THAT(t1.HasExpired()); TEST_THAT(!t2.HasExpired()); TEST_THAT(!t3.HasExpired()); - sleep(1); + safe_sleep(1); TEST_THAT(!t0.HasExpired()); TEST_THAT(t1.HasExpired()); TEST_THAT(t2.HasExpired()); @@ -272,7 +283,7 @@ int test(int argc, const char *argv[]) TEST_THAT(!t1.HasExpired()); TEST_THAT(!t2.HasExpired()); - sleep(1); + safe_sleep(1); TEST_THAT(!t0.HasExpired()); TEST_THAT(t1.HasExpired()); TEST_THAT(!t2.HasExpired()); -- cgit v1.2.3