• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
4  *
5  * Basic open_tree() failure tests.
6  */
7 #include "tst_test.h"
8 #include "lapi/fsmount.h"
9 
10 #define MNTPOINT	"mntpoint"
11 
12 static struct tcase {
13 	char *name;
14 	int dirfd;
15 	const char *pathname;
16 	unsigned int flags;
17 	int exp_errno;
18 } tcases[] = {
19 	{"invalid-fd", -1, MNTPOINT, OPEN_TREE_CLONE, EBADF},
20 	{"invalid-path", AT_FDCWD, "invalid", OPEN_TREE_CLONE, ENOENT},
21 	{"invalid-flags", AT_FDCWD, MNTPOINT, 0xFFFFFFFF, EINVAL},
22 };
23 
run(unsigned int n)24 static void run(unsigned int n)
25 {
26 	struct tcase *tc = &tcases[n];
27 
28 	TEST(open_tree(tc->dirfd, tc->pathname, tc->flags));
29 	if (TST_RET != -1) {
30 		SAFE_CLOSE(TST_RET);
31 		tst_res(TFAIL, "%s: open_tree() succeeded unexpectedly (index: %d)",
32 			tc->name, n);
33 		return;
34 	}
35 
36 	if (tc->exp_errno != TST_ERR) {
37 		tst_res(TFAIL | TTERRNO, "%s: open_tree() should fail with %s",
38 			tc->name, tst_strerrno(tc->exp_errno));
39 		return;
40 	}
41 
42 	tst_res(TPASS | TTERRNO, "%s: open_tree() failed as expected",
43 		tc->name);
44 }
45 
46 static struct tst_test test = {
47 	.tcnt = ARRAY_SIZE(tcases),
48 	.test = run,
49 	.setup = fsopen_supported_by_kernel,
50 	.needs_root = 1,
51 	.mount_device = 1,
52 	.mntpoint = MNTPOINT,
53 	.all_filesystems = 1,
54 	.skip_filesystems = (const char *const []){"fuse", NULL},
55 };
56