Skip to content

Commit 0742f10

Browse files
Philo Luintel-lab-lkp
Philo Lu
authored andcommitted
selftests/bpf: Add test for __nullable suffix in tp_btf
Add a tracepoint with __nullable suffix in bpf_testmod, and add a failure load case: $./test_progs -t "module_attach" torvalds#173/1 module_attach/handle_tp_btf_nullable_bare:OK torvalds#173 module_attach:OK Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Philo Lu <[email protected]>
1 parent 8856cf0 commit 0742f10

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ DECLARE_TRACE(bpf_testmod_test_write_bare,
3434
TP_ARGS(task, ctx)
3535
);
3636

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+
3743
#undef BPF_TESTMOD_DECLARE_TRACE
3844
#ifdef DECLARE_TRACE_WRITABLE
3945
#define BPF_TESTMOD_DECLARE_TRACE(call, proto, args, size) \

tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
394394
if (bpf_testmod_loop_test(101) > 100)
395395
trace_bpf_testmod_test_read(current, &ctx);
396396

397+
trace_bpf_testmod_test_nullable_bare(NULL);
398+
397399
/* Magic number to enable writable tp */
398400
if (len == 64) {
399401
struct bpf_testmod_test_writable_ctx writable = {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <test_progs.h>
55
#include <stdbool.h>
66
#include "test_module_attach.skel.h"
7+
#include "test_module_attach_fail.skel.h"
78
#include "testing_helpers.h"
89

910
static int duration;
@@ -33,7 +34,7 @@ static int trigger_module_test_writable(int *val)
3334
return 0;
3435
}
3536

36-
void test_module_attach(void)
37+
static void module_attach_succ(void)
3738
{
3839
const int READ_SZ = 456;
3940
const int WRITE_SZ = 457;
@@ -115,3 +116,14 @@ void test_module_attach(void)
115116
cleanup:
116117
test_module_attach__destroy(skel);
117118
}
119+
120+
static void module_attach_fail(void)
121+
{
122+
RUN_TESTS(test_module_attach_fail);
123+
}
124+
125+
void test_module_attach(void)
126+
{
127+
module_attach_succ();
128+
module_attach_fail();
129+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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("invalid mem access")
11+
int BPF_PROG(handle_tp_btf_nullable_bare, struct bpf_testmod_test_read_ctx *nullable_ctx)
12+
{
13+
return nullable_ctx->len;
14+
}
15+
16+
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)