• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * NAME
22  * 	getpgid01.c
23  *
24  * DESCRIPTION
25  *	Testcase to check the basic functionality of getpgid().
26  *
27  * ALGORITHM
28  * 	block1: Does getpgid(0), and checks for error.
29  * 	block2: Does getpgid(getpid()) and checks for error.
30  * 	block3: Does getpgid(getppid()) and checks for error.
31  * 	block4: Verifies that getpgid(getpgid(0)) == getpgid(0).
32  * 	block5: Does getpgid(1) and checks for error.
33  *
34  * USAGE
35  * 	getpgid01
36  *
37  * HISTORY
38  *	07/2001 Ported by Wayne Boyer
39  *
40  * RESTRICTIONS
41  *	Expects that there are no EPERM limitations on getting the
42  *	process group ID from proc 1 (init).
43  */
44 #define _GNU_SOURCE 1
45 
46 #include <errno.h>
47 #include <unistd.h>
48 #include <stdarg.h>
49 #include <sys/wait.h>
50 #include <sys/types.h>
51 #include "test.h"
52 
53 void setup(void);
54 void cleanup(void);
55 
56 char *TCID = "getpgid01";
57 int TST_TOTAL = 1;
58 
main(int ac,char ** av)59 int main(int ac, char **av)
60 {
61 	int lc;
62 
63 	register int pgid_0, pgid_1;
64 	register int my_pid, my_ppid;
65 	int ex_stat;
66 
67 	tst_parse_opts(ac, av, NULL, NULL);
68 
69 	setup();
70 
71 	for (lc = 0; TEST_LOOPING(lc); lc++) {
72 		tst_count = 0;
73 
74 		if ((pgid_0 = FORK_OR_VFORK()) == -1)
75 			tst_brkm(TBROK, cleanup, "fork failed");
76 		if (pgid_0 > 0) {
77 			while ((pgid_0 = wait(&ex_stat)) != -1) ;
78 
79 			if (WEXITSTATUS(ex_stat) == 0)
80 				tst_resm(TPASS, "%s PASSED", TCID);
81 			else
82 				tst_resm(TFAIL, "%s FAILED", TCID);
83 
84 			exit(0);
85 		}
86 
87 		if ((pgid_0 = getpgid(0)) == -1)
88 			tst_resm(TFAIL | TERRNO, "getpgid(0) failed");
89 		else
90 			tst_resm(TPASS, "getpgid(0) PASSED");
91 
92 //block2:
93 		my_pid = getpid();
94 		if ((pgid_1 = getpgid(my_pid)) == -1)
95 			tst_resm(TFAIL | TERRNO, "getpgid(%d) failed", my_pid);
96 
97 		if (pgid_0 != pgid_1) {
98 			tst_resm(TFAIL, "getpgid(my_pid=%d) != getpgid(0) "
99 				 "[%d != %d]", my_pid, pgid_1, pgid_0);
100 		} else
101 			tst_resm(TPASS, "getpgid(getpid()) PASSED");
102 
103 //block3:
104 		my_ppid = getppid();
105 		if ((pgid_1 = getpgid(my_ppid)) == -1)
106 			tst_resm(TFAIL | TERRNO, "getpgid(%d) failed", my_ppid);
107 
108 		if (pgid_0 != pgid_1) {
109 			tst_resm(TFAIL, "getpgid(%d) != getpgid(0) [%d != %d]",
110 				 my_ppid, pgid_1, pgid_0);
111 		} else
112 			tst_resm(TPASS, "getpgid(getppid()) PASSED");
113 
114 //block4:
115 		if ((pgid_1 = getpgid(pgid_0)) < 0)
116 			tst_resm(TFAIL | TERRNO, "getpgid(%d) failed", pgid_0);
117 
118 		if (pgid_0 != pgid_1) {
119 			tst_resm(TFAIL, "getpgid(%d) != getpgid(0) [%d != %d]",
120 				 pgid_0, pgid_1, pgid_0);
121 		} else
122 			tst_resm(TPASS, "getpgid(%d) PASSED", pgid_0);
123 
124 //block5:
125 		if (getpgid(1) < 0)
126 			tst_resm(TFAIL | TERRNO, "getpgid(1) failed");
127 		else
128 			tst_resm(TPASS, "getpgid(1) PASSED");
129 	}
130 	cleanup();
131 	tst_exit();
132 
133 }
134 
setup(void)135 void setup(void)
136 {
137 
138 	tst_sig(FORK, DEF_HANDLER, cleanup);
139 
140 	TEST_PAUSE;
141 }
142 
cleanup(void)143 void cleanup(void)
144 {
145 }
146