Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf test: Add pipe output testing for annotate

Parameterize the basic testing to generate directly a perf.data file
or to generate/use one from pipe input or output. To simplify the
refactor move some of the head/grep logic around. Use "-q" with grep
to make the test output cleaner.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250311211635.541090-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
658b34cc 3a86d63e

+40 -16
+40 -16
tools/perf/tests/shell/annotate.sh
··· 35 35 trap trap_cleanup EXIT TERM INT 36 36 37 37 test_basic() { 38 - echo "Basic perf annotate test" 39 - if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null 38 + mode=$1 39 + echo "${mode} perf annotate test" 40 + if [ "x${mode}" == "xBasic" ] 40 41 then 41 - echo "Basic annotate [Failed: perf record]" 42 + perf record -o "${perfdata}" ${testprog} 2> /dev/null 43 + else 44 + perf record -o - ${testprog} 2> /dev/null > "${perfdata}" 45 + fi 46 + if [ "x$?" != "x0" ] 47 + then 48 + echo "${mode} annotate [Failed: perf record]" 42 49 err=1 43 50 return 44 51 fi 45 52 46 53 # Generate the annotated output file 47 - perf annotate --no-demangle -i "${perfdata}" --stdio 2> /dev/null | head -250 > "${perfout}" 54 + if [ "x${mode}" == "xBasic" ] 55 + then 56 + perf annotate --no-demangle -i "${perfdata}" --stdio 2> /dev/null > "${perfout}" 57 + else 58 + perf annotate --no-demangle -i - --stdio 2> /dev/null < "${perfdata}" > "${perfout}" 59 + fi 48 60 49 61 # check if it has the target symbol 50 - if ! grep "${testsym}" "${perfout}" 62 + if ! head -250 "${perfout}" | grep -q "${testsym}" 51 63 then 52 - echo "Basic annotate [Failed: missing target symbol]" 64 + echo "${mode} annotate [Failed: missing target symbol]" 53 65 err=1 54 66 return 55 67 fi 56 68 57 69 # check if it has the disassembly lines 58 - if ! grep "${disasm_regex}" "${perfout}" 70 + if ! head -250 "${perfout}" | grep -q "${disasm_regex}" 59 71 then 60 - echo "Basic annotate [Failed: missing disasm output from default disassembler]" 72 + echo "${mode} annotate [Failed: missing disasm output from default disassembler]" 61 73 err=1 62 74 return 63 75 fi 64 76 65 77 # check again with a target symbol name 66 - if ! perf annotate --no-demangle -i "${perfdata}" "${testsym}" 2> /dev/null | \ 67 - head -250 | grep -m 3 "${disasm_regex}" 78 + if [ "x${mode}" == "xBasic" ] 68 79 then 69 - echo "Basic annotate [Failed: missing disasm output when specifying the target symbol]" 80 + perf annotate --no-demangle -i "${perfdata}" "${testsym}" 2> /dev/null > "${perfout}" 81 + else 82 + perf annotate --no-demangle -i - "${testsym}" 2> /dev/null < "${perfdata}" > "${perfout}" 83 + fi 84 + 85 + if ! head -250 "${perfout}"| grep -q -m 3 "${disasm_regex}" 86 + then 87 + echo "${mode} annotate [Failed: missing disasm output when specifying the target symbol]" 70 88 err=1 71 89 return 72 90 fi 73 91 74 92 # check one more with external objdump tool (forced by --objdump option) 75 - if ! perf annotate --no-demangle -i "${perfdata}" --objdump=objdump 2> /dev/null | \ 76 - head -250 | grep -m 3 "${disasm_regex}" 93 + if [ "x${mode}" == "xBasic" ] 77 94 then 78 - echo "Basic annotate [Failed: missing disasm output from non default disassembler (using --objdump)]" 95 + perf annotate --no-demangle -i "${perfdata}" --objdump=objdump 2> /dev/null > "${perfout}" 96 + else 97 + perf annotate --no-demangle -i - "${testsym}" 2> /dev/null < "${perfdata}" > "${perfout}" 98 + fi 99 + if ! head -250 "${perfout}" | grep -q -m 3 "${disasm_regex}" 100 + then 101 + echo "${mode} annotate [Failed: missing disasm output from non default disassembler (using --objdump)]" 79 102 err=1 80 103 return 81 104 fi 82 - echo "Basic annotate test [Success]" 105 + echo "${mode} annotate test [Success]" 83 106 } 84 107 85 - test_basic 108 + test_basic Basic 109 + test_basic Pipe 86 110 87 111 cleanup 88 112 exit $err