selftests/bpf: livepatch_trampoline: skip when prerequisites are missing
Subsystems (3)
PATCH v3 1/1 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.
---
v3:
- Skip on -ENOENT from load_livepatch() instead of duplicating module path logic (suggested by Jiri Olsa)
- Tested: ./test_progs -t livepatch_trampoline (SKIP when livepatch-sample.ko missing)
v2:
- Skip when /sys/kernel/livepatch is missing
- Guard sysfs write in unload_livepatch() when enabled knob is absent
v2: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
v1: https://patchew.org/linux/[email protected]/
.../bpf/prog_tests/livepatch_trampoline.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c +20 -2
@@ -2,9 +2,13 @@/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ #include <test_progs.h> +#include <errno.h> +#include <unistd.h> #include "testing_helpers.h" #include "livepatch_trampoline.skel.h" +#define LIVEPATCH_ENABLED_PATH "/sys/kernel/livepatch/livepatch_sample/enabled" +static int load_livepatch (void ) {char path[4096 ];
@@ -19,7 +23,8 @@ static int load_livepatch(void)static void unload_livepatch (void ) {/* Disable the livepatch before unloading the module */ -system ("echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled" ); +if (!access (LIVEPATCH_ENABLED_PATH ,F_OK )) +system ("echo 0 > " LIVEPATCH_ENABLED_PATH );unload_module ("livepatch_sample" , env_verbosity >VERBOSE_NONE ); }
@@ -81,9 +86,22 @@ static void __test_livepatch_trampoline(bool fexit_first)void test_livepatch_trampoline (void ) {int retry_cnt =0 ; +int err; + +/* Skip if kernel was built without CONFIG_LIVEPATCH */ +if (access ("/sys/kernel/livepatch" ,F_OK )) { +test__skip (); +return ; + } retry: -if (load_livepatch ()) { + err =load_livepatch (); +if (err) { +if (err == -ENOENT ) { +test__skip (); +return ; + } +if (retry_cnt) {ASSERT_OK (1 ,"load_livepatch" ); goto out;
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
Signature · 1 line
2.43.0
On Mon, Mar 09, 2026 at 11:37:12AM +0800, Sun Jian wrote:
[...]
tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c line 5
Quoted 12 lines
.../bpf/prog_tests/livepatch_trampoline.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c +1
-0@@ -2,9 +2,13 @@/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ #include <test_progs.h> +#include <errno.h>
NIT: #include <errno.h> is unnecessary — it's already pulled in by test_progs.h.
Other than that, the patch looks good to me.
Quoted 48 lines
tools/testing/selftests/bpf/prog_tests/livepatch_trampoline.c +19
-2+#include <unistd.h> #include "testing_helpers.h" #include "livepatch_trampoline.skel.h" +#define LIVEPATCH_ENABLED_PATH "/sys/kernel/livepatch/livepatch_sample/enabled" +static int load_livepatch (void ) {char path[4096 ];@@ -19,7 +23,8 @@ static int load_livepatch(void)static void unload_livepatch (void ) {/* Disable the livepatch before unloading the module */ -system ("echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled" ); +if (!access (LIVEPATCH_ENABLED_PATH ,F_OK )) +system ("echo 0 > " LIVEPATCH_ENABLED_PATH );unload_module ("livepatch_sample" , env_verbosity >VERBOSE_NONE ); }@@ -81,9 +86,22 @@ static void __test_livepatch_trampoline(bool fexit_first)void test_livepatch_trampoline (void ) {int retry_cnt =0 ; +int err; + +/* Skip if kernel was built without CONFIG_LIVEPATCH */ +if (access ("/sys/kernel/livepatch" ,F_OK )) { +test__skip (); +return ; + } retry: -if (load_livepatch ()) { + err =load_livepatch (); +if (err) { +if (err == -ENOENT ) { +test__skip (); +return ; + } +if (retry_cnt) {ASSERT_OK (1 ,"load_livepatch" ); goto out;base-commit:
1f318b96cc84d7c2ab792fcc0bfd42a7ca890681Signature · 1 line
2.43.0