blob: a7e081c18086042cbb9d93e48111a43d5c81dbaa [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"
vapier8cf81042006-08-22 05:14:20 +000073#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000074
Garrett Coopera9670cd2010-11-28 21:55:20 -080075void setup(void);
76void setup_test(int option);
vapierd13d74b2006-02-11 07:24:00 +000077
yaberauneya1a7f5422009-12-06 20:53:42 +000078int testcase[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080079 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 * */
vapierd13d74b2006-02-11 07:24:00 +000085};
86
Cyril Hrubis63564ce2015-02-04 13:28:31 +010087char *TCID = "timer_settime03";
88int TST_TOTAL = ARRAY_SIZE(testcase);
89
90static struct itimerspec new_set, old_set, *old_temp, *new_temp;
91static kernel_timer_t timer, tim;
92
Wanlong Gao354ebb42012-12-07 10:10:04 +080093int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000094{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020095 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020096 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000097
Garrett Cooperdf3eb162010-11-28 22:44:32 -080098 if ((msg = parse_opts(ac, av, NULL, NULL))
Wanlong Gao354ebb42012-12-07 10:10:04 +080099 != NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800100 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000101 }
102
vapierd13d74b2006-02-11 07:24:00 +0000103 setup();
104
vapierd13d74b2006-02-11 07:24:00 +0000105 for (lc = 0; TEST_LOOPING(lc); lc++) {
106
Caspar Zhangd59a6592013-03-07 14:59:12 +0800107 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +0000108
109 for (i = 0; i < TST_TOTAL; i++) {
110
111 /* Set up individual tests */
vapier6670f842006-08-22 05:57:53 +0000112 setup_test(i);
Jan Stancek359980f2013-02-15 10:16:05 +0100113 TEST(ltp_syscall(__NR_timer_settime, tim, 0, new_temp,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 old_temp));
vapierd13d74b2006-02-11 07:24:00 +0000115
116 /* check return code */
yaberauneya1a7f5422009-12-06 20:53:42 +0000117 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) {
118 tst_resm(TPASS | TTERRNO, "failed as expected");
vapierd13d74b2006-02-11 07:24:00 +0000119 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000120 tst_resm(TFAIL | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 "didn't fail as expected [expected "
122 "errno = %d (%s)]",
123 testcase[i], strerror(testcase[i]));
124 } /* end of else */
vapierd13d74b2006-02-11 07:24:00 +0000125
Garrett Cooper2c282152010-12-16 00:55:50 -0800126 }
yaberauneya1a7f5422009-12-06 20:53:42 +0000127
Garrett Cooper2c282152010-12-16 00:55:50 -0800128 }
vapierd13d74b2006-02-11 07:24:00 +0000129
vapierd13d74b2006-02-11 07:24:00 +0000130 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000131 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000132}
133
134/* This function sets up individual tests */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800135void setup_test(int option)
vapierd13d74b2006-02-11 07:24:00 +0000136{
137 switch (option) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000138 case 0:
139 /* Pass NULL structure as new setting */
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200140 new_temp = NULL;
yaberauneya1a7f5422009-12-06 20:53:42 +0000141 tim = timer;
142 old_temp = &old_set;
143 break;
144 case 1:
145 /* Make tv_nsec value less than 0 */
146 new_set.it_value.tv_nsec = -1;
147 new_set.it_value.tv_sec = 5;
148 new_set.it_interval.tv_sec = 0;
149 new_set.it_interval.tv_nsec = 0;
150 new_temp = &new_set;
151 break;
152 case 2:
153 /* Make tv_nsec more than NSEC_PER_SEC */
154 new_set.it_value.tv_nsec = NSEC_PER_SEC + 1;
155 break;
156 case 3:
157 /* make timer_id invalid */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800158 tim = (kernel_timer_t) - 1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000159 new_set.it_value.tv_nsec = 0;
160 break;
161 case 4:
162 /* make new_setting a bad pointer */
163 tim = timer;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800164 new_temp = (struct itimerspec *)-1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000165 break;
166 case 5:
167 /* make old_setting a bad pointer */
168 new_temp = &new_set;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800169 old_temp = (struct itimerspec *)-1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000170 break;
vapierd13d74b2006-02-11 07:24:00 +0000171 }
172}
173
174/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800175void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000176{
Garrett Cooper2c282152010-12-16 00:55:50 -0800177
vapierd13d74b2006-02-11 07:24:00 +0000178 tst_sig(NOFORK, DEF_HANDLER, cleanup);
179
Jan Stancek359980f2013-02-15 10:16:05 +0100180 if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800181 tst_brkm(TBROK, NULL, "Timer create failed. Cannot"
Wanlong Gao354ebb42012-12-07 10:10:04 +0800182 " setup test");
vapierd13d74b2006-02-11 07:24:00 +0000183 }
184
vapierd13d74b2006-02-11 07:24:00 +0000185 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800186}
vapierd13d74b2006-02-11 07:24:00 +0000187
188/*
189 * cleanup() - Performs one time cleanup for this test at
190 * completion or premature exit
191 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800192void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000193{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700194}