1 /*
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
13 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 */
17 /**************************************************************************
18 *
19 * TEST IDENTIFIER : clock_settime02
20 *
21 * EXECUTED BY : root / superuser
22 *
23 * TEST TITLE : Basic test for clock_settime(2)
24 *
25 * TEST CASE TOTAL : 1
26 *
27 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
28 *
29 * 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.
36 *
37 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
40 *
41 * 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.
48 *
49 * Cleanup:
50 * Print errno log and/or timing stats if options given
51 *
52 * USAGE: <for command-line>
53 * clock_settime02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
54 * where:
55 * -c n : Run n copies simultaneously.
56 * -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
67 #include <stdlib.h>
68 #include <errno.h>
69 #include <time.h>
70 #include <signal.h>
71
72 #include "test.h"
73 #include "common_timers.h"
74
75 static void setup(void);
76 static void cleanup(void);
77
78 char *TCID = "clock_settime02";
79 int TST_TOTAL = 1;
80 static struct timespec saved;
81
main(int ac,char ** av)82 int main(int ac, char **av)
83 {
84 int lc;
85 struct timespec spec;
86
87 tst_parse_opts(ac, av, NULL, NULL);
88
89 setup();
90
91 for (lc = 0; TEST_LOOPING(lc); lc++) {
92
93 tst_count = 0;
94
95 spec.tv_sec = saved.tv_sec + 1;
96 spec.tv_nsec = 0;
97
98 TEST(ltp_syscall(__NR_clock_settime, CLOCK_REALTIME, &spec));
99 tst_resm((TEST_RETURN < 0 ? TFAIL | TTERRNO : TPASS),
100 "clock_settime %s",
101 (TEST_RETURN == 0 ? "passed" : "failed"));
102 }
103
104 cleanup();
105 tst_exit();
106 }
107
setup(void)108 static void setup(void)
109 {
110 tst_sig(NOFORK, DEF_HANDLER, cleanup);
111
112 tst_require_root();
113
114 /* Save the current time specifications */
115 if (ltp_syscall(__NR_clock_gettime, CLOCK_REALTIME, &saved) < 0)
116 tst_brkm(TBROK, NULL, "Could not save the current time");
117
118 TEST_PAUSE;
119 }
120
cleanup(void)121 static void cleanup(void)
122 {
123 /* Set the saved time */
124 if (clock_settime(CLOCK_REALTIME, &saved) < 0) {
125 tst_resm(TWARN, "FATAL COULD NOT RESET THE CLOCK");
126 tst_resm(TFAIL, "Error Setting Time, errno=%d", errno);
127 }
128 }
129