Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: add processing of EXPECT_NOT to of_unittest_expect

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 <frowand.list@gmail.com>
Link: https://lore.kernel.org/r/20230213185702.395776-3-frowand.list@gmail.com
Signed-off-by: Rob Herring <robh@kernel.org>

authored by

Frank Rowand and committed by
Rob Herring
568a10bf 511f3aa7

+145 -12
+145 -12
scripts/dtc/of_unittest_expect
··· 9 9 # on the console log that results from executing the Linux kernel 10 10 # devicetree unittest (drivers/of/unitest.c). 11 11 12 - $VUFX = "230121a"; 12 + $VUFX = "230211a"; 13 13 14 14 use strict 'refs'; 15 15 use strict subs; ··· 62 62 } else { 63 63 return 0; 64 64 } 65 + } elsif ($type eq "all") { 66 + return 1; 65 67 } elsif ($type eq "") { 66 68 if ($expect_next ne $got_next) { 67 69 return 0; ··· 132 130 133 131 <<int>> matches: [+-]*[0-9]+ 134 132 <<hex>> matches: (0x)*[0-9a-f]+ 133 + <<all>> matches: anything to end of line 135 134 136 135 'EXPECT \\' (begin) and 'EXPECT /' (end) lines are suppressed. 137 136 ··· 243 240 $pr_fmt = "### dt-test ### "; 244 241 $exp_begin = "${pr_fmt}EXPECT \\\\ : "; 245 242 $exp_end = "${pr_fmt}EXPECT / : "; 243 + $expnot_begin = "${pr_fmt}EXPECT_NOT \\\\ : "; 244 + $expnot_end = "${pr_fmt}EXPECT_NOT / : "; 246 245 247 246 248 247 $line_num = ""; ··· 254 249 while ($line = <ARGV>) { 255 250 256 251 chomp $line; 252 + 253 + $suppress_line = 0; 257 254 258 255 $prefix = " "; ## 2 characters 259 256 ··· 313 306 $begin = pop @exp_found_or_begin; 314 307 if (compare($data, $begin)) { 315 308 $found = 1; 309 + $exp_found++; 316 310 } 317 311 } elsif (@begin > 0) { 318 312 $begin = pop @exp_begin_stack; ··· 324 316 if ($no_begin) { 325 317 326 318 $exp_missing_begin++; 327 - print "** ERROR: EXPECT end without any EXPECT begin:\n"; 319 + print "** ERROR: EXPECT end without matching EXPECT begin:\n"; 328 320 print " end ---> $line\n"; 329 321 330 322 } elsif (! $found) { ··· 337 329 printf "** %s%s$script_name WARNING - not found ---> %s\n", 338 330 $line_num, $timestamp, $data; 339 331 340 - } elsif (! compare($data, $begin)) { 332 + } elsif (! compare($data, $begin) and ($data ne $begin)) { 341 333 342 334 $exp_missing_end++; 343 335 print "** ERROR: EXPECT end does not match EXPECT begin:\n"; 344 336 print " begin -> $begin\n"; 345 337 print " end ---> $line\n"; 346 338 339 + } 340 + 341 + next LINE; 342 + } 343 + 344 + 345 + # ----- find EXPECT_NOT begin 346 + 347 + if ($line =~ /^\s*$expnot_begin/) { 348 + $data = $line; 349 + $data =~ s/^\s*$expnot_begin//; 350 + push @expnot_begin_stack, $data; 351 + 352 + if ($verbose) { 353 + if ($print_line_num) { 354 + $line_num = sprintf("%4s ", $.); 355 + } 356 + printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line; 357 + } 358 + 359 + next LINE; 360 + } 361 + 362 + 363 + # ----- find EXPECT_NOT end 364 + 365 + if ($line =~ /^\s*$expnot_end/) { 366 + $data = $line; 367 + $data =~ s/^\s*$expnot_end//; 368 + 369 + if ($verbose) { 370 + if ($print_line_num) { 371 + $line_num = sprintf("%4s ", $.); 372 + } 373 + printf "%s %s%s%s\n", $prefix, $line_num, $timestamp, $line; 374 + } 375 + 376 + $found = 0; 377 + $no_begin = 0; 378 + if (@expnot_found_or_begin > 0) { 379 + $begin = pop @expnot_found_or_begin; 380 + if (compare($data, $begin)) { 381 + $found = 1; 382 + $expnot_found++; 383 + } 384 + } elsif (@expnot_begin_stack <= 0) { 385 + $no_begin = 1; 386 + } 387 + 388 + if ($no_begin) { 389 + 390 + $expnot_missing_begin++; 391 + print "** ERROR: EXPECT_NOT end without matching EXPECT_NOT begin:\n"; 392 + print " end ---> $line\n"; 393 + 394 + } 395 + 396 + if ($found) { 397 + 398 + if ($print_line_num) { 399 + $line_num = sprintf("%4s ", $.); 400 + } 401 + 402 + printf "** %s%s$script_name WARNING - next line matches EXPECT_NOT\n", 403 + $line_num, $timestamp; 404 + printf "** %s%s%s\n", $line_num, $timestamp, $line; 405 + 347 406 } else { 348 407 349 - $exp_found++; 408 + $expnot_missing++; 350 409 410 + } 411 + 412 + if (@expnot_begin_stack > 0) { 413 + $begin = pop @expnot_begin_stack; 414 + 415 + if (! compare($data, $begin) and ($data ne $begin)) { 416 + 417 + $expnot_missing_end++; 418 + print "** ERROR: EXPECT_NOT end does not match EXPECT_NOT begin:\n"; 419 + print " begin -> $begin\n"; 420 + print " end ---> $line\n"; 421 + 422 + } 351 423 } 352 424 353 425 next LINE; ··· 462 374 463 375 if ($hide_expect) { 464 376 $suppress_line = 1; 465 - next LINE; 466 377 } 467 378 $prefix = "ok"; # 2 characters 468 379 } 469 380 381 + 382 + $found = 0; 383 + foreach $begin (@expnot_begin_stack) { 384 + if (compare($begin, $line)) { 385 + $found = 1; 386 + last; 387 + } 388 + } 389 + 390 + if ($found) { 391 + $begin = shift @begin; 392 + while (! compare($begin, $line)) { 393 + push @expnot_found_or_begin, $begin; 394 + $begin = shift @begin; 395 + } 396 + push @expnot_found_or_begin, $line; 397 + 398 + if ($hide_expect) { 399 + $suppress_line = 1; 400 + } 401 + $prefix = "**"; # 2 characters 402 + } 403 + 404 + 405 + if ($suppress_line) { 406 + next LINE; 407 + } 470 408 471 409 if ($print_line_num) { 472 410 $line_num = sprintf("%4s ", $.); ··· 505 391 print "\n"; 506 392 print "** EXPECT statistics:\n"; 507 393 print "**\n"; 508 - printf "** EXPECT found : %4i\n", $exp_found; 509 - printf "** EXPECT not found : %4i\n", $exp_missing; 510 - printf "** missing EXPECT begin : %4i\n", $exp_missing_begin; 511 - printf "** missing EXPECT end : %4i\n", $exp_missing_end; 512 - printf "** unittest FAIL : %4i\n", $unittest_fail; 513 - printf "** internal error : %4i\n", $internal_err; 394 + printf "** non-zero values expected:\n"; 395 + print "**\n"; 396 + printf "** EXPECT found : %4i\n", $exp_found; 397 + printf "** EXPECT_NOT not found : %4i\n", $expnot_missing; 398 + print "**\n"; 399 + printf "** zero values expected:\n"; 400 + print "**\n"; 401 + printf "** EXPECT not found : %4i\n", $exp_missing; 402 + printf "** missing EXPECT begin : %4i\n", $exp_missing_begin; 403 + printf "** missing EXPECT end : %4i\n", $exp_missing_end; 404 + print "**\n"; 405 + printf "** EXPECT_NOT found : %4i\n", $expnot_found; 406 + printf "** missing EXPECT_NOT begin : %4i\n", $expnot_missing_begin; 407 + printf "** missing EXPECT_NOT end : %4i\n", $expnot_missing_end; 408 + print "**\n"; 409 + printf "** unittest FAIL : %4i\n", $unittest_fail; 410 + printf "** internal error : %4i\n", $internal_err; 514 411 } 515 412 516 413 if (@exp_begin_stack) { 517 - print "** ERROR: EXPECT begin without any EXPECT end:\n"; 414 + print "** ERROR: EXPECT begin without matching EXPECT end:\n"; 518 415 print " This list may be misleading.\n"; 519 416 foreach $begin (@exp_begin_stack) { 417 + print " begin ---> $begin\n"; 418 + } 419 + } 420 + 421 + if (@expnot_begin_stack) { 422 + print "** ERROR: EXPECT_NOT begin without matching EXPECT_NOT end:\n"; 423 + print " This list may be misleading.\n"; 424 + foreach $begin (@expnot_begin_stack) { 520 425 print " begin ---> $begin\n"; 521 426 } 522 427 }