Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+20 -6
+20 -6
tools/testing/selftests/landlock/fs_test.c
··· 231 231 EXPECT_EQ(0, remove_path(TMP_DIR)); 232 232 } 233 233 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 + 234 248 static void create_layout1(struct __test_metadata *const _metadata) 235 249 { 236 250 create_file(_metadata, file1_s1d1); ··· 524 510 ASSERT_EQ(0, close(ruleset_fd)); 525 511 } 526 512 527 - TEST_F_FORK(layout1, unknown_access_rights) 513 + TEST_F_FORK(layout0, unknown_access_rights) 528 514 { 529 515 __u64 access_mask; 530 516 ··· 622 608 } 623 609 } 624 610 625 - TEST_F_FORK(layout1, proc_nsfs) 611 + TEST_F_FORK(layout0, proc_nsfs) 626 612 { 627 613 const struct rule rules[] = { 628 614 { ··· 671 657 ASSERT_EQ(0, close(path_beneath.parent_fd)); 672 658 } 673 659 674 - TEST_F_FORK(layout1, unpriv) 660 + TEST_F_FORK(layout0, unpriv) 675 661 { 676 662 const struct rule rules[] = { 677 663 { 678 - .path = dir_s1d2, 664 + .path = TMP_DIR, 679 665 .access = ACCESS_RO, 680 666 }, 681 667 {}, ··· 1315 1301 ASSERT_EQ(0, test_open(file1_s1d3, O_RDONLY)); 1316 1302 } 1317 1303 1318 - TEST_F_FORK(layout1, max_layers) 1304 + TEST_F_FORK(layout0, max_layers) 1319 1305 { 1320 1306 int i, err; 1321 1307 const struct rule rules[] = { 1322 1308 { 1323 - .path = dir_s1d2, 1309 + .path = TMP_DIR, 1324 1310 .access = ACCESS_RO, 1325 1311 }, 1326 1312 {},