[PATCH 11/27] selftests/landlock: Assert helper results that are used afterwards
From: Günther Noack
Date: Thu Oct 08 2026 - 10:28:38 EST
Some helpers check a result with EXPECT_*() and then use it:
cap_get_proc() in _init_caps() and _change_cap(), and
landlock_create_ruleset() in drop_access_rights(), create_domain() and
create_fs_domain(). On failure they pass NULL or -1 to the next calls,
which then fail with misleading messages.
Use ASSERT_*() for these checks, as create_scoped_domain() already does.
Assisted-by: LLM
Signed-off-by: Günther Noack <gnoack3000@xxxxxxxxx>
---
tools/testing/selftests/landlock/common.h | 6 +++---
tools/testing/selftests/landlock/ptrace_test.c | 2 +-
.../testing/selftests/landlock/scoped_abstract_unix_test.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h
index e195c0f48eb3..e1aa0ec02c96 100644
--- a/tools/testing/selftests/landlock/common.h
+++ b/tools/testing/selftests/landlock/common.h
@@ -53,7 +53,7 @@ static void _init_caps(struct __test_metadata *const _metadata, bool drop_all)
EXPECT_EQ(0, cap_set_secbits(noroot));
cap_p = cap_get_proc();
- EXPECT_NE(NULL, cap_p);
+ ASSERT_NE(NULL, cap_p);
EXPECT_NE(-1, cap_clear(cap_p));
if (!drop_all) {
EXPECT_NE(-1, cap_set_flag(cap_p, CAP_PERMITTED,
@@ -89,7 +89,7 @@ static void _change_cap(struct __test_metadata *const _metadata,
cap_t cap_p;
cap_p = cap_get_proc();
- EXPECT_NE(NULL, cap_p);
+ ASSERT_NE(NULL, cap_p);
EXPECT_NE(-1, cap_set_flag(cap_p, flag, 1, &cap, value));
EXPECT_NE(-1, cap_set_proc(cap_p))
{
@@ -214,7 +214,7 @@ drop_access_rights(struct __test_metadata *const _metadata,
ruleset_fd =
landlock_create_ruleset(ruleset_attr, sizeof(*ruleset_attr), 0);
- EXPECT_LE(0, ruleset_fd)
+ ASSERT_LE(0, ruleset_fd)
{
TH_LOG("Failed to create a ruleset: %s", strerror(errno));
}
diff --git a/tools/testing/selftests/landlock/ptrace_test.c b/tools/testing/selftests/landlock/ptrace_test.c
index 10371c1830ad..b951889cd6ca 100644
--- a/tools/testing/selftests/landlock/ptrace_test.c
+++ b/tools/testing/selftests/landlock/ptrace_test.c
@@ -37,7 +37,7 @@ static void create_domain(struct __test_metadata *const _metadata)
ruleset_fd =
landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
- EXPECT_LE(0, ruleset_fd)
+ ASSERT_LE(0, ruleset_fd)
{
TH_LOG("Failed to create a ruleset: %s", strerror(errno));
}
diff --git a/tools/testing/selftests/landlock/scoped_abstract_unix_test.c b/tools/testing/selftests/landlock/scoped_abstract_unix_test.c
index 5e8224623780..55a1599819c8 100644
--- a/tools/testing/selftests/landlock/scoped_abstract_unix_test.c
+++ b/tools/testing/selftests/landlock/scoped_abstract_unix_test.c
@@ -40,7 +40,7 @@ static void create_fs_domain(struct __test_metadata *const _metadata)
ruleset_fd =
landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
- EXPECT_LE(0, ruleset_fd)
+ ASSERT_LE(0, ruleset_fd)
{
TH_LOG("Failed to create a ruleset: %s", strerror(errno));
}
--
2.56.0