drm/panthor: Don't add write fences to the shared BOs
[drm/drm-misc.git] / scripts / dtc / of_unittest_expect
blob0a535a8e98217d592689cfb0f0f2a5ffde839834
1 #!/usr/bin/perl
2 # SPDX-License-Identifier: GPL-2.0
4 # Copyright 2020, 2022 Sony Corporation
6 # Author: Frank Rowand
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).
12 $VUFX = "230211a";
14 use strict 'refs';
15 use strict subs;
17 use Getopt::Long;
18 use Text::Wrap;
20 # strip off everything before final "/"
21 (undef, $script_name) = split(/^.*\//, $0);
23 # following /usr/include/sysexits.h
24 $EX_OK=0;
25 $EX_USAGE=64;
28 #______________________________________________________________________________
29 sub compare {
30 my ($expect, $got) = @_;
31 my $expect_next;
32 my $expect_next_lit;
33 my $got_next;
34 my $type;
36 while ($expect) {
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);
45 $got_next = $got;
46 $got_next =~ s/^($expect_next_lit).*/\1/;
47 $got =~ s/^$expect_next_lit//;
49 if ($expect_next ne $got_next) {
50 return 0;
53 if ($type eq "int") {
54 if ($got =~ /^[+-]*[0-9]+/) {
55 $got =~ s/^[+-]*[0-9]+//;
56 } else {
57 return 0;
59 } elsif ($type eq "hex") {
60 if ($got =~ /^(0x)*[0-9a-f]+/) {
61 $got =~ s/^(0x)*[0-9a-f]+//;
62 } else {
63 return 0;
65 } elsif ($type eq "all") {
66 return 1;
67 } elsif ($type eq "") {
68 if ($expect_next ne $got_next) {
69 return 0;
70 } else {
71 return 1;
73 } else {
74 $internal_err++;
75 print "** ERROR: special pattern not recognized: <<$type>>, CONSOLE_LOG line: $.\n";
76 return 0;
81 # should not get here
82 $internal_err++;
83 print "** ERROR: $script_name internal error, at end of compare(), CONSOLE_LOG line: $.\n";
85 return 0;
89 #______________________________________________________________________________
90 sub usage {
92 # ***** when editing, be careful to not put tabs in the string printed:
94 print STDERR
96 usage:
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.
153 Known Issues:
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).
161 return {};
164 #______________________________________________________________________________
165 #______________________________________________________________________________
167 if (!GetOptions(
168 "h" => \$help,
169 "help" => \$help,
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,
176 )) {
177 print STDERR "\n";
178 print STDERR "ERROR processing command line options\n";
179 print STDERR "\n";
180 print STDERR "For help, type '$script_name --help'\n";
181 print STDERR "\n";
183 exit $EX_OK;
187 if ($no_strip_ts) {
188 $strip_ts = 1;
189 $no_strip_ts = 0;
190 } else {
191 $strip_ts = 0;
192 $no_strip_ts = 1;
196 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
197 if ($help){
199 &usage;
201 exit $EX_OK;
205 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207 if ($version) {
208 print STDERR "\n$script_name $VUFX\n\n";
209 print STDERR "\n";
211 exit $EX_OK;
215 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
216 if ($#ARGV != 0) {
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.
225 print STDERR "\n";
226 print STDERR "Required arguments: CONSOLE_LOG\n";
227 print STDERR "\n";
229 exit $EX_USAGE;
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 / : ";
250 $line_num = "";
251 $timestamp = "";
253 LINE:
254 while ($line = <ARGV>) {
256 chomp $line;
258 $suppress_line = 0;
260 $prefix = " "; ## 2 characters
263 if ($strip_ts) {
265 $timestamp = $line;
267 if ($timestamp =~ /^\[\s*[0-9]+\.[0-9]*\] /) {
268 ($timestamp, $null) = split(/]/, $line);
269 $timestamp = $timestamp . "] ";
271 } else {
272 $timestamp = "";
276 $line =~ s/^\[\s*[0-9]+\.[0-9]*\] //;
279 # ----- find EXPECT begin
281 if ($line =~ /^\s*$exp_begin/) {
282 $data = $line;
283 $data =~ s/^\s*$exp_begin//;
284 push @exp_begin_stack, $data;
286 if ($verbose) {
287 if ($print_line_num) {
288 $line_num = sprintf("%4s ", $.);
290 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
293 next LINE;
297 # ----- find EXPECT end
299 if ($line =~ /^\s*$exp_end/) {
300 $data = $line;
301 $data =~ s/^\s*$exp_end//;
303 if ($verbose) {
304 if ($print_line_num) {
305 $line_num = sprintf("%4s ", $.);
307 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
310 $found = 0;
311 $no_begin = 0;
312 if (@exp_found_or_begin > 0) {
313 $begin = pop @exp_found_or_begin;
314 if (compare($data, $begin)) {
315 $found = 1;
316 $exp_found++;
318 } elsif (@begin > 0) {
319 $begin = pop @exp_begin_stack;
320 } else {
321 $no_begin = 1;
324 if ($no_begin) {
326 $exp_missing_begin++;
327 print "** ERROR: EXPECT end without matching EXPECT begin:\n";
328 print " end ---> $line\n";
330 } elsif (! $found) {
332 if ($print_line_num) {
333 $line_num = sprintf("%4s ", $.);
336 $exp_missing++;
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)) {
342 $exp_missing_end++;
343 print "** ERROR: EXPECT end does not match EXPECT begin:\n";
344 print " begin -> $begin\n";
345 print " end ---> $line\n";
349 next LINE;
353 # ----- find EXPECT_NOT begin
355 if ($line =~ /^\s*$expnot_begin/) {
356 $data = $line;
357 $data =~ s/^\s*$expnot_begin//;
358 push @expnot_begin_stack, $data;
360 if ($verbose) {
361 if ($print_line_num) {
362 $line_num = sprintf("%4s ", $.);
364 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
367 next LINE;
371 # ----- find EXPECT_NOT end
373 if ($line =~ /^\s*$expnot_end/) {
374 $data = $line;
375 $data =~ s/^\s*$expnot_end//;
377 if ($verbose) {
378 if ($print_line_num) {
379 $line_num = sprintf("%4s ", $.);
381 printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
384 $found = 0;
385 $no_begin = 0;
386 if (@expnot_found_or_begin > 0) {
387 $begin = pop @expnot_found_or_begin;
388 if (compare($data, $begin)) {
389 $found = 1;
390 $expnot_found++;
392 } elsif (@expnot_begin_stack <= 0) {
393 $no_begin = 1;
396 if ($no_begin) {
398 $expnot_missing_begin++;
399 print "** ERROR: EXPECT_NOT end without matching EXPECT_NOT begin:\n";
400 print " end ---> $line\n";
404 if ($found) {
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;
414 } else {
416 $expnot_missing++;
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";
433 next LINE;
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 /) {
443 $unittest_fail++;
444 $prefix = ">>"; # 2 characters
447 $found = 0;
448 foreach $begin (@exp_begin_stack) {
449 if (compare($begin, $line)) {
450 $found = 1;
451 last;
455 if ($found) {
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;
463 if ($hide_expect) {
464 $suppress_line = 1;
466 $prefix = "ok"; # 2 characters
470 $found = 0;
471 foreach $begin (@expnot_begin_stack) {
472 if (compare($begin, $line)) {
473 $found = 1;
474 last;
478 if ($found) {
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;
486 if ($hide_expect) {
487 $suppress_line = 1;
489 $prefix = "**"; # 2 characters
493 if ($suppress_line) {
494 next 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) {
505 print "\n";
506 print "** EXPECT statistics:\n";
507 print "**\n";
508 printf "** non-zero values expected:\n";
509 print "**\n";
510 printf "** EXPECT found : %4i\n", $exp_found;
511 printf "** EXPECT_NOT not found : %4i\n", $expnot_missing;
512 print "**\n";
513 printf "** zero values expected:\n";
514 print "**\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;
518 print "**\n";
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;
522 print "**\n";
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";