lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 17 May 2023 23:39:26 +0530
From:   Anup Sharma <anupnewsmail@...il.com>
To:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Ian Rogers <irogers@...gle.com>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Anup Sharma <anupnewsmail@...il.com>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] perf: test: Add support for testing JSON generated by perf
 data command

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ