selftests: bpf: Move bpf_printk to bpf_helpers.h
authorMichal Rostecki <mrostecki@opensuse.org>
Thu, 23 May 2019 12:53:54 +0000 (14:53 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 24 May 2019 20:47:17 +0000 (13:47 -0700)
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>
tools/testing/selftests/bpf/bpf_helpers.h
tools/testing/selftests/bpf/progs/sockmap_parse_prog.c
tools/testing/selftests/bpf/progs/sockmap_tcp_msg_prog.c
tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c
tools/testing/selftests/bpf/progs/test_lwt_seg6local.c
tools/testing/selftests/bpf/progs/test_xdp_noinline.c
tools/testing/selftests/bpf/test_sockmap_kern.h

index 5f6f9e7aba2abfddd591027693324de04e7fdadc..4b27840b810921fa77ec4d0e342d5cc3bacd0926 100644 (file)
@@ -8,6 +8,14 @@
  */
 #define SEC(NAME) __attribute__((section(NAME), used))
 
+/* helper macro to print out debug messages */
+#define bpf_printk(fmt, ...)                           \
+({                                                     \
+       char ____fmt[] = fmt;                           \
+       bpf_trace_printk(____fmt, sizeof(____fmt),      \
+                        ##__VA_ARGS__);                \
+})
+
 /* helper functions called from eBPF programs written in C */
 static void *(*bpf_map_lookup_elem)(void *map, const void *key) =
        (void *) BPF_FUNC_map_lookup_elem;
index 0f92858f6226a37feb921eeea494902a2520d8bc..ed3e4a551c57bd79eba5b4b9c4a2c70a6d44313a 100644 (file)
@@ -5,13 +5,6 @@
 
 int _version SEC("version") = 1;
 
-#define bpf_printk(fmt, ...)                                   \
-({                                                             \
-              char ____fmt[] = fmt;                            \
-              bpf_trace_printk(____fmt, sizeof(____fmt),       \
-                               ##__VA_ARGS__);                 \
-})
-
 SEC("sk_skb1")
 int bpf_prog1(struct __sk_buff *skb)
 {
index 12a7b5c82ed62331503d44f2f2efe96f50118f8d..65fbfdb6cd3a1a2c5306ec9b5a0b19c5833c0afe 100644 (file)
@@ -5,13 +5,6 @@
 
 int _version SEC("version") = 1;
 
-#define bpf_printk(fmt, ...)                                   \
-({                                                             \
-              char ____fmt[] = fmt;                            \
-              bpf_trace_printk(____fmt, sizeof(____fmt),       \
-                               ##__VA_ARGS__);                 \
-})
-
 SEC("sk_msg1")
 int bpf_prog1(struct sk_msg_md *msg)
 {
index 2ce7634a4012a19c6b35c3bdf35d4518c5ae5c46..bdc22be46f2efb4c5813f32c753ceb2bb9061981 100644 (file)
@@ -5,13 +5,6 @@
 
 int _version SEC("version") = 1;
 
-#define bpf_printk(fmt, ...)                                   \
-({                                                             \
-              char ____fmt[] = fmt;                            \
-              bpf_trace_printk(____fmt, sizeof(____fmt),       \
-                               ##__VA_ARGS__);                 \
-})
-
 struct bpf_map_def SEC("maps") sock_map_rx = {
        .type = BPF_MAP_TYPE_SOCKMAP,
        .key_size = sizeof(int),
index 0575751bc1bc4020535a238bda9d4be9a2503eb8..7c7cb3177463b689ccf524a97957a9b80a5fa521 100644 (file)
@@ -6,13 +6,6 @@
 #include "bpf_helpers.h"
 #include "bpf_endian.h"
 
-#define bpf_printk(fmt, ...)                           \
-({                                                     \
-       char ____fmt[] = fmt;                           \
-       bpf_trace_printk(____fmt, sizeof(____fmt),      \
-                       ##__VA_ARGS__);                 \
-})
-
 /* Packet parsing state machine helpers. */
 #define cursor_advance(_cursor, _len) \
        ({ void *_tmp = _cursor; _cursor += _len; _tmp; })
index 5e4aac74f9d02f998c212ce536dc3243b805a514..4fe6aaad22a404115cded39185971e7cd7e798c9 100644 (file)
 #include <linux/udp.h>
 #include "bpf_helpers.h"
 
-#define bpf_printk(fmt, ...)                           \
-({                                                     \
-       char ____fmt[] = fmt;                           \
-       bpf_trace_printk(____fmt, sizeof(____fmt),      \
-                       ##__VA_ARGS__);                 \
-})
-
 static __u32 rol32(__u32 word, unsigned int shift)
 {
        return (word << shift) | (word >> ((-shift) & 31));
index e7639f66a9418f675914ea57dbdc649347600e7b..4e7d3da21357ea62421d5fce69e19e4e64fbda09 100644 (file)
  * are established and verdicts are decided.
  */
 
-#define bpf_printk(fmt, ...)                                   \
-({                                                             \
-              char ____fmt[] = fmt;                            \
-              bpf_trace_printk(____fmt, sizeof(____fmt),       \
-                               ##__VA_ARGS__);                 \
-})
-
 struct bpf_map_def SEC("maps") sock_map = {
        .type = TEST_MAP_TYPE,
        .key_size = sizeof(int),