diff options
author | Yauheni Kaliuta <yauheni.kaliuta@redhat.com> | 2021-04-08 09:13:05 +0300 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2021-04-09 09:54:47 +0300 |
commit | 7a85e4dfa7f5d052ae5016e96f1ee426a8870e78 (patch) | |
tree | 22cc3b3b4ff4dc5ab95e6e6392e586bf76593c29 /tools/testing/selftests/bpf/prog_tests | |
parent | 361d32028c7d52d28d7f0562193a2f4a41d10351 (diff) | |
download | linux-7a85e4dfa7f5d052ae5016e96f1ee426a8870e78.tar.xz |
selftests/bpf: Pass page size from userspace in map_ptr
Use ASSERT to check result but keep CHECK where format was used to
report error.
Use bpf_map__set_max_entries() to set map size dynamically from
userspace according to page size.
Zero-initialize the variable in bpf prog, otherwise it will cause
problems on some versions of Clang.
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-4-yauheni.kaliuta@redhat.com
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests')
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/map_ptr.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/map_ptr.c b/tools/testing/selftests/bpf/prog_tests/map_ptr.c index c230a573c373..4972f92205c7 100644 --- a/tools/testing/selftests/bpf/prog_tests/map_ptr.c +++ b/tools/testing/selftests/bpf/prog_tests/map_ptr.c @@ -12,11 +12,22 @@ void test_map_ptr(void) __u32 duration = 0, retval; char buf[128]; int err; + int page_size = getpagesize(); - skel = map_ptr_kern__open_and_load(); - if (CHECK(!skel, "skel_open_load", "open_load failed\n")) + skel = map_ptr_kern__open(); + if (!ASSERT_OK_PTR(skel, "skel_open")) return; + err = bpf_map__set_max_entries(skel->maps.m_ringbuf, page_size); + if (!ASSERT_OK(err, "bpf_map__set_max_entries")) + goto cleanup; + + err = map_ptr_kern__load(skel); + if (!ASSERT_OK(err, "skel_load")) + goto cleanup; + + skel->bss->page_size = page_size; + err = bpf_prog_test_run(bpf_program__fd(skel->progs.cg_skb), 1, &pkt_v4, sizeof(pkt_v4), buf, NULL, &retval, NULL); |