A failed ASSERT in a forked child calls abort(), so the parent sees
the child die from a signal and the test fails.  A failed EXPECT only
sets _metadata->exit_code, and a child that exits with a fixed status
of 0 hides that failure from the parent.  The child in
trace_fown.deny_scope_fown has this problem.

Exit with _metadata->exit_code in that child.  Do the same in the
audit.log_subdomains_off_fork children.  They only use ASSERT for now,
but this keeps them correct when a check becomes an EXPECT.

Assisted-by: LLM
Signed-off-by: Günther Noack <[email protected]>
---
 tools/testing/selftests/landlock/audit_test.c         | 4 ++--
 tools/testing/selftests/landlock/scoped_signal_test.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/landlock/audit_test.c 
b/tools/testing/selftests/landlock/audit_test.c
index 4bea8c880a4d..502a0825d877 100644
--- a/tools/testing/selftests/landlock/audit_test.c
+++ b/tools/testing/selftests/landlock/audit_test.c
@@ -314,7 +314,7 @@ TEST_F(audit, log_subdomains_off_fork)
                ASSERT_EQ(0, landlock_restrict_self(ruleset_fd, 0));
                ASSERT_EQ(-1, kill(getppid(), 0));
                ASSERT_EQ(EPERM, errno);
-               _exit(0);
+               _exit(_metadata->exit_code);
                return;
        }
 
@@ -347,7 +347,7 @@ TEST_F(audit, log_subdomains_off_fork)
                ASSERT_EQ(0, landlock_restrict_self(ruleset_fd, 0));
                ASSERT_EQ(-1, kill(getppid(), 0));
                ASSERT_EQ(EPERM, errno);
-               _exit(0);
+               _exit(_metadata->exit_code);
                return;
        }
 
diff --git a/tools/testing/selftests/landlock/scoped_signal_test.c 
b/tools/testing/selftests/landlock/scoped_signal_test.c
index 259cdcc8aa5c..47307dd2e242 100644
--- a/tools/testing/selftests/landlock/scoped_signal_test.c
+++ b/tools/testing/selftests/landlock/scoped_signal_test.c
@@ -1090,7 +1090,7 @@ TEST_F(trace_fown, deny_scope_fown)
                ASSERT_EQ(1, write(pipe_child[1], ".", 1));
                EXPECT_EQ(0, close(pipe_child[1]));
 
-               _exit(0);
+               _exit(_metadata->exit_code);
                return;
        }
        EXPECT_EQ(0, close(pipe_parent[0]));
-- 
2.56.0


Reply via email to