diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c index 56ffbbd..3553f20 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c @@ -10,8 +10,6 @@ * Same test as 1-1.c. */ -#define _XOPEN_SOURCE 600 - #include #include #include @@ -21,12 +19,13 @@ #define SIGTOTEST SIGALRM #define TIMERSEC 2 -#define SLEEPDELTA 3 #define ACCEPTABLEDELTA 1 -void handler(int signo) +static int endflg = 0; + +static void handler(int signo) { - printf("Caught signal\n"); + endflg = 1; } int main(int argc, char *argv[]) @@ -39,33 +38,33 @@ int main(int argc, char *argv[]) struct sigaction act; timer_t tid; struct itimerspec its; - struct timespec ts, tsleft; + struct timespec tstart, tstop; int rc; rc = sysconf(_SC_CPUTIME); printf("sysconf(_SC_CPUTIME) returns: %d\n", rc); - if (rc <= 0) { - return PTS_UNRESOLVED; + + if (rc == -1) { + printf("_POSIX_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; } - + ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; - act.sa_handler=handler; - act.sa_flags=0; + act.sa_handler = handler; + act.sa_flags = 0; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; - ts.tv_sec=TIMERSEC+SLEEPDELTA; - ts.tv_nsec=0; - if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset"); return PTS_UNRESOLVED; } + if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction"); return PTS_UNRESOLVED; @@ -76,23 +75,34 @@ int main(int argc, char *argv[]) return PTS_UNRESOLVED; } + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstart) != 0) { + perror("clock_gettime() failed"); + return PTS_UNRESOLVED; + } + if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success"); return PTS_UNRESOLVED; } - if (nanosleep(&ts, &tsleft) != -1) { - perror("nanosleep() not interrupted"); - return PTS_FAIL; + /* + * We need to bussy loop here as the timer is set to wait for 2 seconds + * of cputime of this process (which doesn't tick in any sleep function) + */ + while (!endflg); + + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstop) != 0) { + perror("clock_gettime() failed"); + return PTS_UNRESOLVED; } - if (abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) { - printf("Test PASSED"); + if (abs(tstop.tv_sec - tstart.tv_sec - TIMERSEC) <= ACCEPTABLEDELTA) { + printf("Test PASSED\n"); return PTS_PASS; } else { printf("Timer did not last for correct amount of time\n"); printf("timer: %d != correct %d\n", - (int) ts.tv_sec- (int) tsleft.tv_sec, + (int) tstop.tv_sec - tstart.tv_sec, TIMERSEC); return PTS_FAIL; } diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c index 83e87e4..b703a16 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c @@ -19,26 +19,30 @@ #define SIGTOTEST SIGALRM #define TIMERSEC 2 -#define SLEEPDELTA 3 #define ACCEPTABLEDELTA 1 -void handler(int signo) +static int endflg = 0; + +static void handler(int signo) { - printf("Caught signal\n"); + endflg = 1; } int main(int argc, char *argv[]) { - int rc; - rc = sysconf(_SC_THREAD_CPUTIME); - printf("rc = %d\n", rc); - -#if _POSIX_THREAD_CPUTIME != -1 +#if _POSIX_THREAD_CPUTIME == -1 + printf("_POSIX_THREAD_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; +#else struct sigevent ev; struct sigaction act; timer_t tid; struct itimerspec its; - struct timespec ts, tsleft; + struct timespec tstart, tstop; + int rc; + + rc = sysconf(_SC_THREAD_CPUTIME); + printf("sysconf(_SC_THREAD_CPUTIME) returns: %d\n", rc); if (rc == -1) { printf("_POSIX_THREAD_CPUTIME unsupported\n"); @@ -48,21 +52,19 @@ int main(int argc, char *argv[]) ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; - act.sa_handler=handler; - act.sa_flags=0; + act.sa_handler = handler; + act.sa_flags = 0; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; - ts.tv_sec=TIMERSEC+SLEEPDELTA; - ts.tv_nsec=0; - if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset"); return PTS_UNRESOLVED; } + if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction"); return PTS_UNRESOLVED; @@ -73,31 +75,38 @@ int main(int argc, char *argv[]) return PTS_UNRESOLVED; } + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstart) != 0) { + perror("clock_gettime() failed"); + return PTS_UNRESOLVED; + } + if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success"); return PTS_UNRESOLVED; } - if (nanosleep(&ts, &tsleft) != -1) { - perror("nanosleep() not interrupted"); - return PTS_FAIL; + /* + * We need to bussy loop here as the timer is set to wait for 2 seconds + * of cputime of this process (which doesn't tick in any sleep function) + */ + while (!endflg); + + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstop) != 0) { + perror("clock_gettime() failed"); + return PTS_UNRESOLVED; } - if (abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) { - printf("Test PASSED"); + if (abs(tstop.tv_sec - tstart.tv_sec - TIMERSEC) <= ACCEPTABLEDELTA) { + printf("Test PASSED\n"); return PTS_PASS; } else { printf("Timer did not last for correct amount of time\n"); printf("timer: %d != correct %d\n", - (int) ts.tv_sec- (int) tsleft.tv_sec, + (int) tstop.tv_sec - tstart.tv_sec, TIMERSEC); return PTS_FAIL; } return PTS_UNRESOLVED; -#else - printf("_POSIX_THREAD_CPUTIME unsupported\n"); - return PTS_UNSUPPORTED; #endif - }