On Tue, Sep 27, 2022 at 11:24 AM Pramukh Naduthota <pnaduthota@xxxxxxxxxx> wrote: > > 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 nit: use /* */ for copyright line > +#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) static > +{ > + struct test_pinned_devmap *ptr; > + > + ASSERT_OK_PTR(ptr = test_pinned_devmap__open_and_load(), "first load"); nit: don't be too clever inside ASSERT_OK_PTR(), do assignment outside and then check ptr > + 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(); if it's just one subtest then there isn't much point in making it a subtest > +} > 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"); please use a bit more specific name to minimize potential interference with other parallel tests > + > + > +char _license[] SEC("license") = "GPL"; > -- > 2.30.2 >