1 # SPDX-License-Identifier: GPL-2.0
2 # Carsten Haitzler <carsten.haitzler@arm.com>, 2021
4 # This is sourced from a driver script so no need for #!/bin... etc. at the
5 # top - the assumption below is that it runs as part of sourcing after the
6 # test sets up some basic env vars to say what it is.
8 # This currently works with ETMv4 / ETF not any other packet types at thi
9 # point. This will need changes if that changes.
11 # perf record options for the perf tests to use
13 PERFRECOPT
="$PERFRECMEM -e cs_etm//u"
18 # If the test tool/binary does not exist and is executable then skip the test
19 if ! test -x "$BIN"; then exit 2; fi
20 # If CoreSight is not available, skip the test
21 perf list pmu |
grep -q cs_etm ||
exit 2
23 # If the data dir env is set then make the data dir use that instead of ./
24 if test -n "$PERF_TEST_CORESIGHT_DATADIR"; then
25 DATD
="$PERF_TEST_CORESIGHT_DATADIR";
27 # If the stat dir env is set then make the data dir use that instead of ./
29 if test -n "$PERF_TEST_CORESIGHT_STATDIR"; then
30 STATD
="$PERF_TEST_CORESIGHT_STATDIR";
33 # Called if the test fails - error code 1
39 # Check that some statistics from our perf
42 if test "$2" -lt "$3"; then
43 echo ", FAILED" >> "$STATF"
44 err
"Sanity check number of $1 is too low ($2 < $3)"
48 perf_dump_aux_verify
() {
49 # Some basic checking that the AUX chunk contains some sensible data
50 # to see that we are recording something and at least a minimum
51 # amount of it. We should almost always see Fn packets in just about
52 # anything but certainly we will see some trace info and async
54 DUMP
="$DATD/perf-tmp-aux-dump.txt"
55 perf report
--stdio --dump -i "$1" | \
56 grep -o -e I_ATOM_F
-e I_ASYNC
-e I_TRACE_INFO
> "$DUMP"
57 # Simply count how many of these packets we find to see that we are
58 # producing a reasonable amount of data - exact checks are not sane
59 # as this is a lossy process where we may lose some blocks and the
60 # compiler may produce different code depending on the compiler and
61 # optimization options, so this is rough just to see if we're
62 # either missing almost all the data or all of it
63 ATOM_FX_NUM
=$
(grep -c I_ATOM_F
"$DUMP")
64 ASYNC_NUM
=$
(grep -c I_ASYNC
"$DUMP")
65 TRACE_INFO_NUM
=$
(grep -c I_TRACE_INFO
"$DUMP")
68 # Arguments provide minimums for a pass
71 CHECK_TRACE_INFO_MIN
="$4"
73 # Write out statistics, so over time you can track results to see if
74 # there is a pattern - for example we have less "noisy" results that
75 # produce more consistent amounts of data each run, to see if over
76 # time any techinques to minimize data loss are having an effect or
78 STATF
="$STATD/stats-$TEST-$DATV.csv"
79 if ! test -f "$STATF"; then
80 echo "ATOM Fx Count, Minimum, ASYNC Count, Minimum, TRACE INFO Count, Minimum" > "$STATF"
82 echo -n "$ATOM_FX_NUM, $CHECK_FX_MIN, $ASYNC_NUM, $CHECK_ASYNC_MIN, $TRACE_INFO_NUM, $CHECK_TRACE_INFO_MIN" >> "$STATF"
84 # Actually check to see if we passed or failed.
85 check_val_min
"ATOM_FX" "$ATOM_FX_NUM" "$CHECK_FX_MIN" "$STATF"
86 check_val_min
"ASYNC" "$ASYNC_NUM" "$CHECK_ASYNC_MIN" "$STATF"
87 check_val_min
"TRACE_INFO" "$TRACE_INFO_NUM" "$CHECK_TRACE_INFO_MIN" "$STATF"
88 echo ", Ok" >> "$STATF"
91 perf_dump_aux_tid_verify
() {
92 # Specifically crafted test will produce a list of Tread ID's to
93 # stdout that need to be checked to see that they have had trace
94 # info collected in AUX blocks in the perf data. This will go
95 # through all the TID's that are listed as CID=0xabcdef and see
96 # that all the Thread IDs the test tool reports are in the perf
99 # The TID test tools will print a TID per stdout line that are being
102 # Scan the perf report to find the TIDs that are actually CID in hex
103 # and build a list of the ones found
104 FOUND_TIDS
=$
(perf report
--stdio --dump -i "$1" | \
105 grep -o "CID=0x[0-9a-z]\+" |
sed 's/CID=//g' | \
107 # No CID=xxx found - maybe your kernel is reporting these as
108 # VMID=xxx so look there
109 if test -z "$FOUND_TIDS"; then
110 FOUND_TIDS
=$
(perf report
--stdio --dump -i "$1" | \
111 grep -o "VMID=0x[0-9a-z]\+" |
sed 's/VMID=//g' | \
115 # Iterate over the list of TIDs that the test says it has and find
116 # them in the TIDs found in the perf report
118 for TID2
in $TIDS; do
120 for TIDHEX
in $FOUND_TIDS; do
121 TID
=$
(printf "%i" $TIDHEX)
122 if test "$TID" -eq "$TID2"; then
127 if test -z "$FOUND"; then
128 MISSING
="$MISSING $TID"
131 if test -n "$MISSING"; then
132 err
"Thread IDs $MISSING not found in perf AUX data"