blob: 573cc5f7cfc298483234872d702ba1aad1bbe6a2 [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_settime02
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 : Basic test for timer_settime(2)
vapier6670f842006-08-22 05:57:53 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 4
vapier6670f842006-08-22 05:57:53 +000026 *
vapierd13d74b2006-02-11 07:24:00 +000027 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
vapier6670f842006-08-22 05:57:53 +000028 *
vapierd13d74b2006-02-11 07:24:00 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * This is a Phase I test for the timer_settime(2) system call.
35 * It is intended to provide a limited exposure of the system call.
vapier6670f842006-08-22 05:57:53 +000036 *
vapierd13d74b2006-02-11 07:24:00 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
vapier6670f842006-08-22 05:57:53 +000040 *
vapierd13d74b2006-02-11 07:24:00 +000041 * Test:
42 * Loop if the proper options are given.
43 * setup individual test
44 * Execute system call
45 * Check return code, if system call failed (return=-1)
46 * Log the errno and Issue a FAIL message.
47 * Otherwise, Issue a PASS message.
vapier6670f842006-08-22 05:57:53 +000048 *
vapierd13d74b2006-02-11 07:24:00 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
vapier6670f842006-08-22 05:57:53 +000051 *
vapierd13d74b2006-02-11 07:24:00 +000052 * USAGE: <for command-line>
53 * timer_settime02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
54 * where:
vapier6670f842006-08-22 05:57:53 +000055 * -c n : Run n copies simultaneously.
vapierd13d74b2006-02-11 07:24:00 +000056 * -e : Turn on errno logging.
57 * -i n : Execute test n times.
58 * -I x : Execute test for x seconds.
59 * -p : Pause for SIGUSR1 before starting
60 * -P x : Pause for x seconds between iterations.
61 * -t : Turn on syscall timing.
62 *
63 *RESTRICTIONS:
64 * None
65 *****************************************************************************/
66
vapierbc8a4612006-08-22 05:43:15 +000067#include <stdlib.h>
68#include <errno.h>
69#include <time.h>
70#include <signal.h>
71
vapierd13d74b2006-02-11 07:24:00 +000072#include "test.h"
vapierbc8a4612006-08-22 05:43:15 +000073#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000074
Garrett Coopera9670cd2010-11-28 21:55:20 -080075void setup(void);
vapierd13d74b2006-02-11 07:24:00 +000076static int setup_test(int option);
77
78char *TCID = "timer_settime02"; /* Test program identifier. */
79int TST_TOTAL = 4; /* Total number of test cases. */
vapierd13d74b2006-02-11 07:24:00 +000080
81static struct itimerspec new_set, old_set, *old_temp;
Subrata Modak4e947652010-05-28 12:50:38 +053082static kernel_timer_t timer;
vapierd13d74b2006-02-11 07:24:00 +000083static int flag;
84
Wanlong Gao354ebb42012-12-07 10:10:04 +080085int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000086{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020087 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020088 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000089
Cyril Hrubiscf0d6262014-09-23 14:03:31 +020090 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -080091 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000092 }
93
vapierd13d74b2006-02-11 07:24:00 +000094 setup();
95
vapierd13d74b2006-02-11 07:24:00 +000096 for (lc = 0; TEST_LOOPING(lc); lc++) {
97
Caspar Zhangd59a6592013-03-07 14:59:12 +080098 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000099
100 for (i = 0; i < TST_TOTAL; i++) {
101
102 /* Set up individual test */
yaberauneya1a7f5422009-12-06 20:53:42 +0000103 if (setup_test(i) == 0) {
Jan Stancek359980f2013-02-15 10:16:05 +0100104 TEST(ltp_syscall(__NR_timer_settime, timer,
105 flag, &new_set, old_temp));
yaberauneya1a7f5422009-12-06 20:53:42 +0000106 tst_resm((TEST_RETURN == 0 ?
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107 TPASS :
108 TFAIL | TTERRNO),
109 "%s",
110 (TEST_RETURN ==
111 0 ? "passed" : "failed")
112 );
vapierd13d74b2006-02-11 07:24:00 +0000113 }
114
Garrett Cooper2c282152010-12-16 00:55:50 -0800115 }
116 }
vapierd13d74b2006-02-11 07:24:00 +0000117
vapierd13d74b2006-02-11 07:24:00 +0000118 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000119 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000120}
121
122/* This function does set up for individual tests */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800123static int setup_test(int option)
vapierd13d74b2006-02-11 07:24:00 +0000124{
125 struct timespec timenow; /* Used to obtain current time */
yaberauneya1a7f5422009-12-06 20:53:42 +0000126 int rc = 0;
vapierd13d74b2006-02-11 07:24:00 +0000127
128 switch (option) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000129 case 0:
130 /* This is general initialization.
131 * make old_setting NULL
132 * make flags equal to zero
133 * use one-shot timer
134 */
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200135 old_temp = NULL;
yaberauneya1a7f5422009-12-06 20:53:42 +0000136 new_set.it_interval.tv_sec = 0;
137 new_set.it_interval.tv_nsec = 0;
138 new_set.it_value.tv_sec = 5;
139 new_set.it_value.tv_nsec = 0;
140 flag = 0;
141 break;
142 case 1:
143 /* get the old_setting in old_set
144 * This test case also takes care
145 * of situation where the timerid is
146 * already armed
147 */
148 old_temp = &old_set;
149 break;
150 case 2:
151 /* Use the periodic timer */
152 new_set.it_interval.tv_sec = 5;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800153 new_set.it_value.tv_sec = 0;
yaberauneya1a7f5422009-12-06 20:53:42 +0000154 break;
155 case 3:
156 /* Use TIMER_ABSTIME flag for setting
157 * absolute time for timer
158 */
159 flag = TIMER_ABSTIME;
Garrett Cooper2c282152010-12-16 00:55:50 -0800160 /*
yaberauneya1a7f5422009-12-06 20:53:42 +0000161 * Let's not use the linux_syscall_number syscall(2)
162 * wrapper here because our primary test focus is
163 * timer_create, not clock_gettime. That's covered in
164 * those respective tests.
165 */
166 if (clock_gettime(CLOCK_REALTIME, &timenow) < 0) {
167 tst_resm(TWARN | TERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800168 "clock_gettime failed; skipping the test");
yaberauneya1a7f5422009-12-06 20:53:42 +0000169 rc = -1;
170 } else {
vapierd13d74b2006-02-11 07:24:00 +0000171 new_set.it_value.tv_sec = timenow.tv_sec + 25;
yaberauneya1a7f5422009-12-06 20:53:42 +0000172 }
173 break;
vapierd13d74b2006-02-11 07:24:00 +0000174 }
yaberauneya1a7f5422009-12-06 20:53:42 +0000175 return rc;
vapierd13d74b2006-02-11 07:24:00 +0000176}
177
178/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800179void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000180{
Garrett Cooper2c282152010-12-16 00:55:50 -0800181
vapierd13d74b2006-02-11 07:24:00 +0000182 tst_sig(NOFORK, DEF_HANDLER, cleanup);
183
vapierd13d74b2006-02-11 07:24:00 +0000184 TEST_PAUSE;
185
Jan Stancek359980f2013-02-15 10:16:05 +0100186 if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0)
Garrett Cooper53740502010-12-16 00:04:01 -0800187 tst_brkm(TBROK, NULL, "timer_create failed");
Garrett Coopera9670cd2010-11-28 21:55:20 -0800188}
vapierd13d74b2006-02-11 07:24:00 +0000189
190/*
191 * cleanup() - Performs one time cleanup for this test at
192 * completion or premature exit
193 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800194void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000195{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700196}