89 lines · bash
1#!/bin/bash2# perf annotate basic tests3# SPDX-License-Identifier: GPL-2.04 5set -e6 7shelldir=$(dirname "$0")8 9# shellcheck source=lib/perf_has_symbol.sh10. "${shelldir}"/lib/perf_has_symbol.sh11 12testsym="noploop"13 14skip_test_missing_symbol ${testsym}15 16err=017perfdata=$(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}".old26 27 trap - EXIT TERM INT28}29 30trap_cleanup() {31 echo "Unexpected signal in ${FUNCNAME[1]}"32 cleanup33 exit 134}35trap trap_cleanup EXIT TERM INT36 37test_basic() {38 echo "Basic perf annotate test"39 if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null40 then41 echo "Basic annotate [Failed: perf record]"42 err=143 return44 fi45 46 # Generate the annotated output file47 perf annotate -i "${perfdata}" --stdio 2> /dev/null > "${perfout}"48 49 # check if it has the target symbol50 if ! grep "${testsym}" "${perfout}"51 then52 echo "Basic annotate [Failed: missing target symbol]"53 err=154 return55 fi56 57 # check if it has the disassembly lines58 if ! grep "${disasm_regex}" "${perfout}"59 then60 echo "Basic annotate [Failed: missing disasm output from default disassembler]"61 err=162 return63 fi64 65 # check again with a target symbol name66 if ! perf annotate -i "${perfdata}" "${testsym}" 2> /dev/null | \67 grep -m 3 "${disasm_regex}"68 then69 echo "Basic annotate [Failed: missing disasm output when specifying the target symbol]"70 err=171 return72 fi73 74 # check one more with external objdump tool (forced by --objdump option)75 if ! perf annotate -i "${perfdata}" --objdump=objdump 2> /dev/null | \76 grep -m 3 "${disasm_regex}"77 then78 echo "Basic annotate [Failed: missing disasm output from non default disassembler (using --objdump)]"79 err=180 return81 fi82 echo "Basic annotate test [Success]"83}84 85test_basic86 87cleanup88exit $err89