3 # Copywrite 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4 # Licensed under the terms of the GNU GPL License version 2
9 use Fcntl
qw(F_GETFL F_SETFL O_NONBLOCK);
10 use File
::Path
qw(mkpath);
11 use File
::Copy
qw(cp);
16 $#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
26 $default{"NUM_TESTS"} = 1;
27 $default{"REBOOT_TYPE"} = "grub";
28 $default{"TEST_TYPE"} = "test";
29 $default{"BUILD_TYPE"} = "randconfig";
30 $default{"MAKE_CMD"} = "make";
31 $default{"TIMEOUT"} = 120;
32 $default{"TMP_DIR"} = "/tmp/ktest";
33 $default{"SLEEP_TIME"} = 60; # sleep time between tests
34 $default{"BUILD_NOCLEAN"} = 0;
35 $default{"REBOOT_ON_ERROR"} = 0;
36 $default{"POWEROFF_ON_ERROR"} = 0;
37 $default{"REBOOT_ON_SUCCESS"} = 1;
38 $default{"POWEROFF_ON_SUCCESS"} = 0;
39 $default{"BUILD_OPTIONS"} = "";
40 $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
41 $default{"CLEAR_LOG"} = 0;
42 $default{"SUCCESS_LINE"} = "login:";
43 $default{"BOOTED_TIMEOUT"} = 1;
44 $default{"DIE_ON_FAILURE"} = 1;
45 $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
46 $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
47 $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
64 my $poweroff_on_error;
66 my $powercycle_after_reboot;
67 my $poweroff_after_halt;
82 my $in_patchcheck = 0;
91 my $bisect_sleep_time;
104 my ($lvalue, $rvalue) = @_;
106 if (defined($opt{$lvalue})) {
107 die "Error: Option $lvalue defined more than once!\n";
109 $opt{$lvalue} = $rvalue;
110 if ($rvalue =~ /^\s*$/) {
111 delete $opt{$lvalue};
113 $opt{$lvalue} = $rvalue;
120 open(IN
, $config) || die "can't read file $config";
123 $name =~ s
,.*/(.*),$1,;
128 my $num_tests_set = 0;
134 # ignore blank lines and comments
135 next if (/^\s*$/ || /\s*\#/);
137 if (/^\s*TEST_START(.*)/) {
141 if ($num_tests_set) {
142 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
145 my $old_test_num = $test_num;
146 my $old_repeat = $repeat;
148 $test_num += $repeat;
152 if ($rest =~ /\s+SKIP(.*)/) {
159 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
162 $repeat_tests{"$test_num"} = $repeat;
165 if ($rest =~ /\s+SKIP(.*)/) {
170 if ($rest !~ /^\s*$/) {
171 die "$name: $.: Gargbage found after TEST_START\n$_";
175 $test_num = $old_test_num;
176 $repeat = $old_repeat;
179 } elsif (/^\s*DEFAULTS(.*)$/) {
184 if ($rest =~ /\s+SKIP(.*)/) {
191 if ($rest !~ /^\s*$/) {
192 die "$name: $.: Gargbage found after DEFAULTS\n$_";
195 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
203 ($lvalue eq "NUM_TESTS" ||
204 $lvalue eq "LOG_FILE" ||
205 $lvalue eq "CLEAR_LOG")) {
206 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
209 if ($lvalue eq "NUM_TESTS") {
211 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
214 die "$name: $.: NUM_TESTS must be set in default section\n";
219 if ($default || $lvalue =~ /\[\d+\]$/) {
220 set_value
($lvalue, $rvalue);
222 my $val = "$lvalue\[$test_num\]";
223 set_value
($val, $rvalue);
226 $repeats{$val} = $repeat;
230 die "$name: $.: Garbage found in config\n$_";
237 $test_num += $repeat - 1;
238 $opt{"NUM_TESTS"} = $test_num;
243 foreach my $default (keys %default) {
244 if (!defined($opt{$default})) {
245 $opt{$default} = $default{$default};
251 if (defined($opt{"LOG_FILE"})) {
252 open(OUT
, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
259 if (defined($opt{"LOG_FILE"})) {
274 # try to reboot normally
275 if (run_command
$reboot) {
276 if (defined($powercycle_after_reboot)) {
277 sleep $powercycle_after_reboot;
278 run_command
"$power_cycle";
281 # nope? power cycle it.
282 run_command
"$power_cycle";
289 return $test_type eq "build" ||
290 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
291 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
295 doprint
"CRITICAL FAILURE... ", @_, "\n";
299 if ($reboot_on_error && !do_not_reboot
) {
301 doprint
"REBOOTING\n";
304 } elsif ($poweroff_on_error && defined($power_off)) {
305 doprint
"POWERING OFF\n";
317 my $pid = open($fp, "$console|") or
318 dodie
"Can't open console $console";
320 $flags = fcntl($fp, F_GETFL
, 0) or
321 dodie
"Can't get flags for the socket: $!";
322 $flags = fcntl($fp, F_SETFL
, $flags | O_NONBLOCK
) or
323 dodie
"Can't set flags for the socket: $!";
331 doprint
"kill child process $pid\n";
339 if ($monitor_cnt++) {
342 $monitor_fp = \
*MONFD
;
343 $monitor_pid = open_console
$monitor_fp;
347 open(MONFD
, "Stop perl from warning about single use of MONFD");
351 if (--$monitor_cnt) {
354 close_console
($monitor_fp, $monitor_pid);
357 sub wait_for_monitor
{
361 doprint
"** Wait for monitor to settle down **\n";
363 # read the monitor and wait for the system to calm down
365 $line = wait_for_input
($monitor_fp, $time);
366 print "$line" if (defined($line));
367 } while (defined($line));
368 print "** Monitor flushed **\n";
373 if ($die_on_failure) {
381 # no need to reboot for just building.
382 if (!do_not_reboot
) {
383 doprint
"REBOOTING\n";
386 wait_for_monitor
$sleep_time;
390 doprint
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
391 doprint
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
392 doprint
"KTEST RESULT: TEST $i Failed: ", @_, "\n";
393 doprint
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
394 doprint
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
396 return 1 if (!defined($store_failures));
399 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
400 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
402 my $dir = "$machine-$test_type-$build_type-fail-$date";
403 my $faildir = "$store_failures/$dir";
407 die "can't create $faildir";
409 if (-f
"$output_config") {
410 cp
"$output_config", "$faildir/config" or
411 die "failed to copy .config";
414 cp
$buildlog, "$faildir/buildlog" or
415 die "failed to move $buildlog";
418 cp
$dmesg, "$faildir/dmesg" or
419 die "failed to move $dmesg";
422 doprint
"*** Saved info to $faildir ***\n";
433 $command =~ s/\$SSH_USER/$ssh_user/g;
434 $command =~ s/\$MACHINE/$machine/g;
436 doprint
("$command ... ");
438 $pid = open(CMD
, "$command 2>&1 |") or
439 (fail
"unable to exec $command" and return 0);
441 if (defined($opt{"LOG_FILE"})) {
442 open(LOG
, ">>$opt{LOG_FILE}") or
443 dodie
"failed to write to log";
447 if (defined($redirect)) {
448 open (RD
, ">$redirect") or
449 dodie
"failed to write to redirect $redirect";
454 print LOG
if ($dolog);
462 close(LOG
) if ($dolog);
463 close(RD
) if ($dord);
476 my $cp_exec = $ssh_exec;
478 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
479 return run_command
"$cp_exec";
483 my ($src, $dst) = @_;
484 my $cp_scp = $scp_to_target;
486 $cp_scp =~ s/\$SRC_FILE/$src/g;
487 $cp_scp =~ s/\$DST_FILE/$dst/g;
489 return run_command
"$cp_scp";
494 if ($reboot_type ne "grub") {
497 return if (defined($grub_number));
499 doprint
"Find grub menu ... ";
502 my $ssh_grub = $ssh_exec;
503 $ssh_grub =~ s
,\
$SSH_COMMAND,cat
/boot/grub
/menu
.lst
,g
;
505 open(IN
, "$ssh_grub |")
506 or die "unable to get menu.lst";
509 if (/^\s*title\s+$grub_menu\s*$/) {
512 } elsif (/^\s*title\s/) {
518 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
519 if ($grub_number < 0);
520 doprint
"$grub_number\n";
525 my ($fp, $time) = @_;
531 if (!defined($time)) {
536 vec($rin, fileno($fp), 1) = 1;
537 $ready = select($rin, undef, undef, $time);
541 # try to read one char at a time
542 while (sysread $fp, $ch, 1) {
544 last if ($ch eq "\n");
547 if (!length($line)) {
555 if ($reboot_type eq "grub") {
556 run_command
"$ssh_exec '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
560 run_command
"$reboot_script";
566 doprint
"git rev-list --max-count=1 $commit ... ";
567 my $sha1 = `git rev-list --max-count=1 $commit`;
574 dodie
"Failed to get git $commit";
587 my $skip_call_trace = 0;
595 open(DMESG
, "> $dmesg") or
596 die "unable to write to $dmesg";
603 $line = wait_for_input
($monitor_fp, $booted_timeout);
605 $line = wait_for_input
($monitor_fp);
608 last if (!defined($line));
613 # we are not guaranteed to get a full line
616 if ($full_line =~ /$success_line/) {
620 if ($full_line =~ /\[ backtrace testing \]/) {
621 $skip_call_trace = 1;
624 if ($full_line =~ /call trace:/i) {
625 $bug = 1 if (!$skip_call_trace);
628 if ($full_line =~ /\[ end of backtrace testing \]/) {
629 $skip_call_trace = 0;
632 if ($full_line =~ /Kernel panic -/) {
644 return 0 if ($in_bisect);
645 fail
"failed - got a bug report" and return 0;
649 return 0 if ($in_bisect);
650 fail
"failed - never got a boot prompt." and return 0;
658 run_scp
"$outputdir/$build_target", "$target_image" or
659 dodie
"failed to copy image";
661 my $install_mods = 0;
663 # should we process modules?
665 open(IN
, "$output_config") or dodie
("Can't read config file");
667 if (/CONFIG_MODULES(=y)?/) {
668 $install_mods = 1 if (defined($1));
674 if (!$install_mods) {
675 doprint
"No modules needed\n";
679 run_command
"$make INSTALL_MOD_PATH=$tmpdir modules_install" or
680 dodie
"Failed to install modules";
682 my $modlib = "/lib/modules/$version";
683 my $modtar = "ktest-mods.tar.bz2";
685 run_ssh
"rm -rf $modlib" or
686 dodie
"failed to remove old mods: $modlib";
688 # would be nice if scp -r did not follow symbolic links
689 run_command
"cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
690 dodie
"making tarball";
692 run_scp
"$tmpdir/$modtar", "/tmp" or
693 dodie
"failed to copy modules";
695 unlink "$tmpdir/$modtar";
697 run_ssh
"'(cd / && tar xf /tmp/$modtar)'" or
698 dodie
"failed to tar modules";
700 run_ssh
"rm -f /tmp/$modtar";
702 return if (!defined($post_install));
704 my $cp_post_install = $post_install;
705 $cp_post_install = s/\$KERNEL_VERSION/$version/g;
706 run_command
"$cp_post_install" or
707 dodie
"Failed to run post install";
713 my @files = `git show $patch | diffstat -l`;
715 open(IN
, "git show $patch |") or
716 dodie
"failed to show $patch";
718 if (m
,^--- a
/(.*),) {
720 $files[$#files] = $1;
725 open(IN
, $buildlog) or dodie
"Can't open $buildlog";
727 if (/^\s*(.*?):.*(warning|error)/) {
729 foreach my $file (@files) {
730 my $fullpath = "$builddir/$file";
731 if ($file eq $err || $fullpath eq $err) {
732 fail
"$file built with warnings" and return 0;
748 if ($type =~ /^useconfig:(.*)/) {
749 run_command
"cp $1 $output_config" or
750 dodie
"could not copy $1 to .config";
755 # old config can ask questions
756 if ($type eq "oldconfig") {
757 $type = "oldnoconfig";
759 # allow for empty configs
760 run_command
"touch $output_config";
762 run_command
"mv $output_config $outputdir/config_temp" or
763 dodie
"moving .config";
765 if (!$noclean && !run_command
"$make mrproper") {
766 dodie
"make mrproper";
769 run_command
"mv $outputdir/config_temp $output_config" or
770 dodie
"moving config_temp";
772 } elsif (!$noclean) {
773 unlink "$output_config";
774 run_command
"$make mrproper" or
775 dodie
"make mrproper";
778 # add something to distinguish this build
779 open(OUT
, "> $outputdir/localversion") or dodie
("Can't make localversion file");
780 print OUT
"$localversion\n";
783 if (defined($minconfig)) {
784 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
787 run_command
"$defconfig $make $type" or
788 dodie
"failed make config";
790 $redirect = "$buildlog";
791 if (!run_command
"$make $build_options") {
793 # bisect may need this to pass
794 return 0 if ($in_bisect);
795 fail
"failed build" and return 0;
803 if (!run_ssh
"halt" or defined($power_off)) {
804 if (defined($poweroff_after_halt)) {
805 sleep $poweroff_after_halt;
806 run_command
"$power_off";
810 run_command
"$power_off";
819 doprint
"\n\n*******************************************\n";
820 doprint
"*******************************************\n";
821 doprint
"KTEST RESULT: TEST $i SUCCESS!!!! **\n";
822 doprint
"*******************************************\n";
823 doprint
"*******************************************\n";
825 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot
) {
826 doprint
"Reboot and wait $sleep_time seconds\n";
829 wait_for_monitor
$sleep_time;
835 # get the release name
836 doprint
"$make kernelrelease ... ";
837 $version = `$make kernelrelease | tail -1`;
839 doprint
"$version\n";
845 # child should have no power
846 $reboot_on_error = 0;
847 $poweroff_on_error = 0;
850 run_command
$run_test or $failed = 1;
869 doprint
"run test $run_test\n";
873 $SIG{CHLD
} = qw(child_finished);
877 child_run_test
if (!$child_pid);
882 $line = wait_for_input
($monitor_fp, 1);
883 if (defined($line)) {
885 # we are not guaranteed to get a full line
888 if ($full_line =~ /call trace:/i) {
892 if ($full_line =~ /Kernel panic -/) {
900 } while (!$child_done && !$bug);
903 doprint
"Detected kernel crash!\n";
904 # kill the child with extreme prejudice
908 waitpid $child_pid, 0;
911 if ($bug || $child_exit) {
912 return 0 if $in_bisect;
913 fail
"test failed" and return 0;
921 doprint
"$command ... ";
923 my $output = `$command 2>&1`;
930 dodie
"Failed to git bisect";
934 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
936 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
938 doprint
"Found bad commit... $1\n";
941 # we already logged it, just print it now.
956 if (defined($minconfig)) {
957 build
"useconfig:$minconfig" or $failed = 1;
959 # ?? no config to use?
960 build
"oldconfig" or $failed = 1;
963 if ($type ne "build") {
964 dodie
"Failed on build" if $failed;
972 monitor
or $failed = 1;
974 if ($type ne "boot") {
975 dodie
"Failed on boot" if $failed;
977 do_run_test
or $failed = 1;
985 # reboot the box to a good kernel
986 if ($type ne "build") {
987 doprint
"Reboot and sleep $bisect_sleep_time seconds\n";
990 wait_for_monitor
$bisect_sleep_time;
997 # Are we looking for where it worked, not failed?
998 if ($reverse_bisect) {
1014 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1015 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1016 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1018 my $good = $opt{"BISECT_GOOD[$i]"};
1019 my $bad = $opt{"BISECT_BAD[$i]"};
1020 my $type = $opt{"BISECT_TYPE[$i]"};
1021 my $start = $opt{"BISECT_START[$i]"};
1022 my $replay = $opt{"BISECT_REPLAY[$i]"};
1024 # convert to true sha1's
1025 $good = get_sha1
($good);
1026 $bad = get_sha1
($bad);
1028 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1029 $opt{"BISECT_REVERSE[$i]"} == 1) {
1030 doprint
"Performing a reverse bisect (bad is good, good is bad!)\n";
1031 $reverse_bisect = 1;
1033 $reverse_bisect = 0;
1038 # Can't have a test without having a test to run
1039 if ($type eq "test" && !defined($run_test)) {
1043 my $check = $opt{"BISECT_CHECK[$i]"};
1044 if (defined($check) && $check ne "0") {
1047 my $head = get_sha1
("HEAD");
1049 if ($check ne "good") {
1050 doprint
"TESTING BISECT BAD [$bad]\n";
1051 run_command
"git checkout $bad" or
1052 die "Failed to checkout $bad";
1054 $result = run_bisect
$type;
1056 if ($result ne "bad") {
1057 fail
"Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1061 if ($check ne "bad") {
1062 doprint
"TESTING BISECT GOOD [$good]\n";
1063 run_command
"git checkout $good" or
1064 die "Failed to checkout $good";
1066 $result = run_bisect
$type;
1068 if ($result ne "good") {
1069 fail
"Tested BISECT_GOOD [$good] and it failed" and return 0;
1073 # checkout where we started
1074 run_command
"git checkout $head" or
1075 die "Failed to checkout $head";
1078 run_command
"git bisect start" or
1079 dodie
"could not start bisect";
1081 run_command
"git bisect good $good" or
1082 dodie
"could not set bisect good to $good";
1084 run_git_bisect
"git bisect bad $bad" or
1085 dodie
"could not set bisect bad to $bad";
1087 if (defined($replay)) {
1088 run_command
"git bisect replay $replay" or
1089 dodie
"failed to run replay";
1092 if (defined($start)) {
1093 run_command
"git checkout $start" or
1094 dodie
"failed to checkout $start";
1099 $result = run_bisect
$type;
1100 $test = run_git_bisect
"git bisect $result";
1103 run_command
"git bisect log" or
1104 dodie
"could not capture git bisect log";
1106 run_command
"git bisect reset" or
1107 dodie
"could not reset git bisect";
1109 doprint
"Bad commit was [$bisect_bad]\n";
1119 die "PATCHCHECK_START[$i] not defined\n"
1120 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1121 die "PATCHCHECK_TYPE[$i] not defined\n"
1122 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1124 my $start = $opt{"PATCHCHECK_START[$i]"};
1127 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1128 $end = $opt{"PATCHCHECK_END[$i]"};
1131 # Get the true sha1's since we can use things like HEAD~3
1132 $start = get_sha1
($start);
1133 $end = get_sha1
($end);
1135 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1137 # Can't have a test without having a test to run
1138 if ($type eq "test" && !defined($run_test)) {
1142 open (IN
, "git log --pretty=oneline $end|") or
1143 dodie
"could not get git list";
1149 $list[$#list+1] = $_;
1150 last if (/^$start/);
1154 if ($list[$#list] !~ /^$start/) {
1155 fail
"SHA1 $start not found";
1158 # go backwards in the list
1159 @list = reverse @list;
1161 my $save_clean = $noclean;
1164 foreach my $item (@list) {
1166 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1168 doprint
"\nProcessing commit $item\n\n";
1170 run_command
"git checkout $sha1" or
1171 die "Failed to checkout $sha1";
1173 # only clean on the first and last patch
1174 if ($item eq $list[0] ||
1175 $item eq $list[$#list]) {
1176 $noclean = $save_clean;
1181 if (defined($minconfig)) {
1182 build
"useconfig:$minconfig" or return 0;
1184 # ?? no config to use?
1185 build
"oldconfig" or return 0;
1188 check_buildlog
$sha1 or return 0;
1190 next if ($type eq "build");
1199 monitor
or $failed = 1;
1201 if (!$failed && $type ne "boot"){
1202 do_run_test
or $failed = 1;
1205 return 0 if ($failed);
1214 read_config
$ARGV[0];
1217 die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
1218 die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
1219 die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
1220 die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
1221 die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
1222 die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
1223 die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
1224 die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
1225 die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
1227 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
1228 unlink $opt{"LOG_FILE"};
1231 doprint
"\n\nSTARTING AUTOMATED TESTS\n\n";
1233 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
1236 doprint
"DEFAULT OPTIONS:\n";
1238 doprint
"\nTEST $i OPTIONS";
1239 if (defined($repeat_tests{$i})) {
1240 $repeat = $repeat_tests{$i};
1241 doprint
" ITERATE $repeat";
1246 foreach my $option (sort keys %opt) {
1248 if ($option =~ /\[(\d+)\]$/) {
1254 doprint
"$option = $opt{$option}\n";
1258 sub set_test_option
{
1259 my ($name, $i) = @_;
1261 my $option = "$name\[$i\]";
1263 if (defined($opt{$option})) {
1264 return $opt{$option};
1267 foreach my $test (keys %repeat_tests) {
1269 $i < $test + $repeat_tests{$test}) {
1270 $option = "$name\[$test\]";
1271 if (defined($opt{$option})) {
1272 return $opt{$option};
1277 if (defined($opt{$name})) {
1284 # First we need to do is the builds
1285 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1289 my $makecmd = set_test_option
("MAKE_CMD", $i);
1291 $machine = set_test_option
("MACHINE", $i);
1292 $ssh_user = set_test_option
("SSH_USER", $i);
1293 $tmpdir = set_test_option
("TMP_DIR", $i);
1294 $outputdir = set_test_option
("OUTPUT_DIR", $i);
1295 $builddir = set_test_option
("BUILD_DIR", $i);
1296 $test_type = set_test_option
("TEST_TYPE", $i);
1297 $build_type = set_test_option
("BUILD_TYPE", $i);
1298 $build_options = set_test_option
("BUILD_OPTIONS", $i);
1299 $power_cycle = set_test_option
("POWER_CYCLE", $i);
1300 $reboot = set_test_option
("REBOOT", $i);
1301 $noclean = set_test_option
("BUILD_NOCLEAN", $i);
1302 $minconfig = set_test_option
("MIN_CONFIG", $i);
1303 $run_test = set_test_option
("TEST", $i);
1304 $addconfig = set_test_option
("ADD_CONFIG", $i);
1305 $reboot_type = set_test_option
("REBOOT_TYPE", $i);
1306 $grub_menu = set_test_option
("GRUB_MENU", $i);
1307 $post_install = set_test_option
("POST_INSTALL", $i);
1308 $reboot_script = set_test_option
("REBOOT_SCRIPT", $i);
1309 $reboot_on_error = set_test_option
("REBOOT_ON_ERROR", $i);
1310 $poweroff_on_error = set_test_option
("POWEROFF_ON_ERROR", $i);
1311 $die_on_failure = set_test_option
("DIE_ON_FAILURE", $i);
1312 $power_off = set_test_option
("POWER_OFF", $i);
1313 $powercycle_after_reboot = set_test_option
("POWERCYCLE_AFTER_REBOOT", $i);
1314 $poweroff_after_halt = set_test_option
("POWEROFF_AFTER_HALT", $i);
1315 $sleep_time = set_test_option
("SLEEP_TIME", $i);
1316 $bisect_sleep_time = set_test_option
("BISECT_SLEEP_TIME", $i);
1317 $store_failures = set_test_option
("STORE_FAILURES", $i);
1318 $timeout = set_test_option
("TIMEOUT", $i);
1319 $booted_timeout = set_test_option
("BOOTED_TIMEOUT", $i);
1320 $console = set_test_option
("CONSOLE", $i);
1321 $success_line = set_test_option
("SUCCESS_LINE", $i);
1322 $build_target = set_test_option
("BUILD_TARGET", $i);
1323 $ssh_exec = set_test_option
("SSH_EXEC", $i);
1324 $scp_to_target = set_test_option
("SCP_TO_TARGET", $i);
1325 $target_image = set_test_option
("TARGET_IMAGE", $i);
1326 $localversion = set_test_option
("LOCALVERSION", $i);
1328 chdir $builddir || die "can't change directory to $builddir";
1332 die "can't create $tmpdir";
1335 $ENV{"SSH_USER"} = $ssh_user;
1336 $ENV{"MACHINE"} = $machine;
1338 $target = "$ssh_user\@$machine";
1340 $buildlog = "$tmpdir/buildlog-$machine";
1341 $dmesg = "$tmpdir/dmesg-$machine";
1342 $make = "$makecmd O=$outputdir";
1343 $output_config = "$outputdir/.config";
1344 $output_config = "$outputdir/.config";
1346 if ($reboot_type eq "grub") {
1347 dodie
"GRUB_MENU not defined" if (!defined($grub_menu));
1348 } elsif (!defined($reboot_script)) {
1349 dodie
"REBOOT_SCRIPT not defined"
1352 my $run_type = $build_type;
1353 if ($test_type eq "patchcheck") {
1354 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
1355 } elsif ($test_type eq "bisect") {
1356 $run_type = $opt{"BISECT_TYPE[$i]"};
1359 # mistake in config file?
1360 if (!defined($run_type)) {
1361 $run_type = "ERROR";
1365 doprint
"RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
1370 if (!defined($minconfig)) {
1371 $minconfig = $addconfig;
1373 } elsif (defined($addconfig)) {
1374 run_command
"cat $addconfig $minconfig > $tmpdir/use_config" or
1375 dodie
"Failed to create temp config";
1376 $minconfig = "$tmpdir/use_config";
1379 my $checkout = $opt{"CHECKOUT[$i]"};
1380 if (defined($checkout)) {
1381 run_command
"git checkout $checkout" or
1382 die "failed to checkout $checkout";
1385 if ($test_type eq "bisect") {
1388 } elsif ($test_type eq "patchcheck") {
1393 if ($build_type ne "nobuild") {
1394 build
$build_type or next;
1397 if ($test_type ne "build") {
1404 monitor
or $failed = 1;;
1406 if (!$failed && $test_type ne "boot" && defined($run_test)) {
1407 do_run_test
or $failed = 1;
1416 if ($opt{"POWEROFF_ON_SUCCESS"}) {
1418 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot
) {
1422 doprint
"\n $successes of $opt{NUM_TESTS} tests were successful\n\n";