Skip to content

Commit a8524cb

Browse files
ahjf-07Kernel Patches Daemon
authored andcommitted
selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
livepatch_trampoline relies on livepatch sysfs and livepatch-sample.ko. When CONFIG_LIVEPATCH is disabled or the samples module isn't built, the test fails with ENOENT and causes false failures in minimal CI configs. Skip the test when livepatch sysfs or the sample module is unavailable. Also avoid writing to livepatch sysfs when it's not present. Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com> Acked-by: Jiri Olsa <jolsa@kernel.org>
1 parent 94aca0b commit a8524cb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "testing_helpers.h"
66
#include "livepatch_trampoline.skel.h"
77

8+
#define LIVEPATCH_ENABLED_PATH "/sys/kernel/livepatch/livepatch_sample/enabled"
9+
810
static int load_livepatch(void)
911
{
1012
char path[4096];
@@ -19,7 +21,8 @@ static int load_livepatch(void)
1921
static void unload_livepatch(void)
2022
{
2123
/* Disable the livepatch before unloading the module */
22-
system("echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled");
24+
if (!access(LIVEPATCH_ENABLED_PATH, F_OK))
25+
system("echo 0 > " LIVEPATCH_ENABLED_PATH);
2326

2427
unload_module("livepatch_sample", env_verbosity > VERBOSE_NONE);
2528
}
@@ -81,9 +84,22 @@ static void __test_livepatch_trampoline(bool fexit_first)
8184
void test_livepatch_trampoline(void)
8285
{
8386
int retry_cnt = 0;
87+
int err;
88+
89+
/* Skip if kernel was built without CONFIG_LIVEPATCH */
90+
if (access("/sys/kernel/livepatch", F_OK)) {
91+
test__skip();
92+
return;
93+
}
8494

8595
retry:
86-
if (load_livepatch()) {
96+
err = load_livepatch();
97+
if (err) {
98+
if (err == -ENOENT) {
99+
test__skip();
100+
return;
101+
}
102+
87103
if (retry_cnt) {
88104
ASSERT_OK(1, "load_livepatch");
89105
goto out;

0 commit comments

Comments
 (0)