linux-next/tools/perf/tests/shell/test_perf_data_converter_json.sh
Ian Rogers 8226e4a3b3 perf test: Use common python setup library
Avoid replicated logic by having a common library to set the PYTHON
environment variable.

Reviewed-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20231129213428.2227448-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-05 15:48:52 -03:00

66 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# 'perf data convert --to-json' command test
# SPDX-License-Identifier: GPL-2.0
set -e
err=0
shelldir=$(dirname "$0")
# shellcheck source=lib/setup_python.sh
. "${shelldir}"/lib/setup_python.sh
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
test_json_converter_command()
{
echo "Testing Perf Data Convertion Command to JSON"
perf record -o "$perfdata" -F 99 -g -- perf test -w noploop > /dev/null 2>&1
perf data convert --to-json "$result" --force -i "$perfdata" >/dev/null 2>&1
if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then
echo "Perf Data Converter Command to JSON [SUCCESS]"
else
echo "Perf Data Converter Command to JSON [FAILED]"
err=1
exit
fi
}
validate_json_format()
{
echo "Validating Perf Data Converted JSON file"
if [ -f "$result" ] ; then
if $PYTHON -c "import json; json.load(open('$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
exit
fi
else
echo "File not found [FAILED]"
err=2
exit
fi
}
test_json_converter_command
validate_json_format
exit ${err}