Skip to content

Commit 592efeb

Browse files
committed
selftests/landlock: Don't create useless file layouts
Add and use a layout0 test fixture to not populate the tmpfs filesystem if it is not required for tests: unknown_access_rights, proc_nsfs, unpriv and max_layers. This doesn't change these tests but it speeds up their setup and makes them less prone to error. This prepare the ground for a next commit. Link: https://lore.kernel.org/r/20230612191430.339153-3-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 74ce793 commit 592efeb

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

tools/testing/selftests/landlock/fs_test.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,20 @@ static void cleanup_layout(struct __test_metadata *const _metadata)
231231
EXPECT_EQ(0, remove_path(TMP_DIR));
232232
}
233233

234+
/* clang-format off */
235+
FIXTURE(layout0) {};
236+
/* clang-format on */
237+
238+
FIXTURE_SETUP(layout0)
239+
{
240+
prepare_layout(_metadata);
241+
}
242+
243+
FIXTURE_TEARDOWN(layout0)
244+
{
245+
cleanup_layout(_metadata);
246+
}
247+
234248
static void create_layout1(struct __test_metadata *const _metadata)
235249
{
236250
create_file(_metadata, file1_s1d1);
@@ -510,7 +524,7 @@ TEST_F_FORK(layout1, file_and_dir_access_rights)
510524
ASSERT_EQ(0, close(ruleset_fd));
511525
}
512526

513-
TEST_F_FORK(layout1, unknown_access_rights)
527+
TEST_F_FORK(layout0, unknown_access_rights)
514528
{
515529
__u64 access_mask;
516530

@@ -608,7 +622,7 @@ static void enforce_ruleset(struct __test_metadata *const _metadata,
608622
}
609623
}
610624

611-
TEST_F_FORK(layout1, proc_nsfs)
625+
TEST_F_FORK(layout0, proc_nsfs)
612626
{
613627
const struct rule rules[] = {
614628
{
@@ -657,11 +671,11 @@ TEST_F_FORK(layout1, proc_nsfs)
657671
ASSERT_EQ(0, close(path_beneath.parent_fd));
658672
}
659673

660-
TEST_F_FORK(layout1, unpriv)
674+
TEST_F_FORK(layout0, unpriv)
661675
{
662676
const struct rule rules[] = {
663677
{
664-
.path = dir_s1d2,
678+
.path = TMP_DIR,
665679
.access = ACCESS_RO,
666680
},
667681
{},
@@ -1301,12 +1315,12 @@ TEST_F_FORK(layout1, inherit_superset)
13011315
ASSERT_EQ(0, test_open(file1_s1d3, O_RDONLY));
13021316
}
13031317

1304-
TEST_F_FORK(layout1, max_layers)
1318+
TEST_F_FORK(layout0, max_layers)
13051319
{
13061320
int i, err;
13071321
const struct rule rules[] = {
13081322
{
1309-
.path = dir_s1d2,
1323+
.path = TMP_DIR,
13101324
.access = ACCESS_RO,
13111325
},
13121326
{},

0 commit comments

Comments
 (0)