Skip to content

Commit

Permalink
of: add processing of EXPECT_NOT to of_unittest_expect
Browse files Browse the repository at this point in the history
scripts/dtc/of_unittest_expect processes EXPECT messages that
document expected kernel messages triggered by unittest.  Add
processing of EXPECT_NOT messages that document kernel messages
triggered by unittest that are not expected.

This is commit 2 of 2, implementing the processing of EXPECT_NOT
messages.

Signed-off-by: Frank Rowand <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
frowand authored and robherring committed Feb 17, 2023
1 parent 511f3aa commit 568a10b
Showing 1 changed file with 145 additions and 12 deletions.
157 changes: 145 additions & 12 deletions scripts/dtc/of_unittest_expect
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# on the console log that results from executing the Linux kernel
# devicetree unittest (drivers/of/unitest.c).

$VUFX = "230121a";
$VUFX = "230211a";

use strict 'refs';
use strict subs;
Expand Down Expand Up @@ -62,6 +62,8 @@ sub compare {
} else {
return 0;
}
} elsif ($type eq "all") {
return 1;
} elsif ($type eq "") {
if ($expect_next ne $got_next) {
return 0;
Expand Down Expand Up @@ -130,6 +132,7 @@ usage:
<<int>> matches: [+-]*[0-9]+
<<hex>> matches: (0x)*[0-9a-f]+
<<all>> matches: anything to end of line
'EXPECT \\' (begin) and 'EXPECT /' (end) lines are suppressed.
Expand Down Expand Up @@ -240,6 +243,8 @@ if ($#ARGV != 0) {
$pr_fmt = "### dt-test ### ";
$exp_begin = "${pr_fmt}EXPECT \\\\ : ";
$exp_end = "${pr_fmt}EXPECT / : ";
$expnot_begin = "${pr_fmt}EXPECT_NOT \\\\ : ";
$expnot_end = "${pr_fmt}EXPECT_NOT / : ";


$line_num = "";
Expand All @@ -250,6 +255,8 @@ while ($line = <ARGV>) {

chomp $line;

$suppress_line = 0;

$prefix = " "; ## 2 characters


Expand Down Expand Up @@ -306,6 +313,7 @@ while ($line = <ARGV>) {
$begin = pop @exp_found_or_begin;
if (compare($data, $begin)) {
$found = 1;
$exp_found++;
}
} elsif (@begin > 0) {
$begin = pop @exp_begin_stack;
Expand All @@ -316,7 +324,7 @@ while ($line = <ARGV>) {
if ($no_begin) {

$exp_missing_begin++;
print "** ERROR: EXPECT end without any EXPECT begin:\n";
print "** ERROR: EXPECT end without matching EXPECT begin:\n";
print " end ---> $line\n";

} elsif (! $found) {
Expand All @@ -329,17 +337,97 @@ while ($line = <ARGV>) {
printf "** %s%s$script_name WARNING - not found ---> %s\n",
$line_num, $timestamp, $data;

} elsif (! compare($data, $begin)) {
} elsif (! compare($data, $begin) and ($data ne $begin)) {

$exp_missing_end++;
print "** ERROR: EXPECT end does not match EXPECT begin:\n";
print " begin -> $begin\n";
print " end ---> $line\n";

}

next LINE;
}


# ----- find EXPECT_NOT begin

if ($line =~ /^\s*$expnot_begin/) {
$data = $line;
$data =~ s/^\s*$expnot_begin//;
push @expnot_begin_stack, $data;

if ($verbose) {
if ($print_line_num) {
$line_num = sprintf("%4s ", $.);
}
printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
}

next LINE;
}


# ----- find EXPECT_NOT end

if ($line =~ /^\s*$expnot_end/) {
$data = $line;
$data =~ s/^\s*$expnot_end//;

if ($verbose) {
if ($print_line_num) {
$line_num = sprintf("%4s ", $.);
}
printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line;
}

$found = 0;
$no_begin = 0;
if (@expnot_found_or_begin > 0) {
$begin = pop @expnot_found_or_begin;
if (compare($data, $begin)) {
$found = 1;
$expnot_found++;
}
} elsif (@expnot_begin_stack <= 0) {
$no_begin = 1;
}

if ($no_begin) {

$expnot_missing_begin++;
print "** ERROR: EXPECT_NOT end without matching EXPECT_NOT begin:\n";
print " end ---> $line\n";

}

if ($found) {

if ($print_line_num) {
$line_num = sprintf("%4s ", $.);
}

printf "** %s%s$script_name WARNING - next line matches EXPECT_NOT\n",
$line_num, $timestamp;
printf "** %s%s%s\n", $line_num, $timestamp, $line;

} else {

$exp_found++;
$expnot_missing++;

}

if (@expnot_begin_stack > 0) {
$begin = pop @expnot_begin_stack;

if (! compare($data, $begin) and ($data ne $begin)) {

$expnot_missing_end++;
print "** ERROR: EXPECT_NOT end does not match EXPECT_NOT begin:\n";
print " begin -> $begin\n";
print " end ---> $line\n";

}
}

next LINE;
Expand Down Expand Up @@ -374,12 +462,38 @@ while ($line = <ARGV>) {

if ($hide_expect) {
$suppress_line = 1;
next LINE;
}
$prefix = "ok"; # 2 characters
}


$found = 0;
foreach $begin (@expnot_begin_stack) {
if (compare($begin, $line)) {
$found = 1;
last;
}
}

if ($found) {
$begin = shift @begin;
while (! compare($begin, $line)) {
push @expnot_found_or_begin, $begin;
$begin = shift @begin;
}
push @expnot_found_or_begin, $line;

if ($hide_expect) {
$suppress_line = 1;
}
$prefix = "**"; # 2 characters
}


if ($suppress_line) {
next LINE;
}

if ($print_line_num) {
$line_num = sprintf("%4s ", $.);
}
Expand All @@ -391,18 +505,37 @@ if (! $no_expect_stats) {
print "\n";
print "** EXPECT statistics:\n";
print "**\n";
printf "** EXPECT found : %4i\n", $exp_found;
printf "** EXPECT not found : %4i\n", $exp_missing;
printf "** missing EXPECT begin : %4i\n", $exp_missing_begin;
printf "** missing EXPECT end : %4i\n", $exp_missing_end;
printf "** unittest FAIL : %4i\n", $unittest_fail;
printf "** internal error : %4i\n", $internal_err;
printf "** non-zero values expected:\n";
print "**\n";
printf "** EXPECT found : %4i\n", $exp_found;
printf "** EXPECT_NOT not found : %4i\n", $expnot_missing;
print "**\n";
printf "** zero values expected:\n";
print "**\n";
printf "** EXPECT not found : %4i\n", $exp_missing;
printf "** missing EXPECT begin : %4i\n", $exp_missing_begin;
printf "** missing EXPECT end : %4i\n", $exp_missing_end;
print "**\n";
printf "** EXPECT_NOT found : %4i\n", $expnot_found;
printf "** missing EXPECT_NOT begin : %4i\n", $expnot_missing_begin;
printf "** missing EXPECT_NOT end : %4i\n", $expnot_missing_end;
print "**\n";
printf "** unittest FAIL : %4i\n", $unittest_fail;
printf "** internal error : %4i\n", $internal_err;
}

if (@exp_begin_stack) {
print "** ERROR: EXPECT begin without any EXPECT end:\n";
print "** ERROR: EXPECT begin without matching EXPECT end:\n";
print " This list may be misleading.\n";
foreach $begin (@exp_begin_stack) {
print " begin ---> $begin\n";
}
}

if (@expnot_begin_stack) {
print "** ERROR: EXPECT_NOT begin without matching EXPECT_NOT end:\n";
print " This list may be misleading.\n";
foreach $begin (@expnot_begin_stack) {
print " begin ---> $begin\n";
}
}

0 comments on commit 568a10b

Please sign in to comment.