xref: /linux/tools/perf/tests/shell/base_report/test_basic.sh (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1#!/bin/bash
2
3# SPDX-License-Identifier: GPL-2.0
4
5#
6#	test_basic of perf_report test
7#	Author: Michael Petlan <mpetlan@redhat.com>
8#
9#	Description:
10#
11#		This test tests basic functionality of perf report command.
12#
13#
14
15# include working environment
16. ../common/init.sh
17
18TEST_RESULT=0
19
20
21### help message
22
23if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then
24	# test that a help message is shown and looks reasonable
25	$CMD_PERF report --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err
26	PERF_EXIT_CODE=$?
27
28	../common/check_all_patterns_found.pl "PERF-REPORT" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" "OVERHEAD\s+CALCULATION" "SEE ALSO" < $LOGS_DIR/basic_helpmsg.log
29	CHECK_EXIT_CODE=$?
30	../common/check_all_patterns_found.pl "input" "verbose" "show-nr-samples" "show-cpu-utilization" "threads" "comms" "pid" "tid" "dsos" "symbols" "symbol-filter" < $LOGS_DIR/basic_helpmsg.log
31	(( CHECK_EXIT_CODE += $? ))
32	../common/check_all_patterns_found.pl "hide-unresolved" "sort" "fields" "parent" "exclude-other" "column-widths" "field-separator" "dump-raw-trace" "children" < $LOGS_DIR/basic_helpmsg.log
33	(( CHECK_EXIT_CODE += $? ))
34	../common/check_all_patterns_found.pl "call-graph" "max-stack" "inverted" "ignore-callees" "pretty" "stdio" "tui" "gtk" "vmlinux" "kallsyms" "modules" < $LOGS_DIR/basic_helpmsg.log
35	(( CHECK_EXIT_CODE += $? ))
36	../common/check_all_patterns_found.pl "force" "symfs" "cpu" "disassembler-style" "source" "asm-raw" "show-total-period" "show-info" "branch-stack" "group" < $LOGS_DIR/basic_helpmsg.log
37	(( CHECK_EXIT_CODE += $? ))
38	../common/check_all_patterns_found.pl "branch-history" "objdump" "demangle" "percent-limit" "percentage" "header" "itrace" "full-source-path" "show-ref-call-graph" < $LOGS_DIR/basic_helpmsg.log
39	(( CHECK_EXIT_CODE += $? ))
40	../common/check_no_patterns_found.pl "No manual entry for" < $LOGS_DIR/basic_helpmsg.err
41	(( CHECK_EXIT_CODE += $? ))
42
43	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "help message"
44	(( TEST_RESULT += $? ))
45else
46	print_testcase_skipped "help message"
47fi
48
49
50### basic execution
51
52# test that perf report is even working
53$CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio > $LOGS_DIR/basic_basic.log 2> $LOGS_DIR/basic_basic.err
54PERF_EXIT_CODE=$?
55
56REGEX_LOST_SAMPLES_INFO="#\s*Total Lost Samples:\s+$RE_NUMBER"
57REGEX_SAMPLES_INFO="#\s*Samples:\s+(?:$RE_NUMBER)\w?\s+of\s+event\s+'$RE_EVENT_ANY'"
58REGEX_LINES_HEADER="#\s*Children\s+Self\s+Command\s+Shared Object\s+Symbol"
59REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+"
60../common/check_all_patterns_found.pl "$REGEX_LOST_SAMPLES_INFO" "$REGEX_SAMPLES_INFO" "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_basic.log
61CHECK_EXIT_CODE=$?
62../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_basic.err
63(( CHECK_EXIT_CODE += $? ))
64
65print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "basic execution"
66(( TEST_RESULT += $? ))
67
68
69### number of samples
70
71# '--show-nr-samples' should show number of samples for each symbol
72$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --show-nr-samples > $LOGS_DIR/basic_nrsamples.log 2> $LOGS_DIR/basic_nrsamples.err
73PERF_EXIT_CODE=$?
74
75REGEX_LINES_HEADER="#\s*Children\s+Self\s+Samples\s+Command\s+Shared Object\s+Symbol"
76REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+"
77../common/check_all_patterns_found.pl "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_nrsamples.log
78CHECK_EXIT_CODE=$?
79../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_nrsamples.err
80(( CHECK_EXIT_CODE += $? ))
81
82print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "number of samples"
83(( TEST_RESULT += $? ))
84
85
86### header
87
88# '--header' and '--header-only' should show perf report header
89$CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio --header-only > $LOGS_DIR/basic_header.log
90PERF_EXIT_CODE=$?
91
92REGEX_LINE_TIMESTAMP="#\s+captured on\s*:\s*$RE_DATE_TIME"
93REGEX_LINE_HOSTNAME="#\s+hostname\s*:\s*$MY_HOSTNAME"
94REGEX_LINE_KERNEL="#\s+os release\s*:\s*${MY_KERNEL_VERSION//+/\\+}"
95REGEX_LINE_PERF="#\s+perf version\s*:\s*"
96REGEX_LINE_ARCH="#\s+arch\s*:\s*$MY_ARCH"
97REGEX_LINE_CPUS_ONLINE="#\s+nrcpus online\s*:\s*$MY_CPUS_ONLINE"
98REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$MY_CPUS_AVAILABLE"
99# disable precise check for "nrcpus avail" in BASIC runmode
100test $PERFTOOL_TESTSUITE_RUNMODE -lt $RUNMODE_STANDARD && REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$RE_NUMBER"
101../common/check_all_patterns_found.pl "$REGEX_LINE_TIMESTAMP" "$REGEX_LINE_HOSTNAME" "$REGEX_LINE_KERNEL" "$REGEX_LINE_PERF" "$REGEX_LINE_ARCH" "$REGEX_LINE_CPUS_ONLINE" "$REGEX_LINE_CPUS_AVAIL" < $LOGS_DIR/basic_header.log
102CHECK_EXIT_CODE=$?
103
104print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "header"
105(( TEST_RESULT += $? ))
106
107# '--header' and '--header-only' should use creation time
108OLD_TIMESTAMP=`$CMD_PERF report --stdio --header-only -i $CURRENT_TEST_DIR/perf.data | grep "captured on"`
109PERF_EXIT_CODE=$?
110
111( tar -C $CURRENT_TEST_DIR -c perf.data | xz > $CURRENT_TEST_DIR/perf.data.tar.xz ; xzcat $CURRENT_TEST_DIR/perf.data.tar.xz | tar x -C $HEADER_TAR_DIR )
112(( PERF_EXIT_CODE += $? ))
113
114NEW_TIMESTAMP=`$CMD_PERF report --stdio --header-only -i $HEADER_TAR_DIR/perf.data | grep "captured on"`
115(( PERF_EXIT_CODE += $? ))
116
117test "$OLD_TIMESTAMP" = "$NEW_TIMESTAMP"
118CHECK_EXIT_CODE=$?
119
120print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "header timestamp"
121(( TEST_RESULT += $? ))
122
123
124### show CPU utilization
125
126# '--showcpuutilization' should show percentage for both system and userspace mode
127$CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio --showcpuutilization > $LOGS_DIR/basic_cpuut.log 2> $LOGS_DIR/basic_cpuut.err
128PERF_EXIT_CODE=$?
129
130REGEX_LINES_HEADER="#\s*Children\s+Self\s+sys\s+usr\s+Command\s+Shared Object\s+Symbol"
131REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+"
132../common/check_all_patterns_found.pl "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_cpuut.log
133CHECK_EXIT_CODE=$?
134../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_cpuut.err
135(( CHECK_EXIT_CODE += $? ))
136
137print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "show CPU utilization"
138(( TEST_RESULT += $? ))
139
140
141### pid
142
143# '--pid=' should limit the output for a process with the given pid only
144$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --pid=1 > $LOGS_DIR/basic_pid.log 2> $LOGS_DIR/basic_pid.err
145PERF_EXIT_CODE=$?
146
147grep -P -v '^#' $LOGS_DIR/basic_pid.log | grep -P '\s+[\d\.]+%' | ../common/check_all_lines_matched.pl "systemd|init"
148CHECK_EXIT_CODE=$?
149../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_pid.err
150(( CHECK_EXIT_CODE += $? ))
151
152print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "pid"
153(( TEST_RESULT += $? ))
154
155
156### non-existing symbol
157
158# '--symbols' should show only the given symbols
159$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbols=dummynonexistingsymbol > $LOGS_DIR/basic_symbols.log 2> $LOGS_DIR/basic_symbols.err
160PERF_EXIT_CODE=$?
161
162../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/basic_symbols.log
163CHECK_EXIT_CODE=$?
164../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_symbols.err
165(( CHECK_EXIT_CODE += $? ))
166
167print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing symbol"
168(( TEST_RESULT += $? ))
169
170
171### symbol filter
172
173# '--symbol-filter' should filter symbols based on substrings
174$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbol-filter=map > $LOGS_DIR/basic_symbolfilter.log 2> $LOGS_DIR/basic_symbolfilter.err
175PERF_EXIT_CODE=$?
176
177grep -P -v '^#' $LOGS_DIR/basic_symbolfilter.log | grep -P '\s+[\d\.]+%' | ../common/check_all_lines_matched.pl "\[[k\.]\]\s+.*map"
178CHECK_EXIT_CODE=$?
179../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_symbolfilter.err
180(( CHECK_EXIT_CODE += $? ))
181
182print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "symbol filter"
183(( TEST_RESULT += $? ))
184
185
186# TODO: $CMD_PERF report -n --showcpuutilization -TUxDg 2> 01.log
187
188# print overall results
189print_overall_results "$TEST_RESULT"
190exit $?
191