aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/ktest/ktest.pl
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2011-09-30 20:24:07 -0400
committerSteven Rostedt <rostedt@goodmis.org>2011-10-17 11:54:11 -0400
commitab7a3f52cef5ff1c784de7adfbda3421b10754a4 (patch)
tree4ea41c74795c4b58abf838ef1f9aeb3cec86240d /tools/testing/ktest/ktest.pl
parentktest: Add IF and ELSE to config sections (diff)
downloadlinux-dev-ab7a3f52cef5ff1c784de7adfbda3421b10754a4.tar.xz
linux-dev-ab7a3f52cef5ff1c784de7adfbda3421b10754a4.zip
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>
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 {
}
}
+sub process_compare {
+ my ($lval, $cmp, $rval) = @_;
+
+ # remove whitespace
+
+ $lval =~ s/^\s*//;
+ $lval =~ s/\s*$//;
+
+ $rval =~ s/^\s*//;
+ $rval =~ s/\s*$//;
+
+ if ($cmp eq "==") {
+ return $lval eq $rval;
+ } elsif ($cmp eq "!=") {
+ return $lval ne $rval;
+ }
+
+ my $statement = "$lval $cmp $rval";
+ my $ret = eval $statement;
+
+ # $@ stores error of eval
+ if ($@) {
+ return -1;
+ }
+
+ return $ret;
+}
+
sub process_if {
my ($name, $value) = @_;
my $val = process_variables($value);
+ if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
+ my $ret = process_compare($1, $2, $3);
+ if ($ret < 0) {
+ die "$name: $.: Unable to process comparison\n";
+ }
+ return $ret;
+ }
+
if ($val =~ /^\s*0\s*$/) {
return 0;
} elsif ($val =~ /^\s*\d+\s*$/) {
@@ -428,8 +464,8 @@ sub read_config {
$repeat_tests{"$test_num"} = $repeat;
}
- if ($rest =~ /\sIF\s+(\S*)(.*)/) {
- $rest = $2;
+ if ($rest =~ /\sIF\s+(.*)/) {
+ $rest = "";
if (process_if($name, $1)) {
$if_set = 1;
} else {
@@ -461,14 +497,14 @@ sub read_config {
$skip = 0;
}
- if ($rest =~ /\sIF\s+(\S*)(.*)/) {
+ if ($rest =~ /\sIF\s+(.*)/) {
$if = 1;
- $rest = $2;
if (process_if($name, $1)) {
$if_set = 1;
} else {
$skip = 1;
}
+ $rest = "";
} else {
$if = 0;
}
@@ -477,26 +513,32 @@ sub read_config {
die "$name: $.: Gargbage found after DEFAULTS\n$_";
}
- } elsif (/^\s*ELSE(.*)$/) {
+ } elsif (/^\s*ELSE\b(.*)$/) {
if (!$if) {
die "$name: $.: ELSE found with out matching IF section\n$_";
}
$rest = $1;
if ($if_set) {
$skip = 1;
+ $rest = "";
} else {
$skip = 0;
- if ($rest =~ /\sIF\s+(\S*)(.*)/) {
+ if ($rest =~ /\sIF\s+(.*)/) {
# May be a ELSE IF section.
if (!process_if($name, $1)) {
$skip = 1;
}
+ $rest = "";
} else {
$if = 0;
}
}
+ if ($rest !~ /^\s*$/) {
+ die "$name: $.: Gargbage found after DEFAULTS\n$_";
+ }
+
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
next if ($skip);