1#!/bin/sh 2# Check Arm CoreSight disassembly script completes without errors (exclusive) 3# SPDX-License-Identifier: GPL-2.0 4 5# The disassembly script reconstructs ranges of instructions and gives these to objdump to 6# decode. objdump doesn't like ranges that go backwards, but these are a good indication 7# that decoding has gone wrong either in OpenCSD, Perf or in the range reconstruction in 8# the script. Test all 3 parts are working correctly by running the script. 9 10skip_if_no_cs_etm_event() { 11 perf list pmu | grep -q 'cs_etm//' && return 0 12 13 # cs_etm event doesn't exist 14 return 2 15} 16 17skip_if_no_cs_etm_event || exit 2 18 19# Assume an error unless we reach the very end 20set -e 21glb_err=1 22 23perfdata_dir=$(mktemp -d /tmp/__perf_test.perf.data.XXXXX) 24perfdata=${perfdata_dir}/perf.data 25file=$(mktemp /tmp/temporary_file.XXXXX) 26# Relative path works whether it's installed or running from repo 27script_path=$(dirname "$0")/../../scripts/python/arm-cs-trace-disasm.py 28 29cleanup_files() 30{ 31 set +e 32 rm -rf ${perfdata_dir} 33 rm -f ${file} 34 trap - EXIT TERM INT 35 exit $glb_err 36} 37 38trap cleanup_files EXIT TERM INT 39 40# Ranges start and end on branches, so check for some likely branch instructions 41sep="\s\|\s" 42branch_search="\sbl${sep}b${sep}b.ne${sep}b.eq${sep}cbz\s" 43 44## Test kernel ## 45if [ -e /proc/kcore ]; then 46 echo "Testing kernel disassembly" 47 perf record -o ${perfdata} -e cs_etm//k --kcore -- touch $file > /dev/null 2>&1 48 perf script -i ${perfdata} -s python:${script_path} -- \ 49 -d --stop-sample=30 2> /dev/null > ${file} 50 grep -q -e ${branch_search} ${file} 51 echo "Found kernel branches" 52else 53 # kcore is required for correct kernel decode due to runtime code patching 54 echo "No kcore, skipping kernel test" 55fi 56 57## Test user ## 58echo "Testing userspace disassembly" 59perf record -o ${perfdata} -e cs_etm//u -- touch $file > /dev/null 2>&1 60perf script -i ${perfdata} -s python:${script_path} -- \ 61 -d --stop-sample=30 2> /dev/null > ${file} 62grep -q -e ${branch_search} ${file} 63echo "Found userspace branches" 64 65glb_err=0 66