blob: e6a5f6e366c696b3b4e3a4d5afd8ed80871bd9a8 [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 : timer_create04
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 * timer_create(2)
vapier6670f842006-08-22 05:57:53 +000025 *
vapierd13d74b2006-02-11 07:24:00 +000026 * TEST CASE TOTAL : 8
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 timer_create(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 * For case 7 set event parameter as bad pointer
45 * for case 8 set returned timer ID parameter as bad pointer
46 * Execute system call with invalid parameter
47 * Check return code, if system call fails with errno == expected errno
48 * Issue syscall passed with expected errno
49 * Otherwise, Issue syscall failed to produce expected errno
vapier6670f842006-08-22 05:57:53 +000050 *
vapierd13d74b2006-02-11 07:24:00 +000051 * Cleanup:
52 * Print errno log and/or timing stats if options given
vapier6670f842006-08-22 05:57:53 +000053 *
vapierd13d74b2006-02-11 07:24:00 +000054 * USAGE: <for command-line>
55 * timer_create04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
56 * where:
57 * -c n : run n copies simultaneously
58 * -e : Turn on errno logging.
59 * -i n : Execute test n times.
60 * -I x : Execute test for x seconds.
61 * -p : Pause for SIGUSR1 before starting
62 * -P x : Pause for x seconds between iterations.
63 * -t : Turn on syscall timing.
64 *
65 * RESTRICTIONS:
66 * None
67 *****************************************************************************/
68
vapierbc8a4612006-08-22 05:43:15 +000069#include <stdlib.h>
vapierd13d74b2006-02-11 07:24:00 +000070#include <errno.h>
yaberauneya1a7f5422009-12-06 20:53:42 +000071#include <string.h>
vapierd13d74b2006-02-11 07:24:00 +000072#include <time.h>
73#include <signal.h>
74
vapierbc8a4612006-08-22 05:43:15 +000075#include "test.h"
76#include "usctest.h"
77#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 = "timer_create04"; /* Test program identifier. */
vapierd13d74b2006-02-11 07:24:00 +000082int TST_TOTAL; /* Total number of test cases. */
vapierd13d74b2006-02-11 07:24:00 +000083
Wanlong Gao354ebb42012-12-07 10:10:04 +080084static int exp_enos[] = { EINVAL, EFAULT, 0 };
vapierd13d74b2006-02-11 07:24:00 +000085
yaberauneya1a7f5422009-12-06 20:53:42 +000086int testcase[6] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080087 EINVAL, /* MAX_CLOCKS */
88 EINVAL, /* MAX_CLOCKS + 1 */
89 EFAULT, /* bad sigevent */
90 EFAULT /* bad timer_id */
vapierd13d74b2006-02-11 07:24:00 +000091};
92
yaberauneya1a7f5422009-12-06 20:53:42 +000093/*
94 * cleanup() - Performs one time cleanup for this test at
95 * completion or premature exit
96 */
Wanlong Gao354ebb42012-12-07 10:10:04 +080097void cleanup(void)
yaberauneya1a7f5422009-12-06 20:53:42 +000098{
99 /*
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100 * print timing stats if that option was specified.
101 * print errno log if that option was specified.
102 */
yaberauneya1a7f5422009-12-06 20:53:42 +0000103 TEST_CLEANUP;
104
Garrett Cooper2c282152010-12-16 00:55:50 -0800105}
yaberauneya1a7f5422009-12-06 20:53:42 +0000106
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +0000108{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200109 int lc, i;
110 char *msg;
Subrata Modak4e947652010-05-28 12:50:38 +0530111 kernel_timer_t timer_id, *temp_id; /* stores the returned timer_id */
vapierd13d74b2006-02-11 07:24:00 +0000112 struct sigevent *temp_ev; /* used for bad address test case */
113
subrata_modake8af9782008-02-26 11:14:44 +0000114 clockid_t clocks[6] = {
vapierd13d74b2006-02-11 07:24:00 +0000115 MAX_CLOCKS,
116 MAX_CLOCKS + 1,
117 CLOCK_REALTIME,
subrata_modake8af9782008-02-26 11:14:44 +0000118 CLOCK_MONOTONIC,
119 CLOCK_PROCESS_CPUTIME_ID,
120 CLOCK_THREAD_CPUTIME_ID
vapierd13d74b2006-02-11 07:24:00 +0000121 };
122
Garrett Cooper53740502010-12-16 00:04:01 -0800123 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
124 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000125
126 TST_TOTAL = sizeof(testcase) / sizeof(testcase[0]);
127
subrata_modake8af9782008-02-26 11:14:44 +0000128 /* PROCESS_CPUTIME_ID & THREAD_CPUTIME_ID are not supported on
129 * kernel versions lower than 2.6.12
130 */
yaberauneya1a7f5422009-12-06 20:53:42 +0000131 if (tst_kvercmp(2, 6, 12) < 0) {
132 testcase[4] = EINVAL;
133 testcase[5] = EINVAL;
134 } else {
135 testcase[4] = EFAULT;
136 testcase[5] = EFAULT;
subrata_modake8af9782008-02-26 11:14:44 +0000137 }
138
vapierd13d74b2006-02-11 07:24:00 +0000139 setup();
subrata_modake8af9782008-02-26 11:14:44 +0000140
vapierd13d74b2006-02-11 07:24:00 +0000141 for (lc = 0; TEST_LOOPING(lc); lc++) {
142
vapierd13d74b2006-02-11 07:24:00 +0000143 Tst_count = 0;
144
145 for (i = 0; i < TST_TOTAL; i++) {
146
Wanlong Gao354ebb42012-12-07 10:10:04 +0800147 temp_ev = (struct sigevent *)NULL;
vapierd13d74b2006-02-11 07:24:00 +0000148 temp_id = &timer_id;
149
yaberauneya1a7f5422009-12-06 20:53:42 +0000150 switch (i) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800151 case 2: /* make the timer_id bad address */
152 temp_id = (kernel_timer_t *) - 1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000153 break;
154 case 3:
155 /* make the event bad address */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800156 temp_ev = (struct sigevent *)-1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000157 break;
158 case 4:
159 /* Produce an invalid timer_id address. */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800160 if (tst_kvercmp(2, 6, 12) >= 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800161 temp_id = (kernel_timer_t *) - 1;
yaberauneya1a7f5422009-12-06 20:53:42 +0000162 break;
163 case 5:
164 /* Produce an invalid event address. */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800165 if (tst_kvercmp(2, 6, 12) >= 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166 temp_ev = (struct sigevent *)-1;
vapierd13d74b2006-02-11 07:24:00 +0000167 }
168
Jan Stancek359980f2013-02-15 10:16:05 +0100169 TEST(ltp_syscall(__NR_timer_create, clocks[i], temp_ev,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800170 temp_id));
vapierd13d74b2006-02-11 07:24:00 +0000171
172 /* check return code */
yaberauneya1a7f5422009-12-06 20:53:42 +0000173 if (TEST_RETURN == -1 && TEST_ERRNO == testcase[i]) {
174 tst_resm(TPASS | TTERRNO, "failed as expected");
vapierd13d74b2006-02-11 07:24:00 +0000175 } else {
yaberauneya1a7f5422009-12-06 20:53:42 +0000176 tst_resm(TFAIL | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800177 "didn't fail as expected [expected "
178 "errno = %d (%s)]",
179 testcase[i], strerror(testcase[i]));
180 } /* end of else */
vapierd13d74b2006-02-11 07:24:00 +0000181
Garrett Cooper2c282152010-12-16 00:55:50 -0800182 }
yaberauneya1a7f5422009-12-06 20:53:42 +0000183
Garrett Cooper2c282152010-12-16 00:55:50 -0800184 }
vapierd13d74b2006-02-11 07:24:00 +0000185
vapierd13d74b2006-02-11 07:24:00 +0000186 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000187 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000188}
189
190/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800191void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000192{
Garrett Cooper2c282152010-12-16 00:55:50 -0800193
vapierd13d74b2006-02-11 07:24:00 +0000194 tst_sig(NOFORK, DEF_HANDLER, cleanup);
195
196 /* set the expected errnos... */
197 TEST_EXP_ENOS(exp_enos);
198
vapierd13d74b2006-02-11 07:24:00 +0000199 TEST_PAUSE;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700200}