Skip to content

Commit 23b772c

Browse files
committed
ktest.pl: Add -D option to override options
Add -D option that lets the user override options in the config. For instance, if the config has: BUILD_NOCLEAN=1 which prevents mrproper from being called before builds, and the user wants to call it once. The user can run: ktest -D BUILD_NOCLEAN=0 config And the default "BUILD_NOCLEAN" options will be disabled. If the user wants to change the second test to do a build and not boot, the user can run: ktest -D 'TEST_TYPE[2]=build' config Where the '[#]' is for the test to assign the variable for. In the above example, it will happen on test 2. Cc: "John Warthog9 Hawley" <[email protected]> Cc: Dhaval Giani <[email protected]> Cc: Greg KH <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt <[email protected]>
1 parent 89be9a8 commit 23b772c

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
my %repeat_tests;
2222
my %repeats;
2323
my %evals;
24+
my @command_vars;
2425

2526
#default opts
2627
my %default = (
@@ -1286,6 +1287,19 @@ sub read_config {
12861287

12871288
$test_case = __read_config $config, \$test_num;
12881289

1290+
foreach my $val (@command_vars) {
1291+
chomp $val;
1292+
my %command_overrides;
1293+
if ($val =~ m/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1294+
my $lvalue = $1;
1295+
my $rvalue = $2;
1296+
1297+
set_value($lvalue, $rvalue, 1, \%command_overrides, "COMMAND LINE");
1298+
} else {
1299+
die "Invalid option definition '$val'\n";
1300+
}
1301+
}
1302+
12891303
# make sure we have all mandatory configs
12901304
get_mandatory_configs;
12911305

@@ -4242,8 +4256,37 @@ sub cancel_test {
42424256
die "\nCaught Sig Int, test interrupted: $!\n"
42434257
}
42444258

4245-
$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
4259+
sub die_usage {
4260+
die << "EOF"
4261+
ktest.pl version: $VERSION
4262+
usage: ktest.pl [options] [config-file]
4263+
[options]:
4264+
-D value: Where value can act as an option override.
4265+
-D BUILD_NOCLEAN=1
4266+
Sets global BUILD_NOCLEAN to 1
4267+
-D TEST_TYPE[2]=build
4268+
Sets TEST_TYPE of test 2 to "build"
4269+
4270+
EOF
4271+
;
4272+
}
4273+
4274+
while ( $#ARGV >= 0 ) {
4275+
if ( $ARGV[0] eq "-D" ) {
4276+
shift;
4277+
die_usage if ($#ARGV < 1);
4278+
my $val = shift;
4279+
4280+
$command_vars[$#command_vars + 1] = $val;
4281+
4282+
} elsif ( $ARGV[0] eq "-h" ) {
4283+
die_usage;
4284+
} else {
4285+
last;
4286+
}
4287+
}
42464288

4289+
$#ARGV < 1 or die_usage;
42474290
if ($#ARGV == 0) {
42484291
$ktest_config = $ARGV[0];
42494292
if (! -f $ktest_config) {

0 commit comments

Comments
 (0)