xref: /linux/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h (revision 9410645520e9b820069761f3450ef6661418e279)
19f7fa225SAndrii Nakryiko /* SPDX-License-Identifier: GPL-2.0 */
29f7fa225SAndrii Nakryiko /* Copyright (c) 2020 Facebook */
39f7fa225SAndrii Nakryiko #undef TRACE_SYSTEM
49f7fa225SAndrii Nakryiko #define TRACE_SYSTEM bpf_testmod
59f7fa225SAndrii Nakryiko 
69f7fa225SAndrii Nakryiko #if !defined(_BPF_TESTMOD_EVENTS_H) || defined(TRACE_HEADER_MULTI_READ)
79f7fa225SAndrii Nakryiko #define _BPF_TESTMOD_EVENTS_H
89f7fa225SAndrii Nakryiko 
99f7fa225SAndrii Nakryiko #include <linux/tracepoint.h>
109f7fa225SAndrii Nakryiko #include "bpf_testmod.h"
119f7fa225SAndrii Nakryiko 
129f7fa225SAndrii Nakryiko TRACE_EVENT(bpf_testmod_test_read,
139f7fa225SAndrii Nakryiko 	TP_PROTO(struct task_struct *task, struct bpf_testmod_test_read_ctx *ctx),
149f7fa225SAndrii Nakryiko 	TP_ARGS(task, ctx),
159f7fa225SAndrii Nakryiko 	TP_STRUCT__entry(
169f7fa225SAndrii Nakryiko 		__field(pid_t, pid)
179f7fa225SAndrii Nakryiko 		__array(char, comm, TASK_COMM_LEN)
189f7fa225SAndrii Nakryiko 		__field(loff_t, off)
199f7fa225SAndrii Nakryiko 		__field(size_t, len)
209f7fa225SAndrii Nakryiko 	),
219f7fa225SAndrii Nakryiko 	TP_fast_assign(
229f7fa225SAndrii Nakryiko 		__entry->pid = task->pid;
239f7fa225SAndrii Nakryiko 		memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
249f7fa225SAndrii Nakryiko 		__entry->off = ctx->off;
259f7fa225SAndrii Nakryiko 		__entry->len = ctx->len;
269f7fa225SAndrii Nakryiko 	),
279f7fa225SAndrii Nakryiko 	TP_printk("pid=%d comm=%s off=%llu len=%zu",
289f7fa225SAndrii Nakryiko 		  __entry->pid, __entry->comm, __entry->off, __entry->len)
299f7fa225SAndrii Nakryiko );
309f7fa225SAndrii Nakryiko 
31407be922SQais Yousef /* A bare tracepoint with no event associated with it */
32407be922SQais Yousef DECLARE_TRACE(bpf_testmod_test_write_bare,
33407be922SQais Yousef 	TP_PROTO(struct task_struct *task, struct bpf_testmod_test_write_ctx *ctx),
34407be922SQais Yousef 	TP_ARGS(task, ctx)
35407be922SQais Yousef );
36407be922SQais Yousef 
37*2060f07fSPhilo Lu /* Used in bpf_testmod_test_read() to test __nullable suffix */
38*2060f07fSPhilo Lu DECLARE_TRACE(bpf_testmod_test_nullable_bare,
39*2060f07fSPhilo Lu 	TP_PROTO(struct bpf_testmod_test_read_ctx *ctx__nullable),
40*2060f07fSPhilo Lu 	TP_ARGS(ctx__nullable)
41*2060f07fSPhilo Lu );
42*2060f07fSPhilo Lu 
43fa7f17d0SHou Tao #undef BPF_TESTMOD_DECLARE_TRACE
44fa7f17d0SHou Tao #ifdef DECLARE_TRACE_WRITABLE
45fa7f17d0SHou Tao #define BPF_TESTMOD_DECLARE_TRACE(call, proto, args, size) \
46fa7f17d0SHou Tao 	DECLARE_TRACE_WRITABLE(call, PARAMS(proto), PARAMS(args), size)
47fa7f17d0SHou Tao #else
48fa7f17d0SHou Tao #define BPF_TESTMOD_DECLARE_TRACE(call, proto, args, size) \
49fa7f17d0SHou Tao 	DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
50fa7f17d0SHou Tao #endif
51fa7f17d0SHou Tao 
52fa7f17d0SHou Tao BPF_TESTMOD_DECLARE_TRACE(bpf_testmod_test_writable_bare,
53fa7f17d0SHou Tao 	TP_PROTO(struct bpf_testmod_test_writable_ctx *ctx),
54fa7f17d0SHou Tao 	TP_ARGS(ctx),
55fa7f17d0SHou Tao 	sizeof(struct bpf_testmod_test_writable_ctx)
56fa7f17d0SHou Tao );
57fa7f17d0SHou Tao 
589f7fa225SAndrii Nakryiko #endif /* _BPF_TESTMOD_EVENTS_H */
599f7fa225SAndrii Nakryiko 
609f7fa225SAndrii Nakryiko #undef TRACE_INCLUDE_PATH
619f7fa225SAndrii Nakryiko #define TRACE_INCLUDE_PATH .
629f7fa225SAndrii Nakryiko #define TRACE_INCLUDE_FILE bpf_testmod-events
639f7fa225SAndrii Nakryiko #include <trace/define_trace.h>
64