blob: f8f64bb891245af9c12f71a89de23f4688ecb797 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
Wanlong Gao8ebcc192012-09-18 17:14:01 +080022 * fork03.c
plars865695b2001-08-27 22:15:12 +000023 *
24 * DESCRIPTION
25 * Check that child can use a large text space and do a large
subrata_modakbdbaec52009-02-26 12:14:51 +000026 * number of operations.
plars865695b2001-08-27 22:15:12 +000027 *
28 * ALGORITHM
Wanlong Gao8ebcc192012-09-18 17:14:01 +080029 * Fork one process, check for pid == 0 in child.
30 * Check for pid > 0 in parent after wait.
plars865695b2001-08-27 22:15:12 +000031 *
32 * USAGE
Wanlong Gao8ebcc192012-09-18 17:14:01 +080033 * fork03
plars865695b2001-08-27 22:15:12 +000034 *
35 * HISTORY
36 * 07/2001 Ported by Wayne Boyer
37 *
38 * RESTRICTIONS
Wanlong Gao8ebcc192012-09-18 17:14:01 +080039 * None
plars865695b2001-08-27 22:15:12 +000040 */
Wanlong Gao8ebcc192012-09-18 17:14:01 +080041
plars74948ad2002-11-14 16:16:14 +000042#include <sys/types.h>
43#include <sys/wait.h>
plars865695b2001-08-27 22:15:12 +000044#include <stdio.h>
45#include "test.h"
plars865695b2001-08-27 22:15:12 +000046
plars865695b2001-08-27 22:15:12 +000047char *TCID = "fork03";
48int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000049
Wanlong Gao8ebcc192012-09-18 17:14:01 +080050static void setup(void);
51static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000052
plars74948ad2002-11-14 16:16:14 +000053int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000054{
55 float fl1, fl2;
56 int i;
57 int pid1, pid2, status;
58
Wanlong Gao8ebcc192012-09-18 17:14:01 +080059 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020060 const char *msg;
plars865695b2001-08-27 22:15:12 +000061
Wanlong Gao8ebcc192012-09-18 17:14:01 +080062 msg = parse_opts(ac, av, NULL, NULL);
63 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080064 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000065
plars865695b2001-08-27 22:15:12 +000066 setup();
67
plars865695b2001-08-27 22:15:12 +000068 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080069 tst_count = 0;
Wanlong Gao8ebcc192012-09-18 17:14:01 +080070 pid1 = fork();
71 if (pid1 == -1)
plars865695b2001-08-27 22:15:12 +000072 tst_brkm(TBROK, cleanup, "fork() failed");
plars865695b2001-08-27 22:15:12 +000073
Wanlong Gao8ebcc192012-09-18 17:14:01 +080074 if (pid1 == 0) {
plars865695b2001-08-27 22:15:12 +000075 /* child uses some cpu cycles */
76 for (i = 1; i < 32767; i++) {
77 fl1 = 0.000001;
78 fl1 = fl2 = 0.000001;
79 fl1 = fl1 * 10.0;
80 fl2 = fl1 / 1.232323;
81 fl1 = fl2 - fl2;
82 fl1 = fl2;
83 }
84
85 /* Pid must always be zero in child */
Wanlong Gao8ebcc192012-09-18 17:14:01 +080086 if (pid1 != 0)
plars865695b2001-08-27 22:15:12 +000087 exit(1);
Wanlong Gao8ebcc192012-09-18 17:14:01 +080088 else
plars865695b2001-08-27 22:15:12 +000089 exit(0);
Wanlong Gao8ebcc192012-09-18 17:14:01 +080090 } else {
plars865695b2001-08-27 22:15:12 +000091 tst_resm(TINFO, "process id in parent of child from "
92 "fork : %d", pid1);
93 pid2 = wait(&status); /* wait for child */
94
95 if (pid1 != pid2) {
96 tst_resm(TFAIL, "pids don't match : %d vs %d",
97 pid1, pid2);
98 continue;
99 }
100
101 if ((status >> 8) != 0) {
102 tst_resm(TFAIL, "child exited with failure");
103 continue;
104 }
105
106 tst_resm(TPASS, "test 1 PASSED");
107 }
108 }
plars865695b2001-08-27 22:15:12 +0000109
Wanlong Gao8ebcc192012-09-18 17:14:01 +0800110 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800111 tst_exit();
plars865695b2001-08-27 22:15:12 +0000112}
113
Mike Frysingerc57fba52014-04-09 18:56:30 -0400114static void setup(void)
plars865695b2001-08-27 22:15:12 +0000115{
plars865695b2001-08-27 22:15:12 +0000116 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000117 TEST_PAUSE;
118}
119
Mike Frysingerc57fba52014-04-09 18:56:30 -0400120static void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000121{
Wanlong Gao8ebcc192012-09-18 17:14:01 +0800122}