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

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Add test for __nullable suffix in tp_btf

Add a tracepoint with __nullable suffix in bpf_testmod, and add cases
for it:

$ ./test_progs -t "tp_btf_nullable"
#406/1 tp_btf_nullable/handle_tp_btf_nullable_bare1:OK
#406/2 tp_btf_nullable/handle_tp_btf_nullable_bare2:OK
#406 tp_btf_nullable:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Philo Lu <lulie@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240911033719.91468-3-lulie@linux.alibaba.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Philo Lu and committed by
Martin KaFai Lau
2060f07f 8aeaed21

+46
+6
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
··· 34 34 TP_ARGS(task, ctx) 35 35 ); 36 36 37 + /* Used in bpf_testmod_test_read() to test __nullable suffix */ 38 + DECLARE_TRACE(bpf_testmod_test_nullable_bare, 39 + TP_PROTO(struct bpf_testmod_test_read_ctx *ctx__nullable), 40 + TP_ARGS(ctx__nullable) 41 + ); 42 + 37 43 #undef BPF_TESTMOD_DECLARE_TRACE 38 44 #ifdef DECLARE_TRACE_WRITABLE 39 45 #define BPF_TESTMOD_DECLARE_TRACE(call, proto, args, size) \
+2
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
··· 356 356 if (bpf_testmod_loop_test(101) > 100) 357 357 trace_bpf_testmod_test_read(current, &ctx); 358 358 359 + trace_bpf_testmod_test_nullable_bare(NULL); 360 + 359 361 /* Magic number to enable writable tp */ 360 362 if (len == 64) { 361 363 struct bpf_testmod_test_writable_ctx writable = {
+14
tools/testing/selftests/bpf/prog_tests/tp_btf_nullable.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <test_progs.h> 4 + #include "test_tp_btf_nullable.skel.h" 5 + 6 + void test_tp_btf_nullable(void) 7 + { 8 + if (!env.has_testmod) { 9 + test__skip(); 10 + return; 11 + } 12 + 13 + RUN_TESTS(test_tp_btf_nullable); 14 + }
+24
tools/testing/selftests/bpf/progs/test_tp_btf_nullable.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include "vmlinux.h" 4 + #include <bpf/bpf_helpers.h> 5 + #include <bpf/bpf_tracing.h> 6 + #include "../bpf_testmod/bpf_testmod.h" 7 + #include "bpf_misc.h" 8 + 9 + SEC("tp_btf/bpf_testmod_test_nullable_bare") 10 + __failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'") 11 + int BPF_PROG(handle_tp_btf_nullable_bare1, struct bpf_testmod_test_read_ctx *nullable_ctx) 12 + { 13 + return nullable_ctx->len; 14 + } 15 + 16 + SEC("tp_btf/bpf_testmod_test_nullable_bare") 17 + int BPF_PROG(handle_tp_btf_nullable_bare2, struct bpf_testmod_test_read_ctx *nullable_ctx) 18 + { 19 + if (nullable_ctx) 20 + return nullable_ctx->len; 21 + return 0; 22 + } 23 + 24 + char _license[] SEC("license") = "GPL";