plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 22 | * fork03.c |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * |
| 24 | * DESCRIPTION |
| 25 | * Check that child can use a large text space and do a large |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 26 | * number of operations. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 27 | * |
| 28 | * ALGORITHM |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 29 | * Fork one process, check for pid == 0 in child. |
| 30 | * Check for pid > 0 in parent after wait. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 31 | * |
| 32 | * USAGE |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 33 | * fork03 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | * |
| 35 | * HISTORY |
| 36 | * 07/2001 Ported by Wayne Boyer |
| 37 | * |
| 38 | * RESTRICTIONS |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 39 | * None |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | */ |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 41 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 42 | #include <sys/types.h> |
| 43 | #include <sys/wait.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | #include <stdio.h> |
| 45 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 47 | char *TCID = "fork03"; |
| 48 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 49 | |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 50 | static void setup(void); |
| 51 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 53 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | { |
| 55 | float fl1, fl2; |
| 56 | int i; |
| 57 | int pid1, pid2, status; |
| 58 | |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 59 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 60 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 61 | |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 62 | msg = parse_opts(ac, av, NULL, NULL); |
| 63 | if (msg != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 64 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | setup(); |
| 67 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 69 | tst_count = 0; |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 70 | pid1 = fork(); |
| 71 | if (pid1 == -1) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | tst_brkm(TBROK, cleanup, "fork() failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 74 | if (pid1 == 0) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | /* 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 Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 86 | if (pid1 != 0) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | exit(1); |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 88 | else |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | exit(0); |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 90 | } else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | 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 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 109 | |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 110 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 111 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 114 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 117 | TEST_PAUSE; |
| 118 | } |
| 119 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 120 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | { |
Wanlong Gao | 8ebcc19 | 2012-09-18 17:14:01 +0800 | [diff] [blame] | 122 | } |