aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/ktest/ktest.pl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/ktest/ktest.pl')
-rwxr-xr-xtools/testing/ktest/ktest.pl54
1 files changed, 48 insertions, 6 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index c76e18f00c44..ed20d6881ec9 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -361,11 +361,47 @@ sub set_variable {
361 } 361 }
362} 362}
363 363
364sub process_compare {
365 my ($lval, $cmp, $rval) = @_;
366
367 # remove whitespace
368
369 $lval =~ s/^\s*//;
370 $lval =~ s/\s*$//;
371
372 $rval =~ s/^\s*//;
373 $rval =~ s/\s*$//;
374
375 if ($cmp eq "==") {
376 return $lval eq $rval;
377 } elsif ($cmp eq "!=") {
378 return $lval ne $rval;
379 }
380
381 my $statement = "$lval $cmp $rval";
382 my $ret = eval $statement;
383
384 # $@ stores error of eval
385 if ($@) {
386 return -1;
387 }
388
389 return $ret;
390}
391
364sub process_if { 392sub process_if {
365 my ($name, $value) = @_; 393 my ($name, $value) = @_;
366 394
367 my $val = process_variables($value); 395 my $val = process_variables($value);
368 396
397 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
398 my $ret = process_compare($1, $2, $3);
399 if ($ret < 0) {
400 die "$name: $.: Unable to process comparison\n";
401 }
402 return $ret;
403 }
404
369 if ($val =~ /^\s*0\s*$/) { 405 if ($val =~ /^\s*0\s*$/) {
370 return 0; 406 return 0;
371 } elsif ($val =~ /^\s*\d+\s*$/) { 407 } elsif ($val =~ /^\s*\d+\s*$/) {
@@ -428,8 +464,8 @@ sub read_config {
428 $repeat_tests{"$test_num"} = $repeat; 464 $repeat_tests{"$test_num"} = $repeat;
429 } 465 }
430 466
431 if ($rest =~ /\sIF\s+(\S*)(.*)/) { 467 if ($rest =~ /\sIF\s+(.*)/) {
432 $rest = $2; 468 $rest = "";
433 if (process_if($name, $1)) { 469 if (process_if($name, $1)) {
434 $if_set = 1; 470 $if_set = 1;
435 } else { 471 } else {
@@ -461,14 +497,14 @@ sub read_config {
461 $skip = 0; 497 $skip = 0;
462 } 498 }
463 499
464 if ($rest =~ /\sIF\s+(\S*)(.*)/) { 500 if ($rest =~ /\sIF\s+(.*)/) {
465 $if = 1; 501 $if = 1;
466 $rest = $2;
467 if (process_if($name, $1)) { 502 if (process_if($name, $1)) {
468 $if_set = 1; 503 $if_set = 1;
469 } else { 504 } else {
470 $skip = 1; 505 $skip = 1;
471 } 506 }
507 $rest = "";
472 } else { 508 } else {
473 $if = 0; 509 $if = 0;
474 } 510 }
@@ -477,26 +513,32 @@ sub read_config {
477 die "$name: $.: Gargbage found after DEFAULTS\n$_"; 513 die "$name: $.: Gargbage found after DEFAULTS\n$_";
478 } 514 }
479 515
480 } elsif (/^\s*ELSE(.*)$/) { 516 } elsif (/^\s*ELSE\b(.*)$/) {
481 if (!$if) { 517 if (!$if) {
482 die "$name: $.: ELSE found with out matching IF section\n$_"; 518 die "$name: $.: ELSE found with out matching IF section\n$_";
483 } 519 }
484 $rest = $1; 520 $rest = $1;
485 if ($if_set) { 521 if ($if_set) {
486 $skip = 1; 522 $skip = 1;
523 $rest = "";
487 } else { 524 } else {
488 $skip = 0; 525 $skip = 0;
489 526
490 if ($rest =~ /\sIF\s+(\S*)(.*)/) { 527 if ($rest =~ /\sIF\s+(.*)/) {
491 # May be a ELSE IF section. 528 # May be a ELSE IF section.
492 if (!process_if($name, $1)) { 529 if (!process_if($name, $1)) {
493 $skip = 1; 530 $skip = 1;
494 } 531 }
532 $rest = "";
495 } else { 533 } else {
496 $if = 0; 534 $if = 0;
497 } 535 }
498 } 536 }
499 537
538 if ($rest !~ /^\s*$/) {
539 die "$name: $.: Gargbage found after DEFAULTS\n$_";
540 }
541
500 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { 542 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
501 543
502 next if ($skip); 544 next if ($skip);