From: "Mickaël Salaün" <mic@digikod.net>
To: "Günther Noack" <gnoack3000@gmail.com>
Cc: "Günther Noack" <gnoack@google.com>,
"Shuah Khan" <shuah@kernel.org>,
linux-security-module@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 26/27] selftests/landlock: Use EXPECT for closing FDs and stopping threads
Date: Fri, 4 Dec 2026 18:08:14 +0100 [thread overview]
Message-ID: <20261204.iJah2viiboov@digikod.net> (raw)
In-Reply-To: <20261104-selftests-refactor-v2-26-c52f23f7ce33@gmail.com>
On Wed, Nov 04, 2026 at 10:09:12PM +0100, Günther Noack wrote:
> Closing FDs and cancelling or joining threads whose results are not
> used is teardown, whether it happens at the end of a test or in the
> middle of it. No later check depends on it, so a failure should be
> reported without aborting the test. Use EXPECT for these calls, as
> most tests already do. The same applies to removing the FIFO and
> reaping the child at the end of named_pipe_ioctl.
>
> The close(0) in ioctl_error() stays an ASSERT, as the following IOCTL
> relies on FD 0 being closed.
>
> Signed-off-by: Günther Noack <gnoack3000@gmail.com>
> ---
> tools/testing/selftests/landlock/base_test.c | 40 ++++-----
> tools/testing/selftests/landlock/fs_test.c | 106 +++++++++++------------
> tools/testing/selftests/landlock/ptrace_test.c | 16 ++--
> tools/testing/selftests/landlock/trace_fs_test.c | 8 +-
> tools/testing/selftests/landlock/trace_test.c | 6 +-
> tools/testing/selftests/landlock/tsync_test.c | 22 ++---
> 6 files changed, 99 insertions(+), 99 deletions(-)
>
> diff --git a/tools/testing/selftests/landlock/base_test.c b/tools/testing/selftests/landlock/base_test.c
> index 4cb30b943aa8..46af291edaef 100644
> --- a/tools/testing/selftests/landlock/base_test.c
> +++ b/tools/testing/selftests/landlock/base_test.c
> @@ -203,7 +203,7 @@ TEST(create_ruleset_checks_ordering)
> ruleset_fd =
> landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
> ASSERT_LE(0, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> /* Tests ordering of syscall argument checks. */
> @@ -249,8 +249,8 @@ TEST(add_rule_checks_ordering)
> ASSERT_LE(0, path_beneath_attr.parent_fd);
> ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath_attr, 0));
> - ASSERT_EQ(0, close(path_beneath_attr.parent_fd));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(path_beneath_attr.parent_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> /* Tests ordering of syscall argument and permission checks. */
> @@ -272,7 +272,7 @@ TEST(restrict_self_checks_ordering)
> ASSERT_LE(0, path_beneath_attr.parent_fd);
> ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath_attr, 0));
> - ASSERT_EQ(0, close(path_beneath_attr.parent_fd));
> + EXPECT_EQ(0, close(path_beneath_attr.parent_fd));
>
> /* Checks unprivileged enforcement without no_new_privs. */
> drop_caps(_metadata);
> @@ -307,7 +307,7 @@ TEST(restrict_self_checks_ordering)
>
> /* Checks valid call. */
> ASSERT_EQ(0, landlock_restrict_self(ruleset_fd, 0));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST(restrict_self_max_layers)
> @@ -328,7 +328,7 @@ TEST(restrict_self_max_layers)
> ASSERT_LE(0, path_beneath_attr.parent_fd);
> ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath_attr, 0));
> - ASSERT_EQ(0, close(path_beneath_attr.parent_fd));
> + EXPECT_EQ(0, close(path_beneath_attr.parent_fd));
>
> /* Enforces the maximum number of allowed layers. */
> for (int i = 0; i < LANDLOCK_MAX_NUM_LAYERS; i++)
> @@ -342,7 +342,7 @@ TEST(restrict_self_max_layers)
>
> /* Checks that the failed call did not set no_new_privs. */
> ASSERT_EQ(0, prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST(restrict_self_fd)
> @@ -496,7 +496,7 @@ TEST(ruleset_fd_io)
> ASSERT_EQ(-1, read(ruleset_fd, &buf, 1));
> ASSERT_EQ(EINVAL, errno);
>
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> /* Tests enforcement of a ruleset FD transferred through a UNIX socket. */
> @@ -525,14 +525,14 @@ TEST(ruleset_fd_transfer)
> ASSERT_EQ(0,
> landlock_add_rule(ruleset_fd_tx, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath_attr, 0));
> - ASSERT_EQ(0, close(path_beneath_attr.parent_fd));
> + EXPECT_EQ(0, close(path_beneath_attr.parent_fd));
>
> /* Sends the ruleset FD over a socketpair and then close it. */
> ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0,
> socket_fds));
> ASSERT_EQ(0, send_fd(socket_fds[0], ruleset_fd_tx));
> - ASSERT_EQ(0, close(socket_fds[0]));
> - ASSERT_EQ(0, close(ruleset_fd_tx));
> + EXPECT_EQ(0, close(socket_fds[0]));
> + EXPECT_EQ(0, close(ruleset_fd_tx));
>
> child = fork();
> ASSERT_LE(0, child);
> @@ -540,32 +540,32 @@ TEST(ruleset_fd_transfer)
> const int ruleset_fd_rx = recv_fd(socket_fds[1]);
>
> ASSERT_LE(0, ruleset_fd_rx);
> - ASSERT_EQ(0, close(socket_fds[1]));
> + EXPECT_EQ(0, close(socket_fds[1]));
>
> /* Enforces the received ruleset on the child. */
> ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0));
> ASSERT_EQ(0, landlock_restrict_self(ruleset_fd_rx, 0));
> - ASSERT_EQ(0, close(ruleset_fd_rx));
> + EXPECT_EQ(0, close(ruleset_fd_rx));
>
> /* Checks that the ruleset enforcement. */
> ASSERT_EQ(-1, open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC));
> ASSERT_EQ(EACCES, errno);
> dir_fd = open("/tmp", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
> ASSERT_LE(0, dir_fd);
> - ASSERT_EQ(0, close(dir_fd));
> + EXPECT_EQ(0, close(dir_fd));
> _exit(_metadata->exit_code);
> return;
> }
>
> - ASSERT_EQ(0, close(socket_fds[1]));
> + EXPECT_EQ(0, close(socket_fds[1]));
>
> /* Checks that the parent is unrestricted. */
> dir_fd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
> ASSERT_LE(0, dir_fd);
> - ASSERT_EQ(0, close(dir_fd));
> + EXPECT_EQ(0, close(dir_fd));
> dir_fd = open("/tmp", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
> ASSERT_LE(0, dir_fd);
> - ASSERT_EQ(0, close(dir_fd));
> + EXPECT_EQ(0, close(dir_fd));
>
> ASSERT_EQ(child, waitpid(child, &status, 0));
> ASSERT_EQ(1, WIFEXITED(status));
> @@ -670,9 +670,9 @@ TEST(useless_quiet_rule_fs)
> ASSERT_EQ(EINVAL, errno);
>
> /* Check that the rule had not been added. */
> - ASSERT_EQ(0, close(root_fd));
> + EXPECT_EQ(0, close(root_fd));
> enforce_ruleset(_metadata, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> ASSERT_EQ(-1, open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC));
> ASSERT_EQ(EACCES, errno);
> @@ -700,7 +700,7 @@ TEST(useless_quiet_rule_net)
> &net_port_attr, LANDLOCK_ADD_RULE_QUIET));
> ASSERT_EQ(EINVAL, errno);
>
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST(invalid_quiet_bits_1)
> diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> index 183dfc42895c..408e4b220e02 100644
> --- a/tools/testing/selftests/landlock/fs_test.c
> +++ b/tools/testing/selftests/landlock/fs_test.c
> @@ -492,7 +492,7 @@ TEST_F_FORK(layout1, inval)
> &path_beneath, 0));
> /* Returns EBADF because ruleset_fd is not a landlock-ruleset FD. */
> ASSERT_EQ(EBADF, errno);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> ruleset_fd = open(dir_s1d1, O_DIRECTORY | O_CLOEXEC);
> ASSERT_LE(0, ruleset_fd);
> @@ -500,7 +500,7 @@ TEST_F_FORK(layout1, inval)
> &path_beneath, 0));
> /* Returns EBADFD because ruleset_fd is not a valid ruleset. */
> ASSERT_EQ(EBADFD, errno);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> /* Gets a real ruleset. */
> ruleset_fd =
> @@ -508,14 +508,14 @@ TEST_F_FORK(layout1, inval)
> ASSERT_LE(0, ruleset_fd);
> ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath, 0));
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
>
> /* Tests without O_PATH. */
> path_beneath.parent_fd = open(dir_s1d2, O_DIRECTORY | O_CLOEXEC);
> ASSERT_LE(0, path_beneath.parent_fd);
> ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath, 0));
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
>
> /* Tests with a ruleset FD. */
> path_beneath.parent_fd = ruleset_fd;
> @@ -556,13 +556,13 @@ TEST_F_FORK(layout1, inval)
> ASSERT_EQ(ENOMSG, errno);
> path_beneath.allowed_access &= ~(1ULL << 60);
>
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
>
> /* Enforces the ruleset. */
> ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0));
> ASSERT_EQ(0, landlock_restrict_self(ruleset_fd, 0));
>
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> /* clang-format off */
> @@ -632,9 +632,9 @@ TEST_F_FORK(layout1, file_and_dir_access_rights)
> ASSERT_EQ(EINVAL, errno);
> }
> }
> - ASSERT_EQ(0, close(path_beneath_file.parent_fd));
> - ASSERT_EQ(0, close(path_beneath_dir.parent_fd));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(path_beneath_file.parent_fd));
> + EXPECT_EQ(0, close(path_beneath_dir.parent_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST_F_FORK(layout0, ruleset_with_unknown_access)
> @@ -676,8 +676,8 @@ TEST_F_FORK(layout0, rule_with_unknown_access)
> &path_beneath, 0));
> EXPECT_EQ(EINVAL, errno);
> }
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST_F_FORK(layout1, rule_with_unhandled_access)
> @@ -734,7 +734,7 @@ static void add_path_beneath(struct __test_metadata *const _metadata,
> TH_LOG("Failed to update the ruleset with \"%s\": %s", path,
> strerror(errno));
> }
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
> }
>
> struct rule {
> @@ -836,7 +836,7 @@ TEST_F_FORK(layout0, proc_nsfs)
> ASSERT_EQ(-1, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath, 0));
> ASSERT_EQ(EBADFD, errno);
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
> }
>
> TEST_F_FORK(layout0, unpriv)
> @@ -859,7 +859,7 @@ TEST_F_FORK(layout0, unpriv)
>
> /* enforce_ruleset() calls prctl(no_new_privs). */
> enforce_ruleset(_metadata, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST_F_FORK(layout1, effective_access)
> @@ -907,14 +907,14 @@ TEST_F_FORK(layout1, effective_access)
> ASSERT_LE(0, lseek(reg_fd, 0, SEEK_SET));
> ASSERT_EQ(1, read(reg_fd, &buf, 1));
> ASSERT_EQ('.', buf);
> - ASSERT_EQ(0, close(reg_fd));
> + EXPECT_EQ(0, close(reg_fd));
>
> /* Just in case, double-checks effective actions. */
> reg_fd = open(file1_s2d2, O_RDONLY | O_CLOEXEC);
> ASSERT_LE(0, reg_fd);
> ASSERT_EQ(-1, write(reg_fd, &buf, 1));
> ASSERT_EQ(EBADF, errno);
> - ASSERT_EQ(0, close(reg_fd));
> + EXPECT_EQ(0, close(reg_fd));
> }
>
> TEST_F_FORK(layout1, unhandled_access)
> @@ -1363,7 +1363,7 @@ TEST_F_FORK(layout1, inherit_subset)
> add_path_beneath(_metadata, ruleset_fd, LANDLOCK_ACCESS_FS_WRITE_FILE,
> dir_s1d3, 0);
> enforce_ruleset(_metadata, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> /*
> * Same tests and results as above, except for open(dir_s1d3) which is
> @@ -1474,7 +1474,7 @@ TEST_F_FORK(layout1, empty_or_same_ruleset)
>
> /* Enforces a second time with the same ruleset. */
> enforce_ruleset(_metadata, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST_F_FORK(layout1, rule_on_mountpoint)
> @@ -1763,7 +1763,7 @@ TEST_F_FORK(layout1, covered_rule)
> ASSERT_EQ(0, test_open(dir_s3d2, O_RDONLY));
>
> enforce_ruleset(_metadata, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> /* Checks that access to the new mount point is denied. */
> ASSERT_EQ(EACCES, test_open(dir_s3d2, O_RDONLY));
> @@ -1886,8 +1886,8 @@ static void test_relative_path(struct __test_metadata *const _metadata,
> }
>
> if (rel == REL_OPEN)
> - ASSERT_EQ(0, close(dirfd));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(dirfd));
> + EXPECT_EQ(0, close(ruleset_fd));
> }
>
> TEST_F_FORK(layout1, relative_open)
> @@ -1929,8 +1929,8 @@ static void copy_file(struct __test_metadata *const _metadata,
> ASSERT_EQ(0, fstat(src_fd, &statbuf));
> ASSERT_EQ(statbuf.st_size,
> sendfile(dst_fd, src_fd, 0, statbuf.st_size));
> - ASSERT_EQ(0, close(src_fd));
> - ASSERT_EQ(0, close(dst_fd));
> + EXPECT_EQ(0, close(src_fd));
> + EXPECT_EQ(0, close(dst_fd));
> }
>
> static void test_execute(struct __test_metadata *const _metadata, const int err,
> @@ -3575,7 +3575,7 @@ TEST_F_FORK(layout1, proc_unlinked_file)
>
> proc_fd = open_proc_fd(_metadata, reg_fd, O_RDONLY | O_CLOEXEC);
> ASSERT_LE(0, proc_fd);
> - ASSERT_EQ(0, close(proc_fd));
> + EXPECT_EQ(0, close(proc_fd));
>
> proc_fd = open_proc_fd(_metadata, reg_fd, O_RDWR | O_CLOEXEC);
> ASSERT_EQ(-1, proc_fd)
> @@ -3585,7 +3585,7 @@ TEST_F_FORK(layout1, proc_unlinked_file)
> }
> ASSERT_EQ(EACCES, errno);
>
> - ASSERT_EQ(0, close(reg_fd));
> + EXPECT_EQ(0, close(reg_fd));
> }
>
> TEST_F_FORK(layout1, proc_pipe)
> @@ -3626,7 +3626,7 @@ TEST_F_FORK(layout1, proc_pipe)
> TH_LOG("Failed to write through /proc/self/fd/%d: %s",
> pipe_fds[1], strerror(errno));
> }
> - ASSERT_EQ(0, close(proc_fd));
> + EXPECT_EQ(0, close(proc_fd));
>
> /* Checks read access to pipe through /proc/self/fd . */
> proc_fd = open_proc_fd(_metadata, pipe_fds[0], O_RDONLY | O_CLOEXEC);
> @@ -3637,10 +3637,10 @@ TEST_F_FORK(layout1, proc_pipe)
> TH_LOG("Failed to read through /proc/self/fd/%d: %s",
> pipe_fds[1], strerror(errno));
> }
> - ASSERT_EQ(0, close(proc_fd));
> + EXPECT_EQ(0, close(proc_fd));
>
> - ASSERT_EQ(0, close(pipe_fds[0]));
> - ASSERT_EQ(0, close(pipe_fds[1]));
> + EXPECT_EQ(0, close(pipe_fds[0]));
> + EXPECT_EQ(0, close(pipe_fds[1]));
> }
>
> /* Invokes truncate(2) and returns its errno or 0. */
> @@ -3901,10 +3901,10 @@ TEST_F_FORK(layout1, ftruncate)
> EXPECT_EQ(0, test_ftruncate(fd_layer2));
> EXPECT_EQ(EACCES, test_ftruncate(fd_layer3));
>
> - ASSERT_EQ(0, close(fd_layer0));
> - ASSERT_EQ(0, close(fd_layer1));
> - ASSERT_EQ(0, close(fd_layer2));
> - ASSERT_EQ(0, close(fd_layer3));
> + EXPECT_EQ(0, close(fd_layer0));
> + EXPECT_EQ(0, close(fd_layer1));
> + EXPECT_EQ(0, close(fd_layer2));
> + EXPECT_EQ(0, close(fd_layer3));
> }
>
> /* clang-format off */
> @@ -3995,7 +3995,7 @@ TEST_F_FORK(ftruncate, open_and_ftruncate)
> if (fd >= 0) {
> EXPECT_EQ(variant->expected_ftruncate_result,
> test_ftruncate(fd));
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
> }
>
> @@ -4032,10 +4032,10 @@ TEST_F_FORK(ftruncate, open_and_ftruncate_in_different_processes)
>
> if (fd >= 0) {
> ASSERT_EQ(0, send_fd(socket_fds[0], fd));
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
>
> - ASSERT_EQ(0, close(socket_fds[0]));
> + EXPECT_EQ(0, close(socket_fds[0]));
>
> _exit(_metadata->exit_code);
> return;
> @@ -4047,15 +4047,15 @@ TEST_F_FORK(ftruncate, open_and_ftruncate_in_different_processes)
>
> EXPECT_EQ(variant->expected_ftruncate_result,
> test_ftruncate(fd));
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
>
> ASSERT_EQ(child, waitpid(child, &status, 0));
> ASSERT_EQ(1, WIFEXITED(status));
> ASSERT_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
>
> - ASSERT_EQ(0, close(socket_fds[0]));
> - ASSERT_EQ(0, close(socket_fds[1]));
> + EXPECT_EQ(0, close(socket_fds[0]));
> + EXPECT_EQ(0, close(socket_fds[1]));
> }
>
> /* Invokes the FS_IOC_GETFLAGS IOCTL and returns its errno or 0. */
> @@ -4089,7 +4089,7 @@ TEST(memfd_ftruncate_and_ioctl)
> EXPECT_EQ(0, test_ftruncate(fd));
> EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd));
>
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
>
> /* Enables Landlock. */
> enforce_fs(_metadata, ACCESS_ALL, NULL);
> @@ -4120,7 +4120,7 @@ TEST_F_FORK(layout1, o_path_ftruncate_and_ioctl)
> EXPECT_EQ(EBADF, test_ftruncate(fd));
> EXPECT_EQ(EBADF, test_fs_ioc_getflags_ioctl(fd));
>
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
>
> /* Enables Landlock. */
> enforce_fs(_metadata, ACCESS_ALL, NULL);
> @@ -4136,7 +4136,7 @@ TEST_F_FORK(layout1, o_path_ftruncate_and_ioctl)
> EXPECT_EQ(EBADF, test_ftruncate(fd));
> EXPECT_EQ(EBADF, test_fs_ioc_getflags_ioctl(fd));
>
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
>
> /* Arbitrary command with nonzero bits in both 16-bit halves. */
> @@ -4171,7 +4171,7 @@ static int ioctl_error(struct __test_metadata *const _metadata, int fd,
>
> /* Restores the old FD 0 and closes the backup FD. */
> ASSERT_EQ(0, dup2(stdinbak_fd, 0));
> - ASSERT_EQ(0, close(stdinbak_fd));
> + EXPECT_EQ(0, close(stdinbak_fd));
>
> if (res < 0)
> return err;
> @@ -4247,7 +4247,7 @@ TEST_F_FORK(layout1, blanket_permitted_ioctls)
> /* Default case is also blocked. */
> EXPECT_EQ(EACCES, ioctl_error(_metadata, fd, unknown_ioctl_cmd));
>
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
>
> /*
> @@ -4281,10 +4281,10 @@ TEST_F_FORK(layout1, named_pipe_ioctl)
> /* FIONREAD is implemented by pipefifo_fops. */
> EXPECT_EQ(0, test_fionread_ioctl(fd));
>
> - ASSERT_EQ(0, close(fd));
> - ASSERT_EQ(0, unlink(path));
> + EXPECT_EQ(0, close(fd));
> + EXPECT_EQ(0, unlink(path));
>
> - ASSERT_EQ(child_pid, waitpid(child_pid, NULL, 0));
> + EXPECT_EQ(child_pid, waitpid(child_pid, NULL, 0));
> }
>
> /*
> @@ -4437,7 +4437,7 @@ TEST_F_FORK(ioctl, handle_dir_access_file)
> EXPECT_EQ(0, ioctl(fd, FIOASYNC, &flag));
> EXPECT_EQ(0, ioctl(fd, FIGETBSZ, &flag));
>
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
>
> TEST_F_FORK(ioctl, handle_dir_access_dir)
> @@ -4479,7 +4479,7 @@ TEST_F_FORK(ioctl, handle_dir_access_dir)
> EXPECT_EQ(0, ioctl(dir_fd, FIOASYNC, &flag));
> EXPECT_EQ(0, ioctl(dir_fd, FIGETBSZ, &flag));
>
> - ASSERT_EQ(0, close(dir_fd));
> + EXPECT_EQ(0, close(dir_fd));
> }
>
> TEST_F_FORK(ioctl, handle_file_access_file)
> @@ -4513,7 +4513,7 @@ TEST_F_FORK(ioctl, handle_file_access_file)
> EXPECT_EQ(0, ioctl(fd, FIOASYNC, &flag));
> EXPECT_EQ(0, ioctl(fd, FIGETBSZ, &flag));
>
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
>
> /*
> @@ -7431,7 +7431,7 @@ TEST_F_FORK(layout3_fs, release_inodes)
> clear_cap(_metadata, CAP_SYS_ADMIN);
>
> enforce_ruleset(_metadata, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> /* Checks that access to the new mount point is denied. */
> ASSERT_EQ(EACCES, test_open(TMP_DIR, O_RDONLY));
> @@ -8164,7 +8164,7 @@ static int apply_a_layer(struct __test_metadata *const _metadata,
> {
> TH_LOG("Failed to enforce ruleset: %s", strerror(errno));
> }
> - ASSERT_EQ(0, close(rs_fd));
> + EXPECT_EQ(0, close(rs_fd));
>
> if (debug_quiet_tests) {
> sprint_access_bits(handled_access_s, sizeof(handled_access_s),
> @@ -8299,7 +8299,7 @@ void audit_quiet_layout1_test_body(struct __test_metadata *const _metadata,
> ASSERT_EQ(0, audit_count_records(self->audit_fd,
> &records));
> ASSERT_EQ(0, records.access);
> - ASSERT_EQ(0, close(fd));
> + EXPECT_EQ(0, close(fd));
> }
> }
> }
> diff --git a/tools/testing/selftests/landlock/ptrace_test.c b/tools/testing/selftests/landlock/ptrace_test.c
> index ea8e4be6659e..f253c6a3a436 100644
> --- a/tools/testing/selftests/landlock/ptrace_test.c
> +++ b/tools/testing/selftests/landlock/ptrace_test.c
> @@ -183,8 +183,8 @@ TEST_F(scoped_domains, trace)
> if (child == 0) {
> char buf_child;
>
> - ASSERT_EQ(0, close(pipe_parent[1]));
> - ASSERT_EQ(0, close(pipe_child[0]));
> + EXPECT_EQ(0, close(pipe_parent[1]));
> + EXPECT_EQ(0, close(pipe_child[0]));
> if (variant->domain_child)
> create_domain(_metadata);
>
> @@ -238,8 +238,8 @@ TEST_F(scoped_domains, trace)
> return;
> }
>
> - ASSERT_EQ(0, close(pipe_child[1]));
> - ASSERT_EQ(0, close(pipe_parent[0]));
> + EXPECT_EQ(0, close(pipe_child[1]));
> + EXPECT_EQ(0, close(pipe_parent[0]));
> if (variant->domain_parent)
> create_domain(_metadata);
>
> @@ -370,8 +370,8 @@ TEST_F(audit, trace)
> if (child == 0) {
> char buf_child;
>
> - ASSERT_EQ(0, close(pipe_parent[1]));
> - ASSERT_EQ(0, close(pipe_child[0]));
> + EXPECT_EQ(0, close(pipe_parent[1]));
> + EXPECT_EQ(0, close(pipe_child[0]));
>
> /* Waits for the parent to be in a domain, if any. */
> ASSERT_EQ(1, read(pipe_parent[0], &buf_child, 1));
> @@ -400,8 +400,8 @@ TEST_F(audit, trace)
> return;
> }
>
> - ASSERT_EQ(0, close(pipe_child[1]));
> - ASSERT_EQ(0, close(pipe_parent[0]));
> + EXPECT_EQ(0, close(pipe_child[1]));
> + EXPECT_EQ(0, close(pipe_parent[0]));
> create_domain(_metadata);
>
> /* Signals that the parent is in a domain. */
> diff --git a/tools/testing/selftests/landlock/trace_fs_test.c b/tools/testing/selftests/landlock/trace_fs_test.c
> index 64014ade3a0e..06161aa6d5d7 100644
> --- a/tools/testing/selftests/landlock/trace_fs_test.c
> +++ b/tools/testing/selftests/landlock/trace_fs_test.c
> @@ -210,8 +210,8 @@ TEST_F(trace_fs, add_rule_path_beneath)
>
> ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath, 0));
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> buf = tracefs_read_buf();
> ASSERT_NE(NULL, buf);
> @@ -274,8 +274,8 @@ TEST_F(trace_fs, add_rule_path_beneath_escaped_path_overflow)
>
> ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath, 0));
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> buf = tracefs_read_buf();
> ASSERT_NE(NULL, buf);
> diff --git a/tools/testing/selftests/landlock/trace_test.c b/tools/testing/selftests/landlock/trace_test.c
> index 1795d41b779f..0effe5d6d973 100644
> --- a/tools/testing/selftests/landlock/trace_test.c
> +++ b/tools/testing/selftests/landlock/trace_test.c
> @@ -163,7 +163,7 @@ TEST_F(trace, create_ruleset)
> ruleset_fd =
> landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
> ASSERT_LE(0, ruleset_fd);
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> buf = tracefs_read_buf();
> ASSERT_NE(NULL, buf);
> @@ -514,7 +514,7 @@ TEST_F(trace, add_rule_invalid_fd)
> /* Invalid ruleset fd (-1). */
> ASSERT_EQ(-1, landlock_add_rule(-1, LANDLOCK_RULE_PATH_BENEATH,
> &path_beneath, 0));
> - ASSERT_EQ(0, close(path_beneath.parent_fd));
> + EXPECT_EQ(0, close(path_beneath.parent_fd));
>
> buf = tracefs_read_buf();
> ASSERT_NE(NULL, buf);
> @@ -550,7 +550,7 @@ TEST_F(trace, create_domain_invalid)
> /* Unknown flags. */
> ASSERT_EQ(-1, landlock_restrict_self(ruleset_fd, -1));
>
> - ASSERT_EQ(0, close(ruleset_fd));
> + EXPECT_EQ(0, close(ruleset_fd));
>
> buf = tracefs_read_buf();
> ASSERT_NE(NULL, buf);
> diff --git a/tools/testing/selftests/landlock/tsync_test.c b/tools/testing/selftests/landlock/tsync_test.c
> index 2b53596c986e..aff973ba4735 100644
> --- a/tools/testing/selftests/landlock/tsync_test.c
> +++ b/tools/testing/selftests/landlock/tsync_test.c
> @@ -152,10 +152,10 @@ TEST_F(multi_threaded, restrict)
> EXPECT_EQ(variant->expected_no_new_privs,
> prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0));
>
> - ASSERT_EQ(0, pthread_cancel(t1));
> - ASSERT_EQ(0, pthread_cancel(t2));
> - ASSERT_EQ(0, pthread_join(t1, NULL));
> - ASSERT_EQ(0, pthread_join(t2, NULL));
> + EXPECT_EQ(0, pthread_cancel(t1));
> + EXPECT_EQ(0, pthread_cancel(t2));
> + EXPECT_EQ(0, pthread_join(t1, NULL));
> + EXPECT_EQ(0, pthread_join(t2, NULL));
Could you leave the ASSERTs here? If cancellation fails, the join can
wait forever. If the join fails, we can't safely check the no_new_privs
value written by the worker.
>
> /* Checks the no_new_privs state of the sibling threads. */
> EXPECT_EQ(variant->expected_no_new_privs, no_new_privs1);
> @@ -184,10 +184,10 @@ TEST(multi_threaded_success_despite_diverging_domains)
> EXPECT_EQ(0, landlock_restrict_self(ruleset_fd,
> LANDLOCK_RESTRICT_SELF_TSYNC));
>
> - ASSERT_EQ(0, pthread_cancel(t1));
> - ASSERT_EQ(0, pthread_cancel(t2));
> - ASSERT_EQ(0, pthread_join(t1, NULL));
> - ASSERT_EQ(0, pthread_join(t2, NULL));
> + EXPECT_EQ(0, pthread_cancel(t1));
> + EXPECT_EQ(0, pthread_cancel(t2));
> + EXPECT_EQ(0, pthread_join(t1, NULL));
> + EXPECT_EQ(0, pthread_join(t2, NULL));
> EXPECT_EQ(0, close(ruleset_fd));
> }
>
> @@ -309,11 +309,11 @@ TEST(tsync_interrupt)
> LANDLOCK_RESTRICT_SELF_TSYNC));
>
> sd.stop = true;
> - ASSERT_EQ(0, pthread_join(signaler, NULL));
> + EXPECT_EQ(0, pthread_join(signaler, NULL));
>
> for (i = 0; i < NUM_IDLE_THREADS; i++) {
> - ASSERT_EQ(0, pthread_cancel(threads[i]));
> - ASSERT_EQ(0, pthread_join(threads[i], NULL));
> + EXPECT_EQ(0, pthread_cancel(threads[i]));
> + EXPECT_EQ(0, pthread_join(threads[i], NULL));
> }
>
> EXPECT_EQ(0, close(ruleset_fd));
>
> --
> 2.56.0
>
>
next prev parent reply other threads:[~2026-12-04 17:08 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 21:08 [PATCH v2 00/27] landlock: Selftest fixes and cleanups Günther Noack
2026-11-04 21:08 ` [PATCH v2 01/27] selftests/landlock: Propagate grandchild failures in unix_scoping Günther Noack
2026-11-04 21:08 ` [PATCH v2 02/27] selftests/landlock: Propagate EXPECT failures from forked children Günther Noack
2026-11-04 21:08 ` [PATCH v2 03/27] selftests/landlock: Check the thread result in audit.thread Günther Noack
2026-11-04 21:08 ` [PATCH v2 04/27] selftests/landlock: Zero-initialize the buffer in inconsistent_attr Günther Noack
2026-11-04 21:08 ` [PATCH v2 05/27] selftests/landlock: Fix the openat() success check in fs_bench Günther Noack
2026-11-04 21:08 ` [PATCH v2 06/27] selftests/landlock: Fix the reported clock tick rate " Günther Noack
2026-11-04 21:08 ` [PATCH v2 07/27] selftests/landlock: Fix the ruleset_fd check in empty_or_same_ruleset Günther Noack
2026-11-04 21:08 ` [PATCH v2 08/27] selftests/landlock: Handle a missing control message in recv_fd() Günther Noack
2026-11-04 21:08 ` [PATCH v2 09/27] selftests/landlock: Assert tracefs_extract_field() results that are used Günther Noack
2026-11-04 21:08 ` [PATCH v2 10/27] selftests/landlock: Assert audit initialization in fixture setups Günther Noack
2026-11-04 21:08 ` [PATCH v2 11/27] selftests/landlock: Assert helper results that are used afterwards Günther Noack
2026-12-04 17:07 ` Mickaël Salaün
2026-11-04 21:08 ` [PATCH v2 12/27] selftests/landlock: Assert audit_count_records() before using its result Günther Noack
2026-12-04 17:07 ` Mickaël Salaün
2026-11-04 21:08 ` [PATCH v2 13/27] selftests/landlock: Fix memory leak in audit_init_filter_exe() Günther Noack
2026-11-04 21:09 ` [PATCH v2 14/27] selftests/landlock: Make audit_message large enough for any exe filter Günther Noack
2026-11-04 21:09 ` [PATCH v2 15/27] selftests/landlock: Close leaked file descriptors Günther Noack
2026-11-04 21:09 ` [PATCH v2 16/27] selftests/landlock: Check errno for combined VERSION and ERRATA flags Günther Noack
2026-11-04 21:09 ` [PATCH v2 17/27] selftests/landlock: Fix SIGURG handler setup in scoped_signal_test Günther Noack
2026-11-04 21:09 ` [PATCH v2 18/27] selftests/landlock: Fix regex_escape() error handling in matches_log_fs_extra() Günther Noack
2026-11-04 21:09 ` [PATCH v2 19/27] selftests/landlock: Fix off-by-one in regex_escape() Günther Noack
2026-11-04 21:09 ` [PATCH v2 20/27] selftests/landlock: Fix the snprintf() error check in matches_log_fs_extra() Günther Noack
2026-11-04 21:09 ` [PATCH v2 21/27] selftests/landlock: Use _exit() in the named_pipe_ioctl child Günther Noack
2026-11-04 21:09 ` [PATCH v2 22/27] selftests/landlock: Fix messages and comments in helper programs Günther Noack
2026-11-04 21:09 ` [PATCH v2 23/27] selftests/landlock: Fix stale comments in common.h and audit.h Günther Noack
2026-11-04 21:09 ` [PATCH v2 24/27] selftests/landlock: Use ASSERT for syscall failures before errno checks Günther Noack
2026-12-04 17:07 ` Mickaël Salaün
2026-11-04 21:09 ` [PATCH v2 25/27] selftests/landlock: Assert WIFEXITED() before checking the exit status Günther Noack
2026-12-04 17:08 ` Mickaël Salaün
2026-11-04 21:09 ` [PATCH v2 26/27] selftests/landlock: Use EXPECT for closing FDs and stopping threads Günther Noack
2026-12-04 17:08 ` Mickaël Salaün [this message]
2026-11-04 21:09 ` [PATCH v2 27/27] selftests/landlock: Use EXPECT for checks that later steps do not need Günther Noack
2026-12-04 17:08 ` Mickaël Salaün
2026-12-04 17:07 ` [PATCH v2 00/27] landlock: Selftest fixes and cleanups Mickaël Salaün
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204.iJah2viiboov@digikod.net \
--to=mic@digikod.net \
--cc=gnoack3000@gmail.com \
--cc=gnoack@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox