Skip to content

Commit

Permalink
selftests/bpf: convert tests w/ custom values to BTF-defined maps
Browse files Browse the repository at this point in the history
Convert a bulk of selftests that have maps with custom (not integer) key
and/or value.

Signed-off-by: Andrii Nakryiko <[email protected]>
Acked-by: Song Liu <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
  • Loading branch information
anakryiko authored and borkmann committed Jun 17, 2019
1 parent f654407 commit df0b779
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 140 deletions.
18 changes: 13 additions & 5 deletions tools/testing/selftests/bpf/progs/bpf_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
11 changes: 6 additions & 5 deletions tools/testing/selftests/bpf/progs/socket_cookie_prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
27 changes: 19 additions & 8 deletions tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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,
};

Expand Down
27 changes: 18 additions & 9 deletions tools/testing/selftests/bpf/progs/test_global_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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,
};

Expand Down
45 changes: 30 additions & 15 deletions tools/testing/selftests/bpf/progs/test_l4lb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
45 changes: 30 additions & 15 deletions tools/testing/selftests/bpf/progs/test_l4lb_noinline.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,38 +165,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,
};

Expand Down
45 changes: 31 additions & 14 deletions tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,55 @@ int _version SEC("version") = 1;
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

struct bpf_map_def SEC("maps") outer_map = {
struct {
__u32 type;
__u32 max_entries;
__u32 key_size;
__u32 value_size;
} outer_map SEC(".maps") = {
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
.max_entries = 1,
.key_size = sizeof(__u32),
.value_size = sizeof(__u32),
.max_entries = 1,
};

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

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

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

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

Expand Down
Loading

0 comments on commit df0b779

Please sign in to comment.