aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/prog_tests/map_kptr.c
diff options
context:
space:
mode:
authorKumar Kartikeya Dwivedi <memxor@gmail.com>2022-05-12 01:16:54 +0530
committerAlexei Starovoitov <ast@kernel.org>2022-05-11 16:57:27 -0700
commit0ef6740e97777bbe04aeacd32239ccb1732098d7 (patch)
treebb6dfa8f502812fcf7a081aa26b0ae0b2603b287 /tools/testing/selftests/bpf/prog_tests/map_kptr.c
parentselftests/bpf: Add negative C tests for kptrs (diff)
downloadlinux-dev-0ef6740e97777bbe04aeacd32239ccb1732098d7.tar.xz
linux-dev-0ef6740e97777bbe04aeacd32239ccb1732098d7.zip
selftests/bpf: Add tests for kptr_ref refcounting
Check at runtime how various operations for kptr_ref affect its refcount and verify against the actual count. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20220511194654.765705-5-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/map_kptr.c')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/map_kptr.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/map_kptr.c b/tools/testing/selftests/bpf/prog_tests/map_kptr.c
index 00819277cb17..8142dd9eff4c 100644
--- a/tools/testing/selftests/bpf/prog_tests/map_kptr.c
+++ b/tools/testing/selftests/bpf/prog_tests/map_kptr.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
+#include <network_helpers.h>
#include "map_kptr.skel.h"
#include "map_kptr_fail.skel.h"
@@ -81,8 +82,13 @@ static void test_map_kptr_fail(void)
}
}
-static void test_map_kptr_success(void)
+static void test_map_kptr_success(bool test_run)
{
+ LIBBPF_OPTS(bpf_test_run_opts, opts,
+ .data_in = &pkt_v4,
+ .data_size_in = sizeof(pkt_v4),
+ .repeat = 1,
+ );
struct map_kptr *skel;
int key = 0, ret;
char buf[24];
@@ -91,6 +97,16 @@ static void test_map_kptr_success(void)
if (!ASSERT_OK_PTR(skel, "map_kptr__open_and_load"))
return;
+ ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.test_map_kptr_ref), &opts);
+ ASSERT_OK(ret, "test_map_kptr_ref refcount");
+ ASSERT_OK(opts.retval, "test_map_kptr_ref retval");
+ ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.test_map_kptr_ref2), &opts);
+ ASSERT_OK(ret, "test_map_kptr_ref2 refcount");
+ ASSERT_OK(opts.retval, "test_map_kptr_ref2 retval");
+
+ if (test_run)
+ return;
+
ret = bpf_map_update_elem(bpf_map__fd(skel->maps.array_map), &key, buf, 0);
ASSERT_OK(ret, "array_map update");
ret = bpf_map_update_elem(bpf_map__fd(skel->maps.array_map), &key, buf, 0);
@@ -116,7 +132,12 @@ static void test_map_kptr_success(void)
void test_map_kptr(void)
{
- if (test__start_subtest("success"))
- test_map_kptr_success();
+ if (test__start_subtest("success")) {
+ test_map_kptr_success(false);
+ /* Do test_run twice, so that we see refcount going back to 1
+ * after we leave it in map from first iteration.
+ */
+ test_map_kptr_success(true);
+ }
test_map_kptr_fail();
}