Skip to content

Commit 279385c

Browse files
captain5050namhyung
authored andcommitted
perf tests timechart: Add a perf timechart test
Basic coverage for `perf timechart` doing a record and then a basic sanity test of the generated SVG file. Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 75e9617 commit 279385c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
# perf timechart tests
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
set -e
6+
7+
err=0
8+
perfdata=$(mktemp /tmp/__perf_timechart_test.perf.data.XXXXX)
9+
output=$(mktemp /tmp/__perf_timechart_test.output.XXXXX.svg)
10+
11+
cleanup() {
12+
rm -f "${perfdata}"
13+
rm -f "${output}"
14+
trap - EXIT TERM INT
15+
}
16+
17+
trap_cleanup() {
18+
echo "Unexpected signal in ${FUNCNAME[1]}"
19+
cleanup
20+
exit 1
21+
}
22+
trap trap_cleanup EXIT TERM INT
23+
24+
test_timechart() {
25+
echo "Basic perf timechart test"
26+
27+
# Try to record timechart data.
28+
# perf timechart record uses system-wide recording and specific tracepoints.
29+
# If it fails (e.g. permissions, missing tracepoints), skip the test.
30+
if ! perf timechart record -o "${perfdata}" true > /dev/null 2>&1; then
31+
echo "Basic perf timechart test [Skipped: perf timechart record failed (permissions/events?)]"
32+
return
33+
fi
34+
35+
# Generate the timechart
36+
if ! perf timechart -i "${perfdata}" -o "${output}" > /dev/null 2>&1; then
37+
echo "Basic perf timechart test [Failed: perf timechart command failed]"
38+
err=1
39+
return
40+
fi
41+
42+
# Check if output file exists and is not empty
43+
if [ ! -s "${output}" ]; then
44+
echo "Basic perf timechart test [Failed: output file is empty or missing]"
45+
err=1
46+
return
47+
fi
48+
49+
# Check if it looks like an SVG
50+
if ! grep -q "svg" "${output}"; then
51+
echo "Basic perf timechart test [Failed: output doesn't look like SVG]"
52+
err=1
53+
return
54+
fi
55+
56+
echo "Basic perf timechart test [Success]"
57+
}
58+
59+
if ! perf check feature -q libtraceevent ; then
60+
echo "perf timechart is not supported. Skip."
61+
cleanup
62+
exit 2
63+
fi
64+
65+
test_timechart
66+
cleanup
67+
exit $err

0 commit comments

Comments
 (0)