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

perf testsuite: Add common output checking helper

As a form of validation, it is a common practice to check the outputs
of commands whether they contain expected patterns or match a certain
regular expression.

This output checking helper is designed to allow checking stderr output
of perf commands for unexpected messages, while ignoring messages that
are known to be harmless, e.g.:
"Lowering default frequency rate to \d+\."
"\d+ out of order events recorded."
etc.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240702110849.31904-10-vmolnaro@redhat.com
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Veronika Molnarova and committed by
Arnaldo Carvalho de Melo
13d58a66 c0964af8

+51
+51
tools/perf/tests/shell/common/check_errors_whitelisted.pl
··· 1 + #!/usr/bin/perl 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + $whitelist_file = shift; 5 + 6 + if (defined $whitelist_file) 7 + { 8 + open (INFILE, $whitelist_file) or die "Checker error: Unable to open the whitelist file: $whitelist_file\n"; 9 + @regexps = <INFILE>; 10 + close INFILE or die "Checker error: Unable to close the whitelist file: $whitelist_file\n"; 11 + } 12 + else 13 + { 14 + @regexps = (); 15 + } 16 + 17 + $max_printed_lines = 20; 18 + $max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES}); 19 + 20 + $quiet = 1; 21 + $quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2); 22 + 23 + $passed = 1; 24 + $lines_printed = 0; 25 + 26 + while (<STDIN>) 27 + { 28 + s/\n//; 29 + 30 + $line_matched = 0; 31 + for $r (@regexps) 32 + { 33 + chomp $r; 34 + if (/$r/) 35 + { 36 + $line_matched = 1; 37 + last; 38 + } 39 + } 40 + 41 + unless ($line_matched) 42 + { 43 + if ($lines_printed++ < $max_printed_lines) 44 + { 45 + print "Line did not match any pattern: \"$_\"\n" unless $quiet; 46 + } 47 + $passed = 0; 48 + } 49 + } 50 + 51 + exit ($passed == 0);