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.

Merge tag 'ktest-v7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest

Pull ktest updates from Steven Rostedt:

- Fix undef warning when WARNINGS_FILE is unset

The check_buildlog() references WARNINGS_FILE even when it's not set.
Perl triggers a warning in this case. Check if the WARNINGS_FILE is
defined before checking if the file it represents exists.

- Fix how LOG_FILE is resolved

LOG_FILE is expanded immediately after the config file is parsed. If
LOG_FILE depends on variables from the tests it will use stale values
instead of using the test variables. Have LOG_FILE also resolve test
variables.

- Treat a undefined self reference variable as empty

Variables can recursively include itself for appending. Currently, if
the references itself and it is not defined, it leaves the variable
in the define: "VAR = ${VAR} foo" keeps the ${VAR} around. Have it
removed instead.

- Fix clearing of variables per tests

If a variable has a defined default, a test can not clear it by
assigning the variable to empty. Fix this by clearing the variable
for a test when the test config has that variable assigned to
nothing.

- Fix run_command() to catch stderr in the shell command parsing

Switch to Perl list form open to use "sh -c" wrapper to run shell
commands to have the log file catch shell parsing errors.

- Fix console output during reboot cycle

The POWER_CYCLE callback during reboot() can miss output from the
next boot making ktest miss the boot string it was waiting for.

- Add PRE_KTEST_DIE for PRE_KTEST failures

If the command for PRE_KTEST fails, ktest does not fail (this was by
design as this command was used to add patches that may or may not
apply). Add PRE_KTEST_DIE value to force ktest to fail if PRE_KTEST
fails.

- Run POST_KTEST hooks on failure and cancellation

PRE_KTEST always runs before a ktest test, have POST_KTEST always run
after a test even if the test fails or is cancelled to do the
teardown of PRE_KTEST.

- Add a --dry-run mode

Add --dry-run to parse the config, print the results and exit without
running any of the tests.

- Store failures from the dodie() path as well

The STORE_FAILURES saves the logs on failure, but there's failure
paths that miss storing. Perform STORE_FAILURES in dodie() to capture
these failures too.

* tag 'ktest-v7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest:
ktest: Store failure logs also in fatal paths
ktest: Add a --dry-run mode
ktest: Run POST_KTEST hooks on failure and cancellation
ktest: Add PRE_KTEST_DIE for PRE_KTEST failures
ktest: Stop dropping console output during power-cycle reboot
ktest: Run commands through list-form shell open
ktest: Honor empty per-test option overrides
ktest: Treat undefined self-reference as empty
ktest: Resolve LOG_FILE in test option context
ktest: Avoid undef warning when WARNINGS_FILE is unset

+127 -42
+121 -42
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; ··· 101 100 my $build_type; 102 101 my $build_options; 103 102 my $final_post_ktest; 103 + my $post_ktest_done = 0; 104 104 my $pre_ktest; 105 + my $pre_ktest_die; 105 106 my $post_ktest; 106 107 my $pre_test; 107 108 my $pre_test_die; ··· 286 283 "BUILD_DIR" => \$builddir, 287 284 "TEST_TYPE" => \$test_type, 288 285 "PRE_KTEST" => \$pre_ktest, 286 + "PRE_KTEST_DIE" => \$pre_ktest_die, 289 287 "POST_KTEST" => \$post_ktest, 290 288 "PRE_TEST" => \$pre_test, 291 289 "PRE_TEST_DIE" => \$pre_test_die, ··· 588 584 sub wait_for_monitor; 589 585 590 586 sub _logit { 591 - if (defined($opt{"LOG_FILE"})) { 587 + if (defined($opt{"LOG_FILE"}) && defined(fileno(LOG))) { 592 588 print LOG @_; 593 589 } 594 590 } ··· 914 910 if (defined($command_tmp_vars{$lvalue})) { 915 911 return; 916 912 } 913 + 914 + # If a variable is undefined, treat an unescaped self-reference as empty. 915 + if (!defined($variable{$lvalue})) { 916 + $rvalue =~ s/(?<!\\)\$\{\Q$lvalue\E\}//g; 917 + $rvalue =~ s/^\s+//; 918 + $rvalue =~ s/\s+$//; 919 + } 920 + 917 921 if ($rvalue =~ /^\s*$/) { 918 922 delete $variable{$lvalue}; 919 923 } else { ··· 1366 1354 print "$option\n"; 1367 1355 } 1368 1356 print "Set IGNORE_UNUSED = 1 to have ktest ignore unused variables\n"; 1357 + if ($dry_run) { 1358 + return; 1359 + } 1369 1360 if (!read_yn "Do you want to continue?") { 1370 1361 exit -1; 1371 1362 } ··· 1506 1491 } 1507 1492 1508 1493 if ($powercycle) { 1509 - run_command "$power_cycle"; 1510 - 1511 1494 start_monitor; 1512 - # flush out current monitor 1513 - # May contain the reboot success line 1514 - wait_for_monitor 1; 1495 + if (defined($time)) { 1496 + # Flush stale console output from the old kernel before power-cycling. 1497 + wait_for_monitor 1; 1498 + } 1499 + 1500 + run_command "$power_cycle"; 1515 1501 1516 1502 } else { 1517 1503 # Make sure everything has been written to disk ··· 1591 1575 return $name; 1592 1576 } 1593 1577 1578 + sub run_post_ktest { 1579 + my $cmd; 1580 + 1581 + return if ($post_ktest_done); 1582 + 1583 + if (defined($final_post_ktest)) { 1584 + $cmd = $final_post_ktest; 1585 + } elsif (defined($post_ktest)) { 1586 + $cmd = $post_ktest; 1587 + } else { 1588 + return; 1589 + } 1590 + 1591 + my $cp_post_ktest = eval_kernel_version($cmd); 1592 + run_command $cp_post_ktest; 1593 + $post_ktest_done = 1; 1594 + } 1595 + 1594 1596 sub dodie { 1595 1597 # avoid recursion 1596 1598 return if ($in_die); ··· 1633 1599 1634 1600 if (defined($opt{"LOG_FILE"})) { 1635 1601 print " See $opt{LOG_FILE} for more info.\n"; 1602 + } 1603 + 1604 + # Fatal paths bypass fail(), so STORE_FAILURES needs to be handled here. 1605 + if (defined($store_failures)) { 1606 + save_logs("fail", $store_failures); 1636 1607 } 1637 1608 1638 1609 if ($email_on_error) { ··· 1673 1634 if (defined($post_test)) { 1674 1635 run_command $post_test; 1675 1636 } 1637 + run_post_ktest; 1676 1638 1677 1639 die @_, "\n"; 1678 1640 } ··· 1953 1913 doprint("$command ... "); 1954 1914 $start_time = time; 1955 1915 1956 - $pid = open(CMD, "$command 2>&1 |") or 1916 + $pid = open(CMD, "-|", 1917 + "sh", "-c", 1918 + 'command=$1; shift; exec 2>&1; eval "$command"', 1919 + "sh", $command) or 1957 1920 (fail "unable to exec $command" and return 0); 1958 1921 1959 1922 if (defined($opt{"LOG_FILE"})) { ··· 2551 2508 my $save_no_reboot = $no_reboot; 2552 2509 $no_reboot = 1; 2553 2510 2554 - if (-f $warnings_file) { 2511 + if (defined($warnings_file) && -f $warnings_file) { 2555 2512 open(IN, $warnings_file) or 2556 2513 dodie "Error opening $warnings_file"; 2557 2514 ··· 4226 4183 4227 4184 my $option = "$name\[$i\]"; 4228 4185 4229 - if (option_defined($option)) { 4186 + if (exists($opt{$option})) { 4187 + return undef if (!option_defined($option)); 4230 4188 return $opt{$option}; 4231 4189 } 4232 4190 ··· 4235 4191 if ($i >= $test && 4236 4192 $i < $test + $repeat_tests{$test}) { 4237 4193 $option = "$name\[$test\]"; 4238 - if (option_defined($option)) { 4194 + if (exists($opt{$option})) { 4195 + return undef if (!option_defined($option)); 4239 4196 return $opt{$option}; 4240 4197 } 4241 4198 } ··· 4256 4211 return $option if (!defined($option)); 4257 4212 4258 4213 return eval_option($name, $option, $i); 4214 + } 4215 + 4216 + sub print_test_preamble { 4217 + my ($resolved) = @_; 4218 + 4219 + doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; 4220 + 4221 + for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { 4222 + 4223 + if (!$i) { 4224 + doprint "DEFAULT OPTIONS:\n"; 4225 + } else { 4226 + doprint "\nTEST $i OPTIONS"; 4227 + if (defined($repeat_tests{$i})) { 4228 + $repeat = $repeat_tests{$i}; 4229 + doprint " ITERATE $repeat"; 4230 + } 4231 + doprint "\n"; 4232 + } 4233 + 4234 + foreach my $option (sort keys %opt) { 4235 + my $value; 4236 + 4237 + if ($option =~ /\[(\d+)\]$/) { 4238 + next if ($i != $1); 4239 + 4240 + if ($resolved) { 4241 + my $name = $option; 4242 + $name =~ s/\[\d+\]$//; 4243 + $value = set_test_option($name, $i); 4244 + } else { 4245 + $value = $opt{$option}; 4246 + } 4247 + } else { 4248 + next if ($i); 4249 + 4250 + if ($resolved) { 4251 + $value = set_test_option($option, 0); 4252 + } else { 4253 + $value = $opt{$option}; 4254 + } 4255 + } 4256 + 4257 + $value = "" if (!defined($value)); 4258 + doprint "$option = $value\n"; 4259 + } 4260 + } 4259 4261 } 4260 4262 4261 4263 sub find_mailer { ··· 4390 4298 send_email("KTEST: Your [$name] test was cancelled", 4391 4299 "Your test started at $script_start_time was cancelled: sig int"); 4392 4300 } 4301 + run_post_ktest; 4393 4302 die "\nCaught Sig Int, test interrupted: $!\n" 4394 4303 } 4395 4304 ··· 4404 4311 Sets global BUILD_NOCLEAN to 1 4405 4312 -D TEST_TYPE[2]=build 4406 4313 Sets TEST_TYPE of test 2 to "build" 4314 + --dry-run 4315 + Print resolved test options and exit without running tests. 4407 4316 4408 4317 It can also override all temp variables. 4409 4318 -D USE_TEMP_DIR:=1 ··· 4437 4342 } else { 4438 4343 $command_vars[$#command_vars + 1] = $val; 4439 4344 } 4345 + } elsif ( $ARGV[0] eq "--dry-run" ) { 4346 + $dry_run = 1; 4347 + shift; 4440 4348 } elsif ( $ARGV[0] eq "-h" ) { 4441 4349 die_usage; 4442 4350 } else { ··· 4488 4390 } 4489 4391 read_config $ktest_config; 4490 4392 4393 + if ($dry_run) { 4394 + print_test_preamble 1; 4395 + exit 0; 4396 + } 4397 + 4491 4398 if (defined($opt{"LOG_FILE"})) { 4492 - $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1); 4399 + $opt{"LOG_FILE"} = set_test_option("LOG_FILE", 1); 4493 4400 } 4494 4401 4495 4402 # Append any configs entered in manually to the config file. ··· 4524 4421 LOG->autoflush(1); 4525 4422 } 4526 4423 4527 - doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; 4528 - 4529 - for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { 4530 - 4531 - if (!$i) { 4532 - doprint "DEFAULT OPTIONS:\n"; 4533 - } else { 4534 - doprint "\nTEST $i OPTIONS"; 4535 - if (defined($repeat_tests{$i})) { 4536 - $repeat = $repeat_tests{$i}; 4537 - doprint " ITERATE $repeat"; 4538 - } 4539 - doprint "\n"; 4540 - } 4541 - 4542 - foreach my $option (sort keys %opt) { 4543 - if ($option =~ /\[(\d+)\]$/) { 4544 - next if ($i != $1); 4545 - } else { 4546 - next if ($i); 4547 - } 4548 - 4549 - doprint "$option = $opt{$option}\n"; 4550 - } 4551 - } 4424 + print_test_preamble 0; 4552 4425 4553 4426 $SIG{INT} = qw(cancel_test); 4554 4427 ··· 4571 4492 if ($i == 1) { 4572 4493 if (defined($pre_ktest)) { 4573 4494 doprint "\n"; 4574 - run_command $pre_ktest; 4495 + my $ret = run_command $pre_ktest; 4496 + if (!$ret && defined($pre_ktest_die) && 4497 + $pre_ktest_die) { 4498 + dodie "failed to pre_ktest\n"; 4499 + } 4575 4500 } 4576 4501 if ($email_when_started) { 4577 4502 my $name = get_test_name; ··· 4742 4659 success $i; 4743 4660 } 4744 4661 4745 - if (defined($final_post_ktest)) { 4746 - 4747 - my $cp_final_post_ktest = eval_kernel_version $final_post_ktest; 4748 - run_command $cp_final_post_ktest; 4749 - } 4662 + run_post_ktest; 4750 4663 4751 4664 if ($opt{"POWEROFF_ON_SUCCESS"}) { 4752 4665 halt;
+6
tools/testing/ktest/sample.conf
··· 494 494 # 495 495 # default (undefined) 496 496 #PRE_KTEST = ${SSH} ~/set_up_test 497 + # 498 + # To specify if the test should fail if PRE_KTEST fails, 499 + # PRE_KTEST_DIE needs to be set to 1. Otherwise the PRE_KTEST 500 + # result is ignored. 501 + # (default 0) 502 + #PRE_KTEST_DIE = 1 497 503 498 504 # If you want to execute some command after all the tests have 499 505 # completed, you can set this option. Note, it can be set as a