blob: c59924ea0c82c2a80db8c1667fb23bc76753c69a [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
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_modak56207ce2009-03-23 13:35:39 +000060char *TCID = "getitimer02";
plars865695b2001-08-27 22:15:12 +000061int TST_TOTAL = 1;
62extern int Tst_count;
63
vapierbdbacc92006-02-27 04:30:24 +000064#if !defined(UCLINUX)
65
66void cleanup(void);
67void setup(void);
68
subrata_modak56207ce2009-03-23 13:35:39 +000069int exp_enos[] = { EFAULT, 0 };
plars865695b2001-08-27 22:15:12 +000070
robbiew12c43922003-03-26 19:40:11 +000071int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000072{
subrata_modak56207ce2009-03-23 13:35:39 +000073 int lc; /* loop counter */
74 char *msg; /* message returned from parse_opts */
plars865695b2001-08-27 22:15:12 +000075
76 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -080077 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -080078<<<<<<< HEAD
Garrett Cooper60fa8012010-11-22 13:50:58 -080079 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper53740502010-12-16 00:04:01 -080080=======
plars865695b2001-08-27 22:15:12 +000081 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper53740502010-12-16 00:04:01 -080082>>>>>>> master
plars865695b2001-08-27 22:15:12 +000083 }
84
subrata_modak56207ce2009-03-23 13:35:39 +000085 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000086
subrata_modak56207ce2009-03-23 13:35:39 +000087 /* The following loop checks looping state if -i option given */
plars865695b2001-08-27 22:15:12 +000088
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_modakbdbaec52009-02-26 12:14:51 +000097
plars865695b2001-08-27 22:15:12 +000098 /* call with a bad address */
99 TEST(getitimer(ITIMER_REAL, (struct itimerval *)-1));
subrata_modakbdbaec52009-02-26 12:14:51 +0000100
plars865695b2001-08-27 22:15:12 +0000101 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_modakbdbaec52009-02-26 12:14:51 +0000107
plars865695b2001-08-27 22:15:12 +0000108 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 Cooper53740502010-12-16 00:04:01 -0800124 return 0;
plars865695b2001-08-27 22:15:12 +0000125}
126
127/*
128 * setup() - performs all the ONE TIME setup for this test.
129 */
subrata_modak56207ce2009-03-23 13:35:39 +0000130void setup(void)
plars865695b2001-08-27 22:15:12 +0000131{
Garrett Cooper2c282152010-12-16 00:55:50 -0800132
plars865695b2001-08-27 22:15:12 +0000133 tst_sig(NOFORK, DEF_HANDLER, cleanup);
134
135 /* Set up the expected error numbers for -e option */
136 TEST_EXP_ENOS(exp_enos);
137
plars865695b2001-08-27 22:15:12 +0000138 TEST_PAUSE;
139}
140
141/*
142 * cleanup() - performs all the ONE TIME cleanup for this test at completion
143 * or premature exit.
144 */
subrata_modak56207ce2009-03-23 13:35:39 +0000145void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000146{
147 /*
148 * print timing stats if that option was specified.
149 * print errno log if that option was specified.
150 */
151 TEST_CLEANUP;
152
plars865695b2001-08-27 22:15:12 +0000153}
154
vapierbdbacc92006-02-27 04:30:24 +0000155#else
156
157int main(void)
158{
159 tst_resm(TINFO, "test is not available on uClinux");
Garrett Cooper2c282152010-12-16 00:55:50 -0800160 tst_exit();
vapierbdbacc92006-02-27 04:30:24 +0000161}
162
Garrett Cooper2c282152010-12-16 00:55:50 -0800163#endif /* if !defined(UCLINUX) */