1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org> 4 * 5 * Basic fspick() failure tests. 6 */ 7#include "tst_test.h" 8#include "lapi/fsmount.h" 9 10#define MNTPOINT "mntpoint" 11 12static 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, FSPICK_NO_AUTOMOUNT | FSPICK_CLOEXEC, EBADF}, 20 {"invalid-path", AT_FDCWD, "invalid", FSPICK_NO_AUTOMOUNT | FSPICK_CLOEXEC, ENOENT}, 21 {"invalid-flags", AT_FDCWD, MNTPOINT, 0x10, EINVAL}, 22}; 23 24static void run(unsigned int n) 25{ 26 struct tcase *tc = &tcases[n]; 27 28 TEST(fspick(tc->dirfd, tc->pathname, tc->flags)); 29 if (TST_RET != -1) { 30 SAFE_CLOSE(TST_RET); 31 tst_res(TFAIL, "%s: fspick() 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: fspick() should fail with %s", 38 tc->name, tst_strerrno(tc->exp_errno)); 39 return; 40 } 41 42 tst_res(TPASS | TTERRNO, "%s: fspick() failed as expected", tc->name); 43} 44 45static struct tst_test test = { 46 .tcnt = ARRAY_SIZE(tcases), 47 .test = run, 48 .setup = fsopen_supported_by_kernel, 49 .needs_root = 1, 50 .mount_device = 1, 51 .mntpoint = MNTPOINT, 52 .all_filesystems = 1, 53 .skip_filesystems = (const char *const []){"fuse", NULL}, 54}; 55