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] perf: test: Add support for testing JSON generated by perf data command
Date: Wed, 17 May 2023 23:39:26 +0530 [thread overview]
Message-ID: <ZGUYVjJk2DhX9UrC@yoga> (raw)
This commit adds support for testing the JSON output generated
by the perf data command's conversion to JSON functionality.
The test script now includes a validation step to ensure that
the resulting JSON file is contain valid data.
As a newcomer to this community, any feedback on the implementation
is highly appreciated.
Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
---
.../shell/test_perf_data_converter_json.sh | 64 +++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100755 tools/perf/tests/shell/test_perf_data_converter_json.sh
diff --git a/tools/perf/tests/shell/test_perf_data_converter_json.sh b/tools/perf/tests/shell/test_perf_data_converter_json.sh
new file mode 100755
index 000000000000..88db96e38925
--- /dev/null
+++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+# perf data json converter test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+result=$(mktemp /tmp/__perf_test.output.json.XXXXX)
+
+cleanup()
+{
+ rm -f ${perfdata}
+ rm -f ${result}
+ trap - exit term int
+}
+
+trap_cleanup()
+{
+ cleanup
+ exit ${err}
+}
+trap trap_cleanup exit term int
+
+check()
+{
+ if [ `id -u` != 0 ]; then
+ echo "[Skip] No root permission"
+ err=2
+ exit
+ fi
+}
+
+test_json()
+{
+ echo "Testing perf data convertion to JSON"
+ perf record -o $perfdata -F 99 -a -g -- sleep 1 > /dev/null 2>&1
+ perf data convert --to-json $result --force -i $perfdata >/dev/null 2>&1
+ echo "Perf Data Converter to JSON [SUCCESS]"
+}
+
+validate_json_format()
+{
+ echo "Testing perf data converted to JSON format"
+ if [ -f "${result}" ]; then
+ if jq '.' "${result}" > /dev/null 2>&1; then
+ echo "The file contains valid JSON format [SUCCESS]"
+ else
+ echo "The file does not contain valid JSON format [FAILED]"
+ err=1
+ fi
+ else
+ echo "File not found [FAILED]"
+ err=2
+ exit
+ fi
+}
+
+check
+
+test_json
+validate_json_format
+
+exit ${err}
--
2.34.1
next reply other threads:[~2023-05-17 18:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 18:09 Anup Sharma [this message]
2023-05-17 19:56 ` [PATCH] perf: test: Add support for testing JSON generated by perf data command Ian Rogers
2023-05-18 6:03 ` Namhyung Kim
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=ZGUYVjJk2DhX9UrC@yoga \
--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