2 # SPDX-License-Identifier: GPL-2.0
4 # Copyright 2020, 2022 Sony Corporation
8 # This program is meant to be an aid to reading the verbose output of
9 # on the console log that results from executing the Linux kernel
10 # devicetree unittest (drivers/of/unitest.c).
20 # strip off everything before final "/"
21 (undef, $script_name) = split(/^.*\//, $0);
23 # following /usr/include/sysexits.h
28 #______________________________________________________________________________
30 my ($expect, $got) = @_;
38 ($expect_next, $type) = split(/<</, $expect);
39 ($type) = split(/>>/, $type);
40 $expect =~ s/^.*?>>//; # '?' is non-greedy, minimal match
42 # literal, ignore all metacharacters when used in a regex
43 $expect_next_lit = quotemeta($expect_next);
46 $got_next =~ s/^($expect_next_lit).*/\1/;
47 $got =~ s/^$expect_next_lit//;
49 if ($expect_next ne $got_next) {
54 if ($got =~ /^[+-]*[0-9]+/) {
55 $got =~ s/^[+-]*[0-9]+//;
59 } elsif ($type eq "hex") {
60 if ($got =~ /^(0x)*[0-9a-f]+/) {
61 $got =~ s/^(0x)*[0-9a-f]+//;
65 } elsif ($type eq "all") {
67 } elsif ($type eq "") {
68 if ($expect_next ne $got_next) {
75 print "** ERROR: special pattern not recognized: <<$type>>, CONSOLE_LOG line: $.\n";
83 print "** ERROR: $script_name internal error, at end of compare(), CONSOLE_LOG line: $.\n";
89 #______________________________________________________________________________
92 # ***** when editing, be careful to not put tabs in the string printed:
98 $script_name CONSOLE_LOG
100 -h print program usage
101 --help print program usage
102 --hide-expect suppress output of EXPECTed lines
103 --line-num report line number of CONSOLE_LOG
104 --no-expect-stats do not report EXPECT statistics
105 --no-strip-ts do not strip leading console timestamps
106 --verbose do not suppress EXPECT begin and end lines
107 --version print program version and exit
110 Process a console log for EXPECTed test related messages to either
111 highlight expected devicetree unittest related messages or suppress
112 the messages. Leading console timestamps will be stripped.
114 Various unittests may trigger kernel messages from outside the
115 unittest code. The unittest annotates that it expects the message
116 to occur with an 'EXPECT \\ : text' (begin) before triggering the
117 message, and an 'EXPECT / : text' (end) after triggering the message.
119 If an expected message does not occur, that will be reported.
121 For each expected message, the 'EXPECT \\ : text' (begin) and
122 'EXPECT / : text' (end), 'text' will contain the message text.
124 If 'EXPECT \\' (begin) and 'EXPECT /' (end) lines do not contain
125 matching 'text', that will be reported.
127 If EXPECT lines are nested, 'EXPECT /' (end) lines must be in the
128 reverse order of the corresponding 'EXPECT \\' (begin) lines.
130 'EXPECT \\ : text' (begin) and 'EXPECT / : text' (end) lines can
131 contain special patterns in 'text':
133 <<int>> matches: [+-]*[0-9]+
134 <<hex>> matches: (0x)*[0-9a-f]+
135 <<all>> matches: anything to end of line
137 'EXPECT \\' (begin) and 'EXPECT /' (end) lines are suppressed.
139 A prefix is added to every line of output:
141 'ok ' Line matches an enclosing EXPECT begin/end pair
143 '** ' Line reports $script_name warning or error
145 '-> ' Line reports start or end of the unittests
147 '>> ' Line reports a unittest test FAIL
149 ' ' Lines that are not otherwise prefixed
151 Issues detected in CONSOLE_LOG are reported to STDOUT, not to STDERR.
155 --line-num causes the CONSOLE_LOG line number to be printed in 4 columns.
156 If CONSOLE_LOG contains more than 9999 lines then more columns will be
157 used to report the line number for lines greater than 9999 (eg for
158 lines 10000 - 99999, 5 columns will be used).
164 #______________________________________________________________________________
165 #______________________________________________________________________________
170 "hide-expect" => \
$hide_expect,
171 "line-num" => \
$print_line_num,
172 "no-expect-stats" => \
$no_expect_stats,
173 "no-strip-ts" => \
$no_strip_ts,
174 "verbose" => \
$verbose,
175 "version" => \
$version,
178 print STDERR
"ERROR processing command line options\n";
180 print STDERR
"For help, type '$script_name --help'\n";
196 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
205 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
208 print STDERR
"\n$script_name $VUFX\n\n";
215 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
218 # Limit input files to exactly one.
220 # 'while ($line = <ARGV>) {' in the code below supports multiple file
221 # names on the command line, but the EXPECT statistics are reported
222 # once for all input - it is not an expected use case to generate one
223 # set of statistics for multiple input files.
226 print STDERR
"Required arguments: CONSOLE_LOG\n";
233 #______________________________________________________________________________
235 # Patterns to match 'EXPECT \ : ' (begin) and 'EXPECT / : ' (end)
237 # $exp_* are used as regex match patterns,
238 # so '\\\\' in $exp_begin matches a single '\'
239 # quotemeta() does not do the right thing in this case
241 # $pr_fmt is the prefix that unittest prints for every message
243 $pr_fmt = "### dt-test ### ";
244 $exp_begin = "${pr_fmt}EXPECT \\\\ : ";
245 $exp_end = "${pr_fmt}EXPECT / : ";
246 $expnot_begin = "${pr_fmt}EXPECT_NOT \\\\ : ";
247 $expnot_end = "${pr_fmt}EXPECT_NOT / : ";
254 while ($line = <ARGV
>) {
260 $prefix = " "; ## 2 characters
267 if ($timestamp =~ /^\[\s*[0-9]+\.[0-9]*\] /) {
268 ($timestamp, $null) = split(/]/, $line);
269 $timestamp = $timestamp . "] ";
276 $line =~ s/^\[\s*[0-9]+\.[0-9]*\] //;
279 # ----- find EXPECT begin
281 if ($line =~ /^\s*$exp_begin/) {
283 $data =~ s/^\s*$exp_begin//;
284 push @exp_begin_stack, $data;
287 if ($print_line_num) {
288 $line_num = sprintf("%4s ", $.);
290 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
297 # ----- find EXPECT end
299 if ($line =~ /^\s*$exp_end/) {
301 $data =~ s/^\s*$exp_end//;
304 if ($print_line_num) {
305 $line_num = sprintf("%4s ", $.);
307 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
312 if (@exp_found_or_begin > 0) {
313 $begin = pop @exp_found_or_begin;
314 if (compare
($data, $begin)) {
318 } elsif (@begin > 0) {
319 $begin = pop @exp_begin_stack;
326 $exp_missing_begin++;
327 print "** ERROR: EXPECT end without matching EXPECT begin:\n";
328 print " end ---> $line\n";
332 if ($print_line_num) {
333 $line_num = sprintf("%4s ", $.);
337 printf "** %s%s$script_name WARNING - not found ---> %s\n",
338 $line_num, $timestamp, $data;
340 } elsif (! compare
($data, $begin) and ($data ne $begin)) {
343 print "** ERROR: EXPECT end does not match EXPECT begin:\n";
344 print " begin -> $begin\n";
345 print " end ---> $line\n";
353 # ----- find EXPECT_NOT begin
355 if ($line =~ /^\s*$expnot_begin/) {
357 $data =~ s/^\s*$expnot_begin//;
358 push @expnot_begin_stack, $data;
361 if ($print_line_num) {
362 $line_num = sprintf("%4s ", $.);
364 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
371 # ----- find EXPECT_NOT end
373 if ($line =~ /^\s*$expnot_end/) {
375 $data =~ s/^\s*$expnot_end//;
378 if ($print_line_num) {
379 $line_num = sprintf("%4s ", $.);
381 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
386 if (@expnot_found_or_begin > 0) {
387 $begin = pop @expnot_found_or_begin;
388 if (compare
($data, $begin)) {
392 } elsif (@expnot_begin_stack <= 0) {
398 $expnot_missing_begin++;
399 print "** ERROR: EXPECT_NOT end without matching EXPECT_NOT begin:\n";
400 print " end ---> $line\n";
406 if ($print_line_num) {
407 $line_num = sprintf("%4s ", $.);
410 printf "** %s%s$script_name WARNING - next line matches EXPECT_NOT\n",
411 $line_num, $timestamp;
412 printf "** %s%s%s\n", $line_num, $timestamp, $line;
420 if (@expnot_begin_stack > 0) {
421 $begin = pop @expnot_begin_stack;
423 if (! compare
($data, $begin) and ($data ne $begin)) {
425 $expnot_missing_end++;
426 print "** ERROR: EXPECT_NOT end does not match EXPECT_NOT begin:\n";
427 print " begin -> $begin\n";
428 print " end ---> $line\n";
437 # ----- not an EXPECT line
439 if (($line =~ /^${pr_fmt}start of unittest - you will see error messages$/) ||
440 ($line =~ /^${pr_fmt}end of unittest - [0-9]+ passed, [0-9]+ failed$/ ) ) {
441 $prefix = "->"; # 2 characters
442 } elsif ($line =~ /^${pr_fmt}FAIL /) {
444 $prefix = ">>"; # 2 characters
448 foreach $begin (@exp_begin_stack) {
449 if (compare
($begin, $line)) {
456 $begin = shift @exp_begin_stack;
457 while (! compare
($begin, $line)) {
458 push @exp_found_or_begin, $begin;
459 $begin = shift @exp_begin_stack;
461 push @exp_found_or_begin, $line;
466 $prefix = "ok"; # 2 characters
471 foreach $begin (@expnot_begin_stack) {
472 if (compare
($begin, $line)) {
479 $begin = shift @begin;
480 while (! compare
($begin, $line)) {
481 push @expnot_found_or_begin, $begin;
482 $begin = shift @begin;
484 push @expnot_found_or_begin, $line;
489 $prefix = "**"; # 2 characters
493 if ($suppress_line) {
497 if ($print_line_num) {
498 $line_num = sprintf("%4s ", $.);
501 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
504 if (! $no_expect_stats) {
506 print "** EXPECT statistics:\n";
508 printf "** non-zero values expected:\n";
510 printf "** EXPECT found : %4i\n", $exp_found;
511 printf "** EXPECT_NOT not found : %4i\n", $expnot_missing;
513 printf "** zero values expected:\n";
515 printf "** EXPECT not found : %4i\n", $exp_missing;
516 printf "** missing EXPECT begin : %4i\n", $exp_missing_begin;
517 printf "** missing EXPECT end : %4i\n", $exp_missing_end;
519 printf "** EXPECT_NOT found : %4i\n", $expnot_found;
520 printf "** missing EXPECT_NOT begin : %4i\n", $expnot_missing_begin;
521 printf "** missing EXPECT_NOT end : %4i\n", $expnot_missing_end;
523 printf "** unittest FAIL : %4i\n", $unittest_fail;
524 printf "** internal error : %4i\n", $internal_err;
527 if (@exp_begin_stack) {
528 print "** ERROR: EXPECT begin without matching EXPECT end:\n";
529 print " This list may be misleading.\n";
530 foreach $begin (@exp_begin_stack) {
531 print " begin ---> $begin\n";
535 if (@expnot_begin_stack) {
536 print "** ERROR: EXPECT_NOT begin without matching EXPECT_NOT end:\n";
537 print " This list may be misleading.\n";
538 foreach $begin (@expnot_begin_stack) {
539 print " begin ---> $begin\n";