1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 * 8 * Test that timer_getoverrun() returns the number of overruns that 9 * have happened due to signals being sent from a timer. 10 * 11 * Steps (testing with just one overrun): 12 * - Block signal SIGCONT (SIGCONT used so test will not terminate) 13 * - Set up a timer to send SIGCONT on expiration with an interval 14 * of INTERVALSEC. 15 * - Wait for that timer to expire twice (wait VALUESEC + INTERVALSEC). 16 * - Call timer_getoverrun() and ensure 1 (EXPECTEDOVERRUNS) was returned. 17 * [First signal made it. Second signal was the overrun.] 18 */ 19 20 #include <signal.h> 21 #include <time.h> 22 #include <unistd.h> 23 #include <stdio.h> 24 #include "posixtest.h" 25 26 #define VALUESEC 3 27 #define INTERVALSEC 4 28 29 #define EXPECTEDOVERRUNS 2 30 31 int main(void) 32 { 33 sigset_t set; 34 struct sigevent ev; 35 timer_t tid; 36 struct itimerspec its; 37 int overruns; 38 39 if (sigemptyset(&set) != 0) { 40 perror("sigemptyset() did not return success\n"); 41 return PTS_UNRESOLVED; 42 } 43 44 if (sigaddset(&set, SIGCONT) != 0) { 45 perror("sigaddset() did not return success\n"); 46 return PTS_UNRESOLVED; 47 } 48 49 if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) { 50 perror("sigprocmask() did not return success\n"); 51 return PTS_UNRESOLVED; 52 } 53 54 ev.sigev_notify = SIGEV_SIGNAL; 55 ev.sigev_signo = SIGCONT; 56 57 /* 58 * create first timer 59 */ 60 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { 61 perror("timer_create() did not return success\n"); 62 return PTS_UNRESOLVED; 63 } 64 65 its.it_interval.tv_sec = INTERVALSEC; 66 its.it_interval.tv_nsec = 0; 67 its.it_value.tv_sec = VALUESEC; 68 its.it_value.tv_nsec = 0; 69 70 if (timer_settime(tid, 0, &its, NULL) != 0) { 71 perror("timer_settime() did not return success\n"); 72 return PTS_UNRESOLVED; 73 } 74 75 sleep(VALUESEC + 2 * INTERVALSEC + 1); 76 77 if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) { 78 perror("sigprocmask() did not return success\n"); 79 return PTS_UNRESOLVED; 80 } 81 82 overruns = timer_getoverrun(tid); 83 if (EXPECTEDOVERRUNS == overruns) { 84 printf("Test PASSED\n"); 85 return PTS_PASS; 86 } 87 88 printf("FAIL: %d overruns sent; expected %d\n", 89 overruns, EXPECTEDOVERRUNS); 90 return PTS_FAIL; 91 } 92