Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 247941
b: refs/heads/master
c: 77d942c
h: refs/heads/master
i:
  247939: 81272fe
v: v3
  • Loading branch information
Steven Rostedt authored and Steven Rostedt committed May 20, 2011
1 parent 101d34a commit fdecb0c
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 27d934b28752b860cba6c0d77ea4598861d80998
refs/heads/master: 77d942ceacbad02d8498ac72ed8d634634057aec
62 changes: 62 additions & 0 deletions trunk/tools/testing/ktest/ktest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@

my %entered_configs;
my %config_help;
my %variable;

$config_help{"MACHINE"} = << "EOF"
The machine hostname that you will test.
Expand Down Expand Up @@ -262,6 +263,39 @@ sub get_ktest_configs {
}
}

sub process_variables {
my ($value) = @_;
my $retval = "";

# We want to check for '\', and it is just easier
# to check the previous characet of '$' and not need
# to worry if '$' is the first character. By adding
# a space to $value, we can just check [^\\]\$ and
# it will still work.
$value = " $value";

while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
my $begin = $1;
my $var = $2;
my $end = $3;
# append beginning of value to retval
$retval = "$retval$begin";
if (defined($variable{$var})) {
$retval = "$retval$variable{$var}";
} else {
# put back the origin piece.
$retval = "$retval\$\{$var\}";
}
$value = $end;
}
$retval = "$retval$value";

# remove the space added in the beginning
$retval =~ s/ //;

return "$retval"
}

sub set_value {
my ($lvalue, $rvalue) = @_;

Expand All @@ -271,10 +305,22 @@ sub set_value {
if ($rvalue =~ /^\s*$/) {
delete $opt{$lvalue};
} else {
$rvalue = process_variables($rvalue);
$opt{$lvalue} = $rvalue;
}
}

sub set_variable {
my ($lvalue, $rvalue) = @_;

if ($rvalue =~ /^\s*$/) {
delete $variable{$lvalue};
} else {
$rvalue = process_variables($rvalue);
$variable{$lvalue} = $rvalue;
}
}

sub read_config {
my ($config) = @_;

Expand Down Expand Up @@ -387,6 +433,22 @@ sub read_config {
$repeats{$val} = $repeat;
}
}
} elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
next if ($skip);

my $lvalue = $1;
my $rvalue = $2;

# process config variables.
# Config variables are only active while reading the
# config and can be defined anywhere. They also ignore
# TEST_START and DEFAULTS, but are skipped if they are in
# on of these sections that have SKIP defined.
# The save variable can be
# defined multiple times and the new one simply overrides
# the prevous one.
set_variable($lvalue, $rvalue);

} else {
die "$name: $.: Garbage found in config\n$_";
}
Expand Down
59 changes: 59 additions & 0 deletions trunk/tools/testing/ktest/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,65 @@
# ktest will fail to execute, and no tests will run.
#

#### Config variables ####
#
# This config file can also contain "config variables".
# These are assigned with ":=" instead of the ktest option
# assigment "=".
#
# The difference between ktest options and config variables
# is that config variables can be used multiple times,
# where each instance will override the previous instance.
# And that they only live at time of processing this config.
#
# The advantage to config variables are that they can be used
# by any option or any other config variables to define thing
# that you may use over and over again in the options.
#
# For example:
#
# USER := root
# TARGET := mybox
# TEST_CASE := ssh ${USER}@${TARGET} /path/to/my/test
#
# TEST_START
# MIN_CONFIG = config1
# TEST = ${TEST_CASE}
#
# TEST_START
# MIN_CONFIG = config2
# TEST = ${TEST_CASE}
#
# TEST_CASE := ssh ${USER}@${TARGET} /path/to/my/test2
#
# TEST_START
# MIN_CONFIG = config1
# TEST = ${TEST_CASE}
#
# TEST_START
# MIN_CONFIG = config2
# TEST = ${TEST_CASE}
#
# TEST_DIR := /home/me/test
#
# BUILD_DIR = ${TEST_DIR}/linux.git
# OUTPUT_DIR = ${TEST_DIR}/test
#
# Note, the config variables are evaluated immediately, thus
# updating TARGET after TEST_CASE has been assigned does nothing
# to TEST_CASE.
#
# As shown in the example, to evaluate a config variable, you
# use the ${X} convention. Simple $X will not work.
#
# If the config variable does not exist, the ${X} will not
# be evaluated. Thus:
#
# MAKE_CMD = PATH=/mypath:${PATH} make
#
# If PATH is not a config variable, then the ${PATH} in
# the MAKE_CMD option will be evaluated by the shell when
# the MAKE_CMD option is passed into shell processing.

#### Mandatory Default Options ####

Expand Down

0 comments on commit fdecb0c

Please sign in to comment.