1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2020 Viresh Kumar <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * Basic fspick() test.
6*49cdfc7eSAndroid Build Coastguard Worker */
7*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
8*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/fsmount.h"
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard Worker #define MNTPOINT "mntpoint"
11*49cdfc7eSAndroid Build Coastguard Worker #define TCASE_ENTRY(_flags) {.name = "Flag " #_flags, .flags = _flags}
12*49cdfc7eSAndroid Build Coastguard Worker
13*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
14*49cdfc7eSAndroid Build Coastguard Worker char *name;
15*49cdfc7eSAndroid Build Coastguard Worker unsigned int flags;
16*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
17*49cdfc7eSAndroid Build Coastguard Worker TCASE_ENTRY(FSPICK_CLOEXEC),
18*49cdfc7eSAndroid Build Coastguard Worker TCASE_ENTRY(FSPICK_SYMLINK_NOFOLLOW),
19*49cdfc7eSAndroid Build Coastguard Worker TCASE_ENTRY(FSPICK_NO_AUTOMOUNT),
20*49cdfc7eSAndroid Build Coastguard Worker TCASE_ENTRY(FSPICK_EMPTY_PATH),
21*49cdfc7eSAndroid Build Coastguard Worker };
22*49cdfc7eSAndroid Build Coastguard Worker
run(unsigned int n)23*49cdfc7eSAndroid Build Coastguard Worker static void run(unsigned int n)
24*49cdfc7eSAndroid Build Coastguard Worker {
25*49cdfc7eSAndroid Build Coastguard Worker struct tcase *tc = &tcases[n];
26*49cdfc7eSAndroid Build Coastguard Worker int fspick_fd;
27*49cdfc7eSAndroid Build Coastguard Worker
28*49cdfc7eSAndroid Build Coastguard Worker TEST(fspick_fd = fspick(AT_FDCWD, MNTPOINT, tc->flags));
29*49cdfc7eSAndroid Build Coastguard Worker if (fspick_fd == -1) {
30*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "fspick() failed");
31*49cdfc7eSAndroid Build Coastguard Worker return;
32*49cdfc7eSAndroid Build Coastguard Worker }
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker TEST(fsconfig(fspick_fd, FSCONFIG_SET_STRING, "sync", "false", 0));
35*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1) {
36*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_STRING) failed");
37*49cdfc7eSAndroid Build Coastguard Worker goto out;
38*49cdfc7eSAndroid Build Coastguard Worker }
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker TEST(fsconfig(fspick_fd, FSCONFIG_SET_FLAG, "ro", NULL, 0));
41*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1) {
42*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_FLAG) failed");
43*49cdfc7eSAndroid Build Coastguard Worker goto out;
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Worker TEST(fsconfig(fspick_fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0));
47*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1) {
48*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_CMD_RECONFIGURE) failed");
49*49cdfc7eSAndroid Build Coastguard Worker goto out;
50*49cdfc7eSAndroid Build Coastguard Worker }
51*49cdfc7eSAndroid Build Coastguard Worker
52*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "%s: fspick() passed", tc->name);
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker out:
55*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(fspick_fd);
56*49cdfc7eSAndroid Build Coastguard Worker }
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
59*49cdfc7eSAndroid Build Coastguard Worker .tcnt = ARRAY_SIZE(tcases),
60*49cdfc7eSAndroid Build Coastguard Worker .test = run,
61*49cdfc7eSAndroid Build Coastguard Worker .setup = fsopen_supported_by_kernel,
62*49cdfc7eSAndroid Build Coastguard Worker .needs_root = 1,
63*49cdfc7eSAndroid Build Coastguard Worker .mount_device = 1,
64*49cdfc7eSAndroid Build Coastguard Worker .mntpoint = MNTPOINT,
65*49cdfc7eSAndroid Build Coastguard Worker .all_filesystems = 1,
66*49cdfc7eSAndroid Build Coastguard Worker .skip_filesystems = (const char *const []){"fuse", NULL},
67*49cdfc7eSAndroid Build Coastguard Worker };
68