<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 14, 2020 at 7:36 PM Viresh Kumar <<a href="mailto:viresh.kumar@linaro.org" target="_blank">viresh.kumar@linaro.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Add tests to check working of fsopen() syscall.<br>
<br>
Signed-off-by: Viresh Kumar <<a href="mailto:viresh.kumar@linaro.org" target="_blank">viresh.kumar@linaro.org</a>><br>
---<br>
<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 1 +<br>
runtest/syscalls | 3 +<br>
testcases/kernel/syscalls/fsopen/.gitignore | 2 +<br>
testcases/kernel/syscalls/fsopen/Makefile | 6 ++<br>
testcases/kernel/syscalls/fsopen/fsopen01.c | 71 +++++++++++++++++++++<br>
testcases/kernel/syscalls/fsopen/fsopen02.c | 56 ++++++++++++++++<br>
6 files changed, 139 insertions(+)<br>
create mode 100644 testcases/kernel/syscalls/fsopen/.gitignore<br>
create mode 100644 testcases/kernel/syscalls/fsopen/Makefile<br>
create mode 100644 testcases/kernel/syscalls/fsopen/fsopen01.c<br>
create mode 100644 testcases/kernel/syscalls/fsopen/fsopen02.c<br>
<br>
diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
index df4e8c8322fc..4125160a19bb 100644<br>
--- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
@@ -80,6 +80,7 @@ AC_CHECK_FUNCS([ \<br>
execveat \<br>
fallocate \<br>
fchownat \<br>
+ fsopen \<br>
fstatat \<br>
getdents \<br>
getdents64 \<br>
diff --git a/runtest/syscalls b/runtest/syscalls<br>
index 0743cf4e3f74..0a56599ebad9 100644<br>
--- a/runtest/syscalls<br>
+++ b/runtest/syscalls<br>
@@ -542,6 +542,9 @@ fanotify13 fanotify13<br>
fanotify14 fanotify14<br>
fanotify15 fanotify15<br>
<br>
+fsopen01 fsopen01<br>
+fsopen02 fsopen02<br>
+<br>
ioperm01 ioperm01<br>
ioperm02 ioperm02<br>
<br>
diff --git a/testcases/kernel/syscalls/fsopen/.gitignore b/testcases/kernel/syscalls/fsopen/.gitignore<br>
new file mode 100644<br>
index 000000000000..80089dd137a7<br>
--- /dev/null<br>
+++ b/testcases/kernel/syscalls/fsopen/.gitignore<br>
@@ -0,0 +1,2 @@<br>
+fsopen01<br>
+fsopen02<br>
diff --git a/testcases/kernel/syscalls/fsopen/Makefile b/testcases/kernel/syscalls/fsopen/Makefile<br>
new file mode 100644<br>
index 000000000000..5ea7d67db123<br>
--- /dev/null<br>
+++ b/testcases/kernel/syscalls/fsopen/Makefile<br>
@@ -0,0 +1,6 @@<br>
+# SPDX-License-Identifier: GPL-2.0-or-later<br>
+<br>
+top_srcdir ?= ../../../..<br>
+<br>
+include $(top_srcdir)/include/mk/<a href="http://testcases.mk" rel="noreferrer" target="_blank">testcases.mk</a><br>
+include $(top_srcdir)/include/mk/<a href="http://generic_leaf_target.mk" rel="noreferrer" target="_blank">generic_leaf_target.mk</a><br>
diff --git a/testcases/kernel/syscalls/fsopen/fsopen01.c b/testcases/kernel/syscalls/fsopen/fsopen01.c<br>
new file mode 100644<br>
index 000000000000..3587c67636ea<br>
--- /dev/null<br>
+++ b/testcases/kernel/syscalls/fsopen/fsopen01.c<br>
@@ -0,0 +1,71 @@<br>
+// SPDX-License-Identifier: GPL-2.0-or-later<br>
+/*<br>
+ * Copyright (c) 2020 Viresh Kumar <<a href="mailto:viresh.kumar@linaro.org" target="_blank">viresh.kumar@linaro.org</a>><br>
+ *<br>
+ * Description:<br>
+ * Basic fsopen() test which tries to configure and mount the filesystem as<br>
+ * well.<br>
+ */<br>
+#include "tst_test.h"<br>
+#include "lapi/fsmount.h"<br>
+<br>
+#define MNTPOINT "mntpoint"<br>
+<br>
+static void run(void)<br>
+{<br>
+ int fd, fsmfd;<br>
+<br>
+ TEST(fsopen(tst_device->fs_type, 0));<br>
+ fd = TST_RET;<br>
+<br>
+ if (fd == -1)<br>
+ tst_brk(TFAIL | TERRNO, "fsopen() failed");<br>
+<br>
+ TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));<br>
+ if (TST_RET == -1) {<br>
+ tst_res(TBROK | TERRNO, "fsconfig() failed");<br>
+ goto out;<br>
+ }<br>
+<br>
+ TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));<br>
+ if (TST_RET == -1) {<br>
+ tst_res(TBROK | TERRNO, "fsconfig() failed");<br>
+ goto out;<br>
+ }<br>
+<br>
+ TEST(fsmount(fd, 0, 0));<br>
+ if (TST_RET == -1) {<br>
+ tst_res(TBROK | TERRNO, "fsmount() failed");<br>
+ goto out;<br>
+ }<br>
+<br>
+ fsmfd = TST_RET;<br>
+<br>
+ TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,<br>
+ MOVE_MOUNT_F_EMPTY_PATH));<br>
+<br>
+ SAFE_CLOSE(fsmfd);<br>
+<br>
+ if (TST_RET == -1) {<br>
+ tst_res(TBROK | TERRNO, "move_mount() failed");<br>
+ goto out;<br>
+ }<br>
+<br>
+ SAFE_CLOSE(TST_RET);<br>
+<br>
+ TEST(umount(MNTPOINT));<br>
+<br>
+ tst_res(TPASS, "fsopen() passed");<br>
+<br>
+out:<br>
+ SAFE_CLOSE(fd);<br>
+}<br>
+<br>
+static struct tst_test test = {<br>
+ .min_kver = "5.2",<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">I suggest removing .min_kver check in all of the tests to let they can be running on many distributions(which backport the features).</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ .test_all = run,<br>
+ .needs_root = 1,<br>
+ .needs_tmpdir = 1,<br></blockquote><div> </div><div><span class="gmail_default" style="font-size:small">.needs_tmpdir is not necessary because tst_test->mntpoint helps create that too.</span></div><div><span class="gmail_default" style="font-size:small"></span> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ .format_device = 1,<br>
+ .mntpoint = MNTPOINT,<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Maybe to test more filesystems and skip on FUSE? Just like the way in zlang@'s patch.</div><br></div><div class="gmail_default" style="font-size:small">+ .all_filesystems = 1,</div><div class="gmail_default" style="font-size:small">+ .dev_fs_flags = TST_FS_SKIP_FUSE,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+};<br>
diff --git a/testcases/kernel/syscalls/fsopen/fsopen02.c b/testcases/kernel/syscalls/fsopen/fsopen02.c<br>
new file mode 100644<br>
index 000000000000..6831a12c696b<br>
--- /dev/null<br>
+++ b/testcases/kernel/syscalls/fsopen/fsopen02.c<br>
@@ -0,0 +1,56 @@<br>
+// SPDX-License-Identifier: GPL-2.0-or-later<br>
+/*<br>
+ * Copyright (c) 2020 Viresh Kumar <<a href="mailto:viresh.kumar@linaro.org" target="_blank">viresh.kumar@linaro.org</a>><br>
+ *<br>
+ * Description:<br>
+ * Basic fsopen() failure tests.<br>
+ */<br>
+#include "tst_test.h"<br>
+#include "lapi/fsmount.h"<br>
+<br>
+const char *invalid_fs = "invalid";<br>
+const char *valid_fs;<br>
+<br>
+static struct tcase {<br>
+ char *name;<br>
+ const char **fs;<br>
+ unsigned int flags;<br>
+ int exp_errno;<br>
+} tcases[] = {<br>
+ {"invalid-fs", &invalid_fs, 0, ENODEV},<br>
+ {"invalid-flags", &valid_fs, 0x10, EINVAL},<br>
+};<br>
+<br>
+static void setup(void)<br>
+{<br>
+ valid_fs = tst_device->fs_type;<br>
+}<br>
+<br>
+static void run(unsigned int n)<br>
+{<br>
+ struct tcase *tc = &tcases[n];<br>
+<br>
+ TEST(fsopen(*tc->fs, tc->flags));<br>
+<br>
+ if (TST_RET != -1) {<br>
+ SAFE_CLOSE(TST_RET);<br>
+ tst_brk(TFAIL, "%s: fsopen() succeeded unexpectedly (index: %d)",<br>
+ tc->name, n);<br>
+ }<br>
+<br>
+ if (tc->exp_errno != TST_ERR) {<br>
+ tst_brk(TFAIL | TTERRNO, "%s: fsopen() should fail with %s",<br>
+ tc->name, tst_strerrno(tc->exp_errno));<br>
+ }<br>
+<br>
+ tst_res(TPASS | TTERRNO, "%s: fsopen() failed as expected", tc->name);<br>
+}<br>
+<br>
+static struct tst_test test = {<br>
+ .min_kver = "5.2",<br></blockquote><div> </div><div><span class="gmail_default" style="font-size:small">To delete .min_kver.</span></div><div><span class="gmail_default"></span> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ .tcnt = ARRAY_SIZE(tcases),<br>
+ .test = run,<br>
+ .setup = setup,<br>
+ .needs_root = 1,<br>
+ .needs_device = 1,<br>
+};<br>
-- <br>
2.21.0.rc0.269.g1a574e7a288b<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>