mirror of
https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable.git
synced 2025-10-02 20:59:01 +10:00
Add a new selftest, local_kptr_stash, which uses bpf_kptr_xchg to stash a bpf_obj_new-allocated object in a map. Test the following scenarios: * Stash two rb_nodes in an arraymap, don't unstash them, rely on map free to destruct them * Stash two rb_nodes in an arraymap, unstash the second one in a separate program, rely on map free to destruct first Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com> Link: https://lore.kernel.org/r/20230310230743.2320707-4-davemarchevsky@fb.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
61 lines
1.7 KiB
C
61 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
|
|
|
|
#include <test_progs.h>
|
|
#include <network_helpers.h>
|
|
|
|
#include "local_kptr_stash.skel.h"
|
|
static void test_local_kptr_stash_simple(void)
|
|
{
|
|
LIBBPF_OPTS(bpf_test_run_opts, opts,
|
|
.data_in = &pkt_v4,
|
|
.data_size_in = sizeof(pkt_v4),
|
|
.repeat = 1,
|
|
);
|
|
struct local_kptr_stash *skel;
|
|
int ret;
|
|
|
|
skel = local_kptr_stash__open_and_load();
|
|
if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
|
|
return;
|
|
|
|
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_rb_nodes), &opts);
|
|
ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
|
|
ASSERT_OK(opts.retval, "local_kptr_stash_add_nodes retval");
|
|
|
|
local_kptr_stash__destroy(skel);
|
|
}
|
|
|
|
static void test_local_kptr_stash_unstash(void)
|
|
{
|
|
LIBBPF_OPTS(bpf_test_run_opts, opts,
|
|
.data_in = &pkt_v4,
|
|
.data_size_in = sizeof(pkt_v4),
|
|
.repeat = 1,
|
|
);
|
|
struct local_kptr_stash *skel;
|
|
int ret;
|
|
|
|
skel = local_kptr_stash__open_and_load();
|
|
if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
|
|
return;
|
|
|
|
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_rb_nodes), &opts);
|
|
ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
|
|
ASSERT_OK(opts.retval, "local_kptr_stash_add_nodes retval");
|
|
|
|
ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.unstash_rb_node), &opts);
|
|
ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
|
|
ASSERT_EQ(opts.retval, 42, "local_kptr_stash_add_nodes retval");
|
|
|
|
local_kptr_stash__destroy(skel);
|
|
}
|
|
|
|
void test_local_kptr_stash_success(void)
|
|
{
|
|
if (test__start_subtest("local_kptr_stash_simple"))
|
|
test_local_kptr_stash_simple();
|
|
if (test__start_subtest("local_kptr_stash_unstash"))
|
|
test_local_kptr_stash_unstash();
|
|
}
|