Skip to content

Commit 8d73521

Browse files
Steven Rostedtrostedt
authored andcommitted
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>
1 parent a9f8442 commit 8d73521

2 files changed

Lines changed: 58 additions & 5 deletions

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ sub get_ktest_configs {
304304
}
305305

306306
sub process_variables {
307-
my ($value) = @_;
307+
my ($value, $remove_undef) = @_;
308308
my $retval = "";
309309

310310
# We want to check for '\', and it is just easier
@@ -322,6 +322,10 @@ sub process_variables {
322322
$retval = "$retval$begin";
323323
if (defined($variable{$var})) {
324324
$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";
325329
} else {
326330
# put back the origin piece.
327331
$retval = "$retval\$\{$var\}";
@@ -403,10 +407,40 @@ sub value_defined {
403407
defined($opt{$2});
404408
}
405409

406-
sub process_if {
407-
my ($name, $value) = @_;
410+
my $d = 0;
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 = "\\&\\&";
408429

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+
}
410444

411445
if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
412446
my $ret = process_compare($1, $2, $3);
@@ -431,7 +465,16 @@ sub process_if {
431465
}
432466

433467
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;
435478
}
436479

437480
sub __read_config {

‎tools/testing/ktest/sample.conf‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@
154154
# MAKE_CMD := make ARCH=x86
155155
#
156156
#
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+
#
157167
#
158168
# INCLUDE file
159169
#

0 commit comments

Comments
 (0)