Skip to content

Commit 37739d1

Browse files
vadorovskyAlexei Starovoitov
authored andcommitted
selftests: bpf: Move bpf_printk to bpf_helpers.h
bpf_printk is a macro which is commonly used to print out debug messages in BPF programs and it was copied in many selftests and samples. Since all of them include bpf_helpers.h, this change moves the macro there. Signed-off-by: Michal Rostecki <mrostecki@opensuse.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 5762a20 commit 37739d1

File tree

7 files changed

+8
-42
lines changed

7 files changed

+8
-42
lines changed

tools/testing/selftests/bpf/bpf_helpers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
*/
99
#define SEC(NAME) __attribute__((section(NAME), used))
1010

11+
/* helper macro to print out debug messages */
12+
#define bpf_printk(fmt, ...) \
13+
({ \
14+
char ____fmt[] = fmt; \
15+
bpf_trace_printk(____fmt, sizeof(____fmt), \
16+
##__VA_ARGS__); \
17+
})
18+
1119
/* helper functions called from eBPF programs written in C */
1220
static void *(*bpf_map_lookup_elem)(void *map, const void *key) =
1321
(void *) BPF_FUNC_map_lookup_elem;

tools/testing/selftests/bpf/progs/sockmap_parse_prog.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55

66
int _version SEC("version") = 1;
77

8-
#define bpf_printk(fmt, ...) \
9-
({ \
10-
char ____fmt[] = fmt; \
11-
bpf_trace_printk(____fmt, sizeof(____fmt), \
12-
##__VA_ARGS__); \
13-
})
14-
158
SEC("sk_skb1")
169
int bpf_prog1(struct __sk_buff *skb)
1710
{

tools/testing/selftests/bpf/progs/sockmap_tcp_msg_prog.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55

66
int _version SEC("version") = 1;
77

8-
#define bpf_printk(fmt, ...) \
9-
({ \
10-
char ____fmt[] = fmt; \
11-
bpf_trace_printk(____fmt, sizeof(____fmt), \
12-
##__VA_ARGS__); \
13-
})
14-
158
SEC("sk_msg1")
169
int bpf_prog1(struct sk_msg_md *msg)
1710
{

tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55

66
int _version SEC("version") = 1;
77

8-
#define bpf_printk(fmt, ...) \
9-
({ \
10-
char ____fmt[] = fmt; \
11-
bpf_trace_printk(____fmt, sizeof(____fmt), \
12-
##__VA_ARGS__); \
13-
})
14-
158
struct bpf_map_def SEC("maps") sock_map_rx = {
169
.type = BPF_MAP_TYPE_SOCKMAP,
1710
.key_size = sizeof(int),

tools/testing/selftests/bpf/progs/test_lwt_seg6local.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
#include "bpf_helpers.h"
77
#include "bpf_endian.h"
88

9-
#define bpf_printk(fmt, ...) \
10-
({ \
11-
char ____fmt[] = fmt; \
12-
bpf_trace_printk(____fmt, sizeof(____fmt), \
13-
##__VA_ARGS__); \
14-
})
15-
169
/* Packet parsing state machine helpers. */
1710
#define cursor_advance(_cursor, _len) \
1811
({ void *_tmp = _cursor; _cursor += _len; _tmp; })

tools/testing/selftests/bpf/progs/test_xdp_noinline.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
#include <linux/udp.h>
1616
#include "bpf_helpers.h"
1717

18-
#define bpf_printk(fmt, ...) \
19-
({ \
20-
char ____fmt[] = fmt; \
21-
bpf_trace_printk(____fmt, sizeof(____fmt), \
22-
##__VA_ARGS__); \
23-
})
24-
2518
static __u32 rol32(__u32 word, unsigned int shift)
2619
{
2720
return (word << shift) | (word >> ((-shift) & 31));

tools/testing/selftests/bpf/test_sockmap_kern.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@
2828
* are established and verdicts are decided.
2929
*/
3030

31-
#define bpf_printk(fmt, ...) \
32-
({ \
33-
char ____fmt[] = fmt; \
34-
bpf_trace_printk(____fmt, sizeof(____fmt), \
35-
##__VA_ARGS__); \
36-
})
37-
3831
struct bpf_map_def SEC("maps") sock_map = {
3932
.type = TEST_MAP_TYPE,
4033
.key_size = sizeof(int),

0 commit comments

Comments
 (0)