diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2018-01-17 19:13:31 -0800 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-01-18 22:54:26 +0100 |
commit | 7fedbb7c5a7c4bda418bc1056c06c81db36e4299 (patch) | |
tree | ff8d1f47eff09b3e16909b731c0aa5bee854698a /tools/testing/selftests/bpf/sample_map_ret0.c | |
parent | 395cacb5f1a0a290f1ae9ca4692c400d2b57a705 (diff) |
selftest/bpf: extend the offload test with map checks
Check map device information is reported correctly, and perform
basic map operations. Check device destruction gets rid of the
maps and map allocation failure path by telling netdevsim to
reject map offload via DebugFS.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/testing/selftests/bpf/sample_map_ret0.c')
-rw-r--r-- | tools/testing/selftests/bpf/sample_map_ret0.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/sample_map_ret0.c b/tools/testing/selftests/bpf/sample_map_ret0.c new file mode 100644 index 000000000000..0756303676ac --- /dev/null +++ b/tools/testing/selftests/bpf/sample_map_ret0.c @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */ +#include <linux/bpf.h> +#include "bpf_helpers.h" + +struct bpf_map_def SEC("maps") htab = { + .type = BPF_MAP_TYPE_HASH, + .key_size = sizeof(__u32), + .value_size = sizeof(long), + .max_entries = 2, +}; + +struct bpf_map_def SEC("maps") array = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(__u32), + .value_size = sizeof(long), + .max_entries = 2, +}; + +/* Sample program which should always load for testing control paths. */ +SEC(".text") int func() +{ + __u64 key64 = 0; + __u32 key = 0; + long *value; + + value = bpf_map_lookup_elem(&htab, &key); + if (!value) + return 1; + value = bpf_map_lookup_elem(&array, &key64); + if (!value) + return 1; + + return 0; +} |