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 : clock_gettime03 20 * 21 * EXECUTED BY : anyone 22 * 23 * TEST TITLE : Test checking for basic error conditions for 24 * clock_gettime(2) 25 * 26 * TEST CASE TOTAL : 7 27 * 28 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@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 clock_gettime(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 * If it is the first test case 45 * make temp a bad pointer 46 * Otherwise pass defined struct timespec variable to temp 47 * Execute system call with invalid parameter 48 * Check return code, if system call fails with errno == expected errno 49 * Issue syscall passed with expected errno 50 * Otherwise, Issue syscall failed to produce expected errno 51 * 52 * Cleanup: 53 * Print errno log and/or timing stats if options given 54 * 55 * USAGE: <for command-line> 56 * clock_gettime03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p] 57 * where: 58 * -c n : run n copies simultaneously 59 * -e : Turn on errno logging. 60 * -i n : Execute test n times. 61 * -I x : Execute test for x seconds. 62 * -p : Pause for SIGUSR1 before starting 63 * -P x : Pause for x seconds between iterations. 64 * -t : Turn on syscall timing. 65 * 66 * RESTRICTIONS: 67 * None 68 *****************************************************************************/ 69 70#include <stdlib.h> 71#include <errno.h> 72#include <time.h> 73#include <signal.h> 74 75#include "test.h" 76#include "common_timers.h" 77 78void setup(void); 79 80int testcase[6] = { 81 EFAULT, /* Bad timespec */ 82 EFAULT, /* Bad timespec */ 83 EINVAL, /* MAX_CLOCKS */ 84 EINVAL /* MAX_CLOCKS + 1 */ 85}; 86 87char *TCID = "clock_gettime03"; /* Test program identifier. */ 88int TST_TOTAL = ARRAY_SIZE(testcase); 89 90int main(int ac, char **av) 91{ 92 int i, lc; 93 struct timespec spec, *temp; 94 95 clockid_t clocks[] = { 96 CLOCK_REALTIME, 97 CLOCK_MONOTONIC, 98 MAX_CLOCKS, 99 MAX_CLOCKS + 1, 100 CLOCK_PROCESS_CPUTIME_ID, 101 CLOCK_THREAD_CPUTIME_ID 102 }; 103 104 tst_parse_opts(ac, av, NULL, NULL); 105 106 /* 107 * PROCESS_CPUTIME_ID & THREAD_CPUTIME_ID are not supported on 108 * kernel versions lower than 2.6.12 109 */ 110 if ((tst_kvercmp(2, 6, 12)) < 0) { 111 testcase[4] = EINVAL; 112 testcase[5] = EINVAL; 113 } else { 114 testcase[4] = EFAULT; 115 testcase[5] = EFAULT; 116 } 117 118 setup(); 119 120 for (lc = 0; TEST_LOOPING(lc); lc++) { 121 122 tst_count = 0; 123 124 for (i = 0; i < TST_TOTAL; i++) { 125 temp = &spec; 126 127 if (i == 0) { 128 temp = (struct timespec *)-1; 129 } else if (i == 1) { 130 temp = NULL; 131 } else if ((i >= 4) && (tst_kvercmp(2, 6, 12) >= 0)) { 132 temp = NULL; 133 } 134 135 TEST(ltp_syscall(__NR_clock_gettime, clocks[i], temp)); 136 137 /* check return code */ 138 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) { 139 tst_resm(TPASS | TTERRNO, 140 "got expected failure"); 141 } else { 142 tst_resm(TFAIL | TTERRNO, 143 "failed to produce expected error " 144 "[expected errno = %d (%s), " 145 "TEST_RETURN = %ld]", 146 testcase[i], strerror(testcase[i]), 147 TEST_RETURN); 148 } /* end of else */ 149 150 } /*End of TEST CASE LOOPING */ 151 152 } /*End for TEST_LOOPING */ 153 154 cleanup(); 155 tst_exit(); 156} 157 158/* setup() - performs all ONE TIME setup for this test */ 159void setup(void) 160{ 161 162 tst_sig(NOFORK, DEF_HANDLER, cleanup); 163 164 TEST_PAUSE; 165} 166 167/* 168 * cleanup() - Performs one time cleanup for this test at 169 * completion or premature exit 170 */ 171void cleanup(void) 172{ 173} 174