blob: ff5b426b8f76eb8a2141f5a0d27845e33d0db078 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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 Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
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"
plars865695b2001-08-27 22:15:12 +000056
57#include <errno.h>
58#include <sys/time.h>
59
60void cleanup(void);
61void setup(void);
62
subrata_modak56207ce2009-03-23 13:35:39 +000063char *TCID = "setitimer03";
plars865695b2001-08-27 22:15:12 +000064int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000065
plars74948ad2002-11-14 16:16:14 +000066int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000067{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020068 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020069 const char *msg;
plars865695b2001-08-27 22:15:12 +000070 struct itimerval *value, *ovalue;
71
Garrett Cooper45e285d2010-11-22 12:19:25 -080072 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080073 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000074 }
75
subrata_modak56207ce2009-03-23 13:35:39 +000076 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000077
78 /* The following loop checks looping state if -i option given */
79
80 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080081 /* reset tst_count in case we are looping */
82 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000083
84 /* allocate some space for timer structures */
subrata_modakbdbaec52009-02-26 12:14:51 +000085
Cyril Hrubisd218f342014-09-23 13:14:56 +020086 if ((value = malloc((size_t)sizeof(struct itimerval))) ==
subrata_modak56207ce2009-03-23 13:35:39 +000087 NULL) {
plars865695b2001-08-27 22:15:12 +000088 tst_brkm(TBROK, cleanup, "value malloc failed");
89 }
subrata_modakbdbaec52009-02-26 12:14:51 +000090
Cyril Hrubisd218f342014-09-23 13:14:56 +020091 if ((ovalue = malloc((size_t)sizeof(struct itimerval))) ==
subrata_modak56207ce2009-03-23 13:35:39 +000092 NULL) {
plars865695b2001-08-27 22:15:12 +000093 tst_brkm(TBROK, cleanup, "value malloc failed");
94 }
subrata_modakbdbaec52009-02-26 12:14:51 +000095
plars865695b2001-08-27 22:15:12 +000096 /* set up some reasonable values */
subrata_modakbdbaec52009-02-26 12:14:51 +000097
plars865695b2001-08-27 22:15:12 +000098 value->it_value.tv_sec = 30;
99 value->it_value.tv_usec = 0;
vapier5ea3f5c2006-05-12 15:38:48 +0000100 value->it_interval.tv_sec = 0;
101 value->it_interval.tv_usec = 0;
102
plars865695b2001-08-27 22:15:12 +0000103 /*
104 * issue the system call with the TEST() macro
105 * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2
106 */
subrata_modakbdbaec52009-02-26 12:14:51 +0000107
plars865695b2001-08-27 22:15:12 +0000108 /* make the first value negative to get a failure */
109 TEST(setitimer(-ITIMER_PROF, value, ovalue));
subrata_modakbdbaec52009-02-26 12:14:51 +0000110
plars865695b2001-08-27 22:15:12 +0000111 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_modakbdbaec52009-02-26 12:14:51 +0000117
plars865695b2001-08-27 22:15:12 +0000118 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 Cooper1e6f5a62010-12-19 09:58:10 -0800139 tst_exit();
plars865695b2001-08-27 22:15:12 +0000140
plars865695b2001-08-27 22:15:12 +0000141}
142
143/*
144 * setup() - performs all the ONE TIME setup for this test.
145 */
subrata_modak56207ce2009-03-23 13:35:39 +0000146void setup(void)
plars865695b2001-08-27 22:15:12 +0000147{
Garrett Cooper2c282152010-12-16 00:55:50 -0800148
plars865695b2001-08-27 22:15:12 +0000149 tst_sig(NOFORK, DEF_HANDLER, cleanup);
150
plars865695b2001-08-27 22:15:12 +0000151 TEST_PAUSE;
152}
153
154/*
155 * cleanup() - performs all the ONE TIME cleanup for this test at completion
156 * or premature exit.
157 */
subrata_modak56207ce2009-03-23 13:35:39 +0000158void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000159{
plars865695b2001-08-27 22:15:12 +0000160
Chris Dearmanec6edca2012-10-17 19:54:01 -0700161}