| 1 | |
| 2 | |
| 3 | |
| 4 |
|
| 5 | err=0
|
| 6 |
|
| 7 | |
| 8 | . "$(dirname $0)"/lib/probe.sh
|
| 9 |
|
| 10 | file1=$(mktemp /tmp/file1_XXXX)
|
| 11 | file2=$(echo $file1 | sed 's/file1/file2/g')
|
| 12 |
|
| 13 | buffer="buffer content"
|
| 14 | perf_config_tmp=$(mktemp /tmp/.perfconfig_XXXXX)
|
| 15 |
|
| 16 | trap cleanup EXIT TERM INT HUP
|
| 17 |
|
| 18 | check_vmlinux() {
|
| 19 | echo "Checking if vmlinux BTF exists"
|
| 20 | if [ ! -f /sys/kernel/btf/vmlinux ]
|
| 21 | then
|
| 22 | echo "Skipped due to missing vmlinux BTF"
|
| 23 | return 2
|
| 24 | fi
|
| 25 | return 0
|
| 26 | }
|
| 27 |
|
| 28 | trace_test_string() {
|
| 29 | echo "Testing perf trace's string augmentation"
|
| 30 | output="$(perf trace --sort-events -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1)"
|
| 31 | if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$"
|
| 32 | then
|
| 33 | printf "String augmentation test failed, output:\n$output\n"
|
| 34 | err=1
|
| 35 | fi
|
| 36 | }
|
| 37 |
|
| 38 | trace_test_buffer() {
|
| 39 | echo "Testing perf trace's buffer augmentation"
|
| 40 | |
| 41 | output="$(perf trace --sort-events -e write --max-events=1 -- echo "${buffer}" 2>&1)"
|
| 42 | if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$"
|
| 43 | then
|
| 44 | printf "Buffer augmentation test failed, output:\n$output\n"
|
| 45 | err=1
|
| 46 | fi
|
| 47 | }
|
| 48 |
|
| 49 | trace_test_struct_btf() {
|
| 50 | echo "Testing perf trace's struct augmentation"
|
| 51 | output="$(perf trace --sort-events -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1)"
|
| 52 | if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,.*\}, 0x[0-9a-f]+\) += +[0-9]+$"
|
| 53 | then
|
| 54 | printf "BTF struct augmentation test failed, output:\n$output\n"
|
| 55 | err=1
|
| 56 | fi
|
| 57 | }
|
| 58 |
|
| 59 | cleanup() {
|
| 60 | rm -rf ${file1} ${file2} ${perf_config_tmp}
|
| 61 | }
|
| 62 |
|
| 63 | trap_cleanup() {
|
| 64 | echo "Unexpected signal in ${FUNCNAME[1]}"
|
| 65 | cleanup
|
| 66 | exit 1
|
| 67 | }
|
| 68 |
|
| 69 | |
| 70 | trace_config() {
|
| 71 | export PERF_CONFIG=${perf_config_tmp}
|
| 72 | perf config trace.show_arg_names=false trace.show_duration=false \
|
| 73 | trace.show_timestamp=false trace.args_alignment=0
|
| 74 | }
|
| 75 |
|
| 76 | skip_if_no_perf_trace || exit 2
|
| 77 | check_vmlinux || exit 2
|
| 78 | [ "$(id -u)" = 0 ] || exit 2
|
| 79 |
|
| 80 | trace_config
|
| 81 |
|
| 82 | trace_test_string
|
| 83 |
|
| 84 | if [ $err = 0 ]; then
|
| 85 | trace_test_buffer
|
| 86 | fi
|
| 87 |
|
| 88 | if [ $err = 0 ]; then
|
| 89 | trace_test_struct_btf
|
| 90 | fi
|
| 91 |
|
| 92 | cleanup
|
| 93 |
|
| 94 | exit $err
|