blob: a976702f6b09823aba1e371fc34870a696a49c69 [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_gettime03
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 : Test checking for basic error conditions for
24 * clock_gettime(2)
vapier6670f842006-08-22 05:57:53 +000025 *
vapierd13d74b2006-02-11 07:24:00 +000026 * TEST CASE TOTAL : 7
vapier6670f842006-08-22 05:57:53 +000027 *
vapierd13d74b2006-02-11 07:24:00 +000028 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
vapier6670f842006-08-22 05:57:53 +000029 *
vapierd13d74b2006-02-11 07:24:00 +000030 * SIGNALS
31 * Uses SIGUSR1 to pause before test if option set.
32 * (See the parse_opts(3) man page).
33 *
34 * DESCRIPTION
35 * This test case check whether clock_gettime(2) returns appropriate error
36 * value for invalid parameter
37 *
38 * Setup:
39 * Setup signal handling.
40 * Pause for SIGUSR1 if option specified.
vapier6670f842006-08-22 05:57:53 +000041 *
vapierd13d74b2006-02-11 07:24:00 +000042 * Test:
43 * Loop if the proper options are given.
44 * If it is the first test case
45 * make temp a bad pointer
46 * Otherwise pass defined struct timespec variable to temp
47 * Execute system call with invalid parameter
48 * Check return code, if system call fails with errno == expected errno
49 * Issue syscall passed with expected errno
50 * Otherwise, Issue syscall failed to produce expected errno
vapier6670f842006-08-22 05:57:53 +000051 *
vapierd13d74b2006-02-11 07:24:00 +000052 * Cleanup:
53 * Print errno log and/or timing stats if options given
vapier6670f842006-08-22 05:57:53 +000054 *
vapierd13d74b2006-02-11 07:24:00 +000055 * USAGE: <for command-line>
56 * clock_gettime03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
57 * where:
58 * -c n : run n copies simultaneously
59 * -e : Turn on errno logging.
60 * -i n : Execute test n times.
61 * -I x : Execute test for x seconds.
62 * -p : Pause for SIGUSR1 before starting
63 * -P x : Pause for x seconds between iterations.
64 * -t : Turn on syscall timing.
65 *
66 * RESTRICTIONS:
67 * None
68 *****************************************************************************/
69
vapierbc8a4612006-08-22 05:43:15 +000070#include <stdlib.h>
71#include <errno.h>
72#include <time.h>
73#include <signal.h>
74
vapierd13d74b2006-02-11 07:24:00 +000075#include "test.h"
76#include "usctest.h"
vapierbc8a4612006-08-22 05:43:15 +000077#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000078
Garrett Coopera9670cd2010-11-28 21:55:20 -080079void setup(void);
vapierd13d74b2006-02-11 07:24:00 +000080
Wanlong Gao354ebb42012-12-07 10:10:04 +080081char *TCID = "clock_gettime03"; /* Test program identifier. */
82int TST_TOTAL; /* Total number of test cases. */
83static int exp_enos[] = { EINVAL, EFAULT, 0 };
vapierd13d74b2006-02-11 07:24:00 +000084
yaberauneya1a7f5422009-12-06 20:53:42 +000085int testcase[6] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080086 EFAULT, /* Bad timespec */
87 EFAULT, /* Bad timespec */
88 EINVAL, /* MAX_CLOCKS */
89 EINVAL /* MAX_CLOCKS + 1 */
vapierd13d74b2006-02-11 07:24:00 +000090};
91
Wanlong Gao354ebb42012-12-07 10:10:04 +080092int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000093{
Wanlong Gao354ebb42012-12-07 10:10:04 +080094 int i, lc; /* loop counter */
Cyril Hrubis89af32a2012-10-24 16:39:11 +020095 char *msg;
vapierd13d74b2006-02-11 07:24:00 +000096 struct timespec spec, *temp;
subrata_modake8af9782008-02-26 11:14:44 +000097
98 clockid_t clocks[] = {
vapierd13d74b2006-02-11 07:24:00 +000099 CLOCK_REALTIME,
subrata_modake8af9782008-02-26 11:14:44 +0000100 CLOCK_MONOTONIC,
vapierd13d74b2006-02-11 07:24:00 +0000101 MAX_CLOCKS,
subrata_modake8af9782008-02-26 11:14:44 +0000102 MAX_CLOCKS + 1,
103 CLOCK_PROCESS_CPUTIME_ID,
104 CLOCK_THREAD_CPUTIME_ID
vapierd13d74b2006-02-11 07:24:00 +0000105 };
106
Garrett Coopera9670cd2010-11-28 21:55:20 -0800107 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
108 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000109
110 TST_TOTAL = sizeof(testcase) / sizeof(testcase[0]);
vapier6670f842006-08-22 05:57:53 +0000111
Garrett Cooper2c282152010-12-16 00:55:50 -0800112 /*
Garrett Coopera9670cd2010-11-28 21:55:20 -0800113 * PROCESS_CPUTIME_ID & THREAD_CPUTIME_ID are not supported on
subrata_modake8af9782008-02-26 11:14:44 +0000114 * kernel versions lower than 2.6.12
115 */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800116 if ((tst_kvercmp(2, 6, 12)) < 0) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000117 testcase[4] = EINVAL;
118 testcase[5] = EINVAL;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800119 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000120 testcase[4] = EFAULT;
121 testcase[5] = EFAULT;
subrata_modake8af9782008-02-26 11:14:44 +0000122 }
123
vapierd13d74b2006-02-11 07:24:00 +0000124 setup();
125
vapierd13d74b2006-02-11 07:24:00 +0000126 for (lc = 0; TEST_LOOPING(lc); lc++) {
127
vapierd13d74b2006-02-11 07:24:00 +0000128 Tst_count = 0;
129
130 for (i = 0; i < TST_TOTAL; i++) {
subrata_modake8af9782008-02-26 11:14:44 +0000131 temp = &spec;
132
vapierd13d74b2006-02-11 07:24:00 +0000133 if (i == 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800134 temp = (struct timespec *)-1;
vapierd13d74b2006-02-11 07:24:00 +0000135 } else if (i == 1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800136 temp = (struct timespec *)NULL;
subrata_modake8af9782008-02-26 11:14:44 +0000137 } else if ((i >= 4) && (tst_kvercmp(2, 6, 12) >= 0)) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800138 temp = (struct timespec *)NULL;
vapierd13d74b2006-02-11 07:24:00 +0000139 }
140
Jan Stancek359980f2013-02-15 10:16:05 +0100141 TEST(ltp_syscall(__NR_clock_gettime, clocks[i], temp));
vapierd13d74b2006-02-11 07:24:00 +0000142
143 /* check return code */
yaberauneya1a7f5422009-12-06 20:53:42 +0000144 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) {
145 tst_resm(TPASS | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800146 "got expected failure");
vapierd13d74b2006-02-11 07:24:00 +0000147 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000148 tst_resm(TFAIL | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800149 "failed to produce expected error "
150 "[expected errno = %d (%s), "
151 "TEST_RETURN = %ld]",
152 testcase[i], strerror(testcase[i]),
153 TEST_RETURN);
154 } /* end of else */
vapierd13d74b2006-02-11 07:24:00 +0000155
Wanlong Gao354ebb42012-12-07 10:10:04 +0800156 } /*End of TEST CASE LOOPING */
yaberauneya1a7f5422009-12-06 20:53:42 +0000157
Wanlong Gao354ebb42012-12-07 10:10:04 +0800158 } /*End for TEST_LOOPING */
vapierd13d74b2006-02-11 07:24:00 +0000159
vapierd13d74b2006-02-11 07:24:00 +0000160 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000161 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000162}
163
164/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800165void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000166{
Garrett Cooper2c282152010-12-16 00:55:50 -0800167
vapierd13d74b2006-02-11 07:24:00 +0000168 tst_sig(NOFORK, DEF_HANDLER, cleanup);
169
170 /* set the expected errnos... */
171 TEST_EXP_ENOS(exp_enos);
172
vapierd13d74b2006-02-11 07:24:00 +0000173 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800174}
vapierd13d74b2006-02-11 07:24:00 +0000175
176/*
177 * cleanup() - Performs one time cleanup for this test at
178 * completion or premature exit
179 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800180void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000181{
182 /*
Wanlong Gao354ebb42012-12-07 10:10:04 +0800183 * print timing stats if that option was specified.
184 * print errno log if that option was specified.
185 */
vapierd13d74b2006-02-11 07:24:00 +0000186 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700187}