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