Add new LTP tests related to fsmount family of syscalls
v6 cover Add new LTP tests related to fsmount family of syscalls
Hello,
Here is the sixth version of these patches. This is tested on both ARM and X86 platforms now and no more errors are seen with it.
V5->V6:
- A new implementation of tst_is_mounted() and a new helper tst_is_mounted_at_tmpdir().
- Add cleanup() callback in fsconfig01.c
- Call umount() only if tst_is_mounted_at_tmpdir() passes.
- Call close() in fsopen_supported_by_kernel().
- Use /dev/foo instead of /dev/sda1
V4->V5:
- s/TBROK/TFAIL/ in run(int n) callbacks.
- Many conversions like TEST(fd = fsopen());
- A new implementation of tst_is_mounted().
- fspick.h created to take care of duplicate code.
- tmp directory not removed from code as that will be auto done anyway.
- Other minor improvements.
V3->V4:
- Only the first patch was resent after fixing git log and minor code modifications.
V2->V3:
- Fix errors with xfs.
- Add macros to define test names.
- Continue with multiple iteration tests on failures, instead of returning early.
- Set value of is_mounted in open_tree patch.
- Rename tst_ismount() and make it return 1 on success.
- Fix various formatting issues.
- Add all reviewed/ack tags.
V1->V2:
- Lots of changes, really :)
- Rebased over Zorro's work with fsmount.
- The success tests are modified to test all possible flags, attributes as well.
- Create tst_ismount() and fsopen_supported_by_kernel() helpers.
- Verify if mount is successful or not using tst_ismount().
- Remove min_kver and instead check if older kernels have patches backported or not.
- Test on multiple filesystems.
- Better handling of failures during setup/run callbacks.
- One of the patches around fsmount.h is already merged, dropped it now.
- Other minor cleanups.
Viresh Kumar (10):
tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir()
helpers
lapi/fsmount.h: Add fsopen_supported_by_kernel() lapi/fsmount.h: Include "lapi/fcntl.h" syscalls/fsopen: New tests
syscalls/fsconfig: New tests
syscalls/fsmount: Improve fsmount01 test syscalls/fsmount: Add failure tests syscalls/move_mount: New tests
syscalls/fspick: New tests
syscalls/open_tree: New tests
include/lapi/fsmount.h | 13 +- include/tst_device.h | 7 + lib/tst_device.c | 44 +++++++ runtest/syscalls | 16 +++ testcases/kernel/syscalls/fsconfig/.gitignore | 2 + testcases/kernel/syscalls/fsconfig/Makefile | 6 + .../kernel/syscalls/fsconfig/fsconfig01.c | 91 +++++++++++++ .../kernel/syscalls/fsconfig/fsconfig02.c | 99 ++++++++++++++ testcases/kernel/syscalls/fsmount/.gitignore | 1 + testcases/kernel/syscalls/fsmount/fsmount01.c | 121 +++++++++--------- testcases/kernel/syscalls/fsmount/fsmount02.c | 80 ++++++++++++ testcases/kernel/syscalls/fsopen/.gitignore | 2 + testcases/kernel/syscalls/fsopen/Makefile | 6 + testcases/kernel/syscalls/fsopen/fsopen01.c | 80 ++++++++++++ testcases/kernel/syscalls/fsopen/fsopen02.c | 58 +++++++++ testcases/kernel/syscalls/fspick/.gitignore | 2 + testcases/kernel/syscalls/fspick/Makefile | 6 + testcases/kernel/syscalls/fspick/fspick.h | 60 +++++++++ testcases/kernel/syscalls/fspick/fspick01.c | 62 +++++++++ testcases/kernel/syscalls/fspick/fspick02.c | 54 ++++++++ .../kernel/syscalls/move_mount/.gitignore | 2 + testcases/kernel/syscalls/move_mount/Makefile | 6 + .../kernel/syscalls/move_mount/move_mount01.c | 83 ++++++++++++ .../kernel/syscalls/move_mount/move_mount02.c | 92 +++++++++++++ .../kernel/syscalls/open_tree/.gitignore | 2 + testcases/kernel/syscalls/open_tree/Makefile | 6 + .../kernel/syscalls/open_tree/open_tree01.c | 109 ++++++++++++++++ .../kernel/syscalls/open_tree/open_tree02.c | 105 +++++++++++++++ 28 files changed, 1155 insertions(+), 60 deletions(-) create mode 100644 testcases/kernel/syscalls/fsconfig/.gitignore create mode 100644 testcases/kernel/syscalls/fsconfig/Makefile create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig01.c create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig02.c create mode 100644 testcases/kernel/syscalls/fsmount/fsmount02.c create mode 100644 testcases/kernel/syscalls/fsopen/.gitignore create mode 100644 testcases/kernel/syscalls/fsopen/Makefile create mode 100644 testcases/kernel/syscalls/fsopen/fsopen01.c create mode 100644 testcases/kernel/syscalls/fsopen/fsopen02.c create mode 100644 testcases/kernel/syscalls/fspick/.gitignore create mode 100644 testcases/kernel/syscalls/fspick/Makefile create mode 100644 testcases/kernel/syscalls/fspick/fspick.h create mode 100644 testcases/kernel/syscalls/fspick/fspick01.c create mode 100644 testcases/kernel/syscalls/fspick/fspick02.c create mode 100644 testcases/kernel/syscalls/move_mount/.gitignore create mode 100644 testcases/kernel/syscalls/move_mount/Makefile create mode 100644 testcases/kernel/syscalls/move_mount/move_mount01.c create mode 100644 testcases/kernel/syscalls/move_mount/move_mount02.c create mode 100644 testcases/kernel/syscalls/open_tree/.gitignore create mode 100644 testcases/kernel/syscalls/open_tree/Makefile create mode 100644 testcases/kernel/syscalls/open_tree/open_tree01.c create mode 100644 testcases/kernel/syscalls/open_tree/open_tree02.c
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 1/10 tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir() helpers
This patch moves the ismount() helper added to the fsmount syscall tests to the standard library and renames it to tst_is_mounted() and also adds a new helper tst_is_mounted_at_tmpdir(). These helpers can be used across different files now.
Minor modifications are also done to the helper.
--- include/tst_device.h | 7 +++ lib/tst_device.c | 44 +++++++++++++++++++ testcases/kernel/syscalls/fsmount/fsmount01.c | 25 +---------- 3 files changed, 52 insertions(+), 24 deletions(-)
include/tst_device.h +7 -0
@@ -24,6 +24,13 @@ extern struct tst_device *tst_device;*/ int tst_umount (const char *path); +/* +* Verifies if an earlier mount is successful or not. +* @path: Mount path to verify +*/ +int tst_is_mounted (const char *path); +int tst_is_mounted_at_tmpdir (const char *path); +/* * Clears a first few blocks of the device. This is needed when device has * already been formatted with a filesystems, subset of mkfs.foo utils aborts
lib/tst_device.c +44 -0
50 lines not on this page · raw message
testcases/kernel/syscalls/fsmount/fsmount01.c +1 -24
@@ -12,30 +12,10 @@#include "tst_test.h" #include "lapi/fcntl.h" #include "lapi/fsmount.h" -#include "tst_safe_stdio.h" -#define LINELENGTH 256#define MNTPOINT "newmount_point"static int sfd, mfd, is_mounted; -static int ismount (char *mntpoint) -{ -int ret =0 ; -FILE *file; -char line[LINELENGTH ]; - - file =SAFE_FOPEN ("/proc/mounts" ,"r" ); - -while (fgets (line,sizeof (line), file)) { -if (strstr (line, mntpoint) !=NULL ) { - ret =1 ; -break ; - } - } -SAFE_FCLOSE (file); -return ret; -} -static void cleanup (void ) {if (is_mounted)
@@ -76,12 +56,9 @@ static void test_fsmount(void)tst_res (TPASS ,"move_mount() attached to the mount point" );SAFE_CLOSE (mfd); -if (ismount (MNTPOINT )) { -tst_res (TPASS ,"device mounted" ); +if (tst_is_mounted_at_tmpdir (MNTPOINT )) {SAFE_UMOUNT (MNTPOINT ); is_mounted =0 ; - }else { -tst_res (TFAIL ,"device not mounted" ); } }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 2/10 lapi/fsmount.h: Add fsopen_supported_by_kernel()
In reply to Viresh KumarAdd a helper to check if the fsmount() related syscalls are supported by the kernel or not.
--- include/lapi/fsmount.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/lapi/fsmount.h +11 -0
@@ -130,5 +130,16 @@ enum fsconfig_command {#endif /* OPEN_TREE_CLONE */ +void fsopen_supported_by_kernel (void ) +{ +if ((tst_kvercmp (5 ,2 ,0 )) <0 ) { +/* Check if the syscall is backported on an older kernel */ +TEST (syscall (__NR_fsopen,NULL ,0 )); +if (TST_RET !=-1 ) +SAFE_CLOSE (TST_RET ); +else if (TST_ERR ==ENOSYS ) +tst_brk (TCONF ,"Test not supported on kernel version < v5.2" ); + } +}#endif /* FSMOUNT_H__ */
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 3/10 lapi/fsmount.h: Include "lapi/fcntl.h"
In reply to Viresh KumarAll the files that include (and that will include it in future) are most probably going to need the definitions from "lapi/fcntl.h", include it directly instead of <fcntl.h>, which will break it for old RHL distros.
--- include/lapi/fsmount.h | 2 +- testcases/kernel/syscalls/fsmount/fsmount01.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
include/lapi/fsmount.h +1 -1
@@ -7,12 +7,12 @@#ifndef FSMOUNT_H__ #define FSMOUNT_H__ -#include <fcntl.h> #include <sys/mount.h> #include <sys/syscall.h> #include <sys/types.h> #include "config.h" +#include "lapi/fcntl.h" #include "lapi/syscalls.h" #ifndef HAVE_FSOPEN
testcases/kernel/syscalls/fsmount/fsmount01.c +0 -1
@@ -10,7 +10,6 @@#include <sys/mount.h> #include "tst_test.h" -#include "lapi/fcntl.h" #include "lapi/fsmount.h" #define MNTPOINT "newmount_point"
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 4/10 syscalls/fsopen: New tests
In reply to Viresh KumarAdd tests to check working of fsopen() syscall.
--- runtest/syscalls | 3 + testcases/kernel/syscalls/fsopen/.gitignore | 2 + testcases/kernel/syscalls/fsopen/Makefile | 6 ++ testcases/kernel/syscalls/fsopen/fsopen01.c | 80 +++++++++++++++++++++ testcases/kernel/syscalls/fsopen/fsopen02.c | 58 +++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 testcases/kernel/syscalls/fsopen/.gitignore create mode 100644 testcases/kernel/syscalls/fsopen/Makefile create mode 100644 testcases/kernel/syscalls/fsopen/fsopen01.c create mode 100644 testcases/kernel/syscalls/fsopen/fsopen02.c
runtest/syscalls +3 -0
@@ -344,6 +344,9 @@ fremovexattr02 fremovexattr02 fsmount01 fsmount01 +fsopen01 fsopen01 +fsopen02 fsopen02 + fstat02 fstat02 fstat02_64 fstat02_64 fstat03 fstat03
testcases/kernel/syscalls/fsopen/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/fsopen01 +/fsopen02
testcases/kernel/syscalls/fsopen/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/fsopen/fsopen01.c new file +80 -0
80 lines not on this page · raw message
testcases/kernel/syscalls/fsopen/fsopen02.c new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 5/10 syscalls/fsconfig: New tests
In reply to Viresh KumarAdd tests to check working of fsconfig() syscall.
--- runtest/syscalls | 3 + testcases/kernel/syscalls/fsconfig/.gitignore | 2 + testcases/kernel/syscalls/fsconfig/Makefile | 6 ++ .../kernel/syscalls/fsconfig/fsconfig01.c | 91 +++++++++++++++++ .../kernel/syscalls/fsconfig/fsconfig02.c | 99 +++++++++++++++++++ 5 files changed, 201 insertions(+) create mode 100644 testcases/kernel/syscalls/fsconfig/.gitignore create mode 100644 testcases/kernel/syscalls/fsconfig/Makefile create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig01.c create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig02.c
runtest/syscalls +3 -0
@@ -342,6 +342,9 @@ fpathconf01 fpathconf01 fremovexattr01 fremovexattr01 fremovexattr02 fremovexattr02 +fsconfig01 fsconfig01 +fsconfig02 fsconfig02 + fsmount01 fsmount01 fsopen01 fsopen01
testcases/kernel/syscalls/fsconfig/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/fsconfig01 +/fsconfig02
testcases/kernel/syscalls/fsconfig/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/fsconfig/fsconfig01.c new file +91 -0
91 lines not on this page · raw message
testcases/kernel/syscalls/fsconfig/fsconfig02.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 5/10 syscalls/fsconfig: New tests
Hi!
Pushed with two minor changes:
testcases/kernel/syscalls/fsconfig/fsconfig01.c +2 -0
@@ -77,6 +77,8 @@ static void run(void)SAFE_UMOUNT (MNTPOINT );tst_res (TPASS ,"fsconfig() passed" ); } + +SAFE_CLOSE (fd); }
We need to close the fd here, because the test will run out of file descriptors for large enough -i parameter, since cleanup is executed only at the test end. Also note that SAFE_CLOSE() sets the fd to -1 so that cleanup is no-op unless we trigger some of the tst_brk() statements.
static struct tst_test test = {
testcases/kernel/syscalls/fsconfig/fsconfig02.c +1 -0
@@ -94,6 +94,7 @@ static struct tst_test test = { .test = run, .setup = setup, .cleanup = cleanup, + .needs_tmpdir = 1, .needs_root = 1, .needs_device = 1, };
The test creates a file hence it has to request temporary directory.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v6 5/10 syscalls/fsconfig: New tests
testcases/kernel/syscalls/fsconfig/fsconfig01.c static void run(void) · line 81
Quoted 13 lines · Cyril Hrubis
Hi!
Pushed with two minor changes:testcases/kernel/syscalls/fsconfig/fsconfig01.c +2
-0@@ -77,6 +77,8 @@ static void run(void)SAFE_UMOUNT (MNTPOINT );tst_res (TPASS ,"fsconfig() passed" ); } + +SAFE_CLOSE (fd);
This isn't required as cleanup() routine is taking care of it and this is a test_all type test.
Quoted 14 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c +0
-0}We need to close the fd here, because the test will run out of file descriptors for large enough -i parameter, since cleanup is executed only at the test end. Also note that
SAFE_CLOSE()sets the fd to -1 so that cleanup is no-op unless we trigger some of thetst_brk()statements.static struct
tst_testtest = {testcases/kernel/syscalls/fsconfig/fsconfig02.c +0
-0
testcases/kernel/syscalls/fsconfig/fsconfig02.c static struct tst_test test = { · line 97
Quoted 4 lines
testcases/kernel/syscalls/fsconfig/fsconfig02.c +1
-0@@ -94,6 +94,7 @@ static struct tst_test test = { .test = run, .setup = setup, .cleanup = cleanup, + .needs_tmpdir = 1,
I probably didn't add this as we weren't mounting anything here.
Quoted 9 lines
testcases/kernel/syscalls/fsconfig/fsconfig02.c +0
-0.needs_root = 1, .needs_device = 1, };The test creates a file hence it has to request temporary directory.
Signature · 2 lines
Cyril Hrubis [email protected]
Signature · 1 line
viresh
PATCH v6 5/10 syscalls/fsconfig: New tests
Hi,
Quoted 17 lines · Cyril Hrubis
testcases/kernel/syscalls/fsconfig/fsconfig01.c static void run(void) · line 81
Quoted 13 lines
Hi!
Pushed with two minor changes:testcases/kernel/syscalls/fsconfig/fsconfig01.c +2
-0@@ -77,6 +77,8 @@ static void run(void)SAFE_UMOUNT (MNTPOINT );tst_res (TPASS ,"fsconfig() passed" ); } + +SAFE_CLOSE (fd);This isn't required as
cleanup()routine is taking care of it and this is atest_alltype test.
+1.
Quoted 8 lines
Quoted 7 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c +0
-0}We need to close the fd here, because the test will run out of file descriptors for large enough -i parameter, since cleanup is executed only at the test end. Also note that
SAFE_CLOSE()sets the fd to -1 so that cleanup is no-op unless we trigger some of thetst_brk()statements.
Quoted 18 lines
testcases/kernel/syscalls/fsconfig/fsconfig02.c static struct tst_test test = { · line 97
Quoted 10 lines
static struct
tst_testtest = {testcases/kernel/syscalls/fsconfig/fsconfig02.c +1
-0@@ -94,6 +94,7 @@ static struct tst_test test = { .test = run, .setup = setup, .cleanup = cleanup, + .needs_tmpdir = 1,I probably didn't add this as we weren't mounting anything here.
Quoted 5 lines
testcases/kernel/syscalls/fsconfig/fsconfig02.c +0
-0.needs_root = 1, .needs_device = 1, };The test creates a file hence it has to request temporary directory.
Well, tmp dir would be created anyway due .needs_device, see lib/tst_test.c static int needs_tmpdir(void)
{
return tst_test->needs_tmpdir ||
tst_test->needs_device ||
tst_test->mntpoint ||
tst_test->resource_files ||
tst_test->needs_checkpoints;
}But true it not required to be added as .needs_device implies needs_tmpdir, see dae842774 ("Remove duplicated ".needs_tmpdir=1" when using equivalent flags"). But just a minor detail.
Kind regards,
Petr
PATCH v6 5/10 syscalls/fsconfig: New tests
In reply to Viresh KumarHi!
Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c +0
-0@@ -77,6 +77,8 @@ static void run(void)
Quoted 8 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c static void run(void) · line 81
Quoted 5 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c +2
-0SAFE_UMOUNT (MNTPOINT );tst_res (TPASS ,"fsconfig() passed" ); } + +SAFE_CLOSE (fd);This isn't required as
cleanup()routine is taking care of it and this is atest_alltype test.
It _is_, I've tried top explain in the paragraph below, just run the test with large enough -i, sooner or late the test will run out of file descriptiors and then it will fail.
The key here is that the run() function can be called repeatedly but setup() and cleanup() are called only once at the start and at the end of the test.
Quoted 5 lines
Quoted 5 lines
We need to close the fd here, because the test will run out of file descriptors for large enough -i parameter, since cleanup is executed only at the test end. Also note that
SAFE_CLOSE()sets the fd to -1 so that cleanup is no-op unless we trigger some of thetst_brk()statements.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v6 5/10 syscalls/fsconfig: New tests
Quoted 15 lines · Cyril Hrubis
Hi!
Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c +0
-0@@ -77,6 +77,8 @@ static void run(void)Quoted 8 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c static void run(void) · line 81
Quoted 5 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c +2
-0SAFE_UMOUNT (MNTPOINT );tst_res (TPASS ,"fsconfig() passed" ); } + +SAFE_CLOSE (fd);This isn't required as
cleanup()routine is taking care of it and this is atest_alltype test.
Quoted 7 lines
It _is_, I've tried top explain in the paragraph below, just run the test with large enough -i, sooner or late the test will run out of file descriptiors and then it will fail.
The key here is that the
run()function can be called repeatedly butsetup()andcleanup()are called only once at the start and at the end of the test.
I didn't knew about the -i option, yeah your change makes sense now :)
Signature · 1 line
viresh
PATCH v6 5/10 syscalls/fsconfig: New tests
Hi Viresh,
Quoted 1 line
I didn't knew about the -i option, yeah your change makes sense now :)
NOTE: all test (both C and shell) should support -h (inherited from the library), to display options.
Kind regards,
Petr
PATCH v6 5/10 syscalls/fsconfig: New tests
Quoted 5 lines · Petr Vorel
Hi Viresh,
Quoted 1 line
I didn't knew about the -i option, yeah your change makes sense now :)
NOTE: all test (both C and shell) should support -h (inherited from the library), to display options.
I didn't thought about that as well earlier, but then tried -h option with the executable earlier before your mail came and it worked. So I assume I don't have to do anything special to support the -h option as it is already working fine right now ?
Signature · 1 line
viresh
PATCH v6 5/10 syscalls/fsconfig: New tests
Hi Viresh,
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I didn't knew about the -i option, yeah your change makes sense now :)
NOTE: all test (both C and shell) should support -h (inherited from the library), to display options.
I didn't thought about that as well earlier, but then tried -h option with the executable earlier before your mail came and it worked. So I assume I don't have to do anything special to support the -h option as it is already working fine right now ?
Yes, that's automatically done by library (a nice feature of new C library API). See parse_opts() in lib/tst_test.c. And even better: you can very easily extend it, see 2.2.5 Test specific command line options [1].
Cyril also recently described LTP library model in his blog [3].
We were thinking to separate the library so it can be reused in other projects (similarly like kernel's kconfig is used in other projects). But it'd be good first to rewrite all tests which uses legacy API, which allows remove legacy API itself.
BTW We also try to keep shell API to be similar to C API (when possible), therefore getopt support it's there as well, see 2.3.3 Optional command line parameters [2].
Kind regards,
Petr
[1] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#225-test-specific-command-line-options
[2] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#233-optional-command-line-parameters
[3] https://people.kernel.org/metan/the-ltp-test-driver-model
PATCH v6 5/10 syscalls/fsconfig: New tests
In reply to Viresh KumarHi Viresh,
testcases/kernel/syscalls/fsconfig/fsconfig01.c line 27
Quoted 3 lines
testcases/kernel/syscalls/fsconfig/fsconfig01.c new file +3
-0+TEST (fd =fsopen (tst_device->fs_type,0 )); +if (fd ==-1 ) +tst_brk (TBROK |TERRNO ,"fsopen() failed" );
Just a note all these tst_brk/tst_res after TEST() should use TTERRNO, not TERRNO. Although TERRNO will probably work in this case as well, it'd be better to use TTERRNO (see lib/tst_res.c).
Kind regards,
Petr
PATCH v6 6/10 syscalls/fsmount: Improve fsmount01 test
In reply to Viresh KumarThis patch updates the fsmount01.c file to make it look similar to all other fsmount related syscall tests and here is the list of all changes:
- Test all fsmount flags and mount attributes
- Remove extra PASS messages as all we want to test here is fsmount() and not other syscalls.
- On the same lines, print TFAIL for fsmount() syscall and TBROK for other calls.
- close sfd on failures
- Make the file look similar to other fsmount related tests
- General cleanup
--- testcases/kernel/syscalls/fsmount/fsmount01.c | 99 ++++++++++++------- 1 file changed, 63 insertions(+), 36 deletions(-)
testcases/kernel/syscalls/fsmount/fsmount01.c +63 -36
@@ -3,67 +3,94 @@* Copyright (C) 2020 Red Hat, Inc. All rights reserved. * Author: Zorro Lang <[email protected]> * -* Use new mount API from v5.2 (fsopen(), fsconfig(), fsmount(), move_mount()) -* to mount a filesystem without any specified mount options. +* Basic fsmount() test. */ -#include <sys/mount.h> -#include "tst_test.h" #include "lapi/fsmount.h" -#define MNTPOINT "newmount_point" -static int sfd, mfd, is_mounted; +#define MNTPOINT "mntpoint" -static void cleanup (void ) -{ -if (is_mounted) -SAFE_UMOUNT (MNTPOINT ); -} +#define TCASE_ENTRY (_flags, _attrs) {.name = "Flag " #_flags ", Attr " #_attrs, .flags = _flags, .attrs = _attrs} -static void test_fsmount (void ) +static struct tcase { +char *name; +unsigned int flags; +unsigned int attrs; +} tcases[] = { +TCASE_ENTRY (0 ,MOUNT_ATTR_RDONLY ), +TCASE_ENTRY (0 ,MOUNT_ATTR_NOSUID ), +TCASE_ENTRY (0 ,MOUNT_ATTR_NODEV ), +TCASE_ENTRY (0 ,MOUNT_ATTR_NOEXEC ), +TCASE_ENTRY (0 ,MOUNT_ATTR_RELATIME ), +TCASE_ENTRY (0 ,MOUNT_ATTR_NOATIME ), +TCASE_ENTRY (0 ,MOUNT_ATTR_STRICTATIME ), +TCASE_ENTRY (0 ,MOUNT_ATTR_NODIRATIME ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_RDONLY ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_NOSUID ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_NODEV ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_NOEXEC ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_RELATIME ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_NOATIME ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_STRICTATIME ), +TCASE_ENTRY (FSMOUNT_CLOEXEC ,MOUNT_ATTR_NODIRATIME ), +}; + +static void run (unsigned int n) { -TEST (fsopen (tst_device->fs_type,FSOPEN_CLOEXEC )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"fsopen() on %s failed" , tst_device->fs_type); - sfd =TST_RET ; -tst_res (TPASS ,"fsopen() on %s" , tst_device->fs_type); +struct tcase *tc = &tcases[n]; +int sfd, mfd; + +TEST (sfd =fsopen (tst_device->fs_type,FSOPEN_CLOEXEC )); +if (sfd ==-1 ) { +tst_res (TFAIL |TTERRNO ,"fsopen() on %s failed" , + tst_device->fs_type); +return ; + }TEST (fsconfig (sfd,FSCONFIG_SET_STRING ,"source" , tst_device->dev,0 )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO , +if (TST_RET ==-1 ) { +SAFE_CLOSE (sfd); +tst_res (TFAIL |TTERRNO ,"fsconfig() failed to set source to %s" , tst_device->dev); -tst_res (TPASS ,"fsconfig() set source to %s" , tst_device->dev); - +return ; + }TEST (fsconfig (sfd,FSCONFIG_CMD_CREATE ,NULL ,NULL ,0 )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"fsconfig() created superblock" ); -tst_res (TPASS ,"fsconfig() created superblock" ); +if (TST_RET ==-1 ) { +SAFE_CLOSE (sfd); +tst_res (TFAIL |TTERRNO ,"fsconfig() created superblock" ); +return ; + } -TEST (fsmount (sfd,FSMOUNT_CLOEXEC ,0 )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"fsmount() failed to create a mount object" ); - mfd =TST_RET ; -tst_res (TPASS ,"fsmount() created a mount object" ); +TEST (mfd =fsmount (sfd, tc->flags, tc->attrs));SAFE_CLOSE (sfd); +if (mfd ==-1 ) { +tst_res (TFAIL |TTERRNO , +"fsmount() failed to create a mount object" ); +return ; + } +TEST (move_mount (mfd,"" ,AT_FDCWD ,MNTPOINT ,MOVE_MOUNT_F_EMPTY_PATH )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"move_mount() failed to attach to the mount point" ); - is_mounted =1 ; -tst_res (TPASS ,"move_mount() attached to the mount point" );SAFE_CLOSE (mfd); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO , +"move_mount() failed to attach to the mount point" ); +return ; + } +if (tst_is_mounted_at_tmpdir (MNTPOINT )) {SAFE_UMOUNT (MNTPOINT ); - is_mounted =0 ; +tst_res (TPASS ,"%s: fsmount() passed" , tc->name); } }static struct tst_test test = { - .test_all = test_fsmount, - .cleanup = cleanup, + .tcnt =ARRAY_SIZE (tcases), + .test = run, + .setup = fsopen_supported_by_kernel, .needs_root =1 , .mntpoint =MNTPOINT , .format_device =1 ,
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 7/10 syscalls/fsmount: Add failure tests
In reply to Viresh KumarThis adds fsmount02.c tests to verify all the errors returned on failures.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/fsmount/.gitignore | 1 + testcases/kernel/syscalls/fsmount/fsmount02.c | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 testcases/kernel/syscalls/fsmount/fsmount02.c
runtest/syscalls +1 -0
@@ -346,6 +346,7 @@ fsconfig01 fsconfig01 fsconfig02 fsconfig02 fsmount01 fsmount01 +fsmount02 fsmount02 fsopen01 fsopen01 fsopen02 fsopen02
testcases/kernel/syscalls/fsmount/.gitignore +1 -0
@@ -1 +1,2 @@ /fsmount01 +/fsmount02
testcases/kernel/syscalls/fsmount/fsmount02.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 8/10 syscalls/move_mount: New tests
In reply to Viresh KumarAdd tests to check working of move_mount() syscall.
--- runtest/syscalls | 3 + .../kernel/syscalls/move_mount/.gitignore | 2 + testcases/kernel/syscalls/move_mount/Makefile | 6 ++ .../kernel/syscalls/move_mount/move_mount01.c | 83 +++++++++++++++++ .../kernel/syscalls/move_mount/move_mount02.c | 92 +++++++++++++++++++ 5 files changed, 186 insertions(+) create mode 100644 testcases/kernel/syscalls/move_mount/.gitignore create mode 100644 testcases/kernel/syscalls/move_mount/Makefile create mode 100644 testcases/kernel/syscalls/move_mount/move_mount01.c create mode 100644 testcases/kernel/syscalls/move_mount/move_mount02.c
runtest/syscalls +3 -0
@@ -734,6 +734,9 @@ mount04 mount04 mount05 mount05 mount06 mount06 +move_mount01 move_mount01 +move_mount02 move_mount02 + move_pages01 move_pages01 move_pages02 move_pages02 move_pages03 move_pages03
testcases/kernel/syscalls/move_mount/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/move_mount01 +/move_mount02
testcases/kernel/syscalls/move_mount/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/move_mount/move_mount01.c new file +83 -0
83 lines not on this page · raw message
testcases/kernel/syscalls/move_mount/move_mount02.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 8/10 syscalls/move_mount: New tests
Hi!
I've reviewed and pushed the patchset up to this patch, I will finish the remaning ones tomorrow.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v6 9/10 syscalls/fspick: New tests
In reply to Viresh KumarAdd tests to check working of fspick() syscall.
--- runtest/syscalls | 3 + testcases/kernel/syscalls/fspick/.gitignore | 2 + testcases/kernel/syscalls/fspick/Makefile | 6 ++ testcases/kernel/syscalls/fspick/fspick.h | 60 ++++++++++++++++++++ testcases/kernel/syscalls/fspick/fspick01.c | 62 +++++++++++++++++++++ testcases/kernel/syscalls/fspick/fspick02.c | 54 ++++++++++++++++++ 6 files changed, 187 insertions(+) create mode 100644 testcases/kernel/syscalls/fspick/.gitignore create mode 100644 testcases/kernel/syscalls/fspick/Makefile create mode 100644 testcases/kernel/syscalls/fspick/fspick.h create mode 100644 testcases/kernel/syscalls/fspick/fspick01.c create mode 100644 testcases/kernel/syscalls/fspick/fspick02.c
runtest/syscalls +3 -0
@@ -351,6 +351,9 @@ fsmount02 fsmount02 fsopen01 fsopen01 fsopen02 fsopen02 +fspick01 fspick01 +fspick02 fspick02 + fstat02 fstat02 fstat02_64 fstat02_64 fstat03 fstat03
testcases/kernel/syscalls/fspick/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/fspick01 +/fspick02
testcases/kernel/syscalls/fspick/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/fspick/fspick.h new file +60 -0
60 lines not on this page · raw message
testcases/kernel/syscalls/fspick/fspick01.c new file +62 -0
62 lines not on this page · raw message
testcases/kernel/syscalls/fspick/fspick02.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 9/10 syscalls/fspick: New tests
Hi,
Quoted 1 line
Add tests to check working of
fspick()syscall.
Kind regards,
Petr
PATCH v6 9/10 syscalls/fspick: New tests
In reply to Viresh KumarHi!
Quoted 103 lines
Acked-by Li Wang <[email protected]>Signed-off-by Viresh Kumar <[email protected]>--- runtest/syscalls | 3 + testcases/kernel/syscalls/fspick/.gitignore | 2 + testcases/kernel/syscalls/fspick/Makefile | 6 ++ testcases/kernel/syscalls/fspick/fspick.h | 60 ++++++++++++++++++++ testcases/kernel/syscalls/fspick/fspick01.c | 62 +++++++++++++++++++++ testcases/kernel/syscalls/fspick/fspick02.c | 54 ++++++++++++++++++ 6 files changed, 187 insertions(+) create mode 100644 testcases/kernel/syscalls/fspick/.gitignore create mode 100644 testcases/kernel/syscalls/fspick/Makefile create mode 100644 testcases/kernel/syscalls/fspick/fspick.h create mode 100644 testcases/kernel/syscalls/fspick/fspick01.c create mode 100644 testcases/kernel/syscalls/fspick/fspick02.cruntest/syscalls +3
-0@@ -351,6 +351,9 @@ fsmount02 fsmount02 fsopen01 fsopen01 fsopen02 fsopen02 +fspick01 fspick01 +fspick02 fspick02 + fstat02 fstat02 fstat02_64 fstat02_64 fstat03 fstat03testcases/kernel/syscalls/fspick/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +/fspick01 +/fspick02testcases/kernel/syscalls/fspick/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/fspick/fspick.h new file +47
-0@@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Viresh Kumar <[email protected]> +*/ + +#ifndef FSPICK_H__ +#define FSPICK_H__ + +#define MNTPOINT "mntpoint" + +static int ismounted; + +static void cleanup (void ) +{ +if (ismounted) +SAFE_UMOUNT (MNTPOINT ); +} + +static void setup (void ) +{ +int fd, fsmfd; + +fsopen_supported_by_kernel (); + +TEST (fd =fsopen (tst_device->fs_type,0 )); +if (fd ==-1 ) +tst_brk (TBROK |TERRNO ,"fsopen() failed" ); + +TEST (fsconfig (fd,FSCONFIG_SET_STRING ,"source" , tst_device->dev,0 )); +if (TST_RET ==-1 ) { +SAFE_CLOSE (fd); +tst_brk (TBROK |TERRNO ,"fsconfig() failed" ); + } + +TEST (fsconfig (fd,FSCONFIG_CMD_CREATE ,NULL ,NULL ,0 )); +if (TST_RET ==-1 ) { +SAFE_CLOSE (fd); +tst_brk (TBROK |TERRNO ,"fsconfig() failed" ); + } + +TEST (fsmfd =fsmount (fd,0 ,0 )); +SAFE_CLOSE (fd); + +if (fsmfd ==-1 ) +tst_brk (TBROK |TERRNO ,"fsmount() failed" ); + + TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
testcases/kernel/syscalls/fspick/fspick.h line 57
Quoted 10 lines
testcases/kernel/syscalls/fspick/fspick.h new file +10
-0+ MOVE_MOUNT_F_EMPTY_PATH)); +SAFE_CLOSE (fsmfd); + +if (TST_RET ==-1 ) +tst_brk (TBROK |TERRNO ,"move_mount() failed" ); + +if (!tst_is_mounted_at_tmpdir (MNTPOINT )) +tst_brk (TBROK |TERRNO ,"device not mounted" ); + + ismounted =1 ;
I just wonder if we can set the .mount_device = 1 flag instead and omit the setup and cleanup.
Quoted 43 lines
testcases/kernel/syscalls/fspick/fspick.h new file +3
-0+} + +#endif /* FSPICK_H__ */ testcases/kernel/syscalls/fspick/fspick01.c new file +34
-0@@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Viresh Kumar <[email protected]> +* +* Basic fspick() test. +*/ +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "fspick.h" + +#define TCASE_ENTRY (_flags) {.name = "Flag " #_flags, .flags = _flags} + +static struct tcase { +char *name; +unsigned int flags; +} tcases[] = { +TCASE_ENTRY (FSPICK_CLOEXEC ), +TCASE_ENTRY (FSPICK_SYMLINK_NOFOLLOW ), +TCASE_ENTRY (FSPICK_NO_AUTOMOUNT ), +TCASE_ENTRY (FSPICK_EMPTY_PATH ), +}; + +static void run (unsigned int n) +{ +struct tcase *tc = &tcases[n]; +int fspick_fd; + +TEST (fspick_fd =fspick (AT_FDCWD ,MNTPOINT , tc->flags)); +if (fspick_fd ==-1 ) { +tst_res (TFAIL |TERRNO ,"fspick() failed" ); +return ; + } + +TEST (fsconfig (fspick_fd,FSCONFIG_SET_STRING ,"sync" ,"false" ,0 ));
testcases/kernel/syscalls/fspick/fspick01.c line 44
Quoted 10 lines
testcases/kernel/syscalls/fspick/fspick01.c new file +10
-0+if (TST_RET ==-1 ) { +tst_res (TFAIL |TERRNO ,"fsconfig() failed" ); + goto out; + } + +TEST (fsconfig (fspick_fd,FSCONFIG_SET_FLAG ,"ro" ,NULL ,0 )); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TERRNO ,"fsconfig() failed" ); + goto out; + }
I guess that we should as well call the FSCONFIG_CMD_RECONFIGURE and check that the MNTPOINT is read only, right?
Quoted 80 lines
testcases/kernel/syscalls/fspick/fspick01.c new file +17
-0+tst_res (TPASS ,"%s: fspick() passed" , tc->name); + +out: +SAFE_CLOSE (fspick_fd); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .format_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .dev_fs_flags =TST_FS_SKIP_FUSE , +};testcases/kernel/syscalls/fspick/fspick02.c new file +54
-0@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Viresh Kumar <[email protected]> +* +* Basic fspick() failure tests. +*/ +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "fspick.h" + +static struct tcase { +char *name; +int dirfd; +const char *pathname; +unsigned int flags; +int exp_errno; +} tcases[] = { + {"invalid-fd" ,-1 ,MNTPOINT ,FSPICK_NO_AUTOMOUNT |FSPICK_CLOEXEC ,EBADF }, + {"invalid-path" ,AT_FDCWD ,"invalid" ,FSPICK_NO_AUTOMOUNT |FSPICK_CLOEXEC ,ENOENT }, + {"invalid-flags" ,AT_FDCWD ,MNTPOINT ,0x10 ,EINVAL }, +}; + +static void run (unsigned int n) +{ +struct tcase *tc = &tcases[n]; + +TEST (fspick (tc->dirfd, tc->pathname, tc->flags)); +if (TST_RET !=-1 ) { +SAFE_CLOSE (TST_RET ); +tst_res (TFAIL ,"%s: fspick() succeeded unexpectedly (index: %d)" , + tc->name, n); +return ; + } + +if (tc->exp_errno !=TST_ERR ) { +tst_res (TFAIL |TTERRNO ,"%s: fspick() should fail with %s" , + tc->name,tst_strerrno (tc->exp_errno)); +return ; + } + +tst_res (TPASS |TTERRNO ,"%s: fspick() failed as expected" , tc->name); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .format_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .dev_fs_flags =TST_FS_SKIP_FUSE , +};Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v6 10/10 syscalls/open_tree: New tests
In reply to Viresh KumarAdd tests to check working of open_tree() syscall.
--- runtest/syscalls | 3 + .../kernel/syscalls/open_tree/.gitignore | 2 + testcases/kernel/syscalls/open_tree/Makefile | 6 + .../kernel/syscalls/open_tree/open_tree01.c | 109 ++++++++++++++++++ .../kernel/syscalls/open_tree/open_tree02.c | 105 +++++++++++++++++ 5 files changed, 225 insertions(+) create mode 100644 testcases/kernel/syscalls/open_tree/.gitignore create mode 100644 testcases/kernel/syscalls/open_tree/Makefile create mode 100644 testcases/kernel/syscalls/open_tree/open_tree01.c create mode 100644 testcases/kernel/syscalls/open_tree/open_tree02.c
runtest/syscalls +3 -0
@@ -847,6 +847,9 @@ openat01 openat01 openat02 openat02 openat03 openat03 +open_tree01 open_tree01 +open_tree02 open_tree02 + mincore01 mincore01 mincore02 mincore02
testcases/kernel/syscalls/open_tree/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/open_tree01 +/open_tree02
testcases/kernel/syscalls/open_tree/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/open_tree/open_tree01.c new file +109 -0
109 lines not on this page · raw message
testcases/kernel/syscalls/open_tree/open_tree02.c new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 10/10 syscalls/open_tree: New tests
Hi Viresh,
Quoted 1 line
testcases/kernel/syscalls/open_tree/open_tree01.c +0
-0
...
testcases/kernel/syscalls/open_tree/open_tree01.c line 26
Quoted 4 lines
testcases/kernel/syscalls/open_tree/open_tree01.c +4
-0+static void setup (void ) +{ +fsopen_supported_by_kernel (); +SAFE_MKDIR (OT_MNTPOINT ,0777 );
This fails, because setup (and cleanup) is run fo each filesystem. Therefore it needs to be created just once.
safe_macros.c:172: BROK: open_tree01.c:27: mkdir(ot_mntpoint,0777) failed: EEXIST (17)
Kind regards,
Petr
PATCH v7 10/10 syscalls/open_tree: New tests
In reply to Viresh KumarAdd tests to check working of open_tree() syscall.
---V6->V7:
- Remove the temporary directory from cleanup routine to avoid test failure.
runtest/syscalls | 3 + .../kernel/syscalls/open_tree/.gitignore | 2 + testcases/kernel/syscalls/open_tree/Makefile | 6 + .../kernel/syscalls/open_tree/open_tree01.c | 119 ++++++++++++++++++ .../kernel/syscalls/open_tree/open_tree02.c | 105 ++++++++++++++++ 5 files changed, 235 insertions(+) create mode 100644 testcases/kernel/syscalls/open_tree/.gitignore create mode 100644 testcases/kernel/syscalls/open_tree/Makefile create mode 100644 testcases/kernel/syscalls/open_tree/open_tree01.c create mode 100644 testcases/kernel/syscalls/open_tree/open_tree02.c
runtest/syscalls +3 -0
@@ -847,6 +847,9 @@ openat01 openat01 openat02 openat02 openat03 openat03 +open_tree01 open_tree01 +open_tree02 open_tree02 + mincore01 mincore01 mincore02 mincore02
testcases/kernel/syscalls/open_tree/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/open_tree01 +/open_tree02
testcases/kernel/syscalls/open_tree/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/open_tree/open_tree01.c new file +119 -0
119 lines not on this page · raw message
testcases/kernel/syscalls/open_tree/open_tree02.c new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v7 10/10 syscalls/open_tree: New tests
Hi Viresh,
Quoted 3 lines
V6->V7:
- Remove the temporary directory from cleanup routine to avoid test failure.
Thanks for a quick fix, merged these 2 remaining tests.
Kind regards,
Petr
PATCH v7 10/10 syscalls/open_tree: New tests
In reply to Viresh KumarHi!
Quoted 71 lines
testcases/kernel/syscalls/open_tree/Makefile new file +2
-0+include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/open_tree/open_tree01.c new file +63
-0@@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Viresh Kumar <[email protected]> +* +* Basic open_tree() test. +*/ +#include "tst_test.h" +#include "lapi/fsmount.h" + +#define MNTPOINT "mntpoint" +#define OT_MNTPOINT "ot_mntpoint" + +#define TCASE_ENTRY (_flags) {.name = "Flag " #_flags, .flags = _flags} + +static struct tcase { +char *name; +unsigned int flags; +} tcases[] = { +TCASE_ENTRY (OPEN_TREE_CLONE ), +TCASE_ENTRY (OPEN_TREE_CLOEXEC ) +}; + +static int dir_created; + +static void cleanup (void ) +{ +if (dir_created) +SAFE_RMDIR (OT_MNTPOINT ); +} + +static void setup (void ) +{ +fsopen_supported_by_kernel (); +SAFE_MKDIR (OT_MNTPOINT ,0777 ); + dir_created =1 ; +} + +static void run (unsigned int n) +{ +struct tcase *tc = &tcases[n]; +int fd, fsmfd, otfd; + +TEST (fd =fsopen (tst_device->fs_type,0 )); +if (fd ==-1 ) { +tst_res (TFAIL |TERRNO ,"fsopen() failed" ); +return ; + } + +TEST (fsconfig (fd,FSCONFIG_SET_STRING ,"source" , tst_device->dev,0 )); +if (TST_RET ==-1 ) { +SAFE_CLOSE (fd); +tst_res (TFAIL |TERRNO ,"fsconfig() failed" ); +return ; + } + +TEST (fsconfig (fd,FSCONFIG_CMD_CREATE ,NULL ,NULL ,0 )); +if (TST_RET ==-1 ) { +SAFE_CLOSE (fd); +tst_res (TFAIL |TERRNO ,"fsconfig() failed" ); +return ; + } + +TEST (fsmfd =fsmount (fd,0 ,0 ));
testcases/kernel/syscalls/open_tree/open_tree01.c line 73
Quoted 10 lines
testcases/kernel/syscalls/open_tree/open_tree01.c new file +10
-0+SAFE_CLOSE (fd); + +if (fsmfd ==-1 ) { +tst_res (TFAIL |TERRNO ,"fsmount() failed" ); +return ; + } + +TEST (move_mount (fsmfd,"" ,AT_FDCWD ,MNTPOINT , +MOVE_MOUNT_F_EMPTY_PATH )); +SAFE_CLOSE (fsmfd);
Here as well, shouldn't we just set the .mount_device flag instead?
Quoted 45 lines
testcases/kernel/syscalls/open_tree/open_tree01.c new file +45
-0+if (TST_RET ==-1 ) { +tst_res (TFAIL |TERRNO ,"move_mount() failed" ); +return ; + } + +if (!tst_is_mounted_at_tmpdir (MNTPOINT )) { +tst_res (TFAIL |TERRNO ,"device not mounted" ); +return ; + } + +TEST (otfd =open_tree (AT_FDCWD ,MNTPOINT , tc->flags |OPEN_TREE_CLONE )); +if (otfd ==-1 ) { +tst_res (TFAIL |TERRNO ,"open_tree() failed" ); + goto out; + } + +TEST (move_mount (otfd,"" ,AT_FDCWD ,OT_MNTPOINT , +MOVE_MOUNT_F_EMPTY_PATH )); +SAFE_CLOSE (otfd); + +if (TST_RET ==-1 ) { +tst_res (TFAIL |TERRNO ,"move_mount() failed" ); + goto out; + } + +if (tst_is_mounted_at_tmpdir (OT_MNTPOINT )) { +SAFE_UMOUNT (OT_MNTPOINT ); +tst_res (TPASS ,"%s: open_tree() passed" , tc->name); + } + +out: +SAFE_UMOUNT (MNTPOINT ); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .format_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .dev_fs_flags =TST_FS_SKIP_FUSE , +};
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v7 10/10 syscalls/open_tree: New tests
Hi,
Quoted 5 lines
testcases/kernel/syscalls/open_tree/open_tree01.c line 73
Quoted 3 lines
testcases/kernel/syscalls/open_tree/open_tree01.c new file +3
-0+TEST (move_mount (fsmfd,"" ,AT_FDCWD ,MNTPOINT , +MOVE_MOUNT_F_EMPTY_PATH )); +SAFE_CLOSE (fsmfd);Here as well, shouldn't we just set the .mount_device flag instead?
Sorry for overlooking these. I was too quick.
I guess metan will fix it himself.
Kind regards,
Petr
PATCH v7 10/10 syscalls/open_tree: New tests
In reply to Cyril HrubisQuoted 30 lines · Cyril Hrubis
Quoted 30 lines
testcases/kernel/syscalls/open_tree/open_tree01.c new file +30
-0+static void run (unsigned int n) +{ +struct tcase *tc = &tcases[n]; +int fd, fsmfd, otfd; + +TEST (fd =fsopen (tst_device->fs_type,0 )); +if (fd ==-1 ) { +tst_res (TFAIL |TERRNO ,"fsopen() failed" ); +return ; + } + +TEST (fsconfig (fd,FSCONFIG_SET_STRING ,"source" , tst_device->dev,0 )); +if (TST_RET ==-1 ) { +SAFE_CLOSE (fd); +tst_res (TFAIL |TERRNO ,"fsconfig() failed" ); +return ; + } + +TEST (fsconfig (fd,FSCONFIG_CMD_CREATE ,NULL ,NULL ,0 )); +if (TST_RET ==-1 ) { +SAFE_CLOSE (fd); +tst_res (TFAIL |TERRNO ,"fsconfig() failed" ); +return ; + } + +TEST (fsmfd =fsmount (fd,0 ,0 )); +SAFE_CLOSE (fd); + +if (fsmfd ==-1 ) { +tst_res (TFAIL |TERRNO ,"fsmount() failed" );
Quoted 8 lines
testcases/kernel/syscalls/open_tree/open_tree01.c line 73
Quoted 6 lines
testcases/kernel/syscalls/open_tree/open_tree01.c new file +6
-0+return ; + } + +TEST (move_mount (fsmfd,"" ,AT_FDCWD ,MNTPOINT , +MOVE_MOUNT_F_EMPTY_PATH )); +SAFE_CLOSE (fsmfd);Here as well, shouldn't we just set the .mount_device flag instead?
Hi,
Sorry but I am not sure what will happen by .mount_device here. From what I see from tst_test.c, that flag will end up calling SAFE_MOUNT() automatically, but what we are calling here is fsmount() and move_mount() instead.
Can you please elaborate a bit on that ? Thanks.
Signature · 1 line
viresh
PATCH v7 10/10 syscalls/open_tree: New tests
Hi!
Quoted 10 lines
Quoted 1 line
Here as well, shouldn't we just set the .mount_device flag instead?
Hi,
Sorry but I am not sure what will happen by .mount_device here. From what I see from
tst_test.c, that flag will end up callingSAFE_MOUNT()automatically, but what we are calling here isfsmount()andmove_mount()instead.Can you please elaborate a bit on that ? Thanks.
My point here is that most of the code just mounts the device and since we are testing open_tree() there is no point in mounting the device with the new mount API in the first half of the run() function, it should work fine with the device mounted with the plain old mount(). Also we do OPEN_TREE_CLONE here, so there is no point in mounting the filesystem in the run() fucntion, moreover it will probably fail with the -i parameter.
So I'm suggesting to remove the part that mounts the device in the first half of the test and set the .mount_device flag instead.
Signature · 2 lines
Cyril Hrubis [email protected]