• 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 fsopen() failure tests.
6  */
7 #include "tst_test.h"
8 #include "lapi/fsmount.h"
9 
10 const char *invalid_fs = "invalid";
11 const char *valid_fs;
12 
13 static struct tcase {
14 	char *name;
15 	const char **fs;
16 	unsigned int flags;
17 	int exp_errno;
18 } tcases[] = {
19 	{"invalid-fs", &invalid_fs, 0, ENODEV},
20 	{"invalid-flags", &valid_fs, 0x10, EINVAL},
21 };
22 
setup(void)23 static void setup(void)
24 {
25 	fsopen_supported_by_kernel();
26 
27 	valid_fs = tst_device->fs_type;
28 }
29 
run(unsigned int n)30 static void run(unsigned int n)
31 {
32 	struct tcase *tc = &tcases[n];
33 
34 	TEST(fsopen(*tc->fs, tc->flags));
35 
36 	if (TST_RET != -1) {
37 		SAFE_CLOSE(TST_RET);
38 		tst_res(TFAIL, "%s: fsopen() succeeded unexpectedly (index: %d)",
39 			tc->name, n);
40 		return;
41 	}
42 
43 	if (tc->exp_errno != TST_ERR) {
44 		tst_res(TFAIL | TTERRNO, "%s: fsopen() should fail with %s",
45 			tc->name, tst_strerrno(tc->exp_errno));
46 		return;
47 	}
48 
49 	tst_res(TPASS | TTERRNO, "%s: fsopen() failed as expected", tc->name);
50 }
51 
52 static struct tst_test test = {
53 	.tcnt = ARRAY_SIZE(tcases),
54 	.test = run,
55 	.setup = setup,
56 	.needs_root = 1,
57 	.needs_device = 1,
58 };
59