diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-02-28 02:07:59 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-02-28 02:07:59 -0500 |
commit | 1ac884f173d4842216f6a24c03c9833e3ce6e982 (patch) | |
tree | bb073cbb3e6693096cdb3b9b5ff736a1b5e3ea70 /tools | |
parent | 08e32dcc86e10db1c444942b23bd418968955842 (diff) | |
parent | 5739438b725c09938bb6af9e4477c4283b8326cf (diff) |
Merge tag 'ktest-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest
Pull ktest updates from Steven Rostedt:
"These are various fixes that I have made and never got around to
pushing. I've been asked to get the upstream repo back up-to-date"
* tag 'ktest-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest:
ktest: Add variable run_command_status to save status of commands executed
ktest.pl: Powercycle the box on reboot if no connection can be made
ktest: Add timeout to ssh command
ktest: Fix child exit code processing
ktest: Have POST_TEST run after the test has totally completed
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 111 |
1 files changed, 76 insertions, 35 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index be93ab02b490..6e4eb2fc2d1e 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -179,6 +179,7 @@ my $localversion; | |||
179 | my $iteration = 0; | 179 | my $iteration = 0; |
180 | my $successes = 0; | 180 | my $successes = 0; |
181 | my $stty_orig; | 181 | my $stty_orig; |
182 | my $run_command_status = 0; | ||
182 | 183 | ||
183 | my $bisect_good; | 184 | my $bisect_good; |
184 | my $bisect_bad; | 185 | my $bisect_bad; |
@@ -1325,26 +1326,44 @@ sub wait_for_monitor; | |||
1325 | 1326 | ||
1326 | sub reboot { | 1327 | sub reboot { |
1327 | my ($time) = @_; | 1328 | my ($time) = @_; |
1329 | my $powercycle = 0; | ||
1328 | 1330 | ||
1329 | # Make sure everything has been written to disk | 1331 | # test if the machine can be connected to within 5 seconds |
1330 | run_ssh("sync"); | 1332 | my $stat = run_ssh("echo check machine status", 5); |
1333 | if (!$stat) { | ||
1334 | doprint("power cycle\n"); | ||
1335 | $powercycle = 1; | ||
1336 | } | ||
1337 | |||
1338 | if ($powercycle) { | ||
1339 | run_command "$power_cycle"; | ||
1331 | 1340 | ||
1332 | if (defined($time)) { | ||
1333 | start_monitor; | 1341 | start_monitor; |
1334 | # flush out current monitor | 1342 | # flush out current monitor |
1335 | # May contain the reboot success line | 1343 | # May contain the reboot success line |
1336 | wait_for_monitor 1; | 1344 | wait_for_monitor 1; |
1337 | } | ||
1338 | 1345 | ||
1339 | # try to reboot normally | 1346 | } else { |
1340 | if (run_command $reboot) { | 1347 | # Make sure everything has been written to disk |
1341 | if (defined($powercycle_after_reboot)) { | 1348 | run_ssh("sync"); |
1342 | sleep $powercycle_after_reboot; | 1349 | |
1350 | if (defined($time)) { | ||
1351 | start_monitor; | ||
1352 | # flush out current monitor | ||
1353 | # May contain the reboot success line | ||
1354 | wait_for_monitor 1; | ||
1355 | } | ||
1356 | |||
1357 | # try to reboot normally | ||
1358 | if (run_command $reboot) { | ||
1359 | if (defined($powercycle_after_reboot)) { | ||
1360 | sleep $powercycle_after_reboot; | ||
1361 | run_command "$power_cycle"; | ||
1362 | } | ||
1363 | } else { | ||
1364 | # nope? power cycle it. | ||
1343 | run_command "$power_cycle"; | 1365 | run_command "$power_cycle"; |
1344 | } | 1366 | } |
1345 | } else { | ||
1346 | # nope? power cycle it. | ||
1347 | run_command "$power_cycle"; | ||
1348 | } | 1367 | } |
1349 | 1368 | ||
1350 | if (defined($time)) { | 1369 | if (defined($time)) { |
@@ -1412,6 +1431,10 @@ sub dodie { | |||
1412 | system("stty $stty_orig"); | 1431 | system("stty $stty_orig"); |
1413 | } | 1432 | } |
1414 | 1433 | ||
1434 | if (defined($post_test)) { | ||
1435 | run_command $post_test; | ||
1436 | } | ||
1437 | |||
1415 | die @_, "\n"; | 1438 | die @_, "\n"; |
1416 | } | 1439 | } |
1417 | 1440 | ||
@@ -1624,10 +1647,6 @@ sub save_logs { | |||
1624 | 1647 | ||
1625 | sub fail { | 1648 | sub fail { |
1626 | 1649 | ||
1627 | if (defined($post_test)) { | ||
1628 | run_command $post_test; | ||
1629 | } | ||
1630 | |||
1631 | if ($die_on_failure) { | 1650 | if ($die_on_failure) { |
1632 | dodie @_; | 1651 | dodie @_; |
1633 | } | 1652 | } |
@@ -1660,23 +1679,26 @@ sub fail { | |||
1660 | save_logs "fail", $store_failures; | 1679 | save_logs "fail", $store_failures; |
1661 | } | 1680 | } |
1662 | 1681 | ||
1682 | if (defined($post_test)) { | ||
1683 | run_command $post_test; | ||
1684 | } | ||
1685 | |||
1663 | return 1; | 1686 | return 1; |
1664 | } | 1687 | } |
1665 | 1688 | ||
1666 | sub run_command { | 1689 | sub run_command { |
1667 | my ($command, $redirect) = @_; | 1690 | my ($command, $redirect, $timeout) = @_; |
1668 | my $start_time; | 1691 | my $start_time; |
1669 | my $end_time; | 1692 | my $end_time; |
1670 | my $dolog = 0; | 1693 | my $dolog = 0; |
1671 | my $dord = 0; | 1694 | my $dord = 0; |
1672 | my $pid; | 1695 | my $pid; |
1673 | 1696 | ||
1674 | $start_time = time; | ||
1675 | |||
1676 | $command =~ s/\$SSH_USER/$ssh_user/g; | 1697 | $command =~ s/\$SSH_USER/$ssh_user/g; |
1677 | $command =~ s/\$MACHINE/$machine/g; | 1698 | $command =~ s/\$MACHINE/$machine/g; |
1678 | 1699 | ||
1679 | doprint("$command ... "); | 1700 | doprint("$command ... "); |
1701 | $start_time = time; | ||
1680 | 1702 | ||
1681 | $pid = open(CMD, "$command 2>&1 |") or | 1703 | $pid = open(CMD, "$command 2>&1 |") or |
1682 | (fail "unable to exec $command" and return 0); | 1704 | (fail "unable to exec $command" and return 0); |
@@ -1693,13 +1715,30 @@ sub run_command { | |||
1693 | $dord = 1; | 1715 | $dord = 1; |
1694 | } | 1716 | } |
1695 | 1717 | ||
1696 | while (<CMD>) { | 1718 | my $hit_timeout = 0; |
1697 | print LOG if ($dolog); | 1719 | |
1698 | print RD if ($dord); | 1720 | while (1) { |
1721 | my $fp = \*CMD; | ||
1722 | if (defined($timeout)) { | ||
1723 | doprint "timeout = $timeout\n"; | ||
1724 | } | ||
1725 | my $line = wait_for_input($fp, $timeout); | ||
1726 | if (!defined($line)) { | ||
1727 | my $now = time; | ||
1728 | if (defined($timeout) && (($now - $start_time) >= $timeout)) { | ||
1729 | doprint "Hit timeout of $timeout, killing process\n"; | ||
1730 | $hit_timeout = 1; | ||
1731 | kill 9, $pid; | ||
1732 | } | ||
1733 | last; | ||
1734 | } | ||
1735 | print LOG $line if ($dolog); | ||
1736 | print RD $line if ($dord); | ||
1699 | } | 1737 | } |
1700 | 1738 | ||
1701 | waitpid($pid, 0); | 1739 | waitpid($pid, 0); |
1702 | my $failed = $?; | 1740 | # shift 8 for real exit status |
1741 | $run_command_status = $? >> 8; | ||
1703 | 1742 | ||
1704 | close(CMD); | 1743 | close(CMD); |
1705 | close(LOG) if ($dolog); | 1744 | close(LOG) if ($dolog); |
@@ -1714,21 +1753,25 @@ sub run_command { | |||
1714 | doprint "[$delta seconds] "; | 1753 | doprint "[$delta seconds] "; |
1715 | } | 1754 | } |
1716 | 1755 | ||
1717 | if ($failed) { | 1756 | if ($hit_timeout) { |
1757 | $run_command_status = 1; | ||
1758 | } | ||
1759 | |||
1760 | if ($run_command_status) { | ||
1718 | doprint "FAILED!\n"; | 1761 | doprint "FAILED!\n"; |
1719 | } else { | 1762 | } else { |
1720 | doprint "SUCCESS\n"; | 1763 | doprint "SUCCESS\n"; |
1721 | } | 1764 | } |
1722 | 1765 | ||
1723 | return !$failed; | 1766 | return !$run_command_status; |
1724 | } | 1767 | } |
1725 | 1768 | ||
1726 | sub run_ssh { | 1769 | sub run_ssh { |
1727 | my ($cmd) = @_; | 1770 | my ($cmd, $timeout) = @_; |
1728 | my $cp_exec = $ssh_exec; | 1771 | my $cp_exec = $ssh_exec; |
1729 | 1772 | ||
1730 | $cp_exec =~ s/\$SSH_COMMAND/$cmd/g; | 1773 | $cp_exec =~ s/\$SSH_COMMAND/$cmd/g; |
1731 | return run_command "$cp_exec"; | 1774 | return run_command "$cp_exec", undef , $timeout; |
1732 | } | 1775 | } |
1733 | 1776 | ||
1734 | sub run_scp { | 1777 | sub run_scp { |
@@ -2489,10 +2532,6 @@ sub halt { | |||
2489 | sub success { | 2532 | sub success { |
2490 | my ($i) = @_; | 2533 | my ($i) = @_; |
2491 | 2534 | ||
2492 | if (defined($post_test)) { | ||
2493 | run_command $post_test; | ||
2494 | } | ||
2495 | |||
2496 | $successes++; | 2535 | $successes++; |
2497 | 2536 | ||
2498 | my $name = ""; | 2537 | my $name = ""; |
@@ -2517,6 +2556,10 @@ sub success { | |||
2517 | doprint "Reboot and wait $sleep_time seconds\n"; | 2556 | doprint "Reboot and wait $sleep_time seconds\n"; |
2518 | reboot_to_good $sleep_time; | 2557 | reboot_to_good $sleep_time; |
2519 | } | 2558 | } |
2559 | |||
2560 | if (defined($post_test)) { | ||
2561 | run_command $post_test; | ||
2562 | } | ||
2520 | } | 2563 | } |
2521 | 2564 | ||
2522 | sub answer_bisect { | 2565 | sub answer_bisect { |
@@ -2537,16 +2580,15 @@ sub answer_bisect { | |||
2537 | } | 2580 | } |
2538 | 2581 | ||
2539 | sub child_run_test { | 2582 | sub child_run_test { |
2540 | my $failed = 0; | ||
2541 | 2583 | ||
2542 | # child should have no power | 2584 | # child should have no power |
2543 | $reboot_on_error = 0; | 2585 | $reboot_on_error = 0; |
2544 | $poweroff_on_error = 0; | 2586 | $poweroff_on_error = 0; |
2545 | $die_on_failure = 1; | 2587 | $die_on_failure = 1; |
2546 | 2588 | ||
2547 | run_command $run_test, $testlog or $failed = 1; | 2589 | run_command $run_test, $testlog; |
2548 | 2590 | ||
2549 | exit $failed; | 2591 | exit $run_command_status; |
2550 | } | 2592 | } |
2551 | 2593 | ||
2552 | my $child_done; | 2594 | my $child_done; |
@@ -2629,7 +2671,7 @@ sub do_run_test { | |||
2629 | } | 2671 | } |
2630 | 2672 | ||
2631 | waitpid $child_pid, 0; | 2673 | waitpid $child_pid, 0; |
2632 | $child_exit = $?; | 2674 | $child_exit = $? >> 8; |
2633 | 2675 | ||
2634 | my $end_time = time; | 2676 | my $end_time = time; |
2635 | $test_time = $end_time - $start_time; | 2677 | $test_time = $end_time - $start_time; |
@@ -3330,7 +3372,6 @@ sub config_bisect { | |||
3330 | save_config \%good_configs, $good_config; | 3372 | save_config \%good_configs, $good_config; |
3331 | save_config \%bad_configs, $bad_config; | 3373 | save_config \%bad_configs, $bad_config; |
3332 | 3374 | ||
3333 | |||
3334 | if (defined($config_bisect_check) && $config_bisect_check ne "0") { | 3375 | if (defined($config_bisect_check) && $config_bisect_check ne "0") { |
3335 | if ($config_bisect_check ne "good") { | 3376 | if ($config_bisect_check ne "good") { |
3336 | doprint "Testing bad config\n"; | 3377 | doprint "Testing bad config\n"; |