Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Jeremy Szu <jszu@nvidia.com>
To: shuah@kernel.org, linux-kselftest@vger.kernel.org,
	james.clark@arm.com, linux-perf-users@vger.kernel.org
Cc: Jeremy Szu <jszu@nvidia.com>
Subject: [PATCH] selftest/perf: Add perf-test to perform perf testcase
Date: Tue,  6 Aug 2024 16:10:43 +0800	[thread overview]
Message-ID: <20240806081043.44935-1-jszu@nvidia.com> (raw)

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 <jszu@nvidia.com>
---
 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

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 9039f3709affb..7598dd39cad28 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -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
diff --git a/tools/testing/selftests/perf/Makefile b/tools/testing/selftests/perf/Makefile
new file mode 100644
index 0000000000000..72d90c71ab290
--- /dev/null
+++ b/tools/testing/selftests/perf/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_PROGS := perf_test.sh
+
+include ../lib.mk
diff --git a/tools/testing/selftests/perf/perf_test.sh b/tools/testing/selftests/perf/perf_test.sh
new file mode 100755
index 0000000000000..ee78b4f9906cd
--- /dev/null
+++ b/tools/testing/selftests/perf/perf_test.sh
@@ -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
diff --git a/tools/testing/selftests/perf/settings b/tools/testing/selftests/perf/settings
new file mode 100644
index 0000000000000..a62d2fa1275c6
--- /dev/null
+++ b/tools/testing/selftests/perf/settings
@@ -0,0 +1 @@
+timeout=600
-- 
2.34.1


                 reply	other threads:[~2024-08-06  8:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240806081043.44935-1-jszu@nvidia.com \
    --to=jszu@nvidia.com \
    --cc=james.clark@arm.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox