vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Wipro Technologies Ltd, 2003. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License along |
| 13 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 14 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 15 | * |
| 16 | */ |
| 17 | /************************************************************************** |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 18 | * |
| 19 | * TEST IDENTIFIER : timer_settime03 |
| 20 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 21 | * EXECUTED BY : anyone |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 22 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 23 | * TEST TITLE : Test checking for basic error conditions for |
| 24 | * timer_settime(2) |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 25 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 26 | * TEST CASE TOTAL : 6 |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 27 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 28 | * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com> |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 29 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 30 | * SIGNALS |
| 31 | * Uses SIGUSR1 to pause before test if option set. |
| 32 | * (See the parse_opts(3) man page). |
| 33 | * |
| 34 | * DESCRIPTION |
| 35 | * This test case check whether timer_settime(2) returns appropriate error |
| 36 | * value for invalid parameter |
| 37 | * |
| 38 | * Setup: |
| 39 | * Setup signal handling. |
| 40 | * Pause for SIGUSR1 if option specified. |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 41 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 42 | * Test: |
| 43 | * Loop if the proper options are given. |
| 44 | * setup the individual test. |
| 45 | * Execute system call with invalid parameters. |
| 46 | * Check return code, if system call fails with errno == expected errno |
| 47 | * Issue syscall passed with expected errno |
| 48 | * Otherwise, Issue syscall failed to produce expected errno |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 49 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 50 | * Cleanup: |
| 51 | * Print errno log and/or timing stats if options given |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 52 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 53 | * USAGE: <for command-line> |
| 54 | * timer_settime03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p] |
| 55 | * where: |
| 56 | * -c n : run n copies simultaneously |
| 57 | * -e : Turn on errno logging. |
| 58 | * -i n : Execute test n times. |
| 59 | * -I x : Execute test for x seconds. |
| 60 | * -p : Pause for SIGUSR1 before starting |
| 61 | * -P x : Pause for x seconds between iterations. |
| 62 | * -t : Turn on syscall timing. |
| 63 | * |
| 64 | * RESTRICTIONS: |
| 65 | * None |
| 66 | *****************************************************************************/ |
| 67 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 68 | #include <errno.h> |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 69 | #include <time.h> |
vapier | 8cf8104 | 2006-08-22 05:14:20 +0000 | [diff] [blame] | 70 | #include <unistd.h> |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 71 | |
vapier | 8cf8104 | 2006-08-22 05:14:20 +0000 | [diff] [blame] | 72 | #include "test.h" |
| 73 | #include "usctest.h" |
| 74 | #include "common_timers.h" |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 75 | |
Garrett Cooper | a9670cd | 2010-11-28 21:55:20 -0800 | [diff] [blame] | 76 | void setup(void); |
| 77 | void setup_test(int option); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 78 | |
| 79 | char *TCID = "timer_settime03"; /* Test program identifier. */ |
| 80 | int TST_TOTAL; /* Total number of test cases. */ |
| 81 | extern int Tst_count; /* Test Case counter for tst_* routines */ |
| 82 | |
| 83 | static struct itimerspec new_set, old_set, *old_temp, *new_temp; |
Subrata Modak | 4e94765 | 2010-05-28 12:50:38 +0530 | [diff] [blame] | 84 | static kernel_timer_t timer, tim; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 85 | |
| 86 | static int exp_enos[] = {EINVAL, EFAULT, 0}; |
| 87 | |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 88 | int testcase[] = { |
| 89 | EINVAL, /* New setting null */ |
| 90 | EINVAL, /* tv_nsec < 0 */ |
| 91 | EINVAL, /* nsec > NSEC/SEC */ |
| 92 | EINVAL, /* Invalid timerid */ |
| 93 | EFAULT, /* bad newsetting * */ |
| 94 | EFAULT /* bad oldsetting * */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 97 | int |
| 98 | main(int ac, char **av) |
| 99 | { |
| 100 | int lc, i; /* loop counter */ |
| 101 | char *msg; /* message returned from parse_opts */ |
| 102 | |
| 103 | /* parse standard options */ |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 104 | if ((msg = parse_opts(ac, av, NULL, NULL)) |
| 105 | != NULL) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame^] | 106 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* perform global setup for test */ |
| 110 | setup(); |
| 111 | |
| 112 | TST_TOTAL = sizeof(testcase) / sizeof(testcase[0]); |
| 113 | |
| 114 | /* check looping state if -i option given */ |
| 115 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 116 | |
| 117 | /* reset Tst_count in case we are looping. */ |
| 118 | Tst_count = 0; |
| 119 | |
| 120 | for (i = 0; i < TST_TOTAL; i++) { |
| 121 | |
| 122 | /* Set up individual tests */ |
vapier | 6670f84 | 2006-08-22 05:57:53 +0000 | [diff] [blame] | 123 | setup_test(i); |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 124 | TEST(syscall(__NR_timer_settime, tim, 0, new_temp, |
| 125 | old_temp)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 126 | |
| 127 | /* check return code */ |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 128 | if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) { |
| 129 | tst_resm(TPASS | TTERRNO, "failed as expected"); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 130 | } else { |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 131 | tst_resm(TFAIL | TTERRNO, |
| 132 | "didn't fail as expected [expected " |
| 133 | "errno = %d (%s)]", |
| 134 | testcase[i], strerror(testcase[i])); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 135 | } /* end of else */ |
| 136 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 137 | } /* End of TEST CASE LOOPING */ |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 138 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 139 | } /* End for TEST_LOOPING */ |
| 140 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 141 | cleanup(); |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 142 | tst_exit(); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* This function sets up individual tests */ |
Garrett Cooper | a9670cd | 2010-11-28 21:55:20 -0800 | [diff] [blame] | 146 | void |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 147 | setup_test(int option) |
| 148 | { |
| 149 | switch (option) { |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 150 | case 0: |
| 151 | /* Pass NULL structure as new setting */ |
| 152 | new_temp = (struct itimerspec *) NULL; |
| 153 | tim = timer; |
| 154 | old_temp = &old_set; |
| 155 | break; |
| 156 | case 1: |
| 157 | /* Make tv_nsec value less than 0 */ |
| 158 | new_set.it_value.tv_nsec = -1; |
| 159 | new_set.it_value.tv_sec = 5; |
| 160 | new_set.it_interval.tv_sec = 0; |
| 161 | new_set.it_interval.tv_nsec = 0; |
| 162 | new_temp = &new_set; |
| 163 | break; |
| 164 | case 2: |
| 165 | /* Make tv_nsec more than NSEC_PER_SEC */ |
| 166 | new_set.it_value.tv_nsec = NSEC_PER_SEC + 1; |
| 167 | break; |
| 168 | case 3: |
| 169 | /* make timer_id invalid */ |
Subrata Modak | 4e94765 | 2010-05-28 12:50:38 +0530 | [diff] [blame] | 170 | tim = (kernel_timer_t)-1; |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 171 | new_set.it_value.tv_nsec = 0; |
| 172 | break; |
| 173 | case 4: |
| 174 | /* make new_setting a bad pointer */ |
| 175 | tim = timer; |
| 176 | new_temp = (struct itimerspec *) -1; |
| 177 | break; |
| 178 | case 5: |
| 179 | /* make old_setting a bad pointer */ |
| 180 | new_temp = &new_set; |
| 181 | old_temp = (struct itimerspec *) -1; |
| 182 | break; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
| 186 | /* setup() - performs all ONE TIME setup for this test */ |
Garrett Cooper | a9670cd | 2010-11-28 21:55:20 -0800 | [diff] [blame] | 187 | void |
| 188 | setup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 189 | { |
| 190 | /* capture signals */ |
| 191 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 192 | |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 193 | if (syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame^] | 194 | tst_brkm(TBROK, NULL, "Timer create failed. Cannot" |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 195 | " setup test"); |
| 196 | } |
| 197 | |
| 198 | /* set the expected errnos... */ |
| 199 | TEST_EXP_ENOS(exp_enos); |
| 200 | /* Pause if that option was specified */ |
| 201 | TEST_PAUSE; |
Garrett Cooper | a9670cd | 2010-11-28 21:55:20 -0800 | [diff] [blame] | 202 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * cleanup() - Performs one time cleanup for this test at |
| 206 | * completion or premature exit |
| 207 | */ |
Garrett Cooper | a9670cd | 2010-11-28 21:55:20 -0800 | [diff] [blame] | 208 | void |
yaberauneya | 1a7f542 | 2009-12-06 20:53:42 +0000 | [diff] [blame] | 209 | cleanup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 210 | { |
| 211 | /* |
| 212 | * print timing stats if that option was specified. |
| 213 | * print errno log if that option was specified. |
| 214 | */ |
| 215 | TEST_CLEANUP; |
Garrett Cooper | a9670cd | 2010-11-28 21:55:20 -0800 | [diff] [blame] | 216 | } |