Skip to content

Commit bc7c580

Browse files
Steven Rostedtrostedt
authored andcommitted
ktest: Add options SWITCH_TO_GOOD and SWITCH_TO_TEST
For machines that do no use grub, it may be needed to update an external image (tftp) before doing a reboot into either the test image or the known good image. The option SWITCH_TO_GOOD is added, where if it is defined, the command that is specified as its value will be executed before doing a reboot into a known good image. The option SWITCH_TO_TEST is added, where if it is defined, the command that is specified as its value will be executed before doing a reboot into the test image. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent c5dacb8 commit bc7c580

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
my $power_cycle;
8080
my $reboot;
8181
my $reboot_on_error;
82+
my $switch_to_good;
83+
my $switch_to_test;
8284
my $poweroff_on_error;
8385
my $die_on_failure;
8486
my $powercycle_after_reboot;
@@ -964,6 +966,17 @@ sub reboot {
964966
}
965967
}
966968

969+
sub reboot_to_good {
970+
my ($time) = @_;
971+
972+
if (defined($switch_to_good)) {
973+
run_command $switch_to_good;
974+
return;
975+
}
976+
977+
reboot $time;
978+
}
979+
967980
sub do_not_reboot {
968981
my $i = $iteration;
969982

@@ -980,7 +993,7 @@ sub dodie {
980993
if ($reboot_on_error && !do_not_reboot) {
981994

982995
doprint "REBOOTING\n";
983-
reboot;
996+
reboot_to_good;
984997

985998
} elsif ($poweroff_on_error && defined($power_off)) {
986999
doprint "POWERING OFF\n";
@@ -1116,7 +1129,7 @@ sub fail {
11161129
# no need to reboot for just building.
11171130
if (!do_not_reboot) {
11181131
doprint "REBOOTING\n";
1119-
reboot $sleep_time;
1132+
reboot_to_good $sleep_time;
11201133
}
11211134

11221135
my $name = "";
@@ -1269,6 +1282,10 @@ sub wait_for_input
12691282
}
12701283

12711284
sub reboot_to {
1285+
if (defined($switch_to_test)) {
1286+
run_command $switch_to_test;
1287+
}
1288+
12721289
if ($reboot_type eq "grub") {
12731290
run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
12741291
reboot;
@@ -1754,7 +1771,7 @@ sub success {
17541771

17551772
if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
17561773
doprint "Reboot and wait $sleep_time seconds\n";
1757-
reboot $sleep_time;
1774+
reboot_to_good $sleep_time;
17581775
}
17591776
}
17601777

@@ -1935,7 +1952,7 @@ sub run_git_bisect {
19351952

19361953
sub bisect_reboot {
19371954
doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1938-
reboot $bisect_sleep_time;
1955+
reboot_to_good $bisect_sleep_time;
19391956
}
19401957

19411958
# returns 1 on success, 0 on failure, -1 on skip
@@ -2528,7 +2545,7 @@ sub config_bisect {
25282545

25292546
sub patchcheck_reboot {
25302547
doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2531-
reboot $patchcheck_sleep_time;
2548+
reboot_to_good $patchcheck_sleep_time;
25322549
}
25332550

25342551
sub patchcheck {
@@ -3145,7 +3162,7 @@ sub make_min_config {
31453162
}
31463163

31473164
doprint "Reboot and wait $sleep_time seconds\n";
3148-
reboot $sleep_time;
3165+
reboot_to_good $sleep_time;
31493166
}
31503167

31513168
success $i;
@@ -3314,6 +3331,8 @@ sub set_test_option {
33143331
$no_install = set_test_option("NO_INSTALL", $i);
33153332
$reboot_script = set_test_option("REBOOT_SCRIPT", $i);
33163333
$reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3334+
$switch_to_good = set_test_option("SWITCH_TO_GOOD", $i);
3335+
$switch_to_test = set_test_option("SWITCH_TO_TEST", $i);
33173336
$poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
33183337
$die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
33193338
$power_off = set_test_option("POWER_OFF", $i);
@@ -3472,7 +3491,7 @@ sub set_test_option {
34723491
if ($opt{"POWEROFF_ON_SUCCESS"}) {
34733492
halt;
34743493
} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
3475-
reboot;
3494+
reboot_to_good;
34763495
}
34773496

34783497
doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";

‎tools/testing/ktest/sample.conf‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,27 @@
468468
# The test will not modify that file.
469469
#REBOOT_TYPE = grub
470470

471+
# If you are using a machine that doesn't boot with grub, and
472+
# perhaps gets its kernel from a remote server (tftp), then
473+
# you can use this option to update the target image with the
474+
# test image.
475+
#
476+
# You could also do the same with POST_INSTALL, but the difference
477+
# between that option and this option is that POST_INSTALL runs
478+
# after the install, where this one runs just before a reboot.
479+
# (default undefined)
480+
#SWITCH_TO_TEST = cp ${OUTPUT_DIR}/${BUILD_TARGET} ${TARGET_IMAGE}
481+
482+
# If you are using a machine that doesn't boot with grub, and
483+
# perhaps gets its kernel from a remote server (tftp), then
484+
# you can use this option to update the target image with the
485+
# the known good image to reboot safely back into.
486+
#
487+
# This option holds a command that will execute before needing
488+
# to reboot to a good known image.
489+
# (default undefined)
490+
#SWITCH_TO_GOOD = ssh ${SSH_USER}/${MACHINE} cp good_image ${TARGET_IMAGE}
491+
471492
# The min config that is needed to build for the machine
472493
# A nice way to create this is with the following:
473494
#

0 commit comments

Comments
 (0)