diff options
author | Yauheni Kaliuta <yauheni.kaliuta@redhat.com> | 2021-04-08 09:13:10 +0300 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2021-04-08 23:54:48 -0700 |
commit | cfc0889cebccbc398a9d7a14e4e1b4724afe4bb3 (patch) | |
tree | b0e56d208af23b5ed38c4fac1db88867f6e9978c /tools | |
parent | f3f4c23e1238783f3d719cfbda6c5e2fd03a48c4 (diff) | |
download | linux-riscv-cfc0889cebccbc398a9d7a14e4e1b4724afe4bb3.tar.gz linux-riscv-cfc0889cebccbc398a9d7a14e4e1b4724afe4bb3.tar.bz2 linux-riscv-cfc0889cebccbc398a9d7a14e4e1b4724afe4bb3.zip |
selftests/bpf: ringbuf_multi: Test bpf_map__set_inner_map_fd
Test map__set_inner_map_fd() interaction with map-in-map
initialization. Use hashmap of maps just to make it different to
existing array of maps.
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210408061310.95877-9-yauheni.kaliuta@redhat.com
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c | 14 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/progs/test_ringbuf_multi.c | 11 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c index 159de99621c7..cef63e703924 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c @@ -44,6 +44,7 @@ void test_ringbuf_multi(void) struct ring_buffer *ringbuf = NULL; int err; int page_size = getpagesize(); + int proto_fd = -1; skel = test_ringbuf_multi__open(); if (CHECK(!skel, "skel_open", "skeleton open failed\n")) @@ -61,10 +62,21 @@ void test_ringbuf_multi(void) if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) goto cleanup; + proto_fd = bpf_create_map(BPF_MAP_TYPE_RINGBUF, 0, 0, page_size, 0); + if (CHECK(proto_fd == -1, "bpf_create_map", "bpf_create_map failed\n")) + goto cleanup; + + err = bpf_map__set_inner_map_fd(skel->maps.ringbuf_hash, proto_fd); + if (CHECK(err != 0, "bpf_map__set_inner_map_fd", "bpf_map__set_inner_map_fd failed\n")) + goto cleanup; + err = test_ringbuf_multi__load(skel); if (CHECK(err != 0, "skel_load", "skeleton load failed\n")) goto cleanup; + close(proto_fd); + proto_fd = -1; + /* only trigger BPF program for current process */ skel->bss->pid = getpid(); @@ -114,6 +126,8 @@ void test_ringbuf_multi(void) 2L, skel->bss->total); cleanup: + if (proto_fd >= 0) + close(proto_fd); ring_buffer__free(ringbuf); test_ringbuf_multi__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c index 055c10b2ff80..197b86546dca 100644 --- a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c +++ b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c @@ -30,6 +30,17 @@ struct { }, }; +struct { + __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS); + __uint(max_entries, 1); + __type(key, int); + __array(values, struct ringbuf_map); +} ringbuf_hash SEC(".maps") = { + .values = { + [0] = &ringbuf1, + }, +}; + /* inputs */ int pid = 0; int target_ring = 0; |