blob: 813b472b246abe80c0b1daa76bd5cfec6cc9cb9a [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 * setitimer02.c
23 *
24 * DESCRIPTION
25 * setitimer02 - 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 EFAULT
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 * setitimer02 [-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 = "setitimer02";
plars865695b2001-08-27 22:15:12 +000064int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000065
vapiercc0d4502006-02-27 04:36:28 +000066#if !defined(UCLINUX)
67
plars74948ad2002-11-14 16:16:14 +000068int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000069{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020070 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020071 const char *msg;
plars865695b2001-08-27 22:15:12 +000072 struct itimerval *value;
73
Garrett Cooper45e285d2010-11-22 12:19:25 -080074 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080075 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000076 }
77
subrata_modak56207ce2009-03-23 13:35:39 +000078 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000079
80 /* The following loop checks looping state if -i option given */
81
82 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080083 /* reset tst_count in case we are looping */
84 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000085
86 /* allocate some space for a timer structure */
Cyril Hrubisd218f342014-09-23 13:14:56 +020087 if ((value = malloc((size_t)sizeof(struct itimerval))) ==
subrata_modak56207ce2009-03-23 13:35:39 +000088 NULL) {
plars865695b2001-08-27 22:15:12 +000089 tst_brkm(TBROK, cleanup, "value malloc failed");
90 }
91
92 /* set up some reasonable values */
subrata_modakbdbaec52009-02-26 12:14:51 +000093
plars865695b2001-08-27 22:15:12 +000094 value->it_value.tv_sec = 30;
95 value->it_value.tv_usec = 0;
subrata_modak56207ce2009-03-23 13:35:39 +000096 value->it_interval.tv_sec = 0;
97 value->it_interval.tv_usec = 0;
plars865695b2001-08-27 22:15:12 +000098 /*
99 * issue the system call with the TEST() macro
100 * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2
101 */
subrata_modakbdbaec52009-02-26 12:14:51 +0000102
plars865695b2001-08-27 22:15:12 +0000103 /* call with a bad address */
104 TEST(setitimer(ITIMER_REAL, value, (struct itimerval *)-1));
subrata_modakbdbaec52009-02-26 12:14:51 +0000105
plars865695b2001-08-27 22:15:12 +0000106 if (TEST_RETURN == 0) {
107 tst_resm(TFAIL, "call failed to produce EFAULT error "
subrata_modak56207ce2009-03-23 13:35:39 +0000108 "- errno = %d - %s", TEST_ERRNO,
109 strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +0000110 continue;
111 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000112
plars865695b2001-08-27 22:15:12 +0000113 switch (TEST_ERRNO) {
114 case EFAULT:
115 tst_resm(TPASS, "expected failure - errno = %d - %s",
116 TEST_ERRNO, strerror(TEST_ERRNO));
117 break;
118 default:
119 tst_resm(TFAIL, "call failed to produce EFAULT error "
120 "- errno = %d - %s", TEST_ERRNO,
121 strerror(TEST_ERRNO));
122 }
123
124 /*
125 * clean up things in case we are looping
126 */
127 free(value);
128 value = NULL;
129 }
130
131 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800132 tst_exit();
plars865695b2001-08-27 22:15:12 +0000133
plars865695b2001-08-27 22:15:12 +0000134}
135
vapiercc0d4502006-02-27 04:36:28 +0000136#else
137
Mike Frysingerc57fba52014-04-09 18:56:30 -0400138int main(void)
vapiercc0d4502006-02-27 04:36:28 +0000139{
140 tst_resm(TINFO, "test is not available on uClinux");
Garrett Cooper2c282152010-12-16 00:55:50 -0800141 tst_exit();
vapiercc0d4502006-02-27 04:36:28 +0000142}
143
144#endif /* if !defined(UCLINUX) */
145
plars865695b2001-08-27 22:15:12 +0000146/*
147 * setup() - performs all the ONE TIME setup for this test.
148 */
subrata_modak56207ce2009-03-23 13:35:39 +0000149void setup(void)
plars865695b2001-08-27 22:15:12 +0000150{
Garrett Cooper2c282152010-12-16 00:55:50 -0800151
plars865695b2001-08-27 22:15:12 +0000152 tst_sig(NOFORK, DEF_HANDLER, cleanup);
153
plars865695b2001-08-27 22:15:12 +0000154 TEST_PAUSE;
155}
156
157/*
158 * cleanup() - performs all the ONE TIME cleanup for this test at completion
159 * or premature exit.
160 */
subrata_modak56207ce2009-03-23 13:35:39 +0000161void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000162{
plars865695b2001-08-27 22:15:12 +0000163
Chris Dearmanec6edca2012-10-17 19:54:01 -0700164}