lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251122081929.7588-13-irogers@google.com>
Date: Sat, 22 Nov 2025 00:19:24 -0800
From: Ian Rogers <irogers@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>, 
	Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>, 
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>, 
	Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>, 
	James Clark <james.clark@...aro.org>, Collin Funk <collin.funk1@...il.com>, 
	Dmitry Vyukov <dvyukov@...gle.com>, Andi Kleen <ak@...ux.intel.com>, 
	Thomas Falcon <thomas.falcon@...el.com>, Leo Yan <leo.yan@....com>, 
	Yicong Yang <yangyicong@...ilicon.com>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>, 
	"Masami Hiramatsu (Google)" <mhiramat@...nel.org>, Stephen Brennan <stephen.s.brennan@...cle.com>, 
	Haibo Xu <haibo1.xu@...el.com>, linux-kernel@...r.kernel.org, 
	linux-perf-users@...r.kernel.org
Subject: [PATCH v1 12/17] 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@...gle.com>
---
 tools/perf/tests/shell/top.sh | 74 +++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100755 tools/perf/tests/shell/top.sh

diff --git a/tools/perf/tests/shell/top.sh b/tools/perf/tests/shell/top.sh
new file mode 100755
index 000000000000..768ebcf7a89c
--- /dev/null
+++ b/tools/perf/tests/shell/top.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+# perf top tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+log_file=$(mktemp /tmp/perf.top.log.XXXXX)
+
+cleanup() {
+	rm -f "${log_file}"
+	trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+	echo "Unexpected signal in ${FUNCNAME[1]}"
+	cleanup
+	exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+test_basic_perf_top() {
+	echo "Basic perf top test"
+
+	# Start a workload that spins to generate samples
+	# thloop runs for the specified number of seconds
+	perf test -w thloop 20 &
+	PID=$!
+
+	# Allow it to start
+	sleep 0.1
+
+	# Run perf top for 5 seconds, monitoring that PID
+	# Use --stdio to avoid TUI and redirect output
+	# Use -d 1 to avoid flooding output
+	# Use -e cpu-clock to ensure we get samples
+	# Use sleep to keep stdin open but silent, preventing EOF loop or interactive spam
+	if ! sleep 10 | timeout 5s perf top --stdio -d 1 -e cpu-clock -p $PID > "${log_file}" 2>&1; then
+		retval=$?
+		if [ $retval -ne 124 ] && [ $retval -ne 0 ]; then
+			echo "Basic perf top test [Failed: perf top failed to start or run (ret=$retval)]"
+			head -n 50 "${log_file}"
+			kill $PID
+			wait $PID 2>/dev/null || true
+			err=1
+			return
+		fi
+	fi
+
+	kill $PID
+	wait $PID 2>/dev/null || true
+
+	# Check for some sample data (percentage)
+	if ! grep -E -q "[0-9]+\.[0-9]+%" "${log_file}"; then
+		echo "Basic perf top test [Failed: no sample percentage found]"
+		head -n 50 "${log_file}"
+		err=1
+		return
+	fi
+
+	# Check for the symbol
+	if ! grep -q "test_loop" "${log_file}"; then
+		echo "Basic perf top test [Failed: test_loop symbol not found]"
+		head -n 50 "${log_file}"
+		err=1
+		return
+	fi
+
+	echo "Basic perf top test [Success]"
+}
+
+test_basic_perf_top
+cleanup
+exit $err
-- 
2.52.0.rc2.455.g230fcf2819-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ