blob: dbabd861449fbdede7d8bdf249462b72fe992778 [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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 *
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
Wanlong Gao354ebb42012-12-07 10:10:04 +080079char *TCID = "timer_settime03"; /* Test program identifier. */
80int TST_TOTAL; /* Total number of test cases. */
vapierd13d74b2006-02-11 07:24:00 +000081
82static struct itimerspec new_set, old_set, *old_temp, *new_temp;
Subrata Modak4e947652010-05-28 12:50:38 +053083static kernel_timer_t timer, tim;
vapierd13d74b2006-02-11 07:24:00 +000084
Wanlong Gao354ebb42012-12-07 10:10:04 +080085static int exp_enos[] = { EINVAL, EFAULT, 0 };
vapierd13d74b2006-02-11 07:24:00 +000086
yaberauneya1a7f5422009-12-06 20:53:42 +000087int testcase[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080088 EINVAL, /* New setting null */
89 EINVAL, /* tv_nsec < 0 */
90 EINVAL, /* nsec > NSEC/SEC */
91 EINVAL, /* Invalid timerid */
92 EFAULT, /* bad newsetting * */
93 EFAULT /* bad oldsetting * */
vapierd13d74b2006-02-11 07:24:00 +000094};
95
Wanlong Gao354ebb42012-12-07 10:10:04 +080096int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000097{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020098 int lc, i;
99 char *msg;
vapierd13d74b2006-02-11 07:24:00 +0000100
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800101 if ((msg = parse_opts(ac, av, NULL, NULL))
Wanlong Gao354ebb42012-12-07 10:10:04 +0800102 != NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800103 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000104 }
105
vapierd13d74b2006-02-11 07:24:00 +0000106 setup();
107
108 TST_TOTAL = sizeof(testcase) / sizeof(testcase[0]);
109
vapierd13d74b2006-02-11 07:24:00 +0000110 for (lc = 0; TEST_LOOPING(lc); lc++) {
111
vapierd13d74b2006-02-11 07:24:00 +0000112 Tst_count = 0;
113
114 for (i = 0; i < TST_TOTAL; i++) {
115
116 /* Set up individual tests */
vapier6670f842006-08-22 05:57:53 +0000117 setup_test(i);
Jan Stancek359980f2013-02-15 10:16:05 +0100118 TEST(ltp_syscall(__NR_timer_settime, tim, 0, new_temp,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800119 old_temp));
vapierd13d74b2006-02-11 07:24:00 +0000120
121 /* check return code */
yaberauneya1a7f5422009-12-06 20:53:42 +0000122 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) {
123 tst_resm(TPASS | TTERRNO, "failed as expected");
vapierd13d74b2006-02-11 07:24:00 +0000124 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000125 tst_resm(TFAIL | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800126 "didn't fail as expected [expected "
127 "errno = %d (%s)]",
128 testcase[i], strerror(testcase[i]));
129 } /* end of else */
vapierd13d74b2006-02-11 07:24:00 +0000130
Garrett Cooper2c282152010-12-16 00:55:50 -0800131 }
yaberauneya1a7f5422009-12-06 20:53:42 +0000132
Garrett Cooper2c282152010-12-16 00:55:50 -0800133 }
vapierd13d74b2006-02-11 07:24:00 +0000134
vapierd13d74b2006-02-11 07:24:00 +0000135 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000136 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000137}
138
139/* This function sets up individual tests */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800140void setup_test(int option)
vapierd13d74b2006-02-11 07:24:00 +0000141{
142 switch (option) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000143 case 0:
144 /* Pass NULL structure as new setting */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800145 new_temp = (struct itimerspec *)NULL;
yaberauneya1a7f5422009-12-06 20:53:42 +0000146 tim = timer;
147 old_temp = &old_set;
148 break;
149 case 1:
150 /* Make tv_nsec value less than 0 */
151 new_set.it_value.tv_nsec = -1;
152 new_set.it_value.tv_sec = 5;
153 new_set.it_interval.tv_sec = 0;
154 new_set.it_interval.tv_nsec = 0;
155 new_temp = &new_set;
156 break;
157 case 2:
158 /* Make tv_nsec more than NSEC_PER_SEC */
159 new_set.it_value.tv_nsec = NSEC_PER_SEC + 1;
160 break;
161 case 3:
162 /* make timer_id invalid */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800163 tim = (kernel_timer_t) - 1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000164 new_set.it_value.tv_nsec = 0;
165 break;
166 case 4:
167 /* make new_setting a bad pointer */
168 tim = timer;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800169 new_temp = (struct itimerspec *)-1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000170 break;
171 case 5:
172 /* make old_setting a bad pointer */
173 new_temp = &new_set;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800174 old_temp = (struct itimerspec *)-1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000175 break;
vapierd13d74b2006-02-11 07:24:00 +0000176 }
177}
178
179/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800180void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000181{
Garrett Cooper2c282152010-12-16 00:55:50 -0800182
vapierd13d74b2006-02-11 07:24:00 +0000183 tst_sig(NOFORK, DEF_HANDLER, cleanup);
184
Jan Stancek359980f2013-02-15 10:16:05 +0100185 if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800186 tst_brkm(TBROK, NULL, "Timer create failed. Cannot"
Wanlong Gao354ebb42012-12-07 10:10:04 +0800187 " setup test");
vapierd13d74b2006-02-11 07:24:00 +0000188 }
189
190 /* set the expected errnos... */
191 TEST_EXP_ENOS(exp_enos);
Garrett Cooper2c282152010-12-16 00:55:50 -0800192
vapierd13d74b2006-02-11 07:24:00 +0000193 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800194}
vapierd13d74b2006-02-11 07:24:00 +0000195
196/*
197 * cleanup() - Performs one time cleanup for this test at
198 * completion or premature exit
199 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800200void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000201{
202 /*
Wanlong Gao354ebb42012-12-07 10:10:04 +0800203 * print timing stats if that option was specified.
204 * print errno log if that option was specified.
205 */
vapierd13d74b2006-02-11 07:24:00 +0000206 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700207}