Skip to content

Commit 2295174

Browse files
rbmarliererostedt
authored andcommitted
ktest: Add a --dry-run mode
When working on a ktest configuration, it is often useful to inspect the final option values after includes, defaults, per-test overrides, and variable expansion have been applied, without actually starting a test run. Add a --dry-run option that reads the configuration, prints the test preamble using resolved option values, and exits before opening LOG_FILE or executing any test logic. This is useful for debugging ktest configurations and for scripts that need to validate the final resolved settings without triggering side effects. Cc: John Hawley <[email protected]> Cc: Andrea Righi <[email protected]> Cc: Marcos Paulo de Souza <[email protected]> Cc: Matthieu Baerts <[email protected]> Cc: Fernando Fernandez Mancera <[email protected]> Cc: Pedro Falcato <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Ricardo B. Marlière <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent bc6e165 commit 2295174

1 file changed

Lines changed: 63 additions & 26 deletions

File tree

tools/testing/ktest/ktest.pl

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
);
8686

8787
my $test_log_start = 0;
88+
my $dry_run = 0;
8889

8990
my $ktest_config = "ktest.conf";
9091
my $version;
@@ -587,7 +588,7 @@
587588
sub wait_for_monitor;
588589

589590
sub _logit {
590-
if (defined($opt{"LOG_FILE"})) {
591+
if (defined($opt{"LOG_FILE"}) && defined(fileno(LOG))) {
591592
print LOG @_;
592593
}
593594
}
@@ -1365,6 +1366,9 @@ sub read_config {
13651366
print "$option\n";
13661367
}
13671368
print "Set IGNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1369+
if ($dry_run) {
1370+
return;
1371+
}
13681372
if (!read_yn "Do you want to continue?") {
13691373
exit -1;
13701374
}
@@ -4249,6 +4253,53 @@ sub set_test_option {
42494253
return eval_option($name, $option, $i);
42504254
}
42514255

4256+
sub print_test_preamble {
4257+
my ($resolved) = @_;
4258+
4259+
doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
4260+
4261+
for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4262+
4263+
if (!$i) {
4264+
doprint "DEFAULT OPTIONS:\n";
4265+
} else {
4266+
doprint "\nTEST $i OPTIONS";
4267+
if (defined($repeat_tests{$i})) {
4268+
$repeat = $repeat_tests{$i};
4269+
doprint " ITERATE $repeat";
4270+
}
4271+
doprint "\n";
4272+
}
4273+
4274+
foreach my $option (sort keys %opt) {
4275+
my $value;
4276+
4277+
if ($option =~ /\[(\d+)\]$/) {
4278+
next if ($i != $1);
4279+
4280+
if ($resolved) {
4281+
my $name = $option;
4282+
$name =~ s/\[\d+\]$//;
4283+
$value = set_test_option($name, $i);
4284+
} else {
4285+
$value = $opt{$option};
4286+
}
4287+
} else {
4288+
next if ($i);
4289+
4290+
if ($resolved) {
4291+
$value = set_test_option($option, 0);
4292+
} else {
4293+
$value = $opt{$option};
4294+
}
4295+
}
4296+
4297+
$value = "" if (!defined($value));
4298+
doprint "$option = $value\n";
4299+
}
4300+
}
4301+
}
4302+
42524303
sub find_mailer {
42534304
my ($mailer) = @_;
42544305

@@ -4348,6 +4399,8 @@ sub die_usage {
43484399
Sets global BUILD_NOCLEAN to 1
43494400
-D TEST_TYPE[2]=build
43504401
Sets TEST_TYPE of test 2 to "build"
4402+
--dry-run
4403+
Print resolved test options and exit without running tests.
43514404
43524405
It can also override all temp variables.
43534406
-D USE_TEMP_DIR:=1
@@ -4379,6 +4432,9 @@ sub die_usage {
43794432
} else {
43804433
$command_vars[$#command_vars + 1] = $val;
43814434
}
4435+
} elsif ( $ARGV[0] eq "--dry-run" ) {
4436+
$dry_run = 1;
4437+
shift;
43824438
} elsif ( $ARGV[0] eq "-h" ) {
43834439
die_usage;
43844440
} else {
@@ -4427,6 +4483,11 @@ sub die_usage {
44274483
}
44284484
read_config $ktest_config;
44294485

4486+
if ($dry_run) {
4487+
print_test_preamble 1;
4488+
exit 0;
4489+
}
4490+
44304491
if (defined($opt{"LOG_FILE"})) {
44314492
$opt{"LOG_FILE"} = set_test_option("LOG_FILE", 1);
44324493
}
@@ -4458,31 +4519,7 @@ sub die_usage {
44584519
LOG->autoflush(1);
44594520
}
44604521

4461-
doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
4462-
4463-
for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4464-
4465-
if (!$i) {
4466-
doprint "DEFAULT OPTIONS:\n";
4467-
} else {
4468-
doprint "\nTEST $i OPTIONS";
4469-
if (defined($repeat_tests{$i})) {
4470-
$repeat = $repeat_tests{$i};
4471-
doprint " ITERATE $repeat";
4472-
}
4473-
doprint "\n";
4474-
}
4475-
4476-
foreach my $option (sort keys %opt) {
4477-
if ($option =~ /\[(\d+)\]$/) {
4478-
next if ($i != $1);
4479-
} else {
4480-
next if ($i);
4481-
}
4482-
4483-
doprint "$option = $opt{$option}\n";
4484-
}
4485-
}
4522+
print_test_preamble 0;
44864523

44874524
$SIG{INT} = qw(cancel_test);
44884525

0 commit comments

Comments
 (0)