Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.5.6.
  1#!/bin/bash
  2# perf script task-analyzer tests
  3# SPDX-License-Identifier: GPL-2.0
  4
  5tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX)
  6err=0
  7
  8cleanup() {
  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
 17trap_cleanup() {
 18  cleanup
 19  exit 1
 20}
 21trap trap_cleanup exit term int
 22
 23report() {
 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
 32check_exec_0() {
 33	if [ $? != 0 ]; then
 34		report 1 "invokation of ${$1} command failed"
 35	fi
 36}
 37
 38find_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
 47prepare_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
 53test_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
 60test_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
 67test_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
 75test_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
 83test_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
 90test_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
 97test_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
104test_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
112test_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
118test_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
124test_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
130test_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
137prepare_perf_data
138test_basic
139test_ns_rename
140test_ms_filtertasks_highlight
141test_extended_times_timelimit_limittasks
142test_summary
143test_summaryextended
144test_summaryonly
145test_extended_times_summary_ns
146test_csv
147test_csvsummary
148test_csv_extended_times
149test_csvsummary_extended
150cleanup
151exit $err