Message ID | 20241211021227.2341735-2-eddyz87@gmail.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | [dwarves,v1,1/2] btf_loader: support for multiple BTF_DECL_TAGs pointing to same tag | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
On 11/12/2024 02:12, Eduard Zingerman wrote: > 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> nit: the test is great but it would be good to print out a description even in non-verbose mode; when I run it via ./tests I see 5: Ok could we just echo the comment below, i.e. 5 : Check that pfunct can print btf_decl_tags read from BTF: Ok ? Reviewed-by: Alan Maguire <alan.maguire@oracle.com> Tested-by: Alan Maguire <alan.maguire@oracle.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
On Thu, 2024-12-12 at 19:50 +0000, Alan Maguire wrote: > On 11/12/2024 02:12, Eduard Zingerman wrote: > > 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> > > nit: the test is great but it would be good to print out a description > even in non-verbose mode; when I run it via ./tests I see > > 5: Ok > > could we just echo the comment below, i.e. > > 5 : Check that pfunct can print btf_decl_tags read from BTF: Ok > > ? > > Reviewed-by: Alan Maguire <alan.maguire@oracle.com> > Tested-by: Alan Maguire <alan.maguire@oracle.com> Makes sense, will change. Will wait a bit and resend v2 in the evening. Thank you. [...]
On Thu, Dec 12, 2024 at 07:50:57PM +0000, Alan Maguire wrote: > On 11/12/2024 02:12, Eduard Zingerman wrote: > > 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> > > nit: the test is great but it would be good to print out a description > even in non-verbose mode; when I run it via ./tests I see > > 5: Ok > > could we just echo the comment below, i.e. > > 5 : Check that pfunct can print btf_decl_tags read from BTF: Ok > > ? > > Reviewed-by: Alan Maguire <alan.maguire@oracle.com> > Tested-by: Alan Maguire <alan.maguire@oracle.com> Thanks, applied. - Arnaldo
On Thu, Dec 26, 2024 at 06:11:57PM -0300, Arnaldo Carvalho de Melo wrote: > On Thu, Dec 12, 2024 at 07:50:57PM +0000, Alan Maguire wrote: > > On 11/12/2024 02:12, Eduard Zingerman wrote: > > > 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> > > > > nit: the test is great but it would be good to print out a description > > even in non-verbose mode; when I run it via ./tests I see > > > > 5: Ok > > > > could we just echo the comment below, i.e. > > > > 5 : Check that pfunct can print btf_decl_tags read from BTF: Ok > > > > ? To clarify, I'm doing as Alan suggests and adding that message when the test succeeds. > > Reviewed-by: Alan Maguire <alan.maguire@oracle.com> > > Tested-by: Alan Maguire <alan.maguire@oracle.com> > > Thanks, applied. > > - Arnaldo >
On Thu, Dec 26, 2024 at 06:14:12PM -0300, Arnaldo Carvalho de Melo wrote: > On Thu, Dec 26, 2024 at 06:11:57PM -0300, Arnaldo Carvalho de Melo wrote: > > On Thu, Dec 12, 2024 at 07:50:57PM +0000, Alan Maguire wrote: > > > On 11/12/2024 02:12, Eduard Zingerman wrote: > > > > 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> > > > > > > nit: the test is great but it would be good to print out a description > > > even in non-verbose mode; when I run it via ./tests I see > > > > > > 5: Ok > > > > > > could we just echo the comment below, i.e. > > > > > > 5 : Check that pfunct can print btf_decl_tags read from BTF: Ok > > > > > > ? > > To clarify, I'm doing as Alan suggests and adding that message when the > test succeeds. Running just this test: root@number:/home/acme/git/pahole# tests/pfunct-btf-decl-tags.sh Check that pfunct can print btf_decl_tags read from BTF: Ok root@number:/home/acme/git/pahole# > > > Reviewed-by: Alan Maguire <alan.maguire@oracle.com> > > > Tested-by: Alan Maguire <alan.maguire@oracle.com> > > > > Thanks, applied. > > > > - Arnaldo > >
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
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