aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/ktest/ktest.pl
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2011-05-20 13:36:58 -0400
committerSteven Rostedt <rostedt@goodmis.org>2011-05-20 15:26:26 -0400
commit77d942ceacbad02d8498ac72ed8d634634057aec (patch)
tree172a166472e0a9082358f7b9cd59e1523ca2d8e9 /tools/testing/ktest/ktest.pl
parent27d934b28752b860cba6c0d77ea4598861d80998 (diff)
ktest: Create variables for the ktest config files
I found that I constantly reuse information for each test case. It would be nice to just define a variable to reuse. For example I may have: TEST_START [...] TEST = ssh root@mybox /path/to/my/script TEST_START [...] TEST = ssh root@mybox /path/to/my/script [etc] The issue is, I may wont to change that script or one of the other fields. Then I need to update each line individually. With the addition of config variables (variables only used during parsing the config) we can simplify the config files. These variables can also be defined multiple times and each time the new value will overwrite the old value. The convention to use a config variable over a ktest option is to use := instead of =. Now we could do: USER := root TARGET := mybox TEST_SCRIPT := /path/to/my/script TEST_CASE := ${USER}@${TARGET} ${TEST_SCRIPT} TEST_START [...] TEST = ${TEST_CASE} TEST_START [...] TEST = ${TEST_CASE} [etc] Now we just need to update the variables at the top. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing/ktest/ktest.pl')
-rwxr-xr-xtools/testing/ktest/ktest.pl62
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 65003a196305..18ef66823aa6 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -114,6 +114,7 @@ my $successes = 0;
114 114
115my %entered_configs; 115my %entered_configs;
116my %config_help; 116my %config_help;
117my %variable;
117 118
118$config_help{"MACHINE"} = << "EOF" 119$config_help{"MACHINE"} = << "EOF"
119 The machine hostname that you will test. 120 The machine hostname that you will test.
@@ -262,6 +263,39 @@ sub get_ktest_configs {
262 } 263 }
263} 264}
264 265
266sub process_variables {
267 my ($value) = @_;
268 my $retval = "";
269
270 # We want to check for '\', and it is just easier
271 # to check the previous characet of '$' and not need
272 # to worry if '$' is the first character. By adding
273 # a space to $value, we can just check [^\\]\$ and
274 # it will still work.
275 $value = " $value";
276
277 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
278 my $begin = $1;
279 my $var = $2;
280 my $end = $3;
281 # append beginning of value to retval
282 $retval = "$retval$begin";
283 if (defined($variable{$var})) {
284 $retval = "$retval$variable{$var}";
285 } else {
286 # put back the origin piece.
287 $retval = "$retval\$\{$var\}";
288 }
289 $value = $end;
290 }
291 $retval = "$retval$value";
292
293 # remove the space added in the beginning
294 $retval =~ s/ //;
295
296 return "$retval"
297}
298
265sub set_value { 299sub set_value {
266 my ($lvalue, $rvalue) = @_; 300 my ($lvalue, $rvalue) = @_;
267 301
@@ -271,10 +305,22 @@ sub set_value {
271 if ($rvalue =~ /^\s*$/) { 305 if ($rvalue =~ /^\s*$/) {
272 delete $opt{$lvalue}; 306 delete $opt{$lvalue};
273 } else { 307 } else {
308 $rvalue = process_variables($rvalue);
274 $opt{$lvalue} = $rvalue; 309 $opt{$lvalue} = $rvalue;
275 } 310 }
276} 311}
277 312
313sub set_variable {
314 my ($lvalue, $rvalue) = @_;
315
316 if ($rvalue =~ /^\s*$/) {
317 delete $variable{$lvalue};
318 } else {
319 $rvalue = process_variables($rvalue);
320 $variable{$lvalue} = $rvalue;
321 }
322}
323
278sub read_config { 324sub read_config {
279 my ($config) = @_; 325 my ($config) = @_;
280 326
@@ -387,6 +433,22 @@ sub read_config {
387 $repeats{$val} = $repeat; 433 $repeats{$val} = $repeat;
388 } 434 }
389 } 435 }
436 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
437 next if ($skip);
438
439 my $lvalue = $1;
440 my $rvalue = $2;
441
442 # process config variables.
443 # Config variables are only active while reading the
444 # config and can be defined anywhere. They also ignore
445 # TEST_START and DEFAULTS, but are skipped if they are in
446 # on of these sections that have SKIP defined.
447 # The save variable can be
448 # defined multiple times and the new one simply overrides
449 # the prevous one.
450 set_variable($lvalue, $rvalue);
451
390 } else { 452 } else {
391 die "$name: $.: Garbage found in config\n$_"; 453 die "$name: $.: Garbage found in config\n$_";
392 } 454 }