blob: 21520f483c947af794740e9cfc954341a1873aa5 [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 */
subrata_modak923b23f2009-11-02 13:57:16 +000033/* $Id: setpgrp01.c,v 1.7 2009/11/02 13:57:18 subrata_modak Exp $ */
plars865695b2001-08-27 22:15:12 +000034/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000035 *
plars865695b2001-08-27 22:15:12 +000036 * OS Test - Silicon Graphics, Inc.
subrata_modak4bb656a2009-02-26 12:02:09 +000037 *
plars865695b2001-08-27 22:15:12 +000038 * TEST IDENTIFIER : setpgrp01
subrata_modak4bb656a2009-02-26 12:02:09 +000039 *
plars865695b2001-08-27 22:15:12 +000040 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
plars865695b2001-08-27 22:15:12 +000042 * TEST TITLE : Basic test for setpgrp(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000043 *
plars865695b2001-08-27 22:15:12 +000044 * PARENT DOCUMENT : usctpl01
subrata_modak4bb656a2009-02-26 12:02:09 +000045 *
plars865695b2001-08-27 22:15:12 +000046 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000047 *
plars865695b2001-08-27 22:15:12 +000048 * WALL CLOCK TIME : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
plars865695b2001-08-27 22:15:12 +000050 * CPU TYPES : ALL
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
plars865695b2001-08-27 22:15:12 +000052 * AUTHOR : William Roske
subrata_modak4bb656a2009-02-26 12:02:09 +000053 *
plars865695b2001-08-27 22:15:12 +000054 * CO-PILOT : Dave Fenner
subrata_modak4bb656a2009-02-26 12:02:09 +000055 *
plars865695b2001-08-27 22:15:12 +000056 * DATE STARTED : 05/13/92
subrata_modak4bb656a2009-02-26 12:02:09 +000057 *
plars865695b2001-08-27 22:15:12 +000058 * INITIAL RELEASE : UNICOS 7.0
subrata_modak4bb656a2009-02-26 12:02:09 +000059 *
plars865695b2001-08-27 22:15:12 +000060 * TEST CASES
subrata_modak4bb656a2009-02-26 12:02:09 +000061 *
subrata_modak56207ce2009-03-23 13:35:39 +000062 * 1.) setpgrp(2) returns...(See Description)
subrata_modakbdbaec52009-02-26 12:14:51 +000063 *
plars865695b2001-08-27 22:15:12 +000064 * INPUT SPECIFICATIONS
subrata_modak56207ce2009-03-23 13:35:39 +000065 * The standard options for system call tests are accepted.
plars865695b2001-08-27 22:15:12 +000066 * (See the parse_opts(3) man page).
subrata_modak4bb656a2009-02-26 12:02:09 +000067 *
plars865695b2001-08-27 22:15:12 +000068 * OUTPUT SPECIFICATIONS
subrata_modak56207ce2009-03-23 13:35:39 +000069 *
plars865695b2001-08-27 22:15:12 +000070 * DURATION
subrata_modak56207ce2009-03-23 13:35:39 +000071 * Terminates - with frequency and infinite modes.
subrata_modak4bb656a2009-02-26 12:02:09 +000072 *
plars865695b2001-08-27 22:15:12 +000073 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000074 * Uses SIGUSR1 to pause before test if option set.
75 * (See the parse_opts(3) man page).
plars865695b2001-08-27 22:15:12 +000076 *
77 * RESOURCES
subrata_modak56207ce2009-03-23 13:35:39 +000078 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000079 *
plars865695b2001-08-27 22:15:12 +000080 * ENVIRONMENTAL NEEDS
subrata_modak56207ce2009-03-23 13:35:39 +000081 * The libcuts.a and libsys.a libraries must be included in
plars865695b2001-08-27 22:15:12 +000082 * the compilation of this test.
subrata_modak4bb656a2009-02-26 12:02:09 +000083 *
plars865695b2001-08-27 22:15:12 +000084 * SPECIAL PROCEDURAL REQUIREMENTS
subrata_modak56207ce2009-03-23 13:35:39 +000085 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000086 *
plars865695b2001-08-27 22:15:12 +000087 * INTERCASE DEPENDENCIES
subrata_modak56207ce2009-03-23 13:35:39 +000088 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000089 *
plars865695b2001-08-27 22:15:12 +000090 * DETAILED DESCRIPTION
91 * This is a Phase I test for the setpgrp(2) system call. It is intended
92 * to provide a limited exposure of the system call, for now. It
93 * should/will be extended when full functional tests are written for
94 * setpgrp(2).
subrata_modak4bb656a2009-02-26 12:02:09 +000095 *
subrata_modak56207ce2009-03-23 13:35:39 +000096 * Setup:
97 * Setup signal handling.
plars865695b2001-08-27 22:15:12 +000098 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000099 *
subrata_modak56207ce2009-03-23 13:35:39 +0000100 * Test:
plars865695b2001-08-27 22:15:12 +0000101 * Loop if the proper options are given.
subrata_modak56207ce2009-03-23 13:35:39 +0000102 * Execute system call
plars865695b2001-08-27 22:15:12 +0000103 * Check return code, if system call failed (return=-1)
104 * Log the errno and Issue a FAIL message.
105 * Otherwise, Issue a PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +0000106 *
subrata_modak56207ce2009-03-23 13:35:39 +0000107 * Cleanup:
108 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +0000109 *
110 *
plars865695b2001-08-27 22:15:12 +0000111 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
112
113#include <errno.h>
114#include <signal.h>
115#include <sys/wait.h>
116#include <string.h>
117#include <stdlib.h>
118#include "test.h"
119#include "usctest.h"
120
121void setup();
122void cleanup();
123
subrata_modak56207ce2009-03-23 13:35:39 +0000124char *TCID = "setpgrp01"; /* Test program identifier. */
125int TST_TOTAL = 1; /* Total number of test cases. */
plars865695b2001-08-27 22:15:12 +0000126extern int Tst_count; /* Test Case counter for tst_* routines */
127
subrata_modak56207ce2009-03-23 13:35:39 +0000128int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000129{
subrata_modak56207ce2009-03-23 13:35:39 +0000130 int lc; /* loop counter */
131 char *msg; /* message returned from parse_opts */
132
plars865695b2001-08-27 22:15:12 +0000133 /***************************************************************
134 * parse standard options
135 ***************************************************************/
Garrett Cooper45e285d2010-11-22 12:19:25 -0800136 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000137 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak88c166c2009-06-09 16:01:20 +0000138 tst_exit();
subrata_modak56207ce2009-03-23 13:35:39 +0000139 }
plars865695b2001-08-27 22:15:12 +0000140
141 /***************************************************************
142 * perform global setup for test
143 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000144 setup();
plars865695b2001-08-27 22:15:12 +0000145
146 /***************************************************************
147 * check looping state if -c option given
148 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000149 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000150
subrata_modak56207ce2009-03-23 13:35:39 +0000151 /* reset Tst_count in case we are looping. */
152 Tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000153
subrata_modak56207ce2009-03-23 13:35:39 +0000154 /*
155 * TEST CASE:
156 * Call the setpgrp system call
157 */
plars865695b2001-08-27 22:15:12 +0000158
subrata_modak56207ce2009-03-23 13:35:39 +0000159 /* Call setpgrp(2) */
160 TEST(setpgrp());
subrata_modakbdbaec52009-02-26 12:14:51 +0000161
subrata_modak56207ce2009-03-23 13:35:39 +0000162 /* check return code */
plars865695b2001-08-27 22:15:12 +0000163#ifdef linux
subrata_modak56207ce2009-03-23 13:35:39 +0000164 if (TEST_RETURN != 0) {
plars865695b2001-08-27 22:15:12 +0000165#else
subrata_modak56207ce2009-03-23 13:35:39 +0000166 if (TEST_RETURN <= 0) {
plars865695b2001-08-27 22:15:12 +0000167#endif
subrata_modak56207ce2009-03-23 13:35:39 +0000168 tst_resm(TFAIL,
169 "setpgrp - Call the setpgrp system call failed, errno=%d : %s",
170 TEST_ERRNO, strerror(TEST_ERRNO));
171 } else {
plars865695b2001-08-27 22:15:12 +0000172 /***************************************************************
173 * only perform functional verification if flag set (-f not given)
174 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000175 if (STD_FUNCTIONAL_TEST) {
176 /* No Verification test, yet... */
177 tst_resm(TPASS,
subrata_modak923b23f2009-11-02 13:57:16 +0000178 "setpgrp - Call the setpgrp system call returned %ld",
subrata_modak56207ce2009-03-23 13:35:39 +0000179 TEST_RETURN);
180 }
181 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000182
subrata_modak56207ce2009-03-23 13:35:39 +0000183 } /* End for TEST_LOOPING */
plars865695b2001-08-27 22:15:12 +0000184
185 /***************************************************************
186 * cleanup and exit
187 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000188 cleanup();
plars865695b2001-08-27 22:15:12 +0000189
subrata_modak56207ce2009-03-23 13:35:39 +0000190 return 0;
191} /* End main */
plars865695b2001-08-27 22:15:12 +0000192
193/***************************************************************
194 * setup() - performs all ONE TIME setup for this test.
195 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000196void setup()
plars865695b2001-08-27 22:15:12 +0000197{
subrata_modak56207ce2009-03-23 13:35:39 +0000198 int pid, status;
plars865695b2001-08-27 22:15:12 +0000199
subrata_modak56207ce2009-03-23 13:35:39 +0000200 /* capture signals */
201 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000202
subrata_modak56207ce2009-03-23 13:35:39 +0000203 /* Pause if that option was specified */
204 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000205
subrata_modak56207ce2009-03-23 13:35:39 +0000206 /*
207 * Make sure current process is NOT a session or pgrp leader
208 */
plars865695b2001-08-27 22:15:12 +0000209
subrata_modak56207ce2009-03-23 13:35:39 +0000210 if (getpgrp() == getpid()) {
211 if ((pid = FORK_OR_VFORK()) == -1) {
212 tst_brkm(TBROK, cleanup,
213 "fork() in setup() failed - errno %d", errno);
214 }
215
216 if (pid != 0) { /* parent - sits and waits */
217 wait(&status);
218 exit(WEXITSTATUS(status));
219 }
220
221 /* child - continues with test */
plars865695b2001-08-27 22:15:12 +0000222 }
subrata_modak56207ce2009-03-23 13:35:39 +0000223} /* End setup() */
plars865695b2001-08-27 22:15:12 +0000224
225/***************************************************************
226 * cleanup() - performs all ONE TIME cleanup for this test at
227 * completion or premature exit.
228 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000229void cleanup()
plars865695b2001-08-27 22:15:12 +0000230{
subrata_modak56207ce2009-03-23 13:35:39 +0000231 /*
232 * print timing stats if that option was specified.
233 */
234 TEST_CLEANUP;
plars865695b2001-08-27 22:15:12 +0000235
subrata_modak56207ce2009-03-23 13:35:39 +0000236 /* exit with return code appropriate for results */
237 tst_exit();
238} /* End cleanup() */