blob: ed5d6783c7a5a6d3664b95220a6e4b8f01a74d46 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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 */
33/* $Id: kill09.c,v 1.1 2001/08/27 22:15:14 plars Exp $ */
34/**********************************************************
35 *
36 * OS Test - Silicon Graphics, Inc.
37 *
38 * TEST IDENTIFIER : kill09
39 *
40 * EXECUTED BY : anyone
41 *
42 * TEST TITLE : Basic test for kill(2)
43 *
44 * PARENT DOCUMENT : usctpl01
45 *
46 * TEST CASE TOTAL : 1
47 *
48 * WALL CLOCK TIME : 1
49 *
50 * CPU TYPES : ALL
51 *
52 * AUTHOR : William Roske
53 *
54 * CO-PILOT : Dave Fenner
55 *
56 * DATE STARTED : 03/30/92
57 *
58 * INITIAL RELEASE : UNICOS 7.0
59 *
60 * TEST CASES
61 *
62 * 1.) kill(2) returns...(See Description)
63 *
64 * INPUT SPECIFICATIONS
65 * The standard options for system call tests are accepted.
66 * (See the parse_opts(3) man page).
67 *
68 * OUTPUT SPECIFICATIONS
69 *
70 * DURATION
71 * Terminates - with frequency and infinite modes.
72 *
73 * SIGNALS
74 * Uses SIGUSR1 to pause before test if option set.
75 * (See the parse_opts(3) man page).
76 *
77 * RESOURCES
78 * None
79 *
80 * ENVIRONMENTAL NEEDS
81 * No run-time environmental needs.
82 *
83 * SPECIAL PROCEDURAL REQUIREMENTS
84 * None
85 *
86 * INTERCASE DEPENDENCIES
87 * None
88 *
89 * DETAILED DESCRIPTION
90 * This is a Phase I test for the kill(2) system call. It is intended
91 * to provide a limited exposure of the system call, for now. It
92 * should/will be extended when full functional tests are written for
93 * kill(2).
94 *
95 * Setup:
96 * Setup signal handling.
97 * Pause for SIGUSR1 if option specified.
98 *
99 * Test:
100 * Loop if the proper options are given.
101 * Execute system call
102 * Check return code, if system call failed (return=-1)
103 * Log the errno and Issue a FAIL message.
104 * Otherwise, Issue a PASS message.
105 *
106 * Cleanup:
107 * Print errno log and/or timing stats if options given
108 *
109 *
110 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111
112#include <errno.h>
113#include <string.h>
114#include <signal.h>
115#include <stdlib.h>
116#include <sys/types.h>
117#include <sys/wait.h>
118
119#include "test.h"
120#include "usctest.h"
121
122void setup();
123void cleanup();
124void alarm_handler(int sig);
125
126
127
128
129char *TCID="kill09"; /* Test program identifier. */
130int TST_TOTAL=1; /* Total number of test cases. */
131extern int Tst_count; /* Test Case counter for tst_* routines */
132
133int fork_pid;
134
135int
136main(int ac, char **av)
137{
138 int lc; /* loop counter */
139 char *msg; /* message returned from parse_opts */
140 int status;
141
142 /***************************************************************
143 * parse standard options
144 ***************************************************************/
145 if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) {
146 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
147 tst_exit();
148 }
149
150 /***************************************************************
151 * perform global setup for test
152 ***************************************************************/
153 setup();
154
155
156 /***************************************************************
157 * check looping state if -c option given
158 ***************************************************************/
159 for (lc=0; TEST_LOOPING(lc); lc++) {
160
161 /* reset Tst_count in case we are looping. */
162 Tst_count=0;
163
164 /* make a child process so we can kill it */
165 /* If we cannot fork => we cannot test kill, so break and exit */
166 if ((fork_pid=fork()) == -1) {
167 tst_brkm(TBROK, cleanup,
168 "fork() Failure. errno=%d : %s",
169 errno, strerror(errno));
170 }
171
172 if (fork_pid == 0) {
173 /* CHILD */
174 /*
175 * Setup alarm signal if we don't get the signal to prevent this process
176 * from hanging around forever.
177 */
178 signal(SIGALRM, alarm_handler);
179 alarm(20);
180 pause();
181 exit(1);
182 }
183
184 /* PARENT */
185 /*
186 * Call kill(2)
187 */
188 TEST(kill(fork_pid, SIGKILL));
189 /* check return code */
190 if ( TEST_RETURN == -1 ) {
191 TEST_ERROR_LOG(TEST_ERRNO);
192 tst_resm(TFAIL, "kill(%d, SIGKILL) Failed, errno=%d : %s", fork_pid,
193 TEST_ERRNO, strerror(TEST_ERRNO));
194 } else {
195
196 /***************************************************************
197 * only perform functional verification if flag set (-f not given)
198 ***************************************************************/
199 if ( STD_FUNCTIONAL_TEST ) {
200 /* No Verification test, yet... */
201 tst_resm(TPASS, "kill(%d, SIGKILL) returned %d", fork_pid, TEST_RETURN);
202 }
203 }
204
205 /*
206 * wait for process to cleanup zombies.
207 *
208 */
209 waitpid(0, &status, WNOHANG);
210
211 } /* End for TEST_LOOPING */
212
213 /***************************************************************
214 * cleanup and exit
215 ***************************************************************/
216 cleanup();
217
218 return 0;
219} /* End main */
220
221/***************************************************************
222 * setup() - performs all ONE TIME setup for this test.
223 ***************************************************************/
224void
225setup()
226{
227 /* capture signals */
228 tst_sig(NOFORK, DEF_HANDLER, cleanup);
229
230 (void) signal(SIGCHLD, SIG_IGN);
231
232 /* Pause if that option was specified */
233 TEST_PAUSE;
234
235} /* End setup() */
236
237
238/***************************************************************
239 * cleanup() - performs all ONE TIME cleanup for this test at
240 * completion or premature exit.
241 ***************************************************************/
242void
243cleanup()
244{
245 /*
246 * print timing stats if that option was specified.
247 * print errno log if that option was specified.
248 */
249 TEST_CLEANUP;
250
251 /* exit with return code appropriate for results */
252 tst_exit();
253} /* End cleanup() */
254
255void
256alarm_handler(int sig)
257{
258 exit(8);
259}