blob: 9d2f49188c8a457bb2d1a9e761ff8a713b781b41 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
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., 59
14 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
15 *
16 */
17/**************************************************************************
vapier6670f842006-08-22 05:57:53 +000018 *
19 * TEST IDENTIFIER : timer_settime03
20 *
vapierd13d74b2006-02-11 07:24:00 +000021 * EXECUTED BY : anyone
vapier6670f842006-08-22 05:57:53 +000022 *
vapierd13d74b2006-02-11 07:24:00 +000023 * TEST TITLE : Test checking for basic error conditions for
24 * timer_settime(2)
vapier6670f842006-08-22 05:57:53 +000025 *
vapierd13d74b2006-02-11 07:24:00 +000026 * TEST CASE TOTAL : 6
vapier6670f842006-08-22 05:57:53 +000027 *
vapierd13d74b2006-02-11 07:24:00 +000028 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
vapier6670f842006-08-22 05:57:53 +000029 *
vapierd13d74b2006-02-11 07:24:00 +000030 * 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.
vapier6670f842006-08-22 05:57:53 +000041 *
vapierd13d74b2006-02-11 07:24:00 +000042 * 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
vapier6670f842006-08-22 05:57:53 +000049 *
vapierd13d74b2006-02-11 07:24:00 +000050 * Cleanup:
51 * Print errno log and/or timing stats if options given
vapier6670f842006-08-22 05:57:53 +000052 *
vapierd13d74b2006-02-11 07:24:00 +000053 * 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
vapierd13d74b2006-02-11 07:24:00 +000068#include <errno.h>
vapierd13d74b2006-02-11 07:24:00 +000069#include <time.h>
vapier8cf81042006-08-22 05:14:20 +000070#include <unistd.h>
vapierd13d74b2006-02-11 07:24:00 +000071
vapier8cf81042006-08-22 05:14:20 +000072#include "test.h"
73#include "usctest.h"
74#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000075
Garrett Coopera9670cd2010-11-28 21:55:20 -080076void setup(void);
77void setup_test(int option);
vapierd13d74b2006-02-11 07:24:00 +000078
79char *TCID = "timer_settime03"; /* Test program identifier. */
80int TST_TOTAL; /* Total number of test cases. */
81extern int Tst_count; /* Test Case counter for tst_* routines */
82
83static struct itimerspec new_set, old_set, *old_temp, *new_temp;
Subrata Modak4e947652010-05-28 12:50:38 +053084static kernel_timer_t timer, tim;
vapierd13d74b2006-02-11 07:24:00 +000085
86static int exp_enos[] = {EINVAL, EFAULT, 0};
87
yaberauneya1a7f5422009-12-06 20:53:42 +000088int testcase[] = {
89 EINVAL, /* New setting null */
90 EINVAL, /* tv_nsec < 0 */
91 EINVAL, /* nsec > NSEC/SEC */
92 EINVAL, /* Invalid timerid */
93 EFAULT, /* bad newsetting * */
94 EFAULT /* bad oldsetting * */
vapierd13d74b2006-02-11 07:24:00 +000095};
96
vapierd13d74b2006-02-11 07:24:00 +000097int
98main(int ac, char **av)
99{
100 int lc, i; /* loop counter */
101 char *msg; /* message returned from parse_opts */
102
103 /* parse standard options */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800104 if ((msg = parse_opts(ac, av, NULL, NULL))
105 != NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800106 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000107 }
108
109 /* perform global setup for test */
110 setup();
111
112 TST_TOTAL = sizeof(testcase) / sizeof(testcase[0]);
113
114 /* check looping state if -i option given */
115 for (lc = 0; TEST_LOOPING(lc); lc++) {
116
117 /* reset Tst_count in case we are looping. */
118 Tst_count = 0;
119
120 for (i = 0; i < TST_TOTAL; i++) {
121
122 /* Set up individual tests */
vapier6670f842006-08-22 05:57:53 +0000123 setup_test(i);
yaberauneya1a7f5422009-12-06 20:53:42 +0000124 TEST(syscall(__NR_timer_settime, tim, 0, new_temp,
125 old_temp));
vapierd13d74b2006-02-11 07:24:00 +0000126
127 /* check return code */
yaberauneya1a7f5422009-12-06 20:53:42 +0000128 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) {
129 tst_resm(TPASS | TTERRNO, "failed as expected");
vapierd13d74b2006-02-11 07:24:00 +0000130 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000131 tst_resm(TFAIL | TTERRNO,
132 "didn't fail as expected [expected "
133 "errno = %d (%s)]",
134 testcase[i], strerror(testcase[i]));
vapierd13d74b2006-02-11 07:24:00 +0000135 } /* end of else */
136
vapierd13d74b2006-02-11 07:24:00 +0000137 } /* End of TEST CASE LOOPING */
yaberauneya1a7f5422009-12-06 20:53:42 +0000138
vapierd13d74b2006-02-11 07:24:00 +0000139 } /* End for TEST_LOOPING */
140
vapierd13d74b2006-02-11 07:24:00 +0000141 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000142 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000143}
144
145/* This function sets up individual tests */
Garrett Coopera9670cd2010-11-28 21:55:20 -0800146void
vapierd13d74b2006-02-11 07:24:00 +0000147setup_test(int option)
148{
149 switch (option) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000150 case 0:
151 /* Pass NULL structure as new setting */
152 new_temp = (struct itimerspec *) NULL;
153 tim = timer;
154 old_temp = &old_set;
155 break;
156 case 1:
157 /* Make tv_nsec value less than 0 */
158 new_set.it_value.tv_nsec = -1;
159 new_set.it_value.tv_sec = 5;
160 new_set.it_interval.tv_sec = 0;
161 new_set.it_interval.tv_nsec = 0;
162 new_temp = &new_set;
163 break;
164 case 2:
165 /* Make tv_nsec more than NSEC_PER_SEC */
166 new_set.it_value.tv_nsec = NSEC_PER_SEC + 1;
167 break;
168 case 3:
169 /* make timer_id invalid */
Subrata Modak4e947652010-05-28 12:50:38 +0530170 tim = (kernel_timer_t)-1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000171 new_set.it_value.tv_nsec = 0;
172 break;
173 case 4:
174 /* make new_setting a bad pointer */
175 tim = timer;
176 new_temp = (struct itimerspec *) -1;
177 break;
178 case 5:
179 /* make old_setting a bad pointer */
180 new_temp = &new_set;
181 old_temp = (struct itimerspec *) -1;
182 break;
vapierd13d74b2006-02-11 07:24:00 +0000183 }
184}
185
186/* setup() - performs all ONE TIME setup for this test */
Garrett Coopera9670cd2010-11-28 21:55:20 -0800187void
188setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000189{
190 /* capture signals */
191 tst_sig(NOFORK, DEF_HANDLER, cleanup);
192
yaberauneya1a7f5422009-12-06 20:53:42 +0000193 if (syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800194 tst_brkm(TBROK, NULL, "Timer create failed. Cannot"
vapierd13d74b2006-02-11 07:24:00 +0000195 " setup test");
196 }
197
198 /* set the expected errnos... */
199 TEST_EXP_ENOS(exp_enos);
200 /* Pause if that option was specified */
201 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800202}
vapierd13d74b2006-02-11 07:24:00 +0000203
204/*
205 * cleanup() - Performs one time cleanup for this test at
206 * completion or premature exit
207 */
Garrett Coopera9670cd2010-11-28 21:55:20 -0800208void
yaberauneya1a7f5422009-12-06 20:53:42 +0000209cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000210{
211 /*
212 * print timing stats if that option was specified.
213 * print errno log if that option was specified.
214 */
215 TEST_CLEANUP;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800216}