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) Linux Test Project, 2003-2023
6 */
7
8/*\
9 * [Description]
10 *
11 * Verify that clone(2) fails with
12 *
13 * - EINVAL if child stack is set to NULL
14 */
15
16#include <stdlib.h>
17#include "tst_test.h"
18#include "clone_platform.h"
19
20static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED);
21
22static struct tcase {
23	int (*child_fn)(void *arg);
24	void *child_stack;
25	int exp_errno;
26	char err_desc[10];
27} tcases[] = {
28	{child_fn, NULL, EINVAL, "NULL stack"},
29};
30
31static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED)
32{
33	exit(0);
34}
35
36static void verify_clone(unsigned int nr)
37{
38	struct tcase *tc = &tcases[nr];
39
40	TST_EXP_FAIL(ltp_clone(0, tc->child_fn, NULL,
41				CHILD_STACK_SIZE, tc->child_stack),
42				tc->exp_errno, "%s", tc->err_desc);
43}
44
45static struct tst_test test = {
46	.tcnt = ARRAY_SIZE(tcases),
47	.test = verify_clone,
48	.tags = (const struct tst_tag[]) {
49		{"musl-git", "fa4a8abd06a4"},
50		{}
51	},
52};
53