Skip to contentSkip to conversation

perf test: Add support for testing gecko script

PATCH Superseded Anup Sharma 2 participants 3 messages Aug 9, 2023 – Aug 11, 2023 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf test: Add support for testing gecko script

This commit add support for testing gecko script. The 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. Also it verifies the validity of the JSON format using Python's JSON library if available.

---
 tools/perf/tests/shell/test_gecko.sh | 131 +++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 tools/perf/tests/shell/test_gecko.sh
tools/perf/tests/shell/test_gecko.sh new file +131 -0
new file mode 100644
index 000000000000..457c85474a62
@@ -0,0 +1,131 @@
+#!/bin/bash
+# perf script gecko test
+# SPDX-License-Identifier: GPL-2.0
+
+err=0
+
+cleanup() {
+  rm -rf gecko_profile.json
+  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
+}
+
+find_str_or_fail() {
+    grep -q "$1" <<< "$2"
+    if [ "$?" != 0 ]; then
+        report 1 "$3" "Failed to find required string:'${1}'."
+    else
+        report 0 "$3"
+    fi
+}
+
+# To validate the json format, check if python is installed
+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
+
+# Check execution of perf script gecko command
+test_gecko_command() {
+    echo "Testing Gecko Command"
+    perf script gecko -a sleep 0.5
+	# Store the content of the file in the 'out' variable
+    out=$(< "gecko_profile.json")
+	# Get the length of the gecko_profile.json output in 'out'
+	length=${#out}
+	if [ "$length" -gt 0 ]; then
+        echo "PASS: \"Gecko Command\""
+    else
+        echo "FAIL: \"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()
+	{
+		if [ "$out" ] ; then
+			if [ "$PYTHON -c import json; json.load($out)" ]; 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() {
+    find_str_or_fail "meta" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "threads".
+test_threads() {
+	find_str_or_fail "threads" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "samples".
+test_samples() {
+	find_str_or_fail "samples" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "frameTable".
+test_frametable() {
+	find_str_or_fail "frameTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stackTable".
+test_stacktable() {
+	find_str_or_fail "stackTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stringTable"
+test_stringtable() {
+	find_str_or_fail "stringTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "pausedRanges".
+test_pauseranges(){
+	find_str_or_fail "pausedRanges" "$out" "${FUNCNAME[0]}"
+}
+
+prepare_perf_data
+test_gecko_command
+validate_json_format
+test_meta
+test_threads
+test_samples
+test_frametable
+test_stacktable
+test_stringtable
+test_pauseranges
+cleanup
+exit $err
Signature · 1 line
2.34.1
reviewer
#1 lore raw
Quoted 9 lines · Anup Sharma

This commit add support for testing gecko script. The 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. Also it verifies the validity of the JSON format using Python's JSON library if available.

Hi Anup,

I was trying to test this and grabbing other patches didn't resolve the issue I see:

```
111: perf script gecko test                                          :
--- start ---
test child forked, pid 2886031
./tools/perf/tests/shell/test_gecko.sh: line 120: prepare_perf_data:
command not found
Testing Gecko Command
 Error: Couldn't find script `gecko'
...
```

It can be useful when sending a patch like this to, under a ---, list patches necessary for testing.

Thanks,
Ian

Quoted 145 lines
---
 tools/perf/tests/shell/test_gecko.sh | 131 +++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 tools/perf/tests/shell/test_gecko.sh
tools/perf/tests/shell/test_gecko.sh new file +131 -1
new file mode 100644
index 000000000000..457c85474a62
@@ -0,0 +1,131 @@
+#!/bin/bash
+# perf script gecko test
+# SPDX-License-Identifier: GPL-2.0
+
+err=0
+
+cleanup() {
+  rm -rf gecko_profile.json
+  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
+}
+
+find_str_or_fail() {
+    grep -q "$1" <<< "$2"
+    if [ "$?" != 0 ]; then
+        report 1 "$3" "Failed to find required string:'${1}'."
+    else
+        report 0 "$3"
+    fi
+}
+
+# To validate the json format, check if python is installed
+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
+
+# Check execution of perf script gecko command
+test_gecko_command() {
+    echo "Testing Gecko Command"
+    perf script gecko -a sleep 0.5
+       # Store the content of the file in the 'out' variable
+    out=$(< "gecko_profile.json")
+       # Get the length of the gecko_profile.json output in 'out'
+       length=${#out}
+       if [ "$length" -gt 0 ]; then
+        echo "PASS: \"Gecko Command\""
+    else
+        echo "FAIL: \"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()
+       {
+               if [ "$out" ] ; then
+                       if [ "$PYTHON -c import json; json.load($out)" ]; 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() {
+    find_str_or_fail "meta" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "threads".
+test_threads() {
+       find_str_or_fail "threads" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "samples".
+test_samples() {
+       find_str_or_fail "samples" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "frameTable".
+test_frametable() {
+       find_str_or_fail "frameTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stackTable".
+test_stacktable() {
+       find_str_or_fail "stackTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stringTable"
+test_stringtable() {
+       find_str_or_fail "stringTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "pausedRanges".
+test_pauseranges(){
+       find_str_or_fail "pausedRanges" "$out" "${FUNCNAME[0]}"
+}
+
+prepare_perf_data
+test_gecko_command
+validate_json_format
+test_meta
+test_threads
+test_samples
+test_frametable
+test_stacktable
+test_stringtable
+test_pauseranges
+cleanup
+exit $err
--

2.34.1

#2 lore raw
Quoted 13 lines · Ian Rogers
Quoted 9 lines · Anup Sharma

This commit add support for testing gecko script. The 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. Also it verifies the validity of the JSON format using Python's JSON library if available.

Hi Anup,

Quoted 8 lines

I was trying to test this and grabbing other patches didn't resolve the issue I see:
```
111: perf script gecko test :
--- start ---
test child forked, pid 2886031 ./tools/perf/tests/shell/test_gecko.sh: line 120: prepare_perf_data:
command not found

got it, will fix it.

Quoted 7 lines

Testing Gecko Command
Error: Couldn't find script `gecko'
...
```

It can be useful when sending a patch like this to, under a ---, list patches necessary for testing.

Thanks will send the v2 after adding the patch list.

Quoted 148 lines

Thanks,
Ian

Quoted 145 lines
---
 tools/perf/tests/shell/test_gecko.sh | 131 +++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 tools/perf/tests/shell/test_gecko.sh
tools/perf/tests/shell/test_gecko.sh new file +131 -1
new file mode 100644
index 000000000000..457c85474a62
@@ -0,0 +1,131 @@
+#!/bin/bash
+# perf script gecko test
+# SPDX-License-Identifier: GPL-2.0
+
+err=0
+
+cleanup() {
+  rm -rf gecko_profile.json
+  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
+}
+
+find_str_or_fail() {
+    grep -q "$1" <<< "$2"
+    if [ "$?" != 0 ]; then
+        report 1 "$3" "Failed to find required string:'${1}'."
+    else
+        report 0 "$3"
+    fi
+}
+
+# To validate the json format, check if python is installed
+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
+
+# Check execution of perf script gecko command
+test_gecko_command() {
+    echo "Testing Gecko Command"
+    perf script gecko -a sleep 0.5
+       # Store the content of the file in the 'out' variable
+    out=$(< "gecko_profile.json")
+       # Get the length of the gecko_profile.json output in 'out'
+       length=${#out}
+       if [ "$length" -gt 0 ]; then
+        echo "PASS: \"Gecko Command\""
+    else
+        echo "FAIL: \"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()
+       {
+               if [ "$out" ] ; then
+                       if [ "$PYTHON -c import json; json.load($out)" ]; 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() {
+    find_str_or_fail "meta" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "threads".
+test_threads() {
+       find_str_or_fail "threads" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "samples".
+test_samples() {
+       find_str_or_fail "samples" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "frameTable".
+test_frametable() {
+       find_str_or_fail "frameTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stackTable".
+test_stacktable() {
+       find_str_or_fail "stackTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "stringTable"
+test_stringtable() {
+       find_str_or_fail "stringTable" "$out" "${FUNCNAME[0]}"
+}
+
+# validate output for the presence of "pausedRanges".
+test_pauseranges(){
+       find_str_or_fail "pausedRanges" "$out" "${FUNCNAME[0]}"
+}
+
+prepare_perf_data
+test_gecko_command
+validate_json_format
+test_meta
+test_threads
+test_samples
+test_frametable
+test_stacktable
+test_stringtable
+test_pauseranges
+cleanup
+exit $err
--

2.34.1