blob: d1b5eed65cd3a29a77a9b80014e44a3ab0b23106 [file] [log] [blame]
Garrett Cooper2c282152010-12-16 00:55:50 -08001/*
robbiew0dc07652005-06-03 16:29:48 +00002 * 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 Cooper2c282152010-12-16 00:55:50 -08005 * of this license, see the COPYING file at the top level of this
robbiew0dc07652005-06-03 16:29:48 +00006 * source tree.
Garrett Cooper2c282152010-12-16 00:55:50 -08007 *
robbiew0dc07652005-06-03 16:29:48 +00008 * 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
31int 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 Cooper2c282152010-12-16 00:55:50 -080081
robbiew0dc07652005-06-03 16:29:48 +000082 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;
Chris Dearmanec6edca2012-10-17 19:54:01 -070094}