Skip to content

Commit 2a62512

Browse files
Steven Rostedtrostedt
authored andcommitted
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>
1 parent 77d942c commit 2a62512

2 files changed

Lines changed: 97 additions & 1 deletion

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ sub patchcheck {
20192019
}
20202020
}
20212021

2022-
sub set_test_option {
2022+
sub __set_test_option {
20232023
my ($name, $i) = @_;
20242024

20252025
my $option = "$name\[$i\]";
@@ -2045,6 +2045,72 @@ sub set_test_option {
20452045
return undef;
20462046
}
20472047

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+
20482114
# First we need to do is the builds
20492115
for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
20502116

‎tools/testing/ktest/sample.conf‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,36 @@
133133
# the MAKE_CMD option will be evaluated by the shell when
134134
# the MAKE_CMD option is passed into shell processing.
135135

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+
136166
#### Mandatory Default Options ####
137167

138168
# These options must be in the default section, although most

0 commit comments

Comments
 (0)