1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4f08c3bdfSopenharmony_ci */
5f08c3bdfSopenharmony_ci
6f08c3bdfSopenharmony_ci/*\
7f08c3bdfSopenharmony_ci * [Description]
8f08c3bdfSopenharmony_ci *
9f08c3bdfSopenharmony_ci * This test case checks whether sysfs(2) system call returns appropriate
10f08c3bdfSopenharmony_ci * error number for invalid option and for invalid filesystem name and fs index out of bounds.
11f08c3bdfSopenharmony_ci */
12f08c3bdfSopenharmony_ci
13f08c3bdfSopenharmony_ci#include "tst_test.h"
14f08c3bdfSopenharmony_ci#include "lapi/syscalls.h"
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_cistatic struct test_case {
17f08c3bdfSopenharmony_ci	int option;
18f08c3bdfSopenharmony_ci	char *fsname;
19f08c3bdfSopenharmony_ci	int fsindex;
20f08c3bdfSopenharmony_ci	char *err_desc;
21f08c3bdfSopenharmony_ci	int exp_errno;
22f08c3bdfSopenharmony_ci} tcases[] = {
23f08c3bdfSopenharmony_ci	{1, "ext0", 0, "Invalid filesystem name", EINVAL},
24f08c3bdfSopenharmony_ci	{4, NULL, 0, "Invalid option", EINVAL},
25f08c3bdfSopenharmony_ci	{1, NULL, 0, "Address is out of your address space", EFAULT},
26f08c3bdfSopenharmony_ci	{2, NULL, 1000, "fs_index is out of bounds", EINVAL}
27f08c3bdfSopenharmony_ci};
28f08c3bdfSopenharmony_ci
29f08c3bdfSopenharmony_cistatic void verify_sysfs05(unsigned int nr)
30f08c3bdfSopenharmony_ci{
31f08c3bdfSopenharmony_ci	struct test_case *tc = &tcases[nr];
32f08c3bdfSopenharmony_ci	char buf[1024];
33f08c3bdfSopenharmony_ci
34f08c3bdfSopenharmony_ci	if (tc->option == 1) {
35f08c3bdfSopenharmony_ci		TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsname),
36f08c3bdfSopenharmony_ci					tc->exp_errno, "%s", tc->err_desc);
37f08c3bdfSopenharmony_ci	} else {
38f08c3bdfSopenharmony_ci		TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsindex, buf),
39f08c3bdfSopenharmony_ci					tc->exp_errno, "%s", tc->err_desc);
40f08c3bdfSopenharmony_ci	}
41f08c3bdfSopenharmony_ci}
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_cistatic void setup(void)
44f08c3bdfSopenharmony_ci{
45f08c3bdfSopenharmony_ci	unsigned int i;
46f08c3bdfSopenharmony_ci	char *bad_addr;
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci	bad_addr = tst_get_bad_addr(NULL);
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_ci	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
51f08c3bdfSopenharmony_ci		if (tcases[i].exp_errno == EFAULT)
52f08c3bdfSopenharmony_ci			tcases[i].fsname = bad_addr;
53f08c3bdfSopenharmony_ci	}
54f08c3bdfSopenharmony_ci}
55f08c3bdfSopenharmony_ci
56f08c3bdfSopenharmony_cistatic struct tst_test test = {
57f08c3bdfSopenharmony_ci	.setup = setup,
58f08c3bdfSopenharmony_ci	.tcnt = ARRAY_SIZE(tcases),
59f08c3bdfSopenharmony_ci	.test = verify_sysfs05,
60f08c3bdfSopenharmony_ci};
61f08c3bdfSopenharmony_ci
62