[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200701064527.3158178-4-andriin@fb.com>
Date: Tue, 30 Jun 2020 23:45:25 -0700
From: Andrii Nakryiko <andriin@...com>
To: <bpf@...r.kernel.org>, <netdev@...r.kernel.org>, <ast@...com>,
<daniel@...earbox.net>
CC: <andrii.nakryiko@...il.com>, <kernel-team@...com>,
Andrii Nakryiko <andriin@...com>,
Anton Protopopov <a.s.protopopov@...il.com>
Subject: [PATCH bpf-next 2/3] selftests/bpf: add selftest validating btf_dump's mod-stripping output
Add selftest validating that .strip_mods=true mode works correctly.
Signed-off-by: Andrii Nakryiko <andriin@...com>
---
.../selftests/bpf/prog_tests/btf_dump.c | 5 +-
.../bpf/progs/btf_dump_test_case_strip_mods.c | 50 +++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_strip_mods.c
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
index cb33a7ee4e04..112b653b9c80 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
@@ -21,6 +21,8 @@ static struct btf_dump_test_case {
{"btf_dump: bitfields", "btf_dump_test_case_bitfields", {}},
{"btf_dump: multidim", "btf_dump_test_case_multidim", {}},
{"btf_dump: namespacing", "btf_dump_test_case_namespacing", {}},
+ {"btf_dump: strip mods", "btf_dump_test_case_strip_mods",
+ { .strip_mods = true }},
};
static int btf_dump_all_types(const struct btf *btf,
@@ -125,6 +127,7 @@ void test_btf_dump() {
if (!test__start_subtest(t->name))
continue;
- test_btf_dump_case(i, &btf_dump_test_cases[i]);
+ t->opts.sz = sizeof(t->opts);
+ test_btf_dump_case(i, t);
}
}
diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_strip_mods.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_strip_mods.c
new file mode 100644
index 000000000000..1a6ba26d5d75
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_strip_mods.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+/* Copyright (c) 2020 Facebook */
+
+struct s {
+ const int a;
+ volatile int * const b;
+ const volatile struct {
+ int * const volatile c1;
+ const int (* const c2)(volatile int x, const void * const y);
+ const volatile int c3[10];
+ } c;
+ const union {
+ const int * restrict d1;
+ const volatile int * const volatile restrict d2;
+ } d[2];
+ const struct {
+ const volatile int *e1[5];
+ } e;
+ const volatile int * const * volatile * restrict *f;
+ const void * volatile * (*g)(const int x, const void * restrict y);
+};
+
+/* ----- START-EXPECTED-OUTPUT ----- */
+/*
+ *struct s {
+ * int a;
+ * int *b;
+ * struct {
+ * int *c1;
+ * int (*c2)(int, void *);
+ * int c3[10];
+ * } c;
+ * union {
+ * int *d1;
+ * int *d2;
+ * } d[2];
+ * struct {
+ * int *e1[5];
+ * } e;
+ * int ****f;
+ * void ** (*g)(int, void *);
+ *};
+ *
+ */
+/* ------ END-EXPECTED-OUTPUT ------ */
+
+int f(struct s *s)
+{
+ return 0;
+}
--
2.24.1
Powered by blists - more mailing lists