diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-09-30 20:24:07 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-10-17 11:54:11 -0400 |
commit | ab7a3f52cef5ff1c784de7adfbda3421b10754a4 (patch) | |
tree | 4ea41c74795c4b58abf838ef1f9aeb3cec86240d | |
parent | 45d73a5d8a98dbabcdf37e2da5ef5b0412244643 (diff) |
ktest: Let IF keyword take comparisons
Allow ==, !=, <=, >=, <, and > to be used in IF statements
to compare if a section should be processed or not.
For example:
BITS := 32
DEFAULTS IF ${BITS} == 32
MIN_CONFIG = ${CONFIG_DIR}/config-32
ELSE
MIN_CONFIG = ${CONFIG_DIR}/config-64
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 54 | ||||
-rw-r--r-- | tools/testing/ktest/sample.conf | 14 |
2 files changed, 62 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 | ||
364 | sub 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 | |||
364 | sub process_if { | 392 | sub 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); |
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 6a0a0ba59975..4e8fb91fd517 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf | |||
@@ -72,6 +72,8 @@ | |||
72 | # the same option name under the same test or as default | 72 | # the same option name under the same test or as default |
73 | # ktest will fail to execute, and no tests will run. | 73 | # ktest will fail to execute, and no tests will run. |
74 | # | 74 | # |
75 | # | ||
76 | # | ||
75 | # Both TEST_START and DEFAULTS sections can also have the IF keyword | 77 | # Both TEST_START and DEFAULTS sections can also have the IF keyword |
76 | # The value after the IF must evaluate into a 0 or non 0 positive | 78 | # The value after the IF must evaluate into a 0 or non 0 positive |
77 | # integer, and can use the config variables (explained below). | 79 | # integer, and can use the config variables (explained below). |
@@ -110,6 +112,18 @@ | |||
110 | # ELSE | 112 | # ELSE |
111 | # BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network | 113 | # BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network |
112 | # | 114 | # |
115 | # The if statement may also have comparisons that will and for | ||
116 | # == and !=, strings may be used for both sides. | ||
117 | # | ||
118 | # BOX_TYPE := x86_32 | ||
119 | # | ||
120 | # DEFAULTS IF ${BOX_TYPE} == x86_32 | ||
121 | # BUILD_TYPE = useconfig:${CONFIG_DIR}/config-32 | ||
122 | # ELSE | ||
123 | # BUILD_TYPE = useconfig:${CONFIG_DIR}/config-64 | ||
124 | # | ||
125 | |||
126 | |||
113 | 127 | ||
114 | #### Config variables #### | 128 | #### Config variables #### |
115 | # | 129 | # |