Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df0b7792 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann
Browse files

selftests/bpf: convert tests w/ custom values to BTF-defined maps



Convert a bulk of selftests that have maps with custom (not integer) key
and/or value.

Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent f6544074
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -57,17 +57,25 @@ struct frag_hdr {
	__be32 identification;
};

struct bpf_map_def SEC("maps") jmp_table = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 key_size;
	__u32 value_size;
} jmp_table SEC(".maps") = {
	.type = BPF_MAP_TYPE_PROG_ARRAY,
	.max_entries = 8,
	.key_size = sizeof(__u32),
	.value_size = sizeof(__u32),
	.max_entries = 8
};

struct bpf_map_def SEC("maps") last_dissection = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	struct bpf_flow_keys *value;
} last_dissection SEC(".maps") = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(struct bpf_flow_keys),
	.max_entries = 1,
};

+6 −5
Original line number Diff line number Diff line
@@ -12,15 +12,16 @@ struct socket_cookie {
	__u32 cookie_value;
};

struct bpf_map_def SEC("maps") socket_cookies = {
struct {
	__u32 type;
	__u32 map_flags;
	int *key;
	struct socket_cookie *value;
} socket_cookies SEC(".maps") = {
	.type = BPF_MAP_TYPE_SK_STORAGE,
	.key_size = sizeof(int),
	.value_size = sizeof(struct socket_cookie),
	.map_flags = BPF_F_NO_PREALLOC,
};

BPF_ANNOTATE_KV_PAIR(socket_cookies, int, struct socket_cookie);

SEC("cgroup/connect6")
int set_cookie(struct bpf_sock_addr *ctx)
{
+19 −8
Original line number Diff line number Diff line
@@ -15,17 +15,25 @@ struct stack_trace_t {
	struct bpf_stack_build_id user_stack_buildid[MAX_STACK_RAWTP];
};

struct bpf_map_def SEC("maps") perfmap = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 key_size;
	__u32 value_size;
} perfmap SEC(".maps") = {
	.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
	.max_entries = 2,
	.key_size = sizeof(int),
	.value_size = sizeof(__u32),
	.max_entries = 2,
};

struct bpf_map_def SEC("maps") stackdata_map = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	struct stack_trace_t *value;
} stackdata_map SEC(".maps") = {
	.type = BPF_MAP_TYPE_PERCPU_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(struct stack_trace_t),
	.max_entries = 1,
};

@@ -47,10 +55,13 @@ struct bpf_map_def SEC("maps") stackdata_map = {
 * issue and avoid complicated C programming massaging.
 * This is an acceptable workaround since there is one entry here.
 */
struct bpf_map_def SEC("maps") rawdata_map = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	__u64 (*value)[2 * MAX_STACK_RAWTP];
} rawdata_map SEC(".maps") = {
	.type = BPF_MAP_TYPE_PERCPU_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = MAX_STACK_RAWTP * sizeof(__u64) * 2,
	.max_entries = 1,
};

+18 −9
Original line number Diff line number Diff line
@@ -7,17 +7,23 @@

#include "bpf_helpers.h"

struct bpf_map_def SEC("maps") result_number = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	__u64 *value;
} result_number SEC(".maps") = {
	.type		= BPF_MAP_TYPE_ARRAY,
	.key_size	= sizeof(__u32),
	.value_size	= sizeof(__u64),
	.max_entries	= 11,
};

struct bpf_map_def SEC("maps") result_string = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	const char (*value)[32];
} result_string SEC(".maps") = {
	.type		= BPF_MAP_TYPE_ARRAY,
	.key_size	= sizeof(__u32),
	.value_size	= 32,
	.max_entries	= 5,
};

@@ -27,10 +33,13 @@ struct foo {
	__u64 c;
};

struct bpf_map_def SEC("maps") result_struct = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	struct foo *value;
} result_struct SEC(".maps") = {
	.type		= BPF_MAP_TYPE_ARRAY,
	.key_size	= sizeof(__u32),
	.value_size	= sizeof(struct foo),
	.max_entries	= 5,
};

+30 −15
Original line number Diff line number Diff line
@@ -169,38 +169,53 @@ struct eth_hdr {
	unsigned short eth_proto;
};

struct bpf_map_def SEC("maps") vip_map = {
struct {
	__u32 type;
	__u32 max_entries;
	struct vip *key;
	struct vip_meta *value;
} vip_map SEC(".maps") = {
	.type = BPF_MAP_TYPE_HASH,
	.key_size = sizeof(struct vip),
	.value_size = sizeof(struct vip_meta),
	.max_entries = MAX_VIPS,
};

struct bpf_map_def SEC("maps") ch_rings = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	__u32 *value;
} ch_rings SEC(".maps") = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(__u32),
	.max_entries = CH_RINGS_SIZE,
};

struct bpf_map_def SEC("maps") reals = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	struct real_definition *value;
} reals SEC(".maps") = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(struct real_definition),
	.max_entries = MAX_REALS,
};

struct bpf_map_def SEC("maps") stats = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	struct vip_stats *value;
} stats SEC(".maps") = {
	.type = BPF_MAP_TYPE_PERCPU_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(struct vip_stats),
	.max_entries = MAX_VIPS,
};

struct bpf_map_def SEC("maps") ctl_array = {
struct {
	__u32 type;
	__u32 max_entries;
	__u32 *key;
	struct ctl_value *value;
} ctl_array SEC(".maps") = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(__u32),
	.value_size = sizeof(struct ctl_value),
	.max_entries = CTL_MAP_SIZE,
};

Loading