xref: /linux/tools/perf/tests/shell/test_data_symbol.sh (revision 200323768787a0ee02e01c35c1aff13dc9d77dde)
1#!/bin/bash
2# Test data symbol
3
4# SPDX-License-Identifier: GPL-2.0
5# Leo Yan <leo.yan@linaro.org>, 2022
6
7skip_if_no_mem_event() {
8	perf mem record -e list 2>&1 | grep -E -q 'available' && return 0
9	return 2
10}
11
12skip_if_no_mem_event || exit 2
13
14TEST_PROGRAM="perf test -w datasym"
15PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
16
17check_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
38cleanup_files()
39{
40	echo "Cleaning up files..."
41	rm -f ${PERF_DATA}
42}
43
44trap cleanup_files exit term int
45
46echo "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.
51is_amd=$(grep -E -c 'vendor_id.*AuthenticAMD' /proc/cpuinfo)
52if (($is_amd >= 1)); then
53	perf mem record -o ${PERF_DATA} -C 0 -- taskset -c 0 $TEST_PROGRAM &
54else
55	perf mem record --all-user -o ${PERF_DATA} -- $TEST_PROGRAM &
56fi
57
58PERFPID=$!
59
60sleep 1
61
62kill $PERFPID
63wait $PERFPID
64
65check_result
66exit $?
67