1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. 4f08c3bdfSopenharmony_ci * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Basic clone() test. 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Use clone() to create a child process, and wait for the child process to exit, 13f08c3bdfSopenharmony_ci * verify that the child process pid is correct. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include <stdlib.h> 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci#include "clone_platform.h" 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic void *child_stack; 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_cistatic int do_child(void *arg LTP_ATTRIBUTE_UNUSED) 23f08c3bdfSopenharmony_ci{ 24f08c3bdfSopenharmony_ci exit(0); 25f08c3bdfSopenharmony_ci} 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_cistatic void verify_clone(void) 28f08c3bdfSopenharmony_ci{ 29f08c3bdfSopenharmony_ci int status, child_pid; 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, do_child, NULL, 32f08c3bdfSopenharmony_ci CHILD_STACK_SIZE, child_stack), "clone()"); 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci child_pid = SAFE_WAIT(&status); 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci if (child_pid == TST_RET) 37f08c3bdfSopenharmony_ci tst_res(TPASS, "clone returned %ld", TST_RET); 38f08c3bdfSopenharmony_ci else 39f08c3bdfSopenharmony_ci tst_res(TFAIL, "clone returned %ld, wait returned %d", 40f08c3bdfSopenharmony_ci TST_RET, child_pid); 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_ci if (WIFEXITED(status) && WEXITSTATUS(status) == 0) 43f08c3bdfSopenharmony_ci tst_res(TPASS, "Child exited with 0"); 44f08c3bdfSopenharmony_ci else 45f08c3bdfSopenharmony_ci tst_res(TFAIL, "Child %s", tst_strstatus(status)); 46f08c3bdfSopenharmony_ci} 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_cistatic struct tst_test test = { 49f08c3bdfSopenharmony_ci .test_all = verify_clone, 50f08c3bdfSopenharmony_ci .forks_child = 1, 51f08c3bdfSopenharmony_ci .bufs = (struct tst_buffers []) { 52f08c3bdfSopenharmony_ci {&child_stack, .size = CHILD_STACK_SIZE}, 53f08c3bdfSopenharmony_ci {} 54f08c3bdfSopenharmony_ci }, 55f08c3bdfSopenharmony_ci}; 56