3 # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4 # Licensed under the terms of the GNU GPL License version 2
9 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
10 use File::Path qw(mkpath);
11 use File::Copy qw(cp);
24 $default{"NUM_TESTS"} = 1;
25 $default{"REBOOT_TYPE"} = "grub";
26 $default{"TEST_TYPE"} = "test";
27 $default{"BUILD_TYPE"} = "randconfig";
28 $default{"MAKE_CMD"} = "make";
29 $default{"TIMEOUT"} = 120;
30 $default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
31 $default{"SLEEP_TIME"} = 60; # sleep time between tests
32 $default{"BUILD_NOCLEAN"} = 0;
33 $default{"REBOOT_ON_ERROR"} = 0;
34 $default{"POWEROFF_ON_ERROR"} = 0;
35 $default{"REBOOT_ON_SUCCESS"} = 1;
36 $default{"POWEROFF_ON_SUCCESS"} = 0;
37 $default{"BUILD_OPTIONS"} = "";
38 $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
39 $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
40 $default{"CLEAR_LOG"} = 0;
41 $default{"BISECT_MANUAL"} = 0;
42 $default{"BISECT_SKIP"} = 1;
43 $default{"SUCCESS_LINE"} = "login:";
44 $default{"DETECT_TRIPLE_FAULT"} = 1;
45 $default{"NO_INSTALL"} = 0;
46 $default{"BOOTED_TIMEOUT"} = 1;
47 $default{"DIE_ON_FAILURE"} = 1;
48 $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
49 $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
50 $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
51 $default{"STOP_AFTER_SUCCESS"} = 10;
52 $default{"STOP_AFTER_FAILURE"} = 60;
53 $default{"STOP_TEST_AFTER"} = 600;
54 $default{"LOCALVERSION"} = "-test";
76 my $poweroff_on_error;
78 my $powercycle_after_reboot;
79 my $poweroff_after_halt;
92 my $start_minconfig_defined;
101 my $config_bisect_good;
102 my $in_patchcheck = 0;
112 my $bisect_sleep_time;
113 my $patchcheck_sleep_time;
120 my $detect_triplefault;
122 my $reboot_success_line;
124 my $stop_after_success;
125 my $stop_after_failure;
138 # do not force reboots on config problems
141 # default variables that can be used
142 chomp ($variable{"PWD"} = `pwd`);
144 $config_help{"MACHINE"} = << "EOF"
145 The machine hostname that you will test.
148 $config_help{"SSH_USER"} = << "EOF"
149 The box is expected to have ssh on normal bootup, provide the user
150 (most likely root, since you need privileged operations)
153 $config_help{"BUILD_DIR"} = << "EOF"
154 The directory that contains the Linux source code (full path).
157 $config_help{"OUTPUT_DIR"} = << "EOF"
158 The directory that the objects will be built (full path).
159 (can not be same as BUILD_DIR)
162 $config_help{"BUILD_TARGET"} = << "EOF"
163 The location of the compiled file to copy to the target.
164 (relative to OUTPUT_DIR)
167 $config_help{"TARGET_IMAGE"} = << "EOF"
168 The place to put your image on the test machine.
171 $config_help{"POWER_CYCLE"} = << "EOF"
172 A script or command to reboot the box.
174 Here is a digital loggers power switch example
175 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
177 Here is an example to reboot a virtual box on the current host
178 with the name "Guest".
179 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
182 $config_help{"CONSOLE"} = << "EOF"
183 The script or command that reads the console
185 If you use ttywatch server, something like the following would work.
186 CONSOLE = nc -d localhost 3001
188 For a virtual machine with guest name "Guest".
189 CONSOLE = virsh console Guest
192 $config_help{"LOCALVERSION"} = << "EOF"
193 Required version ending to differentiate the test
194 from other linux builds on the system.
197 $config_help{"REBOOT_TYPE"} = << "EOF"
198 Way to reboot the box to the test kernel.
199 Only valid options so far are "grub" and "script".
201 If you specify grub, it will assume grub version 1
202 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
203 and select that target to reboot to the kernel. If this is not
204 your setup, then specify "script" and have a command or script
205 specified in REBOOT_SCRIPT to boot to the target.
207 The entry in /boot/grub/menu.lst must be entered in manually.
208 The test will not modify that file.
211 $config_help{"GRUB_MENU"} = << "EOF"
212 The grub title name for the test kernel to boot
213 (Only mandatory if REBOOT_TYPE = grub)
215 Note, ktest.pl will not update the grub menu.lst, you need to
216 manually add an option for the test. ktest.pl will search
217 the grub menu.lst for this option to find what kernel to
220 For example, if in the /boot/grub/menu.lst the test kernel title has:
223 GRUB_MENU = Test Kernel
226 $config_help{"REBOOT_SCRIPT"} = << "EOF"
227 A script to reboot the target into the test kernel
228 (Only mandatory if REBOOT_TYPE = script)
238 print "$prompt [Y/n] ";
241 if ($ans =~ /^\s*$/) {
244 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
245 print "Please answer either 'y' or 'n'.\n";
247 if ($ans !~ /^y$/i) {
253 sub get_ktest_config {
257 return if (defined($opt{$config}));
259 if (defined($config_help{$config})) {
261 print $config_help{$config};
266 if (defined($default{$config})) {
267 print "\[$default{$config}\] ";
270 $ans =~ s/^\s*(.*\S)\s*$/$1/;
271 if ($ans =~ /^\s*$/) {
272 if ($default{$config}) {
273 $ans = $default{$config};
275 print "Your answer can not be blank\n";
279 $entered_configs{$config} = process_variables($ans);
284 sub get_ktest_configs {
285 get_ktest_config("MACHINE");
286 get_ktest_config("SSH_USER");
287 get_ktest_config("BUILD_DIR");
288 get_ktest_config("OUTPUT_DIR");
289 get_ktest_config("BUILD_TARGET");
290 get_ktest_config("TARGET_IMAGE");
291 get_ktest_config("POWER_CYCLE");
292 get_ktest_config("CONSOLE");
293 get_ktest_config("LOCALVERSION");
295 my $rtype = $opt{"REBOOT_TYPE"};
297 if (!defined($rtype)) {
298 if (!defined($opt{"GRUB_MENU"})) {
299 get_ktest_config("REBOOT_TYPE");
300 $rtype = $entered_configs{"REBOOT_TYPE"};
306 if ($rtype eq "grub") {
307 get_ktest_config("GRUB_MENU");
309 get_ktest_config("REBOOT_SCRIPT");
313 sub process_variables {
314 my ($value, $remove_undef) = @_;
317 # We want to check for '\', and it is just easier
318 # to check the previous characet of '$' and not need
319 # to worry if '$' is the first character. By adding
320 # a space to $value, we can just check [^\\]\$ and
321 # it will still work.
324 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
328 # append beginning of value to retval
329 $retval = "$retval$begin";
330 if (defined($variable{$var})) {
331 $retval = "$retval$variable{$var}";
332 } elsif (defined($remove_undef) && $remove_undef) {
333 # for if statements, any variable that is not defined,
334 # we simple convert to 0
335 $retval = "${retval}0";
337 # put back the origin piece.
338 $retval = "$retval\$\{$var\}";
342 $retval = "$retval$value";
344 # remove the space added in the beginning
351 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
353 if (defined($opt{$lvalue})) {
354 if (!$override || defined(${$overrides}{$lvalue})) {
357 $extra = "In the same override section!\n";
359 die "$name: $.: Option $lvalue defined more than once!\n$extra";
361 ${$overrides}{$lvalue} = $rvalue;
363 if ($rvalue =~ /^\s*$/) {
364 delete $opt{$lvalue};
366 $rvalue = process_variables($rvalue);
367 $opt{$lvalue} = $rvalue;
372 my ($lvalue, $rvalue) = @_;
374 if ($rvalue =~ /^\s*$/) {
375 delete $variable{$lvalue};
377 $rvalue = process_variables($rvalue);
378 $variable{$lvalue} = $rvalue;
382 sub process_compare {
383 my ($lval, $cmp, $rval) = @_;
394 return $lval eq $rval;
395 } elsif ($cmp eq "!=") {
396 return $lval ne $rval;
399 my $statement = "$lval $cmp $rval";
400 my $ret = eval $statement;
402 # $@ stores error of eval
413 return defined($variable{$2}) ||
418 sub process_expression {
419 my ($name, $val) = @_;
423 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
426 if (process_expression($name, $express)) {
427 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
429 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
437 while ($val =~ s/^(.*?)($OR|$AND)//) {
441 if (process_expression($name, $express)) {
452 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
453 my $ret = process_compare($1, $2, $3);
455 die "$name: $.: Unable to process comparison\n";
460 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
462 return !value_defined($2);
464 return value_defined($2);
468 if ($val =~ /^\s*0\s*$/) {
470 } elsif ($val =~ /^\s*\d+\s*$/) {
474 die ("$name: $.: Undefined content $val in if statement\n");
478 my ($name, $value) = @_;
480 # Convert variables and replace undefined ones with 0
481 my $val = process_variables($value, 1);
482 my $ret = process_expression $name, $val;
488 my ($config, $current_test_num) = @_;
491 open($in, $config) || die "can't read file $config";
494 $name =~ s,.*/(.*),$1,;
496 my $test_num = $$current_test_num;
499 my $num_tests_set = 0;
512 # ignore blank lines and comments
513 next if (/^\s*$/ || /\s*\#/);
515 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
525 if ($type eq "TEST_START") {
527 if ($num_tests_set) {
528 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
531 $old_test_num = $test_num;
532 $old_repeat = $repeat;
534 $test_num += $repeat;
541 # If SKIP is anywhere in the line, the command will be skipped
542 if ($rest =~ s/\s+SKIP\b//) {
549 if ($rest =~ s/\sELSE\b//) {
551 die "$name: $.: ELSE found with out matching IF section\n$_";
562 if ($rest =~ s/\sIF\s+(.*)//) {
563 if (process_if($name, $1)) {
575 if ($type eq "TEST_START") {
576 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
578 $repeat_tests{"$test_num"} = $repeat;
580 } elsif ($rest =~ s/\sOVERRIDE\b//) {
583 # Clear previous overrides
588 if (!$skip && $rest !~ /^\s*$/) {
589 die "$name: $.: Gargbage found after $type\n$_";
592 if ($skip && $type eq "TEST_START") {
593 $test_num = $old_test_num;
594 $repeat = $old_repeat;
597 } elsif (/^\s*ELSE\b(.*)$/) {
599 die "$name: $.: ELSE found with out matching IF section\n$_";
608 if ($rest =~ /\sIF\s+(.*)/) {
609 # May be a ELSE IF section.
610 if (!process_if($name, $1)) {
619 if ($rest !~ /^\s*$/) {
620 die "$name: $.: Gargbage found after DEFAULTS\n$_";
623 } elsif (/^\s*INCLUDE\s+(\S+)/) {
628 die "$name: $.: INCLUDE can only be done in default sections\n$_";
631 my $file = process_variables($1);
633 if ($file !~ m,^/,) {
634 # check the path of the config file first
635 if ($config =~ m,(.*)/,) {
643 die "$name: $.: Can't read file $file\n$_";
646 if (__read_config($file, \$test_num)) {
650 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
658 ($lvalue eq "NUM_TESTS" ||
659 $lvalue eq "LOG_FILE" ||
660 $lvalue eq "CLEAR_LOG")) {
661 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
664 if ($lvalue eq "NUM_TESTS") {
666 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
669 die "$name: $.: NUM_TESTS must be set in default section\n";
674 if ($default || $lvalue =~ /\[\d+\]$/) {
675 set_value($lvalue, $rvalue, $override, \%overrides, $name);
677 my $val = "$lvalue\[$test_num\]";
678 set_value($val, $rvalue, $override, \%overrides, $name);
681 $repeats{$val} = $repeat;
684 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
690 # process config variables.
691 # Config variables are only active while reading the
692 # config and can be defined anywhere. They also ignore
693 # TEST_START and DEFAULTS, but are skipped if they are in
694 # on of these sections that have SKIP defined.
695 # The save variable can be
696 # defined multiple times and the new one simply overrides
698 set_variable($lvalue, $rvalue);
701 die "$name: $.: Garbage found in config\n$_";
706 $test_num += $repeat - 1;
707 $opt{"NUM_TESTS"} = $test_num;
712 $$current_test_num = $test_num;
723 $test_case = __read_config $config, \$test_num;
725 # make sure we have all mandatory configs
728 # was a test specified?
730 print "No test case specified.\n";
731 print "What test case would you like to run?\n";
734 $default{"TEST_TYPE"} = $ans;
739 foreach my $default (keys %default) {
740 if (!defined($opt{$default})) {
741 $opt{$default} = $default{$default};
747 my ($option, $i) = @_;
749 # Add space to evaluate the character before $
750 $option = " $option";
755 foreach my $test (keys %repeat_tests) {
757 $i < $test + $repeat_tests{$test}) {
765 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
770 # Append beginning of line
771 $retval = "$retval$start";
773 # If the iteration option OPT[$i] exists, then use that.
774 # otherwise see if the default OPT (without [$i]) exists.
776 my $o = "$var\[$i\]";
777 my $parento = "$var\[$parent\]";
779 if (defined($opt{$o})) {
781 $retval = "$retval$o";
782 } elsif ($repeated && defined($opt{$parento})) {
784 $retval = "$retval$o";
785 } elsif (defined($opt{$var})) {
787 $retval = "$retval$o";
789 $retval = "$retval\$\{$var\}";
795 $retval = "$retval$option";
803 my ($option, $i) = @_;
807 # Since an option can evaluate to another option,
808 # keep iterating until we do not evaluate any more
811 while ($prev ne $option) {
812 # Check for recursive evaluations.
813 # 100 deep should be more than enough.
815 die "Over 100 evaluations accurred with $option\n" .
816 "Check for recursive variables\n";
819 $option = __eval_option($option, $i);
826 if (defined($opt{"LOG_FILE"})) {
827 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
834 if (defined($opt{"LOG_FILE"})) {
849 sub wait_for_monitor;
854 if (defined($time)) {
856 # flush out current monitor
857 # May contain the reboot success line
861 # try to reboot normally
862 if (run_command $reboot) {
863 if (defined($powercycle_after_reboot)) {
864 sleep $powercycle_after_reboot;
865 run_command "$power_cycle";
868 # nope? power cycle it.
869 run_command "$power_cycle";
872 if (defined($time)) {
873 wait_for_monitor($time, $reboot_success_line);
881 return $test_type eq "build" || $no_reboot ||
882 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
883 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
887 doprint "CRITICAL FAILURE... ", @_, "\n";
891 if ($reboot_on_error && !do_not_reboot) {
893 doprint "REBOOTING\n";
896 } elsif ($poweroff_on_error && defined($power_off)) {
897 doprint "POWERING OFF\n";
901 if (defined($opt{"LOG_FILE"})) {
902 print " See $opt{LOG_FILE} for more info.\n";
913 my $pid = open($fp, "$console|") or
914 dodie "Can't open console $console";
916 $flags = fcntl($fp, F_GETFL, 0) or
917 dodie "Can't get flags for the socket: $!";
918 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
919 dodie "Can't set flags for the socket: $!";
927 doprint "kill child process $pid\n";
935 if ($monitor_cnt++) {
938 $monitor_fp = \*MONFD;
939 $monitor_pid = open_console $monitor_fp;
943 open(MONFD, "Stop perl from warning about single use of MONFD");
947 if (--$monitor_cnt) {
950 close_console($monitor_fp, $monitor_pid);
953 sub wait_for_monitor {
954 my ($time, $stop) = @_;
959 doprint "** Wait for monitor to settle down **\n";
961 # read the monitor and wait for the system to calm down
963 $line = wait_for_input($monitor_fp, $time);
964 last if (!defined($line));
968 if (defined($stop) && $full_line =~ /$stop/) {
969 doprint "wait for monitor detected $stop\n";
977 print "** Monitor flushed **\n";
981 my ($result, $basedir) = @_;
983 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
984 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
986 my $type = $build_type;
987 if ($type =~ /useconfig/) {
991 my $dir = "$machine-$test_type-$type-$result-$date";
993 $dir = "$basedir/$dir";
997 die "can't create $dir";
1001 "config" => $output_config,
1002 "buildlog" => $buildlog,
1004 "testlog" => $testlog,
1007 while (my ($name, $source) = each(%files)) {
1009 cp "$source", "$dir/$name" or
1010 die "failed to copy $source";
1014 doprint "*** Saved info to $dir ***\n";
1019 if ($die_on_failure) {
1027 # no need to reboot for just building.
1028 if (!do_not_reboot) {
1029 doprint "REBOOTING\n";
1035 if (defined($test_name)) {
1036 $name = " ($test_name)";
1039 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1040 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1041 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1042 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1043 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1045 if (defined($store_failures)) {
1046 save_logs "fail", $store_failures;
1058 $command =~ s/\$SSH_USER/$ssh_user/g;
1059 $command =~ s/\$MACHINE/$machine/g;
1061 doprint("$command ... ");
1063 $pid = open(CMD, "$command 2>&1 |") or
1064 (fail "unable to exec $command" and return 0);
1066 if (defined($opt{"LOG_FILE"})) {
1067 open(LOG, ">>$opt{LOG_FILE}") or
1068 dodie "failed to write to log";
1072 if (defined($redirect)) {
1073 open (RD, ">$redirect") or
1074 dodie "failed to write to redirect $redirect";
1079 print LOG if ($dolog);
1080 print RD if ($dord);
1087 close(LOG) if ($dolog);
1088 close(RD) if ($dord);
1091 doprint "FAILED!\n";
1093 doprint "SUCCESS\n";
1101 my $cp_exec = $ssh_exec;
1103 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1104 return run_command "$cp_exec";
1108 my ($src, $dst) = @_;
1109 my $cp_scp = $scp_to_target;
1111 $cp_scp =~ s/\$SRC_FILE/$src/g;
1112 $cp_scp =~ s/\$DST_FILE/$dst/g;
1114 return run_command "$cp_scp";
1117 sub get_grub_index {
1119 if ($reboot_type ne "grub") {
1122 return if (defined($grub_number));
1124 doprint "Find grub menu ... ";
1127 my $ssh_grub = $ssh_exec;
1128 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1130 open(IN, "$ssh_grub |")
1131 or die "unable to get menu.lst";
1136 if (/^\s*title\s+$grub_menu\s*$/) {
1140 } elsif (/^\s*title\s/) {
1146 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1148 doprint "$grub_number\n";
1153 my ($fp, $time) = @_;
1159 if (!defined($time)) {
1164 vec($rin, fileno($fp), 1) = 1;
1165 $ready = select($rin, undef, undef, $time);
1169 # try to read one char at a time
1170 while (sysread $fp, $ch, 1) {
1172 last if ($ch eq "\n");
1175 if (!length($line)) {
1183 if ($reboot_type eq "grub") {
1184 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1189 run_command "$reboot_script";
1195 doprint "git rev-list --max-count=1 $commit ... ";
1196 my $sha1 = `git rev-list --max-count=1 $commit`;
1203 dodie "Failed to get git $commit";
1216 my $skip_call_trace = 0;
1224 open(DMESG, "> $dmesg") or
1225 die "unable to write to $dmesg";
1231 my $monitor_start = time;
1233 my $version_found = 0;
1237 if ($bug && defined($stop_after_failure) &&
1238 $stop_after_failure >= 0) {
1239 my $time = $stop_after_failure - (time - $failure_start);
1240 $line = wait_for_input($monitor_fp, $time);
1241 if (!defined($line)) {
1242 doprint "bug timed out after $booted_timeout seconds\n";
1243 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1247 $line = wait_for_input($monitor_fp, $booted_timeout);
1248 if (!defined($line)) {
1249 my $s = $booted_timeout == 1 ? "" : "s";
1250 doprint "Successful boot found: break after $booted_timeout second$s\n";
1254 $line = wait_for_input($monitor_fp);
1255 if (!defined($line)) {
1256 my $s = $timeout == 1 ? "" : "s";
1257 doprint "Timed out after $timeout second$s\n";
1265 # we are not guaranteed to get a full line
1266 $full_line .= $line;
1268 if ($full_line =~ /$success_line/) {
1270 $success_start = time;
1273 if ($booted && defined($stop_after_success) &&
1274 $stop_after_success >= 0) {
1276 if ($now - $success_start >= $stop_after_success) {
1277 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1282 if ($full_line =~ /\[ backtrace testing \]/) {
1283 $skip_call_trace = 1;
1286 if ($full_line =~ /call trace:/i) {
1287 if (!$bug && !$skip_call_trace) {
1289 $failure_start = time;
1293 if ($bug && defined($stop_after_failure) &&
1294 $stop_after_failure >= 0) {
1296 if ($now - $failure_start >= $stop_after_failure) {
1297 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1302 if ($full_line =~ /\[ end of backtrace testing \]/) {
1303 $skip_call_trace = 0;
1306 if ($full_line =~ /Kernel panic -/) {
1307 $failure_start = time;
1311 # Detect triple faults by testing the banner
1312 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1313 if ($1 eq $version) {
1315 } elsif ($version_found && $detect_triplefault) {
1316 # We already booted into the kernel we are testing,
1317 # but now we booted into another kernel?
1318 # Consider this a triple fault.
1319 doprint "Aleady booted in Linux kernel $version, but now\n";
1320 doprint "we booted into Linux kernel $1.\n";
1321 doprint "Assuming that this is a triple fault.\n";
1322 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1327 if ($line =~ /\n/) {
1331 if ($stop_test_after > 0 && !$booted && !$bug) {
1332 if (time - $monitor_start > $stop_test_after) {
1333 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1342 return 0 if ($in_bisect);
1343 fail "failed - got a bug report" and return 0;
1347 return 0 if ($in_bisect);
1348 fail "failed - never got a boot prompt." and return 0;
1354 sub do_post_install {
1356 return if (!defined($post_install));
1358 my $cp_post_install = $post_install;
1359 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1360 run_command "$cp_post_install" or
1361 dodie "Failed to run post install";
1366 return if ($no_install);
1368 run_scp "$outputdir/$build_target", "$target_image" or
1369 dodie "failed to copy image";
1371 my $install_mods = 0;
1373 # should we process modules?
1375 open(IN, "$output_config") or dodie("Can't read config file");
1377 if (/CONFIG_MODULES(=y)?/) {
1378 $install_mods = 1 if (defined($1));
1384 if (!$install_mods) {
1386 doprint "No modules needed\n";
1390 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1391 dodie "Failed to install modules";
1393 my $modlib = "/lib/modules/$version";
1394 my $modtar = "ktest-mods.tar.bz2";
1396 run_ssh "rm -rf $modlib" or
1397 dodie "failed to remove old mods: $modlib";
1399 # would be nice if scp -r did not follow symbolic links
1400 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1401 dodie "making tarball";
1403 run_scp "$tmpdir/$modtar", "/tmp" or
1404 dodie "failed to copy modules";
1406 unlink "$tmpdir/$modtar";
1408 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1409 dodie "failed to tar modules";
1411 run_ssh "rm -f /tmp/$modtar";
1417 # get the release name
1418 doprint "$make kernelrelease ... ";
1419 $version = `$make kernelrelease | tail -1`;
1421 doprint "$version\n";
1424 sub start_monitor_and_boot {
1425 # Make sure the stable kernel has finished booting
1438 sub check_buildlog {
1441 my @files = `git show $patch | diffstat -l`;
1443 open(IN, "git show $patch |") or
1444 dodie "failed to show $patch";
1446 if (m,^--- a/(.*),) {
1448 $files[$#files] = $1;
1453 open(IN, $buildlog) or dodie "Can't open $buildlog";
1455 if (/^\s*(.*?):.*(warning|error)/) {
1457 foreach my $file (@files) {
1458 my $fullpath = "$builddir/$file";
1459 if ($file eq $err || $fullpath eq $err) {
1460 fail "$file built with warnings" and return 0;
1470 sub apply_min_config {
1471 my $outconfig = "$output_config.new";
1473 # Read the config file and remove anything that
1474 # is in the force_config hash (from minconfig and others)
1475 # then add the force config back.
1477 doprint "Applying minimum configurations into $output_config.new\n";
1479 open (OUT, ">$outconfig") or
1480 dodie "Can't create $outconfig";
1482 if (-f $output_config) {
1483 open (IN, $output_config) or
1484 dodie "Failed to open $output_config";
1486 if (/^(# )?(CONFIG_[^\s=]*)/) {
1487 next if (defined($force_config{$2}));
1493 foreach my $config (keys %force_config) {
1494 print OUT "$force_config{$config}\n";
1498 run_command "mv $outconfig $output_config";
1501 sub make_oldconfig {
1503 my @force_list = keys %force_config;
1505 if ($#force_list >= 0) {
1509 if (!run_command "$make oldnoconfig") {
1510 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1511 # try a yes '' | oldconfig
1512 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1513 run_command "yes '' | $make oldconfig" or
1514 dodie "failed make config oldconfig";
1518 # read a config file and use this to force new configs.
1519 sub load_force_config {
1522 open(IN, $config) or
1523 dodie "failed to read $config";
1526 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1527 $force_config{$1} = $_;
1528 } elsif (/^# (CONFIG_\S*) is not set/) {
1529 $force_config{$1} = $_;
1540 # Failed builds should not reboot the target
1541 my $save_no_reboot = $no_reboot;
1544 if (defined($pre_build)) {
1545 my $ret = run_command $pre_build;
1546 if (!$ret && defined($pre_build_die) &&
1548 dodie "failed to pre_build\n";
1552 if ($type =~ /^useconfig:(.*)/) {
1553 run_command "cp $1 $output_config" or
1554 dodie "could not copy $1 to .config";
1556 $type = "oldconfig";
1559 # old config can ask questions
1560 if ($type eq "oldconfig") {
1561 $type = "oldnoconfig";
1563 # allow for empty configs
1564 run_command "touch $output_config";
1567 run_command "mv $output_config $outputdir/config_temp" or
1568 dodie "moving .config";
1570 run_command "$make mrproper" or dodie "make mrproper";
1572 run_command "mv $outputdir/config_temp $output_config" or
1573 dodie "moving config_temp";
1576 } elsif (!$noclean) {
1577 unlink "$output_config";
1578 run_command "$make mrproper" or
1579 dodie "make mrproper";
1582 # add something to distinguish this build
1583 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1584 print OUT "$localversion\n";
1587 if (defined($minconfig)) {
1588 load_force_config($minconfig);
1591 if ($type ne "oldnoconfig") {
1592 run_command "$make $type" or
1593 dodie "failed make config";
1595 # Run old config regardless, to enforce min configurations
1598 $redirect = "$buildlog";
1599 my $build_ret = run_command "$make $build_options";
1602 if (defined($post_build)) {
1603 my $ret = run_command $post_build;
1604 if (!$ret && defined($post_build_die) &&
1606 dodie "failed to post_build\n";
1611 # bisect may need this to pass
1613 $no_reboot = $save_no_reboot;
1616 fail "failed build" and return 0;
1619 $no_reboot = $save_no_reboot;
1625 if (!run_ssh "halt" or defined($power_off)) {
1626 if (defined($poweroff_after_halt)) {
1627 sleep $poweroff_after_halt;
1628 run_command "$power_off";
1632 run_command "$power_off";
1643 if (defined($test_name)) {
1644 $name = " ($test_name)";
1647 doprint "\n\n*******************************************\n";
1648 doprint "*******************************************\n";
1649 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1650 doprint "*******************************************\n";
1651 doprint "*******************************************\n";
1653 if (defined($store_successes)) {
1654 save_logs "success", $store_successes;
1657 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1658 doprint "Reboot and wait $sleep_time seconds\n";
1665 doprint "Pass or fail? [p/f]";
1668 if ($ans eq "p" || $ans eq "P") {
1670 } elsif ($ans eq "f" || $ans eq "F") {
1673 print "Please answer 'P' or 'F'\n";
1678 sub child_run_test {
1681 # child should have no power
1682 $reboot_on_error = 0;
1683 $poweroff_on_error = 0;
1684 $die_on_failure = 1;
1686 $redirect = "$testlog";
1687 run_command $run_test or $failed = 1;
1695 sub child_finished {
1708 doprint "run test $run_test\n";
1712 $SIG{CHLD} = qw(child_finished);
1716 child_run_test if (!$child_pid);
1721 $line = wait_for_input($monitor_fp, 1);
1722 if (defined($line)) {
1724 # we are not guaranteed to get a full line
1725 $full_line .= $line;
1728 if ($full_line =~ /call trace:/i) {
1732 if ($full_line =~ /Kernel panic -/) {
1736 if ($line =~ /\n/) {
1740 } while (!$child_done && !$bug);
1743 my $failure_start = time;
1746 $line = wait_for_input($monitor_fp, 1);
1747 if (defined($line)) {
1751 if ($now - $failure_start >= $stop_after_failure) {
1754 } while (defined($line));
1756 doprint "Detected kernel crash!\n";
1757 # kill the child with extreme prejudice
1761 waitpid $child_pid, 0;
1764 if ($bug || $child_exit) {
1765 return 0 if $in_bisect;
1766 fail "test failed" and return 0;
1771 sub run_git_bisect {
1774 doprint "$command ... ";
1776 my $output = `$command 2>&1`;
1783 dodie "Failed to git bisect";
1786 doprint "SUCCESS\n";
1787 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1788 doprint "$1 [$2]\n";
1789 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1791 doprint "Found bad commit... $1\n";
1794 # we already logged it, just print it now.
1802 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1803 reboot $bisect_sleep_time;
1806 # returns 1 on success, 0 on failure, -1 on skip
1807 sub run_bisect_test {
1808 my ($type, $buildtype) = @_;
1817 build $buildtype or $failed = 1;
1819 if ($type ne "build") {
1820 if ($failed && $bisect_skip) {
1824 dodie "Failed on build" if $failed;
1827 start_monitor_and_boot or $failed = 1;
1829 if ($type ne "boot") {
1830 if ($failed && $bisect_skip) {
1836 dodie "Failed on boot" if $failed;
1838 do_run_test or $failed = 1;
1849 # reboot the box to a kernel we can ssh to
1850 if ($type ne "build") {
1860 my $buildtype = "oldconfig";
1862 # We should have a minconfig to use?
1863 if (defined($minconfig)) {
1864 $buildtype = "useconfig:$minconfig";
1867 my $ret = run_bisect_test $type, $buildtype;
1869 if ($bisect_manual) {
1870 $ret = answer_bisect;
1873 # Are we looking for where it worked, not failed?
1874 if ($reverse_bisect) {
1880 } elsif ($ret == 0) {
1882 } elsif ($bisect_skip) {
1883 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1893 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1894 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1895 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1897 my $good = $opt{"BISECT_GOOD[$i]"};
1898 my $bad = $opt{"BISECT_BAD[$i]"};
1899 my $type = $opt{"BISECT_TYPE[$i]"};
1900 my $start = $opt{"BISECT_START[$i]"};
1901 my $replay = $opt{"BISECT_REPLAY[$i]"};
1902 my $start_files = $opt{"BISECT_FILES[$i]"};
1904 if (defined($start_files)) {
1905 $start_files = " -- " . $start_files;
1910 # convert to true sha1's
1911 $good = get_sha1($good);
1912 $bad = get_sha1($bad);
1914 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1915 $opt{"BISECT_REVERSE[$i]"} == 1) {
1916 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1917 $reverse_bisect = 1;
1919 $reverse_bisect = 0;
1922 # Can't have a test without having a test to run
1923 if ($type eq "test" && !defined($run_test)) {
1927 my $check = $opt{"BISECT_CHECK[$i]"};
1928 if (defined($check) && $check ne "0") {
1931 my $head = get_sha1("HEAD");
1933 if ($check ne "good") {
1934 doprint "TESTING BISECT BAD [$bad]\n";
1935 run_command "git checkout $bad" or
1936 die "Failed to checkout $bad";
1938 $result = run_bisect $type;
1940 if ($result ne "bad") {
1941 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1945 if ($check ne "bad") {
1946 doprint "TESTING BISECT GOOD [$good]\n";
1947 run_command "git checkout $good" or
1948 die "Failed to checkout $good";
1950 $result = run_bisect $type;
1952 if ($result ne "good") {
1953 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1957 # checkout where we started
1958 run_command "git checkout $head" or
1959 die "Failed to checkout $head";
1962 run_command "git bisect start$start_files" or
1963 dodie "could not start bisect";
1965 run_command "git bisect good $good" or
1966 dodie "could not set bisect good to $good";
1968 run_git_bisect "git bisect bad $bad" or
1969 dodie "could not set bisect bad to $bad";
1971 if (defined($replay)) {
1972 run_command "git bisect replay $replay" or
1973 dodie "failed to run replay";
1976 if (defined($start)) {
1977 run_command "git checkout $start" or
1978 dodie "failed to checkout $start";
1983 $result = run_bisect $type;
1984 $test = run_git_bisect "git bisect $result";
1987 run_command "git bisect log" or
1988 dodie "could not capture git bisect log";
1990 run_command "git bisect reset" or
1991 dodie "could not reset git bisect";
1993 doprint "Bad commit was [$bisect_bad]\n";
2006 sub assign_configs {
2007 my ($hash, $config) = @_;
2010 or dodie "Failed to read $config";
2013 if (/^((CONFIG\S*)=.*)/) {
2021 sub process_config_ignore {
2024 assign_configs \%config_ignore, $config;
2027 sub read_current_config {
2028 my ($config_ref) = @_;
2030 %{$config_ref} = ();
2031 undef %{$config_ref};
2033 my @key = keys %{$config_ref};
2035 print "did not delete!\n";
2038 open (IN, "$output_config");
2041 if (/^(CONFIG\S+)=(.*)/) {
2042 ${$config_ref}{$1} = $2;
2048 sub get_dependencies {
2051 my $arr = $dependency{$config};
2052 if (!defined($arr)) {
2058 foreach my $dep (@{$arr}) {
2059 print "ADD DEP $dep\n";
2060 @deps = (@deps, get_dependencies $dep);
2069 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2071 foreach my $config (@configs) {
2072 print OUT "$config_set{$config}\n";
2073 my @deps = get_dependencies $config;
2074 foreach my $dep (@deps) {
2075 print OUT "$config_set{$dep}\n";
2079 foreach my $config (keys %config_ignore) {
2080 print OUT "$config_ignore{$config}\n";
2088 sub compare_configs {
2091 foreach my $item (keys %a) {
2092 if (!defined($b{$item})) {
2093 print "diff $item\n";
2101 print "diff2 $keys[0]\n";
2103 return -1 if ($#keys >= 0);
2108 sub run_config_bisect_test {
2111 return run_bisect_test $type, "oldconfig";
2114 sub process_passed {
2117 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2118 # Passed! All these configs are part of a good compile.
2119 # Add them to the min options.
2120 foreach my $config (keys %configs) {
2121 if (defined($config_list{$config})) {
2122 doprint " removing $config\n";
2123 $config_ignore{$config} = $config_list{$config};
2124 delete $config_list{$config};
2127 doprint "config copied to $outputdir/config_good\n";
2128 run_command "cp -f $output_config $outputdir/config_good";
2131 sub process_failed {
2134 doprint "\n\n***************************************\n";
2135 doprint "Found bad config: $config\n";
2136 doprint "***************************************\n\n";
2139 sub run_config_bisect {
2141 my @start_list = keys %config_list;
2143 if ($#start_list < 0) {
2144 doprint "No more configs to test!!!\n";
2148 doprint "***** RUN TEST ***\n";
2149 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2153 my $count = $#start_list + 1;
2154 doprint " $count configs to test\n";
2156 my $half = int($#start_list / 2);
2159 my @tophalf = @start_list[0 .. $half];
2161 create_config @tophalf;
2162 read_current_config \%current_config;
2164 $count = $#tophalf + 1;
2165 doprint "Testing $count configs\n";
2167 # make sure we test something
2168 foreach my $config (@tophalf) {
2169 if (defined($current_config{$config})) {
2175 # try the other half
2176 doprint "Top half produced no set configs, trying bottom half\n";
2177 @tophalf = @start_list[$half + 1 .. $#start_list];
2178 create_config @tophalf;
2179 read_current_config \%current_config;
2180 foreach my $config (@tophalf) {
2181 if (defined($current_config{$config})) {
2187 doprint "Failed: Can't make new config with current configs\n";
2188 foreach my $config (@start_list) {
2189 doprint " CONFIG: $config\n";
2193 $count = $#tophalf + 1;
2194 doprint "Testing $count configs\n";
2197 $ret = run_config_bisect_test $type;
2198 if ($bisect_manual) {
2199 $ret = answer_bisect;
2202 process_passed %current_config;
2206 doprint "This config had a failure.\n";
2207 doprint "Removing these configs that were not set in this config:\n";
2208 doprint "config copied to $outputdir/config_bad\n";
2209 run_command "cp -f $output_config $outputdir/config_bad";
2211 # A config exists in this group that was bad.
2212 foreach my $config (keys %config_list) {
2213 if (!defined($current_config{$config})) {
2214 doprint " removing $config\n";
2215 delete $config_list{$config};
2219 @start_list = @tophalf;
2221 if ($#start_list == 0) {
2222 process_failed $start_list[0];
2226 # remove half the configs we are looking at and see if
2228 $half = int($#start_list / 2);
2229 } while ($#start_list > 0);
2231 # we found a single config, try it again unless we are running manually
2233 if ($bisect_manual) {
2234 process_failed $start_list[0];
2238 my @tophalf = @start_list[0 .. 0];
2240 $ret = run_config_bisect_test $type;
2242 process_passed %current_config;
2246 process_failed $start_list[0];
2253 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2255 my $tmpconfig = "$tmpdir/use_config";
2257 if (defined($config_bisect_good)) {
2258 process_config_ignore $config_bisect_good;
2261 # Make the file with the bad config and the min config
2262 if (defined($minconfig)) {
2263 # read the min config for things to ignore
2264 run_command "cp $minconfig $tmpconfig" or
2265 dodie "failed to copy $minconfig to $tmpconfig";
2270 if (-f $tmpconfig) {
2271 load_force_config($tmpconfig);
2272 process_config_ignore $tmpconfig;
2275 # now process the start config
2276 run_command "cp $start_config $output_config" or
2277 dodie "failed to copy $start_config to $output_config";
2279 # read directly what we want to check
2281 open (IN, $output_config)
2282 or dodie "faied to open $output_config";
2285 if (/^((CONFIG\S*)=.*)/) {
2286 $config_check{$2} = $1;
2291 # Now run oldconfig with the minconfig
2294 # check to see what we lost (or gained)
2295 open (IN, $output_config)
2296 or dodie "Failed to read $start_config";
2298 my %removed_configs;
2302 if (/^((CONFIG\S*)=.*)/) {
2303 # save off all options
2304 $config_set{$2} = $1;
2305 if (defined($config_check{$2})) {
2306 if (defined($config_ignore{$2})) {
2307 $removed_configs{$2} = $1;
2309 $config_list{$2} = $1;
2311 } elsif (!defined($config_ignore{$2})) {
2312 $added_configs{$2} = $1;
2313 $config_list{$2} = $1;
2319 my @confs = keys %removed_configs;
2321 doprint "Configs overridden by default configs and removed from check:\n";
2322 foreach my $config (@confs) {
2323 doprint " $config\n";
2326 @confs = keys %added_configs;
2328 doprint "Configs appearing in make oldconfig and added:\n";
2329 foreach my $config (@confs) {
2330 doprint " $config\n";
2337 # Sometimes kconfig does weird things. We must make sure
2338 # that the config we autocreate has everything we need
2339 # to test, otherwise we may miss testing configs, or
2340 # may not be able to create a new config.
2341 # Here we create a config with everything set.
2342 create_config (keys %config_list);
2343 read_current_config \%config_test;
2344 foreach my $config (keys %config_list) {
2345 if (!defined($config_test{$config})) {
2348 doprint "Configs not produced by kconfig (will not be checked):\n";
2350 doprint " $config\n";
2351 delete $config_list{$config};
2356 $ret = run_config_bisect;
2359 return $ret if ($ret < 0);
2364 sub patchcheck_reboot {
2365 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2366 reboot $patchcheck_sleep_time;
2372 die "PATCHCHECK_START[$i] not defined\n"
2373 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2374 die "PATCHCHECK_TYPE[$i] not defined\n"
2375 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2377 my $start = $opt{"PATCHCHECK_START[$i]"};
2380 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2381 $end = $opt{"PATCHCHECK_END[$i]"};
2384 # Get the true sha1's since we can use things like HEAD~3
2385 $start = get_sha1($start);
2386 $end = get_sha1($end);
2388 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2390 # Can't have a test without having a test to run
2391 if ($type eq "test" && !defined($run_test)) {
2395 open (IN, "git log --pretty=oneline $end|") or
2396 dodie "could not get git list";
2402 $list[$#list+1] = $_;
2403 last if (/^$start/);
2407 if ($list[$#list] !~ /^$start/) {
2408 fail "SHA1 $start not found";
2411 # go backwards in the list
2412 @list = reverse @list;
2414 my $save_clean = $noclean;
2415 my %ignored_warnings;
2417 if (defined($ignore_warnings)) {
2418 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2419 $ignored_warnings{$sha1} = 1;
2424 foreach my $item (@list) {
2426 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2428 doprint "\nProcessing commit $item\n\n";
2430 run_command "git checkout $sha1" or
2431 die "Failed to checkout $sha1";
2433 # only clean on the first and last patch
2434 if ($item eq $list[0] ||
2435 $item eq $list[$#list]) {
2436 $noclean = $save_clean;
2441 if (defined($minconfig)) {
2442 build "useconfig:$minconfig" or return 0;
2444 # ?? no config to use?
2445 build "oldconfig" or return 0;
2449 if (!defined($ignored_warnings{$sha1})) {
2450 check_buildlog $sha1 or return 0;
2453 next if ($type eq "build");
2457 start_monitor_and_boot or $failed = 1;
2459 if (!$failed && $type ne "boot"){
2460 do_run_test or $failed = 1;
2463 return 0 if ($failed);
2483 # $config depends on $dep
2484 my ($config, $dep) = @_;
2486 if (defined($depends{$config})) {
2487 $depends{$config} .= " " . $dep;
2489 $depends{$config} = $dep;
2492 # record the number of configs depending on $dep
2493 if (defined $depcount{$dep}) {
2496 $depcount{$dep} = 1;
2500 # taken from streamline_config.pl
2512 if (! -f $kconfig) {
2513 doprint "file $kconfig does not exist, skipping\n";
2517 open(KIN, "$kconfig")
2518 or die "Can't open $kconfig";
2522 # Make sure that lines ending with \ continue
2524 $_ = $line . " " . $_;
2535 # collect any Kconfig sources
2536 if (/^source\s*"(.*)"/) {
2537 $kconfigs[$#kconfigs+1] = $1;
2541 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2545 for (my $i = 0; $i < $iflevel; $i++) {
2546 add_dep $config, $ifdeps[$i];
2549 # collect the depends for the config
2550 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2552 add_dep $config, $1;
2554 # Get the configs that select this config
2555 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2557 # selected by depends on config
2558 add_dep $1, $config;
2560 # Check for if statements
2561 } elsif (/^if\s+(.*\S)\s*$/) {
2563 # remove beginning and ending non text
2564 $deps =~ s/^[^a-zA-Z0-9_]*//;
2565 $deps =~ s/[^a-zA-Z0-9_]*$//;
2567 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2569 $ifdeps[$iflevel++] = join ':', @deps;
2571 } elsif (/^endif/) {
2573 $iflevel-- if ($iflevel);
2576 } elsif (/^\s*help\s*$/) {
2582 # read in any configs that were found.
2583 foreach $kconfig (@kconfigs) {
2584 if (!defined($read_kconfigs{$kconfig})) {
2585 $read_kconfigs{$kconfig} = 1;
2586 read_kconfig("$builddir/$kconfig");
2592 # find out which arch this is by the kconfig file
2593 open (IN, $output_config)
2594 or dodie "Failed to read $output_config";
2597 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2604 if (!defined($arch)) {
2605 doprint "Could not find arch from config file\n";
2606 doprint "no dependencies used\n";
2610 # arch is really the subarch, we need to know
2611 # what directory to look at.
2612 if ($arch eq "i386" || $arch eq "x86_64") {
2614 } elsif ($arch =~ /^tile/) {
2618 my $kconfig = "$builddir/arch/$arch/Kconfig";
2620 if (! -f $kconfig && $arch =~ /\d$/) {
2622 # some subarchs have numbers, truncate them
2624 $kconfig = "$builddir/arch/$arch/Kconfig";
2625 if (! -f $kconfig) {
2626 doprint "No idea what arch dir $orig is for\n";
2627 doprint "no dependencies used\n";
2632 read_kconfig($kconfig);
2635 sub read_config_list {
2639 or dodie "Failed to read $config";
2642 if (/^((CONFIG\S*)=.*)/) {
2643 if (!defined($config_ignore{$2})) {
2644 $config_list{$2} = $1;
2652 sub read_output_config {
2655 assign_configs \%config_ignore, $config;
2658 sub make_new_config {
2661 open (OUT, ">$output_config")
2662 or dodie "Failed to write $output_config";
2664 foreach my $config (@configs) {
2665 print OUT "$config\n";
2673 $config =~ s/CONFIG_//;
2681 my $kconfig = chomp_config $dep;
2683 $dep = $depends{"$kconfig"};
2685 # the dep string we have saves the dependencies as they
2686 # were found, including expressions like ! && ||. We
2687 # want to split this out into just an array of configs.
2689 my $valid = "A-Za-z_0-9";
2693 while ($dep =~ /[$valid]/) {
2695 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2696 my $conf = "CONFIG_" . $1;
2698 $configs[$#configs + 1] = $conf;
2700 $dep =~ s/^[^$valid]*[$valid]+//;
2702 die "this should never happen";
2712 my %processed_configs;
2713 my %nochange_config;
2715 sub test_this_config {
2720 # if we already processed this config, skip it
2721 if (defined($processed_configs{$config})) {
2724 $processed_configs{$config} = 1;
2726 # if this config failed during this round, skip it
2727 if (defined($nochange_config{$config})) {
2731 my $kconfig = chomp_config $config;
2733 # Test dependencies first
2734 if (defined($depends{"$kconfig"})) {
2735 my @parents = get_depends $config;
2736 foreach my $parent (@parents) {
2737 # if the parent is in the min config, check it first
2738 next if (!defined($min_configs{$parent}));
2739 $found = test_this_config($parent);
2740 if (defined($found)) {
2746 # Remove this config from the list of configs
2747 # do a make oldnoconfig and then read the resulting
2748 # .config to make sure it is missing the config that
2750 my %configs = %min_configs;
2751 delete $configs{$config};
2752 make_new_config ((values %configs), (values %keep_configs));
2755 assign_configs \%configs, $output_config;
2757 return $config if (!defined($configs{$config}));
2759 doprint "disabling config $config did not change .config\n";
2761 $nochange_config{$config} = 1;
2766 sub make_min_config {
2769 if (!defined($output_minconfig)) {
2770 fail "OUTPUT_MIN_CONFIG not defined" and return;
2773 # If output_minconfig exists, and the start_minconfig
2774 # came from min_config, than ask if we should use
2776 if (-f $output_minconfig && !$start_minconfig_defined) {
2777 print "$output_minconfig exists\n";
2778 if (read_yn " Use it as minconfig?") {
2779 $start_minconfig = $output_minconfig;
2783 if (!defined($start_minconfig)) {
2784 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2787 my $temp_config = "$tmpdir/temp_config";
2789 # First things first. We build an allnoconfig to find
2790 # out what the defaults are that we can't touch.
2791 # Some are selections, but we really can't handle selections.
2793 my $save_minconfig = $minconfig;
2796 run_command "$make allnoconfig" or return 0;
2800 process_config_ignore $output_config;
2802 undef %save_configs;
2805 if (defined($ignore_config)) {
2806 # make sure the file exists
2807 `touch $ignore_config`;
2808 assign_configs \%save_configs, $ignore_config;
2811 %keep_configs = %save_configs;
2813 doprint "Load initial configs from $start_minconfig\n";
2815 # Look at the current min configs, and save off all the
2816 # ones that were set via the allnoconfig
2817 assign_configs \%min_configs, $start_minconfig;
2819 my @config_keys = keys %min_configs;
2821 # All configs need a depcount
2822 foreach my $config (@config_keys) {
2823 my $kconfig = chomp_config $config;
2824 if (!defined $depcount{$kconfig}) {
2825 $depcount{$kconfig} = 0;
2829 # Remove anything that was set by the make allnoconfig
2830 # we shouldn't need them as they get set for us anyway.
2831 foreach my $config (@config_keys) {
2832 # Remove anything in the ignore_config
2833 if (defined($keep_configs{$config})) {
2834 my $file = $ignore_config;
2835 $file =~ s,.*/(.*?)$,$1,;
2836 doprint "$config set by $file ... ignored\n";
2837 delete $min_configs{$config};
2840 # But make sure the settings are the same. If a min config
2841 # sets a selection, we do not want to get rid of it if
2842 # it is not the same as what we have. Just move it into
2844 if (defined($config_ignore{$config})) {
2845 if ($config_ignore{$config} ne $min_configs{$config}) {
2846 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2847 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2848 $keep_configs{$config} = $min_configs{$config};
2850 doprint "$config set by allnoconfig ... ignored\n";
2852 delete $min_configs{$config};
2864 # Now disable each config one by one and do a make oldconfig
2865 # till we find a config that changes our list.
2867 my @test_configs = keys %min_configs;
2869 # Sort keys by who is most dependent on
2870 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2873 # Put configs that did not modify the config at the end.
2875 for (my $i = 0; $i < $#test_configs; $i++) {
2876 if (!defined($nochange_config{$test_configs[0]})) {
2880 # This config didn't change the .config last time.
2881 # Place it at the end
2882 my $config = shift @test_configs;
2883 push @test_configs, $config;
2886 # if every test config has failed to modify the .config file
2887 # in the past, then reset and start over.
2889 undef %nochange_config;
2892 undef %processed_configs;
2894 foreach my $config (@test_configs) {
2896 $found = test_this_config $config;
2898 last if (defined($found));
2900 # oh well, try another config
2903 if (!defined($found)) {
2904 # we could have failed due to the nochange_config hash
2905 # reset and try again
2907 undef %nochange_config;
2911 doprint "No more configs found that we can disable\n";
2919 doprint "Test with $config disabled\n";
2921 # set in_bisect to keep build and monitor from dieing
2926 start_monitor_and_boot or $failed = 1;
2932 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
2933 # this config is needed, add it to the ignore list.
2934 $keep_configs{$config} = $min_configs{$config};
2935 $save_configs{$config} = $min_configs{$config};
2936 delete $min_configs{$config};
2938 # update new ignore configs
2939 if (defined($ignore_config)) {
2940 open (OUT, ">$temp_config")
2941 or die "Can't write to $temp_config";
2942 foreach my $config (keys %save_configs) {
2943 print OUT "$save_configs{$config}\n";
2946 run_command "mv $temp_config $ignore_config" or
2947 dodie "failed to copy update to $ignore_config";
2951 # We booted without this config, remove it from the minconfigs.
2952 doprint "$config is not needed, disabling\n";
2954 delete $min_configs{$config};
2956 # Also disable anything that is not enabled in this config
2958 assign_configs \%configs, $output_config;
2959 my @config_keys = keys %min_configs;
2960 foreach my $config (@config_keys) {
2961 if (!defined($configs{$config})) {
2962 doprint "$config is not set, disabling\n";
2963 delete $min_configs{$config};
2967 # Save off all the current mandidory configs
2968 open (OUT, ">$temp_config")
2969 or die "Can't write to $temp_config";
2970 foreach my $config (keys %keep_configs) {
2971 print OUT "$keep_configs{$config}\n";
2973 foreach my $config (keys %min_configs) {
2974 print OUT "$min_configs{$config}\n";
2978 run_command "mv $temp_config $output_minconfig" or
2979 dodie "failed to copy update to $output_minconfig";
2982 doprint "Reboot and wait $sleep_time seconds\n";
2990 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2993 $ktest_config = $ARGV[0];
2994 if (! -f $ktest_config) {
2995 print "$ktest_config does not exist.\n";
2996 if (!read_yn "Create it?") {
3001 $ktest_config = "ktest.conf";
3004 if (! -f $ktest_config) {
3005 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3007 # Generated by ktest.pl
3009 # Define each test with TEST_START
3010 # The config options below it will override the defaults
3018 read_config $ktest_config;
3020 if (defined($opt{"LOG_FILE"})) {
3021 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3024 # Append any configs entered in manually to the config file.
3025 my @new_configs = keys %entered_configs;
3026 if ($#new_configs >= 0) {
3027 print "\nAppending entered in configs to $ktest_config\n";
3028 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3029 foreach my $config (@new_configs) {
3030 print OUT "$config = $entered_configs{$config}\n";
3031 $opt{$config} = $entered_configs{$config};
3035 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3036 unlink $opt{"LOG_FILE"};
3039 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3041 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3044 doprint "DEFAULT OPTIONS:\n";
3046 doprint "\nTEST $i OPTIONS";
3047 if (defined($repeat_tests{$i})) {
3048 $repeat = $repeat_tests{$i};
3049 doprint " ITERATE $repeat";
3054 foreach my $option (sort keys %opt) {
3056 if ($option =~ /\[(\d+)\]$/) {
3062 doprint "$option = $opt{$option}\n";
3066 sub __set_test_option {
3067 my ($name, $i) = @_;
3069 my $option = "$name\[$i\]";
3071 if (defined($opt{$option})) {
3072 return $opt{$option};
3075 foreach my $test (keys %repeat_tests) {
3077 $i < $test + $repeat_tests{$test}) {
3078 $option = "$name\[$test\]";
3079 if (defined($opt{$option})) {
3080 return $opt{$option};
3085 if (defined($opt{$name})) {
3092 sub set_test_option {
3093 my ($name, $i) = @_;
3095 my $option = __set_test_option($name, $i);
3096 return $option if (!defined($option));
3098 return eval_option($option, $i);
3101 # First we need to do is the builds
3102 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3104 # Do not reboot on failing test options
3109 my $makecmd = set_test_option("MAKE_CMD", $i);
3111 $machine = set_test_option("MACHINE", $i);
3112 $ssh_user = set_test_option("SSH_USER", $i);
3113 $tmpdir = set_test_option("TMP_DIR", $i);
3114 $outputdir = set_test_option("OUTPUT_DIR", $i);
3115 $builddir = set_test_option("BUILD_DIR", $i);
3116 $test_type = set_test_option("TEST_TYPE", $i);
3117 $build_type = set_test_option("BUILD_TYPE", $i);
3118 $build_options = set_test_option("BUILD_OPTIONS", $i);
3119 $pre_build = set_test_option("PRE_BUILD", $i);
3120 $post_build = set_test_option("POST_BUILD", $i);
3121 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3122 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
3123 $power_cycle = set_test_option("POWER_CYCLE", $i);
3124 $reboot = set_test_option("REBOOT", $i);
3125 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3126 $minconfig = set_test_option("MIN_CONFIG", $i);
3127 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3128 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3129 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
3130 $run_test = set_test_option("TEST", $i);
3131 $addconfig = set_test_option("ADD_CONFIG", $i);
3132 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3133 $grub_menu = set_test_option("GRUB_MENU", $i);
3134 $post_install = set_test_option("POST_INSTALL", $i);
3135 $no_install = set_test_option("NO_INSTALL", $i);
3136 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3137 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3138 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3139 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3140 $power_off = set_test_option("POWER_OFF", $i);
3141 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3142 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
3143 $sleep_time = set_test_option("SLEEP_TIME", $i);
3144 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
3145 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
3146 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
3147 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
3148 $bisect_skip = set_test_option("BISECT_SKIP", $i);
3149 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
3150 $store_failures = set_test_option("STORE_FAILURES", $i);
3151 $store_successes = set_test_option("STORE_SUCCESSES", $i);
3152 $test_name = set_test_option("TEST_NAME", $i);
3153 $timeout = set_test_option("TIMEOUT", $i);
3154 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3155 $console = set_test_option("CONSOLE", $i);
3156 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
3157 $success_line = set_test_option("SUCCESS_LINE", $i);
3158 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
3159 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3160 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
3161 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
3162 $build_target = set_test_option("BUILD_TARGET", $i);
3163 $ssh_exec = set_test_option("SSH_EXEC", $i);
3164 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
3165 $target_image = set_test_option("TARGET_IMAGE", $i);
3166 $localversion = set_test_option("LOCALVERSION", $i);
3168 $start_minconfig_defined = 1;
3170 if (!defined($start_minconfig)) {
3171 $start_minconfig_defined = 0;
3172 $start_minconfig = $minconfig;
3175 chdir $builddir || die "can't change directory to $builddir";
3177 foreach my $dir ($tmpdir, $outputdir) {
3180 die "can't create $dir";
3184 $ENV{"SSH_USER"} = $ssh_user;
3185 $ENV{"MACHINE"} = $machine;
3187 $target = "$ssh_user\@$machine";
3189 $buildlog = "$tmpdir/buildlog-$machine";
3190 $testlog = "$tmpdir/testlog-$machine";
3191 $dmesg = "$tmpdir/dmesg-$machine";
3192 $make = "$makecmd O=$outputdir";
3193 $output_config = "$outputdir/.config";
3195 if ($reboot_type eq "grub") {
3196 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3197 } elsif (!defined($reboot_script)) {
3198 dodie "REBOOT_SCRIPT not defined"
3201 my $run_type = $build_type;
3202 if ($test_type eq "patchcheck") {
3203 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3204 } elsif ($test_type eq "bisect") {
3205 $run_type = $opt{"BISECT_TYPE[$i]"};
3206 } elsif ($test_type eq "config_bisect") {
3207 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
3210 if ($test_type eq "make_min_config") {
3214 # mistake in config file?
3215 if (!defined($run_type)) {
3216 $run_type = "ERROR";
3220 $installme = " no_install" if ($no_install);
3223 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3229 if (defined($addconfig)) {
3230 my $min = $minconfig;
3231 if (!defined($minconfig)) {
3234 run_command "cat $addconfig $min > $tmpdir/add_config" or
3235 dodie "Failed to create temp config";
3236 $minconfig = "$tmpdir/add_config";
3239 my $checkout = $opt{"CHECKOUT[$i]"};
3240 if (defined($checkout)) {
3241 run_command "git checkout $checkout" or
3242 die "failed to checkout $checkout";
3248 if ($test_type eq "bisect") {
3251 } elsif ($test_type eq "config_bisect") {
3254 } elsif ($test_type eq "patchcheck") {
3257 } elsif ($test_type eq "make_min_config") {
3262 if ($build_type ne "nobuild") {
3263 build $build_type or next;
3266 if ($test_type eq "install") {
3273 if ($test_type ne "build") {
3275 start_monitor_and_boot or $failed = 1;
3277 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3278 do_run_test or $failed = 1;
3287 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3289 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
3293 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";