Skip to content

Commit 2d58468

Browse files
captain5050namhyung
authored andcommitted
perf test: Add header shell test
Add a shell test that sanity checks perf data and pipe mode produce expected header fields. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent dcbe6e5 commit 2d58468

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tools/perf/tests/shell/header.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# perf header tests
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
set -e
6+
7+
err=0
8+
perfdata=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX)
9+
script_output=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX.script)
10+
11+
cleanup() {
12+
rm -f "${perfdata}"
13+
rm -f "${perfdata}".old
14+
rm -f "${script_output}"
15+
16+
trap - EXIT TERM INT
17+
}
18+
19+
trap_cleanup() {
20+
echo "Unexpected signal in ${FUNCNAME[1]}"
21+
cleanup
22+
exit 1
23+
}
24+
trap trap_cleanup EXIT TERM INT
25+
26+
check_header_output() {
27+
declare -a fields=(
28+
"captured"
29+
"hostname"
30+
"os release"
31+
"arch"
32+
"cpuid"
33+
"nrcpus"
34+
"event"
35+
"cmdline"
36+
"perf version"
37+
"sibling (cores|dies|threads)"
38+
"sibling threads"
39+
"total memory"
40+
)
41+
for i in "${fields[@]}"
42+
do
43+
if ! grep -q -E "$i" "${script_output}"
44+
then
45+
echo "Failed to find expect $i in output"
46+
err=1
47+
fi
48+
done
49+
}
50+
51+
test_file() {
52+
echo "Test perf header file"
53+
54+
perf record -o "${perfdata}" -g -- perf test -w noploop
55+
perf report --header-only -I -i "${perfdata}" > "${script_output}"
56+
check_header_output
57+
58+
echo "Test perf header file [Done]"
59+
}
60+
61+
test_pipe() {
62+
echo "Test perf header pipe"
63+
64+
perf record -o - -g -- perf test -w noploop | perf report --header-only -I -i - > "${script_output}"
65+
check_header_output
66+
67+
echo "Test perf header pipe [Done]"
68+
}
69+
70+
test_file
71+
test_pipe
72+
73+
cleanup
74+
exit $err

0 commit comments

Comments
 (0)