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
39 lines
638 B
Perl
Executable file
39 lines
638 B
Perl
Executable file
#!/usr/bin/perl
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
@regexps = @ARGV;
|
|
|
|
$max_printed_lines = 20;
|
|
$max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES});
|
|
|
|
$quiet = 1;
|
|
$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
|
|
|
|
$passed = 1;
|
|
$lines_printed = 0;
|
|
|
|
while (<STDIN>)
|
|
{
|
|
s/\n//;
|
|
|
|
$line_matched = 0;
|
|
for $r (@regexps)
|
|
{
|
|
if (/$r/)
|
|
{
|
|
$line_matched = 1;
|
|
last;
|
|
}
|
|
}
|
|
|
|
unless ($line_matched)
|
|
{
|
|
if ($lines_printed++ < $max_printed_lines)
|
|
{
|
|
print "Line did not match any pattern: \"$_\"\n" unless $quiet;
|
|
}
|
|
$passed = 0;
|
|
}
|
|
}
|
|
|
|
exit ($passed == 0);
|