Skip to content

Commit 3de64b6

Browse files
committed
selftests/landlock: Add supports_filesystem() helper
Replace supports_overlayfs() with supports_filesystem() to be able to check several filesystems. This will be useful in a following commit. Only check for overlay filesystem once in the setup step, and then rely on self->skip_test. Cc: Guenter Roeck <groeck@chromium.org> Cc: Jeff Xu <jeffxu@google.com> Link: https://lore.kernel.org/r/20230612191430.339153-4-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 592efeb commit 3de64b6

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

tools/testing/selftests/landlock/fs_test.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ static bool fgrep(FILE *const inf, const char *const str)
107107
return false;
108108
}
109109

110-
static bool supports_overlayfs(void)
110+
static bool supports_filesystem(const char *const filesystem)
111111
{
112+
char str[32];
113+
int len;
112114
bool res;
113115
FILE *const inf = fopen("/proc/filesystems", "r");
114116

@@ -119,7 +121,12 @@ static bool supports_overlayfs(void)
119121
if (!inf)
120122
return true;
121123

122-
res = fgrep(inf, "nodev\toverlay\n");
124+
len = snprintf(str, sizeof(str), "nodev\t%s\n", filesystem);
125+
if (len >= sizeof(str))
126+
/* Ignores too-long filesystem names. */
127+
return true;
128+
129+
res = fgrep(inf, str);
123130
fclose(inf);
124131
return res;
125132
}
@@ -4044,14 +4051,17 @@ static const char (*merge_sub_files[])[] = {
40444051
* └── work
40454052
*/
40464053

4047-
/* clang-format off */
4048-
FIXTURE(layout2_overlay) {};
4049-
/* clang-format on */
4054+
FIXTURE(layout2_overlay)
4055+
{
4056+
bool skip_test;
4057+
};
40504058

40514059
FIXTURE_SETUP(layout2_overlay)
40524060
{
4053-
if (!supports_overlayfs())
4054-
SKIP(return, "overlayfs is not supported");
4061+
if (!supports_filesystem("overlay")) {
4062+
self->skip_test = true;
4063+
SKIP(return, "overlayfs is not supported (setup)");
4064+
}
40554065

40564066
prepare_layout(_metadata);
40574067

@@ -4089,8 +4099,8 @@ FIXTURE_SETUP(layout2_overlay)
40894099

40904100
FIXTURE_TEARDOWN(layout2_overlay)
40914101
{
4092-
if (!supports_overlayfs())
4093-
SKIP(return, "overlayfs is not supported");
4102+
if (self->skip_test)
4103+
SKIP(return, "overlayfs is not supported (teardown)");
40944104

40954105
EXPECT_EQ(0, remove_path(lower_do1_fl3));
40964106
EXPECT_EQ(0, remove_path(lower_dl1_fl2));
@@ -4123,8 +4133,8 @@ FIXTURE_TEARDOWN(layout2_overlay)
41234133

41244134
TEST_F_FORK(layout2_overlay, no_restriction)
41254135
{
4126-
if (!supports_overlayfs())
4127-
SKIP(return, "overlayfs is not supported");
4136+
if (self->skip_test)
4137+
SKIP(return, "overlayfs is not supported (test)");
41284138

41294139
ASSERT_EQ(0, test_open(lower_fl1, O_RDONLY));
41304140
ASSERT_EQ(0, test_open(lower_dl1, O_RDONLY));
@@ -4289,8 +4299,8 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)
42894299
size_t i;
42904300
const char *path_entry;
42914301

4292-
if (!supports_overlayfs())
4293-
SKIP(return, "overlayfs is not supported");
4302+
if (self->skip_test)
4303+
SKIP(return, "overlayfs is not supported (test)");
42944304

42954305
/* Sets rules on base directories (i.e. outside overlay scope). */
42964306
ruleset_fd = create_ruleset(_metadata, ACCESS_RW, layer1_base);

0 commit comments

Comments
 (0)