1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
Georg Müller 98ce8e4a9d perf test uprobe_from_different_cu: Skip if there is no gcc
Without gcc, the test will fail.

On cleanup, ignore probe removal errors. Otherwise, in case of an error
adding the probe, the temporary directory is not removed.

Fixes: 56cbeacf14 ("perf probe: Add test for regression introduced by switch to die_get_decl_file()")
Signed-off-by: Georg Müller <georgmueller@gmx.net>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Georg Müller <georgmueller@gmx.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230728151812.454806-2-georgmueller@gmx.net
Link: https://lore.kernel.org/r/CAP-5=fUP6UuLgRty3t2=fQsQi3k4hDMz415vWdp1x88QMvZ8ug@mail.gmail.com/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-07-28 15:31:21 -03:00

83 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# test perf probe of function from different CU
# SPDX-License-Identifier: GPL-2.0
set -e
# skip if there's no gcc
if ! [ -x "$(command -v gcc)" ]; then
echo "failed: no gcc compiler"
exit 2
fi
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 || true
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
perf probe -x ${temp_dir}/testfile --funcs foo
perf probe -x ${temp_dir}/testfile foo
cleanup