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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
| 57 | #include <errno.h> |
| 58 | #include <sys/time.h> |
| 59 | |
| 60 | void cleanup(void); |
| 61 | void setup(void); |
| 62 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 63 | char *TCID = "setitimer03"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 66 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 68 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 69 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | struct itimerval *value, *ovalue; |
| 71 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 72 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 73 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | } |
| 75 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 76 | setup(); /* global setup */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | |
| 78 | /* The following loop checks looping state if -i option given */ |
| 79 | |
| 80 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 81 | /* reset tst_count in case we are looping */ |
| 82 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | |
| 84 | /* allocate some space for timer structures */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 85 | |
Cyril Hrubis | d218f34 | 2014-09-23 13:14:56 +0200 | [diff] [blame] | 86 | if ((value = malloc((size_t)sizeof(struct itimerval))) == |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | tst_brkm(TBROK, cleanup, "value malloc failed"); |
| 89 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 90 | |
Cyril Hrubis | d218f34 | 2014-09-23 13:14:56 +0200 | [diff] [blame] | 91 | if ((ovalue = malloc((size_t)sizeof(struct itimerval))) == |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | tst_brkm(TBROK, cleanup, "value malloc failed"); |
| 94 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 95 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | /* set up some reasonable values */ |
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 | value->it_value.tv_sec = 30; |
| 99 | value->it_value.tv_usec = 0; |
vapier | 5ea3f5c | 2006-05-12 15:38:48 +0000 | [diff] [blame] | 100 | value->it_interval.tv_sec = 0; |
| 101 | value->it_interval.tv_usec = 0; |
| 102 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | /* |
| 104 | * issue the system call with the TEST() macro |
| 105 | * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 |
| 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 | /* make the first value negative to get a failure */ |
| 109 | TEST(setitimer(-ITIMER_PROF, value, ovalue)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 110 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | if (TEST_RETURN == 0) { |
| 112 | tst_resm(TFAIL, "call failed to produce expected error " |
| 113 | "- errno = %d - %s", TEST_ERRNO, |
| 114 | strerror(TEST_ERRNO)); |
| 115 | continue; |
| 116 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 117 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 118 | switch (TEST_ERRNO) { |
| 119 | case EINVAL: |
| 120 | tst_resm(TPASS, "expected failure - errno = %d - %s", |
| 121 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 122 | break; |
| 123 | default: |
| 124 | tst_resm(TFAIL, "call failed to produce expected error " |
| 125 | "- errno = %d - %s", TEST_ERRNO, |
| 126 | strerror(TEST_ERRNO)); |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * clean up things in case we are looping |
| 131 | */ |
| 132 | free(value); |
| 133 | free(ovalue); |
| 134 | value = NULL; |
| 135 | ovalue = NULL; |
| 136 | } |
| 137 | |
| 138 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 139 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 140 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* |
| 144 | * setup() - performs all the ONE TIME setup for this test. |
| 145 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 146 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 147 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 148 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 149 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 150 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 151 | TEST_PAUSE; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 156 | * or premature exit. |
| 157 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 159 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 160 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 161 | } |