Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test shell trace_exit_race: Show what went wrong in verbose mode

If it fails we need to check what was the reason, what were the lines
that didn't match the expected format, so:

root@number:~# perf test -v "trace exit race"
--- start ---
test child forked, pid 2028724
Lines not matching the expected regexp: ' +[0-9]+\.[0-9]+ +true/[0-9]+ syscalls:sys_enter_exit_group\(\)$':
0.000 :2028750/2028750 syscalls:sys_enter_exit_group()
---- end(-1) ----
110: perf trace exit race : FAILED!
root@number:~#

In this case we're not resolving the process COMM for some reason and
fallback to printing just the pid/tid, this will be fixed in a followup
patch.

Howard Chu spotted a problem with single code surrounding a regexp, that
made the test always fail, but since there were some failures when I
tested (COMM not being resolved in some of the results) the end inverse
grep would show some lines and thus didn't notice the single quote
problem.

He also provided a patch to test if less than the number of expected
matches took place but all of them with the expected output, in which
case the inverse grep wouldn't show anything, confusing the tester.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Benjamin Peterson <benjamin@engflow.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/lkml/ZzdknoHqrJbojb6P@x1
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+22 -2
+22 -2
tools/perf/tests/shell/trace_exit_race.sh
··· 11 11 12 12 skip_if_no_perf_trace || exit 2 13 13 14 + if [ "$1" = "-v" ]; then 15 + verbose="1" 16 + fi 17 + 18 + iter=10 19 + regexp=" +[0-9]+\.[0-9]+ +true/[0-9]+ syscalls:sys_enter_exit_group\(\)$" 20 + 14 21 trace_shutdown_race() { 15 - for _ in $(seq 10); do 22 + for _ in $(seq $iter); do 16 23 perf trace -e syscalls:sys_enter_exit_group true 2>>$file 17 24 done 18 - [ "$(grep -c -E ' +[0-9]+\.[0-9]+ +true/[0-9]+ syscalls:sys_enter_exit_group\(\)$' $file)" = "10" ] 25 + result="$(grep -c -E "$regexp" $file)" 26 + [ $result = $iter ] 19 27 } 20 28 21 29 ··· 35 27 36 28 trace_shutdown_race 37 29 err=$? 30 + 31 + if [ $err != 0 ] && [ "${verbose}" = "1" ]; then 32 + lines_not_matching=$(mktemp /tmp/temporary_file.XXXXX) 33 + if grep -v -E "$regexp" $file > $lines_not_matching ; then 34 + echo "Lines not matching the expected regexp: '$regexp':" 35 + cat $lines_not_matching 36 + else 37 + echo "Missing output, expected $iter but only got $result" 38 + fi 39 + rm -f $lines_not_matching 40 + fi 41 + 38 42 rm -f ${file} 39 43 exit $err