blob: de3ad24744b564f6abbe1e0d65d01c95269c9c41 [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_gettime02
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 clock_gettime(2)
vapier6670f842006-08-22 05:57:53 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 2
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_gettime(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 * Execute system call for each defined clock value
44 * Check return code, if system call failed (return=-1)
45 * Log the errno and Issue a FAIL message.
46 * Otherwise, Issue a PASS message.
vapier6670f842006-08-22 05:57:53 +000047 *
vapierd13d74b2006-02-11 07:24:00 +000048 * Cleanup:
49 * Print errno log and/or timing stats if options given
vapier6670f842006-08-22 05:57:53 +000050 *
vapierd13d74b2006-02-11 07:24:00 +000051 * USAGE: <for command-line>
52 * clock_gettime02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
53 * where:
vapier6670f842006-08-22 05:57:53 +000054 * -c n : Run n copies simultaneously.
vapierd13d74b2006-02-11 07:24:00 +000055 * -e : Turn on errno logging.
56 * -i n : Execute test n times.
57 * -I x : Execute test for x seconds.
58 * -p : Pause for SIGUSR1 before starting
59 * -P x : Pause for x seconds between iterations.
60 * -t : Turn on syscall timing.
61 *
62 *RESTRICTIONS:
63 * None
64 *****************************************************************************/
65
vapierbc8a4612006-08-22 05:43:15 +000066#include <stdlib.h>
67#include <errno.h>
68#include <time.h>
69#include <signal.h>
70
vapierd13d74b2006-02-11 07:24:00 +000071#include "test.h"
vapierbc8a4612006-08-22 05:43:15 +000072#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000073
Garrett Coopera9670cd2010-11-28 21:55:20 -080074void setup(void);
Cyril Hrubis63564ce2015-02-04 13:28:31 +010075static clockid_t clocks[2] = { CLOCK_REALTIME, CLOCK_MONOTONIC };
vapierd13d74b2006-02-11 07:24:00 +000076
Cyril Hrubis63564ce2015-02-04 13:28:31 +010077char *TCID = "clock_gettime02";
78int TST_TOTAL = ARRAY_SIZE(clocks);
vapierd13d74b2006-02-11 07:24:00 +000079
Wanlong Gao354ebb42012-12-07 10:10:04 +080080int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000081{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020082 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020083 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000084 struct timespec spec;
vapierd13d74b2006-02-11 07:24:00 +000085
Wanlong Gao354ebb42012-12-07 10:10:04 +080086 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Coopera9670cd2010-11-28 21:55:20 -080087 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000088
vapierd13d74b2006-02-11 07:24:00 +000089 setup();
90
vapierd13d74b2006-02-11 07:24:00 +000091 for (lc = 0; TEST_LOOPING(lc); lc++) {
92
Caspar Zhangd59a6592013-03-07 14:59:12 +080093 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000094
95 for (i = 0; i < TST_TOTAL; i++) {
Jan Stancek359980f2013-02-15 10:16:05 +010096 TEST(ltp_syscall(__NR_clock_gettime, clocks[i], &spec));
yaberauneya1a7f5422009-12-06 20:53:42 +000097 tst_resm((TEST_RETURN < 0 ? TFAIL | TTERRNO : TPASS),
Wanlong Gao354ebb42012-12-07 10:10:04 +080098 "%s",
99 (TEST_RETURN == 0 ? "passed" : "failed"));
Garrett Cooper2c282152010-12-16 00:55:50 -0800100 }
101 }
vapierd13d74b2006-02-11 07:24:00 +0000102
yaberauneya1a7f5422009-12-06 20:53:42 +0000103 CLEANUP();
104 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000105}
106
107/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800108void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000109{
Garrett Cooper2c282152010-12-16 00:55:50 -0800110
yaberauneya1a7f5422009-12-06 20:53:42 +0000111 tst_sig(NOFORK, DEF_HANDLER, CLEANUP);
vapierd13d74b2006-02-11 07:24:00 +0000112
vapierd13d74b2006-02-11 07:24:00 +0000113 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800114}
vapierd13d74b2006-02-11 07:24:00 +0000115
116/*
yaberauneya1a7f5422009-12-06 20:53:42 +0000117 * CLEANUP() - Performs one time CLEANUP for this test at
vapierd13d74b2006-02-11 07:24:00 +0000118 * completion or premature exit
119 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800120void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000121{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700122}