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/\${MACHINE}";
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;
112 my $detect_triplefault;
115 my $stop_after_success;
116 my $stop_after_failure;
129 $config_help{"MACHINE"} = << "EOF"
130 The machine hostname that you will test.
133 $config_help{"SSH_USER"} = << "EOF"
134 The box is expected to have ssh on normal bootup, provide the user
135 (most likely root, since you need privileged operations)
138 $config_help{"BUILD_DIR"} = << "EOF"
139 The directory that contains the Linux source code (full path).
142 $config_help{"OUTPUT_DIR"} = << "EOF"
143 The directory that the objects will be built (full path).
144 (can not be same as BUILD_DIR)
147 $config_help{"BUILD_TARGET"} = << "EOF"
148 The location of the compiled file to copy to the target.
149 (relative to OUTPUT_DIR)
152 $config_help{"TARGET_IMAGE"} = << "EOF"
153 The place to put your image on the test machine.
156 $config_help{"POWER_CYCLE"} = << "EOF"
157 A script or command to reboot the box.
159 Here is a digital loggers power switch example
160 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
162 Here is an example to reboot a virtual box on the current host
163 with the name "Guest".
164 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
167 $config_help{"CONSOLE"} = << "EOF"
168 The script or command that reads the console
170 If you use ttywatch server, something like the following would work.
171 CONSOLE = nc -d localhost 3001
173 For a virtual machine with guest name "Guest".
174 CONSOLE = virsh console Guest
177 $config_help{"LOCALVERSION"} = << "EOF"
178 Required version ending to differentiate the test
179 from other linux builds on the system.
182 $config_help{"REBOOT_TYPE"} = << "EOF"
183 Way to reboot the box to the test kernel.
184 Only valid options so far are "grub" and "script".
186 If you specify grub, it will assume grub version 1
187 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
188 and select that target to reboot to the kernel. If this is not
189 your setup, then specify "script" and have a command or script
190 specified in REBOOT_SCRIPT to boot to the target.
192 The entry in /boot/grub/menu.lst must be entered in manually.
193 The test will not modify that file.
196 $config_help{"GRUB_MENU"} = << "EOF"
197 The grub title name for the test kernel to boot
198 (Only mandatory if REBOOT_TYPE = grub)
200 Note, ktest.pl will not update the grub menu.lst, you need to
201 manually add an option for the test. ktest.pl will search
202 the grub menu.lst for this option to find what kernel to
205 For example, if in the /boot/grub/menu.lst the test kernel title has:
208 GRUB_MENU = Test Kernel
211 $config_help{"REBOOT_SCRIPT"} = << "EOF"
212 A script to reboot the target into the test kernel
213 (Only mandatory if REBOOT_TYPE = script)
218 sub get_ktest_config {
221 return if (defined($opt{$config}));
223 if (defined($config_help{$config})) {
225 print $config_help{$config};
230 if (defined($default{$config})) {
231 print "\[$default{$config}\] ";
233 $entered_configs{$config} = <STDIN>;
234 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
235 if ($entered_configs{$config} =~ /^\s*$/) {
236 if ($default{$config}) {
237 $entered_configs{$config} = $default{$config};
239 print "Your answer can not be blank\n";
247 sub get_ktest_configs {
248 get_ktest_config("MACHINE");
249 get_ktest_config("SSH_USER");
250 get_ktest_config("BUILD_DIR");
251 get_ktest_config("OUTPUT_DIR");
252 get_ktest_config("BUILD_TARGET");
253 get_ktest_config("TARGET_IMAGE");
254 get_ktest_config("POWER_CYCLE");
255 get_ktest_config("CONSOLE");
256 get_ktest_config("LOCALVERSION");
258 my $rtype = $opt{"REBOOT_TYPE"};
260 if (!defined($rtype)) {
261 if (!defined($opt{"GRUB_MENU"})) {
262 get_ktest_config("REBOOT_TYPE");
263 $rtype = $entered_configs{"REBOOT_TYPE"};
269 if ($rtype eq "grub") {
270 get_ktest_config("GRUB_MENU");
272 get_ktest_config("REBOOT_SCRIPT");
276 sub process_variables {
280 # We want to check for '\', and it is just easier
281 # to check the previous characet of '$' and not need
282 # to worry if '$' is the first character. By adding
283 # a space to $value, we can just check [^\\]\$ and
284 # it will still work.
287 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
291 # append beginning of value to retval
292 $retval = "$retval$begin";
293 if (defined($variable{$var})) {
294 $retval = "$retval$variable{$var}";
296 # put back the origin piece.
297 $retval = "$retval\$\{$var\}";
301 $retval = "$retval$value";
303 # remove the space added in the beginning
310 my ($lvalue, $rvalue) = @_;
312 if (defined($opt{$lvalue})) {
313 die "Error: Option $lvalue defined more than once!\n";
315 if ($rvalue =~ /^\s*$/) {
316 delete $opt{$lvalue};
318 $rvalue = process_variables($rvalue);
319 $opt{$lvalue} = $rvalue;
324 my ($lvalue, $rvalue) = @_;
326 if ($rvalue =~ /^\s*$/) {
327 delete $variable{$lvalue};
329 $rvalue = process_variables($rvalue);
330 $variable{$lvalue} = $rvalue;
337 open(IN, $config) || die "can't read file $config";
340 $name =~ s,.*/(.*),$1,;
345 my $num_tests_set = 0;
351 # ignore blank lines and comments
352 next if (/^\s*$/ || /\s*\#/);
354 if (/^\s*TEST_START(.*)/) {
358 if ($num_tests_set) {
359 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
362 my $old_test_num = $test_num;
363 my $old_repeat = $repeat;
365 $test_num += $repeat;
369 if ($rest =~ /\s+SKIP(.*)/) {
376 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
379 $repeat_tests{"$test_num"} = $repeat;
382 if ($rest =~ /\s+SKIP(.*)/) {
387 if ($rest !~ /^\s*$/) {
388 die "$name: $.: Gargbage found after TEST_START\n$_";
392 $test_num = $old_test_num;
393 $repeat = $old_repeat;
396 } elsif (/^\s*DEFAULTS(.*)$/) {
401 if ($rest =~ /\s+SKIP(.*)/) {
408 if ($rest !~ /^\s*$/) {
409 die "$name: $.: Gargbage found after DEFAULTS\n$_";
412 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
420 ($lvalue eq "NUM_TESTS" ||
421 $lvalue eq "LOG_FILE" ||
422 $lvalue eq "CLEAR_LOG")) {
423 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
426 if ($lvalue eq "NUM_TESTS") {
428 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
431 die "$name: $.: NUM_TESTS must be set in default section\n";
436 if ($default || $lvalue =~ /\[\d+\]$/) {
437 set_value($lvalue, $rvalue);
439 my $val = "$lvalue\[$test_num\]";
440 set_value($val, $rvalue);
443 $repeats{$val} = $repeat;
446 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
452 # process config variables.
453 # Config variables are only active while reading the
454 # config and can be defined anywhere. They also ignore
455 # TEST_START and DEFAULTS, but are skipped if they are in
456 # on of these sections that have SKIP defined.
457 # The save variable can be
458 # defined multiple times and the new one simply overrides
460 set_variable($lvalue, $rvalue);
463 die "$name: $.: Garbage found in config\n$_";
470 $test_num += $repeat - 1;
471 $opt{"NUM_TESTS"} = $test_num;
474 # make sure we have all mandatory configs
479 foreach my $default (keys %default) {
480 if (!defined($opt{$default})) {
481 $opt{$default} = $default{$default};
487 my ($option, $i) = @_;
489 # Add space to evaluate the character before $
490 $option = " $option";
493 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
498 # Append beginning of line
499 $retval = "$retval$start";
501 # If the iteration option OPT[$i] exists, then use that.
502 # otherwise see if the default OPT (without [$i]) exists.
504 my $o = "$var\[$i\]";
506 if (defined($opt{$o})) {
508 $retval = "$retval$o";
509 } elsif (defined($opt{$var})) {
511 $retval = "$retval$o";
513 $retval = "$retval\$\{$var\}";
519 $retval = "$retval$option";
527 my ($option, $i) = @_;
531 # Since an option can evaluate to another option,
532 # keep iterating until we do not evaluate any more
535 while ($prev ne $option) {
536 # Check for recursive evaluations.
537 # 100 deep should be more than enough.
539 die "Over 100 evaluations accurred with $option\n" .
540 "Check for recursive variables\n";
543 $option = __eval_option($option, $i);
550 if (defined($opt{"LOG_FILE"})) {
551 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
558 if (defined($opt{"LOG_FILE"})) {
573 # try to reboot normally
574 if (run_command $reboot) {
575 if (defined($powercycle_after_reboot)) {
576 sleep $powercycle_after_reboot;
577 run_command "$power_cycle";
580 # nope? power cycle it.
581 run_command "$power_cycle";
588 return $test_type eq "build" ||
589 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
590 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
594 doprint "CRITICAL FAILURE... ", @_, "\n";
598 if ($reboot_on_error && !do_not_reboot) {
600 doprint "REBOOTING\n";
603 } elsif ($poweroff_on_error && defined($power_off)) {
604 doprint "POWERING OFF\n";
608 if (defined($opt{"LOG_FILE"})) {
609 print " See $opt{LOG_FILE} for more info.\n";
620 my $pid = open($fp, "$console|") or
621 dodie "Can't open console $console";
623 $flags = fcntl($fp, F_GETFL, 0) or
624 dodie "Can't get flags for the socket: $!";
625 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
626 dodie "Can't set flags for the socket: $!";
634 doprint "kill child process $pid\n";
642 if ($monitor_cnt++) {
645 $monitor_fp = \*MONFD;
646 $monitor_pid = open_console $monitor_fp;
650 open(MONFD, "Stop perl from warning about single use of MONFD");
654 if (--$monitor_cnt) {
657 close_console($monitor_fp, $monitor_pid);
660 sub wait_for_monitor {
664 doprint "** Wait for monitor to settle down **\n";
666 # read the monitor and wait for the system to calm down
668 $line = wait_for_input($monitor_fp, $time);
669 print "$line" if (defined($line));
670 } while (defined($line));
671 print "** Monitor flushed **\n";
676 if ($die_on_failure) {
684 # no need to reboot for just building.
685 if (!do_not_reboot) {
686 doprint "REBOOTING\n";
689 wait_for_monitor $sleep_time;
695 if (defined($test_name)) {
696 $name = " ($test_name)";
699 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
700 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
701 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
702 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
703 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
705 return 1 if (!defined($store_failures));
708 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
709 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
711 my $type = $build_type;
712 if ($type =~ /useconfig/) {
716 my $dir = "$machine-$test_type-$type-fail-$date";
717 my $faildir = "$store_failures/$dir";
721 die "can't create $faildir";
723 if (-f "$output_config") {
724 cp "$output_config", "$faildir/config" or
725 die "failed to copy .config";
728 cp $buildlog, "$faildir/buildlog" or
729 die "failed to move $buildlog";
732 cp $dmesg, "$faildir/dmesg" or
733 die "failed to move $dmesg";
736 doprint "*** Saved info to $faildir ***\n";
747 $command =~ s/\$SSH_USER/$ssh_user/g;
748 $command =~ s/\$MACHINE/$machine/g;
750 doprint("$command ... ");
752 $pid = open(CMD, "$command 2>&1 |") or
753 (fail "unable to exec $command" and return 0);
755 if (defined($opt{"LOG_FILE"})) {
756 open(LOG, ">>$opt{LOG_FILE}") or
757 dodie "failed to write to log";
761 if (defined($redirect)) {
762 open (RD, ">$redirect") or
763 dodie "failed to write to redirect $redirect";
768 print LOG if ($dolog);
776 close(LOG) if ($dolog);
777 close(RD) if ($dord);
790 my $cp_exec = $ssh_exec;
792 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
793 return run_command "$cp_exec";
797 my ($src, $dst) = @_;
798 my $cp_scp = $scp_to_target;
800 $cp_scp =~ s/\$SRC_FILE/$src/g;
801 $cp_scp =~ s/\$DST_FILE/$dst/g;
803 return run_command "$cp_scp";
808 if ($reboot_type ne "grub") {
811 return if (defined($grub_number));
813 doprint "Find grub menu ... ";
816 my $ssh_grub = $ssh_exec;
817 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
819 open(IN, "$ssh_grub |")
820 or die "unable to get menu.lst";
823 if (/^\s*title\s+$grub_menu\s*$/) {
826 } elsif (/^\s*title\s/) {
832 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
833 if ($grub_number < 0);
834 doprint "$grub_number\n";
839 my ($fp, $time) = @_;
845 if (!defined($time)) {
850 vec($rin, fileno($fp), 1) = 1;
851 $ready = select($rin, undef, undef, $time);
855 # try to read one char at a time
856 while (sysread $fp, $ch, 1) {
858 last if ($ch eq "\n");
861 if (!length($line)) {
869 if ($reboot_type eq "grub") {
870 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
874 run_command "$reboot_script";
880 doprint "git rev-list --max-count=1 $commit ... ";
881 my $sha1 = `git rev-list --max-count=1 $commit`;
888 dodie "Failed to get git $commit";
901 my $skip_call_trace = 0;
909 open(DMESG, "> $dmesg") or
910 die "unable to write to $dmesg";
916 my $monitor_start = time;
918 my $version_found = 0;
922 if ($bug && defined($stop_after_failure) &&
923 $stop_after_failure >= 0) {
924 my $time = $stop_after_failure - (time - $failure_start);
925 $line = wait_for_input($monitor_fp, $time);
926 if (!defined($line)) {
927 doprint "bug timed out after $booted_timeout seconds\n";
928 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
932 $line = wait_for_input($monitor_fp, $booted_timeout);
933 if (!defined($line)) {
934 my $s = $booted_timeout == 1 ? "" : "s";
935 doprint "Successful boot found: break after $booted_timeout second$s\n";
939 $line = wait_for_input($monitor_fp);
940 if (!defined($line)) {
941 my $s = $timeout == 1 ? "" : "s";
942 doprint "Timed out after $timeout second$s\n";
950 # we are not guaranteed to get a full line
953 if ($full_line =~ /$success_line/) {
955 $success_start = time;
958 if ($booted && defined($stop_after_success) &&
959 $stop_after_success >= 0) {
961 if ($now - $success_start >= $stop_after_success) {
962 doprint "Test forced to stop after $stop_after_success seconds after success\n";
967 if ($full_line =~ /\[ backtrace testing \]/) {
968 $skip_call_trace = 1;
971 if ($full_line =~ /call trace:/i) {
972 if (!$bug && !$skip_call_trace) {
974 $failure_start = time;
978 if ($bug && defined($stop_after_failure) &&
979 $stop_after_failure >= 0) {
981 if ($now - $failure_start >= $stop_after_failure) {
982 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
987 if ($full_line =~ /\[ end of backtrace testing \]/) {
988 $skip_call_trace = 0;
991 if ($full_line =~ /Kernel panic -/) {
992 $failure_start = time;
996 # Detect triple faults by testing the banner
997 if ($full_line =~ /\bLinux version (\S+).*\n/) {
998 if ($1 eq $version) {
1000 } elsif ($version_found && $detect_triplefault) {
1001 # We already booted into the kernel we are testing,
1002 # but now we booted into another kernel?
1003 # Consider this a triple fault.
1004 doprint "Aleady booted in Linux kernel $version, but now\n";
1005 doprint "we booted into Linux kernel $1.\n";
1006 doprint "Assuming that this is a triple fault.\n";
1007 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1012 if ($line =~ /\n/) {
1016 if ($stop_test_after > 0 && !$booted && !$bug) {
1017 if (time - $monitor_start > $stop_test_after) {
1018 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1027 return 0 if ($in_bisect);
1028 fail "failed - got a bug report" and return 0;
1032 return 0 if ($in_bisect);
1033 fail "failed - never got a boot prompt." and return 0;
1039 sub do_post_install {
1041 return if (!defined($post_install));
1043 my $cp_post_install = $post_install;
1044 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1045 run_command "$cp_post_install" or
1046 dodie "Failed to run post install";
1051 run_scp "$outputdir/$build_target", "$target_image" or
1052 dodie "failed to copy image";
1054 my $install_mods = 0;
1056 # should we process modules?
1058 open(IN, "$output_config") or dodie("Can't read config file");
1060 if (/CONFIG_MODULES(=y)?/) {
1061 $install_mods = 1 if (defined($1));
1067 if (!$install_mods) {
1069 doprint "No modules needed\n";
1073 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1074 dodie "Failed to install modules";
1076 my $modlib = "/lib/modules/$version";
1077 my $modtar = "ktest-mods.tar.bz2";
1079 run_ssh "rm -rf $modlib" or
1080 dodie "failed to remove old mods: $modlib";
1082 # would be nice if scp -r did not follow symbolic links
1083 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1084 dodie "making tarball";
1086 run_scp "$tmpdir/$modtar", "/tmp" or
1087 dodie "failed to copy modules";
1089 unlink "$tmpdir/$modtar";
1091 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1092 dodie "failed to tar modules";
1094 run_ssh "rm -f /tmp/$modtar";
1099 sub check_buildlog {
1102 my @files = `git show $patch | diffstat -l`;
1104 open(IN, "git show $patch |") or
1105 dodie "failed to show $patch";
1107 if (m,^--- a/(.*),) {
1109 $files[$#files] = $1;
1114 open(IN, $buildlog) or dodie "Can't open $buildlog";
1116 if (/^\s*(.*?):.*(warning|error)/) {
1118 foreach my $file (@files) {
1119 my $fullpath = "$builddir/$file";
1120 if ($file eq $err || $fullpath eq $err) {
1121 fail "$file built with warnings" and return 0;
1131 sub apply_min_config {
1132 my $outconfig = "$output_config.new";
1134 # Read the config file and remove anything that
1135 # is in the force_config hash (from minconfig and others)
1136 # then add the force config back.
1138 doprint "Applying minimum configurations into $output_config.new\n";
1140 open (OUT, ">$outconfig") or
1141 dodie "Can't create $outconfig";
1143 if (-f $output_config) {
1144 open (IN, $output_config) or
1145 dodie "Failed to open $output_config";
1147 if (/^(# )?(CONFIG_[^\s=]*)/) {
1148 next if (defined($force_config{$2}));
1154 foreach my $config (keys %force_config) {
1155 print OUT "$force_config{$config}\n";
1159 run_command "mv $outconfig $output_config";
1162 sub make_oldconfig {
1166 if (!run_command "$make oldnoconfig") {
1167 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1168 # try a yes '' | oldconfig
1169 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1170 run_command "yes '' | $make oldconfig" or
1171 dodie "failed make config oldconfig";
1175 # read a config file and use this to force new configs.
1176 sub load_force_config {
1179 open(IN, $config) or
1180 dodie "failed to read $config";
1183 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1184 $force_config{$1} = $_;
1185 } elsif (/^# (CONFIG_\S*) is not set/) {
1186 $force_config{$1} = $_;
1197 if (defined($pre_build)) {
1198 my $ret = run_command $pre_build;
1199 if (!$ret && defined($pre_build_die) &&
1201 dodie "failed to pre_build\n";
1205 if ($type =~ /^useconfig:(.*)/) {
1206 run_command "cp $1 $output_config" or
1207 dodie "could not copy $1 to .config";
1209 $type = "oldconfig";
1212 # old config can ask questions
1213 if ($type eq "oldconfig") {
1214 $type = "oldnoconfig";
1216 # allow for empty configs
1217 run_command "touch $output_config";
1219 run_command "mv $output_config $outputdir/config_temp" or
1220 dodie "moving .config";
1222 if (!$noclean && !run_command "$make mrproper") {
1223 dodie "make mrproper";
1226 run_command "mv $outputdir/config_temp $output_config" or
1227 dodie "moving config_temp";
1229 } elsif (!$noclean) {
1230 unlink "$output_config";
1231 run_command "$make mrproper" or
1232 dodie "make mrproper";
1235 # add something to distinguish this build
1236 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1237 print OUT "$localversion\n";
1240 if (defined($minconfig)) {
1241 load_force_config($minconfig);
1244 if ($type ne "oldnoconfig") {
1245 run_command "$make $type" or
1246 dodie "failed make config";
1248 # Run old config regardless, to enforce min configurations
1251 $redirect = "$buildlog";
1252 my $build_ret = run_command "$make $build_options";
1255 if (defined($post_build)) {
1256 my $ret = run_command $post_build;
1257 if (!$ret && defined($post_build_die) &&
1259 dodie "failed to post_build\n";
1264 # bisect may need this to pass
1265 return 0 if ($in_bisect);
1266 fail "failed build" and return 0;
1273 if (!run_ssh "halt" or defined($power_off)) {
1274 if (defined($poweroff_after_halt)) {
1275 sleep $poweroff_after_halt;
1276 run_command "$power_off";
1280 run_command "$power_off";
1291 if (defined($test_name)) {
1292 $name = " ($test_name)";
1295 doprint "\n\n*******************************************\n";
1296 doprint "*******************************************\n";
1297 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1298 doprint "*******************************************\n";
1299 doprint "*******************************************\n";
1301 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1302 doprint "Reboot and wait $sleep_time seconds\n";
1305 wait_for_monitor $sleep_time;
1311 # get the release name
1312 doprint "$make kernelrelease ... ";
1313 $version = `$make kernelrelease | tail -1`;
1315 doprint "$version\n";
1320 doprint "Pass or fail? [p/f]";
1323 if ($ans eq "p" || $ans eq "P") {
1325 } elsif ($ans eq "f" || $ans eq "F") {
1328 print "Please answer 'P' or 'F'\n";
1333 sub child_run_test {
1336 # child should have no power
1337 $reboot_on_error = 0;
1338 $poweroff_on_error = 0;
1339 $die_on_failure = 1;
1341 run_command $run_test or $failed = 1;
1347 sub child_finished {
1360 doprint "run test $run_test\n";
1364 $SIG{CHLD} = qw(child_finished);
1368 child_run_test if (!$child_pid);
1373 $line = wait_for_input($monitor_fp, 1);
1374 if (defined($line)) {
1376 # we are not guaranteed to get a full line
1377 $full_line .= $line;
1380 if ($full_line =~ /call trace:/i) {
1384 if ($full_line =~ /Kernel panic -/) {
1388 if ($line =~ /\n/) {
1392 } while (!$child_done && !$bug);
1395 my $failure_start = time;
1398 $line = wait_for_input($monitor_fp, 1);
1399 if (defined($line)) {
1403 if ($now - $failure_start >= $stop_after_failure) {
1406 } while (defined($line));
1408 doprint "Detected kernel crash!\n";
1409 # kill the child with extreme prejudice
1413 waitpid $child_pid, 0;
1416 if ($bug || $child_exit) {
1417 return 0 if $in_bisect;
1418 fail "test failed" and return 0;
1423 sub run_git_bisect {
1426 doprint "$command ... ";
1428 my $output = `$command 2>&1`;
1435 dodie "Failed to git bisect";
1438 doprint "SUCCESS\n";
1439 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1440 doprint "$1 [$2]\n";
1441 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1443 doprint "Found bad commit... $1\n";
1446 # we already logged it, just print it now.
1454 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1457 wait_for_monitor $bisect_sleep_time;
1461 # returns 1 on success, 0 on failure, -1 on skip
1462 sub run_bisect_test {
1463 my ($type, $buildtype) = @_;
1472 build $buildtype or $failed = 1;
1474 if ($type ne "build") {
1475 if ($failed && $bisect_skip) {
1479 dodie "Failed on build" if $failed;
1487 monitor or $failed = 1;
1489 if ($type ne "boot") {
1490 if ($failed && $bisect_skip) {
1496 dodie "Failed on boot" if $failed;
1498 do_run_test or $failed = 1;
1509 # reboot the box to a kernel we can ssh to
1510 if ($type ne "build") {
1520 my $buildtype = "oldconfig";
1522 # We should have a minconfig to use?
1523 if (defined($minconfig)) {
1524 $buildtype = "useconfig:$minconfig";
1527 my $ret = run_bisect_test $type, $buildtype;
1529 if ($bisect_manual) {
1530 $ret = answer_bisect;
1533 # Are we looking for where it worked, not failed?
1534 if ($reverse_bisect) {
1540 } elsif ($ret == 0) {
1542 } elsif ($bisect_skip) {
1543 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1553 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1554 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1555 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1557 my $good = $opt{"BISECT_GOOD[$i]"};
1558 my $bad = $opt{"BISECT_BAD[$i]"};
1559 my $type = $opt{"BISECT_TYPE[$i]"};
1560 my $start = $opt{"BISECT_START[$i]"};
1561 my $replay = $opt{"BISECT_REPLAY[$i]"};
1562 my $start_files = $opt{"BISECT_FILES[$i]"};
1564 if (defined($start_files)) {
1565 $start_files = " -- " . $start_files;
1570 # convert to true sha1's
1571 $good = get_sha1($good);
1572 $bad = get_sha1($bad);
1574 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1575 $opt{"BISECT_REVERSE[$i]"} == 1) {
1576 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1577 $reverse_bisect = 1;
1579 $reverse_bisect = 0;
1582 # Can't have a test without having a test to run
1583 if ($type eq "test" && !defined($run_test)) {
1587 my $check = $opt{"BISECT_CHECK[$i]"};
1588 if (defined($check) && $check ne "0") {
1591 my $head = get_sha1("HEAD");
1593 if ($check ne "good") {
1594 doprint "TESTING BISECT BAD [$bad]\n";
1595 run_command "git checkout $bad" or
1596 die "Failed to checkout $bad";
1598 $result = run_bisect $type;
1600 if ($result ne "bad") {
1601 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1605 if ($check ne "bad") {
1606 doprint "TESTING BISECT GOOD [$good]\n";
1607 run_command "git checkout $good" or
1608 die "Failed to checkout $good";
1610 $result = run_bisect $type;
1612 if ($result ne "good") {
1613 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1617 # checkout where we started
1618 run_command "git checkout $head" or
1619 die "Failed to checkout $head";
1622 run_command "git bisect start$start_files" or
1623 dodie "could not start bisect";
1625 run_command "git bisect good $good" or
1626 dodie "could not set bisect good to $good";
1628 run_git_bisect "git bisect bad $bad" or
1629 dodie "could not set bisect bad to $bad";
1631 if (defined($replay)) {
1632 run_command "git bisect replay $replay" or
1633 dodie "failed to run replay";
1636 if (defined($start)) {
1637 run_command "git checkout $start" or
1638 dodie "failed to checkout $start";
1643 $result = run_bisect $type;
1644 $test = run_git_bisect "git bisect $result";
1647 run_command "git bisect log" or
1648 dodie "could not capture git bisect log";
1650 run_command "git bisect reset" or
1651 dodie "could not reset git bisect";
1653 doprint "Bad commit was [$bisect_bad]\n";
1666 sub process_config_ignore {
1670 or dodie "Failed to read $config";
1673 if (/^((CONFIG\S*)=.*)/) {
1674 $config_ignore{$2} = $1;
1681 sub read_current_config {
1682 my ($config_ref) = @_;
1684 %{$config_ref} = ();
1685 undef %{$config_ref};
1687 my @key = keys %{$config_ref};
1689 print "did not delete!\n";
1692 open (IN, "$output_config");
1695 if (/^(CONFIG\S+)=(.*)/) {
1696 ${$config_ref}{$1} = $2;
1702 sub get_dependencies {
1705 my $arr = $dependency{$config};
1706 if (!defined($arr)) {
1712 foreach my $dep (@{$arr}) {
1713 print "ADD DEP $dep\n";
1714 @deps = (@deps, get_dependencies $dep);
1723 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1725 foreach my $config (@configs) {
1726 print OUT "$config_set{$config}\n";
1727 my @deps = get_dependencies $config;
1728 foreach my $dep (@deps) {
1729 print OUT "$config_set{$dep}\n";
1733 foreach my $config (keys %config_ignore) {
1734 print OUT "$config_ignore{$config}\n";
1742 sub compare_configs {
1745 foreach my $item (keys %a) {
1746 if (!defined($b{$item})) {
1747 print "diff $item\n";
1755 print "diff2 $keys[0]\n";
1757 return -1 if ($#keys >= 0);
1762 sub run_config_bisect_test {
1765 return run_bisect_test $type, "oldconfig";
1768 sub process_passed {
1771 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1772 # Passed! All these configs are part of a good compile.
1773 # Add them to the min options.
1774 foreach my $config (keys %configs) {
1775 if (defined($config_list{$config})) {
1776 doprint " removing $config\n";
1777 $config_ignore{$config} = $config_list{$config};
1778 delete $config_list{$config};
1781 doprint "config copied to $outputdir/config_good\n";
1782 run_command "cp -f $output_config $outputdir/config_good";
1785 sub process_failed {
1788 doprint "\n\n***************************************\n";
1789 doprint "Found bad config: $config\n";
1790 doprint "***************************************\n\n";
1793 sub run_config_bisect {
1795 my @start_list = keys %config_list;
1797 if ($#start_list < 0) {
1798 doprint "No more configs to test!!!\n";
1802 doprint "***** RUN TEST ***\n";
1803 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1807 my $count = $#start_list + 1;
1808 doprint " $count configs to test\n";
1810 my $half = int($#start_list / 2);
1813 my @tophalf = @start_list[0 .. $half];
1815 create_config @tophalf;
1816 read_current_config \%current_config;
1818 $count = $#tophalf + 1;
1819 doprint "Testing $count configs\n";
1821 # make sure we test something
1822 foreach my $config (@tophalf) {
1823 if (defined($current_config{$config})) {
1829 # try the other half
1830 doprint "Top half produced no set configs, trying bottom half\n";
1831 @tophalf = @start_list[$half + 1 .. $#start_list];
1832 create_config @tophalf;
1833 read_current_config \%current_config;
1834 foreach my $config (@tophalf) {
1835 if (defined($current_config{$config})) {
1841 doprint "Failed: Can't make new config with current configs\n";
1842 foreach my $config (@start_list) {
1843 doprint " CONFIG: $config\n";
1847 $count = $#tophalf + 1;
1848 doprint "Testing $count configs\n";
1851 $ret = run_config_bisect_test $type;
1852 if ($bisect_manual) {
1853 $ret = answer_bisect;
1856 process_passed %current_config;
1860 doprint "This config had a failure.\n";
1861 doprint "Removing these configs that were not set in this config:\n";
1862 doprint "config copied to $outputdir/config_bad\n";
1863 run_command "cp -f $output_config $outputdir/config_bad";
1865 # A config exists in this group that was bad.
1866 foreach my $config (keys %config_list) {
1867 if (!defined($current_config{$config})) {
1868 doprint " removing $config\n";
1869 delete $config_list{$config};
1873 @start_list = @tophalf;
1875 if ($#start_list == 0) {
1876 process_failed $start_list[0];
1880 # remove half the configs we are looking at and see if
1882 $half = int($#start_list / 2);
1883 } while ($#start_list > 0);
1885 # we found a single config, try it again unless we are running manually
1887 if ($bisect_manual) {
1888 process_failed $start_list[0];
1892 my @tophalf = @start_list[0 .. 0];
1894 $ret = run_config_bisect_test $type;
1896 process_passed %current_config;
1900 process_failed $start_list[0];
1907 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1909 my $tmpconfig = "$tmpdir/use_config";
1911 if (defined($config_bisect_good)) {
1912 process_config_ignore $config_bisect_good;
1915 # Make the file with the bad config and the min config
1916 if (defined($minconfig)) {
1917 # read the min config for things to ignore
1918 run_command "cp $minconfig $tmpconfig" or
1919 dodie "failed to copy $minconfig to $tmpconfig";
1925 if (defined($addconfig)) {
1926 run_command "cat $addconfig >> $tmpconfig" or
1927 dodie "failed to append $addconfig";
1930 if (-f $tmpconfig) {
1931 load_force_config($tmpconfig);
1932 process_config_ignore $tmpconfig;
1935 # now process the start config
1936 run_command "cp $start_config $output_config" or
1937 dodie "failed to copy $start_config to $output_config";
1939 # read directly what we want to check
1941 open (IN, $output_config)
1942 or dodie "faied to open $output_config";
1945 if (/^((CONFIG\S*)=.*)/) {
1946 $config_check{$2} = $1;
1951 # Now run oldconfig with the minconfig (and addconfigs)
1954 # check to see what we lost (or gained)
1955 open (IN, $output_config)
1956 or dodie "Failed to read $start_config";
1958 my %removed_configs;
1962 if (/^((CONFIG\S*)=.*)/) {
1963 # save off all options
1964 $config_set{$2} = $1;
1965 if (defined($config_check{$2})) {
1966 if (defined($config_ignore{$2})) {
1967 $removed_configs{$2} = $1;
1969 $config_list{$2} = $1;
1971 } elsif (!defined($config_ignore{$2})) {
1972 $added_configs{$2} = $1;
1973 $config_list{$2} = $1;
1979 my @confs = keys %removed_configs;
1981 doprint "Configs overridden by default configs and removed from check:\n";
1982 foreach my $config (@confs) {
1983 doprint " $config\n";
1986 @confs = keys %added_configs;
1988 doprint "Configs appearing in make oldconfig and added:\n";
1989 foreach my $config (@confs) {
1990 doprint " $config\n";
1997 # Sometimes kconfig does weird things. We must make sure
1998 # that the config we autocreate has everything we need
1999 # to test, otherwise we may miss testing configs, or
2000 # may not be able to create a new config.
2001 # Here we create a config with everything set.
2002 create_config (keys %config_list);
2003 read_current_config \%config_test;
2004 foreach my $config (keys %config_list) {
2005 if (!defined($config_test{$config})) {
2008 doprint "Configs not produced by kconfig (will not be checked):\n";
2010 doprint " $config\n";
2011 delete $config_list{$config};
2016 $ret = run_config_bisect;
2019 return $ret if ($ret < 0);
2024 sub patchcheck_reboot {
2025 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2028 wait_for_monitor $patchcheck_sleep_time;
2035 die "PATCHCHECK_START[$i] not defined\n"
2036 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2037 die "PATCHCHECK_TYPE[$i] not defined\n"
2038 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2040 my $start = $opt{"PATCHCHECK_START[$i]"};
2043 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2044 $end = $opt{"PATCHCHECK_END[$i]"};
2047 # Get the true sha1's since we can use things like HEAD~3
2048 $start = get_sha1($start);
2049 $end = get_sha1($end);
2051 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2053 # Can't have a test without having a test to run
2054 if ($type eq "test" && !defined($run_test)) {
2058 open (IN, "git log --pretty=oneline $end|") or
2059 dodie "could not get git list";
2065 $list[$#list+1] = $_;
2066 last if (/^$start/);
2070 if ($list[$#list] !~ /^$start/) {
2071 fail "SHA1 $start not found";
2074 # go backwards in the list
2075 @list = reverse @list;
2077 my $save_clean = $noclean;
2078 my %ignored_warnings;
2080 if (defined($ignore_warnings)) {
2081 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2082 $ignored_warnings{$sha1} = 1;
2087 foreach my $item (@list) {
2089 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2091 doprint "\nProcessing commit $item\n\n";
2093 run_command "git checkout $sha1" or
2094 die "Failed to checkout $sha1";
2096 # only clean on the first and last patch
2097 if ($item eq $list[0] ||
2098 $item eq $list[$#list]) {
2099 $noclean = $save_clean;
2104 if (defined($minconfig)) {
2105 build "useconfig:$minconfig" or return 0;
2107 # ?? no config to use?
2108 build "oldconfig" or return 0;
2112 if (!defined($ignored_warnings{$sha1})) {
2113 check_buildlog $sha1 or return 0;
2116 next if ($type eq "build");
2125 monitor or $failed = 1;
2127 if (!$failed && $type ne "boot"){
2128 do_run_test or $failed = 1;
2131 return 0 if ($failed);
2142 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2145 $ktest_config = $ARGV[0];
2146 if (! -f $ktest_config) {
2147 print "$ktest_config does not exist.\n";
2150 print "Create it? [Y/n] ";
2153 if ($ans =~ /^\s*$/) {
2156 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
2157 print "Please answer either 'y' or 'n'.\n";
2159 if ($ans !~ /^y$/i) {
2164 $ktest_config = "ktest.conf";
2167 if (! -f $ktest_config) {
2168 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2170 # Generated by ktest.pl
2172 # Define each test with TEST_START
2173 # The config options below it will override the defaults
2181 read_config $ktest_config;
2183 if (defined($opt{"LOG_FILE"})) {
2184 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2187 # Append any configs entered in manually to the config file.
2188 my @new_configs = keys %entered_configs;
2189 if ($#new_configs >= 0) {
2190 print "\nAppending entered in configs to $ktest_config\n";
2191 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2192 foreach my $config (@new_configs) {
2193 print OUT "$config = $entered_configs{$config}\n";
2194 $opt{$config} = $entered_configs{$config};
2198 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2199 unlink $opt{"LOG_FILE"};
2202 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2204 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2207 doprint "DEFAULT OPTIONS:\n";
2209 doprint "\nTEST $i OPTIONS";
2210 if (defined($repeat_tests{$i})) {
2211 $repeat = $repeat_tests{$i};
2212 doprint " ITERATE $repeat";
2217 foreach my $option (sort keys %opt) {
2219 if ($option =~ /\[(\d+)\]$/) {
2225 doprint "$option = $opt{$option}\n";
2229 sub __set_test_option {
2230 my ($name, $i) = @_;
2232 my $option = "$name\[$i\]";
2234 if (defined($opt{$option})) {
2235 return $opt{$option};
2238 foreach my $test (keys %repeat_tests) {
2240 $i < $test + $repeat_tests{$test}) {
2241 $option = "$name\[$test\]";
2242 if (defined($opt{$option})) {
2243 return $opt{$option};
2248 if (defined($opt{$name})) {
2255 sub set_test_option {
2256 my ($name, $i) = @_;
2258 my $option = __set_test_option($name, $i);
2259 return $option if (!defined($option));
2261 return eval_option($option, $i);
2264 # First we need to do is the builds
2265 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2269 my $makecmd = set_test_option("MAKE_CMD", $i);
2271 $machine = set_test_option("MACHINE", $i);
2272 $ssh_user = set_test_option("SSH_USER", $i);
2273 $tmpdir = set_test_option("TMP_DIR", $i);
2274 $outputdir = set_test_option("OUTPUT_DIR", $i);
2275 $builddir = set_test_option("BUILD_DIR", $i);
2276 $test_type = set_test_option("TEST_TYPE", $i);
2277 $build_type = set_test_option("BUILD_TYPE", $i);
2278 $build_options = set_test_option("BUILD_OPTIONS", $i);
2279 $pre_build = set_test_option("PRE_BUILD", $i);
2280 $post_build = set_test_option("POST_BUILD", $i);
2281 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
2282 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
2283 $power_cycle = set_test_option("POWER_CYCLE", $i);
2284 $reboot = set_test_option("REBOOT", $i);
2285 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2286 $minconfig = set_test_option("MIN_CONFIG", $i);
2287 $run_test = set_test_option("TEST", $i);
2288 $addconfig = set_test_option("ADD_CONFIG", $i);
2289 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2290 $grub_menu = set_test_option("GRUB_MENU", $i);
2291 $post_install = set_test_option("POST_INSTALL", $i);
2292 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2293 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2294 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2295 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2296 $power_off = set_test_option("POWER_OFF", $i);
2297 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2298 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
2299 $sleep_time = set_test_option("SLEEP_TIME", $i);
2300 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
2301 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
2302 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
2303 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
2304 $bisect_skip = set_test_option("BISECT_SKIP", $i);
2305 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
2306 $store_failures = set_test_option("STORE_FAILURES", $i);
2307 $test_name = set_test_option("TEST_NAME", $i);
2308 $timeout = set_test_option("TIMEOUT", $i);
2309 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2310 $console = set_test_option("CONSOLE", $i);
2311 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
2312 $success_line = set_test_option("SUCCESS_LINE", $i);
2313 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2314 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
2315 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
2316 $build_target = set_test_option("BUILD_TARGET", $i);
2317 $ssh_exec = set_test_option("SSH_EXEC", $i);
2318 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
2319 $target_image = set_test_option("TARGET_IMAGE", $i);
2320 $localversion = set_test_option("LOCALVERSION", $i);
2322 chdir $builddir || die "can't change directory to $builddir";
2326 die "can't create $tmpdir";
2329 $ENV{"SSH_USER"} = $ssh_user;
2330 $ENV{"MACHINE"} = $machine;
2332 $target = "$ssh_user\@$machine";
2334 $buildlog = "$tmpdir/buildlog-$machine";
2335 $dmesg = "$tmpdir/dmesg-$machine";
2336 $make = "$makecmd O=$outputdir";
2337 $output_config = "$outputdir/.config";
2339 if ($reboot_type eq "grub") {
2340 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
2341 } elsif (!defined($reboot_script)) {
2342 dodie "REBOOT_SCRIPT not defined"
2345 my $run_type = $build_type;
2346 if ($test_type eq "patchcheck") {
2347 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2348 } elsif ($test_type eq "bisect") {
2349 $run_type = $opt{"BISECT_TYPE[$i]"};
2350 } elsif ($test_type eq "config_bisect") {
2351 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
2354 # mistake in config file?
2355 if (!defined($run_type)) {
2356 $run_type = "ERROR";
2360 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
2365 if (!defined($minconfig)) {
2366 $minconfig = $addconfig;
2368 } elsif (defined($addconfig)) {
2369 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
2370 dodie "Failed to create temp config";
2371 $minconfig = "$tmpdir/add_config";
2374 my $checkout = $opt{"CHECKOUT[$i]"};
2375 if (defined($checkout)) {
2376 run_command "git checkout $checkout" or
2377 die "failed to checkout $checkout";
2380 if ($test_type eq "bisect") {
2383 } elsif ($test_type eq "config_bisect") {
2386 } elsif ($test_type eq "patchcheck") {
2391 if ($build_type ne "nobuild") {
2392 build $build_type or next;
2395 if ($test_type ne "build") {
2402 monitor or $failed = 1;;
2404 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2405 do_run_test or $failed = 1;
2414 if ($opt{"POWEROFF_ON_SUCCESS"}) {
2416 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
2420 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";