Add a test for devmap pinning. Signed-off-by: Pramukh Naduthota <pnaduthota@xxxxxxxxxx> --- .../testing/selftests/bpf/prog_tests/devmap.c | 21 +++++++++++++++++++ .../selftests/bpf/progs/test_pinned_devmap.c | 17 +++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/devmap.c create mode 100644 tools/testing/selftests/bpf/progs/test_pinned_devmap.c diff --git a/tools/testing/selftests/bpf/prog_tests/devmap.c b/tools/testing/selftests/bpf/prog_tests/devmap.c new file mode 100644 index 000000000000..735333d3ac07 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/devmap.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2022 Google +#include "testing_helpers.h" +#include "test_progs.h" +#include "test_pinned_devmap.skel.h" +#include "test_pinned_devmap_rdonly_prog.skel.h" + +void test_devmap_pinning(void) +{ + struct test_pinned_devmap *ptr; + + ASSERT_OK_PTR(ptr = test_pinned_devmap__open_and_load(), "first load"); + test_pinned_devmap__destroy(ptr); + ASSERT_OK_PTR(test_pinned_devmap__open_and_load(), "re-load"); +} + +void test_devmap(void) +{ + if (test__start_subtest("pinned_devmap")) + test_devmap_pinning(); +} diff --git a/tools/testing/selftests/bpf/progs/test_pinned_devmap.c b/tools/testing/selftests/bpf/progs/test_pinned_devmap.c new file mode 100644 index 000000000000..63879de18ad3 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_pinned_devmap.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2022 Google */ +#include <stddef.h> +#include <linux/bpf.h> +#include <linux/types.h> +#include <bpf/bpf_helpers.h> + +struct { + __uint(type, BPF_MAP_TYPE_DEVMAP_HASH); + __uint(max_entries, 32); + __type(key, int); + __type(value, int); + __uint(pinning, LIBBPF_PIN_BY_NAME); +} dev_map SEC(".maps"); + + +char _license[] SEC("license") = "GPL"; -- 2.30.2