Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <warthog9@eaglescrag.net>
Cc: Andrea Righi <arighi@nvidia.com>
Cc: Marcos Paulo de Souza <mpdesouza@suse.com>
Cc: Matthieu Baerts <matttbe@kernel.org>
Cc: Fernando Fernandez Mancera <fmancera@suse.de>
Cc: Pedro Falcato <pfalcato@suse.de>
Link: https://patch.msgid.link/20260307-ktest-fixes-v1-9-565d412f4925@suse.com
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

authored by

Ricardo B. Marlière and committed by
Steven Rostedt
22951744 bc6e165a

+63 -26
+63 -26
tools/testing/ktest/ktest.pl
··· 85 85 ); 86 86 87 87 my $test_log_start = 0; 88 + my $dry_run = 0; 88 89 89 90 my $ktest_config = "ktest.conf"; 90 91 my $version; ··· 588 587 sub wait_for_monitor; 589 588 590 589 sub _logit { 591 - if (defined($opt{"LOG_FILE"})) { 590 + if (defined($opt{"LOG_FILE"}) && defined(fileno(LOG))) { 592 591 print LOG @_; 593 592 } 594 593 } ··· 1366 1365 print "$option\n"; 1367 1366 } 1368 1367 print "Set IGNORE_UNUSED = 1 to have ktest ignore unused variables\n"; 1368 + if ($dry_run) { 1369 + return; 1370 + } 1369 1371 if (!read_yn "Do you want to continue?") { 1370 1372 exit -1; 1371 1373 } ··· 4253 4249 return eval_option($name, $option, $i); 4254 4250 } 4255 4251 4252 + sub print_test_preamble { 4253 + my ($resolved) = @_; 4254 + 4255 + doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; 4256 + 4257 + for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { 4258 + 4259 + if (!$i) { 4260 + doprint "DEFAULT OPTIONS:\n"; 4261 + } else { 4262 + doprint "\nTEST $i OPTIONS"; 4263 + if (defined($repeat_tests{$i})) { 4264 + $repeat = $repeat_tests{$i}; 4265 + doprint " ITERATE $repeat"; 4266 + } 4267 + doprint "\n"; 4268 + } 4269 + 4270 + foreach my $option (sort keys %opt) { 4271 + my $value; 4272 + 4273 + if ($option =~ /\[(\d+)\]$/) { 4274 + next if ($i != $1); 4275 + 4276 + if ($resolved) { 4277 + my $name = $option; 4278 + $name =~ s/\[\d+\]$//; 4279 + $value = set_test_option($name, $i); 4280 + } else { 4281 + $value = $opt{$option}; 4282 + } 4283 + } else { 4284 + next if ($i); 4285 + 4286 + if ($resolved) { 4287 + $value = set_test_option($option, 0); 4288 + } else { 4289 + $value = $opt{$option}; 4290 + } 4291 + } 4292 + 4293 + $value = "" if (!defined($value)); 4294 + doprint "$option = $value\n"; 4295 + } 4296 + } 4297 + } 4298 + 4256 4299 sub find_mailer { 4257 4300 my ($mailer) = @_; 4258 4301 ··· 4399 4348 Sets global BUILD_NOCLEAN to 1 4400 4349 -D TEST_TYPE[2]=build 4401 4350 Sets TEST_TYPE of test 2 to "build" 4351 + --dry-run 4352 + Print resolved test options and exit without running tests. 4402 4353 4403 4354 It can also override all temp variables. 4404 4355 -D USE_TEMP_DIR:=1 ··· 4432 4379 } else { 4433 4380 $command_vars[$#command_vars + 1] = $val; 4434 4381 } 4382 + } elsif ( $ARGV[0] eq "--dry-run" ) { 4383 + $dry_run = 1; 4384 + shift; 4435 4385 } elsif ( $ARGV[0] eq "-h" ) { 4436 4386 die_usage; 4437 4387 } else { ··· 4483 4427 } 4484 4428 read_config $ktest_config; 4485 4429 4430 + if ($dry_run) { 4431 + print_test_preamble 1; 4432 + exit 0; 4433 + } 4434 + 4486 4435 if (defined($opt{"LOG_FILE"})) { 4487 4436 $opt{"LOG_FILE"} = set_test_option("LOG_FILE", 1); 4488 4437 } ··· 4519 4458 LOG->autoflush(1); 4520 4459 } 4521 4460 4522 - doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; 4523 - 4524 - for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { 4525 - 4526 - if (!$i) { 4527 - doprint "DEFAULT OPTIONS:\n"; 4528 - } else { 4529 - doprint "\nTEST $i OPTIONS"; 4530 - if (defined($repeat_tests{$i})) { 4531 - $repeat = $repeat_tests{$i}; 4532 - doprint " ITERATE $repeat"; 4533 - } 4534 - doprint "\n"; 4535 - } 4536 - 4537 - foreach my $option (sort keys %opt) { 4538 - if ($option =~ /\[(\d+)\]$/) { 4539 - next if ($i != $1); 4540 - } else { 4541 - next if ($i); 4542 - } 4543 - 4544 - doprint "$option = $opt{$option}\n"; 4545 - } 4546 - } 4461 + print_test_preamble 0; 4547 4462 4548 4463 $SIG{INT} = qw(cancel_test); 4549 4464