plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * getitimer02.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * getitimer02 - check that a getitimer() call fails as expected |
| 26 | * with an incorrect second argument. |
| 27 | * |
| 28 | * ALGORITHM |
| 29 | * loop if that option was specified |
| 30 | * call getitimer() with an incorrect second argument. |
| 31 | * check the errno value |
| 32 | * issue a PASS message if we get EFAULT - errno 14 |
| 33 | * otherwise, the tests fails |
| 34 | * issue a FAIL message |
| 35 | * break any remaining tests |
| 36 | * call cleanup |
| 37 | * |
| 38 | * USAGE: <for command-line> |
| 39 | * getitimer02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] |
| 40 | * where, -c n : Run n copies concurrently. |
| 41 | * -e : Turn on errno logging. |
| 42 | * -i n : Execute test n times. |
| 43 | * -I x : Execute test for x seconds. |
| 44 | * -P x : Pause for x seconds between iterations. |
| 45 | * -t : Turn on syscall timing. |
| 46 | * |
| 47 | * HISTORY |
| 48 | * 03/2001 - Written by Wayne Boyer |
| 49 | * |
| 50 | * RESTRICTIONS |
| 51 | * none |
| 52 | */ |
| 53 | |
| 54 | #include "test.h" |
| 55 | #include "usctest.h" |
| 56 | |
| 57 | #include <errno.h> |
| 58 | #include <sys/time.h> |
| 59 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 60 | char *TCID = "getitimer02"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 61 | int TST_TOTAL = 1; |
| 62 | extern int Tst_count; |
| 63 | |
vapier | bdbacc9 | 2006-02-27 04:30:24 +0000 | [diff] [blame] | 64 | #if !defined(UCLINUX) |
| 65 | |
| 66 | void cleanup(void); |
| 67 | void setup(void); |
| 68 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 69 | int exp_enos[] = { EFAULT, 0 }; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | |
robbiew | 12c4392 | 2003-03-26 19:40:11 +0000 | [diff] [blame] | 71 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | int lc; /* loop counter */ |
| 74 | char *msg; /* message returned from parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | |
| 76 | /* parse standard options */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 77 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 78 | <<<<<<< HEAD |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 79 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 80 | ======= |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 82 | >>>>>>> master |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | } |
| 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | /* The following loop checks looping state if -i option given */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
| 89 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 90 | /* reset Tst_count in case we are looping */ |
| 91 | Tst_count = 0; |
| 92 | |
| 93 | /* |
| 94 | * issue the system call with the TEST() macro |
| 95 | * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 |
| 96 | */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 97 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | /* call with a bad address */ |
| 99 | TEST(getitimer(ITIMER_REAL, (struct itimerval *)-1)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 100 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | if (TEST_RETURN == 0) { |
| 102 | tst_resm(TFAIL, "call failed to produce " |
| 103 | "expected error - errno = %d - %s", |
| 104 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 105 | continue; |
| 106 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 107 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | TEST_ERROR_LOG(TEST_ERRNO); |
| 109 | |
| 110 | switch (TEST_ERRNO) { |
| 111 | case EFAULT: |
| 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 " |
| 117 | "expected error - errno = %d - %s", |
| 118 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | cleanup(); |
| 123 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 124 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* |
| 128 | * setup() - performs all the ONE TIME setup for this test. |
| 129 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 132 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 134 | |
| 135 | /* Set up the expected error numbers for -e option */ |
| 136 | TEST_EXP_ENOS(exp_enos); |
| 137 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 138 | TEST_PAUSE; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 143 | * or premature exit. |
| 144 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 146 | { |
| 147 | /* |
| 148 | * print timing stats if that option was specified. |
| 149 | * print errno log if that option was specified. |
| 150 | */ |
| 151 | TEST_CLEANUP; |
| 152 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 153 | } |
| 154 | |
vapier | bdbacc9 | 2006-02-27 04:30:24 +0000 | [diff] [blame] | 155 | #else |
| 156 | |
| 157 | int main(void) |
| 158 | { |
| 159 | tst_resm(TINFO, "test is not available on uClinux"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 160 | tst_exit(); |
vapier | bdbacc9 | 2006-02-27 04:30:24 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 163 | #endif /* if !defined(UCLINUX) */ |