• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Wipro Technologies Ltd, 2003.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with this program; if not, write the Free Software Foundation, Inc.,
14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  */
17 /**************************************************************************
18  *
19  *    TEST IDENTIFIER	: timer_settime03
20  *
21  *    EXECUTED BY	: anyone
22  *
23  *    TEST TITLE	: Test checking for basic error conditions for
24  *    			  timer_settime(2)
25  *
26  *    TEST CASE TOTAL	: 6
27  *
28  *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
29  *
30  *    SIGNALS
31  * 	Uses SIGUSR1 to pause before test if option set.
32  * 	(See the parse_opts(3) man page).
33  *
34  *    DESCRIPTION
35  *    	This test case check whether timer_settime(2) returns appropriate error
36  *    	value for invalid parameter
37  *
38  * 	Setup:
39  *	 Setup signal handling.
40  *	 Pause for SIGUSR1 if option specified.
41  *
42  * 	Test:
43  *	 Loop if the proper options are given.
44  *	 setup the individual test.
45  *	 Execute system call with invalid parameters.
46  *	 Check return code, if system call fails with errno == expected errno
47  * 	 	Issue syscall passed with expected errno
48  *	 Otherwise, Issue syscall failed to produce expected errno
49  *
50  * 	Cleanup:
51  * 	 Print errno log and/or timing stats if options given
52  *
53  * USAGE:  <for command-line>
54  * timer_settime03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
55  * where:
56  * 	-c n : run n copies simultaneously
57  *	-e   : Turn on errno logging.
58  *	-i n : Execute test n times.
59  *	-I x : Execute test for x seconds.
60  *	-p   : Pause for SIGUSR1 before starting
61  *	-P x : Pause for x seconds between iterations.
62  *	-t   : Turn on syscall timing.
63  *
64  * RESTRICTIONS:
65  * None
66  *****************************************************************************/
67 
68 #include <errno.h>
69 #include <time.h>
70 #include <unistd.h>
71 
72 #include "test.h"
73 #include "common_timers.h"
74 
75 void setup(void);
76 void setup_test(int option);
77 
78 int testcase[] = {
79 	EINVAL,			/* New setting null */
80 	EINVAL,			/* tv_nsec < 0 */
81 	EINVAL,			/* nsec > NSEC/SEC */
82 	EINVAL,			/* Invalid timerid */
83 	EFAULT,			/* bad newsetting * */
84 	EFAULT			/* bad oldsetting * */
85 };
86 
87 char *TCID = "timer_settime03";
88 int TST_TOTAL = ARRAY_SIZE(testcase);
89 
90 static struct itimerspec new_set, old_set, *old_temp, *new_temp;
91 static kernel_timer_t timer, tim;
92 
main(int ac,char ** av)93 int main(int ac, char **av)
94 {
95 	int lc, i;
96 
97 	tst_parse_opts(ac, av, NULL, NULL);
98 
99 	setup();
100 
101 	for (lc = 0; TEST_LOOPING(lc); lc++) {
102 
103 		tst_count = 0;
104 
105 		for (i = 0; i < TST_TOTAL; i++) {
106 
107 			/* Set up individual tests */
108 			setup_test(i);
109 			TEST(ltp_syscall(__NR_timer_settime, tim, 0, new_temp,
110 				     old_temp));
111 
112 			/* check return code */
113 			if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) {
114 				tst_resm(TPASS | TTERRNO, "failed as expected");
115 			} else {
116 				tst_resm(TFAIL | TTERRNO,
117 					 "didn't fail as expected [expected "
118 					 "errno = %d (%s)]",
119 					 testcase[i], strerror(testcase[i]));
120 			}	/* end of else */
121 
122 		}
123 
124 	}
125 
126 	cleanup();
127 	tst_exit();
128 }
129 
130 /* This function sets up individual tests */
setup_test(int option)131 void setup_test(int option)
132 {
133 	switch (option) {
134 	case 0:
135 		/* Pass NULL structure as new setting */
136 		new_temp = NULL;
137 		tim = timer;
138 		old_temp = &old_set;
139 		break;
140 	case 1:
141 		/* Make tv_nsec value less than 0 */
142 		new_set.it_value.tv_nsec = -1;
143 		new_set.it_value.tv_sec = 5;
144 		new_set.it_interval.tv_sec = 0;
145 		new_set.it_interval.tv_nsec = 0;
146 		new_temp = &new_set;
147 		break;
148 	case 2:
149 		/* Make tv_nsec more than NSEC_PER_SEC */
150 		new_set.it_value.tv_nsec = NSEC_PER_SEC + 1;
151 		break;
152 	case 3:
153 		/* make timer_id invalid */
154 		tim = (kernel_timer_t) - 1;
155 		new_set.it_value.tv_nsec = 0;
156 		break;
157 	case 4:
158 		/* make new_setting a bad pointer */
159 		tim = timer;
160 		new_temp = (struct itimerspec *)-1;
161 		break;
162 	case 5:
163 		/* make old_setting a bad pointer */
164 		new_temp = &new_set;
165 		old_temp = (struct itimerspec *)-1;
166 		break;
167 	}
168 }
169 
170 /* setup() - performs all ONE TIME setup for this test */
setup(void)171 void setup(void)
172 {
173 
174 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
175 
176 	if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0) {
177 		tst_brkm(TBROK, NULL, "Timer create failed. Cannot"
178 			 " setup test");
179 	}
180 
181 	TEST_PAUSE;
182 }
183 
184 /*
185  * cleanup() - Performs one time cleanup for this test at
186  * completion or premature exit
187  */
cleanup(void)188 void cleanup(void)
189 {
190 }
191