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{"TEST_TYPE"} = "test";
26 $default{"BUILD_TYPE"} = "randconfig";
27 $default{"MAKE_CMD"} = "make";
28 $default{"TIMEOUT"} = 120;
29 $default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
30 $default{"SLEEP_TIME"} = 60; # sleep time between tests
31 $default{"BUILD_NOCLEAN"} = 0;
32 $default{"REBOOT_ON_ERROR"} = 0;
33 $default{"POWEROFF_ON_ERROR"} = 0;
34 $default{"REBOOT_ON_SUCCESS"} = 1;
35 $default{"POWEROFF_ON_SUCCESS"} = 0;
36 $default{"BUILD_OPTIONS"} = "";
37 $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
38 $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
39 $default{"CLEAR_LOG"} = 0;
40 $default{"BISECT_MANUAL"} = 0;
41 $default{"BISECT_SKIP"} = 1;
42 $default{"SUCCESS_LINE"} = "login:";
43 $default{"DETECT_TRIPLE_FAULT"} = 1;
44 $default{"NO_INSTALL"} = 0;
45 $default{"BOOTED_TIMEOUT"} = 1;
46 $default{"DIE_ON_FAILURE"} = 1;
47 $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
48 $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
49 $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
50 $default{"STOP_AFTER_SUCCESS"} = 10;
51 $default{"STOP_AFTER_FAILURE"} = 60;
52 $default{"STOP_TEST_AFTER"} = 600;
54 # required, and we will ask users if they don't have them but we keep the default
55 # value something that is common.
56 $default{"REBOOT_TYPE"} = "grub";
57 $default{"LOCALVERSION"} = "-test";
58 $default{"SSH_USER"} = "root";
59 $default{"BUILD_TARGET"} = "arch/x86/boot/bzImage";
60 $default{"TARGET_IMAGE"} = "/boot/vmlinuz-test";
82 my $poweroff_on_error;
84 my $powercycle_after_reboot;
85 my $poweroff_after_halt;
98 my $start_minconfig_defined;
107 my $config_bisect_good;
108 my $in_patchcheck = 0;
118 my $bisect_sleep_time;
119 my $patchcheck_sleep_time;
126 my $detect_triplefault;
128 my $reboot_success_line;
130 my $stop_after_success;
131 my $stop_after_failure;
144 # do not force reboots on config problems
147 # default variables that can be used
148 chomp ($variable{"PWD"} = `pwd`);
150 $config_help{"MACHINE"} = << "EOF"
151 The machine hostname that you will test.
154 $config_help{"SSH_USER"} = << "EOF"
155 The box is expected to have ssh on normal bootup, provide the user
156 (most likely root, since you need privileged operations)
159 $config_help{"BUILD_DIR"} = << "EOF"
160 The directory that contains the Linux source code (full path).
163 $config_help{"OUTPUT_DIR"} = << "EOF"
164 The directory that the objects will be built (full path).
165 (can not be same as BUILD_DIR)
168 $config_help{"BUILD_TARGET"} = << "EOF"
169 The location of the compiled file to copy to the target.
170 (relative to OUTPUT_DIR)
173 $config_help{"TARGET_IMAGE"} = << "EOF"
174 The place to put your image on the test machine.
177 $config_help{"POWER_CYCLE"} = << "EOF"
178 A script or command to reboot the box.
180 Here is a digital loggers power switch example
181 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
183 Here is an example to reboot a virtual box on the current host
184 with the name "Guest".
185 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
188 $config_help{"CONSOLE"} = << "EOF"
189 The script or command that reads the console
191 If you use ttywatch server, something like the following would work.
192 CONSOLE = nc -d localhost 3001
194 For a virtual machine with guest name "Guest".
195 CONSOLE = virsh console Guest
198 $config_help{"LOCALVERSION"} = << "EOF"
199 Required version ending to differentiate the test
200 from other linux builds on the system.
203 $config_help{"REBOOT_TYPE"} = << "EOF"
204 Way to reboot the box to the test kernel.
205 Only valid options so far are "grub" and "script".
207 If you specify grub, it will assume grub version 1
208 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
209 and select that target to reboot to the kernel. If this is not
210 your setup, then specify "script" and have a command or script
211 specified in REBOOT_SCRIPT to boot to the target.
213 The entry in /boot/grub/menu.lst must be entered in manually.
214 The test will not modify that file.
217 $config_help{"GRUB_MENU"} = << "EOF"
218 The grub title name for the test kernel to boot
219 (Only mandatory if REBOOT_TYPE = grub)
221 Note, ktest.pl will not update the grub menu.lst, you need to
222 manually add an option for the test. ktest.pl will search
223 the grub menu.lst for this option to find what kernel to
226 For example, if in the /boot/grub/menu.lst the test kernel title has:
229 GRUB_MENU = Test Kernel
232 $config_help{"REBOOT_SCRIPT"} = << "EOF"
233 A script to reboot the target into the test kernel
234 (Only mandatory if REBOOT_TYPE = script)
244 print "$prompt [Y/n] ";
247 if ($ans =~ /^\s*$/) {
250 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
251 print "Please answer either 'y' or 'n'.\n";
253 if ($ans !~ /^y$/i) {
259 sub get_ktest_config {
263 return if (defined($opt{$config}));
265 if (defined($config_help{$config})) {
267 print $config_help{$config};
272 if (defined($default{$config})) {
273 print "\[$default{$config}\] ";
276 $ans =~ s/^\s*(.*\S)\s*$/$1/;
277 if ($ans =~ /^\s*$/) {
278 if ($default{$config}) {
279 $ans = $default{$config};
281 print "Your answer can not be blank\n";
285 $entered_configs{$config} = process_variables($ans);
290 sub get_ktest_configs {
291 get_ktest_config("MACHINE");
292 get_ktest_config("SSH_USER");
293 get_ktest_config("BUILD_DIR");
294 get_ktest_config("OUTPUT_DIR");
295 get_ktest_config("BUILD_TARGET");
296 get_ktest_config("TARGET_IMAGE");
297 get_ktest_config("POWER_CYCLE");
298 get_ktest_config("CONSOLE");
299 get_ktest_config("LOCALVERSION");
301 my $rtype = $opt{"REBOOT_TYPE"};
303 if (!defined($rtype)) {
304 if (!defined($opt{"GRUB_MENU"})) {
305 get_ktest_config("REBOOT_TYPE");
306 $rtype = $entered_configs{"REBOOT_TYPE"};
312 if ($rtype eq "grub") {
313 get_ktest_config("GRUB_MENU");
315 get_ktest_config("REBOOT_SCRIPT");
319 sub process_variables {
320 my ($value, $remove_undef) = @_;
323 # We want to check for '\', and it is just easier
324 # to check the previous characet of '$' and not need
325 # to worry if '$' is the first character. By adding
326 # a space to $value, we can just check [^\\]\$ and
327 # it will still work.
330 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
334 # append beginning of value to retval
335 $retval = "$retval$begin";
336 if (defined($variable{$var})) {
337 $retval = "$retval$variable{$var}";
338 } elsif (defined($remove_undef) && $remove_undef) {
339 # for if statements, any variable that is not defined,
340 # we simple convert to 0
341 $retval = "${retval}0";
343 # put back the origin piece.
344 $retval = "$retval\$\{$var\}";
348 $retval = "$retval$value";
350 # remove the space added in the beginning
357 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
359 if (defined($opt{$lvalue})) {
360 if (!$override || defined(${$overrides}{$lvalue})) {
363 $extra = "In the same override section!\n";
365 die "$name: $.: Option $lvalue defined more than once!\n$extra";
367 ${$overrides}{$lvalue} = $rvalue;
369 if ($rvalue =~ /^\s*$/) {
370 delete $opt{$lvalue};
372 $rvalue = process_variables($rvalue);
373 $opt{$lvalue} = $rvalue;
378 my ($lvalue, $rvalue) = @_;
380 if ($rvalue =~ /^\s*$/) {
381 delete $variable{$lvalue};
383 $rvalue = process_variables($rvalue);
384 $variable{$lvalue} = $rvalue;
388 sub process_compare {
389 my ($lval, $cmp, $rval) = @_;
400 return $lval eq $rval;
401 } elsif ($cmp eq "!=") {
402 return $lval ne $rval;
405 my $statement = "$lval $cmp $rval";
406 my $ret = eval $statement;
408 # $@ stores error of eval
419 return defined($variable{$2}) ||
424 sub process_expression {
425 my ($name, $val) = @_;
429 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
432 if (process_expression($name, $express)) {
433 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
435 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
443 while ($val =~ s/^(.*?)($OR|$AND)//) {
447 if (process_expression($name, $express)) {
458 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
459 my $ret = process_compare($1, $2, $3);
461 die "$name: $.: Unable to process comparison\n";
466 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
468 return !value_defined($2);
470 return value_defined($2);
474 if ($val =~ /^\s*0\s*$/) {
476 } elsif ($val =~ /^\s*\d+\s*$/) {
480 die ("$name: $.: Undefined content $val in if statement\n");
484 my ($name, $value) = @_;
486 # Convert variables and replace undefined ones with 0
487 my $val = process_variables($value, 1);
488 my $ret = process_expression $name, $val;
494 my ($config, $current_test_num) = @_;
497 open($in, $config) || die "can't read file $config";
500 $name =~ s,.*/(.*),$1,;
502 my $test_num = $$current_test_num;
505 my $num_tests_set = 0;
518 # ignore blank lines and comments
519 next if (/^\s*$/ || /\s*\#/);
521 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
531 if ($type eq "TEST_START") {
533 if ($num_tests_set) {
534 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
537 $old_test_num = $test_num;
538 $old_repeat = $repeat;
540 $test_num += $repeat;
547 # If SKIP is anywhere in the line, the command will be skipped
548 if ($rest =~ s/\s+SKIP\b//) {
555 if ($rest =~ s/\sELSE\b//) {
557 die "$name: $.: ELSE found with out matching IF section\n$_";
568 if ($rest =~ s/\sIF\s+(.*)//) {
569 if (process_if($name, $1)) {
581 if ($type eq "TEST_START") {
582 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
584 $repeat_tests{"$test_num"} = $repeat;
586 } elsif ($rest =~ s/\sOVERRIDE\b//) {
589 # Clear previous overrides
594 if (!$skip && $rest !~ /^\s*$/) {
595 die "$name: $.: Gargbage found after $type\n$_";
598 if ($skip && $type eq "TEST_START") {
599 $test_num = $old_test_num;
600 $repeat = $old_repeat;
603 } elsif (/^\s*ELSE\b(.*)$/) {
605 die "$name: $.: ELSE found with out matching IF section\n$_";
614 if ($rest =~ /\sIF\s+(.*)/) {
615 # May be a ELSE IF section.
616 if (!process_if($name, $1)) {
625 if ($rest !~ /^\s*$/) {
626 die "$name: $.: Gargbage found after DEFAULTS\n$_";
629 } elsif (/^\s*INCLUDE\s+(\S+)/) {
634 die "$name: $.: INCLUDE can only be done in default sections\n$_";
637 my $file = process_variables($1);
639 if ($file !~ m,^/,) {
640 # check the path of the config file first
641 if ($config =~ m,(.*)/,) {
649 die "$name: $.: Can't read file $file\n$_";
652 if (__read_config($file, \$test_num)) {
656 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
664 ($lvalue eq "NUM_TESTS" ||
665 $lvalue eq "LOG_FILE" ||
666 $lvalue eq "CLEAR_LOG")) {
667 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
670 if ($lvalue eq "NUM_TESTS") {
672 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
675 die "$name: $.: NUM_TESTS must be set in default section\n";
680 if ($default || $lvalue =~ /\[\d+\]$/) {
681 set_value($lvalue, $rvalue, $override, \%overrides, $name);
683 my $val = "$lvalue\[$test_num\]";
684 set_value($val, $rvalue, $override, \%overrides, $name);
687 $repeats{$val} = $repeat;
690 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
696 # process config variables.
697 # Config variables are only active while reading the
698 # config and can be defined anywhere. They also ignore
699 # TEST_START and DEFAULTS, but are skipped if they are in
700 # on of these sections that have SKIP defined.
701 # The save variable can be
702 # defined multiple times and the new one simply overrides
704 set_variable($lvalue, $rvalue);
707 die "$name: $.: Garbage found in config\n$_";
712 $test_num += $repeat - 1;
713 $opt{"NUM_TESTS"} = $test_num;
718 $$current_test_num = $test_num;
729 $test_case = __read_config $config, \$test_num;
731 # make sure we have all mandatory configs
734 # was a test specified?
736 print "No test case specified.\n";
737 print "What test case would you like to run?\n";
740 $default{"TEST_TYPE"} = $ans;
745 foreach my $default (keys %default) {
746 if (!defined($opt{$default})) {
747 $opt{$default} = $default{$default};
753 my ($option, $i) = @_;
755 # Add space to evaluate the character before $
756 $option = " $option";
761 foreach my $test (keys %repeat_tests) {
763 $i < $test + $repeat_tests{$test}) {
771 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
776 # Append beginning of line
777 $retval = "$retval$start";
779 # If the iteration option OPT[$i] exists, then use that.
780 # otherwise see if the default OPT (without [$i]) exists.
782 my $o = "$var\[$i\]";
783 my $parento = "$var\[$parent\]";
785 if (defined($opt{$o})) {
787 $retval = "$retval$o";
788 } elsif ($repeated && defined($opt{$parento})) {
790 $retval = "$retval$o";
791 } elsif (defined($opt{$var})) {
793 $retval = "$retval$o";
795 $retval = "$retval\$\{$var\}";
801 $retval = "$retval$option";
809 my ($option, $i) = @_;
813 # Since an option can evaluate to another option,
814 # keep iterating until we do not evaluate any more
817 while ($prev ne $option) {
818 # Check for recursive evaluations.
819 # 100 deep should be more than enough.
821 die "Over 100 evaluations accurred with $option\n" .
822 "Check for recursive variables\n";
825 $option = __eval_option($option, $i);
832 if (defined($opt{"LOG_FILE"})) {
833 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
840 if (defined($opt{"LOG_FILE"})) {
855 sub wait_for_monitor;
860 if (defined($time)) {
862 # flush out current monitor
863 # May contain the reboot success line
867 # try to reboot normally
868 if (run_command $reboot) {
869 if (defined($powercycle_after_reboot)) {
870 sleep $powercycle_after_reboot;
871 run_command "$power_cycle";
874 # nope? power cycle it.
875 run_command "$power_cycle";
878 if (defined($time)) {
879 wait_for_monitor($time, $reboot_success_line);
887 return $test_type eq "build" || $no_reboot ||
888 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
889 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
893 doprint "CRITICAL FAILURE... ", @_, "\n";
897 if ($reboot_on_error && !do_not_reboot) {
899 doprint "REBOOTING\n";
902 } elsif ($poweroff_on_error && defined($power_off)) {
903 doprint "POWERING OFF\n";
907 if (defined($opt{"LOG_FILE"})) {
908 print " See $opt{LOG_FILE} for more info.\n";
919 my $pid = open($fp, "$console|") or
920 dodie "Can't open console $console";
922 $flags = fcntl($fp, F_GETFL, 0) or
923 dodie "Can't get flags for the socket: $!";
924 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
925 dodie "Can't set flags for the socket: $!";
933 doprint "kill child process $pid\n";
941 if ($monitor_cnt++) {
944 $monitor_fp = \*MONFD;
945 $monitor_pid = open_console $monitor_fp;
949 open(MONFD, "Stop perl from warning about single use of MONFD");
953 if (--$monitor_cnt) {
956 close_console($monitor_fp, $monitor_pid);
959 sub wait_for_monitor {
960 my ($time, $stop) = @_;
965 doprint "** Wait for monitor to settle down **\n";
967 # read the monitor and wait for the system to calm down
969 $line = wait_for_input($monitor_fp, $time);
970 last if (!defined($line));
974 if (defined($stop) && $full_line =~ /$stop/) {
975 doprint "wait for monitor detected $stop\n";
983 print "** Monitor flushed **\n";
987 my ($result, $basedir) = @_;
989 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
990 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
992 my $type = $build_type;
993 if ($type =~ /useconfig/) {
997 my $dir = "$machine-$test_type-$type-$result-$date";
999 $dir = "$basedir/$dir";
1003 die "can't create $dir";
1007 "config" => $output_config,
1008 "buildlog" => $buildlog,
1010 "testlog" => $testlog,
1013 while (my ($name, $source) = each(%files)) {
1015 cp "$source", "$dir/$name" or
1016 die "failed to copy $source";
1020 doprint "*** Saved info to $dir ***\n";
1025 if ($die_on_failure) {
1033 # no need to reboot for just building.
1034 if (!do_not_reboot) {
1035 doprint "REBOOTING\n";
1041 if (defined($test_name)) {
1042 $name = " ($test_name)";
1045 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1046 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1047 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1048 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1049 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1051 if (defined($store_failures)) {
1052 save_logs "fail", $store_failures;
1064 $command =~ s/\$SSH_USER/$ssh_user/g;
1065 $command =~ s/\$MACHINE/$machine/g;
1067 doprint("$command ... ");
1069 $pid = open(CMD, "$command 2>&1 |") or
1070 (fail "unable to exec $command" and return 0);
1072 if (defined($opt{"LOG_FILE"})) {
1073 open(LOG, ">>$opt{LOG_FILE}") or
1074 dodie "failed to write to log";
1078 if (defined($redirect)) {
1079 open (RD, ">$redirect") or
1080 dodie "failed to write to redirect $redirect";
1085 print LOG if ($dolog);
1086 print RD if ($dord);
1093 close(LOG) if ($dolog);
1094 close(RD) if ($dord);
1097 doprint "FAILED!\n";
1099 doprint "SUCCESS\n";
1107 my $cp_exec = $ssh_exec;
1109 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1110 return run_command "$cp_exec";
1114 my ($src, $dst) = @_;
1115 my $cp_scp = $scp_to_target;
1117 $cp_scp =~ s/\$SRC_FILE/$src/g;
1118 $cp_scp =~ s/\$DST_FILE/$dst/g;
1120 return run_command "$cp_scp";
1123 sub get_grub_index {
1125 if ($reboot_type ne "grub") {
1128 return if (defined($grub_number));
1130 doprint "Find grub menu ... ";
1133 my $ssh_grub = $ssh_exec;
1134 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1136 open(IN, "$ssh_grub |")
1137 or die "unable to get menu.lst";
1142 if (/^\s*title\s+$grub_menu\s*$/) {
1146 } elsif (/^\s*title\s/) {
1152 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1154 doprint "$grub_number\n";
1159 my ($fp, $time) = @_;
1165 if (!defined($time)) {
1170 vec($rin, fileno($fp), 1) = 1;
1171 $ready = select($rin, undef, undef, $time);
1175 # try to read one char at a time
1176 while (sysread $fp, $ch, 1) {
1178 last if ($ch eq "\n");
1181 if (!length($line)) {
1189 if ($reboot_type eq "grub") {
1190 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1195 run_command "$reboot_script";
1201 doprint "git rev-list --max-count=1 $commit ... ";
1202 my $sha1 = `git rev-list --max-count=1 $commit`;
1209 dodie "Failed to get git $commit";
1222 my $skip_call_trace = 0;
1230 open(DMESG, "> $dmesg") or
1231 die "unable to write to $dmesg";
1237 my $monitor_start = time;
1239 my $version_found = 0;
1243 if ($bug && defined($stop_after_failure) &&
1244 $stop_after_failure >= 0) {
1245 my $time = $stop_after_failure - (time - $failure_start);
1246 $line = wait_for_input($monitor_fp, $time);
1247 if (!defined($line)) {
1248 doprint "bug timed out after $booted_timeout seconds\n";
1249 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1253 $line = wait_for_input($monitor_fp, $booted_timeout);
1254 if (!defined($line)) {
1255 my $s = $booted_timeout == 1 ? "" : "s";
1256 doprint "Successful boot found: break after $booted_timeout second$s\n";
1260 $line = wait_for_input($monitor_fp);
1261 if (!defined($line)) {
1262 my $s = $timeout == 1 ? "" : "s";
1263 doprint "Timed out after $timeout second$s\n";
1271 # we are not guaranteed to get a full line
1272 $full_line .= $line;
1274 if ($full_line =~ /$success_line/) {
1276 $success_start = time;
1279 if ($booted && defined($stop_after_success) &&
1280 $stop_after_success >= 0) {
1282 if ($now - $success_start >= $stop_after_success) {
1283 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1288 if ($full_line =~ /\[ backtrace testing \]/) {
1289 $skip_call_trace = 1;
1292 if ($full_line =~ /call trace:/i) {
1293 if (!$bug && !$skip_call_trace) {
1295 $failure_start = time;
1299 if ($bug && defined($stop_after_failure) &&
1300 $stop_after_failure >= 0) {
1302 if ($now - $failure_start >= $stop_after_failure) {
1303 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1308 if ($full_line =~ /\[ end of backtrace testing \]/) {
1309 $skip_call_trace = 0;
1312 if ($full_line =~ /Kernel panic -/) {
1313 $failure_start = time;
1317 # Detect triple faults by testing the banner
1318 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1319 if ($1 eq $version) {
1321 } elsif ($version_found && $detect_triplefault) {
1322 # We already booted into the kernel we are testing,
1323 # but now we booted into another kernel?
1324 # Consider this a triple fault.
1325 doprint "Aleady booted in Linux kernel $version, but now\n";
1326 doprint "we booted into Linux kernel $1.\n";
1327 doprint "Assuming that this is a triple fault.\n";
1328 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1333 if ($line =~ /\n/) {
1337 if ($stop_test_after > 0 && !$booted && !$bug) {
1338 if (time - $monitor_start > $stop_test_after) {
1339 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1348 return 0 if ($in_bisect);
1349 fail "failed - got a bug report" and return 0;
1353 return 0 if ($in_bisect);
1354 fail "failed - never got a boot prompt." and return 0;
1360 sub do_post_install {
1362 return if (!defined($post_install));
1364 my $cp_post_install = $post_install;
1365 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1366 run_command "$cp_post_install" or
1367 dodie "Failed to run post install";
1372 return if ($no_install);
1374 run_scp "$outputdir/$build_target", "$target_image" or
1375 dodie "failed to copy image";
1377 my $install_mods = 0;
1379 # should we process modules?
1381 open(IN, "$output_config") or dodie("Can't read config file");
1383 if (/CONFIG_MODULES(=y)?/) {
1384 $install_mods = 1 if (defined($1));
1390 if (!$install_mods) {
1392 doprint "No modules needed\n";
1396 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1397 dodie "Failed to install modules";
1399 my $modlib = "/lib/modules/$version";
1400 my $modtar = "ktest-mods.tar.bz2";
1402 run_ssh "rm -rf $modlib" or
1403 dodie "failed to remove old mods: $modlib";
1405 # would be nice if scp -r did not follow symbolic links
1406 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1407 dodie "making tarball";
1409 run_scp "$tmpdir/$modtar", "/tmp" or
1410 dodie "failed to copy modules";
1412 unlink "$tmpdir/$modtar";
1414 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1415 dodie "failed to tar modules";
1417 run_ssh "rm -f /tmp/$modtar";
1423 # get the release name
1424 doprint "$make kernelrelease ... ";
1425 $version = `$make kernelrelease | tail -1`;
1427 doprint "$version\n";
1430 sub start_monitor_and_boot {
1431 # Make sure the stable kernel has finished booting
1444 sub check_buildlog {
1447 my @files = `git show $patch | diffstat -l`;
1449 open(IN, "git show $patch |") or
1450 dodie "failed to show $patch";
1452 if (m,^--- a/(.*),) {
1454 $files[$#files] = $1;
1459 open(IN, $buildlog) or dodie "Can't open $buildlog";
1461 if (/^\s*(.*?):.*(warning|error)/) {
1463 foreach my $file (@files) {
1464 my $fullpath = "$builddir/$file";
1465 if ($file eq $err || $fullpath eq $err) {
1466 fail "$file built with warnings" and return 0;
1476 sub apply_min_config {
1477 my $outconfig = "$output_config.new";
1479 # Read the config file and remove anything that
1480 # is in the force_config hash (from minconfig and others)
1481 # then add the force config back.
1483 doprint "Applying minimum configurations into $output_config.new\n";
1485 open (OUT, ">$outconfig") or
1486 dodie "Can't create $outconfig";
1488 if (-f $output_config) {
1489 open (IN, $output_config) or
1490 dodie "Failed to open $output_config";
1492 if (/^(# )?(CONFIG_[^\s=]*)/) {
1493 next if (defined($force_config{$2}));
1499 foreach my $config (keys %force_config) {
1500 print OUT "$force_config{$config}\n";
1504 run_command "mv $outconfig $output_config";
1507 sub make_oldconfig {
1509 my @force_list = keys %force_config;
1511 if ($#force_list >= 0) {
1515 if (!run_command "$make oldnoconfig") {
1516 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1517 # try a yes '' | oldconfig
1518 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1519 run_command "yes '' | $make oldconfig" or
1520 dodie "failed make config oldconfig";
1524 # read a config file and use this to force new configs.
1525 sub load_force_config {
1528 open(IN, $config) or
1529 dodie "failed to read $config";
1532 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1533 $force_config{$1} = $_;
1534 } elsif (/^# (CONFIG_\S*) is not set/) {
1535 $force_config{$1} = $_;
1546 # Failed builds should not reboot the target
1547 my $save_no_reboot = $no_reboot;
1550 if (defined($pre_build)) {
1551 my $ret = run_command $pre_build;
1552 if (!$ret && defined($pre_build_die) &&
1554 dodie "failed to pre_build\n";
1558 if ($type =~ /^useconfig:(.*)/) {
1559 run_command "cp $1 $output_config" or
1560 dodie "could not copy $1 to .config";
1562 $type = "oldconfig";
1565 # old config can ask questions
1566 if ($type eq "oldconfig") {
1567 $type = "oldnoconfig";
1569 # allow for empty configs
1570 run_command "touch $output_config";
1573 run_command "mv $output_config $outputdir/config_temp" or
1574 dodie "moving .config";
1576 run_command "$make mrproper" or dodie "make mrproper";
1578 run_command "mv $outputdir/config_temp $output_config" or
1579 dodie "moving config_temp";
1582 } elsif (!$noclean) {
1583 unlink "$output_config";
1584 run_command "$make mrproper" or
1585 dodie "make mrproper";
1588 # add something to distinguish this build
1589 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1590 print OUT "$localversion\n";
1593 if (defined($minconfig)) {
1594 load_force_config($minconfig);
1597 if ($type ne "oldnoconfig") {
1598 run_command "$make $type" or
1599 dodie "failed make config";
1601 # Run old config regardless, to enforce min configurations
1604 $redirect = "$buildlog";
1605 my $build_ret = run_command "$make $build_options";
1608 if (defined($post_build)) {
1609 my $ret = run_command $post_build;
1610 if (!$ret && defined($post_build_die) &&
1612 dodie "failed to post_build\n";
1617 # bisect may need this to pass
1619 $no_reboot = $save_no_reboot;
1622 fail "failed build" and return 0;
1625 $no_reboot = $save_no_reboot;
1631 if (!run_ssh "halt" or defined($power_off)) {
1632 if (defined($poweroff_after_halt)) {
1633 sleep $poweroff_after_halt;
1634 run_command "$power_off";
1638 run_command "$power_off";
1649 if (defined($test_name)) {
1650 $name = " ($test_name)";
1653 doprint "\n\n*******************************************\n";
1654 doprint "*******************************************\n";
1655 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1656 doprint "*******************************************\n";
1657 doprint "*******************************************\n";
1659 if (defined($store_successes)) {
1660 save_logs "success", $store_successes;
1663 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1664 doprint "Reboot and wait $sleep_time seconds\n";
1671 doprint "Pass or fail? [p/f]";
1674 if ($ans eq "p" || $ans eq "P") {
1676 } elsif ($ans eq "f" || $ans eq "F") {
1679 print "Please answer 'P' or 'F'\n";
1684 sub child_run_test {
1687 # child should have no power
1688 $reboot_on_error = 0;
1689 $poweroff_on_error = 0;
1690 $die_on_failure = 1;
1692 $redirect = "$testlog";
1693 run_command $run_test or $failed = 1;
1701 sub child_finished {
1714 doprint "run test $run_test\n";
1718 $SIG{CHLD} = qw(child_finished);
1722 child_run_test if (!$child_pid);
1727 $line = wait_for_input($monitor_fp, 1);
1728 if (defined($line)) {
1730 # we are not guaranteed to get a full line
1731 $full_line .= $line;
1734 if ($full_line =~ /call trace:/i) {
1738 if ($full_line =~ /Kernel panic -/) {
1742 if ($line =~ /\n/) {
1746 } while (!$child_done && !$bug);
1749 my $failure_start = time;
1752 $line = wait_for_input($monitor_fp, 1);
1753 if (defined($line)) {
1757 if ($now - $failure_start >= $stop_after_failure) {
1760 } while (defined($line));
1762 doprint "Detected kernel crash!\n";
1763 # kill the child with extreme prejudice
1767 waitpid $child_pid, 0;
1770 if ($bug || $child_exit) {
1771 return 0 if $in_bisect;
1772 fail "test failed" and return 0;
1777 sub run_git_bisect {
1780 doprint "$command ... ";
1782 my $output = `$command 2>&1`;
1789 dodie "Failed to git bisect";
1792 doprint "SUCCESS\n";
1793 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1794 doprint "$1 [$2]\n";
1795 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1797 doprint "Found bad commit... $1\n";
1800 # we already logged it, just print it now.
1808 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1809 reboot $bisect_sleep_time;
1812 # returns 1 on success, 0 on failure, -1 on skip
1813 sub run_bisect_test {
1814 my ($type, $buildtype) = @_;
1823 build $buildtype or $failed = 1;
1825 if ($type ne "build") {
1826 if ($failed && $bisect_skip) {
1830 dodie "Failed on build" if $failed;
1833 start_monitor_and_boot or $failed = 1;
1835 if ($type ne "boot") {
1836 if ($failed && $bisect_skip) {
1842 dodie "Failed on boot" if $failed;
1844 do_run_test or $failed = 1;
1855 # reboot the box to a kernel we can ssh to
1856 if ($type ne "build") {
1866 my $buildtype = "oldconfig";
1868 # We should have a minconfig to use?
1869 if (defined($minconfig)) {
1870 $buildtype = "useconfig:$minconfig";
1873 my $ret = run_bisect_test $type, $buildtype;
1875 if ($bisect_manual) {
1876 $ret = answer_bisect;
1879 # Are we looking for where it worked, not failed?
1880 if ($reverse_bisect) {
1886 } elsif ($ret == 0) {
1888 } elsif ($bisect_skip) {
1889 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1899 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1900 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1901 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1903 my $good = $opt{"BISECT_GOOD[$i]"};
1904 my $bad = $opt{"BISECT_BAD[$i]"};
1905 my $type = $opt{"BISECT_TYPE[$i]"};
1906 my $start = $opt{"BISECT_START[$i]"};
1907 my $replay = $opt{"BISECT_REPLAY[$i]"};
1908 my $start_files = $opt{"BISECT_FILES[$i]"};
1910 if (defined($start_files)) {
1911 $start_files = " -- " . $start_files;
1916 # convert to true sha1's
1917 $good = get_sha1($good);
1918 $bad = get_sha1($bad);
1920 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1921 $opt{"BISECT_REVERSE[$i]"} == 1) {
1922 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1923 $reverse_bisect = 1;
1925 $reverse_bisect = 0;
1928 # Can't have a test without having a test to run
1929 if ($type eq "test" && !defined($run_test)) {
1933 my $check = $opt{"BISECT_CHECK[$i]"};
1934 if (defined($check) && $check ne "0") {
1937 my $head = get_sha1("HEAD");
1939 if ($check ne "good") {
1940 doprint "TESTING BISECT BAD [$bad]\n";
1941 run_command "git checkout $bad" or
1942 die "Failed to checkout $bad";
1944 $result = run_bisect $type;
1946 if ($result ne "bad") {
1947 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1951 if ($check ne "bad") {
1952 doprint "TESTING BISECT GOOD [$good]\n";
1953 run_command "git checkout $good" or
1954 die "Failed to checkout $good";
1956 $result = run_bisect $type;
1958 if ($result ne "good") {
1959 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1963 # checkout where we started
1964 run_command "git checkout $head" or
1965 die "Failed to checkout $head";
1968 run_command "git bisect start$start_files" or
1969 dodie "could not start bisect";
1971 run_command "git bisect good $good" or
1972 dodie "could not set bisect good to $good";
1974 run_git_bisect "git bisect bad $bad" or
1975 dodie "could not set bisect bad to $bad";
1977 if (defined($replay)) {
1978 run_command "git bisect replay $replay" or
1979 dodie "failed to run replay";
1982 if (defined($start)) {
1983 run_command "git checkout $start" or
1984 dodie "failed to checkout $start";
1989 $result = run_bisect $type;
1990 $test = run_git_bisect "git bisect $result";
1993 run_command "git bisect log" or
1994 dodie "could not capture git bisect log";
1996 run_command "git bisect reset" or
1997 dodie "could not reset git bisect";
1999 doprint "Bad commit was [$bisect_bad]\n";
2012 sub assign_configs {
2013 my ($hash, $config) = @_;
2016 or dodie "Failed to read $config";
2019 if (/^((CONFIG\S*)=.*)/) {
2027 sub process_config_ignore {
2030 assign_configs \%config_ignore, $config;
2033 sub read_current_config {
2034 my ($config_ref) = @_;
2036 %{$config_ref} = ();
2037 undef %{$config_ref};
2039 my @key = keys %{$config_ref};
2041 print "did not delete!\n";
2044 open (IN, "$output_config");
2047 if (/^(CONFIG\S+)=(.*)/) {
2048 ${$config_ref}{$1} = $2;
2054 sub get_dependencies {
2057 my $arr = $dependency{$config};
2058 if (!defined($arr)) {
2064 foreach my $dep (@{$arr}) {
2065 print "ADD DEP $dep\n";
2066 @deps = (@deps, get_dependencies $dep);
2075 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2077 foreach my $config (@configs) {
2078 print OUT "$config_set{$config}\n";
2079 my @deps = get_dependencies $config;
2080 foreach my $dep (@deps) {
2081 print OUT "$config_set{$dep}\n";
2085 foreach my $config (keys %config_ignore) {
2086 print OUT "$config_ignore{$config}\n";
2094 sub compare_configs {
2097 foreach my $item (keys %a) {
2098 if (!defined($b{$item})) {
2099 print "diff $item\n";
2107 print "diff2 $keys[0]\n";
2109 return -1 if ($#keys >= 0);
2114 sub run_config_bisect_test {
2117 return run_bisect_test $type, "oldconfig";
2120 sub process_passed {
2123 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2124 # Passed! All these configs are part of a good compile.
2125 # Add them to the min options.
2126 foreach my $config (keys %configs) {
2127 if (defined($config_list{$config})) {
2128 doprint " removing $config\n";
2129 $config_ignore{$config} = $config_list{$config};
2130 delete $config_list{$config};
2133 doprint "config copied to $outputdir/config_good\n";
2134 run_command "cp -f $output_config $outputdir/config_good";
2137 sub process_failed {
2140 doprint "\n\n***************************************\n";
2141 doprint "Found bad config: $config\n";
2142 doprint "***************************************\n\n";
2145 sub run_config_bisect {
2147 my @start_list = keys %config_list;
2149 if ($#start_list < 0) {
2150 doprint "No more configs to test!!!\n";
2154 doprint "***** RUN TEST ***\n";
2155 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2159 my $count = $#start_list + 1;
2160 doprint " $count configs to test\n";
2162 my $half = int($#start_list / 2);
2165 my @tophalf = @start_list[0 .. $half];
2167 create_config @tophalf;
2168 read_current_config \%current_config;
2170 $count = $#tophalf + 1;
2171 doprint "Testing $count configs\n";
2173 # make sure we test something
2174 foreach my $config (@tophalf) {
2175 if (defined($current_config{$config})) {
2181 # try the other half
2182 doprint "Top half produced no set configs, trying bottom half\n";
2183 @tophalf = @start_list[$half + 1 .. $#start_list];
2184 create_config @tophalf;
2185 read_current_config \%current_config;
2186 foreach my $config (@tophalf) {
2187 if (defined($current_config{$config})) {
2193 doprint "Failed: Can't make new config with current configs\n";
2194 foreach my $config (@start_list) {
2195 doprint " CONFIG: $config\n";
2199 $count = $#tophalf + 1;
2200 doprint "Testing $count configs\n";
2203 $ret = run_config_bisect_test $type;
2204 if ($bisect_manual) {
2205 $ret = answer_bisect;
2208 process_passed %current_config;
2212 doprint "This config had a failure.\n";
2213 doprint "Removing these configs that were not set in this config:\n";
2214 doprint "config copied to $outputdir/config_bad\n";
2215 run_command "cp -f $output_config $outputdir/config_bad";
2217 # A config exists in this group that was bad.
2218 foreach my $config (keys %config_list) {
2219 if (!defined($current_config{$config})) {
2220 doprint " removing $config\n";
2221 delete $config_list{$config};
2225 @start_list = @tophalf;
2227 if ($#start_list == 0) {
2228 process_failed $start_list[0];
2232 # remove half the configs we are looking at and see if
2234 $half = int($#start_list / 2);
2235 } while ($#start_list > 0);
2237 # we found a single config, try it again unless we are running manually
2239 if ($bisect_manual) {
2240 process_failed $start_list[0];
2244 my @tophalf = @start_list[0 .. 0];
2246 $ret = run_config_bisect_test $type;
2248 process_passed %current_config;
2252 process_failed $start_list[0];
2259 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2261 my $tmpconfig = "$tmpdir/use_config";
2263 if (defined($config_bisect_good)) {
2264 process_config_ignore $config_bisect_good;
2267 # Make the file with the bad config and the min config
2268 if (defined($minconfig)) {
2269 # read the min config for things to ignore
2270 run_command "cp $minconfig $tmpconfig" or
2271 dodie "failed to copy $minconfig to $tmpconfig";
2276 if (-f $tmpconfig) {
2277 load_force_config($tmpconfig);
2278 process_config_ignore $tmpconfig;
2281 # now process the start config
2282 run_command "cp $start_config $output_config" or
2283 dodie "failed to copy $start_config to $output_config";
2285 # read directly what we want to check
2287 open (IN, $output_config)
2288 or dodie "faied to open $output_config";
2291 if (/^((CONFIG\S*)=.*)/) {
2292 $config_check{$2} = $1;
2297 # Now run oldconfig with the minconfig
2300 # check to see what we lost (or gained)
2301 open (IN, $output_config)
2302 or dodie "Failed to read $start_config";
2304 my %removed_configs;
2308 if (/^((CONFIG\S*)=.*)/) {
2309 # save off all options
2310 $config_set{$2} = $1;
2311 if (defined($config_check{$2})) {
2312 if (defined($config_ignore{$2})) {
2313 $removed_configs{$2} = $1;
2315 $config_list{$2} = $1;
2317 } elsif (!defined($config_ignore{$2})) {
2318 $added_configs{$2} = $1;
2319 $config_list{$2} = $1;
2325 my @confs = keys %removed_configs;
2327 doprint "Configs overridden by default configs and removed from check:\n";
2328 foreach my $config (@confs) {
2329 doprint " $config\n";
2332 @confs = keys %added_configs;
2334 doprint "Configs appearing in make oldconfig and added:\n";
2335 foreach my $config (@confs) {
2336 doprint " $config\n";
2343 # Sometimes kconfig does weird things. We must make sure
2344 # that the config we autocreate has everything we need
2345 # to test, otherwise we may miss testing configs, or
2346 # may not be able to create a new config.
2347 # Here we create a config with everything set.
2348 create_config (keys %config_list);
2349 read_current_config \%config_test;
2350 foreach my $config (keys %config_list) {
2351 if (!defined($config_test{$config})) {
2354 doprint "Configs not produced by kconfig (will not be checked):\n";
2356 doprint " $config\n";
2357 delete $config_list{$config};
2362 $ret = run_config_bisect;
2365 return $ret if ($ret < 0);
2370 sub patchcheck_reboot {
2371 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2372 reboot $patchcheck_sleep_time;
2378 die "PATCHCHECK_START[$i] not defined\n"
2379 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2380 die "PATCHCHECK_TYPE[$i] not defined\n"
2381 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2383 my $start = $opt{"PATCHCHECK_START[$i]"};
2386 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2387 $end = $opt{"PATCHCHECK_END[$i]"};
2390 # Get the true sha1's since we can use things like HEAD~3
2391 $start = get_sha1($start);
2392 $end = get_sha1($end);
2394 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2396 # Can't have a test without having a test to run
2397 if ($type eq "test" && !defined($run_test)) {
2401 open (IN, "git log --pretty=oneline $end|") or
2402 dodie "could not get git list";
2408 $list[$#list+1] = $_;
2409 last if (/^$start/);
2413 if ($list[$#list] !~ /^$start/) {
2414 fail "SHA1 $start not found";
2417 # go backwards in the list
2418 @list = reverse @list;
2420 my $save_clean = $noclean;
2421 my %ignored_warnings;
2423 if (defined($ignore_warnings)) {
2424 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2425 $ignored_warnings{$sha1} = 1;
2430 foreach my $item (@list) {
2432 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2434 doprint "\nProcessing commit $item\n\n";
2436 run_command "git checkout $sha1" or
2437 die "Failed to checkout $sha1";
2439 # only clean on the first and last patch
2440 if ($item eq $list[0] ||
2441 $item eq $list[$#list]) {
2442 $noclean = $save_clean;
2447 if (defined($minconfig)) {
2448 build "useconfig:$minconfig" or return 0;
2450 # ?? no config to use?
2451 build "oldconfig" or return 0;
2455 if (!defined($ignored_warnings{$sha1})) {
2456 check_buildlog $sha1 or return 0;
2459 next if ($type eq "build");
2463 start_monitor_and_boot or $failed = 1;
2465 if (!$failed && $type ne "boot"){
2466 do_run_test or $failed = 1;
2469 return 0 if ($failed);
2489 # $config depends on $dep
2490 my ($config, $dep) = @_;
2492 if (defined($depends{$config})) {
2493 $depends{$config} .= " " . $dep;
2495 $depends{$config} = $dep;
2498 # record the number of configs depending on $dep
2499 if (defined $depcount{$dep}) {
2502 $depcount{$dep} = 1;
2506 # taken from streamline_config.pl
2518 if (! -f $kconfig) {
2519 doprint "file $kconfig does not exist, skipping\n";
2523 open(KIN, "$kconfig")
2524 or die "Can't open $kconfig";
2528 # Make sure that lines ending with \ continue
2530 $_ = $line . " " . $_;
2541 # collect any Kconfig sources
2542 if (/^source\s*"(.*)"/) {
2543 $kconfigs[$#kconfigs+1] = $1;
2547 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2551 for (my $i = 0; $i < $iflevel; $i++) {
2552 add_dep $config, $ifdeps[$i];
2555 # collect the depends for the config
2556 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2558 add_dep $config, $1;
2560 # Get the configs that select this config
2561 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2563 # selected by depends on config
2564 add_dep $1, $config;
2566 # Check for if statements
2567 } elsif (/^if\s+(.*\S)\s*$/) {
2569 # remove beginning and ending non text
2570 $deps =~ s/^[^a-zA-Z0-9_]*//;
2571 $deps =~ s/[^a-zA-Z0-9_]*$//;
2573 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2575 $ifdeps[$iflevel++] = join ':', @deps;
2577 } elsif (/^endif/) {
2579 $iflevel-- if ($iflevel);
2582 } elsif (/^\s*help\s*$/) {
2588 # read in any configs that were found.
2589 foreach $kconfig (@kconfigs) {
2590 if (!defined($read_kconfigs{$kconfig})) {
2591 $read_kconfigs{$kconfig} = 1;
2592 read_kconfig("$builddir/$kconfig");
2598 # find out which arch this is by the kconfig file
2599 open (IN, $output_config)
2600 or dodie "Failed to read $output_config";
2603 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2610 if (!defined($arch)) {
2611 doprint "Could not find arch from config file\n";
2612 doprint "no dependencies used\n";
2616 # arch is really the subarch, we need to know
2617 # what directory to look at.
2618 if ($arch eq "i386" || $arch eq "x86_64") {
2620 } elsif ($arch =~ /^tile/) {
2624 my $kconfig = "$builddir/arch/$arch/Kconfig";
2626 if (! -f $kconfig && $arch =~ /\d$/) {
2628 # some subarchs have numbers, truncate them
2630 $kconfig = "$builddir/arch/$arch/Kconfig";
2631 if (! -f $kconfig) {
2632 doprint "No idea what arch dir $orig is for\n";
2633 doprint "no dependencies used\n";
2638 read_kconfig($kconfig);
2641 sub read_config_list {
2645 or dodie "Failed to read $config";
2648 if (/^((CONFIG\S*)=.*)/) {
2649 if (!defined($config_ignore{$2})) {
2650 $config_list{$2} = $1;
2658 sub read_output_config {
2661 assign_configs \%config_ignore, $config;
2664 sub make_new_config {
2667 open (OUT, ">$output_config")
2668 or dodie "Failed to write $output_config";
2670 foreach my $config (@configs) {
2671 print OUT "$config\n";
2679 $config =~ s/CONFIG_//;
2687 my $kconfig = chomp_config $dep;
2689 $dep = $depends{"$kconfig"};
2691 # the dep string we have saves the dependencies as they
2692 # were found, including expressions like ! && ||. We
2693 # want to split this out into just an array of configs.
2695 my $valid = "A-Za-z_0-9";
2699 while ($dep =~ /[$valid]/) {
2701 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2702 my $conf = "CONFIG_" . $1;
2704 $configs[$#configs + 1] = $conf;
2706 $dep =~ s/^[^$valid]*[$valid]+//;
2708 die "this should never happen";
2718 my %processed_configs;
2719 my %nochange_config;
2721 sub test_this_config {
2726 # if we already processed this config, skip it
2727 if (defined($processed_configs{$config})) {
2730 $processed_configs{$config} = 1;
2732 # if this config failed during this round, skip it
2733 if (defined($nochange_config{$config})) {
2737 my $kconfig = chomp_config $config;
2739 # Test dependencies first
2740 if (defined($depends{"$kconfig"})) {
2741 my @parents = get_depends $config;
2742 foreach my $parent (@parents) {
2743 # if the parent is in the min config, check it first
2744 next if (!defined($min_configs{$parent}));
2745 $found = test_this_config($parent);
2746 if (defined($found)) {
2752 # Remove this config from the list of configs
2753 # do a make oldnoconfig and then read the resulting
2754 # .config to make sure it is missing the config that
2756 my %configs = %min_configs;
2757 delete $configs{$config};
2758 make_new_config ((values %configs), (values %keep_configs));
2761 assign_configs \%configs, $output_config;
2763 return $config if (!defined($configs{$config}));
2765 doprint "disabling config $config did not change .config\n";
2767 $nochange_config{$config} = 1;
2772 sub make_min_config {
2775 if (!defined($output_minconfig)) {
2776 fail "OUTPUT_MIN_CONFIG not defined" and return;
2779 # If output_minconfig exists, and the start_minconfig
2780 # came from min_config, than ask if we should use
2782 if (-f $output_minconfig && !$start_minconfig_defined) {
2783 print "$output_minconfig exists\n";
2784 if (read_yn " Use it as minconfig?") {
2785 $start_minconfig = $output_minconfig;
2789 if (!defined($start_minconfig)) {
2790 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2793 my $temp_config = "$tmpdir/temp_config";
2795 # First things first. We build an allnoconfig to find
2796 # out what the defaults are that we can't touch.
2797 # Some are selections, but we really can't handle selections.
2799 my $save_minconfig = $minconfig;
2802 run_command "$make allnoconfig" or return 0;
2806 process_config_ignore $output_config;
2808 undef %save_configs;
2811 if (defined($ignore_config)) {
2812 # make sure the file exists
2813 `touch $ignore_config`;
2814 assign_configs \%save_configs, $ignore_config;
2817 %keep_configs = %save_configs;
2819 doprint "Load initial configs from $start_minconfig\n";
2821 # Look at the current min configs, and save off all the
2822 # ones that were set via the allnoconfig
2823 assign_configs \%min_configs, $start_minconfig;
2825 my @config_keys = keys %min_configs;
2827 # All configs need a depcount
2828 foreach my $config (@config_keys) {
2829 my $kconfig = chomp_config $config;
2830 if (!defined $depcount{$kconfig}) {
2831 $depcount{$kconfig} = 0;
2835 # Remove anything that was set by the make allnoconfig
2836 # we shouldn't need them as they get set for us anyway.
2837 foreach my $config (@config_keys) {
2838 # Remove anything in the ignore_config
2839 if (defined($keep_configs{$config})) {
2840 my $file = $ignore_config;
2841 $file =~ s,.*/(.*?)$,$1,;
2842 doprint "$config set by $file ... ignored\n";
2843 delete $min_configs{$config};
2846 # But make sure the settings are the same. If a min config
2847 # sets a selection, we do not want to get rid of it if
2848 # it is not the same as what we have. Just move it into
2850 if (defined($config_ignore{$config})) {
2851 if ($config_ignore{$config} ne $min_configs{$config}) {
2852 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2853 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2854 $keep_configs{$config} = $min_configs{$config};
2856 doprint "$config set by allnoconfig ... ignored\n";
2858 delete $min_configs{$config};
2870 # Now disable each config one by one and do a make oldconfig
2871 # till we find a config that changes our list.
2873 my @test_configs = keys %min_configs;
2875 # Sort keys by who is most dependent on
2876 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2879 # Put configs that did not modify the config at the end.
2881 for (my $i = 0; $i < $#test_configs; $i++) {
2882 if (!defined($nochange_config{$test_configs[0]})) {
2886 # This config didn't change the .config last time.
2887 # Place it at the end
2888 my $config = shift @test_configs;
2889 push @test_configs, $config;
2892 # if every test config has failed to modify the .config file
2893 # in the past, then reset and start over.
2895 undef %nochange_config;
2898 undef %processed_configs;
2900 foreach my $config (@test_configs) {
2902 $found = test_this_config $config;
2904 last if (defined($found));
2906 # oh well, try another config
2909 if (!defined($found)) {
2910 # we could have failed due to the nochange_config hash
2911 # reset and try again
2913 undef %nochange_config;
2917 doprint "No more configs found that we can disable\n";
2925 doprint "Test with $config disabled\n";
2927 # set in_bisect to keep build and monitor from dieing
2932 start_monitor_and_boot or $failed = 1;
2938 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
2939 # this config is needed, add it to the ignore list.
2940 $keep_configs{$config} = $min_configs{$config};
2941 $save_configs{$config} = $min_configs{$config};
2942 delete $min_configs{$config};
2944 # update new ignore configs
2945 if (defined($ignore_config)) {
2946 open (OUT, ">$temp_config")
2947 or die "Can't write to $temp_config";
2948 foreach my $config (keys %save_configs) {
2949 print OUT "$save_configs{$config}\n";
2952 run_command "mv $temp_config $ignore_config" or
2953 dodie "failed to copy update to $ignore_config";
2957 # We booted without this config, remove it from the minconfigs.
2958 doprint "$config is not needed, disabling\n";
2960 delete $min_configs{$config};
2962 # Also disable anything that is not enabled in this config
2964 assign_configs \%configs, $output_config;
2965 my @config_keys = keys %min_configs;
2966 foreach my $config (@config_keys) {
2967 if (!defined($configs{$config})) {
2968 doprint "$config is not set, disabling\n";
2969 delete $min_configs{$config};
2973 # Save off all the current mandidory configs
2974 open (OUT, ">$temp_config")
2975 or die "Can't write to $temp_config";
2976 foreach my $config (keys %keep_configs) {
2977 print OUT "$keep_configs{$config}\n";
2979 foreach my $config (keys %min_configs) {
2980 print OUT "$min_configs{$config}\n";
2984 run_command "mv $temp_config $output_minconfig" or
2985 dodie "failed to copy update to $output_minconfig";
2988 doprint "Reboot and wait $sleep_time seconds\n";
2996 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2999 $ktest_config = $ARGV[0];
3000 if (! -f $ktest_config) {
3001 print "$ktest_config does not exist.\n";
3002 if (!read_yn "Create it?") {
3007 $ktest_config = "ktest.conf";
3010 if (! -f $ktest_config) {
3011 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3013 # Generated by ktest.pl
3015 # Define each test with TEST_START
3016 # The config options below it will override the defaults
3024 read_config $ktest_config;
3026 if (defined($opt{"LOG_FILE"})) {
3027 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3030 # Append any configs entered in manually to the config file.
3031 my @new_configs = keys %entered_configs;
3032 if ($#new_configs >= 0) {
3033 print "\nAppending entered in configs to $ktest_config\n";
3034 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3035 foreach my $config (@new_configs) {
3036 print OUT "$config = $entered_configs{$config}\n";
3037 $opt{$config} = $entered_configs{$config};
3041 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3042 unlink $opt{"LOG_FILE"};
3045 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3047 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3050 doprint "DEFAULT OPTIONS:\n";
3052 doprint "\nTEST $i OPTIONS";
3053 if (defined($repeat_tests{$i})) {
3054 $repeat = $repeat_tests{$i};
3055 doprint " ITERATE $repeat";
3060 foreach my $option (sort keys %opt) {
3062 if ($option =~ /\[(\d+)\]$/) {
3068 doprint "$option = $opt{$option}\n";
3072 sub __set_test_option {
3073 my ($name, $i) = @_;
3075 my $option = "$name\[$i\]";
3077 if (defined($opt{$option})) {
3078 return $opt{$option};
3081 foreach my $test (keys %repeat_tests) {
3083 $i < $test + $repeat_tests{$test}) {
3084 $option = "$name\[$test\]";
3085 if (defined($opt{$option})) {
3086 return $opt{$option};
3091 if (defined($opt{$name})) {
3098 sub set_test_option {
3099 my ($name, $i) = @_;
3101 my $option = __set_test_option($name, $i);
3102 return $option if (!defined($option));
3104 return eval_option($option, $i);
3107 # First we need to do is the builds
3108 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3110 # Do not reboot on failing test options
3115 my $makecmd = set_test_option("MAKE_CMD", $i);
3117 $machine = set_test_option("MACHINE", $i);
3118 $ssh_user = set_test_option("SSH_USER", $i);
3119 $tmpdir = set_test_option("TMP_DIR", $i);
3120 $outputdir = set_test_option("OUTPUT_DIR", $i);
3121 $builddir = set_test_option("BUILD_DIR", $i);
3122 $test_type = set_test_option("TEST_TYPE", $i);
3123 $build_type = set_test_option("BUILD_TYPE", $i);
3124 $build_options = set_test_option("BUILD_OPTIONS", $i);
3125 $pre_build = set_test_option("PRE_BUILD", $i);
3126 $post_build = set_test_option("POST_BUILD", $i);
3127 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3128 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
3129 $power_cycle = set_test_option("POWER_CYCLE", $i);
3130 $reboot = set_test_option("REBOOT", $i);
3131 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3132 $minconfig = set_test_option("MIN_CONFIG", $i);
3133 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3134 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3135 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
3136 $run_test = set_test_option("TEST", $i);
3137 $addconfig = set_test_option("ADD_CONFIG", $i);
3138 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3139 $grub_menu = set_test_option("GRUB_MENU", $i);
3140 $post_install = set_test_option("POST_INSTALL", $i);
3141 $no_install = set_test_option("NO_INSTALL", $i);
3142 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3143 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3144 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3145 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3146 $power_off = set_test_option("POWER_OFF", $i);
3147 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3148 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
3149 $sleep_time = set_test_option("SLEEP_TIME", $i);
3150 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
3151 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
3152 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
3153 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
3154 $bisect_skip = set_test_option("BISECT_SKIP", $i);
3155 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
3156 $store_failures = set_test_option("STORE_FAILURES", $i);
3157 $store_successes = set_test_option("STORE_SUCCESSES", $i);
3158 $test_name = set_test_option("TEST_NAME", $i);
3159 $timeout = set_test_option("TIMEOUT", $i);
3160 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3161 $console = set_test_option("CONSOLE", $i);
3162 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
3163 $success_line = set_test_option("SUCCESS_LINE", $i);
3164 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
3165 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3166 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
3167 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
3168 $build_target = set_test_option("BUILD_TARGET", $i);
3169 $ssh_exec = set_test_option("SSH_EXEC", $i);
3170 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
3171 $target_image = set_test_option("TARGET_IMAGE", $i);
3172 $localversion = set_test_option("LOCALVERSION", $i);
3174 $start_minconfig_defined = 1;
3176 if (!defined($start_minconfig)) {
3177 $start_minconfig_defined = 0;
3178 $start_minconfig = $minconfig;
3181 chdir $builddir || die "can't change directory to $builddir";
3183 foreach my $dir ($tmpdir, $outputdir) {
3186 die "can't create $dir";
3190 $ENV{"SSH_USER"} = $ssh_user;
3191 $ENV{"MACHINE"} = $machine;
3193 $target = "$ssh_user\@$machine";
3195 $buildlog = "$tmpdir/buildlog-$machine";
3196 $testlog = "$tmpdir/testlog-$machine";
3197 $dmesg = "$tmpdir/dmesg-$machine";
3198 $make = "$makecmd O=$outputdir";
3199 $output_config = "$outputdir/.config";
3201 if ($reboot_type eq "grub") {
3202 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3203 } elsif (!defined($reboot_script)) {
3204 dodie "REBOOT_SCRIPT not defined"
3207 my $run_type = $build_type;
3208 if ($test_type eq "patchcheck") {
3209 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3210 } elsif ($test_type eq "bisect") {
3211 $run_type = $opt{"BISECT_TYPE[$i]"};
3212 } elsif ($test_type eq "config_bisect") {
3213 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
3216 if ($test_type eq "make_min_config") {
3220 # mistake in config file?
3221 if (!defined($run_type)) {
3222 $run_type = "ERROR";
3226 $installme = " no_install" if ($no_install);
3229 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3235 if (defined($addconfig)) {
3236 my $min = $minconfig;
3237 if (!defined($minconfig)) {
3240 run_command "cat $addconfig $min > $tmpdir/add_config" or
3241 dodie "Failed to create temp config";
3242 $minconfig = "$tmpdir/add_config";
3245 my $checkout = $opt{"CHECKOUT[$i]"};
3246 if (defined($checkout)) {
3247 run_command "git checkout $checkout" or
3248 die "failed to checkout $checkout";
3254 if ($test_type eq "bisect") {
3257 } elsif ($test_type eq "config_bisect") {
3260 } elsif ($test_type eq "patchcheck") {
3263 } elsif ($test_type eq "make_min_config") {
3268 if ($build_type ne "nobuild") {
3269 build $build_type or next;
3272 if ($test_type eq "install") {
3279 if ($test_type ne "build") {
3281 start_monitor_and_boot or $failed = 1;
3283 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3284 do_run_test or $failed = 1;
3293 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3295 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
3299 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";