• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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
13  * with this program; if not, write the Free Software Foundation, Inc.,
14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  */
17 /**************************************************************************
18  *
19  *    TEST IDENTIFIER	: timer_create03
20  *
21  *    EXECUTED BY	: anyone
22  *
23  *    TEST TITLE	: Basic test for timer_create(2)
24  *
25  *    TEST CASE TOTAL	: 3
26  *
27  *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
28  *
29  *    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.
36  *
37  * 	Setup:
38  *	  Setup signal handling.
39  *	  Pause for SIGUSR1 if option specified.
40  *
41  * 	Test:
42  *	 Loop if the proper options are given.
43  *	 Execute system call with different notification types for
44  *	 clock ID CLOCK_MONOTONIC
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.
48  *
49  * 	Cleanup:
50  * 	  Print errno log and/or timing stats if options given
51  *
52  * USAGE:  <for command-line>
53  * timer_create03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
54  * where:
55  * 	-c n : Run n copies simultaneously.
56  *	-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 
67 #include <stdlib.h>
68 #include <errno.h>
69 #include <time.h>
70 #include <signal.h>
71 
72 #include "test.h"
73 #include "common_timers.h"
74 
75 void setup(void);
76 void setup_test(int option);
77 
78 char *TCID = "timer_create03";	/* Test program identifier. */
79 int TST_TOTAL = 3;		/* Total number of test cases. */
80 static struct sigevent evp, *evp_ptr;
81 
82 /*
83  * cleanup() - Performs one time cleanup for this test at
84  * completion or premature exit
85  */
cleanup(void)86 void cleanup(void)
87 {
88 }
89 
main(int ac,char ** av)90 int main(int ac, char **av)
91 {
92 	int lc, i;
93 	kernel_timer_t created_timer_id;	/* holds the returned timer_id */
94 	char *message[] = {
95 		"SIGEV_SIGNAL",
96 		"NULL",
97 		"SIGEV_NONE"
98 	};
99 
100 	tst_parse_opts(ac, av, NULL, NULL);
101 
102 	setup();
103 
104 	for (lc = 0; TEST_LOOPING(lc); lc++) {
105 
106 		tst_count = 0;
107 
108 		for (i = 0; i < TST_TOTAL; i++) {
109 
110 			setup_test(i);
111 			TEST(ltp_syscall(__NR_timer_create, CLOCK_MONOTONIC,
112 				     evp_ptr, &created_timer_id));
113 
114 			tst_resm((TEST_RETURN == 0 ? TPASS : TFAIL | TTERRNO),
115 				 "%s with notification type = %s",
116 				 (TEST_RETURN == 0 ? "passed" : "failed"),
117 				 message[i]);
118 
119 		}
120 
121 	}
122 
123 	cleanup();
124 	tst_exit();
125 }
126 
127 /* setup_test() - sets up individual test */
setup_test(int option)128 void setup_test(int option)
129 {
130 	switch (option) {
131 	case 0:
132 		evp.sigev_value = (union sigval) 0;
133 		evp.sigev_signo = SIGALRM;
134 		evp.sigev_notify = SIGEV_SIGNAL;
135 		evp_ptr = &evp;
136 		break;
137 	case 1:
138 		evp_ptr = NULL;
139 		break;
140 	case 2:
141 		evp.sigev_value = (union sigval) 0;
142 		evp.sigev_signo = SIGALRM;	/* any will do */
143 		evp.sigev_notify = SIGEV_NONE;
144 		evp_ptr = &evp;
145 		break;
146 	}
147 }
148 
149 /* setup() - performs all ONE TIME setup for this test */
setup(void)150 void setup(void)
151 {
152 
153 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
154 
155 	TEST_PAUSE;
156 }
157