subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +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 | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 17 | /* */ |
| 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
| 20 | /* */ |
| 21 | /* File: timer_gettime01.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the timer_gettime() syscall */ |
| 24 | /* */ |
| 25 | /* Usage: <for command-line> */ |
| 26 | /* timer_gettime01 [-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_gettime01 */ |
| 37 | /* History: Porting from Crackerjack to LTP is done by */ |
| 38 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
| 39 | /******************************************************************************/ |
| 40 | #include <time.h> |
| 41 | #include <signal.h> |
| 42 | #include <syscall.h> |
| 43 | #include <stdio.h> |
| 44 | #include <errno.h> |
| 45 | |
| 46 | /* Harness Specific Include Files. */ |
| 47 | #include "test.h" |
| 48 | #include "usctest.h" |
| 49 | #include "linux_syscall_numbers.h" |
| 50 | |
Subrata Modak | 4e94765 | 2010-05-28 12:50:38 +0530 | [diff] [blame] | 51 | /* timer_t in kernel(int) is different from Glibc definition(void*). |
| 52 | * Use the kernel definition. |
| 53 | */ |
| 54 | typedef int kernel_timer_t; |
| 55 | |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 56 | /* Extern Global Variables */ |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 57 | |
| 58 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 59 | char *TCID = "timer_gettime01"; /* Test program identifier. */ |
| 60 | int testno; |
| 61 | int TST_TOTAL = 3; /* total number of tests in this file. */ |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 62 | |
| 63 | /* Extern Global Functions */ |
| 64 | /******************************************************************************/ |
| 65 | /* */ |
| 66 | /* Function: cleanup */ |
| 67 | /* */ |
| 68 | /* Description: Performs all one time clean up for this test on successful */ |
| 69 | /* completion, premature exit or failure. Closes all temporary */ |
| 70 | /* files, removes all temporary directories exits the test with */ |
| 71 | /* appropriate return code by calling tst_exit() function. */ |
| 72 | /* */ |
| 73 | /* Input: None. */ |
| 74 | /* */ |
| 75 | /* Output: None. */ |
| 76 | /* */ |
| 77 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 78 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 79 | /* */ |
| 80 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | extern void cleanup() |
| 82 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 83 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 84 | TEST_CLEANUP; |
| 85 | tst_rmdir(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 86 | |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* Local Functions */ |
| 90 | /******************************************************************************/ |
| 91 | /* */ |
| 92 | /* Function: setup */ |
| 93 | /* */ |
| 94 | /* Description: Performs all one time setup for this test. This function is */ |
| 95 | /* typically used to capture signals, create temporary dirs */ |
| 96 | /* and temporary files that may be used in the course of this */ |
| 97 | /* test. */ |
| 98 | /* */ |
| 99 | /* Input: None. */ |
| 100 | /* */ |
| 101 | /* Output: None. */ |
| 102 | /* */ |
| 103 | /* Return: On failure - Exits by calling cleanup(). */ |
| 104 | /* On success - returns 0. */ |
| 105 | /* */ |
| 106 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 107 | void setup() |
| 108 | { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 109 | /* Capture signals if any */ |
| 110 | /* Create temporary directories */ |
| 111 | TEST_PAUSE; |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 112 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 113 | tst_tmpdir(); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | #define ENTER(normal) tst_resm(TINFO, "Enter block %d: test %d (%s)", \ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 117 | block, Tst_count, normal?"NORMAL":"ERROR"); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 118 | |
| 119 | char tmpname[40]; |
| 120 | int parent; |
| 121 | int block = 1; |
| 122 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | int main(int ac, char **av) |
| 124 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 125 | int lc; |
| 126 | char *msg; |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 127 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 128 | kernel_timer_t created_timer_id; |
| 129 | struct sigevent ev; |
| 130 | struct itimerspec spec; |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 131 | |
Garrett Cooper | e1f008e | 2010-12-14 00:21:59 -0800 | [diff] [blame] | 132 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 133 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 134 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 135 | setup(); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 136 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 137 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 138 | Tst_count = 0; |
| 139 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
| 140 | ENTER(1); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 141 | ev.sigev_value = (sigval_t) 0; |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 142 | ev.sigev_signo = SIGALRM; |
| 143 | ev.sigev_notify = SIGEV_SIGNAL; |
| 144 | TEST(syscall(__NR_timer_create, CLOCK_REALTIME, &ev, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | &created_timer_id)); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 146 | TEST(syscall(__NR_timer_gettime, created_timer_id, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 147 | &spec)); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 148 | if (TEST_RETURN == 0) { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 149 | tst_resm(TPASS, "Block %d: test %d PASSED", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 150 | block, Tst_count); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 151 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 152 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 153 | "Block %d: test %d FAILED", |
| 154 | block, Tst_count); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 155 | } |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 156 | |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 157 | /* |
| 158 | |
| 159 | ERRORS |
| 160 | -EINVAL |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 161 | An invalid timer_id value was specified. |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 162 | */ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 163 | ENTER(0); |
| 164 | TEST(syscall(__NR_timer_gettime, -1, &spec)); |
| 165 | if (TEST_RETURN < 0 && TEST_ERRNO == EINVAL) { |
| 166 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 167 | "Block %d: test %d PASSED", |
| 168 | block, Tst_count); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 169 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 170 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 171 | "Block %d: test %d FAILED", |
| 172 | block, Tst_count); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 173 | } |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | |
| 177 | -EFAULT |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 178 | An invalid address of setting was specified. |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 179 | */ |
| 180 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 181 | ENTER(0); |
| 182 | TEST(syscall(__NR_timer_gettime, created_timer_id, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 183 | NULL)); |
| 184 | if (TEST_RETURN < 0 && TEST_ERRNO == EFAULT) { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 185 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 186 | "Block %d: test %d PASSED", |
| 187 | block, Tst_count); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 188 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 189 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 190 | "Block %d: test %d FAILED", |
| 191 | block, Tst_count); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 192 | } |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 193 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 194 | } |
| 195 | } |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 196 | |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 197 | cleanup(); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 198 | tst_exit(); |
subrata_modak | 1f2aeea | 2009-05-21 18:43:48 +0000 | [diff] [blame] | 199 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 200 | } |