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"} = "build";
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;
139 # set when a test is something other that just building
140 # which would require more options.
143 # set when creating a new config
151 # do not force reboots on config problems
154 # default variables that can be used
155 chomp ($variable{"PWD"} = `pwd`);
157 $config_help{"MACHINE"} = << "EOF"
158 The machine hostname that you will test.
159 For build only tests, it is still needed to differentiate log files.
162 $config_help{"SSH_USER"} = << "EOF"
163 The box is expected to have ssh on normal bootup, provide the user
164 (most likely root, since you need privileged operations)
167 $config_help{"BUILD_DIR"} = << "EOF"
168 The directory that contains the Linux source code (full path).
169 You can use \${PWD} that will be the path where ktest.pl is run, or use
170 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
173 $config_help{"OUTPUT_DIR"} = << "EOF"
174 The directory that the objects will be built (full path).
175 (can not be same as BUILD_DIR)
176 You can use \${PWD} that will be the path where ktest.pl is run, or use
177 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
180 $config_help{"BUILD_TARGET"} = << "EOF"
181 The location of the compiled file to copy to the target.
182 (relative to OUTPUT_DIR)
185 $config_help{"BUILD_OPTIONS"} = << "EOF"
186 Options to add to \"make\" when building.
190 $config_help{"TARGET_IMAGE"} = << "EOF"
191 The place to put your image on the test machine.
194 $config_help{"POWER_CYCLE"} = << "EOF"
195 A script or command to reboot the box.
197 Here is a digital loggers power switch example
198 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
200 Here is an example to reboot a virtual box on the current host
201 with the name "Guest".
202 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
205 $config_help{"CONSOLE"} = << "EOF"
206 The script or command that reads the console
208 If you use ttywatch server, something like the following would work.
209 CONSOLE = nc -d localhost 3001
211 For a virtual machine with guest name "Guest".
212 CONSOLE = virsh console Guest
215 $config_help{"LOCALVERSION"} = << "EOF"
216 Required version ending to differentiate the test
217 from other linux builds on the system.
220 $config_help{"REBOOT_TYPE"} = << "EOF"
221 Way to reboot the box to the test kernel.
222 Only valid options so far are "grub" and "script".
224 If you specify grub, it will assume grub version 1
225 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
226 and select that target to reboot to the kernel. If this is not
227 your setup, then specify "script" and have a command or script
228 specified in REBOOT_SCRIPT to boot to the target.
230 The entry in /boot/grub/menu.lst must be entered in manually.
231 The test will not modify that file.
234 $config_help{"GRUB_MENU"} = << "EOF"
235 The grub title name for the test kernel to boot
236 (Only mandatory if REBOOT_TYPE = grub)
238 Note, ktest.pl will not update the grub menu.lst, you need to
239 manually add an option for the test. ktest.pl will search
240 the grub menu.lst for this option to find what kernel to
243 For example, if in the /boot/grub/menu.lst the test kernel title has:
246 GRUB_MENU = Test Kernel
249 $config_help{"REBOOT_SCRIPT"} = << "EOF"
250 A script to reboot the target into the test kernel
251 (Only mandatory if REBOOT_TYPE = script)
256 my ($cancel, $prompt) = @_;
262 print "$prompt [y/n/C] ";
264 print "$prompt [Y/n] ";
268 if ($ans =~ /^\s*$/) {
275 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
277 last if ($ans =~ /^c$/i);
278 print "Please answer either 'y', 'n' or 'c'.\n";
280 print "Please answer either 'y' or 'n'.\n";
286 if ($ans !~ /^y$/i) {
295 return read_prompt 0, $prompt;
301 return read_prompt 1, $prompt;
304 sub get_ktest_config {
308 return if (defined($opt{$config}));
310 if (defined($config_help{$config})) {
312 print $config_help{$config};
317 if (defined($default{$config}) && length($default{$config})) {
318 print "\[$default{$config}\] ";
321 $ans =~ s/^\s*(.*\S)\s*$/$1/;
322 if ($ans =~ /^\s*$/) {
323 if ($default{$config}) {
324 $ans = $default{$config};
326 print "Your answer can not be blank\n";
330 $entered_configs{$config} = ${ans};
335 sub get_ktest_configs {
336 get_ktest_config("MACHINE");
337 get_ktest_config("BUILD_DIR");
338 get_ktest_config("OUTPUT_DIR");
341 get_ktest_config("BUILD_OPTIONS");
344 # options required for other than just building a kernel
346 get_ktest_config("SSH_USER");
347 get_ktest_config("BUILD_TARGET");
348 get_ktest_config("TARGET_IMAGE");
349 get_ktest_config("POWER_CYCLE");
350 get_ktest_config("CONSOLE");
353 get_ktest_config("LOCALVERSION");
355 return if ($buildonly);
357 my $rtype = $opt{"REBOOT_TYPE"};
359 if (!defined($rtype)) {
360 if (!defined($opt{"GRUB_MENU"})) {
361 get_ktest_config("REBOOT_TYPE");
362 $rtype = $entered_configs{"REBOOT_TYPE"};
368 if ($rtype eq "grub") {
369 get_ktest_config("GRUB_MENU");
371 get_ktest_config("REBOOT_SCRIPT");
375 sub process_variables {
376 my ($value, $remove_undef) = @_;
379 # We want to check for '\', and it is just easier
380 # to check the previous characet of '$' and not need
381 # to worry if '$' is the first character. By adding
382 # a space to $value, we can just check [^\\]\$ and
383 # it will still work.
386 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
390 # append beginning of value to retval
391 $retval = "$retval$begin";
392 if (defined($variable{$var})) {
393 $retval = "$retval$variable{$var}";
394 } elsif (defined($remove_undef) && $remove_undef) {
395 # for if statements, any variable that is not defined,
396 # we simple convert to 0
397 $retval = "${retval}0";
399 # put back the origin piece.
400 $retval = "$retval\$\{$var\}";
404 $retval = "$retval$value";
406 # remove the space added in the beginning
413 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
415 if ($lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $rvalue ne "build") {
416 # Note if a test is something other than build, then we
417 # will need other manditory options.
421 if (defined($opt{$lvalue})) {
422 if (!$override || defined(${$overrides}{$lvalue})) {
425 $extra = "In the same override section!\n";
427 die "$name: $.: Option $lvalue defined more than once!\n$extra";
429 ${$overrides}{$lvalue} = $rvalue;
431 if ($rvalue =~ /^\s*$/) {
432 delete $opt{$lvalue};
434 $rvalue = process_variables($rvalue);
435 $opt{$lvalue} = $rvalue;
440 my ($lvalue, $rvalue) = @_;
442 if ($rvalue =~ /^\s*$/) {
443 delete $variable{$lvalue};
445 $rvalue = process_variables($rvalue);
446 $variable{$lvalue} = $rvalue;
450 sub process_compare {
451 my ($lval, $cmp, $rval) = @_;
462 return $lval eq $rval;
463 } elsif ($cmp eq "!=") {
464 return $lval ne $rval;
467 my $statement = "$lval $cmp $rval";
468 my $ret = eval $statement;
470 # $@ stores error of eval
481 return defined($variable{$2}) ||
486 sub process_expression {
487 my ($name, $val) = @_;
491 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
494 if (process_expression($name, $express)) {
495 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
497 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
505 while ($val =~ s/^(.*?)($OR|$AND)//) {
509 if (process_expression($name, $express)) {
520 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
521 my $ret = process_compare($1, $2, $3);
523 die "$name: $.: Unable to process comparison\n";
528 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
530 return !value_defined($2);
532 return value_defined($2);
536 if ($val =~ /^\s*0\s*$/) {
538 } elsif ($val =~ /^\s*\d+\s*$/) {
542 die ("$name: $.: Undefined content $val in if statement\n");
546 my ($name, $value) = @_;
548 # Convert variables and replace undefined ones with 0
549 my $val = process_variables($value, 1);
550 my $ret = process_expression $name, $val;
556 my ($config, $current_test_num) = @_;
559 open($in, $config) || die "can't read file $config";
562 $name =~ s,.*/(.*),$1,;
564 my $test_num = $$current_test_num;
567 my $num_tests_set = 0;
580 # ignore blank lines and comments
581 next if (/^\s*$/ || /\s*\#/);
583 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
593 if ($type eq "TEST_START") {
595 if ($num_tests_set) {
596 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
599 $old_test_num = $test_num;
600 $old_repeat = $repeat;
602 $test_num += $repeat;
609 # If SKIP is anywhere in the line, the command will be skipped
610 if ($rest =~ s/\s+SKIP\b//) {
617 if ($rest =~ s/\sELSE\b//) {
619 die "$name: $.: ELSE found with out matching IF section\n$_";
630 if ($rest =~ s/\sIF\s+(.*)//) {
631 if (process_if($name, $1)) {
643 if ($type eq "TEST_START") {
644 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
646 $repeat_tests{"$test_num"} = $repeat;
648 } elsif ($rest =~ s/\sOVERRIDE\b//) {
651 # Clear previous overrides
656 if (!$skip && $rest !~ /^\s*$/) {
657 die "$name: $.: Gargbage found after $type\n$_";
660 if ($skip && $type eq "TEST_START") {
661 $test_num = $old_test_num;
662 $repeat = $old_repeat;
665 } elsif (/^\s*ELSE\b(.*)$/) {
667 die "$name: $.: ELSE found with out matching IF section\n$_";
676 if ($rest =~ /\sIF\s+(.*)/) {
677 # May be a ELSE IF section.
678 if (!process_if($name, $1)) {
687 if ($rest !~ /^\s*$/) {
688 die "$name: $.: Gargbage found after DEFAULTS\n$_";
691 } elsif (/^\s*INCLUDE\s+(\S+)/) {
696 die "$name: $.: INCLUDE can only be done in default sections\n$_";
699 my $file = process_variables($1);
701 if ($file !~ m,^/,) {
702 # check the path of the config file first
703 if ($config =~ m,(.*)/,) {
711 die "$name: $.: Can't read file $file\n$_";
714 if (__read_config($file, \$test_num)) {
718 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
726 ($lvalue eq "NUM_TESTS" ||
727 $lvalue eq "LOG_FILE" ||
728 $lvalue eq "CLEAR_LOG")) {
729 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
732 if ($lvalue eq "NUM_TESTS") {
734 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
737 die "$name: $.: NUM_TESTS must be set in default section\n";
742 if ($default || $lvalue =~ /\[\d+\]$/) {
743 set_value($lvalue, $rvalue, $override, \%overrides, $name);
745 my $val = "$lvalue\[$test_num\]";
746 set_value($val, $rvalue, $override, \%overrides, $name);
749 $repeats{$val} = $repeat;
752 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
758 # process config variables.
759 # Config variables are only active while reading the
760 # config and can be defined anywhere. They also ignore
761 # TEST_START and DEFAULTS, but are skipped if they are in
762 # on of these sections that have SKIP defined.
763 # The save variable can be
764 # defined multiple times and the new one simply overrides
766 set_variable($lvalue, $rvalue);
769 die "$name: $.: Garbage found in config\n$_";
774 $test_num += $repeat - 1;
775 $opt{"NUM_TESTS"} = $test_num;
780 $$current_test_num = $test_num;
786 print "What test case would you like to run?\n";
787 print " (build, install or boot)\n";
788 print " Other tests are available but require editing the config file\n";
791 $default{"TEST_TYPE"} = $ans;
800 $test_case = __read_config $config, \$test_num;
802 # make sure we have all mandatory configs
805 # was a test specified?
807 print "No test case specified.\n";
813 foreach my $default (keys %default) {
814 if (!defined($opt{$default})) {
815 $opt{$default} = $default{$default};
821 my ($option, $i) = @_;
823 # Add space to evaluate the character before $
824 $option = " $option";
829 foreach my $test (keys %repeat_tests) {
831 $i < $test + $repeat_tests{$test}) {
839 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
844 # Append beginning of line
845 $retval = "$retval$start";
847 # If the iteration option OPT[$i] exists, then use that.
848 # otherwise see if the default OPT (without [$i]) exists.
850 my $o = "$var\[$i\]";
851 my $parento = "$var\[$parent\]";
853 if (defined($opt{$o})) {
855 $retval = "$retval$o";
856 } elsif ($repeated && defined($opt{$parento})) {
858 $retval = "$retval$o";
859 } elsif (defined($opt{$var})) {
861 $retval = "$retval$o";
863 $retval = "$retval\$\{$var\}";
869 $retval = "$retval$option";
877 my ($option, $i) = @_;
881 # Since an option can evaluate to another option,
882 # keep iterating until we do not evaluate any more
885 while ($prev ne $option) {
886 # Check for recursive evaluations.
887 # 100 deep should be more than enough.
889 die "Over 100 evaluations accurred with $option\n" .
890 "Check for recursive variables\n";
893 $option = __eval_option($option, $i);
900 if (defined($opt{"LOG_FILE"})) {
901 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
908 if (defined($opt{"LOG_FILE"})) {
923 sub wait_for_monitor;
928 if (defined($time)) {
930 # flush out current monitor
931 # May contain the reboot success line
935 # try to reboot normally
936 if (run_command $reboot) {
937 if (defined($powercycle_after_reboot)) {
938 sleep $powercycle_after_reboot;
939 run_command "$power_cycle";
942 # nope? power cycle it.
943 run_command "$power_cycle";
946 if (defined($time)) {
947 wait_for_monitor($time, $reboot_success_line);
955 return $test_type eq "build" || $no_reboot ||
956 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
957 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
961 doprint "CRITICAL FAILURE... ", @_, "\n";
965 if ($reboot_on_error && !do_not_reboot) {
967 doprint "REBOOTING\n";
970 } elsif ($poweroff_on_error && defined($power_off)) {
971 doprint "POWERING OFF\n";
975 if (defined($opt{"LOG_FILE"})) {
976 print " See $opt{LOG_FILE} for more info.\n";
987 my $pid = open($fp, "$console|") or
988 dodie "Can't open console $console";
990 $flags = fcntl($fp, F_GETFL, 0) or
991 dodie "Can't get flags for the socket: $!";
992 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
993 dodie "Can't set flags for the socket: $!";
1001 doprint "kill child process $pid\n";
1009 if ($monitor_cnt++) {
1012 $monitor_fp = \*MONFD;
1013 $monitor_pid = open_console $monitor_fp;
1017 open(MONFD, "Stop perl from warning about single use of MONFD");
1021 if (--$monitor_cnt) {
1024 close_console($monitor_fp, $monitor_pid);
1027 sub wait_for_monitor {
1028 my ($time, $stop) = @_;
1033 doprint "** Wait for monitor to settle down **\n";
1035 # read the monitor and wait for the system to calm down
1037 $line = wait_for_input($monitor_fp, $time);
1038 last if (!defined($line));
1040 $full_line .= $line;
1042 if (defined($stop) && $full_line =~ /$stop/) {
1043 doprint "wait for monitor detected $stop\n";
1047 if ($line =~ /\n/) {
1051 print "** Monitor flushed **\n";
1055 my ($result, $basedir) = @_;
1057 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1058 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1060 my $type = $build_type;
1061 if ($type =~ /useconfig/) {
1062 $type = "useconfig";
1065 my $dir = "$machine-$test_type-$type-$result-$date";
1067 $dir = "$basedir/$dir";
1071 die "can't create $dir";
1075 "config" => $output_config,
1076 "buildlog" => $buildlog,
1078 "testlog" => $testlog,
1081 while (my ($name, $source) = each(%files)) {
1083 cp "$source", "$dir/$name" or
1084 die "failed to copy $source";
1088 doprint "*** Saved info to $dir ***\n";
1093 if ($die_on_failure) {
1101 # no need to reboot for just building.
1102 if (!do_not_reboot) {
1103 doprint "REBOOTING\n";
1109 if (defined($test_name)) {
1110 $name = " ($test_name)";
1113 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1114 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1115 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1116 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1117 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1119 if (defined($store_failures)) {
1120 save_logs "fail", $store_failures;
1132 $command =~ s/\$SSH_USER/$ssh_user/g;
1133 $command =~ s/\$MACHINE/$machine/g;
1135 doprint("$command ... ");
1137 $pid = open(CMD, "$command 2>&1 |") or
1138 (fail "unable to exec $command" and return 0);
1140 if (defined($opt{"LOG_FILE"})) {
1141 open(LOG, ">>$opt{LOG_FILE}") or
1142 dodie "failed to write to log";
1146 if (defined($redirect)) {
1147 open (RD, ">$redirect") or
1148 dodie "failed to write to redirect $redirect";
1153 print LOG if ($dolog);
1154 print RD if ($dord);
1161 close(LOG) if ($dolog);
1162 close(RD) if ($dord);
1165 doprint "FAILED!\n";
1167 doprint "SUCCESS\n";
1175 my $cp_exec = $ssh_exec;
1177 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1178 return run_command "$cp_exec";
1182 my ($src, $dst) = @_;
1183 my $cp_scp = $scp_to_target;
1185 $cp_scp =~ s/\$SRC_FILE/$src/g;
1186 $cp_scp =~ s/\$DST_FILE/$dst/g;
1188 return run_command "$cp_scp";
1191 sub get_grub_index {
1193 if ($reboot_type ne "grub") {
1196 return if (defined($grub_number));
1198 doprint "Find grub menu ... ";
1201 my $ssh_grub = $ssh_exec;
1202 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1204 open(IN, "$ssh_grub |")
1205 or die "unable to get menu.lst";
1210 if (/^\s*title\s+$grub_menu\s*$/) {
1214 } elsif (/^\s*title\s/) {
1220 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1222 doprint "$grub_number\n";
1227 my ($fp, $time) = @_;
1233 if (!defined($time)) {
1238 vec($rin, fileno($fp), 1) = 1;
1239 $ready = select($rin, undef, undef, $time);
1243 # try to read one char at a time
1244 while (sysread $fp, $ch, 1) {
1246 last if ($ch eq "\n");
1249 if (!length($line)) {
1257 if ($reboot_type eq "grub") {
1258 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1263 run_command "$reboot_script";
1269 doprint "git rev-list --max-count=1 $commit ... ";
1270 my $sha1 = `git rev-list --max-count=1 $commit`;
1277 dodie "Failed to get git $commit";
1290 my $skip_call_trace = 0;
1298 open(DMESG, "> $dmesg") or
1299 die "unable to write to $dmesg";
1305 my $monitor_start = time;
1307 my $version_found = 0;
1311 if ($bug && defined($stop_after_failure) &&
1312 $stop_after_failure >= 0) {
1313 my $time = $stop_after_failure - (time - $failure_start);
1314 $line = wait_for_input($monitor_fp, $time);
1315 if (!defined($line)) {
1316 doprint "bug timed out after $booted_timeout seconds\n";
1317 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1321 $line = wait_for_input($monitor_fp, $booted_timeout);
1322 if (!defined($line)) {
1323 my $s = $booted_timeout == 1 ? "" : "s";
1324 doprint "Successful boot found: break after $booted_timeout second$s\n";
1328 $line = wait_for_input($monitor_fp);
1329 if (!defined($line)) {
1330 my $s = $timeout == 1 ? "" : "s";
1331 doprint "Timed out after $timeout second$s\n";
1339 # we are not guaranteed to get a full line
1340 $full_line .= $line;
1342 if ($full_line =~ /$success_line/) {
1344 $success_start = time;
1347 if ($booted && defined($stop_after_success) &&
1348 $stop_after_success >= 0) {
1350 if ($now - $success_start >= $stop_after_success) {
1351 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1356 if ($full_line =~ /\[ backtrace testing \]/) {
1357 $skip_call_trace = 1;
1360 if ($full_line =~ /call trace:/i) {
1361 if (!$bug && !$skip_call_trace) {
1363 $failure_start = time;
1367 if ($bug && defined($stop_after_failure) &&
1368 $stop_after_failure >= 0) {
1370 if ($now - $failure_start >= $stop_after_failure) {
1371 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1376 if ($full_line =~ /\[ end of backtrace testing \]/) {
1377 $skip_call_trace = 0;
1380 if ($full_line =~ /Kernel panic -/) {
1381 $failure_start = time;
1385 # Detect triple faults by testing the banner
1386 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1387 if ($1 eq $version) {
1389 } elsif ($version_found && $detect_triplefault) {
1390 # We already booted into the kernel we are testing,
1391 # but now we booted into another kernel?
1392 # Consider this a triple fault.
1393 doprint "Aleady booted in Linux kernel $version, but now\n";
1394 doprint "we booted into Linux kernel $1.\n";
1395 doprint "Assuming that this is a triple fault.\n";
1396 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1401 if ($line =~ /\n/) {
1405 if ($stop_test_after > 0 && !$booted && !$bug) {
1406 if (time - $monitor_start > $stop_test_after) {
1407 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1416 return 0 if ($in_bisect);
1417 fail "failed - got a bug report" and return 0;
1421 return 0 if ($in_bisect);
1422 fail "failed - never got a boot prompt." and return 0;
1428 sub do_post_install {
1430 return if (!defined($post_install));
1432 my $cp_post_install = $post_install;
1433 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1434 run_command "$cp_post_install" or
1435 dodie "Failed to run post install";
1440 return if ($no_install);
1442 run_scp "$outputdir/$build_target", "$target_image" or
1443 dodie "failed to copy image";
1445 my $install_mods = 0;
1447 # should we process modules?
1449 open(IN, "$output_config") or dodie("Can't read config file");
1451 if (/CONFIG_MODULES(=y)?/) {
1452 $install_mods = 1 if (defined($1));
1458 if (!$install_mods) {
1460 doprint "No modules needed\n";
1464 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1465 dodie "Failed to install modules";
1467 my $modlib = "/lib/modules/$version";
1468 my $modtar = "ktest-mods.tar.bz2";
1470 run_ssh "rm -rf $modlib" or
1471 dodie "failed to remove old mods: $modlib";
1473 # would be nice if scp -r did not follow symbolic links
1474 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1475 dodie "making tarball";
1477 run_scp "$tmpdir/$modtar", "/tmp" or
1478 dodie "failed to copy modules";
1480 unlink "$tmpdir/$modtar";
1482 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1483 dodie "failed to tar modules";
1485 run_ssh "rm -f /tmp/$modtar";
1491 # get the release name
1492 doprint "$make kernelrelease ... ";
1493 $version = `$make kernelrelease | tail -1`;
1495 doprint "$version\n";
1498 sub start_monitor_and_boot {
1499 # Make sure the stable kernel has finished booting
1512 sub check_buildlog {
1515 my @files = `git show $patch | diffstat -l`;
1517 open(IN, "git show $patch |") or
1518 dodie "failed to show $patch";
1520 if (m,^--- a/(.*),) {
1522 $files[$#files] = $1;
1527 open(IN, $buildlog) or dodie "Can't open $buildlog";
1529 if (/^\s*(.*?):.*(warning|error)/) {
1531 foreach my $file (@files) {
1532 my $fullpath = "$builddir/$file";
1533 if ($file eq $err || $fullpath eq $err) {
1534 fail "$file built with warnings" and return 0;
1544 sub apply_min_config {
1545 my $outconfig = "$output_config.new";
1547 # Read the config file and remove anything that
1548 # is in the force_config hash (from minconfig and others)
1549 # then add the force config back.
1551 doprint "Applying minimum configurations into $output_config.new\n";
1553 open (OUT, ">$outconfig") or
1554 dodie "Can't create $outconfig";
1556 if (-f $output_config) {
1557 open (IN, $output_config) or
1558 dodie "Failed to open $output_config";
1560 if (/^(# )?(CONFIG_[^\s=]*)/) {
1561 next if (defined($force_config{$2}));
1567 foreach my $config (keys %force_config) {
1568 print OUT "$force_config{$config}\n";
1572 run_command "mv $outconfig $output_config";
1575 sub make_oldconfig {
1577 my @force_list = keys %force_config;
1579 if ($#force_list >= 0) {
1583 if (!run_command "$make oldnoconfig") {
1584 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1585 # try a yes '' | oldconfig
1586 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1587 run_command "yes '' | $make oldconfig" or
1588 dodie "failed make config oldconfig";
1592 # read a config file and use this to force new configs.
1593 sub load_force_config {
1596 open(IN, $config) or
1597 dodie "failed to read $config";
1600 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1601 $force_config{$1} = $_;
1602 } elsif (/^# (CONFIG_\S*) is not set/) {
1603 $force_config{$1} = $_;
1614 # Failed builds should not reboot the target
1615 my $save_no_reboot = $no_reboot;
1618 if (defined($pre_build)) {
1619 my $ret = run_command $pre_build;
1620 if (!$ret && defined($pre_build_die) &&
1622 dodie "failed to pre_build\n";
1626 if ($type =~ /^useconfig:(.*)/) {
1627 run_command "cp $1 $output_config" or
1628 dodie "could not copy $1 to .config";
1630 $type = "oldconfig";
1633 # old config can ask questions
1634 if ($type eq "oldconfig") {
1635 $type = "oldnoconfig";
1637 # allow for empty configs
1638 run_command "touch $output_config";
1641 run_command "mv $output_config $outputdir/config_temp" or
1642 dodie "moving .config";
1644 run_command "$make mrproper" or dodie "make mrproper";
1646 run_command "mv $outputdir/config_temp $output_config" or
1647 dodie "moving config_temp";
1650 } elsif (!$noclean) {
1651 unlink "$output_config";
1652 run_command "$make mrproper" or
1653 dodie "make mrproper";
1656 # add something to distinguish this build
1657 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1658 print OUT "$localversion\n";
1661 if (defined($minconfig)) {
1662 load_force_config($minconfig);
1665 if ($type ne "oldnoconfig") {
1666 run_command "$make $type" or
1667 dodie "failed make config";
1669 # Run old config regardless, to enforce min configurations
1672 $redirect = "$buildlog";
1673 my $build_ret = run_command "$make $build_options";
1676 if (defined($post_build)) {
1677 my $ret = run_command $post_build;
1678 if (!$ret && defined($post_build_die) &&
1680 dodie "failed to post_build\n";
1685 # bisect may need this to pass
1687 $no_reboot = $save_no_reboot;
1690 fail "failed build" and return 0;
1693 $no_reboot = $save_no_reboot;
1699 if (!run_ssh "halt" or defined($power_off)) {
1700 if (defined($poweroff_after_halt)) {
1701 sleep $poweroff_after_halt;
1702 run_command "$power_off";
1706 run_command "$power_off";
1717 if (defined($test_name)) {
1718 $name = " ($test_name)";
1721 doprint "\n\n*******************************************\n";
1722 doprint "*******************************************\n";
1723 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1724 doprint "*******************************************\n";
1725 doprint "*******************************************\n";
1727 if (defined($store_successes)) {
1728 save_logs "success", $store_successes;
1731 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1732 doprint "Reboot and wait $sleep_time seconds\n";
1739 doprint "Pass or fail? [p/f]";
1742 if ($ans eq "p" || $ans eq "P") {
1744 } elsif ($ans eq "f" || $ans eq "F") {
1747 print "Please answer 'P' or 'F'\n";
1752 sub child_run_test {
1755 # child should have no power
1756 $reboot_on_error = 0;
1757 $poweroff_on_error = 0;
1758 $die_on_failure = 1;
1760 $redirect = "$testlog";
1761 run_command $run_test or $failed = 1;
1769 sub child_finished {
1782 doprint "run test $run_test\n";
1786 $SIG{CHLD} = qw(child_finished);
1790 child_run_test if (!$child_pid);
1795 $line = wait_for_input($monitor_fp, 1);
1796 if (defined($line)) {
1798 # we are not guaranteed to get a full line
1799 $full_line .= $line;
1802 if ($full_line =~ /call trace:/i) {
1806 if ($full_line =~ /Kernel panic -/) {
1810 if ($line =~ /\n/) {
1814 } while (!$child_done && !$bug);
1817 my $failure_start = time;
1820 $line = wait_for_input($monitor_fp, 1);
1821 if (defined($line)) {
1825 if ($now - $failure_start >= $stop_after_failure) {
1828 } while (defined($line));
1830 doprint "Detected kernel crash!\n";
1831 # kill the child with extreme prejudice
1835 waitpid $child_pid, 0;
1838 if ($bug || $child_exit) {
1839 return 0 if $in_bisect;
1840 fail "test failed" and return 0;
1845 sub run_git_bisect {
1848 doprint "$command ... ";
1850 my $output = `$command 2>&1`;
1857 dodie "Failed to git bisect";
1860 doprint "SUCCESS\n";
1861 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1862 doprint "$1 [$2]\n";
1863 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1865 doprint "Found bad commit... $1\n";
1868 # we already logged it, just print it now.
1876 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1877 reboot $bisect_sleep_time;
1880 # returns 1 on success, 0 on failure, -1 on skip
1881 sub run_bisect_test {
1882 my ($type, $buildtype) = @_;
1891 build $buildtype or $failed = 1;
1893 if ($type ne "build") {
1894 if ($failed && $bisect_skip) {
1898 dodie "Failed on build" if $failed;
1901 start_monitor_and_boot or $failed = 1;
1903 if ($type ne "boot") {
1904 if ($failed && $bisect_skip) {
1910 dodie "Failed on boot" if $failed;
1912 do_run_test or $failed = 1;
1923 # reboot the box to a kernel we can ssh to
1924 if ($type ne "build") {
1934 my $buildtype = "oldconfig";
1936 # We should have a minconfig to use?
1937 if (defined($minconfig)) {
1938 $buildtype = "useconfig:$minconfig";
1941 my $ret = run_bisect_test $type, $buildtype;
1943 if ($bisect_manual) {
1944 $ret = answer_bisect;
1947 # Are we looking for where it worked, not failed?
1948 if ($reverse_bisect) {
1954 } elsif ($ret == 0) {
1956 } elsif ($bisect_skip) {
1957 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1962 sub update_bisect_replay {
1963 my $tmp_log = "$tmpdir/ktest_bisect_log";
1964 run_command "git bisect log > $tmp_log" or
1965 die "can't create bisect log";
1974 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1975 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1976 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1978 my $good = $opt{"BISECT_GOOD[$i]"};
1979 my $bad = $opt{"BISECT_BAD[$i]"};
1980 my $type = $opt{"BISECT_TYPE[$i]"};
1981 my $start = $opt{"BISECT_START[$i]"};
1982 my $replay = $opt{"BISECT_REPLAY[$i]"};
1983 my $start_files = $opt{"BISECT_FILES[$i]"};
1985 if (defined($start_files)) {
1986 $start_files = " -- " . $start_files;
1991 # convert to true sha1's
1992 $good = get_sha1($good);
1993 $bad = get_sha1($bad);
1995 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1996 $opt{"BISECT_REVERSE[$i]"} == 1) {
1997 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1998 $reverse_bisect = 1;
2000 $reverse_bisect = 0;
2003 # Can't have a test without having a test to run
2004 if ($type eq "test" && !defined($run_test)) {
2008 # Check if a bisect was running
2009 my $bisect_start_file = "$builddir/.git/BISECT_START";
2011 my $check = $opt{"BISECT_CHECK[$i]"};
2012 my $do_check = defined($check) && $check ne "0";
2014 if ( -f $bisect_start_file ) {
2015 print "Bisect in progress found\n";
2017 print " If you say yes, then no checks of good or bad will be done\n";
2019 if (defined($replay)) {
2020 print "** BISECT_REPLAY is defined in config file **";
2021 print " Ignore config option and perform new git bisect log?\n";
2022 if (read_ync " (yes, no, or cancel) ") {
2023 $replay = update_bisect_replay;
2026 } elsif (read_yn "read git log and continue?") {
2027 $replay = update_bisect_replay;
2035 my $head = get_sha1("HEAD");
2037 if ($check ne "good") {
2038 doprint "TESTING BISECT BAD [$bad]\n";
2039 run_command "git checkout $bad" or
2040 die "Failed to checkout $bad";
2042 $result = run_bisect $type;
2044 if ($result ne "bad") {
2045 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2049 if ($check ne "bad") {
2050 doprint "TESTING BISECT GOOD [$good]\n";
2051 run_command "git checkout $good" or
2052 die "Failed to checkout $good";
2054 $result = run_bisect $type;
2056 if ($result ne "good") {
2057 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2061 # checkout where we started
2062 run_command "git checkout $head" or
2063 die "Failed to checkout $head";
2066 run_command "git bisect start$start_files" or
2067 dodie "could not start bisect";
2069 run_command "git bisect good $good" or
2070 dodie "could not set bisect good to $good";
2072 run_git_bisect "git bisect bad $bad" or
2073 dodie "could not set bisect bad to $bad";
2075 if (defined($replay)) {
2076 run_command "git bisect replay $replay" or
2077 dodie "failed to run replay";
2080 if (defined($start)) {
2081 run_command "git checkout $start" or
2082 dodie "failed to checkout $start";
2087 $result = run_bisect $type;
2088 $test = run_git_bisect "git bisect $result";
2091 run_command "git bisect log" or
2092 dodie "could not capture git bisect log";
2094 run_command "git bisect reset" or
2095 dodie "could not reset git bisect";
2097 doprint "Bad commit was [$bisect_bad]\n";
2110 sub assign_configs {
2111 my ($hash, $config) = @_;
2114 or dodie "Failed to read $config";
2117 if (/^((CONFIG\S*)=.*)/) {
2125 sub process_config_ignore {
2128 assign_configs \%config_ignore, $config;
2131 sub read_current_config {
2132 my ($config_ref) = @_;
2134 %{$config_ref} = ();
2135 undef %{$config_ref};
2137 my @key = keys %{$config_ref};
2139 print "did not delete!\n";
2142 open (IN, "$output_config");
2145 if (/^(CONFIG\S+)=(.*)/) {
2146 ${$config_ref}{$1} = $2;
2152 sub get_dependencies {
2155 my $arr = $dependency{$config};
2156 if (!defined($arr)) {
2162 foreach my $dep (@{$arr}) {
2163 print "ADD DEP $dep\n";
2164 @deps = (@deps, get_dependencies $dep);
2173 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2175 foreach my $config (@configs) {
2176 print OUT "$config_set{$config}\n";
2177 my @deps = get_dependencies $config;
2178 foreach my $dep (@deps) {
2179 print OUT "$config_set{$dep}\n";
2183 foreach my $config (keys %config_ignore) {
2184 print OUT "$config_ignore{$config}\n";
2192 sub compare_configs {
2195 foreach my $item (keys %a) {
2196 if (!defined($b{$item})) {
2197 print "diff $item\n";
2205 print "diff2 $keys[0]\n";
2207 return -1 if ($#keys >= 0);
2212 sub run_config_bisect_test {
2215 return run_bisect_test $type, "oldconfig";
2218 sub process_passed {
2221 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2222 # Passed! All these configs are part of a good compile.
2223 # Add them to the min options.
2224 foreach my $config (keys %configs) {
2225 if (defined($config_list{$config})) {
2226 doprint " removing $config\n";
2227 $config_ignore{$config} = $config_list{$config};
2228 delete $config_list{$config};
2231 doprint "config copied to $outputdir/config_good\n";
2232 run_command "cp -f $output_config $outputdir/config_good";
2235 sub process_failed {
2238 doprint "\n\n***************************************\n";
2239 doprint "Found bad config: $config\n";
2240 doprint "***************************************\n\n";
2243 sub run_config_bisect {
2245 my @start_list = keys %config_list;
2247 if ($#start_list < 0) {
2248 doprint "No more configs to test!!!\n";
2252 doprint "***** RUN TEST ***\n";
2253 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2257 my $count = $#start_list + 1;
2258 doprint " $count configs to test\n";
2260 my $half = int($#start_list / 2);
2263 my @tophalf = @start_list[0 .. $half];
2265 create_config @tophalf;
2266 read_current_config \%current_config;
2268 $count = $#tophalf + 1;
2269 doprint "Testing $count configs\n";
2271 # make sure we test something
2272 foreach my $config (@tophalf) {
2273 if (defined($current_config{$config})) {
2279 # try the other half
2280 doprint "Top half produced no set configs, trying bottom half\n";
2281 @tophalf = @start_list[$half + 1 .. $#start_list];
2282 create_config @tophalf;
2283 read_current_config \%current_config;
2284 foreach my $config (@tophalf) {
2285 if (defined($current_config{$config})) {
2291 doprint "Failed: Can't make new config with current configs\n";
2292 foreach my $config (@start_list) {
2293 doprint " CONFIG: $config\n";
2297 $count = $#tophalf + 1;
2298 doprint "Testing $count configs\n";
2301 $ret = run_config_bisect_test $type;
2302 if ($bisect_manual) {
2303 $ret = answer_bisect;
2306 process_passed %current_config;
2310 doprint "This config had a failure.\n";
2311 doprint "Removing these configs that were not set in this config:\n";
2312 doprint "config copied to $outputdir/config_bad\n";
2313 run_command "cp -f $output_config $outputdir/config_bad";
2315 # A config exists in this group that was bad.
2316 foreach my $config (keys %config_list) {
2317 if (!defined($current_config{$config})) {
2318 doprint " removing $config\n";
2319 delete $config_list{$config};
2323 @start_list = @tophalf;
2325 if ($#start_list == 0) {
2326 process_failed $start_list[0];
2330 # remove half the configs we are looking at and see if
2332 $half = int($#start_list / 2);
2333 } while ($#start_list > 0);
2335 # we found a single config, try it again unless we are running manually
2337 if ($bisect_manual) {
2338 process_failed $start_list[0];
2342 my @tophalf = @start_list[0 .. 0];
2344 $ret = run_config_bisect_test $type;
2346 process_passed %current_config;
2350 process_failed $start_list[0];
2357 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2359 my $tmpconfig = "$tmpdir/use_config";
2361 if (defined($config_bisect_good)) {
2362 process_config_ignore $config_bisect_good;
2365 # Make the file with the bad config and the min config
2366 if (defined($minconfig)) {
2367 # read the min config for things to ignore
2368 run_command "cp $minconfig $tmpconfig" or
2369 dodie "failed to copy $minconfig to $tmpconfig";
2374 if (-f $tmpconfig) {
2375 load_force_config($tmpconfig);
2376 process_config_ignore $tmpconfig;
2379 # now process the start config
2380 run_command "cp $start_config $output_config" or
2381 dodie "failed to copy $start_config to $output_config";
2383 # read directly what we want to check
2385 open (IN, $output_config)
2386 or dodie "faied to open $output_config";
2389 if (/^((CONFIG\S*)=.*)/) {
2390 $config_check{$2} = $1;
2395 # Now run oldconfig with the minconfig
2398 # check to see what we lost (or gained)
2399 open (IN, $output_config)
2400 or dodie "Failed to read $start_config";
2402 my %removed_configs;
2406 if (/^((CONFIG\S*)=.*)/) {
2407 # save off all options
2408 $config_set{$2} = $1;
2409 if (defined($config_check{$2})) {
2410 if (defined($config_ignore{$2})) {
2411 $removed_configs{$2} = $1;
2413 $config_list{$2} = $1;
2415 } elsif (!defined($config_ignore{$2})) {
2416 $added_configs{$2} = $1;
2417 $config_list{$2} = $1;
2423 my @confs = keys %removed_configs;
2425 doprint "Configs overridden by default configs and removed from check:\n";
2426 foreach my $config (@confs) {
2427 doprint " $config\n";
2430 @confs = keys %added_configs;
2432 doprint "Configs appearing in make oldconfig and added:\n";
2433 foreach my $config (@confs) {
2434 doprint " $config\n";
2441 # Sometimes kconfig does weird things. We must make sure
2442 # that the config we autocreate has everything we need
2443 # to test, otherwise we may miss testing configs, or
2444 # may not be able to create a new config.
2445 # Here we create a config with everything set.
2446 create_config (keys %config_list);
2447 read_current_config \%config_test;
2448 foreach my $config (keys %config_list) {
2449 if (!defined($config_test{$config})) {
2452 doprint "Configs not produced by kconfig (will not be checked):\n";
2454 doprint " $config\n";
2455 delete $config_list{$config};
2460 $ret = run_config_bisect;
2463 return $ret if ($ret < 0);
2468 sub patchcheck_reboot {
2469 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2470 reboot $patchcheck_sleep_time;
2476 die "PATCHCHECK_START[$i] not defined\n"
2477 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2478 die "PATCHCHECK_TYPE[$i] not defined\n"
2479 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2481 my $start = $opt{"PATCHCHECK_START[$i]"};
2484 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2485 $end = $opt{"PATCHCHECK_END[$i]"};
2488 # Get the true sha1's since we can use things like HEAD~3
2489 $start = get_sha1($start);
2490 $end = get_sha1($end);
2492 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2494 # Can't have a test without having a test to run
2495 if ($type eq "test" && !defined($run_test)) {
2499 open (IN, "git log --pretty=oneline $end|") or
2500 dodie "could not get git list";
2506 $list[$#list+1] = $_;
2507 last if (/^$start/);
2511 if ($list[$#list] !~ /^$start/) {
2512 fail "SHA1 $start not found";
2515 # go backwards in the list
2516 @list = reverse @list;
2518 my $save_clean = $noclean;
2519 my %ignored_warnings;
2521 if (defined($ignore_warnings)) {
2522 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2523 $ignored_warnings{$sha1} = 1;
2528 foreach my $item (@list) {
2530 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2532 doprint "\nProcessing commit $item\n\n";
2534 run_command "git checkout $sha1" or
2535 die "Failed to checkout $sha1";
2537 # only clean on the first and last patch
2538 if ($item eq $list[0] ||
2539 $item eq $list[$#list]) {
2540 $noclean = $save_clean;
2545 if (defined($minconfig)) {
2546 build "useconfig:$minconfig" or return 0;
2548 # ?? no config to use?
2549 build "oldconfig" or return 0;
2553 if (!defined($ignored_warnings{$sha1})) {
2554 check_buildlog $sha1 or return 0;
2557 next if ($type eq "build");
2561 start_monitor_and_boot or $failed = 1;
2563 if (!$failed && $type ne "boot"){
2564 do_run_test or $failed = 1;
2567 return 0 if ($failed);
2587 # $config depends on $dep
2588 my ($config, $dep) = @_;
2590 if (defined($depends{$config})) {
2591 $depends{$config} .= " " . $dep;
2593 $depends{$config} = $dep;
2596 # record the number of configs depending on $dep
2597 if (defined $depcount{$dep}) {
2600 $depcount{$dep} = 1;
2604 # taken from streamline_config.pl
2616 if (! -f $kconfig) {
2617 doprint "file $kconfig does not exist, skipping\n";
2621 open(KIN, "$kconfig")
2622 or die "Can't open $kconfig";
2626 # Make sure that lines ending with \ continue
2628 $_ = $line . " " . $_;
2639 # collect any Kconfig sources
2640 if (/^source\s*"(.*)"/) {
2641 $kconfigs[$#kconfigs+1] = $1;
2645 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2649 for (my $i = 0; $i < $iflevel; $i++) {
2650 add_dep $config, $ifdeps[$i];
2653 # collect the depends for the config
2654 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2656 add_dep $config, $1;
2658 # Get the configs that select this config
2659 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2661 # selected by depends on config
2662 add_dep $1, $config;
2664 # Check for if statements
2665 } elsif (/^if\s+(.*\S)\s*$/) {
2667 # remove beginning and ending non text
2668 $deps =~ s/^[^a-zA-Z0-9_]*//;
2669 $deps =~ s/[^a-zA-Z0-9_]*$//;
2671 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2673 $ifdeps[$iflevel++] = join ':', @deps;
2675 } elsif (/^endif/) {
2677 $iflevel-- if ($iflevel);
2680 } elsif (/^\s*help\s*$/) {
2686 # read in any configs that were found.
2687 foreach $kconfig (@kconfigs) {
2688 if (!defined($read_kconfigs{$kconfig})) {
2689 $read_kconfigs{$kconfig} = 1;
2690 read_kconfig("$builddir/$kconfig");
2696 # find out which arch this is by the kconfig file
2697 open (IN, $output_config)
2698 or dodie "Failed to read $output_config";
2701 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2708 if (!defined($arch)) {
2709 doprint "Could not find arch from config file\n";
2710 doprint "no dependencies used\n";
2714 # arch is really the subarch, we need to know
2715 # what directory to look at.
2716 if ($arch eq "i386" || $arch eq "x86_64") {
2718 } elsif ($arch =~ /^tile/) {
2722 my $kconfig = "$builddir/arch/$arch/Kconfig";
2724 if (! -f $kconfig && $arch =~ /\d$/) {
2726 # some subarchs have numbers, truncate them
2728 $kconfig = "$builddir/arch/$arch/Kconfig";
2729 if (! -f $kconfig) {
2730 doprint "No idea what arch dir $orig is for\n";
2731 doprint "no dependencies used\n";
2736 read_kconfig($kconfig);
2739 sub read_config_list {
2743 or dodie "Failed to read $config";
2746 if (/^((CONFIG\S*)=.*)/) {
2747 if (!defined($config_ignore{$2})) {
2748 $config_list{$2} = $1;
2756 sub read_output_config {
2759 assign_configs \%config_ignore, $config;
2762 sub make_new_config {
2765 open (OUT, ">$output_config")
2766 or dodie "Failed to write $output_config";
2768 foreach my $config (@configs) {
2769 print OUT "$config\n";
2777 $config =~ s/CONFIG_//;
2785 my $kconfig = chomp_config $dep;
2787 $dep = $depends{"$kconfig"};
2789 # the dep string we have saves the dependencies as they
2790 # were found, including expressions like ! && ||. We
2791 # want to split this out into just an array of configs.
2793 my $valid = "A-Za-z_0-9";
2797 while ($dep =~ /[$valid]/) {
2799 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2800 my $conf = "CONFIG_" . $1;
2802 $configs[$#configs + 1] = $conf;
2804 $dep =~ s/^[^$valid]*[$valid]+//;
2806 die "this should never happen";
2816 my %processed_configs;
2817 my %nochange_config;
2819 sub test_this_config {
2824 # if we already processed this config, skip it
2825 if (defined($processed_configs{$config})) {
2828 $processed_configs{$config} = 1;
2830 # if this config failed during this round, skip it
2831 if (defined($nochange_config{$config})) {
2835 my $kconfig = chomp_config $config;
2837 # Test dependencies first
2838 if (defined($depends{"$kconfig"})) {
2839 my @parents = get_depends $config;
2840 foreach my $parent (@parents) {
2841 # if the parent is in the min config, check it first
2842 next if (!defined($min_configs{$parent}));
2843 $found = test_this_config($parent);
2844 if (defined($found)) {
2850 # Remove this config from the list of configs
2851 # do a make oldnoconfig and then read the resulting
2852 # .config to make sure it is missing the config that
2854 my %configs = %min_configs;
2855 delete $configs{$config};
2856 make_new_config ((values %configs), (values %keep_configs));
2859 assign_configs \%configs, $output_config;
2861 return $config if (!defined($configs{$config}));
2863 doprint "disabling config $config did not change .config\n";
2865 $nochange_config{$config} = 1;
2870 sub make_min_config {
2873 if (!defined($output_minconfig)) {
2874 fail "OUTPUT_MIN_CONFIG not defined" and return;
2877 # If output_minconfig exists, and the start_minconfig
2878 # came from min_config, than ask if we should use
2880 if (-f $output_minconfig && !$start_minconfig_defined) {
2881 print "$output_minconfig exists\n";
2882 if (read_yn " Use it as minconfig?") {
2883 $start_minconfig = $output_minconfig;
2887 if (!defined($start_minconfig)) {
2888 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2891 my $temp_config = "$tmpdir/temp_config";
2893 # First things first. We build an allnoconfig to find
2894 # out what the defaults are that we can't touch.
2895 # Some are selections, but we really can't handle selections.
2897 my $save_minconfig = $minconfig;
2900 run_command "$make allnoconfig" or return 0;
2904 process_config_ignore $output_config;
2906 undef %save_configs;
2909 if (defined($ignore_config)) {
2910 # make sure the file exists
2911 `touch $ignore_config`;
2912 assign_configs \%save_configs, $ignore_config;
2915 %keep_configs = %save_configs;
2917 doprint "Load initial configs from $start_minconfig\n";
2919 # Look at the current min configs, and save off all the
2920 # ones that were set via the allnoconfig
2921 assign_configs \%min_configs, $start_minconfig;
2923 my @config_keys = keys %min_configs;
2925 # All configs need a depcount
2926 foreach my $config (@config_keys) {
2927 my $kconfig = chomp_config $config;
2928 if (!defined $depcount{$kconfig}) {
2929 $depcount{$kconfig} = 0;
2933 # Remove anything that was set by the make allnoconfig
2934 # we shouldn't need them as they get set for us anyway.
2935 foreach my $config (@config_keys) {
2936 # Remove anything in the ignore_config
2937 if (defined($keep_configs{$config})) {
2938 my $file = $ignore_config;
2939 $file =~ s,.*/(.*?)$,$1,;
2940 doprint "$config set by $file ... ignored\n";
2941 delete $min_configs{$config};
2944 # But make sure the settings are the same. If a min config
2945 # sets a selection, we do not want to get rid of it if
2946 # it is not the same as what we have. Just move it into
2948 if (defined($config_ignore{$config})) {
2949 if ($config_ignore{$config} ne $min_configs{$config}) {
2950 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2951 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2952 $keep_configs{$config} = $min_configs{$config};
2954 doprint "$config set by allnoconfig ... ignored\n";
2956 delete $min_configs{$config};
2968 # Now disable each config one by one and do a make oldconfig
2969 # till we find a config that changes our list.
2971 my @test_configs = keys %min_configs;
2973 # Sort keys by who is most dependent on
2974 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2977 # Put configs that did not modify the config at the end.
2979 for (my $i = 0; $i < $#test_configs; $i++) {
2980 if (!defined($nochange_config{$test_configs[0]})) {
2984 # This config didn't change the .config last time.
2985 # Place it at the end
2986 my $config = shift @test_configs;
2987 push @test_configs, $config;
2990 # if every test config has failed to modify the .config file
2991 # in the past, then reset and start over.
2993 undef %nochange_config;
2996 undef %processed_configs;
2998 foreach my $config (@test_configs) {
3000 $found = test_this_config $config;
3002 last if (defined($found));
3004 # oh well, try another config
3007 if (!defined($found)) {
3008 # we could have failed due to the nochange_config hash
3009 # reset and try again
3011 undef %nochange_config;
3015 doprint "No more configs found that we can disable\n";
3023 doprint "Test with $config disabled\n";
3025 # set in_bisect to keep build and monitor from dieing
3030 start_monitor_and_boot or $failed = 1;
3036 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3037 # this config is needed, add it to the ignore list.
3038 $keep_configs{$config} = $min_configs{$config};
3039 $save_configs{$config} = $min_configs{$config};
3040 delete $min_configs{$config};
3042 # update new ignore configs
3043 if (defined($ignore_config)) {
3044 open (OUT, ">$temp_config")
3045 or die "Can't write to $temp_config";
3046 foreach my $config (keys %save_configs) {
3047 print OUT "$save_configs{$config}\n";
3050 run_command "mv $temp_config $ignore_config" or
3051 dodie "failed to copy update to $ignore_config";
3055 # We booted without this config, remove it from the minconfigs.
3056 doprint "$config is not needed, disabling\n";
3058 delete $min_configs{$config};
3060 # Also disable anything that is not enabled in this config
3062 assign_configs \%configs, $output_config;
3063 my @config_keys = keys %min_configs;
3064 foreach my $config (@config_keys) {
3065 if (!defined($configs{$config})) {
3066 doprint "$config is not set, disabling\n";
3067 delete $min_configs{$config};
3071 # Save off all the current mandidory configs
3072 open (OUT, ">$temp_config")
3073 or die "Can't write to $temp_config";
3074 foreach my $config (keys %keep_configs) {
3075 print OUT "$keep_configs{$config}\n";
3077 foreach my $config (keys %min_configs) {
3078 print OUT "$min_configs{$config}\n";
3082 run_command "mv $temp_config $output_minconfig" or
3083 dodie "failed to copy update to $output_minconfig";
3086 doprint "Reboot and wait $sleep_time seconds\n";
3094 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3097 $ktest_config = $ARGV[0];
3098 if (! -f $ktest_config) {
3099 print "$ktest_config does not exist.\n";
3100 if (!read_yn "Create it?") {
3105 $ktest_config = "ktest.conf";
3108 if (! -f $ktest_config) {
3111 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3113 # Generated by ktest.pl
3116 # PWD is a ktest.pl variable that will result in the process working
3117 # directory that ktest.pl is executed in.
3119 # THIS_DIR is automatically assigned the PWD of the path that generated
3120 # the config file. It is best to use this variable when assigning other
3121 # directory paths within this directory. This allows you to easily
3122 # move the test cases to other locations or to other machines.
3124 THIS_DIR := $variable{"PWD"}
3126 # Define each test with TEST_START
3127 # The config options below it will override the defaults
3129 TEST_TYPE = $default{"TEST_TYPE"}
3136 read_config $ktest_config;
3138 if (defined($opt{"LOG_FILE"})) {
3139 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3142 # Append any configs entered in manually to the config file.
3143 my @new_configs = keys %entered_configs;
3144 if ($#new_configs >= 0) {
3145 print "\nAppending entered in configs to $ktest_config\n";
3146 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3147 foreach my $config (@new_configs) {
3148 print OUT "$config = $entered_configs{$config}\n";
3149 $opt{$config} = process_variables($entered_configs{$config});
3153 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3154 unlink $opt{"LOG_FILE"};
3157 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3159 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3162 doprint "DEFAULT OPTIONS:\n";
3164 doprint "\nTEST $i OPTIONS";
3165 if (defined($repeat_tests{$i})) {
3166 $repeat = $repeat_tests{$i};
3167 doprint " ITERATE $repeat";
3172 foreach my $option (sort keys %opt) {
3174 if ($option =~ /\[(\d+)\]$/) {
3180 doprint "$option = $opt{$option}\n";
3184 sub __set_test_option {
3185 my ($name, $i) = @_;
3187 my $option = "$name\[$i\]";
3189 if (defined($opt{$option})) {
3190 return $opt{$option};
3193 foreach my $test (keys %repeat_tests) {
3195 $i < $test + $repeat_tests{$test}) {
3196 $option = "$name\[$test\]";
3197 if (defined($opt{$option})) {
3198 return $opt{$option};
3203 if (defined($opt{$name})) {
3210 sub set_test_option {
3211 my ($name, $i) = @_;
3213 my $option = __set_test_option($name, $i);
3214 return $option if (!defined($option));
3216 return eval_option($option, $i);
3219 # First we need to do is the builds
3220 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3222 # Do not reboot on failing test options
3227 my $makecmd = set_test_option("MAKE_CMD", $i);
3229 $machine = set_test_option("MACHINE", $i);
3230 $ssh_user = set_test_option("SSH_USER", $i);
3231 $tmpdir = set_test_option("TMP_DIR", $i);
3232 $outputdir = set_test_option("OUTPUT_DIR", $i);
3233 $builddir = set_test_option("BUILD_DIR", $i);
3234 $test_type = set_test_option("TEST_TYPE", $i);
3235 $build_type = set_test_option("BUILD_TYPE", $i);
3236 $build_options = set_test_option("BUILD_OPTIONS", $i);
3237 $pre_build = set_test_option("PRE_BUILD", $i);
3238 $post_build = set_test_option("POST_BUILD", $i);
3239 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3240 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
3241 $power_cycle = set_test_option("POWER_CYCLE", $i);
3242 $reboot = set_test_option("REBOOT", $i);
3243 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3244 $minconfig = set_test_option("MIN_CONFIG", $i);
3245 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3246 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3247 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
3248 $run_test = set_test_option("TEST", $i);
3249 $addconfig = set_test_option("ADD_CONFIG", $i);
3250 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3251 $grub_menu = set_test_option("GRUB_MENU", $i);
3252 $post_install = set_test_option("POST_INSTALL", $i);
3253 $no_install = set_test_option("NO_INSTALL", $i);
3254 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3255 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3256 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3257 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3258 $power_off = set_test_option("POWER_OFF", $i);
3259 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3260 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
3261 $sleep_time = set_test_option("SLEEP_TIME", $i);
3262 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
3263 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
3264 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
3265 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
3266 $bisect_skip = set_test_option("BISECT_SKIP", $i);
3267 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
3268 $store_failures = set_test_option("STORE_FAILURES", $i);
3269 $store_successes = set_test_option("STORE_SUCCESSES", $i);
3270 $test_name = set_test_option("TEST_NAME", $i);
3271 $timeout = set_test_option("TIMEOUT", $i);
3272 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3273 $console = set_test_option("CONSOLE", $i);
3274 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
3275 $success_line = set_test_option("SUCCESS_LINE", $i);
3276 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
3277 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3278 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
3279 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
3280 $build_target = set_test_option("BUILD_TARGET", $i);
3281 $ssh_exec = set_test_option("SSH_EXEC", $i);
3282 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
3283 $target_image = set_test_option("TARGET_IMAGE", $i);
3284 $localversion = set_test_option("LOCALVERSION", $i);
3286 $start_minconfig_defined = 1;
3288 if (!defined($start_minconfig)) {
3289 $start_minconfig_defined = 0;
3290 $start_minconfig = $minconfig;
3293 chdir $builddir || die "can't change directory to $builddir";
3295 foreach my $dir ($tmpdir, $outputdir) {
3298 die "can't create $dir";
3302 $ENV{"SSH_USER"} = $ssh_user;
3303 $ENV{"MACHINE"} = $machine;
3305 $buildlog = "$tmpdir/buildlog-$machine";
3306 $testlog = "$tmpdir/testlog-$machine";
3307 $dmesg = "$tmpdir/dmesg-$machine";
3308 $make = "$makecmd O=$outputdir";
3309 $output_config = "$outputdir/.config";
3312 $target = "$ssh_user\@$machine";
3313 if ($reboot_type eq "grub") {
3314 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3315 } elsif (!defined($reboot_script)) {
3316 dodie "REBOOT_SCRIPT not defined"
3320 my $run_type = $build_type;
3321 if ($test_type eq "patchcheck") {
3322 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3323 } elsif ($test_type eq "bisect") {
3324 $run_type = $opt{"BISECT_TYPE[$i]"};
3325 } elsif ($test_type eq "config_bisect") {
3326 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
3329 if ($test_type eq "make_min_config") {
3333 # mistake in config file?
3334 if (!defined($run_type)) {
3335 $run_type = "ERROR";
3339 $installme = " no_install" if ($no_install);
3342 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3348 if (defined($addconfig)) {
3349 my $min = $minconfig;
3350 if (!defined($minconfig)) {
3353 run_command "cat $addconfig $min > $tmpdir/add_config" or
3354 dodie "Failed to create temp config";
3355 $minconfig = "$tmpdir/add_config";
3358 my $checkout = $opt{"CHECKOUT[$i]"};
3359 if (defined($checkout)) {
3360 run_command "git checkout $checkout" or
3361 die "failed to checkout $checkout";
3367 if ($test_type eq "bisect") {
3370 } elsif ($test_type eq "config_bisect") {
3373 } elsif ($test_type eq "patchcheck") {
3376 } elsif ($test_type eq "make_min_config") {
3381 if ($build_type ne "nobuild") {
3382 build $build_type or next;
3385 if ($test_type eq "install") {
3392 if ($test_type ne "build") {
3394 start_monitor_and_boot or $failed = 1;
3396 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3397 do_run_test or $failed = 1;
3406 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3408 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
3412 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";