Skip to content

Commit 2273697

Browse files
captain5050acmel
authored andcommitted
perf test script: Add perl script testing support
Basic coverage of perl script support from `perf script`. This is disabled by default and so the test will most normally skip. Committer testing: $ perf test 'perf script perl' 106: perf script perl tests : Skip $ perf test -vv 'perf script perl' 106: perf script perl tests: --- start --- test child forked, pid 578323 perf script perl test [Skipped: no libperl support] ---- end(-2) ---- 106: perf script perl tests : Skip $ perf check feature libperl libperl: [ OFF ] # HAVE_LIBPERL_SUPPORT ( tip: Deprecated, use LIBPERL=1 and install perl-ExtUtils-Embed/libperl-dev to build with it ) $ Install perl-ExtUtils-Embed, build with LIBPERL=1, rebuild: $ perf check feature libperl libperl: [ on ] # HAVE_LIBPERL_SUPPORT $ perf test 'perf script perl' 106: perf script perl tests : Ok $ perf test -vv 'perf script perl' 106: perf script perl tests: --- start --- test child forked, pid 588206 Testing event: sched:sched_switch perf script perl test [Skipped: failed to record sched:sched_switch] Testing event: task-clock Generating perl script... generated Perl script: /tmp/__perf_test_script.RpMn5.pl Executing perl script... perf script perl test [Success: task-clock triggered $VAR1] ---- end(0) ---- 106: perf script perl tests : Ok $ Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Leo Yan <leo.yan@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Yujie Liu <yujie.liu@intel.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 22ca2f7 commit 2273697

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
# perf script perl tests
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
set -e
6+
7+
# set PERF_EXEC_PATH to find scripts in the source directory
8+
perfdir=$(dirname "$0")/../..
9+
if [ -e "$perfdir/scripts/perl/Perf-Trace-Util" ]; then
10+
export PERF_EXEC_PATH=$perfdir
11+
fi
12+
13+
14+
perfdata=$(mktemp /tmp/__perf_test_script_perl.perf.data.XXXXX)
15+
generated_script=$(mktemp /tmp/__perf_test_script.XXXXX.pl)
16+
17+
cleanup() {
18+
rm -f "${perfdata}"
19+
rm -f "${generated_script}"
20+
trap - EXIT TERM INT
21+
}
22+
23+
trap_cleanup() {
24+
echo "Unexpected signal in ${FUNCNAME[1]}"
25+
cleanup
26+
exit 1
27+
}
28+
trap trap_cleanup TERM INT
29+
trap cleanup EXIT
30+
31+
check_perl_support() {
32+
if perf check feature -q libperl; then
33+
return 0
34+
fi
35+
echo "perf script perl test [Skipped: no libperl support]"
36+
return 2
37+
}
38+
39+
test_script() {
40+
local event_name=$1
41+
local expected_output=$2
42+
local record_opts=$3
43+
44+
echo "Testing event: $event_name"
45+
46+
# Try to record. If this fails, it might be permissions or lack of support.
47+
# We return 2 to indicate "skip this event" rather than "fail test".
48+
if ! perf record -o "${perfdata}" -e "$event_name" $record_opts -- perf test -w thloop > /dev/null 2>&1; then
49+
echo "perf script perl test [Skipped: failed to record $event_name]"
50+
return 2
51+
fi
52+
53+
echo "Generating perl script..."
54+
if ! perf script -i "${perfdata}" -g "${generated_script}"; then
55+
echo "perf script perl test [Failed: script generation for $event_name]"
56+
return 1
57+
fi
58+
59+
if [ ! -f "${generated_script}" ]; then
60+
echo "perf script perl test [Failed: script not generated for $event_name]"
61+
return 1
62+
fi
63+
64+
echo "Executing perl script..."
65+
output=$(perf script -i "${perfdata}" -s "${generated_script}" 2>&1)
66+
67+
if echo "$output" | grep -q "$expected_output"; then
68+
echo "perf script perl test [Success: $event_name triggered $expected_output]"
69+
return 0
70+
else
71+
echo "perf script perl test [Failed: $event_name did not trigger $expected_output]"
72+
echo "Output was:"
73+
echo "$output" | head -n 20
74+
return 1
75+
fi
76+
}
77+
78+
check_perl_support || exit 2
79+
80+
# Try tracepoint first
81+
test_script "sched:sched_switch" "sched::sched_switch" "-c 1" && res=0 || res=$?
82+
83+
if [ $res -eq 0 ]; then
84+
exit 0
85+
elif [ $res -eq 1 ]; then
86+
exit 1
87+
fi
88+
89+
# If tracepoint skipped (res=2), try task-clock
90+
# For generic events like task-clock, the generated script uses process_event()
91+
# which dumps data using Data::Dumper. We check for "$VAR1" which is standard Dumper output.
92+
test_script "task-clock" "\$VAR1" "-c 100" && res=0 || res=$?
93+
94+
if [ $res -eq 0 ]; then
95+
exit 0
96+
elif [ $res -eq 1 ]; then
97+
exit 1
98+
fi
99+
100+
# If both skipped
101+
echo "perf script perl test [Skipped: Could not record tracepoint or task-clock]"
102+
exit 2

0 commit comments

Comments
 (0)