3 # Copyright 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);
24 $default{"NUM_TESTS"} = 1;
25 $default{"REBOOT_TYPE"} = "grub";
26 $default{"TEST_TYPE"} = "test";
27 $default{"BUILD_TYPE"} = "randconfig";
28 $default{"MAKE_CMD"} = "make";
29 $default{"TIMEOUT"} = 120;
30 $default{"TMP_DIR"} = "/tmp/ktest";
31 $default{"SLEEP_TIME"} = 60; # sleep time between tests
32 $default{"BUILD_NOCLEAN"} = 0;
33 $default{"REBOOT_ON_ERROR"} = 0;
34 $default{"POWEROFF_ON_ERROR"} = 0;
35 $default{"REBOOT_ON_SUCCESS"} = 1;
36 $default{"POWEROFF_ON_SUCCESS"} = 0;
37 $default{"BUILD_OPTIONS"} = "";
38 $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
39 $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
40 $default{"CLEAR_LOG"} = 0;
41 $default{"BISECT_MANUAL"} = 0;
42 $default{"BISECT_SKIP"} = 1;
43 $default{"SUCCESS_LINE"} = "login:";
44 $default{"DETECT_TRIPLE_FAULT"} = 1;
45 $default{"BOOTED_TIMEOUT"} = 1;
46 $default{"DIE_ON_FAILURE"} = 1;
47 $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
48 $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
49 $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
50 $default{"STOP_AFTER_SUCCESS"} = 10;
51 $default{"STOP_AFTER_FAILURE"} = 60;
52 $default{"STOP_TEST_AFTER"} = 600;
53 $default{"LOCALVERSION"} = "-test";
75 my $poweroff_on_error;
77 my $powercycle_after_reboot;
78 my $poweroff_after_halt;
95 my $config_bisect_good;
96 my $in_patchcheck = 0;
105 my $bisect_sleep_time;
106 my $patchcheck_sleep_time;
111 my $detect_triplefault;
114 my $stop_after_success;
115 my $stop_after_failure;
128 $config_help{"MACHINE"} = << "EOF"
129 The machine hostname that you will test.
132 $config_help{"SSH_USER"} = << "EOF"
133 The box is expected to have ssh on normal bootup, provide the user
134 (most likely root, since you need privileged operations)
137 $config_help{"BUILD_DIR"} = << "EOF"
138 The directory that contains the Linux source code (full path).
141 $config_help{"OUTPUT_DIR"} = << "EOF"
142 The directory that the objects will be built (full path).
143 (can not be same as BUILD_DIR)
146 $config_help{"BUILD_TARGET"} = << "EOF"
147 The location of the compiled file to copy to the target.
148 (relative to OUTPUT_DIR)
151 $config_help{"TARGET_IMAGE"} = << "EOF"
152 The place to put your image on the test machine.
155 $config_help{"POWER_CYCLE"} = << "EOF"
156 A script or command to reboot the box.
158 Here is a digital loggers power switch example
159 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
161 Here is an example to reboot a virtual box on the current host
162 with the name "Guest".
163 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
166 $config_help{"CONSOLE"} = << "EOF"
167 The script or command that reads the console
169 If you use ttywatch server, something like the following would work.
170 CONSOLE = nc -d localhost 3001
172 For a virtual machine with guest name "Guest".
173 CONSOLE = virsh console Guest
176 $config_help{"LOCALVERSION"} = << "EOF"
177 Required version ending to differentiate the test
178 from other linux builds on the system.
181 $config_help{"REBOOT_TYPE"} = << "EOF"
182 Way to reboot the box to the test kernel.
183 Only valid options so far are "grub" and "script".
185 If you specify grub, it will assume grub version 1
186 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
187 and select that target to reboot to the kernel. If this is not
188 your setup, then specify "script" and have a command or script
189 specified in REBOOT_SCRIPT to boot to the target.
191 The entry in /boot/grub/menu.lst must be entered in manually.
192 The test will not modify that file.
195 $config_help{"GRUB_MENU"} = << "EOF"
196 The grub title name for the test kernel to boot
197 (Only mandatory if REBOOT_TYPE = grub)
199 Note, ktest.pl will not update the grub menu.lst, you need to
200 manually add an option for the test. ktest.pl will search
201 the grub menu.lst for this option to find what kernel to
204 For example, if in the /boot/grub/menu.lst the test kernel title has:
207 GRUB_MENU = Test Kernel
210 $config_help{"REBOOT_SCRIPT"} = << "EOF"
211 A script to reboot the target into the test kernel
212 (Only mandatory if REBOOT_TYPE = script)
217 sub get_ktest_config {
220 return if (defined($opt{$config}));
222 if (defined($config_help{$config})) {
224 print $config_help{$config};
229 if (defined($default{$config})) {
230 print "\[$default{$config}\] ";
232 $entered_configs{$config} = <STDIN>;
233 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
234 if ($entered_configs{$config} =~ /^\s*$/) {
235 if ($default{$config}) {
236 $entered_configs{$config} = $default{$config};
238 print "Your answer can not be blank\n";
246 sub get_ktest_configs {
247 get_ktest_config("MACHINE");
248 get_ktest_config("SSH_USER");
249 get_ktest_config("BUILD_DIR");
250 get_ktest_config("OUTPUT_DIR");
251 get_ktest_config("BUILD_TARGET");
252 get_ktest_config("TARGET_IMAGE");
253 get_ktest_config("POWER_CYCLE");
254 get_ktest_config("CONSOLE");
255 get_ktest_config("LOCALVERSION");
257 my $rtype = $opt{"REBOOT_TYPE"};
259 if (!defined($rtype)) {
260 if (!defined($opt{"GRUB_MENU"})) {
261 get_ktest_config("REBOOT_TYPE");
262 $rtype = $entered_configs{"REBOOT_TYPE"};
268 if ($rtype eq "grub") {
269 get_ktest_config("GRUB_MENU");
271 get_ktest_config("REBOOT_SCRIPT");
275 sub process_variables {
279 # We want to check for '\', and it is just easier
280 # to check the previous characet of '$' and not need
281 # to worry if '$' is the first character. By adding
282 # a space to $value, we can just check [^\\]\$ and
283 # it will still work.
286 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
290 # append beginning of value to retval
291 $retval = "$retval$begin";
292 if (defined($variable{$var})) {
293 $retval = "$retval$variable{$var}";
295 # put back the origin piece.
296 $retval = "$retval\$\{$var\}";
300 $retval = "$retval$value";
302 # remove the space added in the beginning
309 my ($lvalue, $rvalue) = @_;
311 if (defined($opt{$lvalue})) {
312 die "Error: Option $lvalue defined more than once!\n";
314 if ($rvalue =~ /^\s*$/) {
315 delete $opt{$lvalue};
317 $rvalue = process_variables($rvalue);
318 $opt{$lvalue} = $rvalue;
323 my ($lvalue, $rvalue) = @_;
325 if ($rvalue =~ /^\s*$/) {
326 delete $variable{$lvalue};
328 $rvalue = process_variables($rvalue);
329 $variable{$lvalue} = $rvalue;
336 open(IN, $config) || die "can't read file $config";
339 $name =~ s,.*/(.*),$1,;
344 my $num_tests_set = 0;
350 # ignore blank lines and comments
351 next if (/^\s*$/ || /\s*\#/);
353 if (/^\s*TEST_START(.*)/) {
357 if ($num_tests_set) {
358 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
361 my $old_test_num = $test_num;
362 my $old_repeat = $repeat;
364 $test_num += $repeat;
368 if ($rest =~ /\s+SKIP(.*)/) {
375 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
378 $repeat_tests{"$test_num"} = $repeat;
381 if ($rest =~ /\s+SKIP(.*)/) {
386 if ($rest !~ /^\s*$/) {
387 die "$name: $.: Gargbage found after TEST_START\n$_";
391 $test_num = $old_test_num;
392 $repeat = $old_repeat;
395 } elsif (/^\s*DEFAULTS(.*)$/) {
400 if ($rest =~ /\s+SKIP(.*)/) {
407 if ($rest !~ /^\s*$/) {
408 die "$name: $.: Gargbage found after DEFAULTS\n$_";
411 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
419 ($lvalue eq "NUM_TESTS" ||
420 $lvalue eq "LOG_FILE" ||
421 $lvalue eq "CLEAR_LOG")) {
422 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
425 if ($lvalue eq "NUM_TESTS") {
427 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
430 die "$name: $.: NUM_TESTS must be set in default section\n";
435 if ($default || $lvalue =~ /\[\d+\]$/) {
436 set_value($lvalue, $rvalue);
438 my $val = "$lvalue\[$test_num\]";
439 set_value($val, $rvalue);
442 $repeats{$val} = $repeat;
445 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
451 # process config variables.
452 # Config variables are only active while reading the
453 # config and can be defined anywhere. They also ignore
454 # TEST_START and DEFAULTS, but are skipped if they are in
455 # on of these sections that have SKIP defined.
456 # The save variable can be
457 # defined multiple times and the new one simply overrides
459 set_variable($lvalue, $rvalue);
462 die "$name: $.: Garbage found in config\n$_";
469 $test_num += $repeat - 1;
470 $opt{"NUM_TESTS"} = $test_num;
473 # make sure we have all mandatory configs
478 foreach my $default (keys %default) {
479 if (!defined($opt{$default})) {
480 $opt{$default} = $default{$default};
486 my ($option, $i) = @_;
488 # Add space to evaluate the character before $
489 $option = " $option";
492 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
497 # Append beginning of line
498 $retval = "$retval$start";
500 # If the iteration option OPT[$i] exists, then use that.
501 # otherwise see if the default OPT (without [$i]) exists.
503 my $o = "$var\[$i\]";
505 if (defined($opt{$o})) {
507 $retval = "$retval$o";
508 } elsif (defined($opt{$var})) {
510 $retval = "$retval$o";
512 $retval = "$retval\$\{$var\}";
518 $retval = "$retval$option";
526 my ($option, $i) = @_;
530 # Since an option can evaluate to another option,
531 # keep iterating until we do not evaluate any more
534 while ($prev ne $option) {
535 # Check for recursive evaluations.
536 # 100 deep should be more than enough.
538 die "Over 100 evaluations accurred with $option\n" .
539 "Check for recursive variables\n";
542 $option = __eval_option($option, $i);
549 if (defined($opt{"LOG_FILE"})) {
550 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
557 if (defined($opt{"LOG_FILE"})) {
572 # try to reboot normally
573 if (run_command $reboot) {
574 if (defined($powercycle_after_reboot)) {
575 sleep $powercycle_after_reboot;
576 run_command "$power_cycle";
579 # nope? power cycle it.
580 run_command "$power_cycle";
587 return $test_type eq "build" ||
588 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
589 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
593 doprint "CRITICAL FAILURE... ", @_, "\n";
597 if ($reboot_on_error && !do_not_reboot) {
599 doprint "REBOOTING\n";
602 } elsif ($poweroff_on_error && defined($power_off)) {
603 doprint "POWERING OFF\n";
607 if (defined($opt{"LOG_FILE"})) {
608 print " See $opt{LOG_FILE} for more info.\n";
619 my $pid = open($fp, "$console|") or
620 dodie "Can't open console $console";
622 $flags = fcntl($fp, F_GETFL, 0) or
623 dodie "Can't get flags for the socket: $!";
624 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
625 dodie "Can't set flags for the socket: $!";
633 doprint "kill child process $pid\n";
641 if ($monitor_cnt++) {
644 $monitor_fp = \*MONFD;
645 $monitor_pid = open_console $monitor_fp;
649 open(MONFD, "Stop perl from warning about single use of MONFD");
653 if (--$monitor_cnt) {
656 close_console($monitor_fp, $monitor_pid);
659 sub wait_for_monitor {
663 doprint "** Wait for monitor to settle down **\n";
665 # read the monitor and wait for the system to calm down
667 $line = wait_for_input($monitor_fp, $time);
668 print "$line" if (defined($line));
669 } while (defined($line));
670 print "** Monitor flushed **\n";
675 if ($die_on_failure) {
683 # no need to reboot for just building.
684 if (!do_not_reboot) {
685 doprint "REBOOTING\n";
688 wait_for_monitor $sleep_time;
694 if (defined($test_name)) {
695 $name = " ($test_name)";
698 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
699 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
700 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
701 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
702 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
704 return 1 if (!defined($store_failures));
707 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
708 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
710 my $type = $build_type;
711 if ($type =~ /useconfig/) {
715 my $dir = "$machine-$test_type-$type-fail-$date";
716 my $faildir = "$store_failures/$dir";
720 die "can't create $faildir";
722 if (-f "$output_config") {
723 cp "$output_config", "$faildir/config" or
724 die "failed to copy .config";
727 cp $buildlog, "$faildir/buildlog" or
728 die "failed to move $buildlog";
731 cp $dmesg, "$faildir/dmesg" or
732 die "failed to move $dmesg";
735 doprint "*** Saved info to $faildir ***\n";
746 $command =~ s/\$SSH_USER/$ssh_user/g;
747 $command =~ s/\$MACHINE/$machine/g;
749 doprint("$command ... ");
751 $pid = open(CMD, "$command 2>&1 |") or
752 (fail "unable to exec $command" and return 0);
754 if (defined($opt{"LOG_FILE"})) {
755 open(LOG, ">>$opt{LOG_FILE}") or
756 dodie "failed to write to log";
760 if (defined($redirect)) {
761 open (RD, ">$redirect") or
762 dodie "failed to write to redirect $redirect";
767 print LOG if ($dolog);
775 close(LOG) if ($dolog);
776 close(RD) if ($dord);
789 my $cp_exec = $ssh_exec;
791 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
792 return run_command "$cp_exec";
796 my ($src, $dst) = @_;
797 my $cp_scp = $scp_to_target;
799 $cp_scp =~ s/\$SRC_FILE/$src/g;
800 $cp_scp =~ s/\$DST_FILE/$dst/g;
802 return run_command "$cp_scp";
807 if ($reboot_type ne "grub") {
810 return if (defined($grub_number));
812 doprint "Find grub menu ... ";
815 my $ssh_grub = $ssh_exec;
816 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
818 open(IN, "$ssh_grub |")
819 or die "unable to get menu.lst";
822 if (/^\s*title\s+$grub_menu\s*$/) {
825 } elsif (/^\s*title\s/) {
831 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
832 if ($grub_number < 0);
833 doprint "$grub_number\n";
838 my ($fp, $time) = @_;
844 if (!defined($time)) {
849 vec($rin, fileno($fp), 1) = 1;
850 $ready = select($rin, undef, undef, $time);
854 # try to read one char at a time
855 while (sysread $fp, $ch, 1) {
857 last if ($ch eq "\n");
860 if (!length($line)) {
868 if ($reboot_type eq "grub") {
869 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
873 run_command "$reboot_script";
879 doprint "git rev-list --max-count=1 $commit ... ";
880 my $sha1 = `git rev-list --max-count=1 $commit`;
887 dodie "Failed to get git $commit";
900 my $skip_call_trace = 0;
908 open(DMESG, "> $dmesg") or
909 die "unable to write to $dmesg";
915 my $monitor_start = time;
917 my $version_found = 0;
921 if ($bug && defined($stop_after_failure) &&
922 $stop_after_failure >= 0) {
923 my $time = $stop_after_failure - (time - $failure_start);
924 $line = wait_for_input($monitor_fp, $time);
925 if (!defined($line)) {
926 doprint "bug timed out after $booted_timeout seconds\n";
927 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
931 $line = wait_for_input($monitor_fp, $booted_timeout);
932 if (!defined($line)) {
933 my $s = $booted_timeout == 1 ? "" : "s";
934 doprint "Successful boot found: break after $booted_timeout second$s\n";
938 $line = wait_for_input($monitor_fp);
939 if (!defined($line)) {
940 my $s = $timeout == 1 ? "" : "s";
941 doprint "Timed out after $timeout second$s\n";
949 # we are not guaranteed to get a full line
952 if ($full_line =~ /$success_line/) {
954 $success_start = time;
957 if ($booted && defined($stop_after_success) &&
958 $stop_after_success >= 0) {
960 if ($now - $success_start >= $stop_after_success) {
961 doprint "Test forced to stop after $stop_after_success seconds after success\n";
966 if ($full_line =~ /\[ backtrace testing \]/) {
967 $skip_call_trace = 1;
970 if ($full_line =~ /call trace:/i) {
971 if (!$bug && !$skip_call_trace) {
973 $failure_start = time;
977 if ($bug && defined($stop_after_failure) &&
978 $stop_after_failure >= 0) {
980 if ($now - $failure_start >= $stop_after_failure) {
981 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
986 if ($full_line =~ /\[ end of backtrace testing \]/) {
987 $skip_call_trace = 0;
990 if ($full_line =~ /Kernel panic -/) {
991 $failure_start = time;
995 # Detect triple faults by testing the banner
996 if ($full_line =~ /\bLinux version (\S+).*\n/) {
997 if ($1 eq $version) {
999 } elsif ($version_found && $detect_triplefault) {
1000 # We already booted into the kernel we are testing,
1001 # but now we booted into another kernel?
1002 # Consider this a triple fault.
1003 doprint "Aleady booted in Linux kernel $version, but now\n";
1004 doprint "we booted into Linux kernel $1.\n";
1005 doprint "Assuming that this is a triple fault.\n";
1006 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1011 if ($line =~ /\n/) {
1015 if ($stop_test_after > 0 && !$booted && !$bug) {
1016 if (time - $monitor_start > $stop_test_after) {
1017 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1026 return 0 if ($in_bisect);
1027 fail "failed - got a bug report" and return 0;
1031 return 0 if ($in_bisect);
1032 fail "failed - never got a boot prompt." and return 0;
1038 sub do_post_install {
1040 return if (!defined($post_install));
1042 my $cp_post_install = $post_install;
1043 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1044 run_command "$cp_post_install" or
1045 dodie "Failed to run post install";
1050 run_scp "$outputdir/$build_target", "$target_image" or
1051 dodie "failed to copy image";
1053 my $install_mods = 0;
1055 # should we process modules?
1057 open(IN, "$output_config") or dodie("Can't read config file");
1059 if (/CONFIG_MODULES(=y)?/) {
1060 $install_mods = 1 if (defined($1));
1066 if (!$install_mods) {
1068 doprint "No modules needed\n";
1072 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1073 dodie "Failed to install modules";
1075 my $modlib = "/lib/modules/$version";
1076 my $modtar = "ktest-mods.tar.bz2";
1078 run_ssh "rm -rf $modlib" or
1079 dodie "failed to remove old mods: $modlib";
1081 # would be nice if scp -r did not follow symbolic links
1082 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1083 dodie "making tarball";
1085 run_scp "$tmpdir/$modtar", "/tmp" or
1086 dodie "failed to copy modules";
1088 unlink "$tmpdir/$modtar";
1090 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
1091 dodie "failed to tar modules";
1093 run_ssh "rm -f /tmp/$modtar";
1098 sub check_buildlog {
1101 my @files = `git show $patch | diffstat -l`;
1103 open(IN, "git show $patch |") or
1104 dodie "failed to show $patch";
1106 if (m,^--- a/(.*),) {
1108 $files[$#files] = $1;
1113 open(IN, $buildlog) or dodie "Can't open $buildlog";
1115 if (/^\s*(.*?):.*(warning|error)/) {
1117 foreach my $file (@files) {
1118 my $fullpath = "$builddir/$file";
1119 if ($file eq $err || $fullpath eq $err) {
1120 fail "$file built with warnings" and return 0;
1130 sub apply_min_config {
1131 my $outconfig = "$output_config.new";
1133 # Read the config file and remove anything that
1134 # is in the force_config hash (from minconfig and others)
1135 # then add the force config back.
1137 doprint "Applying minimum configurations into $output_config.new\n";
1139 open (OUT, ">$outconfig") or
1140 dodie "Can't create $outconfig";
1142 if (-f $output_config) {
1143 open (IN, $output_config) or
1144 dodie "Failed to open $output_config";
1146 if (/^(# )?(CONFIG_[^\s=]*)/) {
1147 next if (defined($force_config{$2}));
1153 foreach my $config (keys %force_config) {
1154 print OUT "$force_config{$config}\n";
1158 run_command "mv $outconfig $output_config";
1161 sub make_oldconfig {
1165 if (!run_command "$make oldnoconfig") {
1166 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1167 # try a yes '' | oldconfig
1168 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1169 run_command "yes '' | $make oldconfig" or
1170 dodie "failed make config oldconfig";
1174 # read a config file and use this to force new configs.
1175 sub load_force_config {
1178 open(IN, $config) or
1179 dodie "failed to read $config";
1182 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1183 $force_config{$1} = $_;
1184 } elsif (/^# (CONFIG_\S*) is not set/) {
1185 $force_config{$1} = $_;
1196 if (defined($pre_build)) {
1197 my $ret = run_command $pre_build;
1198 if (!$ret && defined($pre_build_die) &&
1200 dodie "failed to pre_build\n";
1204 if ($type =~ /^useconfig:(.*)/) {
1205 run_command "cp $1 $output_config" or
1206 dodie "could not copy $1 to .config";
1208 $type = "oldconfig";
1211 # old config can ask questions
1212 if ($type eq "oldconfig") {
1213 $type = "oldnoconfig";
1215 # allow for empty configs
1216 run_command "touch $output_config";
1218 run_command "mv $output_config $outputdir/config_temp" or
1219 dodie "moving .config";
1221 if (!$noclean && !run_command "$make mrproper") {
1222 dodie "make mrproper";
1225 run_command "mv $outputdir/config_temp $output_config" or
1226 dodie "moving config_temp";
1228 } elsif (!$noclean) {
1229 unlink "$output_config";
1230 run_command "$make mrproper" or
1231 dodie "make mrproper";
1234 # add something to distinguish this build
1235 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1236 print OUT "$localversion\n";
1239 if (defined($minconfig)) {
1240 load_force_config($minconfig);
1243 if ($type ne "oldnoconfig") {
1244 run_command "$make $type" or
1245 dodie "failed make config";
1247 # Run old config regardless, to enforce min configurations
1250 $redirect = "$buildlog";
1251 my $build_ret = run_command "$make $build_options";
1254 if (defined($post_build)) {
1255 my $ret = run_command $post_build;
1256 if (!$ret && defined($post_build_die) &&
1258 dodie "failed to post_build\n";
1263 # bisect may need this to pass
1264 return 0 if ($in_bisect);
1265 fail "failed build" and return 0;
1272 if (!run_ssh "halt" or defined($power_off)) {
1273 if (defined($poweroff_after_halt)) {
1274 sleep $poweroff_after_halt;
1275 run_command "$power_off";
1279 run_command "$power_off";
1290 if (defined($test_name)) {
1291 $name = " ($test_name)";
1294 doprint "\n\n*******************************************\n";
1295 doprint "*******************************************\n";
1296 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1297 doprint "*******************************************\n";
1298 doprint "*******************************************\n";
1300 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1301 doprint "Reboot and wait $sleep_time seconds\n";
1304 wait_for_monitor $sleep_time;
1310 # get the release name
1311 doprint "$make kernelrelease ... ";
1312 $version = `$make kernelrelease | tail -1`;
1314 doprint "$version\n";
1319 doprint "Pass or fail? [p/f]";
1322 if ($ans eq "p" || $ans eq "P") {
1324 } elsif ($ans eq "f" || $ans eq "F") {
1327 print "Please answer 'P' or 'F'\n";
1332 sub child_run_test {
1335 # child should have no power
1336 $reboot_on_error = 0;
1337 $poweroff_on_error = 0;
1338 $die_on_failure = 1;
1340 run_command $run_test or $failed = 1;
1346 sub child_finished {
1359 doprint "run test $run_test\n";
1363 $SIG{CHLD} = qw(child_finished);
1367 child_run_test if (!$child_pid);
1372 $line = wait_for_input($monitor_fp, 1);
1373 if (defined($line)) {
1375 # we are not guaranteed to get a full line
1376 $full_line .= $line;
1379 if ($full_line =~ /call trace:/i) {
1383 if ($full_line =~ /Kernel panic -/) {
1387 if ($line =~ /\n/) {
1391 } while (!$child_done && !$bug);
1394 my $failure_start = time;
1397 $line = wait_for_input($monitor_fp, 1);
1398 if (defined($line)) {
1402 if ($now - $failure_start >= $stop_after_failure) {
1405 } while (defined($line));
1407 doprint "Detected kernel crash!\n";
1408 # kill the child with extreme prejudice
1412 waitpid $child_pid, 0;
1415 if ($bug || $child_exit) {
1416 return 0 if $in_bisect;
1417 fail "test failed" and return 0;
1422 sub run_git_bisect {
1425 doprint "$command ... ";
1427 my $output = `$command 2>&1`;
1434 dodie "Failed to git bisect";
1437 doprint "SUCCESS\n";
1438 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1439 doprint "$1 [$2]\n";
1440 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1442 doprint "Found bad commit... $1\n";
1445 # we already logged it, just print it now.
1453 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1456 wait_for_monitor $bisect_sleep_time;
1460 # returns 1 on success, 0 on failure, -1 on skip
1461 sub run_bisect_test {
1462 my ($type, $buildtype) = @_;
1471 build $buildtype or $failed = 1;
1473 if ($type ne "build") {
1474 if ($failed && $bisect_skip) {
1478 dodie "Failed on build" if $failed;
1486 monitor or $failed = 1;
1488 if ($type ne "boot") {
1489 if ($failed && $bisect_skip) {
1495 dodie "Failed on boot" if $failed;
1497 do_run_test or $failed = 1;
1508 # reboot the box to a kernel we can ssh to
1509 if ($type ne "build") {
1519 my $buildtype = "oldconfig";
1521 # We should have a minconfig to use?
1522 if (defined($minconfig)) {
1523 $buildtype = "useconfig:$minconfig";
1526 my $ret = run_bisect_test $type, $buildtype;
1528 if ($bisect_manual) {
1529 $ret = answer_bisect;
1532 # Are we looking for where it worked, not failed?
1533 if ($reverse_bisect) {
1539 } elsif ($ret == 0) {
1541 } elsif ($bisect_skip) {
1542 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1552 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1553 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1554 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1556 my $good = $opt{"BISECT_GOOD[$i]"};
1557 my $bad = $opt{"BISECT_BAD[$i]"};
1558 my $type = $opt{"BISECT_TYPE[$i]"};
1559 my $start = $opt{"BISECT_START[$i]"};
1560 my $replay = $opt{"BISECT_REPLAY[$i]"};
1561 my $start_files = $opt{"BISECT_FILES[$i]"};
1563 if (defined($start_files)) {
1564 $start_files = " -- " . $start_files;
1569 # convert to true sha1's
1570 $good = get_sha1($good);
1571 $bad = get_sha1($bad);
1573 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1574 $opt{"BISECT_REVERSE[$i]"} == 1) {
1575 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1576 $reverse_bisect = 1;
1578 $reverse_bisect = 0;
1581 # Can't have a test without having a test to run
1582 if ($type eq "test" && !defined($run_test)) {
1586 my $check = $opt{"BISECT_CHECK[$i]"};
1587 if (defined($check) && $check ne "0") {
1590 my $head = get_sha1("HEAD");
1592 if ($check ne "good") {
1593 doprint "TESTING BISECT BAD [$bad]\n";
1594 run_command "git checkout $bad" or
1595 die "Failed to checkout $bad";
1597 $result = run_bisect $type;
1599 if ($result ne "bad") {
1600 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1604 if ($check ne "bad") {
1605 doprint "TESTING BISECT GOOD [$good]\n";
1606 run_command "git checkout $good" or
1607 die "Failed to checkout $good";
1609 $result = run_bisect $type;
1611 if ($result ne "good") {
1612 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1616 # checkout where we started
1617 run_command "git checkout $head" or
1618 die "Failed to checkout $head";
1621 run_command "git bisect start$start_files" or
1622 dodie "could not start bisect";
1624 run_command "git bisect good $good" or
1625 dodie "could not set bisect good to $good";
1627 run_git_bisect "git bisect bad $bad" or
1628 dodie "could not set bisect bad to $bad";
1630 if (defined($replay)) {
1631 run_command "git bisect replay $replay" or
1632 dodie "failed to run replay";
1635 if (defined($start)) {
1636 run_command "git checkout $start" or
1637 dodie "failed to checkout $start";
1642 $result = run_bisect $type;
1643 $test = run_git_bisect "git bisect $result";
1646 run_command "git bisect log" or
1647 dodie "could not capture git bisect log";
1649 run_command "git bisect reset" or
1650 dodie "could not reset git bisect";
1652 doprint "Bad commit was [$bisect_bad]\n";
1665 sub process_config_ignore {
1669 or dodie "Failed to read $config";
1672 if (/^((CONFIG\S*)=.*)/) {
1673 $config_ignore{$2} = $1;
1680 sub read_current_config {
1681 my ($config_ref) = @_;
1683 %{$config_ref} = ();
1684 undef %{$config_ref};
1686 my @key = keys %{$config_ref};
1688 print "did not delete!\n";
1691 open (IN, "$output_config");
1694 if (/^(CONFIG\S+)=(.*)/) {
1695 ${$config_ref}{$1} = $2;
1701 sub get_dependencies {
1704 my $arr = $dependency{$config};
1705 if (!defined($arr)) {
1711 foreach my $dep (@{$arr}) {
1712 print "ADD DEP $dep\n";
1713 @deps = (@deps, get_dependencies $dep);
1722 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1724 foreach my $config (@configs) {
1725 print OUT "$config_set{$config}\n";
1726 my @deps = get_dependencies $config;
1727 foreach my $dep (@deps) {
1728 print OUT "$config_set{$dep}\n";
1732 foreach my $config (keys %config_ignore) {
1733 print OUT "$config_ignore{$config}\n";
1741 sub compare_configs {
1744 foreach my $item (keys %a) {
1745 if (!defined($b{$item})) {
1746 print "diff $item\n";
1754 print "diff2 $keys[0]\n";
1756 return -1 if ($#keys >= 0);
1761 sub run_config_bisect_test {
1764 return run_bisect_test $type, "oldconfig";
1767 sub process_passed {
1770 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1771 # Passed! All these configs are part of a good compile.
1772 # Add them to the min options.
1773 foreach my $config (keys %configs) {
1774 if (defined($config_list{$config})) {
1775 doprint " removing $config\n";
1776 $config_ignore{$config} = $config_list{$config};
1777 delete $config_list{$config};
1780 doprint "config copied to $outputdir/config_good\n";
1781 run_command "cp -f $output_config $outputdir/config_good";
1784 sub process_failed {
1787 doprint "\n\n***************************************\n";
1788 doprint "Found bad config: $config\n";
1789 doprint "***************************************\n\n";
1792 sub run_config_bisect {
1794 my @start_list = keys %config_list;
1796 if ($#start_list < 0) {
1797 doprint "No more configs to test!!!\n";
1801 doprint "***** RUN TEST ***\n";
1802 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1806 my $count = $#start_list + 1;
1807 doprint " $count configs to test\n";
1809 my $half = int($#start_list / 2);
1812 my @tophalf = @start_list[0 .. $half];
1814 create_config @tophalf;
1815 read_current_config \%current_config;
1817 $count = $#tophalf + 1;
1818 doprint "Testing $count configs\n";
1820 # make sure we test something
1821 foreach my $config (@tophalf) {
1822 if (defined($current_config{$config})) {
1828 # try the other half
1829 doprint "Top half produced no set configs, trying bottom half\n";
1830 @tophalf = @start_list[$half + 1 .. $#start_list];
1831 create_config @tophalf;
1832 read_current_config \%current_config;
1833 foreach my $config (@tophalf) {
1834 if (defined($current_config{$config})) {
1840 doprint "Failed: Can't make new config with current configs\n";
1841 foreach my $config (@start_list) {
1842 doprint " CONFIG: $config\n";
1846 $count = $#tophalf + 1;
1847 doprint "Testing $count configs\n";
1850 $ret = run_config_bisect_test $type;
1851 if ($bisect_manual) {
1852 $ret = answer_bisect;
1855 process_passed %current_config;
1859 doprint "This config had a failure.\n";
1860 doprint "Removing these configs that were not set in this config:\n";
1861 doprint "config copied to $outputdir/config_bad\n";
1862 run_command "cp -f $output_config $outputdir/config_bad";
1864 # A config exists in this group that was bad.
1865 foreach my $config (keys %config_list) {
1866 if (!defined($current_config{$config})) {
1867 doprint " removing $config\n";
1868 delete $config_list{$config};
1872 @start_list = @tophalf;
1874 if ($#start_list == 0) {
1875 process_failed $start_list[0];
1879 # remove half the configs we are looking at and see if
1881 $half = int($#start_list / 2);
1882 } while ($#start_list > 0);
1884 # we found a single config, try it again unless we are running manually
1886 if ($bisect_manual) {
1887 process_failed $start_list[0];
1891 my @tophalf = @start_list[0 .. 0];
1893 $ret = run_config_bisect_test $type;
1895 process_passed %current_config;
1899 process_failed $start_list[0];
1906 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1908 my $tmpconfig = "$tmpdir/use_config";
1910 if (defined($config_bisect_good)) {
1911 process_config_ignore $config_bisect_good;
1914 # Make the file with the bad config and the min config
1915 if (defined($minconfig)) {
1916 # read the min config for things to ignore
1917 run_command "cp $minconfig $tmpconfig" or
1918 dodie "failed to copy $minconfig to $tmpconfig";
1924 if (defined($addconfig)) {
1925 run_command "cat $addconfig >> $tmpconfig" or
1926 dodie "failed to append $addconfig";
1929 if (-f $tmpconfig) {
1930 load_force_config($tmpconfig);
1931 process_config_ignore $tmpconfig;
1934 # now process the start config
1935 run_command "cp $start_config $output_config" or
1936 dodie "failed to copy $start_config to $output_config";
1938 # read directly what we want to check
1940 open (IN, $output_config)
1941 or dodie "faied to open $output_config";
1944 if (/^((CONFIG\S*)=.*)/) {
1945 $config_check{$2} = $1;
1950 # Now run oldconfig with the minconfig (and addconfigs)
1953 # check to see what we lost (or gained)
1954 open (IN, $output_config)
1955 or dodie "Failed to read $start_config";
1957 my %removed_configs;
1961 if (/^((CONFIG\S*)=.*)/) {
1962 # save off all options
1963 $config_set{$2} = $1;
1964 if (defined($config_check{$2})) {
1965 if (defined($config_ignore{$2})) {
1966 $removed_configs{$2} = $1;
1968 $config_list{$2} = $1;
1970 } elsif (!defined($config_ignore{$2})) {
1971 $added_configs{$2} = $1;
1972 $config_list{$2} = $1;
1978 my @confs = keys %removed_configs;
1980 doprint "Configs overridden by default configs and removed from check:\n";
1981 foreach my $config (@confs) {
1982 doprint " $config\n";
1985 @confs = keys %added_configs;
1987 doprint "Configs appearing in make oldconfig and added:\n";
1988 foreach my $config (@confs) {
1989 doprint " $config\n";
1996 # Sometimes kconfig does weird things. We must make sure
1997 # that the config we autocreate has everything we need
1998 # to test, otherwise we may miss testing configs, or
1999 # may not be able to create a new config.
2000 # Here we create a config with everything set.
2001 create_config (keys %config_list);
2002 read_current_config \%config_test;
2003 foreach my $config (keys %config_list) {
2004 if (!defined($config_test{$config})) {
2007 doprint "Configs not produced by kconfig (will not be checked):\n";
2009 doprint " $config\n";
2010 delete $config_list{$config};
2015 $ret = run_config_bisect;
2018 return $ret if ($ret < 0);
2023 sub patchcheck_reboot {
2024 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2027 wait_for_monitor $patchcheck_sleep_time;
2034 die "PATCHCHECK_START[$i] not defined\n"
2035 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2036 die "PATCHCHECK_TYPE[$i] not defined\n"
2037 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2039 my $start = $opt{"PATCHCHECK_START[$i]"};
2042 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2043 $end = $opt{"PATCHCHECK_END[$i]"};
2046 # Get the true sha1's since we can use things like HEAD~3
2047 $start = get_sha1($start);
2048 $end = get_sha1($end);
2050 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2052 # Can't have a test without having a test to run
2053 if ($type eq "test" && !defined($run_test)) {
2057 open (IN, "git log --pretty=oneline $end|") or
2058 dodie "could not get git list";
2064 $list[$#list+1] = $_;
2065 last if (/^$start/);
2069 if ($list[$#list] !~ /^$start/) {
2070 fail "SHA1 $start not found";
2073 # go backwards in the list
2074 @list = reverse @list;
2076 my $save_clean = $noclean;
2079 foreach my $item (@list) {
2081 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2083 doprint "\nProcessing commit $item\n\n";
2085 run_command "git checkout $sha1" or
2086 die "Failed to checkout $sha1";
2088 # only clean on the first and last patch
2089 if ($item eq $list[0] ||
2090 $item eq $list[$#list]) {
2091 $noclean = $save_clean;
2096 if (defined($minconfig)) {
2097 build "useconfig:$minconfig" or return 0;
2099 # ?? no config to use?
2100 build "oldconfig" or return 0;
2103 check_buildlog $sha1 or return 0;
2105 next if ($type eq "build");
2114 monitor or $failed = 1;
2116 if (!$failed && $type ne "boot"){
2117 do_run_test or $failed = 1;
2120 return 0 if ($failed);
2131 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2134 $ktest_config = $ARGV[0];
2135 if (! -f $ktest_config) {
2136 print "$ktest_config does not exist.\n";
2139 print "Create it? [Y/n] ";
2142 if ($ans =~ /^\s*$/) {
2145 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
2146 print "Please answer either 'y' or 'n'.\n";
2148 if ($ans !~ /^y$/i) {
2153 $ktest_config = "ktest.conf";
2156 if (! -f $ktest_config) {
2157 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2159 # Generated by ktest.pl
2161 # Define each test with TEST_START
2162 # The config options below it will override the defaults
2170 read_config $ktest_config;
2172 if (defined($opt{"LOG_FILE"})) {
2173 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2176 # Append any configs entered in manually to the config file.
2177 my @new_configs = keys %entered_configs;
2178 if ($#new_configs >= 0) {
2179 print "\nAppending entered in configs to $ktest_config\n";
2180 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2181 foreach my $config (@new_configs) {
2182 print OUT "$config = $entered_configs{$config}\n";
2183 $opt{$config} = $entered_configs{$config};
2187 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2188 unlink $opt{"LOG_FILE"};
2191 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2193 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2196 doprint "DEFAULT OPTIONS:\n";
2198 doprint "\nTEST $i OPTIONS";
2199 if (defined($repeat_tests{$i})) {
2200 $repeat = $repeat_tests{$i};
2201 doprint " ITERATE $repeat";
2206 foreach my $option (sort keys %opt) {
2208 if ($option =~ /\[(\d+)\]$/) {
2214 doprint "$option = $opt{$option}\n";
2218 sub __set_test_option {
2219 my ($name, $i) = @_;
2221 my $option = "$name\[$i\]";
2223 if (defined($opt{$option})) {
2224 return $opt{$option};
2227 foreach my $test (keys %repeat_tests) {
2229 $i < $test + $repeat_tests{$test}) {
2230 $option = "$name\[$test\]";
2231 if (defined($opt{$option})) {
2232 return $opt{$option};
2237 if (defined($opt{$name})) {
2244 sub set_test_option {
2245 my ($name, $i) = @_;
2247 my $option = __set_test_option($name, $i);
2248 return $option if (!defined($option));
2250 return eval_option($option, $i);
2253 # First we need to do is the builds
2254 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2258 my $makecmd = set_test_option("MAKE_CMD", $i);
2260 $machine = set_test_option("MACHINE", $i);
2261 $ssh_user = set_test_option("SSH_USER", $i);
2262 $tmpdir = set_test_option("TMP_DIR", $i);
2263 $outputdir = set_test_option("OUTPUT_DIR", $i);
2264 $builddir = set_test_option("BUILD_DIR", $i);
2265 $test_type = set_test_option("TEST_TYPE", $i);
2266 $build_type = set_test_option("BUILD_TYPE", $i);
2267 $build_options = set_test_option("BUILD_OPTIONS", $i);
2268 $pre_build = set_test_option("PRE_BUILD", $i);
2269 $post_build = set_test_option("POST_BUILD", $i);
2270 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
2271 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
2272 $power_cycle = set_test_option("POWER_CYCLE", $i);
2273 $reboot = set_test_option("REBOOT", $i);
2274 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2275 $minconfig = set_test_option("MIN_CONFIG", $i);
2276 $run_test = set_test_option("TEST", $i);
2277 $addconfig = set_test_option("ADD_CONFIG", $i);
2278 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2279 $grub_menu = set_test_option("GRUB_MENU", $i);
2280 $post_install = set_test_option("POST_INSTALL", $i);
2281 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2282 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2283 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2284 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2285 $power_off = set_test_option("POWER_OFF", $i);
2286 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2287 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
2288 $sleep_time = set_test_option("SLEEP_TIME", $i);
2289 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
2290 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
2291 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
2292 $bisect_skip = set_test_option("BISECT_SKIP", $i);
2293 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
2294 $store_failures = set_test_option("STORE_FAILURES", $i);
2295 $test_name = set_test_option("TEST_NAME", $i);
2296 $timeout = set_test_option("TIMEOUT", $i);
2297 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2298 $console = set_test_option("CONSOLE", $i);
2299 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
2300 $success_line = set_test_option("SUCCESS_LINE", $i);
2301 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2302 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
2303 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
2304 $build_target = set_test_option("BUILD_TARGET", $i);
2305 $ssh_exec = set_test_option("SSH_EXEC", $i);
2306 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
2307 $target_image = set_test_option("TARGET_IMAGE", $i);
2308 $localversion = set_test_option("LOCALVERSION", $i);
2310 chdir $builddir || die "can't change directory to $builddir";
2314 die "can't create $tmpdir";
2317 $ENV{"SSH_USER"} = $ssh_user;
2318 $ENV{"MACHINE"} = $machine;
2320 $target = "$ssh_user\@$machine";
2322 $buildlog = "$tmpdir/buildlog-$machine";
2323 $dmesg = "$tmpdir/dmesg-$machine";
2324 $make = "$makecmd O=$outputdir";
2325 $output_config = "$outputdir/.config";
2327 if ($reboot_type eq "grub") {
2328 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
2329 } elsif (!defined($reboot_script)) {
2330 dodie "REBOOT_SCRIPT not defined"
2333 my $run_type = $build_type;
2334 if ($test_type eq "patchcheck") {
2335 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2336 } elsif ($test_type eq "bisect") {
2337 $run_type = $opt{"BISECT_TYPE[$i]"};
2338 } elsif ($test_type eq "config_bisect") {
2339 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
2342 # mistake in config file?
2343 if (!defined($run_type)) {
2344 $run_type = "ERROR";
2348 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
2353 if (!defined($minconfig)) {
2354 $minconfig = $addconfig;
2356 } elsif (defined($addconfig)) {
2357 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
2358 dodie "Failed to create temp config";
2359 $minconfig = "$tmpdir/add_config";
2362 my $checkout = $opt{"CHECKOUT[$i]"};
2363 if (defined($checkout)) {
2364 run_command "git checkout $checkout" or
2365 die "failed to checkout $checkout";
2368 if ($test_type eq "bisect") {
2371 } elsif ($test_type eq "config_bisect") {
2374 } elsif ($test_type eq "patchcheck") {
2379 if ($build_type ne "nobuild") {
2380 build $build_type or next;
2383 if ($test_type ne "build") {
2390 monitor or $failed = 1;;
2392 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2393 do_run_test or $failed = 1;
2402 if ($opt{"POWEROFF_ON_SUCCESS"}) {
2404 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
2408 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";