1#!/bin/sh 2# perf annotate basic tests 3# SPDX-License-Identifier: GPL-2.0 4 5set -e 6 7shelldir=$(dirname "$0") 8 9# shellcheck source=lib/perf_has_symbol.sh 10. "${shelldir}"/lib/perf_has_symbol.sh 11 12testsym="noploop" 13 14skip_test_missing_symbol ${testsym} 15 16err=0 17perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) 18perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX) 19testprog="perf test -w noploop" 20# disassembly format: "percent : offset: instruction (operands ...)" 21disasm_regex="[0-9]*\.[0-9]* *: *\w*: *\w*" 22 23cleanup() { 24 rm -rf "${perfdata}" "${perfout}" 25 rm -rf "${perfdata}".old 26 27 trap - EXIT TERM INT 28} 29 30trap_cleanup() { 31 cleanup 32 exit 1 33} 34trap trap_cleanup EXIT TERM INT 35 36test_basic() { 37 echo "Basic perf annotate test" 38 if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null 39 then 40 echo "Basic annotate [Failed: perf record]" 41 err=1 42 return 43 fi 44 45 # Generate the annotated output file 46 perf annotate -i "${perfdata}" --stdio 2> /dev/null > "${perfout}" 47 48 # check if it has the target symbol 49 if ! grep "${testsym}" "${perfout}" 50 then 51 echo "Basic annotate [Failed: missing target symbol]" 52 err=1 53 return 54 fi 55 56 # check if it has the disassembly lines 57 if ! grep "${disasm_regex}" "${perfout}" 58 then 59 echo "Basic annotate [Failed: missing disasm output from default disassembler]" 60 err=1 61 return 62 fi 63 64 # check again with a target symbol name 65 if ! perf annotate -i "${perfdata}" "${testsym}" 2> /dev/null | \ 66 grep -m 3 "${disasm_regex}" 67 then 68 echo "Basic annotate [Failed: missing disasm output when specifying the target symbol]" 69 err=1 70 return 71 fi 72 73 # check one more with external objdump tool (forced by --objdump option) 74 if ! perf annotate -i "${perfdata}" --objdump=objdump 2> /dev/null | \ 75 grep -m 3 "${disasm_regex}" 76 then 77 echo "Basic annotate [Failed: missing disasm output from non default disassembler (using --objdump)]" 78 err=1 79 return 80 fi 81 echo "Basic annotate test [Success]" 82} 83 84test_basic 85 86cleanup 87exit $err 88