Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / perf / tests / shell / test_perf_data_converter_json.sh
blobc4f1b59d116f6e4705d872824339b234180e206f
1 #!/bin/bash
2 # 'perf data convert --to-json' command test
3 # SPDX-License-Identifier: GPL-2.0
5 set -e
7 err=0
9 shelldir=$(dirname "$0")
10 # shellcheck source=lib/setup_python.sh
11 . "${shelldir}"/lib/setup_python.sh
13 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
14 result=$(mktemp /tmp/__perf_test.output.json.XXXXX)
16 cleanup()
18 rm -f "${perfdata}"
19 rm -f "${result}"
20 trap - exit term int
23 trap_cleanup()
25 cleanup
26 exit ${err}
28 trap trap_cleanup exit term int
30 test_json_converter_command()
32 echo "Testing Perf Data Convertion Command to JSON"
33 perf record -o "$perfdata" -F 99 -g -- perf test -w noploop > /dev/null 2>&1
34 perf data convert --to-json "$result" --force -i "$perfdata" >/dev/null 2>&1
35 if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then
36 echo "Perf Data Converter Command to JSON [SUCCESS]"
37 else
38 echo "Perf Data Converter Command to JSON [FAILED]"
39 err=1
40 exit
44 validate_json_format()
46 echo "Validating Perf Data Converted JSON file"
47 if [ -f "$result" ] ; then
48 if $PYTHON -c "import json; json.load(open('$result'))" >/dev/null 2>&1 ; then
49 echo "The file contains valid JSON format [SUCCESS]"
50 else
51 echo "The file does not contain valid JSON format [FAILED]"
52 err=1
53 exit
55 else
56 echo "File not found [FAILED]"
57 err=2
58 exit
62 test_json_converter_command
63 validate_json_format
65 exit ${err}