xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/clone/clone04.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-only
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2012 Wanlong Gao <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Linux Test Project, 2003-2023
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker  *
11*49cdfc7eSAndroid Build Coastguard Worker  * Verify that clone(2) fails with
12*49cdfc7eSAndroid Build Coastguard Worker  *
13*49cdfc7eSAndroid Build Coastguard Worker  * - EINVAL if child stack is set to NULL
14*49cdfc7eSAndroid Build Coastguard Worker  */
15*49cdfc7eSAndroid Build Coastguard Worker 
16*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker #include "clone_platform.h"
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED);
21*49cdfc7eSAndroid Build Coastguard Worker 
22*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
23*49cdfc7eSAndroid Build Coastguard Worker 	int (*child_fn)(void *arg);
24*49cdfc7eSAndroid Build Coastguard Worker 	void *child_stack;
25*49cdfc7eSAndroid Build Coastguard Worker 	int exp_errno;
26*49cdfc7eSAndroid Build Coastguard Worker 	char err_desc[10];
27*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
28*49cdfc7eSAndroid Build Coastguard Worker 	{child_fn, NULL, EINVAL, "NULL stack"},
29*49cdfc7eSAndroid Build Coastguard Worker };
30*49cdfc7eSAndroid Build Coastguard Worker 
child_fn(void * arg LTP_ATTRIBUTE_UNUSED)31*49cdfc7eSAndroid Build Coastguard Worker static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED)
32*49cdfc7eSAndroid Build Coastguard Worker {
33*49cdfc7eSAndroid Build Coastguard Worker 	exit(0);
34*49cdfc7eSAndroid Build Coastguard Worker }
35*49cdfc7eSAndroid Build Coastguard Worker 
verify_clone(unsigned int nr)36*49cdfc7eSAndroid Build Coastguard Worker static void verify_clone(unsigned int nr)
37*49cdfc7eSAndroid Build Coastguard Worker {
38*49cdfc7eSAndroid Build Coastguard Worker 	struct tcase *tc = &tcases[nr];
39*49cdfc7eSAndroid Build Coastguard Worker 
40*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL(ltp_clone(0, tc->child_fn, NULL,
41*49cdfc7eSAndroid Build Coastguard Worker 				CHILD_STACK_SIZE, tc->child_stack),
42*49cdfc7eSAndroid Build Coastguard Worker 				tc->exp_errno, "%s", tc->err_desc);
43*49cdfc7eSAndroid Build Coastguard Worker }
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
46*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcases),
47*49cdfc7eSAndroid Build Coastguard Worker 	.test = verify_clone,
48*49cdfc7eSAndroid Build Coastguard Worker 	.tags = (const struct tst_tag[]) {
49*49cdfc7eSAndroid Build Coastguard Worker 		{"musl-git", "fa4a8abd06a4"},
50*49cdfc7eSAndroid Build Coastguard Worker 		{}
51*49cdfc7eSAndroid Build Coastguard Worker 	},
52*49cdfc7eSAndroid Build Coastguard Worker };
53