alarm02.c revision 56207cec7732e09c216c751c0b5f88a242bacae6
1/* 2 * Copyright (c) 2000 Silicon Graphics, Inc. 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 * Further, this software is distributed without any warranty that it is 13 * free of the rightful claim of any third person regarding infringement 14 * or the like. Any license provided herein, whether implied or 15 * otherwise, applies only to this software file. Patent licenses, if 16 * any, provided herein do not apply to combinations of this program with 17 * other software, or any other product whatsoever. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write the Free Software Foundation, Inc., 59 21 * Temple Place - Suite 330, Boston MA 02111-1307, USA. 22 * 23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 24 * Mountain View, CA 94043, or: 25 * 26 * http://www.sgi.com 27 * 28 * For further information regarding this notice, see: 29 * 30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 31 */ 32/* $Id: alarm02.c,v 1.3 2009/03/23 13:35:39 subrata_modak Exp $ */ 33/********************************************************** 34 * 35 * OS Test - Silicon Graphics, Inc. 36 * 37 * TEST IDENTIFIER : alarm02 38 * 39 * TEST TITLE : Boundary Value Test for alarm(2) 40 * 41 * PARENT DOCUMENT : almtds02 42 * 43 * TEST CASE TOTAL : 3 44 * 45 * WALL CLOCK TIME : 1 46 * 47 * CPU TYPES : ALL 48 * 49 * AUTHOR : Billy Jean Horne 50 * 51 * CO-PILOT : Kathy Olmsted 52 * 53 * DATE STARTED : 06/01/92 54 * 55 * INITIAL RELEASE : UNICOS 7.0 56 * 57 * TEST CASES 58 * Test Case One - A call to alarm() shall not return an error if 59 * seconds is a -1. 60 * Test FAILS if a non-zero value is returned. 61 * Test Case Two - A call to alarm() shall not return an error if 62 * seconds is the maximum unsigned integer (2**63). 63 * Test FAILS if a non-zero value is returned. 64 * Test Case Three - A call to alarm() shall not return an error if 65 * seconds is the maximum unsigned integer plus 1 ((2**63)+1). 66 * Test FAILS if a non-zero value is returned. 67 * 68 * ENVIRONMENTAL NEEDS 69 * The libcuts.a and libsys.a libraries must be included in 70 * the compilation of this test. 71 * 72 * DETAILED DESCRIPTION 73 * 74 * Setup: 75 * Define a cleanup function. 76 * 77 * Test: 78 * Loop for each test case. 79 * Execute alarm (0) system call to clear previous alarm. 80 * Check return code, if system call failed (return=-1) 81 * Issue a FAIL message and exit the test. 82 * Call alarm() with boundary values for seconds. 83 * Verify that returned value is as expected. 84 * Report results. 85 * 86 * Cleanup: 87 * 88 */ 89#include <sys/types.h> 90#include <errno.h> 91#include <sys/signal.h> 92#include <limits.h> 93#include "test.h" 94#include "usctest.h" /* required for usctest */ 95 96void setup(); 97void cleanup(); 98void alarm_received(); 99 100char *TCID = "alarm02"; /* Test program identifier. */ 101int TST_TOTAL = 3; /* Total number of test cases. */ 102extern int Tst_count; /* Test Case counter for tst_ * routines */ 103 104int received_alarm = 0; /* Indicates a SIGALRM was received */ 105 106/************************************************************ 107 * Main program 108 ***********************************************************/ 109 110int main(int ac, char **av) 111{ 112 113 /* Parameters for usc code */ 114 int lc; /* loop counter */ 115 char *msg; /* message returned from parse_opts */ 116 117 /* Parameters for alarm test */ 118 char *buf[] = { "-1", "ULONG_MAX", "ULONG_MAX+1" }; 119 unsigned long int sec[] = { -1, ULONG_MAX, ULONG_MAX + 1 }; 120 int exp[] = { 0, 0, 0 }; 121 int i; 122 123 /*************************************************************** 124 * parse standard options 125 ***************************************************************/ 126 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { 127 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 128 tst_exit(); 129 } 130 131 /*************************************************************** 132 * perform global setup for test 133 ***************************************************************/ 134 135 setup(); 136 137 /*************************************************************** 138 * check looping state 139 ***************************************************************/ 140 for (lc = 0; TEST_LOOPING(lc); lc++) { 141 142 /* reset Tst_count in case we are looping. */ 143 144 Tst_count = 0; 145 146 for (i = 0; i < TST_TOTAL; i++) { 147 148 /* capture an SIGALRM signal */ 149 received_alarm = 0; 150 signal(SIGALRM, alarm_received); 151 152 TEST(alarm(sec[i])); 153 /* reset the alarm */ 154 alarm(0); 155 if (TEST_RETURN != 0) { 156 tst_resm(TFAIL, 157 "alarm(%u) returned %u, when %u was expected for value %s.", 158 sec[i], TEST_RETURN, exp[i], buf[i]); 159 160 } 161 /*************************************************************** 162 * only perform functional verification if flag set (-f not given) 163 ***************************************************************/ 164 else if (STD_FUNCTIONAL_TEST) { 165 if (received_alarm == 1) { 166 tst_resm(TFAIL, 167 "alarm(%u) returned %u but an alarm signal was received for value %s.", 168 sec[i], TEST_RETURN, buf[i]); 169 } else { 170 tst_resm(TPASS, 171 "alarm(%u) returned %u as expected for value %s.", 172 sec[i], TEST_RETURN, buf[i]); 173 } 174 175 } /* End of STD_FUNCTIONAL_TEST */ 176 } /* End of for loop */ 177 /* 178 * Reset alarm before cleanup. 179 */ 180 181 alarm(0); 182 183 } /* End for TEST_LOOPING */ 184 185 cleanup(); 186 187 return 0; 188} 189 190/*************************************************************** 191 * setup() - performs all ONE TIME setup for this test. 192 ***************************************************************/ 193 194void setup() 195{ 196 197 /* capture signals */ 198 tst_sig(NOFORK, DEF_HANDLER, cleanup); 199 200 /* Pause if that option was specified */ 201 TEST_PAUSE; 202 203 /* End setup() */ 204 205} 206 207/*********************************************************** 208 * Cleanup: 209 * exit using tst_exit. 210 ***********************************************************/ 211 212void cleanup() 213{ 214 /* 215 * print timing stats if that option was specified. 216 * print errno log if that option was specified. 217 */ 218 TEST_CLEANUP; 219 220 /* exit with return code appropriate for results */ 221 222 tst_exit(); 223} 224 225void alarm_received() 226{ 227 received_alarm = 1; 228} 229