1/* 2 * Copyright (c) International Business Machines Corp., 2001 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 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19/* $Header: /cvsroot/ltp/ltp/testcases/kernel/syscalls/getitimer/getitimer03.c,v 1.7 2009/08/28 10:18:24 vapier Exp $ */ 20 21/* 22 * NAME 23 * getitimer03.c 24 * 25 * DESCRIPTION 26 * getitimer03 - check that a getitimer() call fails as expected 27 * with an incorrect first argument. 28 * 29 * CALLS 30 * getitimer() 31 * 32 * ALGORITHM 33 * loop if that option was specified 34 * allocate space and set up needed values 35 * issue the system call 36 * check the errno value 37 * issue a PASS message if we get EINVAL 38 * otherwise, the tests fails 39 * issue a FAIL message 40 * break any remaining tests 41 * call cleanup 42 * 43 * USAGE: <for command-line> 44 * getitmer03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] 45 * where, -c n : Run n copies concurrently. 46 * -e : Turn on errno logging. 47 * -i n : Execute test n times. 48 * -I x : Execute test for x seconds. 49 * -P x : Pause for x seconds between iterations. 50 * -t : Turn on syscall timing. 51 * 52 * USAGE 53 * ./getitimer03 54 * 55 * HISTORY 56 * 03/2001 - Written by Wayne Boyer 57 * 58 * RESTRICTIONS 59 * none 60 */ 61 62#include "test.h" 63 64#include <errno.h> 65#include <sys/time.h> 66 67void cleanup(void); 68void setup(void); 69 70char *TCID = "getitimer03"; 71int TST_TOTAL = 1; 72 73int main(int ac, char **av) 74{ 75 int lc; 76 struct itimerval *value; 77 78 tst_parse_opts(ac, av, NULL, NULL); 79 80 setup(); /* global setup */ 81 82 /* The following loop checks looping state if -i option given */ 83 84 for (lc = 0; TEST_LOOPING(lc); lc++) { 85 /* reset tst_count in case we are looping */ 86 tst_count = 0; 87 88 /* allocate some space for the timer structure */ 89 90 if ((value = malloc((size_t)sizeof(struct itimerval))) == 91 NULL) { 92 tst_brkm(TBROK, cleanup, "value malloc failed"); 93 } 94 95 /* 96 * issue the system call with the TEST() macro 97 * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 98 */ 99 100 /* make the first value negative to get a failure */ 101 TEST(getitimer(-ITIMER_PROF, value)); 102 103 if (TEST_RETURN == 0) { 104 tst_resm(TFAIL, "call failed to produce expected error " 105 "- errno = %d - %s", TEST_ERRNO, 106 strerror(TEST_ERRNO)); 107 continue; 108 } 109 110 switch (TEST_ERRNO) { 111 case EINVAL: 112 tst_resm(TPASS, "expected failure - errno = %d - %s", 113 TEST_ERRNO, strerror(TEST_ERRNO)); 114 break; 115 default: 116 tst_resm(TFAIL, "call failed to produce expected error " 117 "- errno = %d - %s", TEST_ERRNO, 118 strerror(TEST_ERRNO)); 119 } 120 121 /* 122 * clean up things in case we are looping 123 */ 124 125 free(value); 126 value = NULL; 127 } 128 129 cleanup(); 130 131 tst_exit(); 132} 133 134/* 135 * setup() - performs all the ONE TIME setup for this test. 136 */ 137void setup(void) 138{ 139 140 tst_sig(NOFORK, DEF_HANDLER, cleanup); 141 142 TEST_PAUSE; 143} 144 145/* 146 * cleanup() - performs all the ONE TIME cleanup for this test at completion 147 * or premature exit. 148 */ 149void cleanup(void) 150{ 151 152} 153