• 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  * 	getppid02.c
23  *
24  * DESCRIPTION
25  * 	Testcase to check the basic functionality of the getppid() syscall.
26  *
27  * USAGE:  <for command-line>
28  *  getppid02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
29  *     where,  -c n : Run n copies concurrently.
30  *             -f   : Turn off functionality Testing.
31  *             -i n : Execute test n times.
32  *             -I x : Execute test for x seconds.
33  *             -P x : Pause for x seconds between iterations.
34  *             -t   : Turn on syscall timing.
35  *
36  * HISTORY
37  *	07/2001 Ported by Wayne Boyer
38  *
39  * RESTRICTIONS
40  * 	None
41  */
42 #include <sys/types.h>
43 #include <sys/wait.h>
44 #include <err.h>
45 #include <errno.h>
46 #include "test.h"
47 
48 char *TCID = "getppid02";
49 int TST_TOTAL = 1;
50 
51 void setup(void);
52 void cleanup(void);
53 
main(int ac,char ** av)54 int main(int ac, char **av)
55 {
56 
57 	int lc;
58 	int status;
59 	pid_t pid, ppid;
60 
61 	tst_parse_opts(ac, av, NULL, NULL);
62 
63 	setup();
64 
65 	for (lc = 0; TEST_LOOPING(lc); lc++) {
66 		tst_count = 0;
67 
68 		ppid = getpid();
69 		pid = FORK_OR_VFORK();
70 		if (pid == -1)
71 			tst_brkm(TBROK, cleanup, "fork failed");
72 
73 		if (pid == 0) {
74 			TEST(getppid());
75 
76 			if (TEST_RETURN != ppid)
77 				errx(1, "getppid failed (%ld != %d)",
78 				     TEST_RETURN, ppid);
79 			else
80 				printf("return value and parent's pid "
81 				       "value match\n");
82 			exit(0);
83 		} else {
84 			if (wait(&status) == -1)
85 				tst_brkm(TBROK | TERRNO, cleanup,
86 					 "wait failed");
87 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
88 				tst_resm(TFAIL,
89 					 "getppid functionality incorrect");
90 		}
91 	}
92 	cleanup();
93 
94 	tst_exit();
95 }
96 
setup(void)97 void setup(void)
98 {
99 
100 	tst_sig(FORK, DEF_HANDLER, cleanup);
101 
102 	TEST_PAUSE;
103 }
104 
cleanup(void)105 void cleanup(void)
106 {
107 }
108