diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-09-30 19:44:53 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-10-17 11:54:11 -0400 |
commit | 45d73a5d8a98dbabcdf37e2da5ef5b0412244643 (patch) | |
tree | 171cebe896512759e763a9d7bb36efe43455d1d1 /tools/testing/ktest/ktest.pl | |
parent | 4ab1cce5bdd87948b75ed4fe4a8629c0f76267ae (diff) |
ktest: Add IF and ELSE to config sections
Add IF keyword to sections within the config. Also added an ELSE
keyword that allows different config options to be set for a given
section.
For example:
TYPE := 1
STATUS := 0
DEFAULTS IF ${TYPE}
[...]
ELSE IF ${STATUS}
[...]
ELSE
[...]
The above will process the first section as $TYPE is true. If it
was false, it would process the last section as $STATUS is false.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing/ktest/ktest.pl')
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 057676a8e785..c76e18f00c44 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -361,6 +361,21 @@ sub set_variable { | |||
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
364 | sub process_if { | ||
365 | my ($name, $value) = @_; | ||
366 | |||
367 | my $val = process_variables($value); | ||
368 | |||
369 | if ($val =~ /^\s*0\s*$/) { | ||
370 | return 0; | ||
371 | } elsif ($val =~ /^\s*\d+\s*$/) { | ||
372 | return 1; | ||
373 | } | ||
374 | |||
375 | die ("$name: $.: Undefined variable $val in if statement\n"); | ||
376 | return 1; | ||
377 | } | ||
378 | |||
364 | sub read_config { | 379 | sub read_config { |
365 | my ($config) = @_; | 380 | my ($config) = @_; |
366 | 381 | ||
@@ -376,6 +391,8 @@ sub read_config { | |||
376 | my $skip = 0; | 391 | my $skip = 0; |
377 | my $rest; | 392 | my $rest; |
378 | my $test_case = 0; | 393 | my $test_case = 0; |
394 | my $if = 0; | ||
395 | my $if_set = 0; | ||
379 | 396 | ||
380 | while (<IN>) { | 397 | while (<IN>) { |
381 | 398 | ||
@@ -397,7 +414,7 @@ sub read_config { | |||
397 | $default = 0; | 414 | $default = 0; |
398 | $repeat = 1; | 415 | $repeat = 1; |
399 | 416 | ||
400 | if ($rest =~ /\s+SKIP(.*)/) { | 417 | if ($rest =~ /\s+SKIP\b(.*)/) { |
401 | $rest = $1; | 418 | $rest = $1; |
402 | $skip = 1; | 419 | $skip = 1; |
403 | } else { | 420 | } else { |
@@ -411,9 +428,16 @@ sub read_config { | |||
411 | $repeat_tests{"$test_num"} = $repeat; | 428 | $repeat_tests{"$test_num"} = $repeat; |
412 | } | 429 | } |
413 | 430 | ||
414 | if ($rest =~ /\s+SKIP(.*)/) { | 431 | if ($rest =~ /\sIF\s+(\S*)(.*)/) { |
415 | $rest = $1; | 432 | $rest = $2; |
416 | $skip = 1; | 433 | if (process_if($name, $1)) { |
434 | $if_set = 1; | ||
435 | } else { | ||
436 | $skip = 1; | ||
437 | } | ||
438 | $if = 1; | ||
439 | } else { | ||
440 | $if = 0; | ||
417 | } | 441 | } |
418 | 442 | ||
419 | if ($rest !~ /^\s*$/) { | 443 | if ($rest !~ /^\s*$/) { |
@@ -437,10 +461,42 @@ sub read_config { | |||
437 | $skip = 0; | 461 | $skip = 0; |
438 | } | 462 | } |
439 | 463 | ||
464 | if ($rest =~ /\sIF\s+(\S*)(.*)/) { | ||
465 | $if = 1; | ||
466 | $rest = $2; | ||
467 | if (process_if($name, $1)) { | ||
468 | $if_set = 1; | ||
469 | } else { | ||
470 | $skip = 1; | ||
471 | } | ||
472 | } else { | ||
473 | $if = 0; | ||
474 | } | ||
475 | |||
440 | if ($rest !~ /^\s*$/) { | 476 | if ($rest !~ /^\s*$/) { |
441 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; | 477 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; |
442 | } | 478 | } |
443 | 479 | ||
480 | } elsif (/^\s*ELSE(.*)$/) { | ||
481 | if (!$if) { | ||
482 | die "$name: $.: ELSE found with out matching IF section\n$_"; | ||
483 | } | ||
484 | $rest = $1; | ||
485 | if ($if_set) { | ||
486 | $skip = 1; | ||
487 | } else { | ||
488 | $skip = 0; | ||
489 | |||
490 | if ($rest =~ /\sIF\s+(\S*)(.*)/) { | ||
491 | # May be a ELSE IF section. | ||
492 | if (!process_if($name, $1)) { | ||
493 | $skip = 1; | ||
494 | } | ||
495 | } else { | ||
496 | $if = 0; | ||
497 | } | ||
498 | } | ||
499 | |||
444 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { | 500 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { |
445 | 501 | ||
446 | next if ($skip); | 502 | next if ($skip); |