From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 10/21] ktest: Let IF keyword take comparisons
Date: Fri, 28 Oct 2011 07:16:08 -0400 [thread overview]
Message-ID: <20111028112022.431301836@goodmis.org> (raw)
In-Reply-To: 20111028111558.173726794@goodmis.org
[-- Attachment #1: Type: text/plain, Size: 4034 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
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>
---
tools/testing/ktest/ktest.pl | 54 ++++++++++++++++++++++++++++++++++----
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 c76e18f..ed20d68 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);
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index 6a0a0ba..4e8fb91 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -72,6 +72,8 @@
# the same option name under the same test or as default
# ktest will fail to execute, and no tests will run.
#
+#
+#
# Both TEST_START and DEFAULTS sections can also have the IF keyword
# The value after the IF must evaluate into a 0 or non 0 positive
# integer, and can use the config variables (explained below).
@@ -110,6 +112,18 @@
# ELSE
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
#
+# The if statement may also have comparisons that will and for
+# == and !=, strings may be used for both sides.
+#
+# BOX_TYPE := x86_32
+#
+# DEFAULTS IF ${BOX_TYPE} == x86_32
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-32
+# ELSE
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-64
+#
+
+
#### Config variables ####
#
--
1.7.6.3
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2011-10-28 11:23 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-28 11:15 [PATCH 00/21] [GIT PULL] ktest: lots of nice new features Steven Rostedt
2011-10-28 11:15 ` [PATCH 01/21] ktest: Add TEST_TYPE install option Steven Rostedt
2011-10-28 11:16 ` [PATCH 02/21] ktest: Create outputdir if it does not exist Steven Rostedt
2011-10-28 11:16 ` [PATCH 03/21] ktest: Only need to save .config when doing mrproper Steven Rostedt
2011-10-28 11:16 ` [PATCH 04/21] ktest: Include monitor in reboot code Steven Rostedt
2011-10-28 11:16 ` [PATCH 05/21] ktest: Fail when grub menu not found Steven Rostedt
2011-10-28 11:16 ` [PATCH 06/21] ktest: Add NO_INSTALL option to not install for a test Steven Rostedt
2011-10-28 11:16 ` [PATCH 07/21] ktest: Add option REBOOT_SUCCESS_LINE to stop waiting after a reboot Steven Rostedt
2011-10-28 11:16 ` [PATCH 08/21] ktest: Do not reboot on config or build issues Steven Rostedt
2011-10-28 11:16 ` [PATCH 09/21] ktest: Add IF and ELSE to config sections Steven Rostedt
2011-10-28 11:16 ` Steven Rostedt [this message]
2011-10-28 11:16 ` [PATCH 11/21] ktest: Add INCLUDE keyword to include other config files Steven Rostedt
2011-10-28 11:16 ` [PATCH 12/21] ktest: Consolidate TEST_TYPE and DEFAULT code Steven Rostedt
2011-10-28 11:16 ` [PATCH 13/21] ktest: Add OVERRIDE keyword to DEFAULTS section Steven Rostedt
2011-10-28 11:16 ` [PATCH 14/21] ktest: Add DEFINED keyword for IF statements Steven Rostedt
2011-10-28 11:16 ` [PATCH 15/21] ktest: Sort make_min_config configs by dependecies Steven Rostedt
2011-10-28 11:16 ` [PATCH 16/21] ktest: Fix parsing of config section lines Steven Rostedt
2011-10-28 11:16 ` [PATCH 17/21] ktest: Add processing of complex conditionals Steven Rostedt
2011-10-28 11:16 ` [PATCH 18/21] ktest: Do not opencode reboot in grub setting Steven Rostedt
2011-10-28 11:16 ` [PATCH 19/21] ktest: Add another monitor flush before installing kernel Steven Rostedt
2011-10-28 11:16 ` [PATCH 20/21] ktest: Add variable ${PWD} Steven Rostedt
2011-10-28 11:16 ` [PATCH 21/21] ktest: Evaluate variables entered on the command line Steven Rostedt
2011-11-08 1:23 ` [PATCH 00/21] [GIT PULL] ktest: lots of nice new features Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111028112022.431301836@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.