|
| 1 | +#!/bin/bash |
| 2 | +# perf script task-analyzer tests |
| 3 | +# SPDX-License-Identifier: GPL-2.0 |
| 4 | + |
| 5 | +tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX) |
| 6 | +err=0 |
| 7 | + |
| 8 | +cleanup() { |
| 9 | + rm -f perf.data |
| 10 | + rm -f perf.data.old |
| 11 | + rm -f csv |
| 12 | + rm -f csvsummary |
| 13 | + rm -rf $tmpdir |
| 14 | + trap - exit term int |
| 15 | +} |
| 16 | + |
| 17 | +trap_cleanup() { |
| 18 | + cleanup |
| 19 | + exit 1 |
| 20 | +} |
| 21 | +trap trap_cleanup exit term int |
| 22 | + |
| 23 | +report() { |
| 24 | + if [ $1 = 0 ]; then |
| 25 | + echo "PASS: \"$2\"" |
| 26 | + else |
| 27 | + echo "FAIL: \"$2\" Error message: \"$3\"" |
| 28 | + err=1 |
| 29 | + fi |
| 30 | +} |
| 31 | + |
| 32 | +check_exec_0() { |
| 33 | + if [ $? != 0 ]; then |
| 34 | + report 1 "invokation of ${$1} command failed" |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +find_str_or_fail() { |
| 39 | + grep -q "$1" $2 |
| 40 | + if [ $? != 0 ]; then |
| 41 | + report 1 $3 "Failed to find required string:'${1}'." |
| 42 | + else |
| 43 | + report 0 $3 |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +prepare_perf_data() { |
| 48 | + # 1s should be sufficient to catch at least some switches |
| 49 | + perf record -e sched:sched_switch -a -- sleep 1 > /dev/null 2>&1 |
| 50 | +} |
| 51 | + |
| 52 | +# check standard inkvokation with no arguments |
| 53 | +test_basic() { |
| 54 | + out="$tmpdir/perf.out" |
| 55 | + perf script report task-analyzer > $out |
| 56 | + check_exec_0 "perf" |
| 57 | + find_str_or_fail "Comm" $out ${FUNCNAME[0]} |
| 58 | +} |
| 59 | + |
| 60 | +test_ns_rename(){ |
| 61 | + out="$tmpdir/perf.out" |
| 62 | + perf script report task-analyzer --ns --rename-comms-by-tids 0:random > $out |
| 63 | + check_exec_0 "perf" |
| 64 | + find_str_or_fail "Comm" $out ${FUNCNAME[0]} |
| 65 | +} |
| 66 | + |
| 67 | +test_ms_filtertasks_highlight(){ |
| 68 | + out="$tmpdir/perf.out" |
| 69 | + perf script report task-analyzer --ms --filter-tasks perf --highlight-tasks perf \ |
| 70 | + > $out |
| 71 | + check_exec_0 "perf" |
| 72 | + find_str_or_fail "Comm" $out ${FUNCNAME[0]} |
| 73 | +} |
| 74 | + |
| 75 | +test_extended_times_timelimit_limittasks() { |
| 76 | + out="$tmpdir/perf.out" |
| 77 | + perf script report task-analyzer --extended-times --time-limit :99999 \ |
| 78 | + --limit-to-tasks perf > $out |
| 79 | + check_exec_0 "perf" |
| 80 | + find_str_or_fail "Out-Out" $out ${FUNCNAME[0]} |
| 81 | +} |
| 82 | + |
| 83 | +test_summary() { |
| 84 | + out="$tmpdir/perf.out" |
| 85 | + perf script report task-analyzer --summary > $out |
| 86 | + check_exec_0 "perf" |
| 87 | + find_str_or_fail "Summary" $out ${FUNCNAME[0]} |
| 88 | +} |
| 89 | + |
| 90 | +test_summaryextended() { |
| 91 | + out="$tmpdir/perf.out" |
| 92 | + perf script report task-analyzer --summary-extended > $out |
| 93 | + check_exec_0 "perf" |
| 94 | + find_str_or_fail "Inter Task Times" $out ${FUNCNAME[0]} |
| 95 | +} |
| 96 | + |
| 97 | +test_summaryonly() { |
| 98 | + out="$tmpdir/perf.out" |
| 99 | + perf script report task-analyzer --summary-only > $out |
| 100 | + check_exec_0 "perf" |
| 101 | + find_str_or_fail "Summary" $out ${FUNCNAME[0]} |
| 102 | +} |
| 103 | + |
| 104 | +test_extended_times_summary_ns() { |
| 105 | + out="$tmpdir/perf.out" |
| 106 | + perf script report task-analyzer --extended-times --summary --ns > $out |
| 107 | + check_exec_0 "perf" |
| 108 | + find_str_or_fail "Out-Out" $out ${FUNCNAME[0]} |
| 109 | + find_str_or_fail "Summary" $out ${FUNCNAME[0]} |
| 110 | +} |
| 111 | + |
| 112 | +test_csv() { |
| 113 | + perf script report task-analyzer --csv csv > /dev/null |
| 114 | + check_exec_0 "perf" |
| 115 | + find_str_or_fail "Comm;" csv ${FUNCNAME[0]} |
| 116 | +} |
| 117 | + |
| 118 | +test_csv_extended_times() { |
| 119 | + perf script report task-analyzer --csv csv --extended-times > /dev/null |
| 120 | + check_exec_0 "perf" |
| 121 | + find_str_or_fail "Out-Out;" csv ${FUNCNAME[0]} |
| 122 | +} |
| 123 | + |
| 124 | +test_csvsummary() { |
| 125 | + perf script report task-analyzer --csv-summary csvsummary > /dev/null |
| 126 | + check_exec_0 "perf" |
| 127 | + find_str_or_fail "Comm;" csvsummary ${FUNCNAME[0]} |
| 128 | +} |
| 129 | + |
| 130 | +test_csvsummary_extended() { |
| 131 | + perf script report task-analyzer --csv-summary csvsummary --summary-extended \ |
| 132 | + >/dev/null |
| 133 | + check_exec_0 "perf" |
| 134 | + find_str_or_fail "Out-Out;" csvsummary ${FUNCNAME[0]} |
| 135 | +} |
| 136 | + |
| 137 | +prepare_perf_data |
| 138 | +test_basic |
| 139 | +test_ns_rename |
| 140 | +test_ms_filtertasks_highlight |
| 141 | +test_extended_times_timelimit_limittasks |
| 142 | +test_summary |
| 143 | +test_summaryextended |
| 144 | +test_summaryonly |
| 145 | +test_extended_times_summary_ns |
| 146 | +test_csv |
| 147 | +test_csvsummary |
| 148 | +test_csv_extended_times |
| 149 | +test_csvsummary_extended |
| 150 | +cleanup |
| 151 | +exit $err |
0 commit comments