From: Andrii Nakryiko <andriin@fb.com>
To: <andrii.nakryiko@gmail.com>, <ast@fb.com>, <daniel@iogearbox.net>,
<netdev@vger.kernel.org>, <bpf@vger.kernel.org>,
<kernel-team@fb.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Subject: [PATCH v2 bpf-next 11/11] selftests/bpf: convert remaining selftests to BTF-defined maps
Date: Mon, 17 Jun 2019 12:27:00 -0700 [thread overview]
Message-ID: <20190617192700.2313445-12-andriin@fb.com> (raw)
In-Reply-To: <20190617192700.2313445-1-andriin@fb.com>
Convert all the rest of selftests that use BPF maps. These are either
maps with integer key/value or special types of maps that don't event
allow BTF type information for key/value.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
.../selftests/bpf/progs/get_cgroup_id_kern.c | 18 +++--
.../selftests/bpf/progs/sample_map_ret0.c | 18 +++--
.../bpf/progs/sockmap_verdict_prog.c | 36 +++++++---
.../selftests/bpf/progs/test_map_in_map.c | 20 ++++--
.../testing/selftests/bpf/progs/test_obj_id.c | 9 ++-
.../bpf/progs/test_skb_cgroup_id_kern.c | 9 ++-
.../testing/selftests/bpf/progs/test_tc_edt.c | 9 ++-
.../bpf/progs/test_tcp_check_syncookie_kern.c | 9 ++-
.../selftests/bpf/test_queue_stack_map.h | 20 ++++--
.../testing/selftests/bpf/test_sockmap_kern.h | 72 +++++++++++++------
10 files changed, 154 insertions(+), 66 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c b/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c
index 014dba10b8a5..87b202381088 100644
--- a/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c
+++ b/tools/testing/selftests/bpf/progs/get_cgroup_id_kern.c
@@ -4,17 +4,23 @@
#include <linux/bpf.h>
#include "bpf_helpers.h"
-struct bpf_map_def SEC("maps") cg_ids = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 *key;
+ __u64 *value;
+} cg_ids SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u64),
.max_entries = 1,
};
-struct bpf_map_def SEC("maps") pidmap = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 *key;
+ __u32 *value;
+} pidmap SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u32),
.max_entries = 1,
};
diff --git a/tools/testing/selftests/bpf/progs/sample_map_ret0.c b/tools/testing/selftests/bpf/progs/sample_map_ret0.c
index 0756303676ac..0f4d47cecd4d 100644
--- a/tools/testing/selftests/bpf/progs/sample_map_ret0.c
+++ b/tools/testing/selftests/bpf/progs/sample_map_ret0.c
@@ -2,17 +2,23 @@
#include <linux/bpf.h>
#include "bpf_helpers.h"
-struct bpf_map_def SEC("maps") htab = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 *key;
+ long *value;
+} htab SEC(".maps") = {
.type = BPF_MAP_TYPE_HASH,
- .key_size = sizeof(__u32),
- .value_size = sizeof(long),
.max_entries = 2,
};
-struct bpf_map_def SEC("maps") array = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 *key;
+ long *value;
+} array SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(long),
.max_entries = 2,
};
diff --git a/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c b/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c
index d85c874ef25e..983c4f6e4fad 100644
--- a/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c
+++ b/tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c
@@ -4,31 +4,49 @@
int _version SEC("version") = 1;
-struct bpf_map_def SEC("maps") sock_map_rx = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} sock_map_rx SEC(".maps") = {
.type = BPF_MAP_TYPE_SOCKMAP,
+ .max_entries = 20,
.key_size = sizeof(int),
.value_size = sizeof(int),
- .max_entries = 20,
};
-struct bpf_map_def SEC("maps") sock_map_tx = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} sock_map_tx SEC(".maps") = {
.type = BPF_MAP_TYPE_SOCKMAP,
+ .max_entries = 20,
.key_size = sizeof(int),
.value_size = sizeof(int),
- .max_entries = 20,
};
-struct bpf_map_def SEC("maps") sock_map_msg = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} sock_map_msg SEC(".maps") = {
.type = BPF_MAP_TYPE_SOCKMAP,
+ .max_entries = 20,
.key_size = sizeof(int),
.value_size = sizeof(int),
- .max_entries = 20,
};
-struct bpf_map_def SEC("maps") sock_map_break = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ int *key;
+ int *value;
+} sock_map_break SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
.max_entries = 20,
};
diff --git a/tools/testing/selftests/bpf/progs/test_map_in_map.c b/tools/testing/selftests/bpf/progs/test_map_in_map.c
index 2985f262846e..7404bee7c26e 100644
--- a/tools/testing/selftests/bpf/progs/test_map_in_map.c
+++ b/tools/testing/selftests/bpf/progs/test_map_in_map.c
@@ -5,22 +5,30 @@
#include <linux/types.h>
#include "bpf_helpers.h"
-struct bpf_map_def SEC("maps") mim_array = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} mim_array SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
+ .max_entries = 1,
.key_size = sizeof(int),
/* must be sizeof(__u32) for map in map */
.value_size = sizeof(__u32),
- .max_entries = 1,
- .map_flags = 0,
};
-struct bpf_map_def SEC("maps") mim_hash = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} mim_hash SEC(".maps") = {
.type = BPF_MAP_TYPE_HASH_OF_MAPS,
+ .max_entries = 1,
.key_size = sizeof(int),
/* must be sizeof(__u32) for map in map */
.value_size = sizeof(__u32),
- .max_entries = 1,
- .map_flags = 0,
};
SEC("xdp_mimtest")
diff --git a/tools/testing/selftests/bpf/progs/test_obj_id.c b/tools/testing/selftests/bpf/progs/test_obj_id.c
index 880d2963b472..2b1c2efdeed4 100644
--- a/tools/testing/selftests/bpf/progs/test_obj_id.c
+++ b/tools/testing/selftests/bpf/progs/test_obj_id.c
@@ -16,10 +16,13 @@
int _version SEC("version") = 1;
-struct bpf_map_def SEC("maps") test_map_id = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 *key;
+ __u64 *value;
+} test_map_id SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u64),
.max_entries = 1,
};
diff --git a/tools/testing/selftests/bpf/progs/test_skb_cgroup_id_kern.c b/tools/testing/selftests/bpf/progs/test_skb_cgroup_id_kern.c
index 68cf9829f5a7..af296b876156 100644
--- a/tools/testing/selftests/bpf/progs/test_skb_cgroup_id_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_skb_cgroup_id_kern.c
@@ -10,10 +10,13 @@
#define NUM_CGROUP_LEVELS 4
-struct bpf_map_def SEC("maps") cgroup_ids = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 *key;
+ __u64 *value;
+} cgroup_ids SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u64),
.max_entries = NUM_CGROUP_LEVELS,
};
diff --git a/tools/testing/selftests/bpf/progs/test_tc_edt.c b/tools/testing/selftests/bpf/progs/test_tc_edt.c
index 3af64c470d64..c2781dd78617 100644
--- a/tools/testing/selftests/bpf/progs/test_tc_edt.c
+++ b/tools/testing/selftests/bpf/progs/test_tc_edt.c
@@ -16,10 +16,13 @@
#define THROTTLE_RATE_BPS (5 * 1000 * 1000)
/* flow_key => last_tstamp timestamp used */
-struct bpf_map_def SEC("maps") flow_map = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ uint32_t *key;
+ uint64_t *value;
+} flow_map SEC(".maps") = {
.type = BPF_MAP_TYPE_HASH,
- .key_size = sizeof(uint32_t),
- .value_size = sizeof(uint64_t),
.max_entries = 1,
};
diff --git a/tools/testing/selftests/bpf/progs/test_tcp_check_syncookie_kern.c b/tools/testing/selftests/bpf/progs/test_tcp_check_syncookie_kern.c
index 1ab095bcacd8..0f1725e25c44 100644
--- a/tools/testing/selftests/bpf/progs/test_tcp_check_syncookie_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tcp_check_syncookie_kern.c
@@ -16,10 +16,13 @@
#include "bpf_helpers.h"
#include "bpf_endian.h"
-struct bpf_map_def SEC("maps") results = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 *key;
+ __u64 *value;
+} results SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(__u32),
- .value_size = sizeof(__u64),
.max_entries = 1,
};
diff --git a/tools/testing/selftests/bpf/test_queue_stack_map.h b/tools/testing/selftests/bpf/test_queue_stack_map.h
index 295b9b3bc5c7..f284137a36c4 100644
--- a/tools/testing/selftests/bpf/test_queue_stack_map.h
+++ b/tools/testing/selftests/bpf/test_queue_stack_map.h
@@ -10,20 +10,28 @@
int _version SEC("version") = 1;
-struct bpf_map_def __attribute__ ((section("maps"), used)) map_in = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} map_in SEC(".maps") = {
.type = MAP_TYPE,
+ .max_entries = 32,
.key_size = 0,
.value_size = sizeof(__u32),
- .max_entries = 32,
- .map_flags = 0,
};
-struct bpf_map_def __attribute__ ((section("maps"), used)) map_out = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} map_out SEC(".maps") = {
.type = MAP_TYPE,
+ .max_entries = 32,
.key_size = 0,
.value_size = sizeof(__u32),
- .max_entries = 32,
- .map_flags = 0,
};
SEC("test")
diff --git a/tools/testing/selftests/bpf/test_sockmap_kern.h b/tools/testing/selftests/bpf/test_sockmap_kern.h
index 4e7d3da21357..70b9236cedb0 100644
--- a/tools/testing/selftests/bpf/test_sockmap_kern.h
+++ b/tools/testing/selftests/bpf/test_sockmap_kern.h
@@ -28,59 +28,89 @@
* are established and verdicts are decided.
*/
-struct bpf_map_def SEC("maps") sock_map = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} sock_map SEC(".maps") = {
.type = TEST_MAP_TYPE,
+ .max_entries = 20,
.key_size = sizeof(int),
.value_size = sizeof(int),
- .max_entries = 20,
};
-struct bpf_map_def SEC("maps") sock_map_txmsg = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} sock_map_txmsg SEC(".maps") = {
.type = TEST_MAP_TYPE,
+ .max_entries = 20,
.key_size = sizeof(int),
.value_size = sizeof(int),
- .max_entries = 20,
};
-struct bpf_map_def SEC("maps") sock_map_redir = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ __u32 key_size;
+ __u32 value_size;
+} sock_map_redir SEC(".maps") = {
.type = TEST_MAP_TYPE,
+ .max_entries = 20,
.key_size = sizeof(int),
.value_size = sizeof(int),
- .max_entries = 20,
};
-struct bpf_map_def SEC("maps") sock_apply_bytes = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ int *key;
+ int *value;
+} sock_apply_bytes SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
.max_entries = 1
};
-struct bpf_map_def SEC("maps") sock_cork_bytes = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ int *key;
+ int *value;
+} sock_cork_bytes SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
.max_entries = 1
};
-struct bpf_map_def SEC("maps") sock_bytes = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ int *key;
+ int *value;
+} sock_bytes SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
.max_entries = 6
};
-struct bpf_map_def SEC("maps") sock_redir_flags = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ int *key;
+ int *value;
+} sock_redir_flags SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
.max_entries = 1
};
-struct bpf_map_def SEC("maps") sock_skb_opts = {
+struct {
+ __u32 type;
+ __u32 max_entries;
+ int *key;
+ int *value;
+} sock_skb_opts SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(int),
- .value_size = sizeof(int),
.max_entries = 1
};
--
2.17.1
next prev parent reply other threads:[~2019-06-17 19:27 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-17 19:26 [PATCH v2 bpf-next 00/11] BTF-defined BPF map definitions Andrii Nakryiko
2019-06-17 19:26 ` [PATCH v2 bpf-next 01/11] libbpf: add common min/max macro to libbpf_internal.h Andrii Nakryiko
2019-06-17 19:26 ` [PATCH v2 bpf-next 02/11] libbpf: extract BTF loading logic Andrii Nakryiko
2019-06-17 19:40 ` Song Liu
2019-06-17 19:26 ` [PATCH v2 bpf-next 03/11] libbpf: streamline ELF parsing error-handling Andrii Nakryiko
2019-06-17 19:46 ` Song Liu
2019-06-17 19:26 ` [PATCH v2 bpf-next 04/11] libbpf: refactor map initialization Andrii Nakryiko
2019-06-17 19:39 ` Song Liu
2019-06-26 14:48 ` Matt Hart
2019-06-26 18:28 ` Andrii Nakryiko
2019-06-27 15:11 ` Matt Hart
2019-06-17 19:26 ` [PATCH v2 bpf-next 05/11] libbpf: identify maps by section index in addition to offset Andrii Nakryiko
2019-06-17 19:26 ` [PATCH v2 bpf-next 06/11] libbpf: split initialization and loading of BTF Andrii Nakryiko
2019-06-17 19:26 ` [PATCH v2 bpf-next 07/11] libbpf: allow specifying map definitions using BTF Andrii Nakryiko
2019-06-17 19:43 ` Song Liu
2019-06-17 19:26 ` [PATCH v2 bpf-next 08/11] selftests/bpf: add test for BTF-defined maps Andrii Nakryiko
2019-06-17 19:26 ` [PATCH v2 bpf-next 09/11] selftests/bpf: switch BPF_ANNOTATE_KV_PAIR tests to " Andrii Nakryiko
2019-06-17 21:41 ` Song Liu
2019-06-17 22:20 ` Daniel Borkmann
2019-06-17 19:26 ` [PATCH v2 bpf-next 10/11] selftests/bpf: convert tests w/ custom values " Andrii Nakryiko
2019-06-17 19:27 ` Andrii Nakryiko [this message]
2019-06-17 21:17 ` [PATCH v2 bpf-next 00/11] BTF-defined BPF map definitions Daniel Borkmann
2019-06-17 22:17 ` Daniel Borkmann
2019-06-18 21:37 ` Andrii Nakryiko
2019-06-20 14:49 ` Lorenz Bauer
2019-06-21 4:19 ` Andrii Nakryiko
2019-06-21 10:29 ` Lorenz Bauer
2019-06-21 17:56 ` Andrii Nakryiko
2019-06-25 18:14 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190617192700.2313445-12-andriin@fb.com \
--to=andriin@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).