BPF Archive on lore.kernel.org
 help / color / Atom feed
From: Andrii Nakryiko <andriin@fb.com>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
	<daniel@iogearbox.net>
Cc: <andrii.nakryiko@gmail.com>, <kernel-team@fb.com>,
	Andrii Nakryiko <andriin@fb.com>,
	Anton Protopopov <a.s.protopopov@gmail.com>
Subject: [PATCH bpf-next 2/3] selftests/bpf: add selftest validating btf_dump's mod-stripping output
Date: Tue, 30 Jun 2020 23:45:25 -0700
Message-ID: <20200701064527.3158178-4-andriin@fb.com> (raw)
In-Reply-To: <20200701064527.3158178-1-andriin@fb.com>

Add selftest validating that .strip_mods=true mode works correctly.

Signed-off-by: Andrii Nakryiko <andriin@fb.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


  parent reply index

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01  6:45 [PATCH bpf-next 0/3] Strip away modifiers from BPF skeleton global variables Andrii Nakryiko
2020-07-01  6:45 ` [PATCH bpf-next 1/3] libbpf: support stripping modifiers for btf_dump Andrii Nakryiko
2020-07-01  6:45 ` [PATCH bpf-next 2/3] selftests/bpf: add selftest testin btf_dump's mod-stripping output Andrii Nakryiko
2020-07-01  6:47   ` Andrii Nakryiko
2020-07-01  6:45 ` Andrii Nakryiko [this message]
2020-07-01  6:45 ` [PATCH bpf-next 3/3] tools/bpftool: strip away modifiers from global variables Andrii Nakryiko
2020-07-01 15:01 ` [PATCH bpf-next 0/3] Strip away modifiers from BPF skeleton " Alexei Starovoitov
2020-07-01 16:08   ` Andrii Nakryiko
2020-07-01 16:36     ` Alexei Starovoitov
2020-07-01 18:15       ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200701064527.3158178-4-andriin@fb.com \
    --to=andriin@fb.com \
    --cc=a.s.protopopov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git