Merge branch 'for-6.9/amd-sfh' into for-linus
[sfrench/cifs-2.6.git] / tools / perf / tests / shell / test_perf_data_converter_json.sh
1 #!/bin/bash
2 # 'perf data convert --to-json' command test
3 # SPDX-License-Identifier: GPL-2.0
4
5 set -e
6
7 err=0
8
9 shelldir=$(dirname "$0")
10 # shellcheck source=lib/setup_python.sh
11 . "${shelldir}"/lib/setup_python.sh
12
13 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
14 result=$(mktemp /tmp/__perf_test.output.json.XXXXX)
15
16 cleanup()
17 {
18         rm -f "${perfdata}"
19         rm -f "${result}"
20         trap - exit term int
21 }
22
23 trap_cleanup()
24 {
25         cleanup
26         exit ${err}
27 }
28 trap trap_cleanup exit term int
29
30 test_json_converter_command()
31 {
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
41         fi
42 }
43
44 validate_json_format()
45 {
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
54                 fi
55         else
56                 echo "File not found [FAILED]"
57                 err=2
58                 exit
59         fi
60 }
61
62 test_json_converter_command
63 validate_json_format
64
65 exit ${err}