summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-12-03 10:52:38 +0000
committerChris Wilson <chris+github@qwirx.com>2006-12-03 10:52:38 +0000
commitbc82918ca28737fc934c33b69e13bb2efb28d89e (patch)
treebc2b1fdffae020262218882074e4d013d3f087bb
parent3728ab83d06d0e4e7f1739ec4e7480aaeaf0846d (diff)
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).
-rw-r--r--test/common/testcommon.cpp17
1 files changed, 14 insertions, 3 deletions
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 <errno.h>
#include <stdio.h>
+#include <time.h>
#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());