selftests/landlock: fix test when overlayfs is
Subsystems (3)
v7 cover selftests/landlock: fix test when overlayfs is
From: Jeff Xu <[email protected]>
Overlayfs can be disabled in kernel config, causing related tests to fail. Adding a check for overlayfs’s supportability at runtime, so we can call SKIP() when needed.
v7:
Fix bug in supports_overlayfs().
Manual test with kernel with and without overlayfs.
v6: https://lore.kernel.org/all/[email protected]/
In v4, the SKIP() was applied at FIXTURE_SETUP() after mount() fail, however, FIXTURE_TEARDOWN() will fail. It might be complicated for test infra or testcase itself to have cleanup code handing the success/failure of steps in SETUP().
This patch changes the approach, it calls supports_overlay() and SKIP() at the beginning of FIXTURE_SETUP(), FIX_TEARDOWN(), TEST_F_FORK(). Because no modification of system is done by the test, cleanup is not needed.
v4:
https://lore.kernel.org/all/[email protected]/
*** BLURB HERE ***
Jeff Xu (1):
selftests/landlock: skip overlayfs test when kernel not support it
tools/testing/selftests/landlock/fs_test.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+)
base-commit: 963a70bee5880640d0fd83ed29dc1e7ec0d2bd4a
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
PATCH v7 1/1 selftests/landlock: skip overlayfs test when kernel not support it
From: Jeff Xu <[email protected]>
Overlayfs can be disabled in kernel config, causing related tests to fail. Add check for overlayfs’s supportability at runtime, so we can call SKIP() when needed.
--- tools/testing/selftests/landlock/fs_test.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+)
tools/testing/selftests/landlock/fs_test.c +51 -0
@@ -11,6 +11,7 @@#include <fcntl.h> #include <linux/landlock.h> #include <sched.h> +#include <stdio.h> #include <string.h> #include <sys/capability.h> #include <sys/mount.h>
@@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";static const char dir_s3d2[] =TMP_DIR "/s3d1/s3d2" ;static const char dir_s3d3[] =TMP_DIR "/s3d1/s3d2/s3d3" ; +static const char proc_filesystems[] ="/proc/filesystems" ;/* * layout1 hierarchy: *
@@ -169,6 +171,43 @@ static int remove_path(const char *const path)return err; } +static bool fgrep (FILE *inf,const char *str) +{ +char line[32 ]; +int slen =strlen (str); + +while (!feof (inf)) { +if (!fgets (line,sizeof (line), inf)) +break ; +if (strncmp (line, str, slen)) +continue ; + +return true; + } + +return false; +} + +static bool supports_overlayfs (void ) +{ +bool res; +FILE *inf =fopen (proc_filesystems,"r" ); + +/* +* If fopen failed, return supported. +* This help detect missing file (shall not +* happen). +*/ +if (!inf) +return true; + + res =fgrep (inf,"nodev\toverlay\n" ); +fclose (inf); + +return res; +} + +static void prepare_layout (struct __test_metadata *const _metadata) {disable_caps (_metadata);
@@ -3404,6 +3443,9 @@ FIXTURE(layout2_overlay) {};FIXTURE_SETUP (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +prepare_layout (_metadata);create_directory (_metadata,LOWER_BASE );
@@ -3440,6 +3482,9 @@ FIXTURE_SETUP(layout2_overlay)FIXTURE_TEARDOWN (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +EXPECT_EQ (0 ,remove_path (lower_do1_fl3));EXPECT_EQ (0 ,remove_path (lower_dl1_fl2));EXPECT_EQ (0 ,remove_path (lower_fl1));
@@ -3471,6 +3516,9 @@ FIXTURE_TEARDOWN(layout2_overlay) TEST_F_FORK(layout2_overlay, no_restriction) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +ASSERT_EQ (0 ,test_open (lower_fl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1_fl2,O_RDONLY ));
@@ -3634,6 +3682,9 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)size_t i;const char *path_entry; +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +/* Sets rules on base directories (i.e. outside overlay scope). */ ruleset_fd =create_ruleset (_metadata,ACCESS_RW , layer1_base);ASSERT_LE (0 , ruleset_fd);
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
Re: [PATCH v7 1/1] selftests/landlock: skip overlayfs test when kernel not support it
Quoted 8 lines · On Thu, Dec 29, 2022 at 1:02 PM <[email protected]> wrote:
From: Jeff Xu <[email protected]>
Overlayfs can be disabled in kernel config, causing related tests to fail. Add check for overlayfs’s supportability at runtime, so we can call
SKIP()when needed.Signed-off-by Jeff Xu <[email protected]>
Quoted 111 lines
--- tools/testing/selftests/landlock/fs_test.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+)tools/testing/selftests/landlock/fs_test.c +51
-1@@ -11,6 +11,7 @@#include <fcntl.h> #include <linux/landlock.h> #include <sched.h> +#include <stdio.h> #include <string.h> #include <sys/capability.h> #include <sys/mount.h> @@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";static const char dir_s3d2[] =TMP_DIR "/s3d1/s3d2" ;static const char dir_s3d3[] =TMP_DIR "/s3d1/s3d2/s3d3" ; +static const char proc_filesystems[] ="/proc/filesystems" ;/* * layout1 hierarchy: * @@ -169,6 +171,43 @@ static int remove_path(const char *const path)return err; } +static bool fgrep (FILE *inf,const char *str) +{ +char line[32 ]; +int slen =strlen (str); + +while (!feof (inf)) { +if (!fgets (line,sizeof (line), inf)) +break ; +if (strncmp (line, str, slen)) +continue ; + +return true; + } + +return false; +} + +static bool supports_overlayfs (void ) +{ +bool res; +FILE *inf =fopen (proc_filesystems,"r" ); + +/* +* If fopen failed, return supported. +* This help detect missing file (shall not +* happen). +*/ +if (!inf) +return true; + + res =fgrep (inf,"nodev\toverlay\n" ); +fclose (inf); + +return res; +} + +static void prepare_layout (struct __test_metadata *const _metadata) {disable_caps (_metadata);@@ -3404,6 +3443,9 @@ FIXTURE(layout2_overlay) {};FIXTURE_SETUP (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +prepare_layout (_metadata);create_directory (_metadata,LOWER_BASE );@@ -3440,6 +3482,9 @@ FIXTURE_SETUP(layout2_overlay)FIXTURE_TEARDOWN (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +EXPECT_EQ (0 ,remove_path (lower_do1_fl3));EXPECT_EQ (0 ,remove_path (lower_dl1_fl2));EXPECT_EQ (0 ,remove_path (lower_fl1));@@ -3471,6 +3516,9 @@ FIXTURE_TEARDOWN(layout2_overlay) TEST_F_FORK(layout2_overlay, no_restriction) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +ASSERT_EQ (0 ,test_open (lower_fl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1_fl2,O_RDONLY ));@@ -3634,6 +3682,9 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)size_t i;const char *path_entry; +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +/* Sets rules on base directories (i.e. outside overlay scope). */ ruleset_fd =create_ruleset (_metadata,ACCESS_RW , layer1_base);ASSERT_LE (0 , ruleset_fd); --2.39.0.314.g84b9a713c41-goog
Mickaël Salaün
maintainerRe: [PATCH v7 1/1] selftests/landlock: skip overlayfs test when kernel not support it
Please refresh with clang-format-14.
You might want to update the subject to:
selftests/landlock: Skip overlayfs tests when not supported
Quoted 32 lines · Guenter Roeck
Quoted 8 lines · On Thu, Dec 29, 2022 at 1:02 PM <[email protected]> wrote:
From: Jeff Xu <[email protected]>
Overlayfs can be disabled in kernel config, causing related tests to fail. Add check for overlayfs’s supportability at runtime, so we can call
SKIP()when needed.Signed-off-by Jeff Xu <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Quoted 20 lines
--- tools/testing/selftests/landlock/fs_test.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+)tools/testing/selftests/landlock/fs_test.c +1
-0@@ -11,6 +11,7 @@#include <fcntl.h> #include <linux/landlock.h> #include <sched.h> +#include <stdio.h> #include <string.h> #include <sys/capability.h> #include <sys/mount.h> @@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";static const char dir_s3d2[] =TMP_DIR "/s3d1/s3d2" ;static const char dir_s3d3[] =TMP_DIR "/s3d1/s3d2/s3d3" ;
Quoted 1 line
tools/testing/selftests/landlock/fs_test.c static const char dir_s3d1[] = TMP_DIR "/s3d1"; · line 66
Quoted 1 line
tools/testing/selftests/landlock/fs_test.c +1
-0+static const char proc_filesystems[] ="/proc/filesystems" ;
You can inline this string in the fopen() call for now.
Quoted 17 lines
Quoted 17 lines
tools/testing/selftests/landlock/fs_test.c +10
-0/* * layout1 hierarchy: * @@ -169,6 +171,43 @@ static int remove_path(const char *const path)return err; } +static bool fgrep (FILE *inf,const char *str) +{ +char line[32 ]; +int slen =strlen (str); + +while (!feof (inf)) { +if (!fgets (line,sizeof (line), inf)) +break ; +if (strncmp (line, str, slen)) +continue ;
Quoted 8 lines
tools/testing/selftests/landlock/fs_test.c static int remove_path(const char *const path) · line 191
Quoted 8 lines
tools/testing/selftests/landlock/fs_test.c +8
-0+ +return true; + } + +return false; +} + +static bool supports_overlayfs (void )
You can move this two functions just before mkdir_parents().
Quoted 8 lines
tools/testing/selftests/landlock/fs_test.c static int remove_path(const char *const path) · line 199
Quoted 8 lines
tools/testing/selftests/landlock/fs_test.c +8
-0+{ +bool res; +FILE *inf =fopen (proc_filesystems,"r" ); + +/* +* If fopen failed, return supported. +* This help detect missing file (shall not +* happen).
You can make this comment fit in two lines, with 80 columns.
Quoted 23 lines
Quoted 23 lines
tools/testing/selftests/landlock/fs_test.c +14
-0+*/ +if (!inf) +return true; + + res =fgrep (inf,"nodev\toverlay\n" ); +fclose (inf); + +return res; +} + +static void prepare_layout (struct __test_metadata *const _metadata) {disable_caps (_metadata);@@ -3404,6 +3443,9 @@ FIXTURE(layout2_overlay) {};FIXTURE_SETUP (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +prepare_layout (_metadata);
Quoted 7 lines
tools/testing/selftests/landlock/fs_test.c FIXTURE_SETUP(layout2_overlay) · line 3486
Quoted 7 lines
tools/testing/selftests/landlock/fs_test.c +2
-0create_directory (_metadata,LOWER_BASE );@@ -3440,6 +3482,9 @@ FIXTURE_SETUP(layout2_overlay)FIXTURE_TEARDOWN (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" );
This looks good to me except the multiple supports_overlayfs() calls. Only the FIXTURE_SETUP() should be required. I guess some modifications of kselftest_harness.h are need to support that. I'd like to avoid touching TEST_F_FORK() which should be part of kselftest_harness.h
Quoted 27 lines
Quoted 27 lines
tools/testing/selftests/landlock/fs_test.c +7
-1+EXPECT_EQ (0 ,remove_path (lower_do1_fl3));EXPECT_EQ (0 ,remove_path (lower_dl1_fl2));EXPECT_EQ (0 ,remove_path (lower_fl1));@@ -3471,6 +3516,9 @@ FIXTURE_TEARDOWN(layout2_overlay) TEST_F_FORK(layout2_overlay, no_restriction) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +ASSERT_EQ (0 ,test_open (lower_fl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1_fl2,O_RDONLY ));@@ -3634,6 +3682,9 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)size_t i;const char *path_entry; +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +/* Sets rules on base directories (i.e. outside overlay scope). */ ruleset_fd =create_ruleset (_metadata,ACCESS_RW , layer1_base);ASSERT_LE (0 , ruleset_fd); --2.39.0.314.g84b9a713c41-goog
Re: [PATCH v7 1/1] selftests/landlock: skip overlayfs test when kernel not support it
Hi Mickaël
Please see inline.
Quoted 3 lines · Mickaël Salaün
Please refresh with clang-format-14.
My installation has clang-format version 15, but changes are quite big if I use it,
do you still want me to use it ?
Quoted 3 lines
You might want to update the subject to:
selftests/landlock: Skip overlayfs tests when not supported
OK.
Quoted 34 lines · Guenter Roeck
Quoted 32 lines · On Thu, Dec 29, 2022 at 1:02 PM <[email protected]> wrote:
Quoted 8 lines
From: Jeff Xu <[email protected]>
Overlayfs can be disabled in kernel config, causing related tests to fail. Add check for overlayfs’s supportability at runtime, so we can call
SKIP()when needed.Signed-off-by Jeff Xu <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Quoted 20 lines
--- tools/testing/selftests/landlock/fs_test.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+)tools/testing/selftests/landlock/fs_test.c +1
-0@@ -11,6 +11,7 @@#include <fcntl.h> #include <linux/landlock.h> #include <sched.h> +#include <stdio.h> #include <string.h> #include <sys/capability.h> #include <sys/mount.h> @@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";static const char dir_s3d2[] =TMP_DIR "/s3d1/s3d2" ;static const char dir_s3d3[] =TMP_DIR "/s3d1/s3d2/s3d3" ;
Quoted 4 lines
Quoted 1 line
tools/testing/selftests/landlock/fs_test.c static const char dir_s3d1[] = TMP_DIR "/s3d1"; · line 66
Quoted 1 line
tools/testing/selftests/landlock/fs_test.c +1
-0+static const char proc_filesystems[] ="/proc/filesystems" ;You can inline this string in the
fopen()call for now.
Done.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
tools/testing/selftests/landlock/fs_test.c +12
-0/* * layout1 hierarchy: * @@ -169,6 +171,43 @@ static int remove_path(const char *const path)return err; } +static bool fgrep (FILE *inf,const char *str) +{ +char line[32 ]; +int slen =strlen (str); + +while (!feof (inf)) { +if (!fgets (line,sizeof (line), inf)) +break ; +if (strncmp (line, str, slen)) +continue ; + +return true;
Quoted 9 lines
Quoted 6 lines
tools/testing/selftests/landlock/fs_test.c static int remove_path(const char *const path) · line 191
Quoted 6 lines
tools/testing/selftests/landlock/fs_test.c +6
-0+ } + +return false; +} + +static bool supports_overlayfs (void )You can move this two functions just before
mkdir_parents().
Done.
Quoted 12 lines
Quoted 9 lines
tools/testing/selftests/landlock/fs_test.c static int remove_path(const char *const path) · line 199
Quoted 9 lines
tools/testing/selftests/landlock/fs_test.c +8
-0+{ +bool res; +FILE *inf =fopen (proc_filesystems,"r" ); + +/* +* If fopen failed, return supported. +* This help detect missing file (shall not +* happen). You can make this comment fit in two lines, with 80 columns.
Done.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
tools/testing/selftests/landlock/fs_test.c +14
-0+*/ +if (!inf) +return true; + + res =fgrep (inf,"nodev\toverlay\n" ); +fclose (inf); + +return res; +} + +static void prepare_layout (struct __test_metadata *const _metadata) {disable_caps (_metadata);@@ -3404,6 +3443,9 @@ FIXTURE(layout2_overlay) {};FIXTURE_SETUP (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +prepare_layout (_metadata);create_directory (_metadata,LOWER_BASE );@@ -3440,6 +3482,9 @@ FIXTURE_SETUP(layout2_overlay)
Quoted 11 lines
Quoted 4 lines
tools/testing/selftests/landlock/fs_test.c FIXTURE_SETUP(layout2_overlay) · line 3486
Quoted 4 lines
tools/testing/selftests/landlock/fs_test.c +2
-0FIXTURE_TEARDOWN (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" );This looks good to me except the multiple
supports_overlayfs()calls. Only theFIXTURE_SETUP()should be required. I guess some modifications ofkselftest_harness.hare need to support that. I'd like to avoid touchingTEST_F_FORK()which should be part ofkselftest_harness.h
In kselftest_harness.h, SKIP() only applies within the function scope ( FIXTURE_SETUP(), TEST_F_FORK(), FIXTURE_TEARDOWN())
If we want to apply the skip logic to all remaining steps of the testcase, I think we should do it with a dedicated environment check hook (FIXTURE_ENV_CHECK),
called before FIXTURE_SETUP(), if the environment check fails, all of the remaining
test steps will be skipped. In this way, once the env check pass, the remaining test case should also be passing, or if env check fails, there is no need to
delete the resource since no setup is called.
However, this requires change to the kselftest_harness.h, I do think it needs to be a separate feature and commit (we can adopt fs_test to be the first user)
Best regards,
Jeff
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
tools/testing/selftests/landlock/fs_test.c +7
-1+EXPECT_EQ (0 ,remove_path (lower_do1_fl3));EXPECT_EQ (0 ,remove_path (lower_dl1_fl2));EXPECT_EQ (0 ,remove_path (lower_fl1));@@ -3471,6 +3516,9 @@ FIXTURE_TEARDOWN(layout2_overlay) TEST_F_FORK(layout2_overlay, no_restriction) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +ASSERT_EQ (0 ,test_open (lower_fl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1_fl2,O_RDONLY ));@@ -3634,6 +3682,9 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)size_t i;const char *path_entry; +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +/* Sets rules on base directories (i.e. outside overlay scope). */ ruleset_fd =create_ruleset (_metadata,ACCESS_RW , layer1_base);ASSERT_LE (0 , ruleset_fd); --2.39.0.314.g84b9a713c41-goog
Mickaël Salaün
maintainerRe: [PATCH v7 1/1] selftests/landlock: skip overlayfs test when kernel not support it
Quoted 10 lines · Jeff Xu
Hi Mickaël
Please see inline.Quoted 3 lines · Mickaël Salaün
Please refresh with clang-format-14.
My installation has clang-format version 15, but changes are quite big if I use it,
do you still want me to use it ?
That's fine, this patch is almost good, I'll run clang-format-14 on the final one.
Quoted 141 lines
Quoted 4 lines
You might want to update the subject to:
selftests/landlock: Skip overlayfs tests when not supportedOK.
Quoted 34 lines · Guenter Roeck
Quoted 32 lines · On Thu, Dec 29, 2022 at 1:02 PM <[email protected]> wrote:
Quoted 8 lines
From: Jeff Xu <[email protected]>
Overlayfs can be disabled in kernel config, causing related tests to fail. Add check for overlayfs’s supportability at runtime, so we can call
SKIP()when needed.Signed-off-by Jeff Xu <[email protected]>Reviewed-by Guenter Roeck <[email protected]>Quoted 20 lines
--- tools/testing/selftests/landlock/fs_test.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+)tools/testing/selftests/landlock/fs_test.c +1
-0@@ -11,6 +11,7 @@#include <fcntl.h> #include <linux/landlock.h> #include <sched.h> +#include <stdio.h> #include <string.h> #include <sys/capability.h> #include <sys/mount.h> @@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";static const char dir_s3d2[] =TMP_DIR "/s3d1/s3d2" ;static const char dir_s3d3[] =TMP_DIR "/s3d1/s3d2/s3d3" ;Quoted 4 lines
Quoted 1 line
tools/testing/selftests/landlock/fs_test.c static const char dir_s3d1[] = TMP_DIR "/s3d1"; · line 66
Quoted 1 line
tools/testing/selftests/landlock/fs_test.c +1
-0+static const char proc_filesystems[] ="/proc/filesystems" ;You can inline this string in the
fopen()call for now.Done.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
tools/testing/selftests/landlock/fs_test.c +12
-0/* * layout1 hierarchy: * @@ -169,6 +171,43 @@ static int remove_path(const char *const path)return err; } +static bool fgrep (FILE *inf,const char *str) +{ +char line[32 ]; +int slen =strlen (str); + +while (!feof (inf)) { +if (!fgets (line,sizeof (line), inf)) +break ; +if (strncmp (line, str, slen)) +continue ; + +return true;Quoted 9 lines
Quoted 6 lines
tools/testing/selftests/landlock/fs_test.c static int remove_path(const char *const path) · line 191
Quoted 6 lines
tools/testing/selftests/landlock/fs_test.c +6
-0+ } + +return false; +} + +static bool supports_overlayfs (void )You can move this two functions just before
mkdir_parents().Done.
Quoted 12 lines
Quoted 9 lines
tools/testing/selftests/landlock/fs_test.c static int remove_path(const char *const path) · line 199
Quoted 9 lines
tools/testing/selftests/landlock/fs_test.c +8
-0+{ +bool res; +FILE *inf =fopen (proc_filesystems,"r" ); + +/* +* If fopen failed, return supported. +* This help detect missing file (shall not +* happen). You can make this comment fit in two lines, with 80 columns.
Done.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
tools/testing/selftests/landlock/fs_test.c +14
-0+*/ +if (!inf) +return true; + + res =fgrep (inf,"nodev\toverlay\n" ); +fclose (inf); + +return res; +} + +static void prepare_layout (struct __test_metadata *const _metadata) {disable_caps (_metadata);@@ -3404,6 +3443,9 @@ FIXTURE(layout2_overlay) {};FIXTURE_SETUP (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +prepare_layout (_metadata);create_directory (_metadata,LOWER_BASE );@@ -3440,6 +3482,9 @@ FIXTURE_SETUP(layout2_overlay)Quoted 11 lines
Quoted 4 lines
tools/testing/selftests/landlock/fs_test.c FIXTURE_SETUP(layout2_overlay) · line 3486
Quoted 4 lines
tools/testing/selftests/landlock/fs_test.c +2
-0FIXTURE_TEARDOWN (layout2_overlay) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" );This looks good to me except the multiple
supports_overlayfs()calls. Only theFIXTURE_SETUP()should be required. I guess some modifications ofkselftest_harness.hare need to support that. I'd like to avoid touchingTEST_F_FORK()which should be part ofkselftest_harness.hIn
kselftest_harness.h,SKIP()only applies within the function scope (FIXTURE_SETUP(),TEST_F_FORK(),FIXTURE_TEARDOWN())If we want to apply the skip logic to all remaining steps of the testcase, I think we should do it with a dedicated environment check hook (
FIXTURE_ENV_CHECK),
called beforeFIXTURE_SETUP(), if the environment check fails, all of the remaining
test steps will be skipped. In this way, once the env check pass, the remaining test case should also be passing, or if env check fails, there is no need to
delete the resource since no setup is called.
Quoted 3 lines
However, this requires change to the
kselftest_harness.h, I do think it needs to be a separate feature and commit (we can adoptfs_testto be the first user)
Looks good to me, implementing this FIXTURE_ENV_CHECK (or something similar) will be cleaner.
Shuah, what do you think about that?
Quoted 31 lines
Best regards,
JeffQuoted 27 lines
Quoted 27 lines
Quoted 27 lines
tools/testing/selftests/landlock/fs_test.c +7
-1+EXPECT_EQ (0 ,remove_path (lower_do1_fl3));EXPECT_EQ (0 ,remove_path (lower_dl1_fl2));EXPECT_EQ (0 ,remove_path (lower_fl1));@@ -3471,6 +3516,9 @@ FIXTURE_TEARDOWN(layout2_overlay) TEST_F_FORK(layout2_overlay, no_restriction) { +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +ASSERT_EQ (0 ,test_open (lower_fl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1,O_RDONLY ));ASSERT_EQ (0 ,test_open (lower_dl1_fl2,O_RDONLY ));@@ -3634,6 +3682,9 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)size_t i;const char *path_entry; +if (!supports_overlayfs ()) +SKIP (return,"overlayfs is not supported" ); +/* Sets rules on base directories (i.e. outside overlay scope). */ ruleset_fd =create_ruleset (_metadata,ACCESS_RW , layer1_base);ASSERT_LE (0 , ruleset_fd); --2.39.0.314.g84b9a713c41-goog