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;
120 my $reboot_success_line;
122 my $stop_after_success;
123 my $stop_after_failure;
136 $config_help{"MACHINE"} = << "EOF"
137 The machine hostname that you will test.
140 $config_help{"SSH_USER"} = << "EOF"
141 The box is expected to have ssh on normal bootup, provide the user
142 (most likely root, since you need privileged operations)
145 $config_help{"BUILD_DIR"} = << "EOF"
146 The directory that contains the Linux source code (full path).
149 $config_help{"OUTPUT_DIR"} = << "EOF"
150 The directory that the objects will be built (full path).
151 (can not be same as BUILD_DIR)
154 $config_help{"BUILD_TARGET"} = << "EOF"
155 The location of the compiled file to copy to the target.
156 (relative to OUTPUT_DIR)
159 $config_help{"TARGET_IMAGE"} = << "EOF"
160 The place to put your image on the test machine.
163 $config_help{"POWER_CYCLE"} = << "EOF"
164 A script or command to reboot the box.
166 Here is a digital loggers power switch example
167 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
169 Here is an example to reboot a virtual box on the current host
170 with the name "Guest".
171 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
174 $config_help{"CONSOLE"} = << "EOF"
175 The script or command that reads the console
177 If you use ttywatch server, something like the following would work.
178 CONSOLE = nc -d localhost 3001
180 For a virtual machine with guest name "Guest".
181 CONSOLE = virsh console Guest
184 $config_help{"LOCALVERSION"} = << "EOF"
185 Required version ending to differentiate the test
186 from other linux builds on the system.
189 $config_help{"REBOOT_TYPE"} = << "EOF"
190 Way to reboot the box to the test kernel.
191 Only valid options so far are "grub" and "script".
193 If you specify grub, it will assume grub version 1
194 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
195 and select that target to reboot to the kernel. If this is not
196 your setup, then specify "script" and have a command or script
197 specified in REBOOT_SCRIPT to boot to the target.
199 The entry in /boot/grub/menu.lst must be entered in manually.
200 The test will not modify that file.
203 $config_help{"GRUB_MENU"} = << "EOF"
204 The grub title name for the test kernel to boot
205 (Only mandatory if REBOOT_TYPE = grub)
207 Note, ktest.pl will not update the grub menu.lst, you need to
208 manually add an option for the test. ktest.pl will search
209 the grub menu.lst for this option to find what kernel to
212 For example, if in the /boot/grub/menu.lst the test kernel title has:
215 GRUB_MENU = Test Kernel
218 $config_help{"REBOOT_SCRIPT"} = << "EOF"
219 A script to reboot the target into the test kernel
220 (Only mandatory if REBOOT_TYPE = script)
230 print "$prompt [Y/n] ";
233 if ($ans =~ /^\s*$/) {
236 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
237 print "Please answer either 'y' or 'n'.\n";
239 if ($ans !~ /^y$/i) {
245 sub get_ktest_config {
248 return if (defined($opt{$config}));
250 if (defined($config_help{$config})) {
252 print $config_help{$config};
257 if (defined($default{$config})) {
258 print "\[$default{$config}\] ";
260 $entered_configs{$config} = <STDIN>;
261 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
262 if ($entered_configs{$config} =~ /^\s*$/) {
263 if ($default{$config}) {
264 $entered_configs{$config} = $default{$config};
266 print "Your answer can not be blank\n";
274 sub get_ktest_configs {
275 get_ktest_config("MACHINE");
276 get_ktest_config("SSH_USER");
277 get_ktest_config("BUILD_DIR");
278 get_ktest_config("OUTPUT_DIR");
279 get_ktest_config("BUILD_TARGET");
280 get_ktest_config("TARGET_IMAGE");
281 get_ktest_config("POWER_CYCLE");
282 get_ktest_config("CONSOLE");
283 get_ktest_config("LOCALVERSION");
285 my $rtype = $opt{"REBOOT_TYPE"};
287 if (!defined($rtype)) {
288 if (!defined($opt{"GRUB_MENU"})) {
289 get_ktest_config("REBOOT_TYPE");
290 $rtype = $entered_configs{"REBOOT_TYPE"};
296 if ($rtype eq "grub") {
297 get_ktest_config("GRUB_MENU");
299 get_ktest_config("REBOOT_SCRIPT");
303 sub process_variables {
307 # We want to check for '\', and it is just easier
308 # to check the previous characet of '$' and not need
309 # to worry if '$' is the first character. By adding
310 # a space to $value, we can just check [^\\]\$ and
311 # it will still work.
314 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
318 # append beginning of value to retval
319 $retval = "$retval$begin";
320 if (defined($variable{$var})) {
321 $retval = "$retval$variable{$var}";
323 # put back the origin piece.
324 $retval = "$retval\$\{$var\}";
328 $retval = "$retval$value";
330 # remove the space added in the beginning
337 my ($lvalue, $rvalue) = @_;
339 if (defined($opt{$lvalue})) {
340 die "Error: Option $lvalue defined more than once!\n";
342 if ($rvalue =~ /^\s*$/) {
343 delete $opt{$lvalue};
345 $rvalue = process_variables($rvalue);
346 $opt{$lvalue} = $rvalue;
351 my ($lvalue, $rvalue) = @_;
353 if ($rvalue =~ /^\s*$/) {
354 delete $variable{$lvalue};
356 $rvalue = process_variables($rvalue);
357 $variable{$lvalue} = $rvalue;
364 open(IN, $config) || die "can't read file $config";
367 $name =~ s,.*/(.*),$1,;
372 my $num_tests_set = 0;
379 # ignore blank lines and comments
380 next if (/^\s*$/ || /\s*\#/);
382 if (/^\s*TEST_START(.*)/) {
386 if ($num_tests_set) {
387 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
390 my $old_test_num = $test_num;
391 my $old_repeat = $repeat;
393 $test_num += $repeat;
397 if ($rest =~ /\s+SKIP(.*)/) {
405 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
408 $repeat_tests{"$test_num"} = $repeat;
411 if ($rest =~ /\s+SKIP(.*)/) {
416 if ($rest !~ /^\s*$/) {
417 die "$name: $.: Gargbage found after TEST_START\n$_";
421 $test_num = $old_test_num;
422 $repeat = $old_repeat;
425 } elsif (/^\s*DEFAULTS(.*)$/) {
430 if ($rest =~ /\s+SKIP(.*)/) {
437 if ($rest !~ /^\s*$/) {
438 die "$name: $.: Gargbage found after DEFAULTS\n$_";
441 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
449 ($lvalue eq "NUM_TESTS" ||
450 $lvalue eq "LOG_FILE" ||
451 $lvalue eq "CLEAR_LOG")) {
452 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
455 if ($lvalue eq "NUM_TESTS") {
457 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
460 die "$name: $.: NUM_TESTS must be set in default section\n";
465 if ($default || $lvalue =~ /\[\d+\]$/) {
466 set_value($lvalue, $rvalue);
468 my $val = "$lvalue\[$test_num\]";
469 set_value($val, $rvalue);
472 $repeats{$val} = $repeat;
475 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
481 # process config variables.
482 # Config variables are only active while reading the
483 # config and can be defined anywhere. They also ignore
484 # TEST_START and DEFAULTS, but are skipped if they are in
485 # on of these sections that have SKIP defined.
486 # The save variable can be
487 # defined multiple times and the new one simply overrides
489 set_variable($lvalue, $rvalue);
492 die "$name: $.: Garbage found in config\n$_";
499 $test_num += $repeat - 1;
500 $opt{"NUM_TESTS"} = $test_num;
503 # make sure we have all mandatory configs
506 # was a test specified?
508 print "No test case specified.\n";
509 print "What test case would you like to run?\n";
512 $default{"TEST_TYPE"} = $ans;
517 foreach my $default (keys %default) {
518 if (!defined($opt{$default})) {
519 $opt{$default} = $default{$default};
525 my ($option, $i) = @_;
527 # Add space to evaluate the character before $
528 $option = " $option";
531 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
536 # Append beginning of line
537 $retval = "$retval$start";
539 # If the iteration option OPT[$i] exists, then use that.
540 # otherwise see if the default OPT (without [$i]) exists.
542 my $o = "$var\[$i\]";
544 if (defined($opt{$o})) {
546 $retval = "$retval$o";
547 } elsif (defined($opt{$var})) {
549 $retval = "$retval$o";
551 $retval = "$retval\$\{$var\}";
557 $retval = "$retval$option";
565 my ($option, $i) = @_;
569 # Since an option can evaluate to another option,
570 # keep iterating until we do not evaluate any more
573 while ($prev ne $option) {
574 # Check for recursive evaluations.
575 # 100 deep should be more than enough.
577 die "Over 100 evaluations accurred with $option\n" .
578 "Check for recursive variables\n";
581 $option = __eval_option($option, $i);
588 if (defined($opt{"LOG_FILE"})) {
589 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
596 if (defined($opt{"LOG_FILE"})) {
611 sub wait_for_monitor;
616 if (defined($time)) {
618 # flush out current monitor
619 # May contain the reboot success line
623 # try to reboot normally
624 if (run_command $reboot) {
625 if (defined($powercycle_after_reboot)) {
626 sleep $powercycle_after_reboot;
627 run_command "$power_cycle";
630 # nope? power cycle it.
631 run_command "$power_cycle";
634 if (defined($time)) {
635 wait_for_monitor($time, $reboot_success_line);
643 return $test_type eq "build" ||
644 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
645 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
649 doprint "CRITICAL FAILURE... ", @_, "\n";
653 if ($reboot_on_error && !do_not_reboot) {
655 doprint "REBOOTING\n";
658 } elsif ($poweroff_on_error && defined($power_off)) {
659 doprint "POWERING OFF\n";
663 if (defined($opt{"LOG_FILE"})) {
664 print " See $opt{LOG_FILE} for more info.\n";
675 my $pid = open($fp, "$console|") or
676 dodie "Can't open console $console";
678 $flags = fcntl($fp, F_GETFL, 0) or
679 dodie "Can't get flags for the socket: $!";
680 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
681 dodie "Can't set flags for the socket: $!";
689 doprint "kill child process $pid\n";
697 if ($monitor_cnt++) {
700 $monitor_fp = \*MONFD;
701 $monitor_pid = open_console $monitor_fp;
705 open(MONFD, "Stop perl from warning about single use of MONFD");
709 if (--$monitor_cnt) {
712 close_console($monitor_fp, $monitor_pid);
715 sub wait_for_monitor {
716 my ($time, $stop) = @_;
721 doprint "** Wait for monitor to settle down **\n";
723 # read the monitor and wait for the system to calm down
725 $line = wait_for_input($monitor_fp, $time);
726 last if (!defined($line));
730 if (defined($stop) && $full_line =~ /$stop/) {
731 doprint "wait for monitor detected $stop\n";
739 print "** Monitor flushed **\n";
744 if ($die_on_failure) {
752 # no need to reboot for just building.
753 if (!do_not_reboot) {
754 doprint "REBOOTING\n";
760 if (defined($test_name)) {
761 $name = " ($test_name)";
764 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
765 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
766 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
767 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
768 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
770 return 1 if (!defined($store_failures));
773 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
774 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
776 my $type = $build_type;
777 if ($type =~ /useconfig/) {
781 my $dir = "$machine-$test_type-$type-fail-$date";
782 my $faildir = "$store_failures/$dir";
786 die "can't create $faildir";
788 if (-f "$output_config") {
789 cp "$output_config", "$faildir/config" or
790 die "failed to copy .config";
793 cp $buildlog, "$faildir/buildlog" or
794 die "failed to move $buildlog";
797 cp $dmesg, "$faildir/dmesg" or
798 die "failed to move $dmesg";
801 doprint "*** Saved info to $faildir ***\n";
812 $command =~ s/\$SSH_USER/$ssh_user/g;
813 $command =~ s/\$MACHINE/$machine/g;
815 doprint("$command ... ");
817 $pid = open(CMD, "$command 2>&1 |") or
818 (fail "unable to exec $command" and return 0);
820 if (defined($opt{"LOG_FILE"})) {
821 open(LOG, ">>$opt{LOG_FILE}") or
822 dodie "failed to write to log";
826 if (defined($redirect)) {
827 open (RD, ">$redirect") or
828 dodie "failed to write to redirect $redirect";
833 print LOG if ($dolog);
841 close(LOG) if ($dolog);
842 close(RD) if ($dord);
855 my $cp_exec = $ssh_exec;
857 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
858 return run_command "$cp_exec";
862 my ($src, $dst) = @_;
863 my $cp_scp = $scp_to_target;
865 $cp_scp =~ s/\$SRC_FILE/$src/g;
866 $cp_scp =~ s/\$DST_FILE/$dst/g;
868 return run_command "$cp_scp";
873 if ($reboot_type ne "grub") {
876 return if (defined($grub_number));
878 doprint "Find grub menu ... ";
881 my $ssh_grub = $ssh_exec;
882 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
884 open(IN, "$ssh_grub |")
885 or die "unable to get menu.lst";
890 if (/^\s*title\s+$grub_menu\s*$/) {
894 } elsif (/^\s*title\s/) {
900 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
902 doprint "$grub_number\n";
907 my ($fp, $time) = @_;
913 if (!defined($time)) {
918 vec($rin, fileno($fp), 1) = 1;
919 $ready = select($rin, undef, undef, $time);
923 # try to read one char at a time
924 while (sysread $fp, $ch, 1) {
926 last if ($ch eq "\n");
929 if (!length($line)) {
937 if ($reboot_type eq "grub") {
938 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
942 run_command "$reboot_script";
948 doprint "git rev-list --max-count=1 $commit ... ";
949 my $sha1 = `git rev-list --max-count=1 $commit`;
956 dodie "Failed to get git $commit";
969 my $skip_call_trace = 0;
977 open(DMESG, "> $dmesg") or
978 die "unable to write to $dmesg";
984 my $monitor_start = time;
986 my $version_found = 0;
990 if ($bug && defined($stop_after_failure) &&
991 $stop_after_failure >= 0) {
992 my $time = $stop_after_failure - (time - $failure_start);
993 $line = wait_for_input($monitor_fp, $time);
994 if (!defined($line)) {
995 doprint "bug timed out after $booted_timeout seconds\n";
996 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1000 $line = wait_for_input($monitor_fp, $booted_timeout);
1001 if (!defined($line)) {
1002 my $s = $booted_timeout == 1 ? "" : "s";
1003 doprint "Successful boot found: break after $booted_timeout second$s\n";
1007 $line = wait_for_input($monitor_fp);
1008 if (!defined($line)) {
1009 my $s = $timeout == 1 ? "" : "s";
1010 doprint "Timed out after $timeout second$s\n";
1018 # we are not guaranteed to get a full line
1019 $full_line .= $line;
1021 if ($full_line =~ /$success_line/) {
1023 $success_start = time;
1026 if ($booted && defined($stop_after_success) &&
1027 $stop_after_success >= 0) {
1029 if ($now - $success_start >= $stop_after_success) {
1030 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1035 if ($full_line =~ /\[ backtrace testing \]/) {
1036 $skip_call_trace = 1;
1039 if ($full_line =~ /call trace:/i) {
1040 if (!$bug && !$skip_call_trace) {
1042 $failure_start = time;
1046 if ($bug && defined($stop_after_failure) &&
1047 $stop_after_failure >= 0) {
1049 if ($now - $failure_start >= $stop_after_failure) {
1050 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1055 if ($full_line =~ /\[ end of backtrace testing \]/) {
1056 $skip_call_trace = 0;
1059 if ($full_line =~ /Kernel panic -/) {
1060 $failure_start = time;
1064 # Detect triple faults by testing the banner
1065 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1066 if ($1 eq $version) {
1068 } elsif ($version_found && $detect_triplefault) {
1069 # We already booted into the kernel we are testing,
1070 # but now we booted into another kernel?
1071 # Consider this a triple fault.
1072 doprint "Aleady booted in Linux kernel $version, but now\n";
1073 doprint "we booted into Linux kernel $1.\n";
1074 doprint "Assuming that this is a triple fault.\n";
1075 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1080 if ($line =~ /\n/) {
1084 if ($stop_test_after > 0 && !$booted && !$bug) {
1085 if (time - $monitor_start > $stop_test_after) {
1086 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1095 return 0 if ($in_bisect);
1096 fail "failed - got a bug report" and return 0;
1100 return 0 if ($in_bisect);
1101 fail "failed - never got a boot prompt." and return 0;
1107 sub do_post_install {
1109 return if (!defined($post_install));
1111 my $cp_post_install = $post_install;
1112 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1113 run_command "$cp_post_install" or
1114 dodie "Failed to run post install";
1119 return if ($no_install);
1121 run_scp "$outputdir/$build_target", "$target_image" or
1122 dodie "failed to copy image";
1124 my $install_mods = 0;
1126 # should we process modules?
1128 open(IN, "$output_config") or dodie("Can't read config file");
1130 if (/CONFIG_MODULES(=y)?/) {
1131 $install_mods = 1 if (defined($1));
1137 if (!$install_mods) {
1139 doprint "No modules needed\n";
1143 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1144 dodie "Failed to install modules";
1146 my $modlib = "/lib/modules/$version";
1147 my $modtar = "ktest-mods.tar.bz2";
1149 run_ssh "rm -rf $modlib" or
1150 dodie "failed to remove old mods: $modlib";
1152 # would be nice if scp -r did not follow symbolic links
1153 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1154 dodie "making tarball";
1156 run_scp "$tmpdir/$modtar", "/tmp" or
1157 dodie "failed to copy modules";
1159 unlink "$tmpdir/$modtar";
1161 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1162 dodie "failed to tar modules";
1164 run_ssh "rm -f /tmp/$modtar";
1170 # get the release name
1171 doprint "$make kernelrelease ... ";
1172 $version = `$make kernelrelease | tail -1`;
1174 doprint "$version\n";
1177 sub start_monitor_and_boot {
1186 sub check_buildlog {
1189 my @files = `git show $patch | diffstat -l`;
1191 open(IN, "git show $patch |") or
1192 dodie "failed to show $patch";
1194 if (m,^--- a/(.*),) {
1196 $files[$#files] = $1;
1201 open(IN, $buildlog) or dodie "Can't open $buildlog";
1203 if (/^\s*(.*?):.*(warning|error)/) {
1205 foreach my $file (@files) {
1206 my $fullpath = "$builddir/$file";
1207 if ($file eq $err || $fullpath eq $err) {
1208 fail "$file built with warnings" and return 0;
1218 sub apply_min_config {
1219 my $outconfig = "$output_config.new";
1221 # Read the config file and remove anything that
1222 # is in the force_config hash (from minconfig and others)
1223 # then add the force config back.
1225 doprint "Applying minimum configurations into $output_config.new\n";
1227 open (OUT, ">$outconfig") or
1228 dodie "Can't create $outconfig";
1230 if (-f $output_config) {
1231 open (IN, $output_config) or
1232 dodie "Failed to open $output_config";
1234 if (/^(# )?(CONFIG_[^\s=]*)/) {
1235 next if (defined($force_config{$2}));
1241 foreach my $config (keys %force_config) {
1242 print OUT "$force_config{$config}\n";
1246 run_command "mv $outconfig $output_config";
1249 sub make_oldconfig {
1251 my @force_list = keys %force_config;
1253 if ($#force_list >= 0) {
1257 if (!run_command "$make oldnoconfig") {
1258 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1259 # try a yes '' | oldconfig
1260 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1261 run_command "yes '' | $make oldconfig" or
1262 dodie "failed make config oldconfig";
1266 # read a config file and use this to force new configs.
1267 sub load_force_config {
1270 open(IN, $config) or
1271 dodie "failed to read $config";
1274 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1275 $force_config{$1} = $_;
1276 } elsif (/^# (CONFIG_\S*) is not set/) {
1277 $force_config{$1} = $_;
1288 if (defined($pre_build)) {
1289 my $ret = run_command $pre_build;
1290 if (!$ret && defined($pre_build_die) &&
1292 dodie "failed to pre_build\n";
1296 if ($type =~ /^useconfig:(.*)/) {
1297 run_command "cp $1 $output_config" or
1298 dodie "could not copy $1 to .config";
1300 $type = "oldconfig";
1303 # old config can ask questions
1304 if ($type eq "oldconfig") {
1305 $type = "oldnoconfig";
1307 # allow for empty configs
1308 run_command "touch $output_config";
1311 run_command "mv $output_config $outputdir/config_temp" or
1312 dodie "moving .config";
1314 run_command "$make mrproper" or dodie "make mrproper";
1316 run_command "mv $outputdir/config_temp $output_config" or
1317 dodie "moving config_temp";
1320 } elsif (!$noclean) {
1321 unlink "$output_config";
1322 run_command "$make mrproper" or
1323 dodie "make mrproper";
1326 # add something to distinguish this build
1327 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1328 print OUT "$localversion\n";
1331 if (defined($minconfig)) {
1332 load_force_config($minconfig);
1335 if ($type ne "oldnoconfig") {
1336 run_command "$make $type" or
1337 dodie "failed make config";
1339 # Run old config regardless, to enforce min configurations
1342 $redirect = "$buildlog";
1343 my $build_ret = run_command "$make $build_options";
1346 if (defined($post_build)) {
1347 my $ret = run_command $post_build;
1348 if (!$ret && defined($post_build_die) &&
1350 dodie "failed to post_build\n";
1355 # bisect may need this to pass
1356 return 0 if ($in_bisect);
1357 fail "failed build" and return 0;
1364 if (!run_ssh "halt" or defined($power_off)) {
1365 if (defined($poweroff_after_halt)) {
1366 sleep $poweroff_after_halt;
1367 run_command "$power_off";
1371 run_command "$power_off";
1382 if (defined($test_name)) {
1383 $name = " ($test_name)";
1386 doprint "\n\n*******************************************\n";
1387 doprint "*******************************************\n";
1388 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1389 doprint "*******************************************\n";
1390 doprint "*******************************************\n";
1392 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1393 doprint "Reboot and wait $sleep_time seconds\n";
1400 doprint "Pass or fail? [p/f]";
1403 if ($ans eq "p" || $ans eq "P") {
1405 } elsif ($ans eq "f" || $ans eq "F") {
1408 print "Please answer 'P' or 'F'\n";
1413 sub child_run_test {
1416 # child should have no power
1417 $reboot_on_error = 0;
1418 $poweroff_on_error = 0;
1419 $die_on_failure = 1;
1421 run_command $run_test or $failed = 1;
1427 sub child_finished {
1440 doprint "run test $run_test\n";
1444 $SIG{CHLD} = qw(child_finished);
1448 child_run_test if (!$child_pid);
1453 $line = wait_for_input($monitor_fp, 1);
1454 if (defined($line)) {
1456 # we are not guaranteed to get a full line
1457 $full_line .= $line;
1460 if ($full_line =~ /call trace:/i) {
1464 if ($full_line =~ /Kernel panic -/) {
1468 if ($line =~ /\n/) {
1472 } while (!$child_done && !$bug);
1475 my $failure_start = time;
1478 $line = wait_for_input($monitor_fp, 1);
1479 if (defined($line)) {
1483 if ($now - $failure_start >= $stop_after_failure) {
1486 } while (defined($line));
1488 doprint "Detected kernel crash!\n";
1489 # kill the child with extreme prejudice
1493 waitpid $child_pid, 0;
1496 if ($bug || $child_exit) {
1497 return 0 if $in_bisect;
1498 fail "test failed" and return 0;
1503 sub run_git_bisect {
1506 doprint "$command ... ";
1508 my $output = `$command 2>&1`;
1515 dodie "Failed to git bisect";
1518 doprint "SUCCESS\n";
1519 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1520 doprint "$1 [$2]\n";
1521 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1523 doprint "Found bad commit... $1\n";
1526 # we already logged it, just print it now.
1534 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1535 reboot $bisect_sleep_time;
1538 # returns 1 on success, 0 on failure, -1 on skip
1539 sub run_bisect_test {
1540 my ($type, $buildtype) = @_;
1549 build $buildtype or $failed = 1;
1551 if ($type ne "build") {
1552 if ($failed && $bisect_skip) {
1556 dodie "Failed on build" if $failed;
1559 start_monitor_and_boot or $failed = 1;
1561 if ($type ne "boot") {
1562 if ($failed && $bisect_skip) {
1568 dodie "Failed on boot" if $failed;
1570 do_run_test or $failed = 1;
1581 # reboot the box to a kernel we can ssh to
1582 if ($type ne "build") {
1592 my $buildtype = "oldconfig";
1594 # We should have a minconfig to use?
1595 if (defined($minconfig)) {
1596 $buildtype = "useconfig:$minconfig";
1599 my $ret = run_bisect_test $type, $buildtype;
1601 if ($bisect_manual) {
1602 $ret = answer_bisect;
1605 # Are we looking for where it worked, not failed?
1606 if ($reverse_bisect) {
1612 } elsif ($ret == 0) {
1614 } elsif ($bisect_skip) {
1615 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1625 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1626 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1627 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1629 my $good = $opt{"BISECT_GOOD[$i]"};
1630 my $bad = $opt{"BISECT_BAD[$i]"};
1631 my $type = $opt{"BISECT_TYPE[$i]"};
1632 my $start = $opt{"BISECT_START[$i]"};
1633 my $replay = $opt{"BISECT_REPLAY[$i]"};
1634 my $start_files = $opt{"BISECT_FILES[$i]"};
1636 if (defined($start_files)) {
1637 $start_files = " -- " . $start_files;
1642 # convert to true sha1's
1643 $good = get_sha1($good);
1644 $bad = get_sha1($bad);
1646 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1647 $opt{"BISECT_REVERSE[$i]"} == 1) {
1648 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1649 $reverse_bisect = 1;
1651 $reverse_bisect = 0;
1654 # Can't have a test without having a test to run
1655 if ($type eq "test" && !defined($run_test)) {
1659 my $check = $opt{"BISECT_CHECK[$i]"};
1660 if (defined($check) && $check ne "0") {
1663 my $head = get_sha1("HEAD");
1665 if ($check ne "good") {
1666 doprint "TESTING BISECT BAD [$bad]\n";
1667 run_command "git checkout $bad" or
1668 die "Failed to checkout $bad";
1670 $result = run_bisect $type;
1672 if ($result ne "bad") {
1673 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1677 if ($check ne "bad") {
1678 doprint "TESTING BISECT GOOD [$good]\n";
1679 run_command "git checkout $good" or
1680 die "Failed to checkout $good";
1682 $result = run_bisect $type;
1684 if ($result ne "good") {
1685 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1689 # checkout where we started
1690 run_command "git checkout $head" or
1691 die "Failed to checkout $head";
1694 run_command "git bisect start$start_files" or
1695 dodie "could not start bisect";
1697 run_command "git bisect good $good" or
1698 dodie "could not set bisect good to $good";
1700 run_git_bisect "git bisect bad $bad" or
1701 dodie "could not set bisect bad to $bad";
1703 if (defined($replay)) {
1704 run_command "git bisect replay $replay" or
1705 dodie "failed to run replay";
1708 if (defined($start)) {
1709 run_command "git checkout $start" or
1710 dodie "failed to checkout $start";
1715 $result = run_bisect $type;
1716 $test = run_git_bisect "git bisect $result";
1719 run_command "git bisect log" or
1720 dodie "could not capture git bisect log";
1722 run_command "git bisect reset" or
1723 dodie "could not reset git bisect";
1725 doprint "Bad commit was [$bisect_bad]\n";
1738 sub assign_configs {
1739 my ($hash, $config) = @_;
1742 or dodie "Failed to read $config";
1745 if (/^((CONFIG\S*)=.*)/) {
1753 sub process_config_ignore {
1756 assign_configs \%config_ignore, $config;
1759 sub read_current_config {
1760 my ($config_ref) = @_;
1762 %{$config_ref} = ();
1763 undef %{$config_ref};
1765 my @key = keys %{$config_ref};
1767 print "did not delete!\n";
1770 open (IN, "$output_config");
1773 if (/^(CONFIG\S+)=(.*)/) {
1774 ${$config_ref}{$1} = $2;
1780 sub get_dependencies {
1783 my $arr = $dependency{$config};
1784 if (!defined($arr)) {
1790 foreach my $dep (@{$arr}) {
1791 print "ADD DEP $dep\n";
1792 @deps = (@deps, get_dependencies $dep);
1801 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1803 foreach my $config (@configs) {
1804 print OUT "$config_set{$config}\n";
1805 my @deps = get_dependencies $config;
1806 foreach my $dep (@deps) {
1807 print OUT "$config_set{$dep}\n";
1811 foreach my $config (keys %config_ignore) {
1812 print OUT "$config_ignore{$config}\n";
1820 sub compare_configs {
1823 foreach my $item (keys %a) {
1824 if (!defined($b{$item})) {
1825 print "diff $item\n";
1833 print "diff2 $keys[0]\n";
1835 return -1 if ($#keys >= 0);
1840 sub run_config_bisect_test {
1843 return run_bisect_test $type, "oldconfig";
1846 sub process_passed {
1849 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1850 # Passed! All these configs are part of a good compile.
1851 # Add them to the min options.
1852 foreach my $config (keys %configs) {
1853 if (defined($config_list{$config})) {
1854 doprint " removing $config\n";
1855 $config_ignore{$config} = $config_list{$config};
1856 delete $config_list{$config};
1859 doprint "config copied to $outputdir/config_good\n";
1860 run_command "cp -f $output_config $outputdir/config_good";
1863 sub process_failed {
1866 doprint "\n\n***************************************\n";
1867 doprint "Found bad config: $config\n";
1868 doprint "***************************************\n\n";
1871 sub run_config_bisect {
1873 my @start_list = keys %config_list;
1875 if ($#start_list < 0) {
1876 doprint "No more configs to test!!!\n";
1880 doprint "***** RUN TEST ***\n";
1881 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1885 my $count = $#start_list + 1;
1886 doprint " $count configs to test\n";
1888 my $half = int($#start_list / 2);
1891 my @tophalf = @start_list[0 .. $half];
1893 create_config @tophalf;
1894 read_current_config \%current_config;
1896 $count = $#tophalf + 1;
1897 doprint "Testing $count configs\n";
1899 # make sure we test something
1900 foreach my $config (@tophalf) {
1901 if (defined($current_config{$config})) {
1907 # try the other half
1908 doprint "Top half produced no set configs, trying bottom half\n";
1909 @tophalf = @start_list[$half + 1 .. $#start_list];
1910 create_config @tophalf;
1911 read_current_config \%current_config;
1912 foreach my $config (@tophalf) {
1913 if (defined($current_config{$config})) {
1919 doprint "Failed: Can't make new config with current configs\n";
1920 foreach my $config (@start_list) {
1921 doprint " CONFIG: $config\n";
1925 $count = $#tophalf + 1;
1926 doprint "Testing $count configs\n";
1929 $ret = run_config_bisect_test $type;
1930 if ($bisect_manual) {
1931 $ret = answer_bisect;
1934 process_passed %current_config;
1938 doprint "This config had a failure.\n";
1939 doprint "Removing these configs that were not set in this config:\n";
1940 doprint "config copied to $outputdir/config_bad\n";
1941 run_command "cp -f $output_config $outputdir/config_bad";
1943 # A config exists in this group that was bad.
1944 foreach my $config (keys %config_list) {
1945 if (!defined($current_config{$config})) {
1946 doprint " removing $config\n";
1947 delete $config_list{$config};
1951 @start_list = @tophalf;
1953 if ($#start_list == 0) {
1954 process_failed $start_list[0];
1958 # remove half the configs we are looking at and see if
1960 $half = int($#start_list / 2);
1961 } while ($#start_list > 0);
1963 # we found a single config, try it again unless we are running manually
1965 if ($bisect_manual) {
1966 process_failed $start_list[0];
1970 my @tophalf = @start_list[0 .. 0];
1972 $ret = run_config_bisect_test $type;
1974 process_passed %current_config;
1978 process_failed $start_list[0];
1985 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1987 my $tmpconfig = "$tmpdir/use_config";
1989 if (defined($config_bisect_good)) {
1990 process_config_ignore $config_bisect_good;
1993 # Make the file with the bad config and the min config
1994 if (defined($minconfig)) {
1995 # read the min config for things to ignore
1996 run_command "cp $minconfig $tmpconfig" or
1997 dodie "failed to copy $minconfig to $tmpconfig";
2002 if (-f $tmpconfig) {
2003 load_force_config($tmpconfig);
2004 process_config_ignore $tmpconfig;
2007 # now process the start config
2008 run_command "cp $start_config $output_config" or
2009 dodie "failed to copy $start_config to $output_config";
2011 # read directly what we want to check
2013 open (IN, $output_config)
2014 or dodie "faied to open $output_config";
2017 if (/^((CONFIG\S*)=.*)/) {
2018 $config_check{$2} = $1;
2023 # Now run oldconfig with the minconfig
2026 # check to see what we lost (or gained)
2027 open (IN, $output_config)
2028 or dodie "Failed to read $start_config";
2030 my %removed_configs;
2034 if (/^((CONFIG\S*)=.*)/) {
2035 # save off all options
2036 $config_set{$2} = $1;
2037 if (defined($config_check{$2})) {
2038 if (defined($config_ignore{$2})) {
2039 $removed_configs{$2} = $1;
2041 $config_list{$2} = $1;
2043 } elsif (!defined($config_ignore{$2})) {
2044 $added_configs{$2} = $1;
2045 $config_list{$2} = $1;
2051 my @confs = keys %removed_configs;
2053 doprint "Configs overridden by default configs and removed from check:\n";
2054 foreach my $config (@confs) {
2055 doprint " $config\n";
2058 @confs = keys %added_configs;
2060 doprint "Configs appearing in make oldconfig and added:\n";
2061 foreach my $config (@confs) {
2062 doprint " $config\n";
2069 # Sometimes kconfig does weird things. We must make sure
2070 # that the config we autocreate has everything we need
2071 # to test, otherwise we may miss testing configs, or
2072 # may not be able to create a new config.
2073 # Here we create a config with everything set.
2074 create_config (keys %config_list);
2075 read_current_config \%config_test;
2076 foreach my $config (keys %config_list) {
2077 if (!defined($config_test{$config})) {
2080 doprint "Configs not produced by kconfig (will not be checked):\n";
2082 doprint " $config\n";
2083 delete $config_list{$config};
2088 $ret = run_config_bisect;
2091 return $ret if ($ret < 0);
2096 sub patchcheck_reboot {
2097 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2098 reboot $patchcheck_sleep_time;
2104 die "PATCHCHECK_START[$i] not defined\n"
2105 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2106 die "PATCHCHECK_TYPE[$i] not defined\n"
2107 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2109 my $start = $opt{"PATCHCHECK_START[$i]"};
2112 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2113 $end = $opt{"PATCHCHECK_END[$i]"};
2116 # Get the true sha1's since we can use things like HEAD~3
2117 $start = get_sha1($start);
2118 $end = get_sha1($end);
2120 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2122 # Can't have a test without having a test to run
2123 if ($type eq "test" && !defined($run_test)) {
2127 open (IN, "git log --pretty=oneline $end|") or
2128 dodie "could not get git list";
2134 $list[$#list+1] = $_;
2135 last if (/^$start/);
2139 if ($list[$#list] !~ /^$start/) {
2140 fail "SHA1 $start not found";
2143 # go backwards in the list
2144 @list = reverse @list;
2146 my $save_clean = $noclean;
2147 my %ignored_warnings;
2149 if (defined($ignore_warnings)) {
2150 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2151 $ignored_warnings{$sha1} = 1;
2156 foreach my $item (@list) {
2158 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2160 doprint "\nProcessing commit $item\n\n";
2162 run_command "git checkout $sha1" or
2163 die "Failed to checkout $sha1";
2165 # only clean on the first and last patch
2166 if ($item eq $list[0] ||
2167 $item eq $list[$#list]) {
2168 $noclean = $save_clean;
2173 if (defined($minconfig)) {
2174 build "useconfig:$minconfig" or return 0;
2176 # ?? no config to use?
2177 build "oldconfig" or return 0;
2181 if (!defined($ignored_warnings{$sha1})) {
2182 check_buildlog $sha1 or return 0;
2185 next if ($type eq "build");
2189 start_monitor_and_boot or $failed = 1;
2191 if (!$failed && $type ne "boot"){
2192 do_run_test or $failed = 1;
2195 return 0 if ($failed);
2213 # taken from streamline_config.pl
2225 if (! -f $kconfig) {
2226 doprint "file $kconfig does not exist, skipping\n";
2230 open(KIN, "$kconfig")
2231 or die "Can't open $kconfig";
2235 # Make sure that lines ending with \ continue
2237 $_ = $line . " " . $_;
2248 # collect any Kconfig sources
2249 if (/^source\s*"(.*)"/) {
2250 $kconfigs[$#kconfigs+1] = $1;
2254 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2258 for (my $i = 0; $i < $iflevel; $i++) {
2260 $depends{$config} .= " " . $ifdeps[$i];
2262 $depends{$config} = $ifdeps[$i];
2267 # collect the depends for the config
2268 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2270 if (defined($depends{$1})) {
2271 $depends{$config} .= " " . $1;
2273 $depends{$config} = $1;
2276 # Get the configs that select this config
2277 } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
2278 if (defined($depends{$1})) {
2279 $depends{$1} .= " " . $config;
2281 $depends{$1} = $config;
2284 # Check for if statements
2285 } elsif (/^if\s+(.*\S)\s*$/) {
2287 # remove beginning and ending non text
2288 $deps =~ s/^[^a-zA-Z0-9_]*//;
2289 $deps =~ s/[^a-zA-Z0-9_]*$//;
2291 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2293 $ifdeps[$iflevel++] = join ':', @deps;
2295 } elsif (/^endif/) {
2297 $iflevel-- if ($iflevel);
2300 } elsif (/^\s*help\s*$/) {
2306 # read in any configs that were found.
2307 foreach $kconfig (@kconfigs) {
2308 if (!defined($read_kconfigs{$kconfig})) {
2309 $read_kconfigs{$kconfig} = 1;
2310 read_kconfig("$builddir/$kconfig");
2316 # find out which arch this is by the kconfig file
2317 open (IN, $output_config)
2318 or dodie "Failed to read $output_config";
2321 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2328 if (!defined($arch)) {
2329 doprint "Could not find arch from config file\n";
2330 doprint "no dependencies used\n";
2334 # arch is really the subarch, we need to know
2335 # what directory to look at.
2336 if ($arch eq "i386" || $arch eq "x86_64") {
2338 } elsif ($arch =~ /^tile/) {
2342 my $kconfig = "$builddir/arch/$arch/Kconfig";
2344 if (! -f $kconfig && $arch =~ /\d$/) {
2346 # some subarchs have numbers, truncate them
2348 $kconfig = "$builddir/arch/$arch/Kconfig";
2349 if (! -f $kconfig) {
2350 doprint "No idea what arch dir $orig is for\n";
2351 doprint "no dependencies used\n";
2356 read_kconfig($kconfig);
2359 sub read_config_list {
2363 or dodie "Failed to read $config";
2366 if (/^((CONFIG\S*)=.*)/) {
2367 if (!defined($config_ignore{$2})) {
2368 $config_list{$2} = $1;
2376 sub read_output_config {
2379 assign_configs \%config_ignore, $config;
2382 sub make_new_config {
2385 open (OUT, ">$output_config")
2386 or dodie "Failed to write $output_config";
2388 foreach my $config (@configs) {
2389 print OUT "$config\n";
2398 $kconfig =~ s/CONFIG_//;
2400 $dep = $depends{"$kconfig"};
2402 # the dep string we have saves the dependencies as they
2403 # were found, including expressions like ! && ||. We
2404 # want to split this out into just an array of configs.
2406 my $valid = "A-Za-z_0-9";
2410 while ($dep =~ /[$valid]/) {
2412 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2413 my $conf = "CONFIG_" . $1;
2415 $configs[$#configs + 1] = $conf;
2417 $dep =~ s/^[^$valid]*[$valid]+//;
2419 die "this should never happen";
2429 my %processed_configs;
2430 my %nochange_config;
2432 sub test_this_config {
2437 # if we already processed this config, skip it
2438 if (defined($processed_configs{$config})) {
2441 $processed_configs{$config} = 1;
2443 # if this config failed during this round, skip it
2444 if (defined($nochange_config{$config})) {
2448 my $kconfig = $config;
2449 $kconfig =~ s/CONFIG_//;
2451 # Test dependencies first
2452 if (defined($depends{"$kconfig"})) {
2453 my @parents = get_depends $config;
2454 foreach my $parent (@parents) {
2455 # if the parent is in the min config, check it first
2456 next if (!defined($min_configs{$parent}));
2457 $found = test_this_config($parent);
2458 if (defined($found)) {
2464 # Remove this config from the list of configs
2465 # do a make oldnoconfig and then read the resulting
2466 # .config to make sure it is missing the config that
2468 my %configs = %min_configs;
2469 delete $configs{$config};
2470 make_new_config ((values %configs), (values %keep_configs));
2473 assign_configs \%configs, $output_config;
2475 return $config if (!defined($configs{$config}));
2477 doprint "disabling config $config did not change .config\n";
2479 $nochange_config{$config} = 1;
2484 sub make_min_config {
2487 if (!defined($output_minconfig)) {
2488 fail "OUTPUT_MIN_CONFIG not defined" and return;
2491 # If output_minconfig exists, and the start_minconfig
2492 # came from min_config, than ask if we should use
2494 if (-f $output_minconfig && !$start_minconfig_defined) {
2495 print "$output_minconfig exists\n";
2496 if (read_yn " Use it as minconfig?") {
2497 $start_minconfig = $output_minconfig;
2501 if (!defined($start_minconfig)) {
2502 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2505 my $temp_config = "$tmpdir/temp_config";
2507 # First things first. We build an allnoconfig to find
2508 # out what the defaults are that we can't touch.
2509 # Some are selections, but we really can't handle selections.
2511 my $save_minconfig = $minconfig;
2514 run_command "$make allnoconfig" or return 0;
2518 process_config_ignore $output_config;
2520 undef %save_configs;
2523 if (defined($ignore_config)) {
2524 # make sure the file exists
2525 `touch $ignore_config`;
2526 assign_configs \%save_configs, $ignore_config;
2529 %keep_configs = %save_configs;
2531 doprint "Load initial configs from $start_minconfig\n";
2533 # Look at the current min configs, and save off all the
2534 # ones that were set via the allnoconfig
2535 assign_configs \%min_configs, $start_minconfig;
2537 my @config_keys = keys %min_configs;
2539 # Remove anything that was set by the make allnoconfig
2540 # we shouldn't need them as they get set for us anyway.
2541 foreach my $config (@config_keys) {
2542 # Remove anything in the ignore_config
2543 if (defined($keep_configs{$config})) {
2544 my $file = $ignore_config;
2545 $file =~ s,.*/(.*?)$,$1,;
2546 doprint "$config set by $file ... ignored\n";
2547 delete $min_configs{$config};
2550 # But make sure the settings are the same. If a min config
2551 # sets a selection, we do not want to get rid of it if
2552 # it is not the same as what we have. Just move it into
2554 if (defined($config_ignore{$config})) {
2555 if ($config_ignore{$config} ne $min_configs{$config}) {
2556 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2557 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2558 $keep_configs{$config} = $min_configs{$config};
2560 doprint "$config set by allnoconfig ... ignored\n";
2562 delete $min_configs{$config};
2574 # Now disable each config one by one and do a make oldconfig
2575 # till we find a config that changes our list.
2577 # Put configs that did not modify the config at the end.
2578 my @test_configs = keys %min_configs;
2580 for (my $i = 0; $i < $#test_configs; $i++) {
2581 if (!defined($nochange_config{$test_configs[0]})) {
2585 # This config didn't change the .config last time.
2586 # Place it at the end
2587 my $config = shift @test_configs;
2588 push @test_configs, $config;
2591 # if every test config has failed to modify the .config file
2592 # in the past, then reset and start over.
2594 undef %nochange_config;
2597 undef %processed_configs;
2599 foreach my $config (@test_configs) {
2601 $found = test_this_config $config;
2603 last if (defined($found));
2605 # oh well, try another config
2608 if (!defined($found)) {
2609 # we could have failed due to the nochange_config hash
2610 # reset and try again
2612 undef %nochange_config;
2616 doprint "No more configs found that we can disable\n";
2624 doprint "Test with $config disabled\n";
2626 # set in_bisect to keep build and monitor from dieing
2631 start_monitor_and_boot or $failed = 1;
2637 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
2638 # this config is needed, add it to the ignore list.
2639 $keep_configs{$config} = $min_configs{$config};
2640 $save_configs{$config} = $min_configs{$config};
2641 delete $min_configs{$config};
2643 # update new ignore configs
2644 if (defined($ignore_config)) {
2645 open (OUT, ">$temp_config")
2646 or die "Can't write to $temp_config";
2647 foreach my $config (keys %save_configs) {
2648 print OUT "$save_configs{$config}\n";
2651 run_command "mv $temp_config $ignore_config" or
2652 dodie "failed to copy update to $ignore_config";
2656 # We booted without this config, remove it from the minconfigs.
2657 doprint "$config is not needed, disabling\n";
2659 delete $min_configs{$config};
2661 # Also disable anything that is not enabled in this config
2663 assign_configs \%configs, $output_config;
2664 my @config_keys = keys %min_configs;
2665 foreach my $config (@config_keys) {
2666 if (!defined($configs{$config})) {
2667 doprint "$config is not set, disabling\n";
2668 delete $min_configs{$config};
2672 # Save off all the current mandidory configs
2673 open (OUT, ">$temp_config")
2674 or die "Can't write to $temp_config";
2675 foreach my $config (keys %keep_configs) {
2676 print OUT "$keep_configs{$config}\n";
2678 foreach my $config (keys %min_configs) {
2679 print OUT "$min_configs{$config}\n";
2683 run_command "mv $temp_config $output_minconfig" or
2684 dodie "failed to copy update to $output_minconfig";
2687 doprint "Reboot and wait $sleep_time seconds\n";
2695 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2698 $ktest_config = $ARGV[0];
2699 if (! -f $ktest_config) {
2700 print "$ktest_config does not exist.\n";
2701 if (!read_yn "Create it?") {
2706 $ktest_config = "ktest.conf";
2709 if (! -f $ktest_config) {
2710 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2712 # Generated by ktest.pl
2714 # Define each test with TEST_START
2715 # The config options below it will override the defaults
2723 read_config $ktest_config;
2725 if (defined($opt{"LOG_FILE"})) {
2726 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2729 # Append any configs entered in manually to the config file.
2730 my @new_configs = keys %entered_configs;
2731 if ($#new_configs >= 0) {
2732 print "\nAppending entered in configs to $ktest_config\n";
2733 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2734 foreach my $config (@new_configs) {
2735 print OUT "$config = $entered_configs{$config}\n";
2736 $opt{$config} = $entered_configs{$config};
2740 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2741 unlink $opt{"LOG_FILE"};
2744 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2746 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2749 doprint "DEFAULT OPTIONS:\n";
2751 doprint "\nTEST $i OPTIONS";
2752 if (defined($repeat_tests{$i})) {
2753 $repeat = $repeat_tests{$i};
2754 doprint " ITERATE $repeat";
2759 foreach my $option (sort keys %opt) {
2761 if ($option =~ /\[(\d+)\]$/) {
2767 doprint "$option = $opt{$option}\n";
2771 sub __set_test_option {
2772 my ($name, $i) = @_;
2774 my $option = "$name\[$i\]";
2776 if (defined($opt{$option})) {
2777 return $opt{$option};
2780 foreach my $test (keys %repeat_tests) {
2782 $i < $test + $repeat_tests{$test}) {
2783 $option = "$name\[$test\]";
2784 if (defined($opt{$option})) {
2785 return $opt{$option};
2790 if (defined($opt{$name})) {
2797 sub set_test_option {
2798 my ($name, $i) = @_;
2800 my $option = __set_test_option($name, $i);
2801 return $option if (!defined($option));
2803 return eval_option($option, $i);
2806 # First we need to do is the builds
2807 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2811 my $makecmd = set_test_option("MAKE_CMD", $i);
2813 $machine = set_test_option("MACHINE", $i);
2814 $ssh_user = set_test_option("SSH_USER", $i);
2815 $tmpdir = set_test_option("TMP_DIR", $i);
2816 $outputdir = set_test_option("OUTPUT_DIR", $i);
2817 $builddir = set_test_option("BUILD_DIR", $i);
2818 $test_type = set_test_option("TEST_TYPE", $i);
2819 $build_type = set_test_option("BUILD_TYPE", $i);
2820 $build_options = set_test_option("BUILD_OPTIONS", $i);
2821 $pre_build = set_test_option("PRE_BUILD", $i);
2822 $post_build = set_test_option("POST_BUILD", $i);
2823 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
2824 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
2825 $power_cycle = set_test_option("POWER_CYCLE", $i);
2826 $reboot = set_test_option("REBOOT", $i);
2827 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2828 $minconfig = set_test_option("MIN_CONFIG", $i);
2829 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
2830 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
2831 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
2832 $run_test = set_test_option("TEST", $i);
2833 $addconfig = set_test_option("ADD_CONFIG", $i);
2834 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2835 $grub_menu = set_test_option("GRUB_MENU", $i);
2836 $post_install = set_test_option("POST_INSTALL", $i);
2837 $no_install = set_test_option("NO_INSTALL", $i);
2838 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2839 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2840 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2841 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2842 $power_off = set_test_option("POWER_OFF", $i);
2843 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2844 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
2845 $sleep_time = set_test_option("SLEEP_TIME", $i);
2846 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
2847 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
2848 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
2849 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
2850 $bisect_skip = set_test_option("BISECT_SKIP", $i);
2851 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
2852 $store_failures = set_test_option("STORE_FAILURES", $i);
2853 $test_name = set_test_option("TEST_NAME", $i);
2854 $timeout = set_test_option("TIMEOUT", $i);
2855 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2856 $console = set_test_option("CONSOLE", $i);
2857 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
2858 $success_line = set_test_option("SUCCESS_LINE", $i);
2859 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
2860 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2861 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
2862 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
2863 $build_target = set_test_option("BUILD_TARGET", $i);
2864 $ssh_exec = set_test_option("SSH_EXEC", $i);
2865 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
2866 $target_image = set_test_option("TARGET_IMAGE", $i);
2867 $localversion = set_test_option("LOCALVERSION", $i);
2869 $start_minconfig_defined = 1;
2871 if (!defined($start_minconfig)) {
2872 $start_minconfig_defined = 0;
2873 $start_minconfig = $minconfig;
2876 chdir $builddir || die "can't change directory to $builddir";
2878 foreach my $dir ($tmpdir, $outputdir) {
2881 die "can't create $dir";
2885 $ENV{"SSH_USER"} = $ssh_user;
2886 $ENV{"MACHINE"} = $machine;
2888 $target = "$ssh_user\@$machine";
2890 $buildlog = "$tmpdir/buildlog-$machine";
2891 $dmesg = "$tmpdir/dmesg-$machine";
2892 $make = "$makecmd O=$outputdir";
2893 $output_config = "$outputdir/.config";
2895 if ($reboot_type eq "grub") {
2896 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
2897 } elsif (!defined($reboot_script)) {
2898 dodie "REBOOT_SCRIPT not defined"
2901 my $run_type = $build_type;
2902 if ($test_type eq "patchcheck") {
2903 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2904 } elsif ($test_type eq "bisect") {
2905 $run_type = $opt{"BISECT_TYPE[$i]"};
2906 } elsif ($test_type eq "config_bisect") {
2907 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
2910 if ($test_type eq "make_min_config") {
2914 # mistake in config file?
2915 if (!defined($run_type)) {
2916 $run_type = "ERROR";
2920 $installme = " no_install" if ($no_install);
2923 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
2928 if (defined($addconfig)) {
2929 my $min = $minconfig;
2930 if (!defined($minconfig)) {
2933 run_command "cat $addconfig $min > $tmpdir/add_config" or
2934 dodie "Failed to create temp config";
2935 $minconfig = "$tmpdir/add_config";
2938 my $checkout = $opt{"CHECKOUT[$i]"};
2939 if (defined($checkout)) {
2940 run_command "git checkout $checkout" or
2941 die "failed to checkout $checkout";
2944 if ($test_type eq "bisect") {
2947 } elsif ($test_type eq "config_bisect") {
2950 } elsif ($test_type eq "patchcheck") {
2953 } elsif ($test_type eq "make_min_config") {
2958 if ($build_type ne "nobuild") {
2959 build $build_type or next;
2962 if ($test_type eq "install") {
2969 if ($test_type ne "build") {
2971 start_monitor_and_boot or $failed = 1;
2973 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2974 do_run_test or $failed = 1;
2983 if ($opt{"POWEROFF_ON_SUCCESS"}) {
2985 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
2989 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";