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