Add a selftest Signed-off-by: Pramukh Naduthota <pnaduthota@xxxxxxxxxx> --- .../testing/selftests/bpf/prog_tests/devmap.c | 20 +++++++++++++++++++ .../selftests/bpf/progs/test_pinned_devmap.c | 17 ++++++++++++++++ 2 files changed, 37 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..50c5006c1416 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/devmap.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2022 Google */ +#include "testing_helpers.h" +#include "test_progs.h" +#include "test_pinned_devmap.skel.h" + +void test_devmap_pinning(void) +{ + struct test_pinned_devmap *ptr; + + ptr = test_pinned_devmap__open_and_load() + ASSERT_OK_PTR(ptr, "first load"); + test_pinned_devmap__destroy(ptr); + ASSERT_OK_PTR(test_pinned_devmap__open_and_load(), "re-load"); +} + +void test_devmap(void) +{ + 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..2e9b25fe657c --- /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); +} repinned_dev_map SEC(".maps"); + + +char _license[] SEC("license") = "GPL"; -- 2.30.2