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>
This commit is contained in:
Steven Rostedt
2011-09-30 19:44:53 -04:00
committed by Steven Rostedt
parent 4ab1cce5bd
commit 45d73a5d8a
2 changed files with 98 additions and 4 deletions
+60 -4
View File
@@ -361,6 +361,21 @@ sub set_variable {
}
}
sub process_if {
my ($name, $value) = @_;
my $val = process_variables($value);
if ($val =~ /^\s*0\s*$/) {
return 0;
} elsif ($val =~ /^\s*\d+\s*$/) {
return 1;
}
die ("$name: $.: Undefined variable $val in if statement\n");
return 1;
}
sub read_config {
my ($config) = @_;
@@ -376,6 +391,8 @@ sub read_config {
my $skip = 0;
my $rest;
my $test_case = 0;
my $if = 0;
my $if_set = 0;
while (<IN>) {
@@ -397,7 +414,7 @@ sub read_config {
$default = 0;
$repeat = 1;
if ($rest =~ /\s+SKIP(.*)/) {
if ($rest =~ /\s+SKIP\b(.*)/) {
$rest = $1;
$skip = 1;
} else {
@@ -411,9 +428,16 @@ sub read_config {
$repeat_tests{"$test_num"} = $repeat;
}
if ($rest =~ /\s+SKIP(.*)/) {
$rest = $1;
$skip = 1;
if ($rest =~ /\sIF\s+(\S*)(.*)/) {
$rest = $2;
if (process_if($name, $1)) {
$if_set = 1;
} else {
$skip = 1;
}
$if = 1;
} else {
$if = 0;
}
if ($rest !~ /^\s*$/) {
@@ -437,10 +461,42 @@ sub read_config {
$skip = 0;
}
if ($rest =~ /\sIF\s+(\S*)(.*)/) {
$if = 1;
$rest = $2;
if (process_if($name, $1)) {
$if_set = 1;
} else {
$skip = 1;
}
} else {
$if = 0;
}
if ($rest !~ /^\s*$/) {
die "$name: $.: Gargbage found after DEFAULTS\n$_";
}
} elsif (/^\s*ELSE(.*)$/) {
if (!$if) {
die "$name: $.: ELSE found with out matching IF section\n$_";
}
$rest = $1;
if ($if_set) {
$skip = 1;
} else {
$skip = 0;
if ($rest =~ /\sIF\s+(\S*)(.*)/) {
# May be a ELSE IF section.
if (!process_if($name, $1)) {
$skip = 1;
}
} else {
$if = 0;
}
}
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
next if ($skip);