1#!/bin/bash 2# perf pipe recording and injection test 3# SPDX-License-Identifier: GPL-2.0 4 5shelldir=$(dirname "$0") 6# shellcheck source=lib/perf_has_symbol.sh 7. "${shelldir}"/lib/perf_has_symbol.sh 8 9sym="noploop" 10 11skip_test_missing_symbol ${sym} 12 13data=$(mktemp /tmp/perf.data.XXXXXX) 14data2=$(mktemp /tmp/perf.data2.XXXXXX) 15prog="perf test -w noploop" 16err=0 17 18set -e 19 20cleanup() { 21 rm -rf "${data}" 22 rm -rf "${data}".old 23 rm -rf "${data2}" 24 rm -rf "${data2}".old 25 26 trap - EXIT TERM INT 27} 28 29trap_cleanup() { 30 echo "Unexpected signal in ${FUNCNAME[1]}" 31 cleanup 32 exit 1 33} 34trap trap_cleanup EXIT TERM INT 35 36test_record_report() { 37 echo 38 echo "Record+report pipe test" 39 40 task="perf" 41 if ! perf record -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task} 42 then 43 echo "Record+report pipe test [Failed - cannot find the test file in the perf report #1]" 44 err=1 45 return 46 fi 47 48 if ! perf record -g -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task} 49 then 50 echo "Record+report pipe test [Failed - cannot find the test file in the perf report #2]" 51 err=1 52 return 53 fi 54 55 perf record -g -e task-clock:u -o - ${prog} > ${data} 56 if ! perf report -i ${data} --task | grep -q ${task} 57 then 58 echo "Record+report pipe test [Failed - cannot find the test file in the perf report #3]" 59 err=1 60 return 61 fi 62 63 echo "Record+report pipe test [Success]" 64} 65 66test_inject_bids() { 67 inject_opt=$1 68 69 echo 70 echo "Inject ${inject_opt} build-ids test" 71 72 if ! perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt}| perf report -i - | grep -q ${sym} 73 then 74 echo "Inject build-ids test [Failed - cannot find noploop function in pipe #1]" 75 err=1 76 return 77 fi 78 79 if ! perf record -g -e task-clock:u -o - ${prog} | perf inject ${inject_opt} | perf report -i - | grep -q ${sym} 80 then 81 echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #2]" 82 err=1 83 return 84 fi 85 86 perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt} -o ${data} 87 if ! perf report -i ${data} | grep -q ${sym}; then 88 echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #3]" 89 err=1 90 return 91 fi 92 93 perf record -e task-clock:u -o ${data} ${prog} 94 if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q ${sym}; then 95 echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #4]" 96 err=1 97 return 98 fi 99 100 perf record -e task-clock:u -o - ${prog} > ${data} 101 if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q ${sym}; then 102 echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #5]" 103 err=1 104 return 105 fi 106 107 perf record -e task-clock:u -o - ${prog} > ${data} 108 perf inject ${inject_opt} -i ${data} -o ${data2} 109 if ! perf report -i ${data2} | grep -q ${sym}; then 110 echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #6]" 111 err=1 112 return 113 fi 114 115 echo "Inject ${inject_opt} build-ids test [Success]" 116} 117 118test_record_report 119test_inject_bids -B 120test_inject_bids -b 121test_inject_bids --buildid-all 122test_inject_bids --mmap2-buildid-all 123 124cleanup 125exit $err 126 127