selftest/perf: Add perf-test to perform perf testcase
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.
Signed-off-by Jeremy Szu <[email protected]>
--- 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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1 @@ +timeout=600
Signature · 1 line
2.34.1