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 helpers

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
regex.

Add helpers for verifying that all regexes are found in the output, that
all lines match any pattern from a set and that a certain expression is
not present in the output.

In verbose mode these helpers log mismatches for easier failure
investigation.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Cc: kjain@linux.ibm.com
Cc: atrajeev@linux.vnet.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240215110231.15385-6-mpetlan@redhat.com

authored by

Veronika Molnarova and committed by
Namhyung Kim
61d348f1 c8eb2a9f

+107
+39
tools/perf/tests/shell/common/check_all_lines_matched.pl
··· 1 + #!/usr/bin/perl 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + @regexps = @ARGV; 5 + 6 + $max_printed_lines = 20; 7 + $max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES}); 8 + 9 + $quiet = 1; 10 + $quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2); 11 + 12 + $passed = 1; 13 + $lines_printed = 0; 14 + 15 + while (<STDIN>) 16 + { 17 + s/\n//; 18 + 19 + $line_matched = 0; 20 + for $r (@regexps) 21 + { 22 + if (/$r/) 23 + { 24 + $line_matched = 1; 25 + last; 26 + } 27 + } 28 + 29 + unless ($line_matched) 30 + { 31 + if ($lines_printed++ < $max_printed_lines) 32 + { 33 + print "Line did not match any pattern: \"$_\"\n" unless $quiet; 34 + } 35 + $passed = 0; 36 + } 37 + } 38 + 39 + exit ($passed == 0);
+34
tools/perf/tests/shell/common/check_all_patterns_found.pl
··· 1 + #!/usr/bin/perl 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + @regexps = @ARGV; 5 + 6 + $quiet = 1; 7 + $quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2); 8 + 9 + %found = (); 10 + $passed = 1; 11 + 12 + while (<STDIN>) 13 + { 14 + s/\n//; 15 + 16 + for $r (@regexps) 17 + { 18 + if (/$r/) 19 + { 20 + $found{$r} = 1; # FIXME: maybe add counters -- how many times was the regexp matched 21 + } 22 + } 23 + } 24 + 25 + for $r (@regexps) 26 + { 27 + unless (exists $found{$r}) 28 + { 29 + print "Regexp not found: \"$r\"\n" unless $quiet; 30 + $passed = 0; 31 + } 32 + } 33 + 34 + exit ($passed == 0);
+34
tools/perf/tests/shell/common/check_no_patterns_found.pl
··· 1 + #!/usr/bin/perl 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + @regexps = @ARGV; 5 + 6 + $quiet = 1; 7 + $quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2); 8 + 9 + %found = (); 10 + $passed = 1; 11 + 12 + while (<STDIN>) 13 + { 14 + s/\n//; 15 + 16 + for $r (@regexps) 17 + { 18 + if (/$r/) 19 + { 20 + $found{$r} = 1; 21 + } 22 + } 23 + } 24 + 25 + for $r (@regexps) 26 + { 27 + if (exists $found{$r}) 28 + { 29 + print "Regexp found: \"$r\"\n" unless $quiet; 30 + $passed = 0; 31 + } 32 + } 33 + 34 + exit ($passed == 0);