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