Skip to content

Commit 45d73a5

Browse files
Steven Rostedtrostedt
authored andcommitted
ktest: Add IF and ELSE to config sections
Add IF keyword to sections within the config. Also added an ELSE keyword that allows different config options to be set for a given section. For example: TYPE := 1 STATUS := 0 DEFAULTS IF ${TYPE} [...] ELSE IF ${STATUS} [...] ELSE [...] The above will process the first section as $TYPE is true. If it was false, it would process the last section as $STATUS is false. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 4ab1cce commit 45d73a5

2 files changed

Lines changed: 98 additions & 4 deletions

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,21 @@ sub set_variable {
361361
}
362362
}
363363

364+
sub process_if {
365+
my ($name, $value) = @_;
366+
367+
my $val = process_variables($value);
368+
369+
if ($val =~ /^\s*0\s*$/) {
370+
return 0;
371+
} elsif ($val =~ /^\s*\d+\s*$/) {
372+
return 1;
373+
}
374+
375+
die ("$name: $.: Undefined variable $val in if statement\n");
376+
return 1;
377+
}
378+
364379
sub read_config {
365380
my ($config) = @_;
366381

@@ -376,6 +391,8 @@ sub read_config {
376391
my $skip = 0;
377392
my $rest;
378393
my $test_case = 0;
394+
my $if = 0;
395+
my $if_set = 0;
379396

380397
while (<IN>) {
381398

@@ -397,7 +414,7 @@ sub read_config {
397414
$default = 0;
398415
$repeat = 1;
399416

400-
if ($rest =~ /\s+SKIP(.*)/) {
417+
if ($rest =~ /\s+SKIP\b(.*)/) {
401418
$rest = $1;
402419
$skip = 1;
403420
} else {
@@ -411,9 +428,16 @@ sub read_config {
411428
$repeat_tests{"$test_num"} = $repeat;
412429
}
413430

414-
if ($rest =~ /\s+SKIP(.*)/) {
415-
$rest = $1;
416-
$skip = 1;
431+
if ($rest =~ /\sIF\s+(\S*)(.*)/) {
432+
$rest = $2;
433+
if (process_if($name, $1)) {
434+
$if_set = 1;
435+
} else {
436+
$skip = 1;
437+
}
438+
$if = 1;
439+
} else {
440+
$if = 0;
417441
}
418442

419443
if ($rest !~ /^\s*$/) {
@@ -437,10 +461,42 @@ sub read_config {
437461
$skip = 0;
438462
}
439463

464+
if ($rest =~ /\sIF\s+(\S*)(.*)/) {
465+
$if = 1;
466+
$rest = $2;
467+
if (process_if($name, $1)) {
468+
$if_set = 1;
469+
} else {
470+
$skip = 1;
471+
}
472+
} else {
473+
$if = 0;
474+
}
475+
440476
if ($rest !~ /^\s*$/) {
441477
die "$name: $.: Gargbage found after DEFAULTS\n$_";
442478
}
443479

480+
} elsif (/^\s*ELSE(.*)$/) {
481+
if (!$if) {
482+
die "$name: $.: ELSE found with out matching IF section\n$_";
483+
}
484+
$rest = $1;
485+
if ($if_set) {
486+
$skip = 1;
487+
} else {
488+
$skip = 0;
489+
490+
if ($rest =~ /\sIF\s+(\S*)(.*)/) {
491+
# May be a ELSE IF section.
492+
if (!process_if($name, $1)) {
493+
$skip = 1;
494+
}
495+
} else {
496+
$if = 0;
497+
}
498+
}
499+
444500
} elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
445501

446502
next if ($skip);

‎tools/testing/ktest/sample.conf‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,44 @@
7272
# the same option name under the same test or as default
7373
# ktest will fail to execute, and no tests will run.
7474
#
75+
# Both TEST_START and DEFAULTS sections can also have the IF keyword
76+
# The value after the IF must evaluate into a 0 or non 0 positive
77+
# integer, and can use the config variables (explained below).
78+
#
79+
# DEFAULTS IF ${IS_X86_32}
80+
#
81+
# The above will process the DEFAULTS section if the config
82+
# variable IS_X86_32 evaluates to a non zero positive integer
83+
# otherwise if it evaluates to zero, it will act the same
84+
# as if the SKIP keyword was used.
85+
#
86+
# The ELSE keyword can be used directly after a section with
87+
# a IF statement.
88+
#
89+
# TEST_START IF ${RUN_NET_TESTS}
90+
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
91+
#
92+
# ELSE
93+
#
94+
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-normal
95+
#
96+
#
97+
# The ELSE keyword can also contain an IF statement to allow multiple
98+
# if then else sections. But all the sections must be either
99+
# DEFAULT or TEST_START, they can not be a mixture.
100+
#
101+
# TEST_START IF ${RUN_NET_TESTS}
102+
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
103+
#
104+
# ELSE IF ${RUN_DISK_TESTS}
105+
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-tests
106+
#
107+
# ELSE IF ${RUN_CPU_TESTS}
108+
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-cpu
109+
#
110+
# ELSE
111+
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-network
112+
#
75113

76114
#### Config variables ####
77115
#

0 commit comments

Comments
 (0)