1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3*49cdfc7eSAndroid Build Coastguard Worker *
4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify it
5*49cdfc7eSAndroid Build Coastguard Worker * under the terms of version 2 of the GNU General Public License as
6*49cdfc7eSAndroid Build Coastguard Worker * published by the Free Software Foundation.
7*49cdfc7eSAndroid Build Coastguard Worker *
8*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it would be useful, but
9*49cdfc7eSAndroid Build Coastguard Worker * WITHOUT ANY WARRANTY; without even the implied warranty of
10*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11*49cdfc7eSAndroid Build Coastguard Worker *
12*49cdfc7eSAndroid Build Coastguard Worker * Further, this software is distributed without any warranty that it is
13*49cdfc7eSAndroid Build Coastguard Worker * free of the rightful claim of any third person regarding infringement
14*49cdfc7eSAndroid Build Coastguard Worker * or the like. Any license provided herein, whether implied or
15*49cdfc7eSAndroid Build Coastguard Worker * otherwise, applies only to this software file. Patent licenses, if
16*49cdfc7eSAndroid Build Coastguard Worker * any, provided herein do not apply to combinations of this program with
17*49cdfc7eSAndroid Build Coastguard Worker * other software, or any other product whatsoever.
18*49cdfc7eSAndroid Build Coastguard Worker *
19*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License along
20*49cdfc7eSAndroid Build Coastguard Worker * with this program; if not, write the Free Software Foundation, Inc.,
21*49cdfc7eSAndroid Build Coastguard Worker * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24*49cdfc7eSAndroid Build Coastguard Worker * Mountain View, CA 94043, or:
25*49cdfc7eSAndroid Build Coastguard Worker *
26*49cdfc7eSAndroid Build Coastguard Worker * http://www.sgi.com
27*49cdfc7eSAndroid Build Coastguard Worker *
28*49cdfc7eSAndroid Build Coastguard Worker * For further information regarding this notice, see:
29*49cdfc7eSAndroid Build Coastguard Worker *
30*49cdfc7eSAndroid Build Coastguard Worker * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31*49cdfc7eSAndroid Build Coastguard Worker *
32*49cdfc7eSAndroid Build Coastguard Worker */
33*49cdfc7eSAndroid Build Coastguard Worker /* $Id: kill09.c,v 1.8 2009/08/28 13:22:51 vapier Exp $ */
34*49cdfc7eSAndroid Build Coastguard Worker /**********************************************************
35*49cdfc7eSAndroid Build Coastguard Worker *
36*49cdfc7eSAndroid Build Coastguard Worker * OS Test - Silicon Graphics, Inc.
37*49cdfc7eSAndroid Build Coastguard Worker *
38*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : kill09
39*49cdfc7eSAndroid Build Coastguard Worker *
40*49cdfc7eSAndroid Build Coastguard Worker * EXECUTED BY : anyone
41*49cdfc7eSAndroid Build Coastguard Worker *
42*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Basic test for kill(2)
43*49cdfc7eSAndroid Build Coastguard Worker *
44*49cdfc7eSAndroid Build Coastguard Worker * PARENT DOCUMENT : usctpl01
45*49cdfc7eSAndroid Build Coastguard Worker *
46*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 1
47*49cdfc7eSAndroid Build Coastguard Worker *
48*49cdfc7eSAndroid Build Coastguard Worker * WALL CLOCK TIME : 1
49*49cdfc7eSAndroid Build Coastguard Worker *
50*49cdfc7eSAndroid Build Coastguard Worker * CPU TYPES : ALL
51*49cdfc7eSAndroid Build Coastguard Worker *
52*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR : William Roske
53*49cdfc7eSAndroid Build Coastguard Worker *
54*49cdfc7eSAndroid Build Coastguard Worker * CO-PILOT : Dave Fenner
55*49cdfc7eSAndroid Build Coastguard Worker *
56*49cdfc7eSAndroid Build Coastguard Worker * DATE STARTED : 03/30/92
57*49cdfc7eSAndroid Build Coastguard Worker *
58*49cdfc7eSAndroid Build Coastguard Worker * INITIAL RELEASE : UNICOS 7.0
59*49cdfc7eSAndroid Build Coastguard Worker *
60*49cdfc7eSAndroid Build Coastguard Worker * TEST CASES
61*49cdfc7eSAndroid Build Coastguard Worker *
62*49cdfc7eSAndroid Build Coastguard Worker * 1.) kill(2) returns...(See Description)
63*49cdfc7eSAndroid Build Coastguard Worker *
64*49cdfc7eSAndroid Build Coastguard Worker * INPUT SPECIFICATIONS
65*49cdfc7eSAndroid Build Coastguard Worker * The standard options for system call tests are accepted.
66*49cdfc7eSAndroid Build Coastguard Worker * (See the parse_opts(3) man page).
67*49cdfc7eSAndroid Build Coastguard Worker *
68*49cdfc7eSAndroid Build Coastguard Worker * OUTPUT SPECIFICATIONS
69*49cdfc7eSAndroid Build Coastguard Worker *$
70*49cdfc7eSAndroid Build Coastguard Worker * DURATION
71*49cdfc7eSAndroid Build Coastguard Worker * Terminates - with frequency and infinite modes.
72*49cdfc7eSAndroid Build Coastguard Worker *
73*49cdfc7eSAndroid Build Coastguard Worker * SIGNALS
74*49cdfc7eSAndroid Build Coastguard Worker * Uses SIGUSR1 to pause before test if option set.
75*49cdfc7eSAndroid Build Coastguard Worker * (See the parse_opts(3) man page).
76*49cdfc7eSAndroid Build Coastguard Worker *
77*49cdfc7eSAndroid Build Coastguard Worker * RESOURCES
78*49cdfc7eSAndroid Build Coastguard Worker * None
79*49cdfc7eSAndroid Build Coastguard Worker *
80*49cdfc7eSAndroid Build Coastguard Worker * ENVIRONMENTAL NEEDS
81*49cdfc7eSAndroid Build Coastguard Worker * No run-time environmental needs.
82*49cdfc7eSAndroid Build Coastguard Worker *
83*49cdfc7eSAndroid Build Coastguard Worker * SPECIAL PROCEDURAL REQUIREMENTS
84*49cdfc7eSAndroid Build Coastguard Worker * None
85*49cdfc7eSAndroid Build Coastguard Worker *
86*49cdfc7eSAndroid Build Coastguard Worker * INTERCASE DEPENDENCIES
87*49cdfc7eSAndroid Build Coastguard Worker * None
88*49cdfc7eSAndroid Build Coastguard Worker *
89*49cdfc7eSAndroid Build Coastguard Worker * DETAILED DESCRIPTION
90*49cdfc7eSAndroid Build Coastguard Worker * This is a Phase I test for the kill(2) system call. It is intended
91*49cdfc7eSAndroid Build Coastguard Worker * to provide a limited exposure of the system call, for now. It
92*49cdfc7eSAndroid Build Coastguard Worker * should/will be extended when full functional tests are written for
93*49cdfc7eSAndroid Build Coastguard Worker * kill(2).
94*49cdfc7eSAndroid Build Coastguard Worker *
95*49cdfc7eSAndroid Build Coastguard Worker * Setup:
96*49cdfc7eSAndroid Build Coastguard Worker * Setup signal handling.
97*49cdfc7eSAndroid Build Coastguard Worker * Pause for SIGUSR1 if option specified.
98*49cdfc7eSAndroid Build Coastguard Worker *
99*49cdfc7eSAndroid Build Coastguard Worker * Test:
100*49cdfc7eSAndroid Build Coastguard Worker * Loop if the proper options are given.
101*49cdfc7eSAndroid Build Coastguard Worker * Execute system call
102*49cdfc7eSAndroid Build Coastguard Worker * Check return code, if system call failed (return=-1)
103*49cdfc7eSAndroid Build Coastguard Worker * Log the errno and Issue a FAIL message.
104*49cdfc7eSAndroid Build Coastguard Worker * Otherwise, Issue a PASS message.
105*49cdfc7eSAndroid Build Coastguard Worker *
106*49cdfc7eSAndroid Build Coastguard Worker * Cleanup:
107*49cdfc7eSAndroid Build Coastguard Worker * Print errno log and/or timing stats if options given
108*49cdfc7eSAndroid Build Coastguard Worker *
109*49cdfc7eSAndroid Build Coastguard Worker *
110*49cdfc7eSAndroid Build Coastguard Worker *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111*49cdfc7eSAndroid Build Coastguard Worker
112*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
113*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
114*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
115*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
116*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
117*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
118*49cdfc7eSAndroid Build Coastguard Worker
119*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
120*49cdfc7eSAndroid Build Coastguard Worker
121*49cdfc7eSAndroid Build Coastguard Worker void setup();
122*49cdfc7eSAndroid Build Coastguard Worker void cleanup();
123*49cdfc7eSAndroid Build Coastguard Worker void alarm_handler(int sig);
124*49cdfc7eSAndroid Build Coastguard Worker void do_child();
125*49cdfc7eSAndroid Build Coastguard Worker
126*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "kill09";
127*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
128*49cdfc7eSAndroid Build Coastguard Worker
129*49cdfc7eSAndroid Build Coastguard Worker int fork_pid;
130*49cdfc7eSAndroid Build Coastguard Worker
main(int ac,char ** av)131*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
132*49cdfc7eSAndroid Build Coastguard Worker {
133*49cdfc7eSAndroid Build Coastguard Worker int lc;
134*49cdfc7eSAndroid Build Coastguard Worker int status;
135*49cdfc7eSAndroid Build Coastguard Worker
136*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(ac, av, NULL, NULL);
137*49cdfc7eSAndroid Build Coastguard Worker
138*49cdfc7eSAndroid Build Coastguard Worker setup();
139*49cdfc7eSAndroid Build Coastguard Worker
140*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
141*49cdfc7eSAndroid Build Coastguard Worker
142*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
143*49cdfc7eSAndroid Build Coastguard Worker
144*49cdfc7eSAndroid Build Coastguard Worker if ((fork_pid = tst_fork()) == -1)
145*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
146*49cdfc7eSAndroid Build Coastguard Worker
147*49cdfc7eSAndroid Build Coastguard Worker if (fork_pid == 0) {
148*49cdfc7eSAndroid Build Coastguard Worker do_child();
149*49cdfc7eSAndroid Build Coastguard Worker }
150*49cdfc7eSAndroid Build Coastguard Worker
151*49cdfc7eSAndroid Build Coastguard Worker TEST(kill(fork_pid, SIGKILL));
152*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1)
153*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL | TTERRNO, "kill(.., SIGKILL) failed");
154*49cdfc7eSAndroid Build Coastguard Worker else {
155*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS,
156*49cdfc7eSAndroid Build Coastguard Worker "kill(%d, SIGKILL) returned %ld",
157*49cdfc7eSAndroid Build Coastguard Worker fork_pid, TEST_RETURN);
158*49cdfc7eSAndroid Build Coastguard Worker }
159*49cdfc7eSAndroid Build Coastguard Worker
160*49cdfc7eSAndroid Build Coastguard Worker waitpid(0, &status, WNOHANG);
161*49cdfc7eSAndroid Build Coastguard Worker
162*49cdfc7eSAndroid Build Coastguard Worker }
163*49cdfc7eSAndroid Build Coastguard Worker
164*49cdfc7eSAndroid Build Coastguard Worker cleanup();
165*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
166*49cdfc7eSAndroid Build Coastguard Worker }
167*49cdfc7eSAndroid Build Coastguard Worker
do_child(void)168*49cdfc7eSAndroid Build Coastguard Worker void do_child(void)
169*49cdfc7eSAndroid Build Coastguard Worker {
170*49cdfc7eSAndroid Build Coastguard Worker /*
171*49cdfc7eSAndroid Build Coastguard Worker * Setup alarm signal if we don't get the signal to prevent this process
172*49cdfc7eSAndroid Build Coastguard Worker * from hanging around forever.
173*49cdfc7eSAndroid Build Coastguard Worker */
174*49cdfc7eSAndroid Build Coastguard Worker signal(SIGALRM, alarm_handler);
175*49cdfc7eSAndroid Build Coastguard Worker alarm(20);
176*49cdfc7eSAndroid Build Coastguard Worker pause();
177*49cdfc7eSAndroid Build Coastguard Worker exit(1);
178*49cdfc7eSAndroid Build Coastguard Worker }
179*49cdfc7eSAndroid Build Coastguard Worker
setup(void)180*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
181*49cdfc7eSAndroid Build Coastguard Worker {
182*49cdfc7eSAndroid Build Coastguard Worker
183*49cdfc7eSAndroid Build Coastguard Worker tst_sig(NOFORK, DEF_HANDLER, cleanup);
184*49cdfc7eSAndroid Build Coastguard Worker
185*49cdfc7eSAndroid Build Coastguard Worker (void)signal(SIGCHLD, SIG_IGN);
186*49cdfc7eSAndroid Build Coastguard Worker
187*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
188*49cdfc7eSAndroid Build Coastguard Worker
189*49cdfc7eSAndroid Build Coastguard Worker }
190*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)191*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
192*49cdfc7eSAndroid Build Coastguard Worker {
193*49cdfc7eSAndroid Build Coastguard Worker }
194*49cdfc7eSAndroid Build Coastguard Worker
alarm_handler(int sig)195*49cdfc7eSAndroid Build Coastguard Worker void alarm_handler(int sig)
196*49cdfc7eSAndroid Build Coastguard Worker {
197*49cdfc7eSAndroid Build Coastguard Worker exit(8);
198*49cdfc7eSAndroid Build Coastguard Worker }
199