• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
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"
56 
57 #include <errno.h>
58 #include <sys/time.h>
59 
60 void cleanup(void);
61 void setup(void);
62 
63 char *TCID = "setitimer02";
64 int TST_TOTAL = 1;
65 
66 #if !defined(UCLINUX)
67 
main(int ac,char ** av)68 int main(int ac, char **av)
69 {
70 	int lc;
71 	struct itimerval *value;
72 
73 	tst_parse_opts(ac, av, NULL, NULL);
74 
75 	setup();		/* global setup */
76 
77 	/* The following loop checks looping state if -i option given */
78 
79 	for (lc = 0; TEST_LOOPING(lc); lc++) {
80 		/* reset tst_count in case we are looping */
81 		tst_count = 0;
82 
83 		/* allocate some space for a timer structure */
84 		if ((value = malloc((size_t)sizeof(struct itimerval))) ==
85 		    NULL) {
86 			tst_brkm(TBROK, cleanup, "value malloc failed");
87 		}
88 
89 		/* set up some reasonable values */
90 
91 		value->it_value.tv_sec = 30;
92 		value->it_value.tv_usec = 0;
93 		value->it_interval.tv_sec = 0;
94 		value->it_interval.tv_usec = 0;
95 		/*
96 		 * issue the system call with the TEST() macro
97 		 * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2
98 		 */
99 
100 		/* call with a bad address */
101 		TEST(setitimer(ITIMER_REAL, value, (struct itimerval *)-1));
102 
103 		if (TEST_RETURN == 0) {
104 			tst_resm(TFAIL, "call failed to produce EFAULT error "
105 				 "- errno = %d - %s", TEST_ERRNO,
106 				 strerror(TEST_ERRNO));
107 			continue;
108 		}
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 EFAULT error "
117 				 "- errno = %d - %s", TEST_ERRNO,
118 				 strerror(TEST_ERRNO));
119 		}
120 
121 		/*
122 		 * clean up things in case we are looping
123 		 */
124 		free(value);
125 		value = NULL;
126 	}
127 
128 	cleanup();
129 	tst_exit();
130 
131 }
132 
133 #else
134 
main(void)135 int main(void)
136 {
137 	tst_resm(TINFO, "test is not available on uClinux");
138 	tst_exit();
139 }
140 
141 #endif /* if !defined(UCLINUX) */
142 
143 /*
144  * setup() - performs all the ONE TIME setup for this test.
145  */
setup(void)146 void setup(void)
147 {
148 
149 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
150 
151 	TEST_PAUSE;
152 }
153 
154 /*
155  * cleanup() - performs all the ONE TIME cleanup for this test at completion
156  * 	       or premature exit.
157  */
cleanup(void)158 void cleanup(void)
159 {
160 
161 }
162