mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anup Sharma <anupnewsmail@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Anup Sharma <anupnewsmail@gmail.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v5 8/8] perf test: Add support for testing perf gecko script
Date: Sat, 22 Jul 2023 00:00:21 +0530	[thread overview]
Message-ID: <e18ac2e37858ccf484d3ac16504f0cf898ad59cb.1689964167.git.anupnewsmail@gmail.com> (raw)
In-Reply-To: <cover.1689964167.git.anupnewsmail@gmail.com>

This commit add support for testing perf-gecko script.
This test checks for the presence of required sections such as "meta,"
"threads," "samples," "frameTable," "stackTable," "stringTable,"
and "pausedRanges" which are few essential parameter to be present
in output file. It also tests for user-defined color changes using
the --user-color flag, and verifies the validity of the JSON format
using Python's JSON library if available.

Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
---
 tools/perf/tests/shell/test_perf_gecko.sh | 188 ++++++++++++++++++++++
 1 file changed, 188 insertions(+)
 create mode 100755 tools/perf/tests/shell/test_perf_gecko.sh

diff --git a/tools/perf/tests/shell/test_perf_gecko.sh b/tools/perf/tests/shell/test_perf_gecko.sh
new file mode 100755
index 000000000000..5c5f61438579
--- /dev/null
+++ b/tools/perf/tests/shell/test_perf_gecko.sh
@@ -0,0 +1,188 @@
+#!/bin/bash
+# perf script perf-gecko test
+# SPDX-License-Identifier: GPL-2.0
+
+err=0
+
+if [ "$PYTHON" = "" ] ; then
+	if which python3 > /dev/null ; then
+		PYTHON=python3
+	elif which python > /dev/null ; then
+		PYTHON=python
+	else
+		echo Skipping JSON format check, python not detected please set environment variable PYTHON.
+		PYTHON_NOT_AVAILABLE=1
+	fi
+fi
+
+# set PERF_EXEC_PATH to find scripts in the source directory
+perfdir=$(dirname "$0")/../..
+if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then
+  export PERF_EXEC_PATH=$perfdir
+fi
+
+tmpdir=$(mktemp -d /tmp/perf-script-perf-gecko-XXXXX)
+
+cleanup() {
+  rm -f perf.data
+  rm -f perf.data.old
+  rm -rf "$tmpdir"
+  trap - exit term int
+}
+
+trap_cleanup() {
+  cleanup
+  exit 1
+}
+trap trap_cleanup exit term int
+
+report() {
+	if [ "$1" = 0 ]; then
+		echo "PASS: \"$2\""
+	else
+		echo "FAIL: \"$2\" Error message: \"$3\""
+		err=1
+	fi
+}
+
+check_exec_0() {
+	if [ $? != 0 ]; then
+		report 1 "invocation of $1 command failed"
+	fi
+}
+
+find_str_or_fail() {
+	#echo "\"$1"\"
+	#echo "\"$2"\"
+	grep -q "$1" "$2"
+	if [ "$?" != 0 ]; then
+		report 1 "$3" "Failed to find required string:'${1}'."
+	else
+		report 0 "$3"
+	fi
+}
+
+prepare_perf_data() {
+	# 3s should be sufficient to catch few samples
+	perf record -g -- sleep 3 > /dev/null 2>&1
+	# check if perf data file got created in above step.
+	if [ ! -e "perf.data" ]; then
+		printf "FAIL: perf record failed to create \"perf.data\" \n"
+		return 1
+	fi
+}
+
+# check execution of command
+test_perf_gecko_command()
+{
+	echo "Testing Perf Gecko Command"
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	if [ $(cat "${out}" | wc -l) -gt "0" ] ; then
+		echo "PASS: \"Perf Gecko Command\""
+	else
+		echo "FAIL: \"Perf Gecko Command\""
+		err=1
+		exit
+	fi
+}
+
+# with the help of python json libary validate the json output
+if [ "$PYTHON_NOT_AVAILABLE" != "0" ]; then
+	validate_json_format()
+	{
+		out="$tmpdir/perf.out"
+		if [ -f "$out" ] ; then
+			if $PYTHON -c  "import json; json.load(open('$out'))" >/dev/null 2>&1 ; then
+				echo "PASS: \"The file contains valid JSON format\""
+			else
+				echo "FAIL: \"The file does not contain valid JSON format\""
+				err=1
+				exit
+			fi
+		else
+			echo "FAIL: \"File not found\""
+			err=2
+			exit
+		fi
+	}
+fi
+
+# validate output for the presence of "meta".
+test_meta() {
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	find_str_or_fail "meta" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "threads".
+test_threads() {
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	find_str_or_fail "threads" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "samples".
+test_samples() {
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	find_str_or_fail "samples" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "frameTable".
+test_frametable() {
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	find_str_or_fail "frameTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stackTable".
+test_stacktable() {
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	find_str_or_fail "stackTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stringTable"
+test_stringtable() {
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	find_str_or_fail "stringTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "pausedRanges".
+test_pauseranges(){
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko > "$out"
+	check_exec_0 "perf script report perf-gecko"
+	find_str_or_fail "pausedRanges" "$out" "${FUNCNAME[0]}"
+}
+
+# validate user-defined color presence in output "green"
+test_categorycolorchange(){
+	out="$tmpdir/perf.out"
+	perf script report perf-gecko --user-color="green"> "$out"
+	check_exec_0 "perf script report perf-gecko --user-color"
+	find_str_or_fail "green" "$out" "${FUNCNAME[0]}"
+}
+
+prepare_perf_data
+test_perf_gecko_command
+validate_json_format
+test_meta
+test_threads
+test_samples
+test_frametable
+test_stacktable
+test_stringtable
+test_pauseranges
+test_categorycolorchange
+cleanup
+exit $err
-- 
2.34.1


           reply	other threads:[~2023-07-21 18:30 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <cover.1689964167.git.anupnewsmail@gmail.com>]

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=e18ac2e37858ccf484d3ac16504f0cf898ad59cb.1689964167.git.anupnewsmail@gmail.com \
    --to=anupnewsmail@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®