Skip to content

Commit 4acbce0

Browse files
Geliang TangKernel Patches Daemon
authored andcommitted
selftests/bpf: Skip ENOTSUPP in ASSERT_OK
Just like handling ENOTSUPP in test_lsm_cgroup_functional(), this patch adds a new helper test_progs_get_error() to check whether the input error is ENOTSUPP (524) or ENOTSUP (95). If it is, invoke test__skip() to skip the test instead of using test__fail(). Use this helper in ASSERT_OK() before invoking CHECK() macro. Signed-off-by: Geliang Tang <[email protected]>
1 parent bf33088 commit 4acbce0

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,8 @@ static void test_lsm_cgroup_functional(void)
102102
ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 0, "prog count");
103103
ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 0, "total prog count");
104104
err = bpf_prog_attach(alloc_prog_fd, cgroup_fd, BPF_LSM_CGROUP, 0);
105-
if (err == -ENOTSUPP) {
106-
test__skip();
107-
goto close_cgroup;
108-
}
109105
if (!ASSERT_OK(err, "attach alloc_prog_fd"))
110-
goto detach_cgroup;
106+
goto close_cgroup;
111107
ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 1, "prog count");
112108
ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 1, "total prog count");
113109

tools/testing/selftests/bpf/test_progs.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,23 @@ void test__skip(void);
176176
void test__fail(void);
177177
int test__join_cgroup(const char *path);
178178

179+
static inline bool test_progs_check_errno(int error, int check)
180+
{
181+
return error == -check ||
182+
(error && errno == check);
183+
}
184+
185+
static inline int test_progs_get_error(int error)
186+
{
187+
if (test_progs_check_errno(error, ENOTSUP) ||
188+
test_progs_check_errno(error, ENOTSUPP)) {
189+
test__skip();
190+
return 0;
191+
} else {
192+
return error;
193+
}
194+
}
195+
179196
#define PRINT_FAIL(format...) \
180197
({ \
181198
test__fail(); \
@@ -338,8 +355,10 @@ int test__join_cgroup(const char *path);
338355
static int duration = 0; \
339356
long long ___res = (res); \
340357
bool ___ok = ___res == 0; \
341-
CHECK(!___ok, (name), "unexpected error: %lld (errno %d)\n", \
342-
___res, errno); \
358+
if (test_progs_get_error(___res)) \
359+
CHECK(!___ok, (name), \
360+
"unexpected error: %lld (errno %d)\n", \
361+
___res, errno); \
343362
___ok; \
344363
})
345364

0 commit comments

Comments
 (0)