From: Garrett C. <yan...@gm...> - 2012-05-26 23:53:52
|
1. The threshold was too low; setting it to 10 seconds and adding an overlap of 5 seconds ensures that the SIGALRM handler fires. 2. Add a perror call when clock_settime fails. 3. Remove spurious newlines in perror calls. Signed-off-by: Garrett Cooper <yan...@gm...> --- .../conformance/interfaces/clock_settime/4-2.c | 36 +++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-2.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-2.c index 75756fa..373aefd 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-2.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-2.c @@ -28,18 +28,17 @@ #define TIMEROFFSET 9 #define CLOCKOFFSET 4 -#define SHORTTIME 1 +#define SHORTTIME 10 #define SIGTOTEST SIGALRM +int test_passed; + struct timespec tpreset; void handler(int signo) { - printf("Caught signal\n"); - printf("Test PASSED\n"); - setBackTime(tpreset); - exit(PTS_PASS); + test_passed = 1; } int main(int argc, char *argv[]) @@ -62,22 +61,22 @@ int main(int argc, char *argv[]) act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { - perror("sigemptyset() was not successful\n"); + perror("sigemptyset() was not successful"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) != 0) { - perror("sigaction() was not successful\n"); + perror("sigaction() was not successful"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tpT0) != 0) { - perror("clock_gettime() was not successful\n"); + perror("clock_gettime() was not successful"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { - perror("timer_create() did not return success\n"); + perror("timer_create() did not return success"); return PTS_UNRESOLVED; } @@ -87,7 +86,7 @@ int main(int argc, char *argv[]) its.it_value.tv_sec = tpT0.tv_sec + TIMEROFFSET; its.it_value.tv_nsec = tpT0.tv_nsec; if (timer_settime(tid, flags, &its, NULL) != 0) { - perror("timer_settime() did not return success\n"); + perror("timer_settime() did not return success"); return PTS_UNRESOLVED; } @@ -95,13 +94,18 @@ int main(int argc, char *argv[]) tpclock.tv_nsec = its.it_value.tv_nsec; getBeforeTime(&tpreset); if (clock_settime(CLOCK_REALTIME, &tpclock) != 0) { - printf("clock_settime() was not successful\n"); + perror("clock_settime() was not successful"); return PTS_UNRESOLVED; } - sleep(SHORTTIME); - printf("timer should have expired _immediately_\n"); - tpreset.tv_sec += SHORTTIME; + sleep(1.5*SHORTTIME); + if (test_passed) { + printf("Caught signal\n"); + printf("Test PASSED\n"); + } else { + printf("timer should have expired _immediately_\n"); + tpreset.tv_sec += SHORTTIME; + } setBackTime(tpreset); - return PTS_FAIL; -} \ No newline at end of file + exit(test_passed ? PTS_PASS : PTS_FAIL); +} |
From: Cyril H. <ch...@su...> - 2012-05-31 12:52:18
|
Hi! > 1. The threshold was too low; setting it to 10 seconds and adding an > overlap of 5 seconds ensures that the SIGALRM handler fires. I do not agree with this part. The system time is set four seconds after the created timer expiration time and because of that the signal hanlder must be called immediately after that change (unless machine is under heavy load, of course). Looking at the code more closely, I'm not sure if it's a good idea to mix sleep() (which may be implemented via SIGALRM) and timers that cause SIGALRM too. The POSIX seems to say that it's not specified if signal handler will be called in such case, only the interruption of sleep() is guaranteed. -- Cyril Hrubis ch...@su... |