1 /* 2 * 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 21 * NAME 22 * setitimer03.c 23 * 24 * DESCRIPTION 25 * setitimer03 - check that a setitimer() call fails as expected 26 * with incorrect values. 27 * 28 * ALGORITHM 29 * loop if that option was specified 30 * allocate needed space and set up needed values 31 * issue the system call 32 * check the errno value 33 * issue a PASS message if we get EINVAL 34 * otherwise, the tests fails 35 * issue a FAIL message 36 * break any remaining tests 37 * call cleanup 38 * 39 * USAGE: <for command-line> 40 * setitimer03 [-c n] [-e] [-i n] [-I x] [-p x] [-t] 41 * where, -c n : Run n copies concurrently. 42 * -e : Turn on errno logging. 43 * -i n : Execute test n times. 44 * -I x : Execute test for x seconds. 45 * -P x : Pause for x seconds between iterations. 46 * -t : Turn on syscall timing. 47 * 48 * HISTORY 49 * 03/2001 - Written by Wayne Boyer 50 * 51 * RESTRICTIONS 52 * none 53 */ 54 55 #include "test.h" 56 57 #include <errno.h> 58 #include <sys/time.h> 59 60 void cleanup(void); 61 void setup(void); 62 63 char *TCID = "setitimer03"; 64 int TST_TOTAL = 1; 65 66 int main(int ac, char **av) 67 { 68 int lc; 69 struct itimerval *value, *ovalue; 70 71 tst_parse_opts(ac, av, NULL, NULL); 72 73 setup(); /* global setup */ 74 75 /* The following loop checks looping state if -i option given */ 76 77 for (lc = 0; TEST_LOOPING(lc); lc++) { 78 /* reset tst_count in case we are looping */ 79 tst_count = 0; 80 81 /* allocate some space for timer structures */ 82 83 if ((value = malloc((size_t)sizeof(struct itimerval))) == 84 NULL) { 85 tst_brkm(TBROK, cleanup, "value malloc failed"); 86 } 87 88 if ((ovalue = malloc((size_t)sizeof(struct itimerval))) == 89 NULL) { 90 tst_brkm(TBROK, cleanup, "value malloc failed"); 91 } 92 93 /* set up some reasonable values */ 94 95 value->it_value.tv_sec = 30; 96 value->it_value.tv_usec = 0; 97 value->it_interval.tv_sec = 0; 98 value->it_interval.tv_usec = 0; 99 100 /* 101 * issue the system call with the TEST() macro 102 * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 103 */ 104 105 /* make the first value negative to get a failure */ 106 TEST(setitimer(-ITIMER_PROF, value, ovalue)); 107 108 if (TEST_RETURN == 0) { 109 tst_resm(TFAIL, "call failed to produce expected error " 110 "- errno = %d - %s", TEST_ERRNO, 111 strerror(TEST_ERRNO)); 112 continue; 113 } 114 115 switch (TEST_ERRNO) { 116 case EINVAL: 117 tst_resm(TPASS, "expected failure - errno = %d - %s", 118 TEST_ERRNO, strerror(TEST_ERRNO)); 119 break; 120 default: 121 tst_resm(TFAIL, "call failed to produce expected error " 122 "- errno = %d - %s", TEST_ERRNO, 123 strerror(TEST_ERRNO)); 124 } 125 126 /* 127 * clean up things in case we are looping 128 */ 129 free(value); 130 free(ovalue); 131 value = NULL; 132 ovalue = NULL; 133 } 134 135 cleanup(); 136 tst_exit(); 137 138 } 139 140 /* 141 * setup() - performs all the ONE TIME setup for this test. 142 */ 143 void setup(void) 144 { 145 146 tst_sig(NOFORK, DEF_HANDLER, cleanup); 147 148 TEST_PAUSE; 149 } 150 151 /* 152 * cleanup() - performs all the ONE TIME cleanup for this test at completion 153 * or premature exit. 154 */ 155 void cleanup(void) 156 { 157 158 } 159