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) 18testprog="perf test -w noploop" 19# disassembly format: "percent : offset: instruction (operands ...)" 20disasm_regex="[0-9]*\.[0-9]* *: *\w*: *\w*" 21 22cleanup() { 23 rm -rf "${perfdata}" 24 rm -rf "${perfdata}".old 25 26 trap - EXIT TERM INT 27} 28 29trap_cleanup() { 30 cleanup 31 exit 1 32} 33trap trap_cleanup EXIT TERM INT 34 35test_basic() { 36 echo "Basic perf annotate test" 37 if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null 38 then 39 echo "Basic annotate [Failed: perf record]" 40 err=1 41 return 42 fi 43 44 # check if it has the target symbol 45 if ! perf annotate -i "${perfdata}" 2> /dev/null | grep "${testsym}" 46 then 47 echo "Basic annotate [Failed: missing target symbol]" 48 err=1 49 return 50 fi 51 52 # check if it has the disassembly lines 53 if ! perf annotate -i "${perfdata}" 2> /dev/null | grep "${disasm_regex}" 54 then 55 echo "Basic annotate [Failed: missing disasm output from default disassembler]" 56 err=1 57 return 58 fi 59 60 # check again with a target symbol name 61 if ! perf annotate -i "${perfdata}" "${testsym}" 2> /dev/null | \ 62 grep -m 3 "${disasm_regex}" 63 then 64 echo "Basic annotate [Failed: missing disasm output when specifying the target symbol]" 65 err=1 66 return 67 fi 68 69 # check one more with external objdump tool (forced by --objdump option) 70 if ! perf annotate -i "${perfdata}" --objdump=objdump 2> /dev/null | \ 71 grep -m 3 "${disasm_regex}" 72 then 73 echo "Basic annotate [Failed: missing disasm output from non default disassembler (using --objdump)]" 74 err=1 75 return 76 fi 77 echo "Basic annotate test [Success]" 78} 79 80test_basic 81 82cleanup 83exit $err 84