提交 576f627c 编写于 作者: S Steven Rostedt 提交者: Steven Rostedt

ktest: Add poweroff after halt and powercycle after reboot

Added the options POWEROFF_AFTER_HALT to handle boxes that do not
really shut off after a halt is called.

Added POWERCYCLE_AFTER_REBOOT to force a power cycle for boxes that
don't reboot but get stuck during the reboot.
Signed-off-by: NSteven Rostedt <rostedt@goodmis.org>
上级 8b37ca8c
...@@ -53,6 +53,8 @@ my $power_cycle; ...@@ -53,6 +53,8 @@ my $power_cycle;
my $reboot_on_error; my $reboot_on_error;
my $poweroff_on_error; my $poweroff_on_error;
my $die_on_failure; my $die_on_failure;
my $powercycle_after_reboot;
my $poweroff_after_halt;
my $power_off; my $power_off;
my $grub_menu; my $grub_menu;
my $grub_number; my $grub_number;
...@@ -83,6 +85,7 @@ my $success_line; ...@@ -83,6 +85,7 @@ my $success_line;
my $build_target; my $build_target;
my $target_image; my $target_image;
my $localversion; my $localversion;
my $iteration = 0;
sub read_config { sub read_config {
my ($config) = @_; my ($config) = @_;
...@@ -133,16 +136,32 @@ sub run_command; ...@@ -133,16 +136,32 @@ sub run_command;
sub reboot { sub reboot {
# try to reboot normally # try to reboot normally
if (!run_command "ssh $target reboot") { if (run_command "ssh $target reboot") {
if (defined($powercycle_after_reboot)) {
sleep $powercycle_after_reboot;
run_command "$power_cycle";
}
} else {
# nope? power cycle it. # nope? power cycle it.
run_command "$power_cycle"; run_command "$power_cycle";
} }
} }
sub do_not_reboot {
my $i = $iteration;
return $test_type eq "build" ||
($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
}
sub dodie { sub dodie {
doprint "CRITICAL FAILURE... ", @_, "\n"; doprint "CRITICAL FAILURE... ", @_, "\n";
if ($reboot_on_error && $test_type ne "build") { my $i = $iteration;
if ($reboot_on_error && !do_not_reboot) {
doprint "REBOOTING\n"; doprint "REBOOTING\n";
reboot; reboot;
...@@ -151,7 +170,7 @@ sub dodie { ...@@ -151,7 +170,7 @@ sub dodie {
`$power_off`; `$power_off`;
} }
die @_; die @_, "\n";
} }
sub open_console { sub open_console {
...@@ -163,9 +182,9 @@ sub open_console { ...@@ -163,9 +182,9 @@ sub open_console {
dodie "Can't open console $console"; dodie "Can't open console $console";
$flags = fcntl($fp, F_GETFL, 0) or $flags = fcntl($fp, F_GETFL, 0) or
dodie "Can't get flags for the socket: $!\n"; dodie "Can't get flags for the socket: $!";
$flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
dodie "Can't set flags for the socket: $!\n"; dodie "Can't set flags for the socket: $!";
return $pid; return $pid;
} }
...@@ -221,8 +240,10 @@ sub fail { ...@@ -221,8 +240,10 @@ sub fail {
doprint "FAILED\n"; doprint "FAILED\n";
my $i = $iteration;
# no need to reboot for just building. # no need to reboot for just building.
if ($test_type ne "build") { if (!do_not_reboot) {
doprint "REBOOTING\n"; doprint "REBOOTING\n";
reboot; reboot;
start_monitor; start_monitor;
...@@ -230,7 +251,11 @@ sub fail { ...@@ -230,7 +251,11 @@ sub fail {
end_monitor; end_monitor;
} }
doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
doprint "**** Failed: ", @_, " ****\n"; doprint "**** Failed: ", @_, " ****\n";
doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
return 1 if (!defined($store_failures)); return 1 if (!defined($store_failures));
...@@ -434,12 +459,12 @@ sub monitor { ...@@ -434,12 +459,12 @@ sub monitor {
if ($bug) { if ($bug) {
return 0 if ($in_bisect); return 0 if ($in_bisect);
fail "failed - got a bug report\n" and return 0; fail "failed - got a bug report" and return 0;
} }
if (!$booted) { if (!$booted) {
return 0 if ($in_bisect); return 0 if ($in_bisect);
fail "failed - never got a boot prompt.\n" and return 0; fail "failed - never got a boot prompt." and return 0;
} }
return 1; return 1;
...@@ -496,7 +521,8 @@ sub install { ...@@ -496,7 +521,8 @@ sub install {
my $save_env = $ENV{KERNEL_VERSION}; my $save_env = $ENV{KERNEL_VERSION};
$ENV{KERNEL_VERSION} = $version; $ENV{KERNEL_VERSION} = $version;
run_command "$post_install"; run_command "$post_install" or
dodie "Failed to run post install";
$ENV{KERNEL_VERSION} = $save_env; $ENV{KERNEL_VERSION} = $save_env;
} }
...@@ -596,6 +622,11 @@ sub build { ...@@ -596,6 +622,11 @@ sub build {
sub halt { sub halt {
if (!run_command "ssh $target halt" or defined($power_off)) { if (!run_command "ssh $target halt" or defined($power_off)) {
if (defined($poweroff_after_halt)) {
sleep $poweroff_after_halt;
run_command "$power_off";
}
} else {
# nope? the zap it! # nope? the zap it!
run_command "$power_off"; run_command "$power_off";
} }
...@@ -610,9 +641,7 @@ sub success { ...@@ -610,9 +641,7 @@ sub success {
doprint "*******************************************\n"; doprint "*******************************************\n";
doprint "*******************************************\n"; doprint "*******************************************\n";
if ($i != $opt{"NUM_TESTS"} && $test_type ne "build" && if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
!($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") &&
!($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build")) {
doprint "Reboot and wait $sleep_time seconds\n"; doprint "Reboot and wait $sleep_time seconds\n";
reboot; reboot;
start_monitor; start_monitor;
...@@ -1048,6 +1077,8 @@ sub set_test_option { ...@@ -1048,6 +1077,8 @@ sub set_test_option {
# First we need to do is the builds # First we need to do is the builds
for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
$iteration = $i;
my $ssh_user = set_test_option("SSH_USER", $i); my $ssh_user = set_test_option("SSH_USER", $i);
my $makecmd = set_test_option("MAKE_CMD", $i); my $makecmd = set_test_option("MAKE_CMD", $i);
...@@ -1071,6 +1102,8 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { ...@@ -1071,6 +1102,8 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
$poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i); $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
$die_on_failure = set_test_option("DIE_ON_FAILURE", $i); $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
$power_off = set_test_option("POWER_OFF", $i); $power_off = set_test_option("POWER_OFF", $i);
$powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
$poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
$sleep_time = set_test_option("SLEEP_TIME", $i); $sleep_time = set_test_option("SLEEP_TIME", $i);
$bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
$store_failures = set_test_option("STORE_FAILURES", $i); $store_failures = set_test_option("STORE_FAILURES", $i);
...@@ -1096,9 +1129,9 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { ...@@ -1096,9 +1129,9 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
$make = "$makecmd O=$outputdir"; $make = "$makecmd O=$outputdir";
if ($reboot_type eq "grub") { if ($reboot_type eq "grub") {
dodie "GRUB_MENU not defined\n" if (!defined($grub_menu)); dodie "GRUB_MENU not defined" if (!defined($grub_menu));
} elsif (!defined($reboot_script)) { } elsif (!defined($reboot_script)) {
dodie "REBOOT_SCRIPT not defined\n" dodie "REBOOT_SCRIPT not defined"
} }
my $run_type = $build_type; my $run_type = $build_type;
...@@ -1167,7 +1200,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { ...@@ -1167,7 +1200,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
if ($opt{"POWEROFF_ON_SUCCESS"}) { if ($opt{"POWEROFF_ON_SUCCESS"}) {
halt; halt;
} elsif ($opt{"REBOOT_ON_SUCCESS"} && $test_type ne "build") { } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
reboot; reboot;
} }
......
...@@ -160,6 +160,24 @@ ...@@ -160,6 +160,24 @@
# (ignored if POWEROFF_ON_SUCCESS is set) # (ignored if POWEROFF_ON_SUCCESS is set)
#REBOOT_ON_SUCCESS = 1 #REBOOT_ON_SUCCESS = 1
# In case there's isses with rebooting, you can specify this
# to always powercycle after this amount of time after calling
# reboot.
# Note, POWERCYCLE_AFTER_REBOOT = 0 does NOT disable it. It just
# makes it powercycle immediately after rebooting. Do not define
# it if you do not want it.
# (default undefined)
#POWERCYCLE_AFTER_REBOOT = 5
# In case there's isses with halting, you can specify this
# to always poweroff after this amount of time after calling
# halt.
# Note, POWEROFF_AFTER_HALT = 0 does NOT disable it. It just
# makes it poweroff immediately after halting. Do not define
# it if you do not want it.
# (default undefined)
#POWEROFF_AFTER_HALT = 20
# Stop testing if a build fails. If set, the script will end if # Stop testing if a build fails. If set, the script will end if
# a failure is detected, otherwise it will save off the .config, # a failure is detected, otherwise it will save off the .config,
# dmesg and bootlog in a directory called # dmesg and bootlog in a directory called
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册