Re: [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default

Arnaldo Carvalho de Melo
2024-11-19T17:50:16Z

On Tue, Nov 19, 2024 at 12:59:58PM +0000, Alan Maguire wrote:
> On 18/11/2024 20:41, Arnaldo Carvalho de Melo wrote:
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > On a system without any debugging info or when one specifies BTF as the
> > only BTF info desired but no BTF is available (or invalidated using
> > PAHOLE_VMLINUX_BTF_FILENAME to an invalid/non-existent file), we're
> > getting a segfault:
> >
> > root@x1:/home/acme/git/pahole# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
> > root@x1:/home/acme/git/pahole# pahole --running_kernel_vmlinux
> > pahole: couldn't find a vmlinux that matches the running kernel
> > HINT: Maybe you're inside a container or missing a debuginfo package?
> > root@x1:/home/acme/git/pahole# pahole
> > Segmentation fault (core dumped)
> > root@x1:/home/acme/git/pahole#
> >
> > So add a test that checks for that before we fix it:
> >
> > root@x1:/home/acme/git/pahole# tests/default_vmlinux_btf.sh
> > Default BTF on a system without BTF: FAILED
> > root@x1:/home/acme/git/pahole#
> >
> > Reported-by: Matthias Schwarzott <zzam@gentoo.org>
> > Cc: Alan Maguire <alan.maguire@oracle.com>
> > Cc: Andrii Nakryiko <andrii@kernel.org>
> > Cc: Eduard Zingerman <eddyz87@gmail.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Song Liu <song@kernel.org>
> > Cc: Yonghong Song <yonghong.song@linux.dev>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

Thanks, added to the cset,

- Arnaldo

> > ---
> > tests/default_vmlinux_btf.sh | 21 +++++++++++++++++++++
> > 1 file changed, 21 insertions(+)
> > create mode 100755 tests/default_vmlinux_btf.sh
> >
> > diff --git a/tests/default_vmlinux_btf.sh b/tests/default_vmlinux_btf.sh
> > new file mode 100755
> > index 0000000000000000..a9effa2d6d37e0ee
> > --- /dev/null
> > +++ b/tests/default_vmlinux_btf.sh
> > @@ -0,0 +1,21 @@
> > +#!/bin/bash
> > +
> > +echo -n "Default BTF on a system without BTF: "
> > +
> > +ulimit -c 0
> > +
> > +# To suppress the "Segmentation fault core dumped" message in bash we
> > +# pipe it to some other command, if it segfaults it will not produce any
> > +# lines and thus we can infer from the number of lines that the segfault
> > +# took place, tricky, but couldn't find any other way to check this
> > +# while suppressing the core dumped message. -acme
> > +
> > +nr_lines=$(PAHOLE_VMLINUX_BTF_FILENAME=foobar pahole -F btf list_head 2>&1 | wc -l)
> > +
> > +if [ $nr_lines -eq 0 ] ; then
> > + echo "FAILED"
> > + exit 1
> > +fi
> > +
> > +echo "Ok"
> > +exit 0