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
This commit is contained in:
Yauheni Kaliuta 2021-04-08 09:13:10 +03:00 committed by Andrii Nakryiko
parent f3f4c23e12
commit cfc0889ceb
2 changed files with 25 additions and 0 deletions

View File

@ -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);
}

View File

@ -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;