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{"NO_INSTALL"} = 0;
46 $default{"BOOTED_TIMEOUT"} = 1;
47 $default{"DIE_ON_FAILURE"} = 1;
48 $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
49 $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
50 $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
51 $default{"STOP_AFTER_SUCCESS"} = 10;
52 $default{"STOP_AFTER_FAILURE"} = 60;
53 $default{"STOP_TEST_AFTER"} = 600;
54 $default{"LOCALVERSION"} = "-test";
76 my $poweroff_on_error;
78 my $powercycle_after_reboot;
79 my $poweroff_after_halt;
92 my $start_minconfig_defined;
101 my $config_bisect_good;
102 my $in_patchcheck = 0;
111 my $bisect_sleep_time;
112 my $patchcheck_sleep_time;
118 my $detect_triplefault;
121 my $stop_after_success;
122 my $stop_after_failure;
135 $config_help{"MACHINE"} = << "EOF"
136 The machine hostname that you will test.
139 $config_help{"SSH_USER"} = << "EOF"
140 The box is expected to have ssh on normal bootup, provide the user
141 (most likely root, since you need privileged operations)
144 $config_help{"BUILD_DIR"} = << "EOF"
145 The directory that contains the Linux source code (full path).
148 $config_help{"OUTPUT_DIR"} = << "EOF"
149 The directory that the objects will be built (full path).
150 (can not be same as BUILD_DIR)
153 $config_help{"BUILD_TARGET"} = << "EOF"
154 The location of the compiled file to copy to the target.
155 (relative to OUTPUT_DIR)
158 $config_help{"TARGET_IMAGE"} = << "EOF"
159 The place to put your image on the test machine.
162 $config_help{"POWER_CYCLE"} = << "EOF"
163 A script or command to reboot the box.
165 Here is a digital loggers power switch example
166 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
168 Here is an example to reboot a virtual box on the current host
169 with the name "Guest".
170 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
173 $config_help{"CONSOLE"} = << "EOF"
174 The script or command that reads the console
176 If you use ttywatch server, something like the following would work.
177 CONSOLE = nc -d localhost 3001
179 For a virtual machine with guest name "Guest".
180 CONSOLE = virsh console Guest
183 $config_help{"LOCALVERSION"} = << "EOF"
184 Required version ending to differentiate the test
185 from other linux builds on the system.
188 $config_help{"REBOOT_TYPE"} = << "EOF"
189 Way to reboot the box to the test kernel.
190 Only valid options so far are "grub" and "script".
192 If you specify grub, it will assume grub version 1
193 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
194 and select that target to reboot to the kernel. If this is not
195 your setup, then specify "script" and have a command or script
196 specified in REBOOT_SCRIPT to boot to the target.
198 The entry in /boot/grub/menu.lst must be entered in manually.
199 The test will not modify that file.
202 $config_help{"GRUB_MENU"} = << "EOF"
203 The grub title name for the test kernel to boot
204 (Only mandatory if REBOOT_TYPE = grub)
206 Note, ktest.pl will not update the grub menu.lst, you need to
207 manually add an option for the test. ktest.pl will search
208 the grub menu.lst for this option to find what kernel to
211 For example, if in the /boot/grub/menu.lst the test kernel title has:
214 GRUB_MENU = Test Kernel
217 $config_help{"REBOOT_SCRIPT"} = << "EOF"
218 A script to reboot the target into the test kernel
219 (Only mandatory if REBOOT_TYPE = script)
229 print "$prompt [Y/n] ";
232 if ($ans =~ /^\s*$/) {
235 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
236 print "Please answer either 'y' or 'n'.\n";
238 if ($ans !~ /^y$/i) {
244 sub get_ktest_config {
247 return if (defined($opt{$config}));
249 if (defined($config_help{$config})) {
251 print $config_help{$config};
256 if (defined($default{$config})) {
257 print "\[$default{$config}\] ";
259 $entered_configs{$config} = <STDIN>;
260 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
261 if ($entered_configs{$config} =~ /^\s*$/) {
262 if ($default{$config}) {
263 $entered_configs{$config} = $default{$config};
265 print "Your answer can not be blank\n";
273 sub get_ktest_configs {
274 get_ktest_config("MACHINE");
275 get_ktest_config("SSH_USER");
276 get_ktest_config("BUILD_DIR");
277 get_ktest_config("OUTPUT_DIR");
278 get_ktest_config("BUILD_TARGET");
279 get_ktest_config("TARGET_IMAGE");
280 get_ktest_config("POWER_CYCLE");
281 get_ktest_config("CONSOLE");
282 get_ktest_config("LOCALVERSION");
284 my $rtype = $opt{"REBOOT_TYPE"};
286 if (!defined($rtype)) {
287 if (!defined($opt{"GRUB_MENU"})) {
288 get_ktest_config("REBOOT_TYPE");
289 $rtype = $entered_configs{"REBOOT_TYPE"};
295 if ($rtype eq "grub") {
296 get_ktest_config("GRUB_MENU");
298 get_ktest_config("REBOOT_SCRIPT");
302 sub process_variables {
306 # We want to check for '\', and it is just easier
307 # to check the previous characet of '$' and not need
308 # to worry if '$' is the first character. By adding
309 # a space to $value, we can just check [^\\]\$ and
310 # it will still work.
313 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
317 # append beginning of value to retval
318 $retval = "$retval$begin";
319 if (defined($variable{$var})) {
320 $retval = "$retval$variable{$var}";
322 # put back the origin piece.
323 $retval = "$retval\$\{$var\}";
327 $retval = "$retval$value";
329 # remove the space added in the beginning
336 my ($lvalue, $rvalue) = @_;
338 if (defined($opt{$lvalue})) {
339 die "Error: Option $lvalue defined more than once!\n";
341 if ($rvalue =~ /^\s*$/) {
342 delete $opt{$lvalue};
344 $rvalue = process_variables($rvalue);
345 $opt{$lvalue} = $rvalue;
350 my ($lvalue, $rvalue) = @_;
352 if ($rvalue =~ /^\s*$/) {
353 delete $variable{$lvalue};
355 $rvalue = process_variables($rvalue);
356 $variable{$lvalue} = $rvalue;
363 open(IN, $config) || die "can't read file $config";
366 $name =~ s,.*/(.*),$1,;
371 my $num_tests_set = 0;
378 # ignore blank lines and comments
379 next if (/^\s*$/ || /\s*\#/);
381 if (/^\s*TEST_START(.*)/) {
385 if ($num_tests_set) {
386 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
389 my $old_test_num = $test_num;
390 my $old_repeat = $repeat;
392 $test_num += $repeat;
396 if ($rest =~ /\s+SKIP(.*)/) {
404 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
407 $repeat_tests{"$test_num"} = $repeat;
410 if ($rest =~ /\s+SKIP(.*)/) {
415 if ($rest !~ /^\s*$/) {
416 die "$name: $.: Gargbage found after TEST_START\n$_";
420 $test_num = $old_test_num;
421 $repeat = $old_repeat;
424 } elsif (/^\s*DEFAULTS(.*)$/) {
429 if ($rest =~ /\s+SKIP(.*)/) {
436 if ($rest !~ /^\s*$/) {
437 die "$name: $.: Gargbage found after DEFAULTS\n$_";
440 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
448 ($lvalue eq "NUM_TESTS" ||
449 $lvalue eq "LOG_FILE" ||
450 $lvalue eq "CLEAR_LOG")) {
451 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
454 if ($lvalue eq "NUM_TESTS") {
456 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
459 die "$name: $.: NUM_TESTS must be set in default section\n";
464 if ($default || $lvalue =~ /\[\d+\]$/) {
465 set_value($lvalue, $rvalue);
467 my $val = "$lvalue\[$test_num\]";
468 set_value($val, $rvalue);
471 $repeats{$val} = $repeat;
474 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
480 # process config variables.
481 # Config variables are only active while reading the
482 # config and can be defined anywhere. They also ignore
483 # TEST_START and DEFAULTS, but are skipped if they are in
484 # on of these sections that have SKIP defined.
485 # The save variable can be
486 # defined multiple times and the new one simply overrides
488 set_variable($lvalue, $rvalue);
491 die "$name: $.: Garbage found in config\n$_";
498 $test_num += $repeat - 1;
499 $opt{"NUM_TESTS"} = $test_num;
502 # make sure we have all mandatory configs
505 # was a test specified?
507 print "No test case specified.\n";
508 print "What test case would you like to run?\n";
511 $default{"TEST_TYPE"} = $ans;
516 foreach my $default (keys %default) {
517 if (!defined($opt{$default})) {
518 $opt{$default} = $default{$default};
524 my ($option, $i) = @_;
526 # Add space to evaluate the character before $
527 $option = " $option";
530 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
535 # Append beginning of line
536 $retval = "$retval$start";
538 # If the iteration option OPT[$i] exists, then use that.
539 # otherwise see if the default OPT (without [$i]) exists.
541 my $o = "$var\[$i\]";
543 if (defined($opt{$o})) {
545 $retval = "$retval$o";
546 } elsif (defined($opt{$var})) {
548 $retval = "$retval$o";
550 $retval = "$retval\$\{$var\}";
556 $retval = "$retval$option";
564 my ($option, $i) = @_;
568 # Since an option can evaluate to another option,
569 # keep iterating until we do not evaluate any more
572 while ($prev ne $option) {
573 # Check for recursive evaluations.
574 # 100 deep should be more than enough.
576 die "Over 100 evaluations accurred with $option\n" .
577 "Check for recursive variables\n";
580 $option = __eval_option($option, $i);
587 if (defined($opt{"LOG_FILE"})) {
588 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
595 if (defined($opt{"LOG_FILE"})) {
610 sub wait_for_monitor;
615 # try to reboot normally
616 if (run_command $reboot) {
617 if (defined($powercycle_after_reboot)) {
618 sleep $powercycle_after_reboot;
619 run_command "$power_cycle";
622 # nope? power cycle it.
623 run_command "$power_cycle";
626 if (defined($time)) {
628 wait_for_monitor $time;
636 return $test_type eq "build" ||
637 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
638 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
642 doprint "CRITICAL FAILURE... ", @_, "\n";
646 if ($reboot_on_error && !do_not_reboot) {
648 doprint "REBOOTING\n";
651 } elsif ($poweroff_on_error && defined($power_off)) {
652 doprint "POWERING OFF\n";
656 if (defined($opt{"LOG_FILE"})) {
657 print " See $opt{LOG_FILE} for more info.\n";
668 my $pid = open($fp, "$console|") or
669 dodie "Can't open console $console";
671 $flags = fcntl($fp, F_GETFL, 0) or
672 dodie "Can't get flags for the socket: $!";
673 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
674 dodie "Can't set flags for the socket: $!";
682 doprint "kill child process $pid\n";
690 if ($monitor_cnt++) {
693 $monitor_fp = \*MONFD;
694 $monitor_pid = open_console $monitor_fp;
698 open(MONFD, "Stop perl from warning about single use of MONFD");
702 if (--$monitor_cnt) {
705 close_console($monitor_fp, $monitor_pid);
708 sub wait_for_monitor {
712 doprint "** Wait for monitor to settle down **\n";
714 # read the monitor and wait for the system to calm down
716 $line = wait_for_input($monitor_fp, $time);
717 print "$line" if (defined($line));
718 } while (defined($line));
719 print "** Monitor flushed **\n";
724 if ($die_on_failure) {
732 # no need to reboot for just building.
733 if (!do_not_reboot) {
734 doprint "REBOOTING\n";
740 if (defined($test_name)) {
741 $name = " ($test_name)";
744 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
745 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
746 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
747 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
748 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
750 return 1 if (!defined($store_failures));
753 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
754 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
756 my $type = $build_type;
757 if ($type =~ /useconfig/) {
761 my $dir = "$machine-$test_type-$type-fail-$date";
762 my $faildir = "$store_failures/$dir";
766 die "can't create $faildir";
768 if (-f "$output_config") {
769 cp "$output_config", "$faildir/config" or
770 die "failed to copy .config";
773 cp $buildlog, "$faildir/buildlog" or
774 die "failed to move $buildlog";
777 cp $dmesg, "$faildir/dmesg" or
778 die "failed to move $dmesg";
781 doprint "*** Saved info to $faildir ***\n";
792 $command =~ s/\$SSH_USER/$ssh_user/g;
793 $command =~ s/\$MACHINE/$machine/g;
795 doprint("$command ... ");
797 $pid = open(CMD, "$command 2>&1 |") or
798 (fail "unable to exec $command" and return 0);
800 if (defined($opt{"LOG_FILE"})) {
801 open(LOG, ">>$opt{LOG_FILE}") or
802 dodie "failed to write to log";
806 if (defined($redirect)) {
807 open (RD, ">$redirect") or
808 dodie "failed to write to redirect $redirect";
813 print LOG if ($dolog);
821 close(LOG) if ($dolog);
822 close(RD) if ($dord);
835 my $cp_exec = $ssh_exec;
837 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
838 return run_command "$cp_exec";
842 my ($src, $dst) = @_;
843 my $cp_scp = $scp_to_target;
845 $cp_scp =~ s/\$SRC_FILE/$src/g;
846 $cp_scp =~ s/\$DST_FILE/$dst/g;
848 return run_command "$cp_scp";
853 if ($reboot_type ne "grub") {
856 return if (defined($grub_number));
858 doprint "Find grub menu ... ";
861 my $ssh_grub = $ssh_exec;
862 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
864 open(IN, "$ssh_grub |")
865 or die "unable to get menu.lst";
870 if (/^\s*title\s+$grub_menu\s*$/) {
874 } elsif (/^\s*title\s/) {
880 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
882 doprint "$grub_number\n";
887 my ($fp, $time) = @_;
893 if (!defined($time)) {
898 vec($rin, fileno($fp), 1) = 1;
899 $ready = select($rin, undef, undef, $time);
903 # try to read one char at a time
904 while (sysread $fp, $ch, 1) {
906 last if ($ch eq "\n");
909 if (!length($line)) {
917 if ($reboot_type eq "grub") {
918 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
922 run_command "$reboot_script";
928 doprint "git rev-list --max-count=1 $commit ... ";
929 my $sha1 = `git rev-list --max-count=1 $commit`;
936 dodie "Failed to get git $commit";
949 my $skip_call_trace = 0;
957 open(DMESG, "> $dmesg") or
958 die "unable to write to $dmesg";
964 my $monitor_start = time;
966 my $version_found = 0;
970 if ($bug && defined($stop_after_failure) &&
971 $stop_after_failure >= 0) {
972 my $time = $stop_after_failure - (time - $failure_start);
973 $line = wait_for_input($monitor_fp, $time);
974 if (!defined($line)) {
975 doprint "bug timed out after $booted_timeout seconds\n";
976 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
980 $line = wait_for_input($monitor_fp, $booted_timeout);
981 if (!defined($line)) {
982 my $s = $booted_timeout == 1 ? "" : "s";
983 doprint "Successful boot found: break after $booted_timeout second$s\n";
987 $line = wait_for_input($monitor_fp);
988 if (!defined($line)) {
989 my $s = $timeout == 1 ? "" : "s";
990 doprint "Timed out after $timeout second$s\n";
998 # we are not guaranteed to get a full line
1001 if ($full_line =~ /$success_line/) {
1003 $success_start = time;
1006 if ($booted && defined($stop_after_success) &&
1007 $stop_after_success >= 0) {
1009 if ($now - $success_start >= $stop_after_success) {
1010 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1015 if ($full_line =~ /\[ backtrace testing \]/) {
1016 $skip_call_trace = 1;
1019 if ($full_line =~ /call trace:/i) {
1020 if (!$bug && !$skip_call_trace) {
1022 $failure_start = time;
1026 if ($bug && defined($stop_after_failure) &&
1027 $stop_after_failure >= 0) {
1029 if ($now - $failure_start >= $stop_after_failure) {
1030 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1035 if ($full_line =~ /\[ end of backtrace testing \]/) {
1036 $skip_call_trace = 0;
1039 if ($full_line =~ /Kernel panic -/) {
1040 $failure_start = time;
1044 # Detect triple faults by testing the banner
1045 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1046 if ($1 eq $version) {
1048 } elsif ($version_found && $detect_triplefault) {
1049 # We already booted into the kernel we are testing,
1050 # but now we booted into another kernel?
1051 # Consider this a triple fault.
1052 doprint "Aleady booted in Linux kernel $version, but now\n";
1053 doprint "we booted into Linux kernel $1.\n";
1054 doprint "Assuming that this is a triple fault.\n";
1055 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1060 if ($line =~ /\n/) {
1064 if ($stop_test_after > 0 && !$booted && !$bug) {
1065 if (time - $monitor_start > $stop_test_after) {
1066 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1075 return 0 if ($in_bisect);
1076 fail "failed - got a bug report" and return 0;
1080 return 0 if ($in_bisect);
1081 fail "failed - never got a boot prompt." and return 0;
1087 sub do_post_install {
1089 return if (!defined($post_install));
1091 my $cp_post_install = $post_install;
1092 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1093 run_command "$cp_post_install" or
1094 dodie "Failed to run post install";
1099 return if ($no_install);
1101 run_scp "$outputdir/$build_target", "$target_image" or
1102 dodie "failed to copy image";
1104 my $install_mods = 0;
1106 # should we process modules?
1108 open(IN, "$output_config") or dodie("Can't read config file");
1110 if (/CONFIG_MODULES(=y)?/) {
1111 $install_mods = 1 if (defined($1));
1117 if (!$install_mods) {
1119 doprint "No modules needed\n";
1123 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1124 dodie "Failed to install modules";
1126 my $modlib = "/lib/modules/$version";
1127 my $modtar = "ktest-mods.tar.bz2";
1129 run_ssh "rm -rf $modlib" or
1130 dodie "failed to remove old mods: $modlib";
1132 # would be nice if scp -r did not follow symbolic links
1133 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1134 dodie "making tarball";
1136 run_scp "$tmpdir/$modtar", "/tmp" or
1137 dodie "failed to copy modules";
1139 unlink "$tmpdir/$modtar";
1141 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1142 dodie "failed to tar modules";
1144 run_ssh "rm -f /tmp/$modtar";
1150 # get the release name
1151 doprint "$make kernelrelease ... ";
1152 $version = `$make kernelrelease | tail -1`;
1154 doprint "$version\n";
1157 sub start_monitor_and_boot {
1166 sub check_buildlog {
1169 my @files = `git show $patch | diffstat -l`;
1171 open(IN, "git show $patch |") or
1172 dodie "failed to show $patch";
1174 if (m,^--- a/(.*),) {
1176 $files[$#files] = $1;
1181 open(IN, $buildlog) or dodie "Can't open $buildlog";
1183 if (/^\s*(.*?):.*(warning|error)/) {
1185 foreach my $file (@files) {
1186 my $fullpath = "$builddir/$file";
1187 if ($file eq $err || $fullpath eq $err) {
1188 fail "$file built with warnings" and return 0;
1198 sub apply_min_config {
1199 my $outconfig = "$output_config.new";
1201 # Read the config file and remove anything that
1202 # is in the force_config hash (from minconfig and others)
1203 # then add the force config back.
1205 doprint "Applying minimum configurations into $output_config.new\n";
1207 open (OUT, ">$outconfig") or
1208 dodie "Can't create $outconfig";
1210 if (-f $output_config) {
1211 open (IN, $output_config) or
1212 dodie "Failed to open $output_config";
1214 if (/^(# )?(CONFIG_[^\s=]*)/) {
1215 next if (defined($force_config{$2}));
1221 foreach my $config (keys %force_config) {
1222 print OUT "$force_config{$config}\n";
1226 run_command "mv $outconfig $output_config";
1229 sub make_oldconfig {
1231 my @force_list = keys %force_config;
1233 if ($#force_list >= 0) {
1237 if (!run_command "$make oldnoconfig") {
1238 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1239 # try a yes '' | oldconfig
1240 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1241 run_command "yes '' | $make oldconfig" or
1242 dodie "failed make config oldconfig";
1246 # read a config file and use this to force new configs.
1247 sub load_force_config {
1250 open(IN, $config) or
1251 dodie "failed to read $config";
1254 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1255 $force_config{$1} = $_;
1256 } elsif (/^# (CONFIG_\S*) is not set/) {
1257 $force_config{$1} = $_;
1268 if (defined($pre_build)) {
1269 my $ret = run_command $pre_build;
1270 if (!$ret && defined($pre_build_die) &&
1272 dodie "failed to pre_build\n";
1276 if ($type =~ /^useconfig:(.*)/) {
1277 run_command "cp $1 $output_config" or
1278 dodie "could not copy $1 to .config";
1280 $type = "oldconfig";
1283 # old config can ask questions
1284 if ($type eq "oldconfig") {
1285 $type = "oldnoconfig";
1287 # allow for empty configs
1288 run_command "touch $output_config";
1291 run_command "mv $output_config $outputdir/config_temp" or
1292 dodie "moving .config";
1294 run_command "$make mrproper" or dodie "make mrproper";
1296 run_command "mv $outputdir/config_temp $output_config" or
1297 dodie "moving config_temp";
1300 } elsif (!$noclean) {
1301 unlink "$output_config";
1302 run_command "$make mrproper" or
1303 dodie "make mrproper";
1306 # add something to distinguish this build
1307 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1308 print OUT "$localversion\n";
1311 if (defined($minconfig)) {
1312 load_force_config($minconfig);
1315 if ($type ne "oldnoconfig") {
1316 run_command "$make $type" or
1317 dodie "failed make config";
1319 # Run old config regardless, to enforce min configurations
1322 $redirect = "$buildlog";
1323 my $build_ret = run_command "$make $build_options";
1326 if (defined($post_build)) {
1327 my $ret = run_command $post_build;
1328 if (!$ret && defined($post_build_die) &&
1330 dodie "failed to post_build\n";
1335 # bisect may need this to pass
1336 return 0 if ($in_bisect);
1337 fail "failed build" and return 0;
1344 if (!run_ssh "halt" or defined($power_off)) {
1345 if (defined($poweroff_after_halt)) {
1346 sleep $poweroff_after_halt;
1347 run_command "$power_off";
1351 run_command "$power_off";
1362 if (defined($test_name)) {
1363 $name = " ($test_name)";
1366 doprint "\n\n*******************************************\n";
1367 doprint "*******************************************\n";
1368 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1369 doprint "*******************************************\n";
1370 doprint "*******************************************\n";
1372 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1373 doprint "Reboot and wait $sleep_time seconds\n";
1380 doprint "Pass or fail? [p/f]";
1383 if ($ans eq "p" || $ans eq "P") {
1385 } elsif ($ans eq "f" || $ans eq "F") {
1388 print "Please answer 'P' or 'F'\n";
1393 sub child_run_test {
1396 # child should have no power
1397 $reboot_on_error = 0;
1398 $poweroff_on_error = 0;
1399 $die_on_failure = 1;
1401 run_command $run_test or $failed = 1;
1407 sub child_finished {
1420 doprint "run test $run_test\n";
1424 $SIG{CHLD} = qw(child_finished);
1428 child_run_test if (!$child_pid);
1433 $line = wait_for_input($monitor_fp, 1);
1434 if (defined($line)) {
1436 # we are not guaranteed to get a full line
1437 $full_line .= $line;
1440 if ($full_line =~ /call trace:/i) {
1444 if ($full_line =~ /Kernel panic -/) {
1448 if ($line =~ /\n/) {
1452 } while (!$child_done && !$bug);
1455 my $failure_start = time;
1458 $line = wait_for_input($monitor_fp, 1);
1459 if (defined($line)) {
1463 if ($now - $failure_start >= $stop_after_failure) {
1466 } while (defined($line));
1468 doprint "Detected kernel crash!\n";
1469 # kill the child with extreme prejudice
1473 waitpid $child_pid, 0;
1476 if ($bug || $child_exit) {
1477 return 0 if $in_bisect;
1478 fail "test failed" and return 0;
1483 sub run_git_bisect {
1486 doprint "$command ... ";
1488 my $output = `$command 2>&1`;
1495 dodie "Failed to git bisect";
1498 doprint "SUCCESS\n";
1499 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1500 doprint "$1 [$2]\n";
1501 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1503 doprint "Found bad commit... $1\n";
1506 # we already logged it, just print it now.
1514 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1515 reboot $bisect_sleep_time;
1518 # returns 1 on success, 0 on failure, -1 on skip
1519 sub run_bisect_test {
1520 my ($type, $buildtype) = @_;
1529 build $buildtype or $failed = 1;
1531 if ($type ne "build") {
1532 if ($failed && $bisect_skip) {
1536 dodie "Failed on build" if $failed;
1539 start_monitor_and_boot or $failed = 1;
1541 if ($type ne "boot") {
1542 if ($failed && $bisect_skip) {
1548 dodie "Failed on boot" if $failed;
1550 do_run_test or $failed = 1;
1561 # reboot the box to a kernel we can ssh to
1562 if ($type ne "build") {
1572 my $buildtype = "oldconfig";
1574 # We should have a minconfig to use?
1575 if (defined($minconfig)) {
1576 $buildtype = "useconfig:$minconfig";
1579 my $ret = run_bisect_test $type, $buildtype;
1581 if ($bisect_manual) {
1582 $ret = answer_bisect;
1585 # Are we looking for where it worked, not failed?
1586 if ($reverse_bisect) {
1592 } elsif ($ret == 0) {
1594 } elsif ($bisect_skip) {
1595 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1605 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1606 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1607 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1609 my $good = $opt{"BISECT_GOOD[$i]"};
1610 my $bad = $opt{"BISECT_BAD[$i]"};
1611 my $type = $opt{"BISECT_TYPE[$i]"};
1612 my $start = $opt{"BISECT_START[$i]"};
1613 my $replay = $opt{"BISECT_REPLAY[$i]"};
1614 my $start_files = $opt{"BISECT_FILES[$i]"};
1616 if (defined($start_files)) {
1617 $start_files = " -- " . $start_files;
1622 # convert to true sha1's
1623 $good = get_sha1($good);
1624 $bad = get_sha1($bad);
1626 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1627 $opt{"BISECT_REVERSE[$i]"} == 1) {
1628 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1629 $reverse_bisect = 1;
1631 $reverse_bisect = 0;
1634 # Can't have a test without having a test to run
1635 if ($type eq "test" && !defined($run_test)) {
1639 my $check = $opt{"BISECT_CHECK[$i]"};
1640 if (defined($check) && $check ne "0") {
1643 my $head = get_sha1("HEAD");
1645 if ($check ne "good") {
1646 doprint "TESTING BISECT BAD [$bad]\n";
1647 run_command "git checkout $bad" or
1648 die "Failed to checkout $bad";
1650 $result = run_bisect $type;
1652 if ($result ne "bad") {
1653 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1657 if ($check ne "bad") {
1658 doprint "TESTING BISECT GOOD [$good]\n";
1659 run_command "git checkout $good" or
1660 die "Failed to checkout $good";
1662 $result = run_bisect $type;
1664 if ($result ne "good") {
1665 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1669 # checkout where we started
1670 run_command "git checkout $head" or
1671 die "Failed to checkout $head";
1674 run_command "git bisect start$start_files" or
1675 dodie "could not start bisect";
1677 run_command "git bisect good $good" or
1678 dodie "could not set bisect good to $good";
1680 run_git_bisect "git bisect bad $bad" or
1681 dodie "could not set bisect bad to $bad";
1683 if (defined($replay)) {
1684 run_command "git bisect replay $replay" or
1685 dodie "failed to run replay";
1688 if (defined($start)) {
1689 run_command "git checkout $start" or
1690 dodie "failed to checkout $start";
1695 $result = run_bisect $type;
1696 $test = run_git_bisect "git bisect $result";
1699 run_command "git bisect log" or
1700 dodie "could not capture git bisect log";
1702 run_command "git bisect reset" or
1703 dodie "could not reset git bisect";
1705 doprint "Bad commit was [$bisect_bad]\n";
1718 sub assign_configs {
1719 my ($hash, $config) = @_;
1722 or dodie "Failed to read $config";
1725 if (/^((CONFIG\S*)=.*)/) {
1733 sub process_config_ignore {
1736 assign_configs \%config_ignore, $config;
1739 sub read_current_config {
1740 my ($config_ref) = @_;
1742 %{$config_ref} = ();
1743 undef %{$config_ref};
1745 my @key = keys %{$config_ref};
1747 print "did not delete!\n";
1750 open (IN, "$output_config");
1753 if (/^(CONFIG\S+)=(.*)/) {
1754 ${$config_ref}{$1} = $2;
1760 sub get_dependencies {
1763 my $arr = $dependency{$config};
1764 if (!defined($arr)) {
1770 foreach my $dep (@{$arr}) {
1771 print "ADD DEP $dep\n";
1772 @deps = (@deps, get_dependencies $dep);
1781 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1783 foreach my $config (@configs) {
1784 print OUT "$config_set{$config}\n";
1785 my @deps = get_dependencies $config;
1786 foreach my $dep (@deps) {
1787 print OUT "$config_set{$dep}\n";
1791 foreach my $config (keys %config_ignore) {
1792 print OUT "$config_ignore{$config}\n";
1800 sub compare_configs {
1803 foreach my $item (keys %a) {
1804 if (!defined($b{$item})) {
1805 print "diff $item\n";
1813 print "diff2 $keys[0]\n";
1815 return -1 if ($#keys >= 0);
1820 sub run_config_bisect_test {
1823 return run_bisect_test $type, "oldconfig";
1826 sub process_passed {
1829 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1830 # Passed! All these configs are part of a good compile.
1831 # Add them to the min options.
1832 foreach my $config (keys %configs) {
1833 if (defined($config_list{$config})) {
1834 doprint " removing $config\n";
1835 $config_ignore{$config} = $config_list{$config};
1836 delete $config_list{$config};
1839 doprint "config copied to $outputdir/config_good\n";
1840 run_command "cp -f $output_config $outputdir/config_good";
1843 sub process_failed {
1846 doprint "\n\n***************************************\n";
1847 doprint "Found bad config: $config\n";
1848 doprint "***************************************\n\n";
1851 sub run_config_bisect {
1853 my @start_list = keys %config_list;
1855 if ($#start_list < 0) {
1856 doprint "No more configs to test!!!\n";
1860 doprint "***** RUN TEST ***\n";
1861 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1865 my $count = $#start_list + 1;
1866 doprint " $count configs to test\n";
1868 my $half = int($#start_list / 2);
1871 my @tophalf = @start_list[0 .. $half];
1873 create_config @tophalf;
1874 read_current_config \%current_config;
1876 $count = $#tophalf + 1;
1877 doprint "Testing $count configs\n";
1879 # make sure we test something
1880 foreach my $config (@tophalf) {
1881 if (defined($current_config{$config})) {
1887 # try the other half
1888 doprint "Top half produced no set configs, trying bottom half\n";
1889 @tophalf = @start_list[$half + 1 .. $#start_list];
1890 create_config @tophalf;
1891 read_current_config \%current_config;
1892 foreach my $config (@tophalf) {
1893 if (defined($current_config{$config})) {
1899 doprint "Failed: Can't make new config with current configs\n";
1900 foreach my $config (@start_list) {
1901 doprint " CONFIG: $config\n";
1905 $count = $#tophalf + 1;
1906 doprint "Testing $count configs\n";
1909 $ret = run_config_bisect_test $type;
1910 if ($bisect_manual) {
1911 $ret = answer_bisect;
1914 process_passed %current_config;
1918 doprint "This config had a failure.\n";
1919 doprint "Removing these configs that were not set in this config:\n";
1920 doprint "config copied to $outputdir/config_bad\n";
1921 run_command "cp -f $output_config $outputdir/config_bad";
1923 # A config exists in this group that was bad.
1924 foreach my $config (keys %config_list) {
1925 if (!defined($current_config{$config})) {
1926 doprint " removing $config\n";
1927 delete $config_list{$config};
1931 @start_list = @tophalf;
1933 if ($#start_list == 0) {
1934 process_failed $start_list[0];
1938 # remove half the configs we are looking at and see if
1940 $half = int($#start_list / 2);
1941 } while ($#start_list > 0);
1943 # we found a single config, try it again unless we are running manually
1945 if ($bisect_manual) {
1946 process_failed $start_list[0];
1950 my @tophalf = @start_list[0 .. 0];
1952 $ret = run_config_bisect_test $type;
1954 process_passed %current_config;
1958 process_failed $start_list[0];
1965 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1967 my $tmpconfig = "$tmpdir/use_config";
1969 if (defined($config_bisect_good)) {
1970 process_config_ignore $config_bisect_good;
1973 # Make the file with the bad config and the min config
1974 if (defined($minconfig)) {
1975 # read the min config for things to ignore
1976 run_command "cp $minconfig $tmpconfig" or
1977 dodie "failed to copy $minconfig to $tmpconfig";
1982 if (-f $tmpconfig) {
1983 load_force_config($tmpconfig);
1984 process_config_ignore $tmpconfig;
1987 # now process the start config
1988 run_command "cp $start_config $output_config" or
1989 dodie "failed to copy $start_config to $output_config";
1991 # read directly what we want to check
1993 open (IN, $output_config)
1994 or dodie "faied to open $output_config";
1997 if (/^((CONFIG\S*)=.*)/) {
1998 $config_check{$2} = $1;
2003 # Now run oldconfig with the minconfig
2006 # check to see what we lost (or gained)
2007 open (IN, $output_config)
2008 or dodie "Failed to read $start_config";
2010 my %removed_configs;
2014 if (/^((CONFIG\S*)=.*)/) {
2015 # save off all options
2016 $config_set{$2} = $1;
2017 if (defined($config_check{$2})) {
2018 if (defined($config_ignore{$2})) {
2019 $removed_configs{$2} = $1;
2021 $config_list{$2} = $1;
2023 } elsif (!defined($config_ignore{$2})) {
2024 $added_configs{$2} = $1;
2025 $config_list{$2} = $1;
2031 my @confs = keys %removed_configs;
2033 doprint "Configs overridden by default configs and removed from check:\n";
2034 foreach my $config (@confs) {
2035 doprint " $config\n";
2038 @confs = keys %added_configs;
2040 doprint "Configs appearing in make oldconfig and added:\n";
2041 foreach my $config (@confs) {
2042 doprint " $config\n";
2049 # Sometimes kconfig does weird things. We must make sure
2050 # that the config we autocreate has everything we need
2051 # to test, otherwise we may miss testing configs, or
2052 # may not be able to create a new config.
2053 # Here we create a config with everything set.
2054 create_config (keys %config_list);
2055 read_current_config \%config_test;
2056 foreach my $config (keys %config_list) {
2057 if (!defined($config_test{$config})) {
2060 doprint "Configs not produced by kconfig (will not be checked):\n";
2062 doprint " $config\n";
2063 delete $config_list{$config};
2068 $ret = run_config_bisect;
2071 return $ret if ($ret < 0);
2076 sub patchcheck_reboot {
2077 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2078 reboot $patchcheck_sleep_time;
2084 die "PATCHCHECK_START[$i] not defined\n"
2085 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2086 die "PATCHCHECK_TYPE[$i] not defined\n"
2087 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2089 my $start = $opt{"PATCHCHECK_START[$i]"};
2092 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2093 $end = $opt{"PATCHCHECK_END[$i]"};
2096 # Get the true sha1's since we can use things like HEAD~3
2097 $start = get_sha1($start);
2098 $end = get_sha1($end);
2100 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2102 # Can't have a test without having a test to run
2103 if ($type eq "test" && !defined($run_test)) {
2107 open (IN, "git log --pretty=oneline $end|") or
2108 dodie "could not get git list";
2114 $list[$#list+1] = $_;
2115 last if (/^$start/);
2119 if ($list[$#list] !~ /^$start/) {
2120 fail "SHA1 $start not found";
2123 # go backwards in the list
2124 @list = reverse @list;
2126 my $save_clean = $noclean;
2127 my %ignored_warnings;
2129 if (defined($ignore_warnings)) {
2130 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2131 $ignored_warnings{$sha1} = 1;
2136 foreach my $item (@list) {
2138 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2140 doprint "\nProcessing commit $item\n\n";
2142 run_command "git checkout $sha1" or
2143 die "Failed to checkout $sha1";
2145 # only clean on the first and last patch
2146 if ($item eq $list[0] ||
2147 $item eq $list[$#list]) {
2148 $noclean = $save_clean;
2153 if (defined($minconfig)) {
2154 build "useconfig:$minconfig" or return 0;
2156 # ?? no config to use?
2157 build "oldconfig" or return 0;
2161 if (!defined($ignored_warnings{$sha1})) {
2162 check_buildlog $sha1 or return 0;
2165 next if ($type eq "build");
2169 start_monitor_and_boot or $failed = 1;
2171 if (!$failed && $type ne "boot"){
2172 do_run_test or $failed = 1;
2175 return 0 if ($failed);
2193 # taken from streamline_config.pl
2205 if (! -f $kconfig) {
2206 doprint "file $kconfig does not exist, skipping\n";
2210 open(KIN, "$kconfig")
2211 or die "Can't open $kconfig";
2215 # Make sure that lines ending with \ continue
2217 $_ = $line . " " . $_;
2228 # collect any Kconfig sources
2229 if (/^source\s*"(.*)"/) {
2230 $kconfigs[$#kconfigs+1] = $1;
2234 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2238 for (my $i = 0; $i < $iflevel; $i++) {
2240 $depends{$config} .= " " . $ifdeps[$i];
2242 $depends{$config} = $ifdeps[$i];
2247 # collect the depends for the config
2248 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2250 if (defined($depends{$1})) {
2251 $depends{$config} .= " " . $1;
2253 $depends{$config} = $1;
2256 # Get the configs that select this config
2257 } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
2258 if (defined($depends{$1})) {
2259 $depends{$1} .= " " . $config;
2261 $depends{$1} = $config;
2264 # Check for if statements
2265 } elsif (/^if\s+(.*\S)\s*$/) {
2267 # remove beginning and ending non text
2268 $deps =~ s/^[^a-zA-Z0-9_]*//;
2269 $deps =~ s/[^a-zA-Z0-9_]*$//;
2271 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2273 $ifdeps[$iflevel++] = join ':', @deps;
2275 } elsif (/^endif/) {
2277 $iflevel-- if ($iflevel);
2280 } elsif (/^\s*help\s*$/) {
2286 # read in any configs that were found.
2287 foreach $kconfig (@kconfigs) {
2288 if (!defined($read_kconfigs{$kconfig})) {
2289 $read_kconfigs{$kconfig} = 1;
2290 read_kconfig("$builddir/$kconfig");
2296 # find out which arch this is by the kconfig file
2297 open (IN, $output_config)
2298 or dodie "Failed to read $output_config";
2301 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2308 if (!defined($arch)) {
2309 doprint "Could not find arch from config file\n";
2310 doprint "no dependencies used\n";
2314 # arch is really the subarch, we need to know
2315 # what directory to look at.
2316 if ($arch eq "i386" || $arch eq "x86_64") {
2318 } elsif ($arch =~ /^tile/) {
2322 my $kconfig = "$builddir/arch/$arch/Kconfig";
2324 if (! -f $kconfig && $arch =~ /\d$/) {
2326 # some subarchs have numbers, truncate them
2328 $kconfig = "$builddir/arch/$arch/Kconfig";
2329 if (! -f $kconfig) {
2330 doprint "No idea what arch dir $orig is for\n";
2331 doprint "no dependencies used\n";
2336 read_kconfig($kconfig);
2339 sub read_config_list {
2343 or dodie "Failed to read $config";
2346 if (/^((CONFIG\S*)=.*)/) {
2347 if (!defined($config_ignore{$2})) {
2348 $config_list{$2} = $1;
2356 sub read_output_config {
2359 assign_configs \%config_ignore, $config;
2362 sub make_new_config {
2365 open (OUT, ">$output_config")
2366 or dodie "Failed to write $output_config";
2368 foreach my $config (@configs) {
2369 print OUT "$config\n";
2378 $kconfig =~ s/CONFIG_//;
2380 $dep = $depends{"$kconfig"};
2382 # the dep string we have saves the dependencies as they
2383 # were found, including expressions like ! && ||. We
2384 # want to split this out into just an array of configs.
2386 my $valid = "A-Za-z_0-9";
2390 while ($dep =~ /[$valid]/) {
2392 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2393 my $conf = "CONFIG_" . $1;
2395 $configs[$#configs + 1] = $conf;
2397 $dep =~ s/^[^$valid]*[$valid]+//;
2399 die "this should never happen";
2409 my %processed_configs;
2410 my %nochange_config;
2412 sub test_this_config {
2417 # if we already processed this config, skip it
2418 if (defined($processed_configs{$config})) {
2421 $processed_configs{$config} = 1;
2423 # if this config failed during this round, skip it
2424 if (defined($nochange_config{$config})) {
2428 my $kconfig = $config;
2429 $kconfig =~ s/CONFIG_//;
2431 # Test dependencies first
2432 if (defined($depends{"$kconfig"})) {
2433 my @parents = get_depends $config;
2434 foreach my $parent (@parents) {
2435 # if the parent is in the min config, check it first
2436 next if (!defined($min_configs{$parent}));
2437 $found = test_this_config($parent);
2438 if (defined($found)) {
2444 # Remove this config from the list of configs
2445 # do a make oldnoconfig and then read the resulting
2446 # .config to make sure it is missing the config that
2448 my %configs = %min_configs;
2449 delete $configs{$config};
2450 make_new_config ((values %configs), (values %keep_configs));
2453 assign_configs \%configs, $output_config;
2455 return $config if (!defined($configs{$config}));
2457 doprint "disabling config $config did not change .config\n";
2459 $nochange_config{$config} = 1;
2464 sub make_min_config {
2467 if (!defined($output_minconfig)) {
2468 fail "OUTPUT_MIN_CONFIG not defined" and return;
2471 # If output_minconfig exists, and the start_minconfig
2472 # came from min_config, than ask if we should use
2474 if (-f $output_minconfig && !$start_minconfig_defined) {
2475 print "$output_minconfig exists\n";
2476 if (read_yn " Use it as minconfig?") {
2477 $start_minconfig = $output_minconfig;
2481 if (!defined($start_minconfig)) {
2482 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2485 my $temp_config = "$tmpdir/temp_config";
2487 # First things first. We build an allnoconfig to find
2488 # out what the defaults are that we can't touch.
2489 # Some are selections, but we really can't handle selections.
2491 my $save_minconfig = $minconfig;
2494 run_command "$make allnoconfig" or return 0;
2498 process_config_ignore $output_config;
2500 undef %save_configs;
2503 if (defined($ignore_config)) {
2504 # make sure the file exists
2505 `touch $ignore_config`;
2506 assign_configs \%save_configs, $ignore_config;
2509 %keep_configs = %save_configs;
2511 doprint "Load initial configs from $start_minconfig\n";
2513 # Look at the current min configs, and save off all the
2514 # ones that were set via the allnoconfig
2515 assign_configs \%min_configs, $start_minconfig;
2517 my @config_keys = keys %min_configs;
2519 # Remove anything that was set by the make allnoconfig
2520 # we shouldn't need them as they get set for us anyway.
2521 foreach my $config (@config_keys) {
2522 # Remove anything in the ignore_config
2523 if (defined($keep_configs{$config})) {
2524 my $file = $ignore_config;
2525 $file =~ s,.*/(.*?)$,$1,;
2526 doprint "$config set by $file ... ignored\n";
2527 delete $min_configs{$config};
2530 # But make sure the settings are the same. If a min config
2531 # sets a selection, we do not want to get rid of it if
2532 # it is not the same as what we have. Just move it into
2534 if (defined($config_ignore{$config})) {
2535 if ($config_ignore{$config} ne $min_configs{$config}) {
2536 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2537 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2538 $keep_configs{$config} = $min_configs{$config};
2540 doprint "$config set by allnoconfig ... ignored\n";
2542 delete $min_configs{$config};
2554 # Now disable each config one by one and do a make oldconfig
2555 # till we find a config that changes our list.
2557 # Put configs that did not modify the config at the end.
2558 my @test_configs = keys %min_configs;
2560 for (my $i = 0; $i < $#test_configs; $i++) {
2561 if (!defined($nochange_config{$test_configs[0]})) {
2565 # This config didn't change the .config last time.
2566 # Place it at the end
2567 my $config = shift @test_configs;
2568 push @test_configs, $config;
2571 # if every test config has failed to modify the .config file
2572 # in the past, then reset and start over.
2574 undef %nochange_config;
2577 undef %processed_configs;
2579 foreach my $config (@test_configs) {
2581 $found = test_this_config $config;
2583 last if (defined($found));
2585 # oh well, try another config
2588 if (!defined($found)) {
2589 # we could have failed due to the nochange_config hash
2590 # reset and try again
2592 undef %nochange_config;
2596 doprint "No more configs found that we can disable\n";
2604 doprint "Test with $config disabled\n";
2606 # set in_bisect to keep build and monitor from dieing
2611 start_monitor_and_boot or $failed = 1;
2617 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
2618 # this config is needed, add it to the ignore list.
2619 $keep_configs{$config} = $min_configs{$config};
2620 $save_configs{$config} = $min_configs{$config};
2621 delete $min_configs{$config};
2623 # update new ignore configs
2624 if (defined($ignore_config)) {
2625 open (OUT, ">$temp_config")
2626 or die "Can't write to $temp_config";
2627 foreach my $config (keys %save_configs) {
2628 print OUT "$save_configs{$config}\n";
2631 run_command "mv $temp_config $ignore_config" or
2632 dodie "failed to copy update to $ignore_config";
2636 # We booted without this config, remove it from the minconfigs.
2637 doprint "$config is not needed, disabling\n";
2639 delete $min_configs{$config};
2641 # Also disable anything that is not enabled in this config
2643 assign_configs \%configs, $output_config;
2644 my @config_keys = keys %min_configs;
2645 foreach my $config (@config_keys) {
2646 if (!defined($configs{$config})) {
2647 doprint "$config is not set, disabling\n";
2648 delete $min_configs{$config};
2652 # Save off all the current mandidory configs
2653 open (OUT, ">$temp_config")
2654 or die "Can't write to $temp_config";
2655 foreach my $config (keys %keep_configs) {
2656 print OUT "$keep_configs{$config}\n";
2658 foreach my $config (keys %min_configs) {
2659 print OUT "$min_configs{$config}\n";
2663 run_command "mv $temp_config $output_minconfig" or
2664 dodie "failed to copy update to $output_minconfig";
2667 doprint "Reboot and wait $sleep_time seconds\n";
2675 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2678 $ktest_config = $ARGV[0];
2679 if (! -f $ktest_config) {
2680 print "$ktest_config does not exist.\n";
2681 if (!read_yn "Create it?") {
2686 $ktest_config = "ktest.conf";
2689 if (! -f $ktest_config) {
2690 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2692 # Generated by ktest.pl
2694 # Define each test with TEST_START
2695 # The config options below it will override the defaults
2703 read_config $ktest_config;
2705 if (defined($opt{"LOG_FILE"})) {
2706 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2709 # Append any configs entered in manually to the config file.
2710 my @new_configs = keys %entered_configs;
2711 if ($#new_configs >= 0) {
2712 print "\nAppending entered in configs to $ktest_config\n";
2713 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2714 foreach my $config (@new_configs) {
2715 print OUT "$config = $entered_configs{$config}\n";
2716 $opt{$config} = $entered_configs{$config};
2720 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2721 unlink $opt{"LOG_FILE"};
2724 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2726 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2729 doprint "DEFAULT OPTIONS:\n";
2731 doprint "\nTEST $i OPTIONS";
2732 if (defined($repeat_tests{$i})) {
2733 $repeat = $repeat_tests{$i};
2734 doprint " ITERATE $repeat";
2739 foreach my $option (sort keys %opt) {
2741 if ($option =~ /\[(\d+)\]$/) {
2747 doprint "$option = $opt{$option}\n";
2751 sub __set_test_option {
2752 my ($name, $i) = @_;
2754 my $option = "$name\[$i\]";
2756 if (defined($opt{$option})) {
2757 return $opt{$option};
2760 foreach my $test (keys %repeat_tests) {
2762 $i < $test + $repeat_tests{$test}) {
2763 $option = "$name\[$test\]";
2764 if (defined($opt{$option})) {
2765 return $opt{$option};
2770 if (defined($opt{$name})) {
2777 sub set_test_option {
2778 my ($name, $i) = @_;
2780 my $option = __set_test_option($name, $i);
2781 return $option if (!defined($option));
2783 return eval_option($option, $i);
2786 # First we need to do is the builds
2787 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2791 my $makecmd = set_test_option("MAKE_CMD", $i);
2793 $machine = set_test_option("MACHINE", $i);
2794 $ssh_user = set_test_option("SSH_USER", $i);
2795 $tmpdir = set_test_option("TMP_DIR", $i);
2796 $outputdir = set_test_option("OUTPUT_DIR", $i);
2797 $builddir = set_test_option("BUILD_DIR", $i);
2798 $test_type = set_test_option("TEST_TYPE", $i);
2799 $build_type = set_test_option("BUILD_TYPE", $i);
2800 $build_options = set_test_option("BUILD_OPTIONS", $i);
2801 $pre_build = set_test_option("PRE_BUILD", $i);
2802 $post_build = set_test_option("POST_BUILD", $i);
2803 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
2804 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
2805 $power_cycle = set_test_option("POWER_CYCLE", $i);
2806 $reboot = set_test_option("REBOOT", $i);
2807 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2808 $minconfig = set_test_option("MIN_CONFIG", $i);
2809 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
2810 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
2811 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
2812 $run_test = set_test_option("TEST", $i);
2813 $addconfig = set_test_option("ADD_CONFIG", $i);
2814 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2815 $grub_menu = set_test_option("GRUB_MENU", $i);
2816 $post_install = set_test_option("POST_INSTALL", $i);
2817 $no_install = set_test_option("NO_INSTALL", $i);
2818 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2819 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2820 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2821 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2822 $power_off = set_test_option("POWER_OFF", $i);
2823 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2824 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
2825 $sleep_time = set_test_option("SLEEP_TIME", $i);
2826 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
2827 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
2828 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
2829 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
2830 $bisect_skip = set_test_option("BISECT_SKIP", $i);
2831 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
2832 $store_failures = set_test_option("STORE_FAILURES", $i);
2833 $test_name = set_test_option("TEST_NAME", $i);
2834 $timeout = set_test_option("TIMEOUT", $i);
2835 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2836 $console = set_test_option("CONSOLE", $i);
2837 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
2838 $success_line = set_test_option("SUCCESS_LINE", $i);
2839 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2840 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
2841 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
2842 $build_target = set_test_option("BUILD_TARGET", $i);
2843 $ssh_exec = set_test_option("SSH_EXEC", $i);
2844 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
2845 $target_image = set_test_option("TARGET_IMAGE", $i);
2846 $localversion = set_test_option("LOCALVERSION", $i);
2848 $start_minconfig_defined = 1;
2850 if (!defined($start_minconfig)) {
2851 $start_minconfig_defined = 0;
2852 $start_minconfig = $minconfig;
2855 chdir $builddir || die "can't change directory to $builddir";
2857 foreach my $dir ($tmpdir, $outputdir) {
2860 die "can't create $dir";
2864 $ENV{"SSH_USER"} = $ssh_user;
2865 $ENV{"MACHINE"} = $machine;
2867 $target = "$ssh_user\@$machine";
2869 $buildlog = "$tmpdir/buildlog-$machine";
2870 $dmesg = "$tmpdir/dmesg-$machine";
2871 $make = "$makecmd O=$outputdir";
2872 $output_config = "$outputdir/.config";
2874 if ($reboot_type eq "grub") {
2875 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
2876 } elsif (!defined($reboot_script)) {
2877 dodie "REBOOT_SCRIPT not defined"
2880 my $run_type = $build_type;
2881 if ($test_type eq "patchcheck") {
2882 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2883 } elsif ($test_type eq "bisect") {
2884 $run_type = $opt{"BISECT_TYPE[$i]"};
2885 } elsif ($test_type eq "config_bisect") {
2886 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
2889 if ($test_type eq "make_min_config") {
2893 # mistake in config file?
2894 if (!defined($run_type)) {
2895 $run_type = "ERROR";
2899 $installme = " no_install" if ($no_install);
2902 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
2907 if (defined($addconfig)) {
2908 my $min = $minconfig;
2909 if (!defined($minconfig)) {
2912 run_command "cat $addconfig $min > $tmpdir/add_config" or
2913 dodie "Failed to create temp config";
2914 $minconfig = "$tmpdir/add_config";
2917 my $checkout = $opt{"CHECKOUT[$i]"};
2918 if (defined($checkout)) {
2919 run_command "git checkout $checkout" or
2920 die "failed to checkout $checkout";
2923 if ($test_type eq "bisect") {
2926 } elsif ($test_type eq "config_bisect") {
2929 } elsif ($test_type eq "patchcheck") {
2932 } elsif ($test_type eq "make_min_config") {
2937 if ($build_type ne "nobuild") {
2938 build $build_type or next;
2941 if ($test_type eq "install") {
2948 if ($test_type ne "build") {
2950 start_monitor_and_boot or $failed = 1;
2952 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2953 do_run_test or $failed = 1;
2962 if ($opt{"POWEROFF_ON_SUCCESS"}) {
2964 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
2968 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";