Merge branch 'next' into for-linus
[linux-2.6-microblaze.git] / tools / perf / tests / shell / test_data_symbol.sh
1 #!/bin/bash
2 # Test data symbol
3
4 # SPDX-License-Identifier: GPL-2.0
5 # Leo Yan <leo.yan@linaro.org>, 2022
6
7 skip_if_no_mem_event() {
8         perf mem record -e list 2>&1 | grep -E -q 'available' && return 0
9         return 2
10 }
11
12 skip_if_no_mem_event || exit 2
13
14 TEST_PROGRAM="perf test -w datasym"
15 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
16
17 check_result() {
18         # The memory report format is as below:
19         #    99.92%  ...  [.] buf1+0x38
20         result=$(perf mem report -i ${PERF_DATA} -s symbol_daddr -q 2>&1 |
21                  awk '/buf1/ { print $4 }')
22
23         # Testing is failed if has no any sample for "buf1"
24         [ -z "$result" ] && return 1
25
26         while IFS= read -r line; do
27                 # The "data1" and "data2" fields in structure "buf1" have
28                 # offset "0x0" and "0x38", returns failure if detect any
29                 # other offset value.
30                 if [ "$line" != "buf1+0x0" ] && [ "$line" != "buf1+0x38" ]; then
31                         return 1
32                 fi
33         done <<< "$result"
34
35         return 0
36 }
37
38 cleanup_files()
39 {
40         echo "Cleaning up files..."
41         rm -f ${PERF_DATA}
42 }
43
44 trap cleanup_files exit term int
45
46 echo "Recording workload..."
47
48 # perf mem/c2c internally uses IBS PMU on AMD CPU which doesn't support
49 # user/kernel filtering and per-process monitoring, spin program on
50 # specific CPU and test in per-CPU mode.
51 is_amd=$(grep -E -c 'vendor_id.*AuthenticAMD' /proc/cpuinfo)
52 if (($is_amd >= 1)); then
53         perf mem record -o ${PERF_DATA} -C 0 -- taskset -c 0 $TEST_PROGRAM &
54 else
55         perf mem record --all-user -o ${PERF_DATA} -- $TEST_PROGRAM &
56 fi
57
58 PERFPID=$!
59
60 sleep 1
61
62 kill $PERFPID
63 wait $PERFPID
64
65 check_result
66 exit $?