Re: [PATCH net-next v2 2/2] Add a selftest for devmap pinning.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/1/22 2:11 AM, Pramukh Naduthota wrote:
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");

Looks like you never actually compiled your selftest? :(

    [...]
    TEST-OBJ [test_progs] rcu_read_lock.test.o
    TEST-OBJ [test_progs] btf_dump.test.o
  In file included from /tmp/work/bpf/bpf/tools/testing/selftests/bpf/prog_tests/devmap.c:4:
  /tmp/work/bpf/bpf/tools/testing/selftests/bpf/prog_tests/devmap.c: In function ‘test_devmap_pinning’:
  ./test_progs.h:352:35: error: expected expression before ‘{’ token
    352 | #define ASSERT_OK_PTR(ptr, name) ({     \
        |                                   ^
  /tmp/work/bpf/bpf/tools/testing/selftests/bpf/prog_tests/devmap.c:12:2: note: in expansion of macro ‘ASSERT_OK_PTR’
     12 |  ASSERT_OK_PTR(ptr, "first load");
        |  ^~~~~~~~~~~~~
  /tmp/work/bpf/bpf/tools/testing/selftests/bpf/prog_tests/devmap.c:11:8: error: called object is not a function or function pointer
     11 |  ptr = test_pinned_devmap__open_and_load()
        |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  make: *** [Makefile:539: /tmp/work/bpf/bpf/tools/testing/selftests/bpf/devmap.test.o] Error 1
  make: *** Waiting for unfinished jobs....
  make: Leaving directory '/tmp/work/bpf/bpf/tools/testing/selftests/bpf'
  Error: Process completed with exit code 2.

+	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";





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux