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.
148 # do not force reboots on config problems
151 # default variables that can be used
152 chomp ($variable{"PWD"} = `pwd`);
154 $config_help{"MACHINE"} = << "EOF"
155 The machine hostname that you will test.
156 For build only tests, it is still needed to differentiate log files.
159 $config_help{"SSH_USER"} = << "EOF"
160 The box is expected to have ssh on normal bootup, provide the user
161 (most likely root, since you need privileged operations)
164 $config_help{"BUILD_DIR"} = << "EOF"
165 The directory that contains the Linux source code (full path).
166 You can use \${PWD} that will be the path where ktest.pl is run, or use
167 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
170 $config_help{"OUTPUT_DIR"} = << "EOF"
171 The directory that the objects will be built (full path).
172 (can not be same as BUILD_DIR)
173 You can use \${PWD} that will be the path where ktest.pl is run, or use
174 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
177 $config_help{"BUILD_TARGET"} = << "EOF"
178 The location of the compiled file to copy to the target.
179 (relative to OUTPUT_DIR)
182 $config_help{"TARGET_IMAGE"} = << "EOF"
183 The place to put your image on the test machine.
186 $config_help{"POWER_CYCLE"} = << "EOF"
187 A script or command to reboot the box.
189 Here is a digital loggers power switch example
190 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
192 Here is an example to reboot a virtual box on the current host
193 with the name "Guest".
194 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
197 $config_help{"CONSOLE"} = << "EOF"
198 The script or command that reads the console
200 If you use ttywatch server, something like the following would work.
201 CONSOLE = nc -d localhost 3001
203 For a virtual machine with guest name "Guest".
204 CONSOLE = virsh console Guest
207 $config_help{"LOCALVERSION"} = << "EOF"
208 Required version ending to differentiate the test
209 from other linux builds on the system.
212 $config_help{"REBOOT_TYPE"} = << "EOF"
213 Way to reboot the box to the test kernel.
214 Only valid options so far are "grub" and "script".
216 If you specify grub, it will assume grub version 1
217 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
218 and select that target to reboot to the kernel. If this is not
219 your setup, then specify "script" and have a command or script
220 specified in REBOOT_SCRIPT to boot to the target.
222 The entry in /boot/grub/menu.lst must be entered in manually.
223 The test will not modify that file.
226 $config_help{"GRUB_MENU"} = << "EOF"
227 The grub title name for the test kernel to boot
228 (Only mandatory if REBOOT_TYPE = grub)
230 Note, ktest.pl will not update the grub menu.lst, you need to
231 manually add an option for the test. ktest.pl will search
232 the grub menu.lst for this option to find what kernel to
235 For example, if in the /boot/grub/menu.lst the test kernel title has:
238 GRUB_MENU = Test Kernel
241 $config_help{"REBOOT_SCRIPT"} = << "EOF"
242 A script to reboot the target into the test kernel
243 (Only mandatory if REBOOT_TYPE = script)
248 my ($cancel, $prompt) = @_;
254 print "$prompt [y/n/C] ";
256 print "$prompt [Y/n] ";
260 if ($ans =~ /^\s*$/) {
267 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
269 last if ($ans =~ /^c$/i);
270 print "Please answer either 'y', 'n' or 'c'.\n";
272 print "Please answer either 'y' or 'n'.\n";
278 if ($ans !~ /^y$/i) {
287 return read_prompt 0, $prompt;
293 return read_prompt 1, $prompt;
296 sub get_ktest_config {
300 return if (defined($opt{$config}));
302 if (defined($config_help{$config})) {
304 print $config_help{$config};
309 if (defined($default{$config})) {
310 print "\[$default{$config}\] ";
313 $ans =~ s/^\s*(.*\S)\s*$/$1/;
314 if ($ans =~ /^\s*$/) {
315 if ($default{$config}) {
316 $ans = $default{$config};
318 print "Your answer can not be blank\n";
322 $entered_configs{$config} = ${ans};
327 sub get_ktest_configs {
328 get_ktest_config("MACHINE");
329 get_ktest_config("BUILD_DIR");
330 get_ktest_config("OUTPUT_DIR");
332 # options required for other than just building a kernel
334 get_ktest_config("SSH_USER");
335 get_ktest_config("BUILD_TARGET");
336 get_ktest_config("TARGET_IMAGE");
337 get_ktest_config("POWER_CYCLE");
338 get_ktest_config("CONSOLE");
341 get_ktest_config("LOCALVERSION");
343 return if ($buildonly);
345 my $rtype = $opt{"REBOOT_TYPE"};
347 if (!defined($rtype)) {
348 if (!defined($opt{"GRUB_MENU"})) {
349 get_ktest_config("REBOOT_TYPE");
350 $rtype = $entered_configs{"REBOOT_TYPE"};
356 if ($rtype eq "grub") {
357 get_ktest_config("GRUB_MENU");
359 get_ktest_config("REBOOT_SCRIPT");
363 sub process_variables {
364 my ($value, $remove_undef) = @_;
367 # We want to check for '\', and it is just easier
368 # to check the previous characet of '$' and not need
369 # to worry if '$' is the first character. By adding
370 # a space to $value, we can just check [^\\]\$ and
371 # it will still work.
374 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
378 # append beginning of value to retval
379 $retval = "$retval$begin";
380 if (defined($variable{$var})) {
381 $retval = "$retval$variable{$var}";
382 } elsif (defined($remove_undef) && $remove_undef) {
383 # for if statements, any variable that is not defined,
384 # we simple convert to 0
385 $retval = "${retval}0";
387 # put back the origin piece.
388 $retval = "$retval\$\{$var\}";
392 $retval = "$retval$value";
394 # remove the space added in the beginning
401 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
403 if ($lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $rvalue ne "build") {
404 # Note if a test is something other than build, then we
405 # will need other manditory options.
409 if (defined($opt{$lvalue})) {
410 if (!$override || defined(${$overrides}{$lvalue})) {
413 $extra = "In the same override section!\n";
415 die "$name: $.: Option $lvalue defined more than once!\n$extra";
417 ${$overrides}{$lvalue} = $rvalue;
419 if ($rvalue =~ /^\s*$/) {
420 delete $opt{$lvalue};
422 $rvalue = process_variables($rvalue);
423 $opt{$lvalue} = $rvalue;
428 my ($lvalue, $rvalue) = @_;
430 if ($rvalue =~ /^\s*$/) {
431 delete $variable{$lvalue};
433 $rvalue = process_variables($rvalue);
434 $variable{$lvalue} = $rvalue;
438 sub process_compare {
439 my ($lval, $cmp, $rval) = @_;
450 return $lval eq $rval;
451 } elsif ($cmp eq "!=") {
452 return $lval ne $rval;
455 my $statement = "$lval $cmp $rval";
456 my $ret = eval $statement;
458 # $@ stores error of eval
469 return defined($variable{$2}) ||
474 sub process_expression {
475 my ($name, $val) = @_;
479 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
482 if (process_expression($name, $express)) {
483 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
485 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
493 while ($val =~ s/^(.*?)($OR|$AND)//) {
497 if (process_expression($name, $express)) {
508 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
509 my $ret = process_compare($1, $2, $3);
511 die "$name: $.: Unable to process comparison\n";
516 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
518 return !value_defined($2);
520 return value_defined($2);
524 if ($val =~ /^\s*0\s*$/) {
526 } elsif ($val =~ /^\s*\d+\s*$/) {
530 die ("$name: $.: Undefined content $val in if statement\n");
534 my ($name, $value) = @_;
536 # Convert variables and replace undefined ones with 0
537 my $val = process_variables($value, 1);
538 my $ret = process_expression $name, $val;
544 my ($config, $current_test_num) = @_;
547 open($in, $config) || die "can't read file $config";
550 $name =~ s,.*/(.*),$1,;
552 my $test_num = $$current_test_num;
555 my $num_tests_set = 0;
568 # ignore blank lines and comments
569 next if (/^\s*$/ || /\s*\#/);
571 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
581 if ($type eq "TEST_START") {
583 if ($num_tests_set) {
584 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
587 $old_test_num = $test_num;
588 $old_repeat = $repeat;
590 $test_num += $repeat;
597 # If SKIP is anywhere in the line, the command will be skipped
598 if ($rest =~ s/\s+SKIP\b//) {
605 if ($rest =~ s/\sELSE\b//) {
607 die "$name: $.: ELSE found with out matching IF section\n$_";
618 if ($rest =~ s/\sIF\s+(.*)//) {
619 if (process_if($name, $1)) {
631 if ($type eq "TEST_START") {
632 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
634 $repeat_tests{"$test_num"} = $repeat;
636 } elsif ($rest =~ s/\sOVERRIDE\b//) {
639 # Clear previous overrides
644 if (!$skip && $rest !~ /^\s*$/) {
645 die "$name: $.: Gargbage found after $type\n$_";
648 if ($skip && $type eq "TEST_START") {
649 $test_num = $old_test_num;
650 $repeat = $old_repeat;
653 } elsif (/^\s*ELSE\b(.*)$/) {
655 die "$name: $.: ELSE found with out matching IF section\n$_";
664 if ($rest =~ /\sIF\s+(.*)/) {
665 # May be a ELSE IF section.
666 if (!process_if($name, $1)) {
675 if ($rest !~ /^\s*$/) {
676 die "$name: $.: Gargbage found after DEFAULTS\n$_";
679 } elsif (/^\s*INCLUDE\s+(\S+)/) {
684 die "$name: $.: INCLUDE can only be done in default sections\n$_";
687 my $file = process_variables($1);
689 if ($file !~ m,^/,) {
690 # check the path of the config file first
691 if ($config =~ m,(.*)/,) {
699 die "$name: $.: Can't read file $file\n$_";
702 if (__read_config($file, \$test_num)) {
706 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
714 ($lvalue eq "NUM_TESTS" ||
715 $lvalue eq "LOG_FILE" ||
716 $lvalue eq "CLEAR_LOG")) {
717 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
720 if ($lvalue eq "NUM_TESTS") {
722 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
725 die "$name: $.: NUM_TESTS must be set in default section\n";
730 if ($default || $lvalue =~ /\[\d+\]$/) {
731 set_value($lvalue, $rvalue, $override, \%overrides, $name);
733 my $val = "$lvalue\[$test_num\]";
734 set_value($val, $rvalue, $override, \%overrides, $name);
737 $repeats{$val} = $repeat;
740 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
746 # process config variables.
747 # Config variables are only active while reading the
748 # config and can be defined anywhere. They also ignore
749 # TEST_START and DEFAULTS, but are skipped if they are in
750 # on of these sections that have SKIP defined.
751 # The save variable can be
752 # defined multiple times and the new one simply overrides
754 set_variable($lvalue, $rvalue);
757 die "$name: $.: Garbage found in config\n$_";
762 $test_num += $repeat - 1;
763 $opt{"NUM_TESTS"} = $test_num;
768 $$current_test_num = $test_num;
774 print "What test case would you like to run?\n";
775 print " (build, install or boot)\n";
776 print " Other tests are available but require editing the config file\n";
779 $default{"TEST_TYPE"} = $ans;
788 $test_case = __read_config $config, \$test_num;
790 # make sure we have all mandatory configs
793 # was a test specified?
795 print "No test case specified.\n";
801 foreach my $default (keys %default) {
802 if (!defined($opt{$default})) {
803 $opt{$default} = $default{$default};
809 my ($option, $i) = @_;
811 # Add space to evaluate the character before $
812 $option = " $option";
817 foreach my $test (keys %repeat_tests) {
819 $i < $test + $repeat_tests{$test}) {
827 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
832 # Append beginning of line
833 $retval = "$retval$start";
835 # If the iteration option OPT[$i] exists, then use that.
836 # otherwise see if the default OPT (without [$i]) exists.
838 my $o = "$var\[$i\]";
839 my $parento = "$var\[$parent\]";
841 if (defined($opt{$o})) {
843 $retval = "$retval$o";
844 } elsif ($repeated && defined($opt{$parento})) {
846 $retval = "$retval$o";
847 } elsif (defined($opt{$var})) {
849 $retval = "$retval$o";
851 $retval = "$retval\$\{$var\}";
857 $retval = "$retval$option";
865 my ($option, $i) = @_;
869 # Since an option can evaluate to another option,
870 # keep iterating until we do not evaluate any more
873 while ($prev ne $option) {
874 # Check for recursive evaluations.
875 # 100 deep should be more than enough.
877 die "Over 100 evaluations accurred with $option\n" .
878 "Check for recursive variables\n";
881 $option = __eval_option($option, $i);
888 if (defined($opt{"LOG_FILE"})) {
889 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
896 if (defined($opt{"LOG_FILE"})) {
911 sub wait_for_monitor;
916 if (defined($time)) {
918 # flush out current monitor
919 # May contain the reboot success line
923 # try to reboot normally
924 if (run_command $reboot) {
925 if (defined($powercycle_after_reboot)) {
926 sleep $powercycle_after_reboot;
927 run_command "$power_cycle";
930 # nope? power cycle it.
931 run_command "$power_cycle";
934 if (defined($time)) {
935 wait_for_monitor($time, $reboot_success_line);
943 return $test_type eq "build" || $no_reboot ||
944 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
945 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
949 doprint "CRITICAL FAILURE... ", @_, "\n";
953 if ($reboot_on_error && !do_not_reboot) {
955 doprint "REBOOTING\n";
958 } elsif ($poweroff_on_error && defined($power_off)) {
959 doprint "POWERING OFF\n";
963 if (defined($opt{"LOG_FILE"})) {
964 print " See $opt{LOG_FILE} for more info.\n";
975 my $pid = open($fp, "$console|") or
976 dodie "Can't open console $console";
978 $flags = fcntl($fp, F_GETFL, 0) or
979 dodie "Can't get flags for the socket: $!";
980 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
981 dodie "Can't set flags for the socket: $!";
989 doprint "kill child process $pid\n";
997 if ($monitor_cnt++) {
1000 $monitor_fp = \*MONFD;
1001 $monitor_pid = open_console $monitor_fp;
1005 open(MONFD, "Stop perl from warning about single use of MONFD");
1009 if (--$monitor_cnt) {
1012 close_console($monitor_fp, $monitor_pid);
1015 sub wait_for_monitor {
1016 my ($time, $stop) = @_;
1021 doprint "** Wait for monitor to settle down **\n";
1023 # read the monitor and wait for the system to calm down
1025 $line = wait_for_input($monitor_fp, $time);
1026 last if (!defined($line));
1028 $full_line .= $line;
1030 if (defined($stop) && $full_line =~ /$stop/) {
1031 doprint "wait for monitor detected $stop\n";
1035 if ($line =~ /\n/) {
1039 print "** Monitor flushed **\n";
1043 my ($result, $basedir) = @_;
1045 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1046 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1048 my $type = $build_type;
1049 if ($type =~ /useconfig/) {
1050 $type = "useconfig";
1053 my $dir = "$machine-$test_type-$type-$result-$date";
1055 $dir = "$basedir/$dir";
1059 die "can't create $dir";
1063 "config" => $output_config,
1064 "buildlog" => $buildlog,
1066 "testlog" => $testlog,
1069 while (my ($name, $source) = each(%files)) {
1071 cp "$source", "$dir/$name" or
1072 die "failed to copy $source";
1076 doprint "*** Saved info to $dir ***\n";
1081 if ($die_on_failure) {
1089 # no need to reboot for just building.
1090 if (!do_not_reboot) {
1091 doprint "REBOOTING\n";
1097 if (defined($test_name)) {
1098 $name = " ($test_name)";
1101 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1102 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1103 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1104 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1105 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1107 if (defined($store_failures)) {
1108 save_logs "fail", $store_failures;
1120 $command =~ s/\$SSH_USER/$ssh_user/g;
1121 $command =~ s/\$MACHINE/$machine/g;
1123 doprint("$command ... ");
1125 $pid = open(CMD, "$command 2>&1 |") or
1126 (fail "unable to exec $command" and return 0);
1128 if (defined($opt{"LOG_FILE"})) {
1129 open(LOG, ">>$opt{LOG_FILE}") or
1130 dodie "failed to write to log";
1134 if (defined($redirect)) {
1135 open (RD, ">$redirect") or
1136 dodie "failed to write to redirect $redirect";
1141 print LOG if ($dolog);
1142 print RD if ($dord);
1149 close(LOG) if ($dolog);
1150 close(RD) if ($dord);
1153 doprint "FAILED!\n";
1155 doprint "SUCCESS\n";
1163 my $cp_exec = $ssh_exec;
1165 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1166 return run_command "$cp_exec";
1170 my ($src, $dst) = @_;
1171 my $cp_scp = $scp_to_target;
1173 $cp_scp =~ s/\$SRC_FILE/$src/g;
1174 $cp_scp =~ s/\$DST_FILE/$dst/g;
1176 return run_command "$cp_scp";
1179 sub get_grub_index {
1181 if ($reboot_type ne "grub") {
1184 return if (defined($grub_number));
1186 doprint "Find grub menu ... ";
1189 my $ssh_grub = $ssh_exec;
1190 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1192 open(IN, "$ssh_grub |")
1193 or die "unable to get menu.lst";
1198 if (/^\s*title\s+$grub_menu\s*$/) {
1202 } elsif (/^\s*title\s/) {
1208 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1210 doprint "$grub_number\n";
1215 my ($fp, $time) = @_;
1221 if (!defined($time)) {
1226 vec($rin, fileno($fp), 1) = 1;
1227 $ready = select($rin, undef, undef, $time);
1231 # try to read one char at a time
1232 while (sysread $fp, $ch, 1) {
1234 last if ($ch eq "\n");
1237 if (!length($line)) {
1245 if ($reboot_type eq "grub") {
1246 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1251 run_command "$reboot_script";
1257 doprint "git rev-list --max-count=1 $commit ... ";
1258 my $sha1 = `git rev-list --max-count=1 $commit`;
1265 dodie "Failed to get git $commit";
1278 my $skip_call_trace = 0;
1286 open(DMESG, "> $dmesg") or
1287 die "unable to write to $dmesg";
1293 my $monitor_start = time;
1295 my $version_found = 0;
1299 if ($bug && defined($stop_after_failure) &&
1300 $stop_after_failure >= 0) {
1301 my $time = $stop_after_failure - (time - $failure_start);
1302 $line = wait_for_input($monitor_fp, $time);
1303 if (!defined($line)) {
1304 doprint "bug timed out after $booted_timeout seconds\n";
1305 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1309 $line = wait_for_input($monitor_fp, $booted_timeout);
1310 if (!defined($line)) {
1311 my $s = $booted_timeout == 1 ? "" : "s";
1312 doprint "Successful boot found: break after $booted_timeout second$s\n";
1316 $line = wait_for_input($monitor_fp);
1317 if (!defined($line)) {
1318 my $s = $timeout == 1 ? "" : "s";
1319 doprint "Timed out after $timeout second$s\n";
1327 # we are not guaranteed to get a full line
1328 $full_line .= $line;
1330 if ($full_line =~ /$success_line/) {
1332 $success_start = time;
1335 if ($booted && defined($stop_after_success) &&
1336 $stop_after_success >= 0) {
1338 if ($now - $success_start >= $stop_after_success) {
1339 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1344 if ($full_line =~ /\[ backtrace testing \]/) {
1345 $skip_call_trace = 1;
1348 if ($full_line =~ /call trace:/i) {
1349 if (!$bug && !$skip_call_trace) {
1351 $failure_start = time;
1355 if ($bug && defined($stop_after_failure) &&
1356 $stop_after_failure >= 0) {
1358 if ($now - $failure_start >= $stop_after_failure) {
1359 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1364 if ($full_line =~ /\[ end of backtrace testing \]/) {
1365 $skip_call_trace = 0;
1368 if ($full_line =~ /Kernel panic -/) {
1369 $failure_start = time;
1373 # Detect triple faults by testing the banner
1374 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1375 if ($1 eq $version) {
1377 } elsif ($version_found && $detect_triplefault) {
1378 # We already booted into the kernel we are testing,
1379 # but now we booted into another kernel?
1380 # Consider this a triple fault.
1381 doprint "Aleady booted in Linux kernel $version, but now\n";
1382 doprint "we booted into Linux kernel $1.\n";
1383 doprint "Assuming that this is a triple fault.\n";
1384 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1389 if ($line =~ /\n/) {
1393 if ($stop_test_after > 0 && !$booted && !$bug) {
1394 if (time - $monitor_start > $stop_test_after) {
1395 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1404 return 0 if ($in_bisect);
1405 fail "failed - got a bug report" and return 0;
1409 return 0 if ($in_bisect);
1410 fail "failed - never got a boot prompt." and return 0;
1416 sub do_post_install {
1418 return if (!defined($post_install));
1420 my $cp_post_install = $post_install;
1421 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1422 run_command "$cp_post_install" or
1423 dodie "Failed to run post install";
1428 return if ($no_install);
1430 run_scp "$outputdir/$build_target", "$target_image" or
1431 dodie "failed to copy image";
1433 my $install_mods = 0;
1435 # should we process modules?
1437 open(IN, "$output_config") or dodie("Can't read config file");
1439 if (/CONFIG_MODULES(=y)?/) {
1440 $install_mods = 1 if (defined($1));
1446 if (!$install_mods) {
1448 doprint "No modules needed\n";
1452 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1453 dodie "Failed to install modules";
1455 my $modlib = "/lib/modules/$version";
1456 my $modtar = "ktest-mods.tar.bz2";
1458 run_ssh "rm -rf $modlib" or
1459 dodie "failed to remove old mods: $modlib";
1461 # would be nice if scp -r did not follow symbolic links
1462 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1463 dodie "making tarball";
1465 run_scp "$tmpdir/$modtar", "/tmp" or
1466 dodie "failed to copy modules";
1468 unlink "$tmpdir/$modtar";
1470 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1471 dodie "failed to tar modules";
1473 run_ssh "rm -f /tmp/$modtar";
1479 # get the release name
1480 doprint "$make kernelrelease ... ";
1481 $version = `$make kernelrelease | tail -1`;
1483 doprint "$version\n";
1486 sub start_monitor_and_boot {
1487 # Make sure the stable kernel has finished booting
1500 sub check_buildlog {
1503 my @files = `git show $patch | diffstat -l`;
1505 open(IN, "git show $patch |") or
1506 dodie "failed to show $patch";
1508 if (m,^--- a/(.*),) {
1510 $files[$#files] = $1;
1515 open(IN, $buildlog) or dodie "Can't open $buildlog";
1517 if (/^\s*(.*?):.*(warning|error)/) {
1519 foreach my $file (@files) {
1520 my $fullpath = "$builddir/$file";
1521 if ($file eq $err || $fullpath eq $err) {
1522 fail "$file built with warnings" and return 0;
1532 sub apply_min_config {
1533 my $outconfig = "$output_config.new";
1535 # Read the config file and remove anything that
1536 # is in the force_config hash (from minconfig and others)
1537 # then add the force config back.
1539 doprint "Applying minimum configurations into $output_config.new\n";
1541 open (OUT, ">$outconfig") or
1542 dodie "Can't create $outconfig";
1544 if (-f $output_config) {
1545 open (IN, $output_config) or
1546 dodie "Failed to open $output_config";
1548 if (/^(# )?(CONFIG_[^\s=]*)/) {
1549 next if (defined($force_config{$2}));
1555 foreach my $config (keys %force_config) {
1556 print OUT "$force_config{$config}\n";
1560 run_command "mv $outconfig $output_config";
1563 sub make_oldconfig {
1565 my @force_list = keys %force_config;
1567 if ($#force_list >= 0) {
1571 if (!run_command "$make oldnoconfig") {
1572 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1573 # try a yes '' | oldconfig
1574 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1575 run_command "yes '' | $make oldconfig" or
1576 dodie "failed make config oldconfig";
1580 # read a config file and use this to force new configs.
1581 sub load_force_config {
1584 open(IN, $config) or
1585 dodie "failed to read $config";
1588 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1589 $force_config{$1} = $_;
1590 } elsif (/^# (CONFIG_\S*) is not set/) {
1591 $force_config{$1} = $_;
1602 # Failed builds should not reboot the target
1603 my $save_no_reboot = $no_reboot;
1606 if (defined($pre_build)) {
1607 my $ret = run_command $pre_build;
1608 if (!$ret && defined($pre_build_die) &&
1610 dodie "failed to pre_build\n";
1614 if ($type =~ /^useconfig:(.*)/) {
1615 run_command "cp $1 $output_config" or
1616 dodie "could not copy $1 to .config";
1618 $type = "oldconfig";
1621 # old config can ask questions
1622 if ($type eq "oldconfig") {
1623 $type = "oldnoconfig";
1625 # allow for empty configs
1626 run_command "touch $output_config";
1629 run_command "mv $output_config $outputdir/config_temp" or
1630 dodie "moving .config";
1632 run_command "$make mrproper" or dodie "make mrproper";
1634 run_command "mv $outputdir/config_temp $output_config" or
1635 dodie "moving config_temp";
1638 } elsif (!$noclean) {
1639 unlink "$output_config";
1640 run_command "$make mrproper" or
1641 dodie "make mrproper";
1644 # add something to distinguish this build
1645 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1646 print OUT "$localversion\n";
1649 if (defined($minconfig)) {
1650 load_force_config($minconfig);
1653 if ($type ne "oldnoconfig") {
1654 run_command "$make $type" or
1655 dodie "failed make config";
1657 # Run old config regardless, to enforce min configurations
1660 $redirect = "$buildlog";
1661 my $build_ret = run_command "$make $build_options";
1664 if (defined($post_build)) {
1665 my $ret = run_command $post_build;
1666 if (!$ret && defined($post_build_die) &&
1668 dodie "failed to post_build\n";
1673 # bisect may need this to pass
1675 $no_reboot = $save_no_reboot;
1678 fail "failed build" and return 0;
1681 $no_reboot = $save_no_reboot;
1687 if (!run_ssh "halt" or defined($power_off)) {
1688 if (defined($poweroff_after_halt)) {
1689 sleep $poweroff_after_halt;
1690 run_command "$power_off";
1694 run_command "$power_off";
1705 if (defined($test_name)) {
1706 $name = " ($test_name)";
1709 doprint "\n\n*******************************************\n";
1710 doprint "*******************************************\n";
1711 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1712 doprint "*******************************************\n";
1713 doprint "*******************************************\n";
1715 if (defined($store_successes)) {
1716 save_logs "success", $store_successes;
1719 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1720 doprint "Reboot and wait $sleep_time seconds\n";
1727 doprint "Pass or fail? [p/f]";
1730 if ($ans eq "p" || $ans eq "P") {
1732 } elsif ($ans eq "f" || $ans eq "F") {
1735 print "Please answer 'P' or 'F'\n";
1740 sub child_run_test {
1743 # child should have no power
1744 $reboot_on_error = 0;
1745 $poweroff_on_error = 0;
1746 $die_on_failure = 1;
1748 $redirect = "$testlog";
1749 run_command $run_test or $failed = 1;
1757 sub child_finished {
1770 doprint "run test $run_test\n";
1774 $SIG{CHLD} = qw(child_finished);
1778 child_run_test if (!$child_pid);
1783 $line = wait_for_input($monitor_fp, 1);
1784 if (defined($line)) {
1786 # we are not guaranteed to get a full line
1787 $full_line .= $line;
1790 if ($full_line =~ /call trace:/i) {
1794 if ($full_line =~ /Kernel panic -/) {
1798 if ($line =~ /\n/) {
1802 } while (!$child_done && !$bug);
1805 my $failure_start = time;
1808 $line = wait_for_input($monitor_fp, 1);
1809 if (defined($line)) {
1813 if ($now - $failure_start >= $stop_after_failure) {
1816 } while (defined($line));
1818 doprint "Detected kernel crash!\n";
1819 # kill the child with extreme prejudice
1823 waitpid $child_pid, 0;
1826 if ($bug || $child_exit) {
1827 return 0 if $in_bisect;
1828 fail "test failed" and return 0;
1833 sub run_git_bisect {
1836 doprint "$command ... ";
1838 my $output = `$command 2>&1`;
1845 dodie "Failed to git bisect";
1848 doprint "SUCCESS\n";
1849 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1850 doprint "$1 [$2]\n";
1851 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1853 doprint "Found bad commit... $1\n";
1856 # we already logged it, just print it now.
1864 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1865 reboot $bisect_sleep_time;
1868 # returns 1 on success, 0 on failure, -1 on skip
1869 sub run_bisect_test {
1870 my ($type, $buildtype) = @_;
1879 build $buildtype or $failed = 1;
1881 if ($type ne "build") {
1882 if ($failed && $bisect_skip) {
1886 dodie "Failed on build" if $failed;
1889 start_monitor_and_boot or $failed = 1;
1891 if ($type ne "boot") {
1892 if ($failed && $bisect_skip) {
1898 dodie "Failed on boot" if $failed;
1900 do_run_test or $failed = 1;
1911 # reboot the box to a kernel we can ssh to
1912 if ($type ne "build") {
1922 my $buildtype = "oldconfig";
1924 # We should have a minconfig to use?
1925 if (defined($minconfig)) {
1926 $buildtype = "useconfig:$minconfig";
1929 my $ret = run_bisect_test $type, $buildtype;
1931 if ($bisect_manual) {
1932 $ret = answer_bisect;
1935 # Are we looking for where it worked, not failed?
1936 if ($reverse_bisect) {
1942 } elsif ($ret == 0) {
1944 } elsif ($bisect_skip) {
1945 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1950 sub update_bisect_replay {
1951 my $tmp_log = "$tmpdir/ktest_bisect_log";
1952 run_command "git bisect log > $tmp_log" or
1953 die "can't create bisect log";
1962 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1963 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1964 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1966 my $good = $opt{"BISECT_GOOD[$i]"};
1967 my $bad = $opt{"BISECT_BAD[$i]"};
1968 my $type = $opt{"BISECT_TYPE[$i]"};
1969 my $start = $opt{"BISECT_START[$i]"};
1970 my $replay = $opt{"BISECT_REPLAY[$i]"};
1971 my $start_files = $opt{"BISECT_FILES[$i]"};
1973 if (defined($start_files)) {
1974 $start_files = " -- " . $start_files;
1979 # convert to true sha1's
1980 $good = get_sha1($good);
1981 $bad = get_sha1($bad);
1983 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1984 $opt{"BISECT_REVERSE[$i]"} == 1) {
1985 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1986 $reverse_bisect = 1;
1988 $reverse_bisect = 0;
1991 # Can't have a test without having a test to run
1992 if ($type eq "test" && !defined($run_test)) {
1996 # Check if a bisect was running
1997 my $bisect_start_file = "$builddir/.git/BISECT_START";
1999 my $check = $opt{"BISECT_CHECK[$i]"};
2000 my $do_check = defined($check) && $check ne "0";
2002 if ( -f $bisect_start_file ) {
2003 print "Bisect in progress found\n";
2005 print " If you say yes, then no checks of good or bad will be done\n";
2007 if (defined($replay)) {
2008 print "** BISECT_REPLAY is defined in config file **";
2009 print " Ignore config option and perform new git bisect log?\n";
2010 if (read_ync " (yes, no, or cancel) ") {
2011 $replay = update_bisect_replay;
2014 } elsif (read_yn "read git log and continue?") {
2015 $replay = update_bisect_replay;
2023 my $head = get_sha1("HEAD");
2025 if ($check ne "good") {
2026 doprint "TESTING BISECT BAD [$bad]\n";
2027 run_command "git checkout $bad" or
2028 die "Failed to checkout $bad";
2030 $result = run_bisect $type;
2032 if ($result ne "bad") {
2033 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2037 if ($check ne "bad") {
2038 doprint "TESTING BISECT GOOD [$good]\n";
2039 run_command "git checkout $good" or
2040 die "Failed to checkout $good";
2042 $result = run_bisect $type;
2044 if ($result ne "good") {
2045 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2049 # checkout where we started
2050 run_command "git checkout $head" or
2051 die "Failed to checkout $head";
2054 run_command "git bisect start$start_files" or
2055 dodie "could not start bisect";
2057 run_command "git bisect good $good" or
2058 dodie "could not set bisect good to $good";
2060 run_git_bisect "git bisect bad $bad" or
2061 dodie "could not set bisect bad to $bad";
2063 if (defined($replay)) {
2064 run_command "git bisect replay $replay" or
2065 dodie "failed to run replay";
2068 if (defined($start)) {
2069 run_command "git checkout $start" or
2070 dodie "failed to checkout $start";
2075 $result = run_bisect $type;
2076 $test = run_git_bisect "git bisect $result";
2079 run_command "git bisect log" or
2080 dodie "could not capture git bisect log";
2082 run_command "git bisect reset" or
2083 dodie "could not reset git bisect";
2085 doprint "Bad commit was [$bisect_bad]\n";
2098 sub assign_configs {
2099 my ($hash, $config) = @_;
2102 or dodie "Failed to read $config";
2105 if (/^((CONFIG\S*)=.*)/) {
2113 sub process_config_ignore {
2116 assign_configs \%config_ignore, $config;
2119 sub read_current_config {
2120 my ($config_ref) = @_;
2122 %{$config_ref} = ();
2123 undef %{$config_ref};
2125 my @key = keys %{$config_ref};
2127 print "did not delete!\n";
2130 open (IN, "$output_config");
2133 if (/^(CONFIG\S+)=(.*)/) {
2134 ${$config_ref}{$1} = $2;
2140 sub get_dependencies {
2143 my $arr = $dependency{$config};
2144 if (!defined($arr)) {
2150 foreach my $dep (@{$arr}) {
2151 print "ADD DEP $dep\n";
2152 @deps = (@deps, get_dependencies $dep);
2161 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2163 foreach my $config (@configs) {
2164 print OUT "$config_set{$config}\n";
2165 my @deps = get_dependencies $config;
2166 foreach my $dep (@deps) {
2167 print OUT "$config_set{$dep}\n";
2171 foreach my $config (keys %config_ignore) {
2172 print OUT "$config_ignore{$config}\n";
2180 sub compare_configs {
2183 foreach my $item (keys %a) {
2184 if (!defined($b{$item})) {
2185 print "diff $item\n";
2193 print "diff2 $keys[0]\n";
2195 return -1 if ($#keys >= 0);
2200 sub run_config_bisect_test {
2203 return run_bisect_test $type, "oldconfig";
2206 sub process_passed {
2209 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2210 # Passed! All these configs are part of a good compile.
2211 # Add them to the min options.
2212 foreach my $config (keys %configs) {
2213 if (defined($config_list{$config})) {
2214 doprint " removing $config\n";
2215 $config_ignore{$config} = $config_list{$config};
2216 delete $config_list{$config};
2219 doprint "config copied to $outputdir/config_good\n";
2220 run_command "cp -f $output_config $outputdir/config_good";
2223 sub process_failed {
2226 doprint "\n\n***************************************\n";
2227 doprint "Found bad config: $config\n";
2228 doprint "***************************************\n\n";
2231 sub run_config_bisect {
2233 my @start_list = keys %config_list;
2235 if ($#start_list < 0) {
2236 doprint "No more configs to test!!!\n";
2240 doprint "***** RUN TEST ***\n";
2241 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2245 my $count = $#start_list + 1;
2246 doprint " $count configs to test\n";
2248 my $half = int($#start_list / 2);
2251 my @tophalf = @start_list[0 .. $half];
2253 create_config @tophalf;
2254 read_current_config \%current_config;
2256 $count = $#tophalf + 1;
2257 doprint "Testing $count configs\n";
2259 # make sure we test something
2260 foreach my $config (@tophalf) {
2261 if (defined($current_config{$config})) {
2267 # try the other half
2268 doprint "Top half produced no set configs, trying bottom half\n";
2269 @tophalf = @start_list[$half + 1 .. $#start_list];
2270 create_config @tophalf;
2271 read_current_config \%current_config;
2272 foreach my $config (@tophalf) {
2273 if (defined($current_config{$config})) {
2279 doprint "Failed: Can't make new config with current configs\n";
2280 foreach my $config (@start_list) {
2281 doprint " CONFIG: $config\n";
2285 $count = $#tophalf + 1;
2286 doprint "Testing $count configs\n";
2289 $ret = run_config_bisect_test $type;
2290 if ($bisect_manual) {
2291 $ret = answer_bisect;
2294 process_passed %current_config;
2298 doprint "This config had a failure.\n";
2299 doprint "Removing these configs that were not set in this config:\n";
2300 doprint "config copied to $outputdir/config_bad\n";
2301 run_command "cp -f $output_config $outputdir/config_bad";
2303 # A config exists in this group that was bad.
2304 foreach my $config (keys %config_list) {
2305 if (!defined($current_config{$config})) {
2306 doprint " removing $config\n";
2307 delete $config_list{$config};
2311 @start_list = @tophalf;
2313 if ($#start_list == 0) {
2314 process_failed $start_list[0];
2318 # remove half the configs we are looking at and see if
2320 $half = int($#start_list / 2);
2321 } while ($#start_list > 0);
2323 # we found a single config, try it again unless we are running manually
2325 if ($bisect_manual) {
2326 process_failed $start_list[0];
2330 my @tophalf = @start_list[0 .. 0];
2332 $ret = run_config_bisect_test $type;
2334 process_passed %current_config;
2338 process_failed $start_list[0];
2345 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2347 my $tmpconfig = "$tmpdir/use_config";
2349 if (defined($config_bisect_good)) {
2350 process_config_ignore $config_bisect_good;
2353 # Make the file with the bad config and the min config
2354 if (defined($minconfig)) {
2355 # read the min config for things to ignore
2356 run_command "cp $minconfig $tmpconfig" or
2357 dodie "failed to copy $minconfig to $tmpconfig";
2362 if (-f $tmpconfig) {
2363 load_force_config($tmpconfig);
2364 process_config_ignore $tmpconfig;
2367 # now process the start config
2368 run_command "cp $start_config $output_config" or
2369 dodie "failed to copy $start_config to $output_config";
2371 # read directly what we want to check
2373 open (IN, $output_config)
2374 or dodie "faied to open $output_config";
2377 if (/^((CONFIG\S*)=.*)/) {
2378 $config_check{$2} = $1;
2383 # Now run oldconfig with the minconfig
2386 # check to see what we lost (or gained)
2387 open (IN, $output_config)
2388 or dodie "Failed to read $start_config";
2390 my %removed_configs;
2394 if (/^((CONFIG\S*)=.*)/) {
2395 # save off all options
2396 $config_set{$2} = $1;
2397 if (defined($config_check{$2})) {
2398 if (defined($config_ignore{$2})) {
2399 $removed_configs{$2} = $1;
2401 $config_list{$2} = $1;
2403 } elsif (!defined($config_ignore{$2})) {
2404 $added_configs{$2} = $1;
2405 $config_list{$2} = $1;
2411 my @confs = keys %removed_configs;
2413 doprint "Configs overridden by default configs and removed from check:\n";
2414 foreach my $config (@confs) {
2415 doprint " $config\n";
2418 @confs = keys %added_configs;
2420 doprint "Configs appearing in make oldconfig and added:\n";
2421 foreach my $config (@confs) {
2422 doprint " $config\n";
2429 # Sometimes kconfig does weird things. We must make sure
2430 # that the config we autocreate has everything we need
2431 # to test, otherwise we may miss testing configs, or
2432 # may not be able to create a new config.
2433 # Here we create a config with everything set.
2434 create_config (keys %config_list);
2435 read_current_config \%config_test;
2436 foreach my $config (keys %config_list) {
2437 if (!defined($config_test{$config})) {
2440 doprint "Configs not produced by kconfig (will not be checked):\n";
2442 doprint " $config\n";
2443 delete $config_list{$config};
2448 $ret = run_config_bisect;
2451 return $ret if ($ret < 0);
2456 sub patchcheck_reboot {
2457 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2458 reboot $patchcheck_sleep_time;
2464 die "PATCHCHECK_START[$i] not defined\n"
2465 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2466 die "PATCHCHECK_TYPE[$i] not defined\n"
2467 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2469 my $start = $opt{"PATCHCHECK_START[$i]"};
2472 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2473 $end = $opt{"PATCHCHECK_END[$i]"};
2476 # Get the true sha1's since we can use things like HEAD~3
2477 $start = get_sha1($start);
2478 $end = get_sha1($end);
2480 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2482 # Can't have a test without having a test to run
2483 if ($type eq "test" && !defined($run_test)) {
2487 open (IN, "git log --pretty=oneline $end|") or
2488 dodie "could not get git list";
2494 $list[$#list+1] = $_;
2495 last if (/^$start/);
2499 if ($list[$#list] !~ /^$start/) {
2500 fail "SHA1 $start not found";
2503 # go backwards in the list
2504 @list = reverse @list;
2506 my $save_clean = $noclean;
2507 my %ignored_warnings;
2509 if (defined($ignore_warnings)) {
2510 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2511 $ignored_warnings{$sha1} = 1;
2516 foreach my $item (@list) {
2518 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2520 doprint "\nProcessing commit $item\n\n";
2522 run_command "git checkout $sha1" or
2523 die "Failed to checkout $sha1";
2525 # only clean on the first and last patch
2526 if ($item eq $list[0] ||
2527 $item eq $list[$#list]) {
2528 $noclean = $save_clean;
2533 if (defined($minconfig)) {
2534 build "useconfig:$minconfig" or return 0;
2536 # ?? no config to use?
2537 build "oldconfig" or return 0;
2541 if (!defined($ignored_warnings{$sha1})) {
2542 check_buildlog $sha1 or return 0;
2545 next if ($type eq "build");
2549 start_monitor_and_boot or $failed = 1;
2551 if (!$failed && $type ne "boot"){
2552 do_run_test or $failed = 1;
2555 return 0 if ($failed);
2575 # $config depends on $dep
2576 my ($config, $dep) = @_;
2578 if (defined($depends{$config})) {
2579 $depends{$config} .= " " . $dep;
2581 $depends{$config} = $dep;
2584 # record the number of configs depending on $dep
2585 if (defined $depcount{$dep}) {
2588 $depcount{$dep} = 1;
2592 # taken from streamline_config.pl
2604 if (! -f $kconfig) {
2605 doprint "file $kconfig does not exist, skipping\n";
2609 open(KIN, "$kconfig")
2610 or die "Can't open $kconfig";
2614 # Make sure that lines ending with \ continue
2616 $_ = $line . " " . $_;
2627 # collect any Kconfig sources
2628 if (/^source\s*"(.*)"/) {
2629 $kconfigs[$#kconfigs+1] = $1;
2633 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2637 for (my $i = 0; $i < $iflevel; $i++) {
2638 add_dep $config, $ifdeps[$i];
2641 # collect the depends for the config
2642 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2644 add_dep $config, $1;
2646 # Get the configs that select this config
2647 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2649 # selected by depends on config
2650 add_dep $1, $config;
2652 # Check for if statements
2653 } elsif (/^if\s+(.*\S)\s*$/) {
2655 # remove beginning and ending non text
2656 $deps =~ s/^[^a-zA-Z0-9_]*//;
2657 $deps =~ s/[^a-zA-Z0-9_]*$//;
2659 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2661 $ifdeps[$iflevel++] = join ':', @deps;
2663 } elsif (/^endif/) {
2665 $iflevel-- if ($iflevel);
2668 } elsif (/^\s*help\s*$/) {
2674 # read in any configs that were found.
2675 foreach $kconfig (@kconfigs) {
2676 if (!defined($read_kconfigs{$kconfig})) {
2677 $read_kconfigs{$kconfig} = 1;
2678 read_kconfig("$builddir/$kconfig");
2684 # find out which arch this is by the kconfig file
2685 open (IN, $output_config)
2686 or dodie "Failed to read $output_config";
2689 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2696 if (!defined($arch)) {
2697 doprint "Could not find arch from config file\n";
2698 doprint "no dependencies used\n";
2702 # arch is really the subarch, we need to know
2703 # what directory to look at.
2704 if ($arch eq "i386" || $arch eq "x86_64") {
2706 } elsif ($arch =~ /^tile/) {
2710 my $kconfig = "$builddir/arch/$arch/Kconfig";
2712 if (! -f $kconfig && $arch =~ /\d$/) {
2714 # some subarchs have numbers, truncate them
2716 $kconfig = "$builddir/arch/$arch/Kconfig";
2717 if (! -f $kconfig) {
2718 doprint "No idea what arch dir $orig is for\n";
2719 doprint "no dependencies used\n";
2724 read_kconfig($kconfig);
2727 sub read_config_list {
2731 or dodie "Failed to read $config";
2734 if (/^((CONFIG\S*)=.*)/) {
2735 if (!defined($config_ignore{$2})) {
2736 $config_list{$2} = $1;
2744 sub read_output_config {
2747 assign_configs \%config_ignore, $config;
2750 sub make_new_config {
2753 open (OUT, ">$output_config")
2754 or dodie "Failed to write $output_config";
2756 foreach my $config (@configs) {
2757 print OUT "$config\n";
2765 $config =~ s/CONFIG_//;
2773 my $kconfig = chomp_config $dep;
2775 $dep = $depends{"$kconfig"};
2777 # the dep string we have saves the dependencies as they
2778 # were found, including expressions like ! && ||. We
2779 # want to split this out into just an array of configs.
2781 my $valid = "A-Za-z_0-9";
2785 while ($dep =~ /[$valid]/) {
2787 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2788 my $conf = "CONFIG_" . $1;
2790 $configs[$#configs + 1] = $conf;
2792 $dep =~ s/^[^$valid]*[$valid]+//;
2794 die "this should never happen";
2804 my %processed_configs;
2805 my %nochange_config;
2807 sub test_this_config {
2812 # if we already processed this config, skip it
2813 if (defined($processed_configs{$config})) {
2816 $processed_configs{$config} = 1;
2818 # if this config failed during this round, skip it
2819 if (defined($nochange_config{$config})) {
2823 my $kconfig = chomp_config $config;
2825 # Test dependencies first
2826 if (defined($depends{"$kconfig"})) {
2827 my @parents = get_depends $config;
2828 foreach my $parent (@parents) {
2829 # if the parent is in the min config, check it first
2830 next if (!defined($min_configs{$parent}));
2831 $found = test_this_config($parent);
2832 if (defined($found)) {
2838 # Remove this config from the list of configs
2839 # do a make oldnoconfig and then read the resulting
2840 # .config to make sure it is missing the config that
2842 my %configs = %min_configs;
2843 delete $configs{$config};
2844 make_new_config ((values %configs), (values %keep_configs));
2847 assign_configs \%configs, $output_config;
2849 return $config if (!defined($configs{$config}));
2851 doprint "disabling config $config did not change .config\n";
2853 $nochange_config{$config} = 1;
2858 sub make_min_config {
2861 if (!defined($output_minconfig)) {
2862 fail "OUTPUT_MIN_CONFIG not defined" and return;
2865 # If output_minconfig exists, and the start_minconfig
2866 # came from min_config, than ask if we should use
2868 if (-f $output_minconfig && !$start_minconfig_defined) {
2869 print "$output_minconfig exists\n";
2870 if (read_yn " Use it as minconfig?") {
2871 $start_minconfig = $output_minconfig;
2875 if (!defined($start_minconfig)) {
2876 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2879 my $temp_config = "$tmpdir/temp_config";
2881 # First things first. We build an allnoconfig to find
2882 # out what the defaults are that we can't touch.
2883 # Some are selections, but we really can't handle selections.
2885 my $save_minconfig = $minconfig;
2888 run_command "$make allnoconfig" or return 0;
2892 process_config_ignore $output_config;
2894 undef %save_configs;
2897 if (defined($ignore_config)) {
2898 # make sure the file exists
2899 `touch $ignore_config`;
2900 assign_configs \%save_configs, $ignore_config;
2903 %keep_configs = %save_configs;
2905 doprint "Load initial configs from $start_minconfig\n";
2907 # Look at the current min configs, and save off all the
2908 # ones that were set via the allnoconfig
2909 assign_configs \%min_configs, $start_minconfig;
2911 my @config_keys = keys %min_configs;
2913 # All configs need a depcount
2914 foreach my $config (@config_keys) {
2915 my $kconfig = chomp_config $config;
2916 if (!defined $depcount{$kconfig}) {
2917 $depcount{$kconfig} = 0;
2921 # Remove anything that was set by the make allnoconfig
2922 # we shouldn't need them as they get set for us anyway.
2923 foreach my $config (@config_keys) {
2924 # Remove anything in the ignore_config
2925 if (defined($keep_configs{$config})) {
2926 my $file = $ignore_config;
2927 $file =~ s,.*/(.*?)$,$1,;
2928 doprint "$config set by $file ... ignored\n";
2929 delete $min_configs{$config};
2932 # But make sure the settings are the same. If a min config
2933 # sets a selection, we do not want to get rid of it if
2934 # it is not the same as what we have. Just move it into
2936 if (defined($config_ignore{$config})) {
2937 if ($config_ignore{$config} ne $min_configs{$config}) {
2938 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2939 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2940 $keep_configs{$config} = $min_configs{$config};
2942 doprint "$config set by allnoconfig ... ignored\n";
2944 delete $min_configs{$config};
2956 # Now disable each config one by one and do a make oldconfig
2957 # till we find a config that changes our list.
2959 my @test_configs = keys %min_configs;
2961 # Sort keys by who is most dependent on
2962 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2965 # Put configs that did not modify the config at the end.
2967 for (my $i = 0; $i < $#test_configs; $i++) {
2968 if (!defined($nochange_config{$test_configs[0]})) {
2972 # This config didn't change the .config last time.
2973 # Place it at the end
2974 my $config = shift @test_configs;
2975 push @test_configs, $config;
2978 # if every test config has failed to modify the .config file
2979 # in the past, then reset and start over.
2981 undef %nochange_config;
2984 undef %processed_configs;
2986 foreach my $config (@test_configs) {
2988 $found = test_this_config $config;
2990 last if (defined($found));
2992 # oh well, try another config
2995 if (!defined($found)) {
2996 # we could have failed due to the nochange_config hash
2997 # reset and try again
2999 undef %nochange_config;
3003 doprint "No more configs found that we can disable\n";
3011 doprint "Test with $config disabled\n";
3013 # set in_bisect to keep build and monitor from dieing
3018 start_monitor_and_boot or $failed = 1;
3024 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3025 # this config is needed, add it to the ignore list.
3026 $keep_configs{$config} = $min_configs{$config};
3027 $save_configs{$config} = $min_configs{$config};
3028 delete $min_configs{$config};
3030 # update new ignore configs
3031 if (defined($ignore_config)) {
3032 open (OUT, ">$temp_config")
3033 or die "Can't write to $temp_config";
3034 foreach my $config (keys %save_configs) {
3035 print OUT "$save_configs{$config}\n";
3038 run_command "mv $temp_config $ignore_config" or
3039 dodie "failed to copy update to $ignore_config";
3043 # We booted without this config, remove it from the minconfigs.
3044 doprint "$config is not needed, disabling\n";
3046 delete $min_configs{$config};
3048 # Also disable anything that is not enabled in this config
3050 assign_configs \%configs, $output_config;
3051 my @config_keys = keys %min_configs;
3052 foreach my $config (@config_keys) {
3053 if (!defined($configs{$config})) {
3054 doprint "$config is not set, disabling\n";
3055 delete $min_configs{$config};
3059 # Save off all the current mandidory configs
3060 open (OUT, ">$temp_config")
3061 or die "Can't write to $temp_config";
3062 foreach my $config (keys %keep_configs) {
3063 print OUT "$keep_configs{$config}\n";
3065 foreach my $config (keys %min_configs) {
3066 print OUT "$min_configs{$config}\n";
3070 run_command "mv $temp_config $output_minconfig" or
3071 dodie "failed to copy update to $output_minconfig";
3074 doprint "Reboot and wait $sleep_time seconds\n";
3082 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3085 $ktest_config = $ARGV[0];
3086 if (! -f $ktest_config) {
3087 print "$ktest_config does not exist.\n";
3088 if (!read_yn "Create it?") {
3093 $ktest_config = "ktest.conf";
3096 if (! -f $ktest_config) {
3098 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3100 # Generated by ktest.pl
3103 # PWD is a ktest.pl variable that will result in the process working
3104 # directory that ktest.pl is executed in.
3106 # THIS_DIR is automatically assigned the PWD of the path that generated
3107 # the config file. It is best to use this variable when assigning other
3108 # directory paths within this directory. This allows you to easily
3109 # move the test cases to other locations or to other machines.
3111 THIS_DIR := $variable{"PWD"}
3113 # Define each test with TEST_START
3114 # The config options below it will override the defaults
3116 TEST_TYPE = $default{"TEST_TYPE"}
3123 read_config $ktest_config;
3125 if (defined($opt{"LOG_FILE"})) {
3126 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3129 # Append any configs entered in manually to the config file.
3130 my @new_configs = keys %entered_configs;
3131 if ($#new_configs >= 0) {
3132 print "\nAppending entered in configs to $ktest_config\n";
3133 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3134 foreach my $config (@new_configs) {
3135 print OUT "$config = $entered_configs{$config}\n";
3136 $opt{$config} = process_variables($entered_configs{$config});
3140 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3141 unlink $opt{"LOG_FILE"};
3144 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3146 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3149 doprint "DEFAULT OPTIONS:\n";
3151 doprint "\nTEST $i OPTIONS";
3152 if (defined($repeat_tests{$i})) {
3153 $repeat = $repeat_tests{$i};
3154 doprint " ITERATE $repeat";
3159 foreach my $option (sort keys %opt) {
3161 if ($option =~ /\[(\d+)\]$/) {
3167 doprint "$option = $opt{$option}\n";
3171 sub __set_test_option {
3172 my ($name, $i) = @_;
3174 my $option = "$name\[$i\]";
3176 if (defined($opt{$option})) {
3177 return $opt{$option};
3180 foreach my $test (keys %repeat_tests) {
3182 $i < $test + $repeat_tests{$test}) {
3183 $option = "$name\[$test\]";
3184 if (defined($opt{$option})) {
3185 return $opt{$option};
3190 if (defined($opt{$name})) {
3197 sub set_test_option {
3198 my ($name, $i) = @_;
3200 my $option = __set_test_option($name, $i);
3201 return $option if (!defined($option));
3203 return eval_option($option, $i);
3206 # First we need to do is the builds
3207 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3209 # Do not reboot on failing test options
3214 my $makecmd = set_test_option("MAKE_CMD", $i);
3216 $machine = set_test_option("MACHINE", $i);
3217 $ssh_user = set_test_option("SSH_USER", $i);
3218 $tmpdir = set_test_option("TMP_DIR", $i);
3219 $outputdir = set_test_option("OUTPUT_DIR", $i);
3220 $builddir = set_test_option("BUILD_DIR", $i);
3221 $test_type = set_test_option("TEST_TYPE", $i);
3222 $build_type = set_test_option("BUILD_TYPE", $i);
3223 $build_options = set_test_option("BUILD_OPTIONS", $i);
3224 $pre_build = set_test_option("PRE_BUILD", $i);
3225 $post_build = set_test_option("POST_BUILD", $i);
3226 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3227 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
3228 $power_cycle = set_test_option("POWER_CYCLE", $i);
3229 $reboot = set_test_option("REBOOT", $i);
3230 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3231 $minconfig = set_test_option("MIN_CONFIG", $i);
3232 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3233 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3234 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
3235 $run_test = set_test_option("TEST", $i);
3236 $addconfig = set_test_option("ADD_CONFIG", $i);
3237 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3238 $grub_menu = set_test_option("GRUB_MENU", $i);
3239 $post_install = set_test_option("POST_INSTALL", $i);
3240 $no_install = set_test_option("NO_INSTALL", $i);
3241 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3242 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3243 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3244 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3245 $power_off = set_test_option("POWER_OFF", $i);
3246 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3247 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
3248 $sleep_time = set_test_option("SLEEP_TIME", $i);
3249 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
3250 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
3251 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
3252 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
3253 $bisect_skip = set_test_option("BISECT_SKIP", $i);
3254 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
3255 $store_failures = set_test_option("STORE_FAILURES", $i);
3256 $store_successes = set_test_option("STORE_SUCCESSES", $i);
3257 $test_name = set_test_option("TEST_NAME", $i);
3258 $timeout = set_test_option("TIMEOUT", $i);
3259 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3260 $console = set_test_option("CONSOLE", $i);
3261 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
3262 $success_line = set_test_option("SUCCESS_LINE", $i);
3263 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
3264 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3265 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
3266 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
3267 $build_target = set_test_option("BUILD_TARGET", $i);
3268 $ssh_exec = set_test_option("SSH_EXEC", $i);
3269 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
3270 $target_image = set_test_option("TARGET_IMAGE", $i);
3271 $localversion = set_test_option("LOCALVERSION", $i);
3273 $start_minconfig_defined = 1;
3275 if (!defined($start_minconfig)) {
3276 $start_minconfig_defined = 0;
3277 $start_minconfig = $minconfig;
3280 chdir $builddir || die "can't change directory to $builddir";
3282 foreach my $dir ($tmpdir, $outputdir) {
3285 die "can't create $dir";
3289 $ENV{"SSH_USER"} = $ssh_user;
3290 $ENV{"MACHINE"} = $machine;
3292 $buildlog = "$tmpdir/buildlog-$machine";
3293 $testlog = "$tmpdir/testlog-$machine";
3294 $dmesg = "$tmpdir/dmesg-$machine";
3295 $make = "$makecmd O=$outputdir";
3296 $output_config = "$outputdir/.config";
3299 $target = "$ssh_user\@$machine";
3300 if ($reboot_type eq "grub") {
3301 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3302 } elsif (!defined($reboot_script)) {
3303 dodie "REBOOT_SCRIPT not defined"
3307 my $run_type = $build_type;
3308 if ($test_type eq "patchcheck") {
3309 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3310 } elsif ($test_type eq "bisect") {
3311 $run_type = $opt{"BISECT_TYPE[$i]"};
3312 } elsif ($test_type eq "config_bisect") {
3313 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
3316 if ($test_type eq "make_min_config") {
3320 # mistake in config file?
3321 if (!defined($run_type)) {
3322 $run_type = "ERROR";
3326 $installme = " no_install" if ($no_install);
3329 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3335 if (defined($addconfig)) {
3336 my $min = $minconfig;
3337 if (!defined($minconfig)) {
3340 run_command "cat $addconfig $min > $tmpdir/add_config" or
3341 dodie "Failed to create temp config";
3342 $minconfig = "$tmpdir/add_config";
3345 my $checkout = $opt{"CHECKOUT[$i]"};
3346 if (defined($checkout)) {
3347 run_command "git checkout $checkout" or
3348 die "failed to checkout $checkout";
3354 if ($test_type eq "bisect") {
3357 } elsif ($test_type eq "config_bisect") {
3360 } elsif ($test_type eq "patchcheck") {
3363 } elsif ($test_type eq "make_min_config") {
3368 if ($build_type ne "nobuild") {
3369 build $build_type or next;
3372 if ($test_type eq "install") {
3379 if ($test_type ne "build") {
3381 start_monitor_and_boot or $failed = 1;
3383 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3384 do_run_test or $failed = 1;
3393 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3395 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
3399 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";