blob: 57424fe2b33c35f353c0ba53f46a149c1d3783b3 [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_create02
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 timer_create(2)
vapier6670f842006-08-22 05:57:53 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 3
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 timer_create(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 with different notification types for
44 * clock ID CLOCK_REALTIME
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.
vapier6670f842006-08-22 05:57:53 +000048 *
vapierd13d74b2006-02-11 07:24:00 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
vapier6670f842006-08-22 05:57:53 +000051 *
vapierd13d74b2006-02-11 07:24:00 +000052 * USAGE: <for command-line>
53 * timer_create02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
54 * where:
vapier6670f842006-08-22 05:57:53 +000055 * -c n : Run n copies simultaneously.
vapierd13d74b2006-02-11 07:24:00 +000056 * -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
vapierbc8a4612006-08-22 05:43:15 +000067#include <stdlib.h>
vapierd13d74b2006-02-11 07:24:00 +000068#include <errno.h>
69#include <time.h>
70#include <signal.h>
71
vapierbc8a4612006-08-22 05:43:15 +000072#include "test.h"
73#include "usctest.h"
74#include "common_timers.h"
vapierd13d74b2006-02-11 07:24:00 +000075
Garrett Coopera9670cd2010-11-28 21:55:20 -080076void setup(void);
77void setup_test(int option);
vapierd13d74b2006-02-11 07:24:00 +000078
79char *TCID = "timer_create02"; /* Test program identifier. */
80int TST_TOTAL = 3; /* Total number of test cases. */
subrata_modake8af9782008-02-26 11:14:44 +000081static struct sigevent evp, *evp_ptr;
vapierd13d74b2006-02-11 07:24:00 +000082
Wanlong Gao354ebb42012-12-07 10:10:04 +080083int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000084{
vapier18760652006-08-22 06:06:25 +000085 int lc, i, j; /* loop counter */
Cyril Hrubis89af32a2012-10-24 16:39:11 +020086 char *msg;
Subrata Modak4e947652010-05-28 12:50:38 +053087 kernel_timer_t created_timer_id; /* holds the returned timer_id */
vapierd13d74b2006-02-11 07:24:00 +000088 char *message[3] = {
vapier6670f842006-08-22 05:57:53 +000089 "SIGEV_SIGNAL",
90 "NULL",
91 "SIGEV_NONE"
vapierd13d74b2006-02-11 07:24:00 +000092 };
subrata_modak0bd2fa82009-05-26 10:10:32 +000093 const char *mrstr = "MONOTONIC_RAW";
vapierd13d74b2006-02-11 07:24:00 +000094
Garrett Coopera9670cd2010-11-28 21:55:20 -080095 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
96 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000097
vapierd13d74b2006-02-11 07:24:00 +000098 setup();
99
vapier18760652006-08-22 06:06:25 +0000100 for (lc = 0; TEST_LOOPING(lc); lc++) {
vapierd13d74b2006-02-11 07:24:00 +0000101
vapierd13d74b2006-02-11 07:24:00 +0000102 Tst_count = 0;
103
104 for (i = 0; i < TST_TOTAL; i++) {
105
106 setup_test(i);
vapierd13d74b2006-02-11 07:24:00 +0000107
Subrata Modakc98956b2010-05-07 14:21:00 +0530108 for (j = 0; j < CLOCKS_DEFINED; ++j) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000109
110 if (strstr(get_clock_str(clock_list[j]),
Wanlong Gao354ebb42012-12-07 10:10:04 +0800111 "CPUTIME_ID")) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000112 /* (PROCESS_CPUTIME_ID &
113 * THREAD_CPUTIME_ID)
114 * is not supported on kernel versions
115 * lower than 2.6.12
subrata_modake8af9782008-02-26 11:14:44 +0000116 */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800117 if ((tst_kvercmp(2, 6, 12)) < 0) {
subrata_modake8af9782008-02-26 11:14:44 +0000118 continue;
119 }
120 }
subrata_modak0bd2fa82009-05-26 10:10:32 +0000121 if (strstr(get_clock_str(clock_list[j]), mrstr))
122 continue;
123
Jan Stancek359980f2013-02-15 10:16:05 +0100124 TEST(ltp_syscall(__NR_timer_create,
125 clock_list[j], evp_ptr,
126 &created_timer_id));
vapier18760652006-08-22 06:06:25 +0000127
yaberauneya1a7f5422009-12-06 20:53:42 +0000128 tst_resm((TEST_RETURN == 0 ?
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129 TPASS :
130 TFAIL | TTERRNO),
131 "%s %s with notification type = %s",
132 get_clock_str(clock_list[j]),
133 (TEST_RETURN == 0 ?
134 "passed" : "failed"), message[i]);
vapierd13d74b2006-02-11 07:24:00 +0000135 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800136 }
137 }
vapierd13d74b2006-02-11 07:24:00 +0000138
vapierd13d74b2006-02-11 07:24:00 +0000139 cleanup();
yaberauneya1a7f5422009-12-06 20:53:42 +0000140 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000141}
142
143/* setup_test() - sets up individual test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800144void setup_test(int option)
vapierd13d74b2006-02-11 07:24:00 +0000145{
146 switch (option) {
yaberauneya1a7f5422009-12-06 20:53:42 +0000147 case 0:
148 evp.sigev_value = (sigval_t) 0;
149 evp.sigev_signo = SIGALRM;
150 evp.sigev_notify = SIGEV_SIGNAL;
151 evp_ptr = &evp;
152 break;
153 case 1:
154 evp_ptr = NULL;
155 break;
156 case 2:
Wanlong Gao354ebb42012-12-07 10:10:04 +0800157 evp.sigev_value = (sigval_t) 0;
158 evp.sigev_signo = SIGALRM; /* any will do */
yaberauneya1a7f5422009-12-06 20:53:42 +0000159 evp.sigev_notify = SIGEV_NONE;
160 evp_ptr = &evp;
161 break;
vapierd13d74b2006-02-11 07:24:00 +0000162 }
163}
164
165/* setup() - performs all ONE TIME setup for this test */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000167{
Garrett Cooper2c282152010-12-16 00:55:50 -0800168
vapierd13d74b2006-02-11 07:24:00 +0000169 tst_sig(NOFORK, DEF_HANDLER, cleanup);
170
vapierd13d74b2006-02-11 07:24:00 +0000171 TEST_PAUSE;
Garrett Coopera9670cd2010-11-28 21:55:20 -0800172}
vapierd13d74b2006-02-11 07:24:00 +0000173
174/*
175 * cleanup() - Performs one time cleanup for this test at
176 * completion or premature exit
177 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800178void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000179{
180 /*
Wanlong Gao354ebb42012-12-07 10:10:04 +0800181 * print timing stats if that option was specified.
182 * print errno log if that option was specified.
183 */
vapierd13d74b2006-02-11 07:24:00 +0000184 TEST_CLEANUP;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700185}