timer_create03.c revision 2c28215423293e443469a07ae7011135d058b671
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., 59 14 * Temple Place - Suite 330, Boston MA 02111-1307, 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 "usctest.h" 74#include "common_timers.h" 75 76void setup(void); 77void setup_test(int option); 78 79char *TCID = "timer_create03"; /* Test program identifier. */ 80int TST_TOTAL = 3; /* Total number of test cases. */ 81extern int Tst_count; /* Test Case counter for tst_* routines */ 82static struct sigevent evp, *evp_ptr; 83 84/* 85 * cleanup() - Performs one time cleanup for this test at 86 * completion or premature exit 87 */ 88void 89cleanup(void) 90{ 91 /* 92 * print timing stats if that option was specified. 93 * print errno log if that option was specified. 94 */ 95 TEST_CLEANUP; 96} 97 98int 99main(int ac, char **av) 100{ 101 int lc, i; /* loop counter */ 102 char *msg; /* message returned from parse_opts */ 103 kernel_timer_t created_timer_id; /* holds the returned timer_id */ 104 char *message[] = { 105 "SIGEV_SIGNAL", 106 "NULL", 107 "SIGEV_NONE" 108 }; 109 110 /* parse standard options */ 111 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != 112 (char *) NULL) { 113 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 114 } 115 116 setup(); 117 118 for (lc = 0; TEST_LOOPING(lc); lc++) { 119 120 Tst_count = 0; 121 122 for (i = 0; i < TST_TOTAL; i++) { 123 124 setup_test(i); 125 TEST(syscall(__NR_timer_create, CLOCK_MONOTONIC, 126 evp_ptr, &created_timer_id)); 127 128 tst_resm((TEST_RETURN == 0 ? TPASS : TFAIL | TTERRNO), 129 "%s with notification type = %s", 130 (TEST_RETURN == 0 ? "passed" : "failed"), 131 message[i]); 132 133 } 134 135 } 136 137 cleanup(); 138 tst_exit(); 139} 140 141/* setup_test() - sets up individual test */ 142void 143setup_test(int option) 144{ 145 switch (option) { 146 case 0: 147 evp.sigev_value = (sigval_t) 0; 148 evp.sigev_signo = SIGALRM; 149 evp.sigev_notify = SIGEV_SIGNAL; 150 evp_ptr = &evp; 151 break; 152 case 1: 153 evp_ptr = NULL; 154 break; 155 case 2: 156 evp.sigev_value = (sigval_t) 0; 157 evp.sigev_signo = SIGALRM; /* any will do */ 158 evp.sigev_notify = SIGEV_NONE; 159 evp_ptr = &evp; 160 break; 161 } 162} 163 164/* setup() - performs all ONE TIME setup for this test */ 165void 166setup(void) 167{ 168 169 tst_sig(NOFORK, DEF_HANDLER, cleanup); 170 171 TEST_PAUSE; 172}