From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 09/17][RFC] ktest: Add IF and ELSE to config sections
Date: Mon, 17 Oct 2011 12:05:04 -0400 [thread overview]
Message-ID: <20111017165951.126001279@goodmis.org> (raw)
In-Reply-To: 20111017160455.498567257@goodmis.org
[-- Attachment #1: Type: text/plain, Size: 4536 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
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>
---
tools/testing/ktest/ktest.pl | 64 ++++++++++++++++++++++++++++++++++++--
tools/testing/ktest/sample.conf | 38 +++++++++++++++++++++++
2 files changed, 98 insertions(+), 4 deletions(-)
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 057676a..c76e18f 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -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);
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index 67bc4e0..6a0a0ba 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -72,6 +72,44 @@
# 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).
+#
+# DEFAULTS IF ${IS_X86_32}
+#
+# The above will process the DEFAULTS section if the config
+# variable IS_X86_32 evaluates to a non zero positive integer
+# otherwise if it evaluates to zero, it will act the same
+# as if the SKIP keyword was used.
+#
+# The ELSE keyword can be used directly after a section with
+# a IF statement.
+#
+# TEST_START IF ${RUN_NET_TESTS}
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
+#
+# ELSE
+#
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-normal
+#
+#
+# The ELSE keyword can also contain an IF statement to allow multiple
+# if then else sections. But all the sections must be either
+# DEFAULT or TEST_START, they can not be a mixture.
+#
+# TEST_START IF ${RUN_NET_TESTS}
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
+#
+# ELSE IF ${RUN_DISK_TESTS}
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-tests
+#
+# ELSE IF ${RUN_CPU_TESTS}
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-cpu
+#
+# ELSE
+# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
+#
#### 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-17 17:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-17 16:04 [PATCH 00/17][RFC] ktest updates for v3.2 Steven Rostedt
2011-10-17 16:04 ` [PATCH 01/17][RFC] ktest: Add TEST_TYPE install option Steven Rostedt
2011-10-17 16:04 ` [PATCH 02/17][RFC] ktest: Create outputdir if it does not exist Steven Rostedt
2011-10-17 16:04 ` [PATCH 03/17][RFC] ktest: Only need to save .config when doing mrproper Steven Rostedt
2011-10-17 16:04 ` [PATCH 04/17][RFC] ktest: Include monitor in reboot code Steven Rostedt
2011-10-17 16:05 ` [PATCH 05/17][RFC] ktest: Fail when grub menu not found Steven Rostedt
2011-10-17 16:05 ` [PATCH 06/17][RFC] ktest: Add NO_INSTALL option to not install for a test Steven Rostedt
2011-10-17 16:05 ` [PATCH 07/17][RFC] ktest: Add option REBOOT_SUCCESS_LINE to stop waiting after a reboot Steven Rostedt
2011-10-17 16:05 ` [PATCH 08/17][RFC] ktest: Do not reboot on config or build issues Steven Rostedt
2011-10-17 16:05 ` Steven Rostedt [this message]
2011-10-17 16:05 ` [PATCH 10/17][RFC] ktest: Let IF keyword take comparisons Steven Rostedt
2011-10-17 16:05 ` [PATCH 11/17][RFC] ktest: Add INCLUDE keyword to include other config files Steven Rostedt
2011-10-17 16:05 ` [PATCH 12/17][RFC] ktest: Consolidate TEST_TYPE and DEFAULT code Steven Rostedt
2011-10-17 16:05 ` [PATCH 13/17][RFC] ktest: Add OVERRIDE keyword to DEFAULTS section Steven Rostedt
2011-10-17 16:05 ` [PATCH 14/17][RFC] ktest: Add DEFINED keyword for IF statements Steven Rostedt
2011-10-17 16:05 ` [PATCH 15/17][RFC] ktest: Sort make_min_config configs by dependecies Steven Rostedt
2011-10-17 16:05 ` [PATCH 16/17][RFC] ktest: Fix parsing of config section lines Steven Rostedt
2011-10-17 16:05 ` [PATCH 17/17][RFC] ktest: Add processing of complex conditionals Steven Rostedt
2011-10-20 14:31 ` [PATCH 00/17][RFC] ktest updates for v3.2 Andrew Jones
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=20111017165951.126001279@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox