Skip to contentSkip to conversation

selftest/perf: Add perf-test to perform perf testcase

PATCH New Jeremy Szu 1 participant 1 message Aug 6, 2024 Kselftest

lore
Share & tools
lore

Jeremy Szu

author
#0 lore raw

PATCH 1/1 selftest/perf: Add perf-test to perform perf testcase

The perf test supports testing many functions and includes a way to detect the prerequisites for each test case. Add a script to launch the perf test.

---
 tools/testing/selftests/Makefile          |  1 +
 tools/testing/selftests/perf/Makefile     |  5 ++++
 tools/testing/selftests/perf/perf_test.sh | 30 +++++++++++++++++++++++
 tools/testing/selftests/perf/settings     |  1 +
 4 files changed, 37 insertions(+)
 create mode 100644 tools/testing/selftests/perf/Makefile
 create mode 100755 tools/testing/selftests/perf/perf_test.sh
 create mode 100644 tools/testing/selftests/perf/settings
tools/testing/selftests/Makefile +1 -0
index 9039f3709affb..7598dd39cad28 100644
@@ -67,6 +67,7 @@ TARGETS += net/openvswitch
 TARGETS += net/tcp_ao
 TARGETS += net/netfilter
 TARGETS += nsfs
+TARGETS += perf
 TARGETS += perf_events
 TARGETS += pidfd
 TARGETS += pid_namespace
tools/testing/selftests/perf/Makefile new file +5 -0
new file mode 100644
index 0000000000000..72d90c71ab290
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := perf_test.sh
+
+include ../lib.mk
tools/testing/selftests/perf/perf_test.sh new file +30 -0
new file mode 100755
index 0000000000000..ee78b4f9906cd
@@ -0,0 +1,30 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+skip() {
+    echo "SKIP: $1"
+    exit 4
+}
+
+fail() {
+    echo "FAIL: $1"
+    exit 255
+}
+
+if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
+    [ "$(id -u)" -ne 0 ] && \
+        skip "this test must be run as root."
+    which perf >/dev/null 2>&1 || \
+        skip "perf is not installed."
+
+    cmd_output=$(perf test -vv 2>&1)
+    perf_ret=$?
+
+    if [ $perf_ret -ne 0 ]; then
+        (IFS='\n'; echo $cmd_output)
+        fail "perf command returns non-zero."
+    elif [[ $cmd_output == *"FAILED!"* ]]; then
+        (IFS='\n'; echo $cmd_output)
+        fail "perf test got FAILED!"
+    fi
+fi
tools/testing/selftests/perf/settings new file +1 -0
new file mode 100644
index 0000000000000..a62d2fa1275c6
@@ -0,0 +1 @@
+timeout=600
Signature · 1 line
2.34.1