Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add selftest for attaching fexit to __noreturn functions

The reuslt:

$ tools/testing/selftests/bpf/test_progs --name=fexit_noreturns
#99/1 fexit_noreturns/noreturns:OK
#99 fexit_noreturns:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Link: https://lore.kernel.org/r/20250318114447.75484-3-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Yafang Shao and committed by
Alexei Starovoitov
be16ddea cfe816d4

+24
+9
tools/testing/selftests/bpf/prog_tests/fexit_noreturns.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <test_progs.h> 4 + #include "fexit_noreturns.skel.h" 5 + 6 + void test_fexit_noreturns(void) 7 + { 8 + RUN_TESTS(fexit_noreturns); 9 + }
+15
tools/testing/selftests/bpf/progs/fexit_noreturns.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/bpf.h> 4 + #include <bpf/bpf_helpers.h> 5 + #include <bpf/bpf_tracing.h> 6 + #include "bpf_misc.h" 7 + 8 + char _license[] SEC("license") = "GPL"; 9 + 10 + SEC("fexit/do_exit") 11 + __failure __msg("Attaching fexit/fmod_ret to __noreturn functions is rejected.") 12 + int BPF_PROG(noreturns) 13 + { 14 + return 0; 15 + }