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