diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-05-20 15:48:59 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-05-20 15:48:59 -0400 |
commit | 2a62512bceb44ad45f78aa7ca0e9cfaee9eae46f (patch) | |
tree | 53790abb9948f7ad3f1269f74bd59b553130e67b /tools | |
parent | 77d942ceacbad02d8498ac72ed8d634634057aec (diff) |
ktest: Allow options to be used by other options
There are cases where one ktest option may be used within another
ktest option. Allow them to be reused just like config variables
but there are evaluated at time of test not config processing time.
Thus having something like:
MAKE_CMD = make ARCH=${ARCH}
TEST_START
ARCH = powerpc
TEST_START
ARCH = arm
Will have the arch defined for each test iteration.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 68 | ||||
-rw-r--r-- | tools/testing/ktest/sample.conf | 30 |
2 files changed, 97 insertions, 1 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 18ef66823aa..1fd29b2daa9 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -2019,7 +2019,7 @@ for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { | |||
2019 | } | 2019 | } |
2020 | } | 2020 | } |
2021 | 2021 | ||
2022 | sub set_test_option { | 2022 | sub __set_test_option { |
2023 | my ($name, $i) = @_; | 2023 | my ($name, $i) = @_; |
2024 | 2024 | ||
2025 | my $option = "$name\[$i\]"; | 2025 | my $option = "$name\[$i\]"; |
@@ -2045,6 +2045,72 @@ sub set_test_option { | |||
2045 | return undef; | 2045 | return undef; |
2046 | } | 2046 | } |
2047 | 2047 | ||
2048 | sub eval_option { | ||
2049 | my ($option, $i) = @_; | ||
2050 | |||
2051 | # Add space to evaluate the character before $ | ||
2052 | $option = " $option"; | ||
2053 | my $retval = ""; | ||
2054 | |||
2055 | while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) { | ||
2056 | my $start = $1; | ||
2057 | my $var = $2; | ||
2058 | my $end = $3; | ||
2059 | |||
2060 | # Append beginning of line | ||
2061 | $retval = "$retval$start"; | ||
2062 | |||
2063 | # If the iteration option OPT[$i] exists, then use that. | ||
2064 | # otherwise see if the default OPT (without [$i]) exists. | ||
2065 | |||
2066 | my $o = "$var\[$i\]"; | ||
2067 | |||
2068 | if (defined($opt{$o})) { | ||
2069 | $o = $opt{$o}; | ||
2070 | $retval = "$retval$o"; | ||
2071 | } elsif (defined($opt{$var})) { | ||
2072 | $o = $opt{$var}; | ||
2073 | $retval = "$retval$o"; | ||
2074 | } else { | ||
2075 | $retval = "$retval\$\{$var\}"; | ||
2076 | } | ||
2077 | |||
2078 | $option = $end; | ||
2079 | } | ||
2080 | |||
2081 | $retval = "$retval$option"; | ||
2082 | |||
2083 | $retval =~ s/^ //; | ||
2084 | |||
2085 | return $retval; | ||
2086 | } | ||
2087 | |||
2088 | sub set_test_option { | ||
2089 | my ($name, $i) = @_; | ||
2090 | |||
2091 | my $option = __set_test_option($name, $i); | ||
2092 | return $option if (!defined($option)); | ||
2093 | |||
2094 | my $prev = ""; | ||
2095 | |||
2096 | # Since an option can evaluate to another option, | ||
2097 | # keep iterating until we do not evaluate any more | ||
2098 | # options. | ||
2099 | my $r = 0; | ||
2100 | while ($prev ne $option) { | ||
2101 | # Check for recursive evaluations. | ||
2102 | # 100 deep should be more than enough. | ||
2103 | if ($r++ > 100) { | ||
2104 | die "Over 100 evaluations accurred with $name\n" . | ||
2105 | "Check for recursive variables\n"; | ||
2106 | } | ||
2107 | $prev = $option; | ||
2108 | $option = eval_option($option, $i); | ||
2109 | } | ||
2110 | |||
2111 | return $option; | ||
2112 | } | ||
2113 | |||
2048 | # First we need to do is the builds | 2114 | # First we need to do is the builds |
2049 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | 2115 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { |
2050 | 2116 | ||
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 761079edde6..48cbcc80602 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf | |||
@@ -133,6 +133,36 @@ | |||
133 | # the MAKE_CMD option will be evaluated by the shell when | 133 | # the MAKE_CMD option will be evaluated by the shell when |
134 | # the MAKE_CMD option is passed into shell processing. | 134 | # the MAKE_CMD option is passed into shell processing. |
135 | 135 | ||
136 | #### Using options in other options #### | ||
137 | # | ||
138 | # Options that are defined in the config file may also be used | ||
139 | # by other options. All options are evaulated at time of | ||
140 | # use (except that config variables are evaluated at config | ||
141 | # processing time). | ||
142 | # | ||
143 | # If an ktest option is used within another option, instead of | ||
144 | # typing it again in that option you can simply use the option | ||
145 | # just like you can config variables. | ||
146 | # | ||
147 | # MACHINE = mybox | ||
148 | # | ||
149 | # TEST = ssh root@${MACHINE} /path/to/test | ||
150 | # | ||
151 | # The option will be used per test case. Thus: | ||
152 | # | ||
153 | # TEST_TYPE = test | ||
154 | # TEST = ssh root@{MACHINE} | ||
155 | # | ||
156 | # TEST_START | ||
157 | # MACHINE = box1 | ||
158 | # | ||
159 | # TEST_START | ||
160 | # MACHINE = box2 | ||
161 | # | ||
162 | # For both test cases, MACHINE will be evaluated at the time | ||
163 | # of the test case. The first test will run ssh root@box1 | ||
164 | # and the second will run ssh root@box2. | ||
165 | |||
136 | #### Mandatory Default Options #### | 166 | #### Mandatory Default Options #### |
137 | 167 | ||
138 | # These options must be in the default section, although most | 168 | # These options must be in the default section, although most |