All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: dwarves@vger.kernel.org, arnaldo.melo@gmail.com, alan.maguire@oracle.com
Cc: bpf@vger.kernel.org, kernel-team@fb.com, ast@kernel.org,
	daniel@iogearbox.net, andrii@kernel.org, yonghong.song@linux.dev,
	Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF
Date: Tue, 10 Dec 2024 18:12:27 -0800	[thread overview]
Message-ID: <20241211021227.2341735-2-eddyz87@gmail.com> (raw)
In-Reply-To: <20241211021227.2341735-1-eddyz87@gmail.com>

When using BTF as a source, pfunct should now be able to print
btf_decl_tags for programs like below:

  #define __tag(x) __attribute__((btf_decl_tag(#x)))
  __tag(a) __tag(b) void foo(void) {}

This situation arises after recent kernel changes, where tags 'kfunc'
and 'bpf_fastcall' are added to some functions. To avoid dependency on
a recent kernel version test this by compiling a small C program using
clang with --target=bpf, which would instruct clang to generate .BTF
section.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
 tests/pfunct-btf-decl-tags.sh | 65 +++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100755 tests/pfunct-btf-decl-tags.sh

diff --git a/tests/pfunct-btf-decl-tags.sh b/tests/pfunct-btf-decl-tags.sh
new file mode 100755
index 0000000..7e7f547
--- /dev/null
+++ b/tests/pfunct-btf-decl-tags.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Check that pfunct can print btf_decl_tags read from BTF
+
+tmpobj=$(mktemp /tmp/pfunct-btf-decl-tags.sh.XXXXXX.o)
+
+cleanup()
+{
+	rm $tmpobj
+}
+
+trap cleanup EXIT
+
+CLANG=${CLANG:-clang}
+if ! command -v $CLANG > /dev/null; then
+	echo "Need clang for test $0"
+	exit 1
+fi
+
+(cat <<EOF
+#define __tag(x) __attribute__((btf_decl_tag(#x)))
+
+__tag(a) __tag(b) __tag(c) void foo(void) {}
+__tag(a) __tag(b)          void bar(void) {}
+__tag(a)                   void buz(void) {}
+
+EOF
+) | $CLANG --target=bpf -c -g -x c -o $tmpobj -
+
+# tags order is not guaranteed
+sort_tags=$(cat <<EOF
+{
+match(\$0,/^(.*) (void .*)/,tags_and_proto);
+tags  = tags_and_proto[1];
+proto = tags_and_proto[2];
+split(tags, tags_arr ,/ /);
+asort(tags_arr);
+for (t in tags_arr) printf "%s ", tags_arr[t];
+print proto;
+}
+EOF
+)
+
+expected=$(cat <<EOF
+a b c void foo(void);
+a b void bar(void);
+a void buz(void);
+EOF
+)
+
+out=$(pfunct -P -F btf $tmpobj | awk "$sort_tags" | sort)
+d=$(diff -u <(echo "$expected") <(echo "$out"))
+
+if [[ "$d" == "" ]]; then
+	echo "Ok"
+	exit 0
+else
+	echo "pfunct output does not match expected:"
+	echo "$d"
+	echo
+	echo "Complete output:"
+	echo "$out"
+	exit 1
+fi
-- 
2.47.0


  reply	other threads:[~2024-12-11  2:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-11  2:12 [PATCH dwarves v1 1/2] btf_loader: support for multiple BTF_DECL_TAGs pointing to same tag Eduard Zingerman
2024-12-11  2:12 ` Eduard Zingerman [this message]
2024-12-12 19:50   ` [PATCH dwarves v1 2/2] tests: verify that pfunct prints btf_decl_tags read from BTF Alan Maguire
2024-12-12 19:54     ` Eduard Zingerman
2024-12-26 21:11     ` Arnaldo Carvalho de Melo
2024-12-26 21:14       ` Arnaldo Carvalho de Melo
2024-12-26 21:19         ` Arnaldo Carvalho de Melo
2025-01-03  1:18         ` Eduard Zingerman
2024-12-12 20:29 ` [PATCH dwarves v1 1/2] btf_loader: support for multiple BTF_DECL_TAGs pointing to same tag Alan Maguire
2024-12-12 20:36   ` Eduard Zingerman

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=20241211021227.2341735-2-eddyz87@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=arnaldo.melo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dwarves@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=yonghong.song@linux.dev \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.