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 * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Call clone() with CLONE_VFORK flag set. verify that
12 * execution of parent is suspended until child finishes
13 */
14
15 #define _GNU_SOURCE
16
17 #include <stdlib.h>
18 #include <sched.h>
19 #include "tst_test.h"
20 #include "clone_platform.h"
21
22 static volatile int child_exited;
23 static void *child_stack;
24
child_fn(void * unused LTP_ATTRIBUTE_UNUSED)25 static int child_fn(void *unused LTP_ATTRIBUTE_UNUSED)
26 {
27 int i;
28
29 for (i = 0; i < 100; i++) {
30 sched_yield();
31 usleep(1000);
32 }
33
34 child_exited = 1;
35 _exit(0);
36 }
37
verify_clone(void)38 static void verify_clone(void)
39 {
40 child_exited = 0;
41
42 TST_EXP_PID_SILENT(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
43 CHILD_STACK_SIZE, child_stack), "clone with vfork");
44
45 if (!TST_PASS)
46 return;
47
48 TST_EXP_VAL(child_exited, 1);
49 }
50
51 static struct tst_test test = {
52 .test_all = verify_clone,
53 .bufs = (struct tst_buffers []) {
54 {&child_stack, .size = CHILD_STACK_SIZE},
55 {},
56 },
57 };
58