Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 247942
b: refs/heads/master
c: 2a62512
h: refs/heads/master
v: v3
  • Loading branch information
Steven Rostedt authored and Steven Rostedt committed May 20, 2011
1 parent fdecb0c commit 96c5384
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 77d942ceacbad02d8498ac72ed8d634634057aec
refs/heads/master: 2a62512bceb44ad45f78aa7ca0e9cfaee9eae46f
68 changes: 67 additions & 1 deletion trunk/tools/testing/ktest/ktest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ sub patchcheck {
}
}

sub set_test_option {
sub __set_test_option {
my ($name, $i) = @_;

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

sub eval_option {
my ($option, $i) = @_;

# Add space to evaluate the character before $
$option = " $option";
my $retval = "";

while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
my $start = $1;
my $var = $2;
my $end = $3;

# Append beginning of line
$retval = "$retval$start";

# If the iteration option OPT[$i] exists, then use that.
# otherwise see if the default OPT (without [$i]) exists.

my $o = "$var\[$i\]";

if (defined($opt{$o})) {
$o = $opt{$o};
$retval = "$retval$o";
} elsif (defined($opt{$var})) {
$o = $opt{$var};
$retval = "$retval$o";
} else {
$retval = "$retval\$\{$var\}";
}

$option = $end;
}

$retval = "$retval$option";

$retval =~ s/^ //;

return $retval;
}

sub set_test_option {
my ($name, $i) = @_;

my $option = __set_test_option($name, $i);
return $option if (!defined($option));

my $prev = "";

# Since an option can evaluate to another option,
# keep iterating until we do not evaluate any more
# options.
my $r = 0;
while ($prev ne $option) {
# Check for recursive evaluations.
# 100 deep should be more than enough.
if ($r++ > 100) {
die "Over 100 evaluations accurred with $name\n" .
"Check for recursive variables\n";
}
$prev = $option;
$option = eval_option($option, $i);
}

return $option;
}

# First we need to do is the builds
for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {

Expand Down
30 changes: 30 additions & 0 deletions trunk/tools/testing/ktest/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,36 @@
# the MAKE_CMD option will be evaluated by the shell when
# the MAKE_CMD option is passed into shell processing.

#### Using options in other options ####
#
# Options that are defined in the config file may also be used
# by other options. All options are evaulated at time of
# use (except that config variables are evaluated at config
# processing time).
#
# If an ktest option is used within another option, instead of
# typing it again in that option you can simply use the option
# just like you can config variables.
#
# MACHINE = mybox
#
# TEST = ssh root@${MACHINE} /path/to/test
#
# The option will be used per test case. Thus:
#
# TEST_TYPE = test
# TEST = ssh root@{MACHINE}
#
# TEST_START
# MACHINE = box1
#
# TEST_START
# MACHINE = box2
#
# For both test cases, MACHINE will be evaluated at the time
# of the test case. The first test will run ssh root@box1
# and the second will run ssh root@box2.

#### Mandatory Default Options ####

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

0 comments on commit 96c5384

Please sign in to comment.