blob: 996fb6cc4bf922780490cc23a9e7be0a3944802b [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 : clock_settime02
20 *
vapierd13d74b2006-02-11 07:24:00 +000021 * EXECUTED BY : root / superuser
vapier6670f842006-08-22 05:57:53 +000022 *
vapierd13d74b2006-02-11 07:24:00 +000023 * TEST TITLE : Basic test for clock_settime(2)
vapier6670f842006-08-22 05:57:53 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 1
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 clock_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 * Set the parameters of timespec struct
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 * clock_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 +000076
77char *TCID = "clock_settime02"; /* Test program identifier. */
78int TST_TOTAL = 1; /* Total number of test cases. */
vapierd13d74b2006-02-11 07:24:00 +000079static struct timespec saved; /* Used to reset the time */
80
Wanlong Gao354ebb42012-12-07 10:10:04 +080081int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000082{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020083 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020084 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000085 struct timespec spec; /* Used to specify time for test */
86
Wanlong Gao354ebb42012-12-07 10:10:04 +080087 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Coopera9670cd2010-11-28 21:55:20 -080088 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000089
vapierd13d74b2006-02-11 07:24:00 +000090 setup();
91
vapierd13d74b2006-02-11 07:24:00 +000092 for (lc = 0; TEST_LOOPING(lc); lc++) {
93
Caspar Zhangd59a6592013-03-07 14:59:12 +080094 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000095
96 spec.tv_sec = 1;
97 spec.tv_nsec = 0;
98
Jan Stancek359980f2013-02-15 10:16:05 +010099 TEST(ltp_syscall(__NR_clock_settime, CLOCK_REALTIME, &spec));
yaberauneya1a7f5422009-12-06 20:53:42 +0000100 tst_resm((TEST_RETURN < 0 ? TFAIL | TTERRNO : TPASS),
Wanlong Gao354ebb42012-12-07 10:10:04 +0800101 "clock_settime %s",
102 (TEST_RETURN == 0 ? "passed" : "failed"));
Garrett Cooper2c282152010-12-16 00:55:50 -0800103 }
vapierd13d74b2006-02-11 07:24:00 +0000104
vapierd13d74b2006-02-11 07:24:00 +0000105 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000106 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000107}
108
109/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800110void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000111{
Garrett Cooper2c282152010-12-16 00:55:50 -0800112
vapierd13d74b2006-02-11 07:24:00 +0000113 tst_sig(NOFORK, DEF_HANDLER, cleanup);
114
115 /* Check whether we are root */
116 if (geteuid() != 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800117 tst_brkm(TBROK, NULL, "Test must be run as root");
vapierd13d74b2006-02-11 07:24:00 +0000118 }
119 /* Save the current time specifications */
Jan Stancek359980f2013-02-15 10:16:05 +0100120 if (ltp_syscall(__NR_clock_gettime, CLOCK_REALTIME, &saved) < 0)
Garrett Cooper53740502010-12-16 00:04:01 -0800121 tst_brkm(TBROK, NULL, "Could not save the current time");
vapierd13d74b2006-02-11 07:24:00 +0000122
vapierd13d74b2006-02-11 07:24:00 +0000123 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800124}
vapierd13d74b2006-02-11 07:24:00 +0000125
126/*
127 * cleanup() - Performs one time cleanup for this test at
128 * completion or premature exit
129 */
130
Wanlong Gao354ebb42012-12-07 10:10:04 +0800131void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000132{
133 /* Set the saved time */
134 if (clock_settime(CLOCK_REALTIME, &saved) < 0) {
135 tst_resm(TWARN, "FATAL COULD NOT RESET THE CLOCK");
136 tst_resm(TFAIL, "Error Setting Time, errno=%d", errno);
137 }
Chris Dearmanec6edca2012-10-17 19:54:01 -0700138}