1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2003-2023 5f08c3bdfSopenharmony_ci * Author: 2001 Ported by Wayne Boyer 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci *[Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Check that child process can use a large text space and do a large number 12f08c3bdfSopenharmony_ci * of operations. In this situation, check for pid == 0 in child and check 13f08c3bdfSopenharmony_ci * for pid > 0 in parent after wait. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include <unistd.h> 17f08c3bdfSopenharmony_ci#include <sys/wait.h> 18f08c3bdfSopenharmony_ci#include <stdlib.h> 19f08c3bdfSopenharmony_ci#include "tst_test.h" 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_cistatic void verify_fork(void) 22f08c3bdfSopenharmony_ci{ 23f08c3bdfSopenharmony_ci float fl1, fl2; 24f08c3bdfSopenharmony_ci int pid1, pid2, status, i; 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci pid1 = SAFE_FORK(); 27f08c3bdfSopenharmony_ci if (!pid1) { 28f08c3bdfSopenharmony_ci /* child uses some cpu time slices */ 29f08c3bdfSopenharmony_ci for (i = 1; i < 32767; i++) { 30f08c3bdfSopenharmony_ci fl1 = 0.000001; 31f08c3bdfSopenharmony_ci fl1 = fl2 = 0.000001; 32f08c3bdfSopenharmony_ci fl1 = fl1 * 10.0; 33f08c3bdfSopenharmony_ci fl2 = fl1 / 1.232323; 34f08c3bdfSopenharmony_ci fl1 = fl2 - fl2; 35f08c3bdfSopenharmony_ci fl1 = fl2; 36f08c3bdfSopenharmony_ci } 37f08c3bdfSopenharmony_ci exit(!!pid1); 38f08c3bdfSopenharmony_ci } 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci tst_res(TINFO, "process id in parent of child from fork: %d", pid1); 41f08c3bdfSopenharmony_ci pid2 = SAFE_WAIT(&status); 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci if (pid1 != pid2) { 44f08c3bdfSopenharmony_ci tst_res(TFAIL, "pids don't match: %d vs %d", pid1, pid2); 45f08c3bdfSopenharmony_ci return; 46f08c3bdfSopenharmony_ci } 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci if ((status >> 8) != 0) { 49f08c3bdfSopenharmony_ci tst_res(TFAIL, "child exited with failure"); 50f08c3bdfSopenharmony_ci return; 51f08c3bdfSopenharmony_ci } 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_ci tst_res(TPASS, "test PASSED"); 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cistatic struct tst_test test = { 57f08c3bdfSopenharmony_ci .test_all = verify_fork, 58f08c3bdfSopenharmony_ci .forks_child = 1, 59f08c3bdfSopenharmony_ci}; 60