Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 1 | /* |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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 |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 5 | * of this license, see the COPYING file at the top level of this |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 6 | * source tree. |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 7 | * |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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() |
| 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 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 81 | |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 82 | overruns = timer_getoverrun(tid); |
| 83 | if (EXPECTEDOVERRUNS == overruns) { |
| 84 | printf("Test PASSED\n"); |
| 85 | return PTS_PASS; |
| 86 | } else { |
| 87 | printf("FAIL: %d overruns sent; expected %d\n", |
| 88 | overruns, EXPECTEDOVERRUNS); |
| 89 | return PTS_FAIL; |
| 90 | } |
| 91 | |
| 92 | printf("UNRESOLVED: This code should not be executed.\n"); |
| 93 | return PTS_UNRESOLVED; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 94 | } |