diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-10-17 11:36:44 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-10-17 11:58:18 -0400 |
commit | 8d735212e441af855afd28ccc402fcaf12999f8d (patch) | |
tree | 8a9c7213cb8684b25ad07299fe383f2030eb3fe9 /tools/testing | |
parent | a9f84424be8d12e8a84b9eac112cd1152587d437 (diff) |
ktest: Add processing of complex conditionals
The IF statements for DEFAULTS and TEST_START sections now handle
complex statements (&&,||)
Example:
TEST_START IF (DEFINED ALL_TESTS || ${MYTEST} == boottest) && ${MACHINE} == gandalf
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing')
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 53 | ||||
-rw-r--r-- | tools/testing/ktest/sample.conf | 10 |
2 files changed, 58 insertions, 5 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index d292c2d8dfe9..1bda07f6d673 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -304,7 +304,7 @@ sub get_ktest_configs { | |||
304 | } | 304 | } |
305 | 305 | ||
306 | sub process_variables { | 306 | sub process_variables { |
307 | my ($value) = @_; | 307 | my ($value, $remove_undef) = @_; |
308 | my $retval = ""; | 308 | my $retval = ""; |
309 | 309 | ||
310 | # We want to check for '\', and it is just easier | 310 | # We want to check for '\', and it is just easier |
@@ -322,6 +322,10 @@ sub process_variables { | |||
322 | $retval = "$retval$begin"; | 322 | $retval = "$retval$begin"; |
323 | if (defined($variable{$var})) { | 323 | if (defined($variable{$var})) { |
324 | $retval = "$retval$variable{$var}"; | 324 | $retval = "$retval$variable{$var}"; |
325 | } elsif (defined($remove_undef) && $remove_undef) { | ||
326 | # for if statements, any variable that is not defined, | ||
327 | # we simple convert to 0 | ||
328 | $retval = "${retval}0"; | ||
325 | } else { | 329 | } else { |
326 | # put back the origin piece. | 330 | # put back the origin piece. |
327 | $retval = "$retval\$\{$var\}"; | 331 | $retval = "$retval\$\{$var\}"; |
@@ -403,10 +407,40 @@ sub value_defined { | |||
403 | defined($opt{$2}); | 407 | defined($opt{$2}); |
404 | } | 408 | } |
405 | 409 | ||
406 | sub process_if { | 410 | my $d = 0; |
407 | my ($name, $value) = @_; | 411 | sub process_expression { |
412 | my ($name, $val) = @_; | ||
413 | |||
414 | my $c = $d++; | ||
415 | |||
416 | while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) { | ||
417 | my $express = $1; | ||
418 | |||
419 | if (process_expression($name, $express)) { | ||
420 | $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /; | ||
421 | } else { | ||
422 | $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /; | ||
423 | } | ||
424 | } | ||
425 | |||
426 | $d--; | ||
427 | my $OR = "\\|\\|"; | ||
428 | my $AND = "\\&\\&"; | ||
408 | 429 | ||
409 | my $val = process_variables($value); | 430 | while ($val =~ s/^(.*?)($OR|$AND)//) { |
431 | my $express = $1; | ||
432 | my $op = $2; | ||
433 | |||
434 | if (process_expression($name, $express)) { | ||
435 | if ($op eq "||") { | ||
436 | return 1; | ||
437 | } | ||
438 | } else { | ||
439 | if ($op eq "&&") { | ||
440 | return 0; | ||
441 | } | ||
442 | } | ||
443 | } | ||
410 | 444 | ||
411 | if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) { | 445 | if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) { |
412 | my $ret = process_compare($1, $2, $3); | 446 | my $ret = process_compare($1, $2, $3); |
@@ -431,7 +465,16 @@ sub process_if { | |||
431 | } | 465 | } |
432 | 466 | ||
433 | die ("$name: $.: Undefined content $val in if statement\n"); | 467 | die ("$name: $.: Undefined content $val in if statement\n"); |
434 | return 1; | 468 | } |
469 | |||
470 | sub process_if { | ||
471 | my ($name, $value) = @_; | ||
472 | |||
473 | # Convert variables and replace undefined ones with 0 | ||
474 | my $val = process_variables($value, 1); | ||
475 | my $ret = process_expression $name, $val; | ||
476 | |||
477 | return $ret; | ||
435 | } | 478 | } |
436 | 479 | ||
437 | sub __read_config { | 480 | sub __read_config { |
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 7b49f07b6423..dbedfa196727 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf | |||
@@ -154,6 +154,16 @@ | |||
154 | # MAKE_CMD := make ARCH=x86 | 154 | # MAKE_CMD := make ARCH=x86 |
155 | # | 155 | # |
156 | # | 156 | # |
157 | # And/or ops (&&,||) may also be used to make complex conditionals. | ||
158 | # | ||
159 | # TEST_START IF (DEFINED ALL_TESTS || ${MYTEST} == boottest) && ${MACHINE} == gandalf | ||
160 | # | ||
161 | # Notice the use of paranthesis. Without any paranthesis the above would be | ||
162 | # processed the same as: | ||
163 | # | ||
164 | # TEST_START IF DEFINED ALL_TESTS || (${MYTEST} == boottest && ${MACHINE} == gandalf) | ||
165 | # | ||
166 | # | ||
157 | # | 167 | # |
158 | # INCLUDE file | 168 | # INCLUDE file |
159 | # | 169 | # |