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., 21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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: alarm03.c,v 1.10 2009/08/28 10:57:29 vapier Exp $ */ 33 /********************************************************** 34 * 35 * OS Test - Silicon Graphics, Inc. 36 * 37 * TEST IDENTIFIER : alarm03 38 * 39 * EXECUTED BY : anyone 40 * 41 * TEST TITLE : alarm(2) cleared by a fork 42 * 43 * PARENT DOCUMENT : usctpl01 44 * 45 * TEST CASE TOTAL : 1 46 * 47 * WALL CLOCK TIME : 1 48 * 49 * CPU TYPES : ALL 50 * 51 * AUTHOR : Richard Logan 52 * 53 * CO-PILOT : Dennis Arason 54 * 55 * DATE STARTED : 08/96 56 * 57 * 58 * TEST CASES 59 * 60 * 1.) alarm(100), fork, child's alarm(0) shall return 0; 61 * 2.) alarm(100), fork, parent's alarm(0) shall return non-zero. 62 * 63 * INPUT SPECIFICATIONS 64 * The standard options for system call tests are accepted. 65 * (See the parse_opts(3) man page). 66 * 67 * 68 * SPECIAL PROCEDURAL REQUIREMENTS 69 * None 70 * 71 * 72 * DETAILED DESCRIPTION 73 * This is a Phase I test for the alarm(2) system call. It is intended 74 * to provide a limited exposure of the system call, for now. It 75 * should/will be extended when full functional tests are written for 76 * alarm(2). 77 * 78 * Setup: 79 * Setup signal handling. 80 * Pause for SIGUSR1 if option specified. 81 * 82 * Test: 83 * Loop if the proper options are given. 84 * Execute system call 85 * Check return code, if system call failed (return=-1) 86 * Log the errno and Issue a FAIL message. 87 * Otherwise, Issue a PASS message. 88 * 89 * Cleanup: 90 * Print errno log and/or timing stats if options given 91 * 92 * 93 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ 94 95 #include <errno.h> 96 #include <string.h> 97 #include <signal.h> 98 #include <stdlib.h> 99 #include <sys/wait.h> 100 #include "test.h" 101 #include "safe_macros.h" 102 103 void setup(); 104 void cleanup(); 105 void trapper(); 106 107 char *TCID = "alarm03"; 108 int TST_TOTAL = 1; 109 110 int main(int ac, char **av) 111 { 112 int lc; 113 int status, retval = 0; 114 115 tst_parse_opts(ac, av, NULL, NULL); 116 117 setup(); 118 119 for (lc = 0; TEST_LOOPING(lc); lc++) { 120 121 tst_count = 0; 122 123 /* 124 * Call alarm(2) 125 */ 126 TEST(alarm(100)); 127 128 switch (FORK_OR_VFORK()) { 129 case -1: 130 tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); 131 break; 132 133 case 0: 134 TEST(alarm(0)); 135 136 if (TEST_RETURN != 0) { 137 retval = 1; 138 printf("%d: alarm(100), fork, alarm(0) child's " 139 "alarm returned %ld\n", 140 getpid(), TEST_RETURN); 141 } else { 142 printf("%d: alarm(100), fork, alarm(0) child's " 143 "alarm returned %ld\n", 144 getpid(), TEST_RETURN); 145 } 146 147 exit(retval); 148 break; 149 150 default: 151 tst_count++; 152 TEST(alarm(0)); 153 /* The timer may be rounded up to the next nearest second, this is OK */ 154 if (TEST_RETURN <= 0 || TEST_RETURN > 101) { 155 retval = 1; 156 tst_resm(TFAIL, 157 "alarm(100), fork, alarm(0) parent's alarm returned %ld", 158 TEST_RETURN); 159 } else { 160 tst_resm(TPASS, 161 "alarm(100), fork, alarm(0) parent's alarm returned %ld", 162 TEST_RETURN); 163 } 164 SAFE_WAIT(cleanup, &status); 165 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) 166 tst_resm(TFAIL, "see failures reported above"); 167 168 } 169 170 } 171 172 cleanup(); 173 tst_exit(); 174 } 175 176 void setup(void) 177 { 178 179 tst_sig(FORK, DEF_HANDLER, cleanup); 180 181 signal(SIGALRM, trapper); 182 183 TEST_PAUSE; 184 } 185 186 void cleanup(void) 187 { 188 } 189 190 void trapper(int sig) 191 { 192 signal(SIGALRM, trapper); 193 } 194