alarm02.c revision 6b66d95a141208bd67ec3542f1386693c931d65e
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.4 2009/08/28 10:57:29 vapier 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" 95 96void setup(); 97void cleanup(); 98void alarm_received(); 99 100char *TCID = "alarm02"; /* Test program identifier. */ 101int TST_TOTAL = 3; /* Total number of test cases. */ 102 103int received_alarm = 0; /* Indicates a SIGALRM was received */ 104 105int main(int ac, char **av) 106{ 107 108 /* Parameters for usc code */ 109 int lc; /* loop counter */ 110 char *msg; /* message returned from parse_opts */ 111 112 /* Parameters for alarm test */ 113 char *buf[] = { "-1", "ULONG_MAX", "ULONG_MAX+1" }; 114 unsigned long int sec[] = { -1, ULONG_MAX, ULONG_MAX + 1 }; 115 int exp[] = { 0, 0, 0 }; 116 int i; 117 118 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) 119 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 120 121 setup(); 122 123 for (lc = 0; TEST_LOOPING(lc); lc++) { 124 125 Tst_count = 0; 126 127 for (i = 0; i < TST_TOTAL; i++) { 128 129 received_alarm = 0; 130 signal(SIGALRM, alarm_received); 131 132 TEST(alarm(sec[i])); 133 alarm(0); 134 if (TEST_RETURN != 0) 135 tst_resm(TFAIL, 136 "alarm(%lu) returned %ld, when %u was " 137 "expected for value %s", 138 sec[i], TEST_RETURN, exp[i], buf[i]); 139 else if (STD_FUNCTIONAL_TEST) { 140 if (received_alarm == 1) { 141 tst_resm(TFAIL, 142 "alarm(%lu) returned %ldu but an " 143 "alarm signal was received for " 144 "value %s", 145 sec[i], TEST_RETURN, buf[i]); 146 } else { 147 tst_resm(TPASS, 148 "alarm(%lu) returned %ld as " 149 "expected for value %s", 150 sec[i], TEST_RETURN, buf[i]); 151 } 152 153 } 154 } 155 /* 156 * Reset alarm before cleanup. 157 */ 158 159 alarm(0); 160 161 } 162 163 cleanup(); 164 tst_exit(); 165 166} 167 168void setup() 169{ 170 171 tst_sig(NOFORK, DEF_HANDLER, cleanup); 172 173 TEST_PAUSE; 174 175} 176 177void cleanup() 178{ 179 TEST_CLEANUP; 180} 181 182void alarm_received() 183{ 184 received_alarm = 1; 185} 186