• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) International Business Machines  Corp., 2001
3  *  07/2001 John George - Ported
4  *  04/2002 wjhuie sigset cleanups
5  *
6  * This program is free software;  you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14  * the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.
18  */
19 
20 /*
21  * Tests to see if pids returned from fork and waitpid are same
22  *
23  * Fork 8 kids, 2 will immediately exit, 2 will sleep, 2 will be compute bound
24  * and 2 will fork/reap a child for 50 times.
25  */
26 
27 #include "waitpid_common.h"
28 
29 static void do_compute(void);
30 static void do_fork(void);
31 static void do_sleep(void);
32 
do_child_1(void)33 static void do_child_1(void)
34 {
35 	pid_t pid;
36 	int i;
37 
38 	for (i = 0; i < MAXKIDS; i++) {
39 		pid = SAFE_FORK();
40 		if (pid == 0) {
41 			if (i == 0 || i == 1)
42 				do_exit(0);
43 
44 			if (i == 2 || i == 3)
45 				do_compute();
46 
47 			if (i == 4 || i == 5)
48 				do_fork();
49 
50 			if (i == 6 || i == 7)
51 				do_sleep();
52 		}
53 
54 		fork_kid_pid[i] = pid;
55 	}
56 
57 	TST_CHECKPOINT_WAKE2(0, MAXKIDS);
58 
59 	if (TST_TRACE(reap_children(0, 0, fork_kid_pid, MAXKIDS)))
60 		return;
61 
62 	tst_res(TPASS, "Test PASSED");
63 }
64 
do_compute(void)65 static void do_compute(void)
66 {
67 	int i;
68 
69 	TST_CHECKPOINT_WAIT(0);
70 
71 	for (i = 0; i < 100000; i++) ;
72 	for (i = 0; i < 100000; i++) ;
73 	for (i = 0; i < 100000; i++) ;
74 	for (i = 0; i < 100000; i++) ;
75 	for (i = 0; i < 100000; i++) ;
76 	for (i = 0; i < 100000; i++) ;
77 	for (i = 0; i < 100000; i++) ;
78 	for (i = 0; i < 100000; i++) ;
79 	for (i = 0; i < 100000; i++) ;
80 	for (i = 0; i < 100000; i++) ;
81 
82 	exit(3);
83 }
84 
do_fork(void)85 static void do_fork(void)
86 {
87 	pid_t fork_pid;
88 	int i;
89 
90 	TST_CHECKPOINT_WAIT(0);
91 
92 	for (i = 0; i < 50; i++) {
93 		fork_pid = SAFE_FORK();
94 		if (fork_pid == 0)
95 			exit(3);
96 
97 		if (TST_TRACE(reap_children(fork_pid, 0, &fork_pid, 1)))
98 			break;
99 	}
100 
101 	exit(3);
102 }
103 
do_sleep(void)104 static void do_sleep(void)
105 {
106 	TST_CHECKPOINT_WAIT(0);
107 
108 	sleep(1);
109 	sleep(1);
110 
111 	exit(3);
112 }
113 
114 static struct tst_test test = {
115 	.tid = "waitpid10",
116 	.forks_child = 1,
117 	.needs_checkpoints = 1,
118 	.setup = waitpid_setup,
119 	.cleanup = waitpid_cleanup,
120 	.test_all = waitpid_test,
121 };
122