diff options
| author | Yureka Lilian <yuka@yuka.dev> | 2025-08-14 20:01:13 +0200 |
|---|---|---|
| committer | Andrii Nakryiko <andrii@kernel.org> | 2025-08-15 16:52:52 -0700 |
| commit | 7f8fa9d370c11ba2fb296598267e14d3bfe4ea11 (patch) | |
| tree | 5f77a2546e36eea99eb95d4c3a11d34025be250c /tools/testing/selftests/bpf/prog_tests/pinning_devmap_reuse.c | |
| parent | libbpf: Fix reuse of DEVMAP (diff) | |
| download | linux-7f8fa9d370c11ba2fb296598267e14d3bfe4ea11.tar.gz linux-7f8fa9d370c11ba2fb296598267e14d3bfe4ea11.zip | |
selftests/bpf: Add test for DEVMAP reuse
The test covers basic re-use of a pinned DEVMAP map,
with both matching and mismatching parameters.
Signed-off-by: Yureka Lilian <yuka@yuka.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20250814180113.1245565-4-yuka@yuka.dev
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/pinning_devmap_reuse.c')
| -rw-r--r-- | tools/testing/selftests/bpf/prog_tests/pinning_devmap_reuse.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/pinning_devmap_reuse.c b/tools/testing/selftests/bpf/prog_tests/pinning_devmap_reuse.c new file mode 100644 index 000000000000..9ae49b587f3e --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/pinning_devmap_reuse.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <test_progs.h> + + +#include "test_pinning_devmap.skel.h" + +void test_pinning_devmap_reuse(void) +{ + const char *pinpath1 = "/sys/fs/bpf/pinmap1"; + const char *pinpath2 = "/sys/fs/bpf/pinmap2"; + struct test_pinning_devmap *skel1 = NULL, *skel2 = NULL; + int err; + DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts); + + /* load the object a first time */ + skel1 = test_pinning_devmap__open_and_load(); + if (!ASSERT_OK_PTR(skel1, "skel_load1")) + goto out; + + /* load the object a second time, re-using the pinned map */ + skel2 = test_pinning_devmap__open_and_load(); + if (!ASSERT_OK_PTR(skel2, "skel_load2")) + goto out; + + /* we can close the reference safely without + * the map's refcount falling to 0 + */ + test_pinning_devmap__destroy(skel1); + skel1 = NULL; + + /* now, swap the pins */ + err = renameat2(0, pinpath1, 0, pinpath2, RENAME_EXCHANGE); + if (!ASSERT_OK(err, "swap pins")) + goto out; + + /* load the object again, this time the re-use should fail */ + skel1 = test_pinning_devmap__open_and_load(); + if (!ASSERT_ERR_PTR(skel1, "skel_load3")) + goto out; + +out: + unlink(pinpath1); + unlink(pinpath2); + test_pinning_devmap__destroy(skel1); + test_pinning_devmap__destroy(skel2); +} |
