Skip to content

Commit 75e9617

Browse files
captain5050namhyung
authored andcommitted
perf tests top: Add basic perf top coverage test
The test starts a backgroup thloop workload and monitors it using cpu-clock ensuring test_loop appears in the output. Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 0eb307d commit 75e9617

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tools/perf/tests/shell/top.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# perf top tests
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
set -e
6+
7+
err=0
8+
log_file=$(mktemp /tmp/perf.top.log.XXXXX)
9+
10+
cleanup() {
11+
rm -f "${log_file}"
12+
trap - EXIT TERM INT
13+
}
14+
15+
trap_cleanup() {
16+
echo "Unexpected signal in ${FUNCNAME[1]}"
17+
cleanup
18+
exit 1
19+
}
20+
trap trap_cleanup EXIT TERM INT
21+
22+
test_basic_perf_top() {
23+
echo "Basic perf top test"
24+
25+
# Start a workload that spins to generate samples
26+
# thloop runs for the specified number of seconds
27+
perf test -w thloop 20 &
28+
PID=$!
29+
30+
# Allow it to start
31+
sleep 0.1
32+
33+
# Run perf top for 5 seconds, monitoring that PID
34+
# Use --stdio to avoid TUI and redirect output
35+
# Use -d 1 to avoid flooding output
36+
# Use -e cpu-clock to ensure we get samples
37+
# Use sleep to keep stdin open but silent, preventing EOF loop or interactive spam
38+
if ! sleep 10 | timeout 5s perf top --stdio -d 1 -e cpu-clock -p $PID > "${log_file}" 2>&1; then
39+
retval=$?
40+
if [ $retval -ne 124 ] && [ $retval -ne 0 ]; then
41+
echo "Basic perf top test [Failed: perf top failed to start or run (ret=$retval)]"
42+
head -n 50 "${log_file}"
43+
kill $PID
44+
wait $PID 2>/dev/null || true
45+
err=1
46+
return
47+
fi
48+
fi
49+
50+
kill $PID
51+
wait $PID 2>/dev/null || true
52+
53+
# Check for some sample data (percentage)
54+
if ! grep -E -q "[0-9]+\.[0-9]+%" "${log_file}"; then
55+
echo "Basic perf top test [Failed: no sample percentage found]"
56+
head -n 50 "${log_file}"
57+
err=1
58+
return
59+
fi
60+
61+
# Check for the symbol
62+
if ! grep -q "test_loop" "${log_file}"; then
63+
echo "Basic perf top test [Failed: test_loop symbol not found]"
64+
head -n 50 "${log_file}"
65+
err=1
66+
return
67+
fi
68+
69+
echo "Basic perf top test [Success]"
70+
}
71+
72+
test_basic_perf_top
73+
cleanup
74+
exit $err

0 commit comments

Comments
 (0)