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., 14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 15 * 16 */ 17 /************************************************************************** 18 * 19 * TEST IDENTIFIER : timer_create04 20 * 21 * EXECUTED BY : anyone 22 * 23 * TEST TITLE : Test checking for basic error conditions for 24 * timer_create(2) 25 * 26 * TEST CASE TOTAL : 8 27 * 28 * AUTHOR : Aniruddha Marathe <aniruddha.marathe (at) wipro.com> 29 * 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_create(2) returns appropriate error 36 * value for invalid parameter 37 * 38 * Setup: 39 * Setup signal handling. 40 * Pause for SIGUSR1 if option specified. 41 * 42 * Test: 43 * Loop if the proper options are given. 44 * For case 7 set event parameter as bad pointer 45 * for case 8 set returned timer ID parameter as bad pointer 46 * Execute system call with invalid parameter 47 * Check return code, if system call fails with errno == expected errno 48 * Issue syscall passed with expected errno 49 * Otherwise, Issue syscall failed to produce expected errno 50 * 51 * Cleanup: 52 * Print errno log and/or timing stats if options given 53 * 54 * USAGE: <for command-line> 55 * timer_create04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p] 56 * where: 57 * -c n : run n copies simultaneously 58 * -e : Turn on errno logging. 59 * -i n : Execute test n times. 60 * -I x : Execute test for x seconds. 61 * -p : Pause for SIGUSR1 before starting 62 * -P x : Pause for x seconds between iterations. 63 * -t : Turn on syscall timing. 64 * 65 * RESTRICTIONS: 66 * None 67 *****************************************************************************/ 68 69 #include <stdlib.h> 70 #include <errno.h> 71 #include <string.h> 72 #include <time.h> 73 #include <signal.h> 74 75 #include "test.h" 76 #include "common_timers.h" 77 78 void setup(void); 79 80 int testcase[6] = { 81 EINVAL, /* MAX_CLOCKS */ 82 EINVAL, /* MAX_CLOCKS + 1 */ 83 EFAULT, /* bad sigevent */ 84 EFAULT /* bad timer_id */ 85 }; 86 87 char *TCID = "timer_create04"; /* Test program identifier. */ 88 int TST_TOTAL = ARRAY_SIZE(testcase); 89 90 /* 91 * cleanup() - Performs one time cleanup for this test at 92 * completion or premature exit 93 */ 94 void cleanup(void) 95 { 96 97 } 98 99 int main(int ac, char **av) 100 { 101 int lc, i; 102 kernel_timer_t timer_id, *temp_id; /* stores the returned timer_id */ 103 struct sigevent *temp_ev; /* used for bad address test case */ 104 105 clockid_t clocks[6] = { 106 MAX_CLOCKS, 107 MAX_CLOCKS + 1, 108 CLOCK_REALTIME, 109 CLOCK_MONOTONIC, 110 CLOCK_PROCESS_CPUTIME_ID, 111 CLOCK_THREAD_CPUTIME_ID 112 }; 113 114 tst_parse_opts(ac, av, NULL, NULL); 115 116 TST_TOTAL = sizeof(testcase) / sizeof(testcase[0]); 117 118 /* PROCESS_CPUTIME_ID & THREAD_CPUTIME_ID are not supported on 119 * kernel versions lower than 2.6.12 120 */ 121 if (tst_kvercmp(2, 6, 12) < 0) { 122 testcase[4] = EINVAL; 123 testcase[5] = EINVAL; 124 } else { 125 testcase[4] = EFAULT; 126 testcase[5] = EFAULT; 127 } 128 129 setup(); 130 131 for (lc = 0; TEST_LOOPING(lc); lc++) { 132 133 tst_count = 0; 134 135 for (i = 0; i < TST_TOTAL; i++) { 136 137 temp_ev = NULL; 138 temp_id = &timer_id; 139 140 switch (i) { 141 case 2: /* make the timer_id bad address */ 142 temp_id = (kernel_timer_t *) - 1; 143 break; 144 case 3: 145 /* make the event bad address */ 146 temp_ev = (struct sigevent *)-1; 147 break; 148 case 4: 149 /* Produce an invalid timer_id address. */ 150 if (tst_kvercmp(2, 6, 12) >= 0) 151 temp_id = (kernel_timer_t *) - 1; 152 break; 153 case 5: 154 /* Produce an invalid event address. */ 155 if (tst_kvercmp(2, 6, 12) >= 0) 156 temp_ev = (struct sigevent *)-1; 157 } 158 159 TEST(ltp_syscall(__NR_timer_create, clocks[i], temp_ev, 160 temp_id)); 161 162 /* check return code */ 163 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) { 164 tst_resm(TPASS | TTERRNO, "failed as expected"); 165 } else { 166 tst_resm(TFAIL | TTERRNO, 167 "didn't fail as expected [expected " 168 "errno = %d (%s)]", 169 testcase[i], strerror(testcase[i])); 170 } /* end of else */ 171 172 } 173 174 } 175 176 cleanup(); 177 tst_exit(); 178 } 179 180 /* setup() - performs all ONE TIME setup for this test */ 181 void setup(void) 182 { 183 184 tst_sig(NOFORK, DEF_HANDLER, cleanup); 185 186 TEST_PAUSE; 187 } 188