blob: 01767eb338559a76b27a7349d32bb02e22f5b109 [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"
73#include "usctest.h"
vapierbc8a4612006-08-22 05:43:15 +000074#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000075
Garrett Coopera9670cd2010-11-28 21:55:20 -080076void setup(void);
vapierd13d74b2006-02-11 07:24:00 +000077static int setup_test(int option);
78
79char *TCID = "timer_settime02"; /* Test program identifier. */
80int TST_TOTAL = 4; /* Total number of test cases. */
vapierd13d74b2006-02-11 07:24:00 +000081
82static struct itimerspec new_set, old_set, *old_temp;
Subrata Modak4e947652010-05-28 12:50:38 +053083static kernel_timer_t timer;
vapierd13d74b2006-02-11 07:24:00 +000084static int flag;
85
Wanlong Gao354ebb42012-12-07 10:10:04 +080086int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000087{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020088 int lc, i;
89 char *msg;
vapierd13d74b2006-02-11 07:24:00 +000090
Wanlong Gao354ebb42012-12-07 10:10:04 +080091 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -080092 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000093 }
94
vapierd13d74b2006-02-11 07:24:00 +000095 setup();
96
vapierd13d74b2006-02-11 07:24:00 +000097 for (lc = 0; TEST_LOOPING(lc); lc++) {
98
vapierd13d74b2006-02-11 07:24:00 +000099 Tst_count = 0;
100
101 for (i = 0; i < TST_TOTAL; i++) {
102
103 /* Set up individual test */
yaberauneya1a7f5422009-12-06 20:53:42 +0000104 if (setup_test(i) == 0) {
Jan Stancek359980f2013-02-15 10:16:05 +0100105 TEST(ltp_syscall(__NR_timer_settime, timer,
106 flag, &new_set, old_temp));
yaberauneya1a7f5422009-12-06 20:53:42 +0000107 tst_resm((TEST_RETURN == 0 ?
Wanlong Gao354ebb42012-12-07 10:10:04 +0800108 TPASS :
109 TFAIL | TTERRNO),
110 "%s",
111 (TEST_RETURN ==
112 0 ? "passed" : "failed")
113 );
vapierd13d74b2006-02-11 07:24:00 +0000114 }
115
Garrett Cooper2c282152010-12-16 00:55:50 -0800116 }
117 }
vapierd13d74b2006-02-11 07:24:00 +0000118
vapierd13d74b2006-02-11 07:24:00 +0000119 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000120 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000121}
122
123/* This function does set up for individual tests */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124static int setup_test(int option)
vapierd13d74b2006-02-11 07:24:00 +0000125{
126 struct timespec timenow; /* Used to obtain current time */
yaberauneya1a7f5422009-12-06 20:53:42 +0000127 int rc = 0;
vapierd13d74b2006-02-11 07:24:00 +0000128
129 switch (option) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000130 case 0:
131 /* This is general initialization.
132 * make old_setting NULL
133 * make flags equal to zero
134 * use one-shot timer
135 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800136 old_temp = (struct itimerspec *)NULL;
yaberauneya1a7f5422009-12-06 20:53:42 +0000137 new_set.it_interval.tv_sec = 0;
138 new_set.it_interval.tv_nsec = 0;
139 new_set.it_value.tv_sec = 5;
140 new_set.it_value.tv_nsec = 0;
141 flag = 0;
142 break;
143 case 1:
144 /* get the old_setting in old_set
145 * This test case also takes care
146 * of situation where the timerid is
147 * already armed
148 */
149 old_temp = &old_set;
150 break;
151 case 2:
152 /* Use the periodic timer */
153 new_set.it_interval.tv_sec = 5;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800154 new_set.it_value.tv_sec = 0;
yaberauneya1a7f5422009-12-06 20:53:42 +0000155 break;
156 case 3:
157 /* Use TIMER_ABSTIME flag for setting
158 * absolute time for timer
159 */
160 flag = TIMER_ABSTIME;
Garrett Cooper2c282152010-12-16 00:55:50 -0800161 /*
yaberauneya1a7f5422009-12-06 20:53:42 +0000162 * Let's not use the linux_syscall_number syscall(2)
163 * wrapper here because our primary test focus is
164 * timer_create, not clock_gettime. That's covered in
165 * those respective tests.
166 */
167 if (clock_gettime(CLOCK_REALTIME, &timenow) < 0) {
168 tst_resm(TWARN | TERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800169 "clock_gettime failed; skipping the test");
yaberauneya1a7f5422009-12-06 20:53:42 +0000170 rc = -1;
171 } else {
vapierd13d74b2006-02-11 07:24:00 +0000172 new_set.it_value.tv_sec = timenow.tv_sec + 25;
yaberauneya1a7f5422009-12-06 20:53:42 +0000173 }
174 break;
vapierd13d74b2006-02-11 07:24:00 +0000175 }
yaberauneya1a7f5422009-12-06 20:53:42 +0000176 return rc;
vapierd13d74b2006-02-11 07:24:00 +0000177}
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
vapierd13d74b2006-02-11 07:24:00 +0000185 TEST_PAUSE;
186
Jan Stancek359980f2013-02-15 10:16:05 +0100187 if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0)
Garrett Cooper53740502010-12-16 00:04:01 -0800188 tst_brkm(TBROK, NULL, "timer_create failed");
Garrett Coopera9670cd2010-11-28 21:55:20 -0800189}
vapierd13d74b2006-02-11 07:24:00 +0000190
191/*
192 * cleanup() - Performs one time cleanup for this test at
193 * completion or premature exit
194 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800195void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000196{
197 /*
Wanlong Gao354ebb42012-12-07 10:10:04 +0800198 * print timing stats if that option was specified.
199 * print errno log if that option was specified.
200 */
vapierd13d74b2006-02-11 07:24:00 +0000201 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700202}