subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
| 4 | /* This program is free software; you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU General Public License as published by */ |
| 6 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 7 | /* (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* This program is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 12 | /* the GNU General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU General Public License */ |
| 15 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 17 | /* */ |
| 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
| 20 | /* */ |
| 21 | /* File: timer_getoverrun01.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the timer_getoverrun() syscall */ |
| 24 | /* */ |
| 25 | /* Usage: <for command-line> */ |
| 26 | /* timer_getoverrun01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 27 | /* where, -c n : Run n copies concurrently. */ |
| 28 | /* -e : Turn on errno logging. */ |
| 29 | /* -i n : Execute test n times. */ |
| 30 | /* -I x : Execute test for x seconds. */ |
| 31 | /* -P x : Pause for x seconds between iterations. */ |
| 32 | /* -t : Turn on syscall timing. */ |
| 33 | /* */ |
| 34 | /* Total Tests: 1 */ |
| 35 | /* */ |
| 36 | /* Test Name: timer_getoverrun01 */ |
| 37 | /* History: Porting from Crackerjack to LTP is done by */ |
| 38 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
| 39 | /******************************************************************************/ |
| 40 | |
| 41 | #include <stdio.h> |
| 42 | #include <errno.h> |
| 43 | #include <time.h> |
| 44 | #include <signal.h> |
| 45 | #include <syscall.h> |
| 46 | |
| 47 | /* Harness Specific Include Files. */ |
| 48 | #include "test.h" |
| 49 | #include "usctest.h" |
| 50 | #include "linux_syscall_numbers.h" |
| 51 | |
Subrata Modak | 4e94765 | 2010-05-28 12:50:38 +0530 | [diff] [blame] | 52 | /* timer_t in kernel(int) is different from Glibc definition(void*). |
| 53 | * Use the kernel definition. |
| 54 | */ |
| 55 | typedef int kernel_timer_t; |
| 56 | |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 57 | /* Extern Global Variables */ |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 58 | |
| 59 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 60 | char *TCID = "timer_getoverrun01"; /* Test program identifier. */ |
| 61 | int testno; |
| 62 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 63 | |
| 64 | /* Extern Global Functions */ |
| 65 | /******************************************************************************/ |
| 66 | /* */ |
| 67 | /* Function: cleanup */ |
| 68 | /* */ |
| 69 | /* Description: Performs all one time clean up for this test on successful */ |
| 70 | /* completion, premature exit or failure. Closes all temporary */ |
| 71 | /* files, removes all temporary directories exits the test with */ |
| 72 | /* appropriate return code by calling tst_exit() function. */ |
| 73 | /* */ |
| 74 | /* Input: None. */ |
| 75 | /* */ |
| 76 | /* Output: None. */ |
| 77 | /* */ |
| 78 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 79 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 80 | /* */ |
| 81 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 82 | extern void cleanup() |
| 83 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 84 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | TEST_CLEANUP; |
| 86 | tst_rmdir(); |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 87 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 88 | tst_exit(); |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* Local Functions */ |
| 92 | /******************************************************************************/ |
| 93 | /* */ |
| 94 | /* Function: setup */ |
| 95 | /* */ |
| 96 | /* Description: Performs all one time setup for this test. This function is */ |
| 97 | /* typically used to capture signals, create temporary dirs */ |
| 98 | /* and temporary files that may be used in the course of this */ |
| 99 | /* test. */ |
| 100 | /* */ |
| 101 | /* Input: None. */ |
| 102 | /* */ |
| 103 | /* Output: None. */ |
| 104 | /* */ |
| 105 | /* Return: On failure - Exits by calling cleanup(). */ |
| 106 | /* On success - returns 0. */ |
| 107 | /* */ |
| 108 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 109 | void setup() |
| 110 | { |
| 111 | /* Capture signals if any */ |
| 112 | /* Create temporary directories */ |
| 113 | TEST_PAUSE; |
| 114 | tst_tmpdir(); |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | char tmpname[40]; |
| 118 | int parent; |
| 119 | int block = 1; |
| 120 | |
| 121 | #define ENTER(normal) tst_resm(TINFO, "Enter block %d: test %d (%s)", \ |
| 122 | block, Tst_count, normal?"NORMAL":"ERROR"); |
| 123 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 124 | int main(int ac, char **av) |
| 125 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 126 | int lc; |
| 127 | char *msg; |
Subrata Modak | 4e94765 | 2010-05-28 12:50:38 +0530 | [diff] [blame] | 128 | kernel_timer_t created_timer_id; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 129 | struct sigevent ev; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 130 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 131 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
| 132 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 133 | tst_exit(); |
| 134 | } |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 135 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 136 | setup(); |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 137 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 138 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 139 | Tst_count = 0; |
| 140 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 141 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 142 | ev.sigev_value = (sigval_t) 0; |
| 143 | ev.sigev_signo = SIGALRM; |
| 144 | ev.sigev_notify = SIGEV_SIGNAL; |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 145 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 146 | TEST(ltp_syscall |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 147 | (__NR_timer_create, CLOCK_REALTIME, &ev, |
| 148 | &created_timer_id)); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 149 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 150 | ENTER(1); |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 151 | TEST(ltp_syscall(__NR_timer_getoverrun, |
| 152 | created_timer_id)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 153 | if (TEST_RETURN == 0) { |
| 154 | tst_resm(TPASS, "Block %d: test %d PASSED", |
| 155 | block, Tst_count); |
| 156 | } else { |
| 157 | tst_resm(TFAIL, |
| 158 | "Block %d: test %d FAILED... errno = %d : %s", |
| 159 | block, Tst_count, TEST_ERRNO, |
| 160 | strerror(TEST_ERRNO)); |
| 161 | cleanup(); |
| 162 | tst_exit(); |
| 163 | } |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 164 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 165 | ENTER(0); |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 166 | TEST(ltp_syscall(__NR_timer_getoverrun, -1)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 167 | if (TEST_RETURN < 0 && TEST_ERRNO == EINVAL) { |
| 168 | tst_resm(TPASS, "Block %d: test %d PASSED", |
| 169 | block, Tst_count); |
| 170 | } else { |
| 171 | tst_resm(TFAIL, |
| 172 | "Block %d: test %d FAILED... errno = %d : %s", |
| 173 | block, Tst_count, TEST_ERRNO, |
| 174 | strerror(TEST_ERRNO)); |
| 175 | cleanup(); |
| 176 | tst_exit(); |
| 177 | } |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 178 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 179 | } |
| 180 | } |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 181 | cleanup(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 182 | tst_exit(); |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 183 | } |
| 184 | |
subrata_modak | 0716875 | 2009-05-21 18:41:36 +0000 | [diff] [blame] | 185 | /* |
| 186 | |
| 187 | NAME |
| 188 | timer_getoverrun |
| 189 | SYNOPSIS |
| 190 | #include <time.h> |
| 191 | |
| 192 | int timer_getoverrun(timer_t timerid); |
| 193 | |
| 194 | Only a single signal shall be queued to the process for a given timer |
| 195 | at any point in time. When a timer for which a signal is still pending |
| 196 | expires, no signal shall be queued, and a timer overrun shall occur. |
| 197 | When a timer expiration signal is delivered to or accepted by a pro- |
| 198 | cess, if the implementation supports the Realtime Signals Extension, |
| 199 | the timer_getoverrun() function shall return the timer expiration |
| 200 | overrun count for the specified timer. The overrun count returned con- |
| 201 | tains the number of extra timer expirations that occurred between the |
| 202 | time the signal was generated (queued) and when it was delivered or |
| 203 | accepted, up to but not including an implementation-defined maximum of |
| 204 | {DELAYTIMER_MAX}. If the number of such extra expirations is greater |
| 205 | than or equal to {DELAYTIMER_MAX}, then the overrun count shall be set |
| 206 | to {DELAYTIMER_MAX}. The value returned by timer_getoverrun() shall |
| 207 | apply to the most recent expiration signal delivery or acceptance for |
| 208 | the timer. If no expiration signal has been delivered for the timer, |
| 209 | or if the Realtime Signals Extension is not supported, the return |
| 210 | value of timer_getoverrun() is unspecified. |
| 211 | |
| 212 | RETURN VALUE |
| 213 | If the timer_getoverrun() function succeeds, it shall return the timer |
| 214 | expiration overrun count as explained above. |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 215 | */ |