Messages in this thread | | | From | Ian Rogers <> | Date | Thu, 27 Jul 2023 10:45:21 -0700 | Subject | Re: [PATCH v2 1/2] perf probe: add test for regression introduced by switch to die_get_decl_file |
| |
On Wed, Jun 28, 2023 at 1:25 AM Georg Müller <georgmueller@gmx.net> wrote: > > This patch adds a test to validate that perf probe works for binaries > where DWARF info is split into multiple CUs > > Signed-off-by: Georg Müller <georgmueller@gmx.net> > Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/ > --- > .../shell/test_uprobe_from_different_cu.sh | 77 +++++++++++++++++++ > 1 file changed, 77 insertions(+) > create mode 100755 tools/perf/tests/shell/test_uprobe_from_different_cu.sh > > diff --git a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh > new file mode 100755 > index 000000000000..00d2e0e2e0c2 > --- /dev/null > +++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh > @@ -0,0 +1,77 @@ > +#!/bin/bash > +# test perf probe of function from different CU > +# SPDX-License-Identifier: GPL-2.0 > + > +set -e > + > +temp_dir=$(mktemp -d /tmp/perf-uprobe-different-cu-sh.XXXXXXXXXX) > + > +cleanup() > +{ > + trap - EXIT TERM INT > + if [[ "${temp_dir}" =~ ^/tmp/perf-uprobe-different-cu-sh.*$ ]]; then > + echo "--- Cleaning up ---" > + perf probe -x ${temp_dir}/testfile -d foo > + rm -f "${temp_dir}/"* > + rmdir "${temp_dir}" > + fi > +} > + > +trap_cleanup() > +{ > + cleanup > + exit 1 > +} > + > +trap trap_cleanup EXIT TERM INT > + > +cat > ${temp_dir}/testfile-foo.h << EOF > +struct t > +{ > + int *p; > + int c; > +}; > + > +extern int foo (int i, struct t *t); > +EOF > + > +cat > ${temp_dir}/testfile-foo.c << EOF > +#include "testfile-foo.h" > + > +int > +foo (int i, struct t *t) > +{ > + int j, res = 0; > + for (j = 0; j < i && j < t->c; j++) > + res += t->p[j]; > + > + return res; > +} > +EOF > + > +cat > ${temp_dir}/testfile-main.c << EOF > +#include "testfile-foo.h" > + > +static struct t g; > + > +int > +main (int argc, char **argv) > +{ > + int i; > + int j[argc]; > + g.c = argc; > + g.p = j; > + for (i = 0; i < argc; i++) > + j[i] = (int) argv[i][0]; > + return foo (3, &g); > +} > +EOF > + > +gcc -g -Og -flto -c ${temp_dir}/testfile-foo.c -o ${temp_dir}/testfile-foo.o > +gcc -g -Og -c ${temp_dir}/testfile-main.c -o ${temp_dir}/testfile-main.o > +gcc -g -Og -o ${temp_dir}/testfile ${temp_dir}/testfile-foo.o ${temp_dir}/testfile-main.o
Thanks for the test Georg! By directly relying on gcc this test fails for me in some constrained environments, like containers. I think there should be a skip if gcc isn't present. A different option is to just build the test code into the perf binary itself as a test workload: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/workloads?h=perf-tools-next
Wdyt? Thanks, Ian
> + > +perf probe -x ${temp_dir}/testfile --funcs foo > +perf probe -x ${temp_dir}/testfile foo > + > +cleanup > -- > 2.41.0 >
| |