blob: eb8ba9fe2d1b1d4d03b06573643ed86e7e4176b3 [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"
vapierbc8a4612006-08-22 05:43:15 +000076#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000077
Garrett Coopera9670cd2010-11-28 21:55:20 -080078void setup(void);
vapierd13d74b2006-02-11 07:24:00 +000079
yaberauneya1a7f5422009-12-06 20:53:42 +000080int testcase[6] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080081 EFAULT, /* Bad timespec */
82 EFAULT, /* Bad timespec */
83 EINVAL, /* MAX_CLOCKS */
84 EINVAL /* MAX_CLOCKS + 1 */
vapierd13d74b2006-02-11 07:24:00 +000085};
86
Cyril Hrubis63564ce2015-02-04 13:28:31 +010087char *TCID = "clock_gettime03"; /* Test program identifier. */
88int TST_TOTAL = ARRAY_SIZE(testcase);
89
Wanlong Gao354ebb42012-12-07 10:10:04 +080090int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000091{
Wanlong Gao354ebb42012-12-07 10:10:04 +080092 int i, lc; /* loop counter */
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020093 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000094 struct timespec spec, *temp;
subrata_modake8af9782008-02-26 11:14:44 +000095
96 clockid_t clocks[] = {
vapierd13d74b2006-02-11 07:24:00 +000097 CLOCK_REALTIME,
subrata_modake8af9782008-02-26 11:14:44 +000098 CLOCK_MONOTONIC,
vapierd13d74b2006-02-11 07:24:00 +000099 MAX_CLOCKS,
subrata_modake8af9782008-02-26 11:14:44 +0000100 MAX_CLOCKS + 1,
101 CLOCK_PROCESS_CPUTIME_ID,
102 CLOCK_THREAD_CPUTIME_ID
vapierd13d74b2006-02-11 07:24:00 +0000103 };
104
Garrett Coopera9670cd2010-11-28 21:55:20 -0800105 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
106 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000107
Garrett Cooper2c282152010-12-16 00:55:50 -0800108 /*
Garrett Coopera9670cd2010-11-28 21:55:20 -0800109 * PROCESS_CPUTIME_ID & THREAD_CPUTIME_ID are not supported on
subrata_modake8af9782008-02-26 11:14:44 +0000110 * kernel versions lower than 2.6.12
111 */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800112 if ((tst_kvercmp(2, 6, 12)) < 0) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000113 testcase[4] = EINVAL;
114 testcase[5] = EINVAL;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800115 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000116 testcase[4] = EFAULT;
117 testcase[5] = EFAULT;
subrata_modake8af9782008-02-26 11:14:44 +0000118 }
119
vapierd13d74b2006-02-11 07:24:00 +0000120 setup();
121
vapierd13d74b2006-02-11 07:24:00 +0000122 for (lc = 0; TEST_LOOPING(lc); lc++) {
123
Caspar Zhangd59a6592013-03-07 14:59:12 +0800124 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +0000125
126 for (i = 0; i < TST_TOTAL; i++) {
subrata_modake8af9782008-02-26 11:14:44 +0000127 temp = &spec;
128
vapierd13d74b2006-02-11 07:24:00 +0000129 if (i == 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800130 temp = (struct timespec *)-1;
vapierd13d74b2006-02-11 07:24:00 +0000131 } else if (i == 1) {
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200132 temp = NULL;
subrata_modake8af9782008-02-26 11:14:44 +0000133 } else if ((i >= 4) && (tst_kvercmp(2, 6, 12) >= 0)) {
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200134 temp = NULL;
vapierd13d74b2006-02-11 07:24:00 +0000135 }
136
Jan Stancek359980f2013-02-15 10:16:05 +0100137 TEST(ltp_syscall(__NR_clock_gettime, clocks[i], temp));
vapierd13d74b2006-02-11 07:24:00 +0000138
139 /* check return code */
yaberauneya1a7f5422009-12-06 20:53:42 +0000140 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) {
141 tst_resm(TPASS | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800142 "got expected failure");
vapierd13d74b2006-02-11 07:24:00 +0000143 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000144 tst_resm(TFAIL | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800145 "failed to produce expected error "
146 "[expected errno = %d (%s), "
147 "TEST_RETURN = %ld]",
148 testcase[i], strerror(testcase[i]),
149 TEST_RETURN);
150 } /* end of else */
vapierd13d74b2006-02-11 07:24:00 +0000151
Wanlong Gao354ebb42012-12-07 10:10:04 +0800152 } /*End of TEST CASE LOOPING */
yaberauneya1a7f5422009-12-06 20:53:42 +0000153
Wanlong Gao354ebb42012-12-07 10:10:04 +0800154 } /*End for TEST_LOOPING */
vapierd13d74b2006-02-11 07:24:00 +0000155
vapierd13d74b2006-02-11 07:24:00 +0000156 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000157 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000158}
159
160/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800161void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000162{
Garrett Cooper2c282152010-12-16 00:55:50 -0800163
vapierd13d74b2006-02-11 07:24:00 +0000164 tst_sig(NOFORK, DEF_HANDLER, cleanup);
165
vapierd13d74b2006-02-11 07:24:00 +0000166 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800167}
vapierd13d74b2006-02-11 07:24:00 +0000168
169/*
170 * cleanup() - Performs one time cleanup for this test at
171 * completion or premature exit
172 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800173void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000174{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700175}