3 # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4 # Licensed under the terms of the GNU GPL License version 2
9 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
10 use File::Path qw(mkpath);
11 use File::Copy qw(cp);
24 $default{"NUM_TESTS"} = 1;
25 $default{"REBOOT_TYPE"} = "grub";
26 $default{"TEST_TYPE"} = "test";
27 $default{"BUILD_TYPE"} = "randconfig";
28 $default{"MAKE_CMD"} = "make";
29 $default{"TIMEOUT"} = 120;
30 $default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
31 $default{"SLEEP_TIME"} = 60; # sleep time between tests
32 $default{"BUILD_NOCLEAN"} = 0;
33 $default{"REBOOT_ON_ERROR"} = 0;
34 $default{"POWEROFF_ON_ERROR"} = 0;
35 $default{"REBOOT_ON_SUCCESS"} = 1;
36 $default{"POWEROFF_ON_SUCCESS"} = 0;
37 $default{"BUILD_OPTIONS"} = "";
38 $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
39 $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
40 $default{"CLEAR_LOG"} = 0;
41 $default{"BISECT_MANUAL"} = 0;
42 $default{"BISECT_SKIP"} = 1;
43 $default{"SUCCESS_LINE"} = "login:";
44 $default{"DETECT_TRIPLE_FAULT"} = 1;
45 $default{"NO_INSTALL"} = 0;
46 $default{"BOOTED_TIMEOUT"} = 1;
47 $default{"DIE_ON_FAILURE"} = 1;
48 $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
49 $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
50 $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
51 $default{"STOP_AFTER_SUCCESS"} = 10;
52 $default{"STOP_AFTER_FAILURE"} = 60;
53 $default{"STOP_TEST_AFTER"} = 600;
54 $default{"LOCALVERSION"} = "-test";
76 my $poweroff_on_error;
78 my $powercycle_after_reboot;
79 my $poweroff_after_halt;
92 my $start_minconfig_defined;
101 my $config_bisect_good;
102 my $in_patchcheck = 0;
111 my $bisect_sleep_time;
112 my $patchcheck_sleep_time;
118 my $detect_triplefault;
120 my $reboot_success_line;
122 my $stop_after_success;
123 my $stop_after_failure;
136 # do not force reboots on config problems
139 $config_help{"MACHINE"} = << "EOF"
140 The machine hostname that you will test.
143 $config_help{"SSH_USER"} = << "EOF"
144 The box is expected to have ssh on normal bootup, provide the user
145 (most likely root, since you need privileged operations)
148 $config_help{"BUILD_DIR"} = << "EOF"
149 The directory that contains the Linux source code (full path).
152 $config_help{"OUTPUT_DIR"} = << "EOF"
153 The directory that the objects will be built (full path).
154 (can not be same as BUILD_DIR)
157 $config_help{"BUILD_TARGET"} = << "EOF"
158 The location of the compiled file to copy to the target.
159 (relative to OUTPUT_DIR)
162 $config_help{"TARGET_IMAGE"} = << "EOF"
163 The place to put your image on the test machine.
166 $config_help{"POWER_CYCLE"} = << "EOF"
167 A script or command to reboot the box.
169 Here is a digital loggers power switch example
170 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
172 Here is an example to reboot a virtual box on the current host
173 with the name "Guest".
174 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
177 $config_help{"CONSOLE"} = << "EOF"
178 The script or command that reads the console
180 If you use ttywatch server, something like the following would work.
181 CONSOLE = nc -d localhost 3001
183 For a virtual machine with guest name "Guest".
184 CONSOLE = virsh console Guest
187 $config_help{"LOCALVERSION"} = << "EOF"
188 Required version ending to differentiate the test
189 from other linux builds on the system.
192 $config_help{"REBOOT_TYPE"} = << "EOF"
193 Way to reboot the box to the test kernel.
194 Only valid options so far are "grub" and "script".
196 If you specify grub, it will assume grub version 1
197 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
198 and select that target to reboot to the kernel. If this is not
199 your setup, then specify "script" and have a command or script
200 specified in REBOOT_SCRIPT to boot to the target.
202 The entry in /boot/grub/menu.lst must be entered in manually.
203 The test will not modify that file.
206 $config_help{"GRUB_MENU"} = << "EOF"
207 The grub title name for the test kernel to boot
208 (Only mandatory if REBOOT_TYPE = grub)
210 Note, ktest.pl will not update the grub menu.lst, you need to
211 manually add an option for the test. ktest.pl will search
212 the grub menu.lst for this option to find what kernel to
215 For example, if in the /boot/grub/menu.lst the test kernel title has:
218 GRUB_MENU = Test Kernel
221 $config_help{"REBOOT_SCRIPT"} = << "EOF"
222 A script to reboot the target into the test kernel
223 (Only mandatory if REBOOT_TYPE = script)
233 print "$prompt [Y/n] ";
236 if ($ans =~ /^\s*$/) {
239 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
240 print "Please answer either 'y' or 'n'.\n";
242 if ($ans !~ /^y$/i) {
248 sub get_ktest_config {
251 return if (defined($opt{$config}));
253 if (defined($config_help{$config})) {
255 print $config_help{$config};
260 if (defined($default{$config})) {
261 print "\[$default{$config}\] ";
263 $entered_configs{$config} = <STDIN>;
264 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
265 if ($entered_configs{$config} =~ /^\s*$/) {
266 if ($default{$config}) {
267 $entered_configs{$config} = $default{$config};
269 print "Your answer can not be blank\n";
277 sub get_ktest_configs {
278 get_ktest_config("MACHINE");
279 get_ktest_config("SSH_USER");
280 get_ktest_config("BUILD_DIR");
281 get_ktest_config("OUTPUT_DIR");
282 get_ktest_config("BUILD_TARGET");
283 get_ktest_config("TARGET_IMAGE");
284 get_ktest_config("POWER_CYCLE");
285 get_ktest_config("CONSOLE");
286 get_ktest_config("LOCALVERSION");
288 my $rtype = $opt{"REBOOT_TYPE"};
290 if (!defined($rtype)) {
291 if (!defined($opt{"GRUB_MENU"})) {
292 get_ktest_config("REBOOT_TYPE");
293 $rtype = $entered_configs{"REBOOT_TYPE"};
299 if ($rtype eq "grub") {
300 get_ktest_config("GRUB_MENU");
302 get_ktest_config("REBOOT_SCRIPT");
306 sub process_variables {
310 # We want to check for '\', and it is just easier
311 # to check the previous characet of '$' and not need
312 # to worry if '$' is the first character. By adding
313 # a space to $value, we can just check [^\\]\$ and
314 # it will still work.
317 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
321 # append beginning of value to retval
322 $retval = "$retval$begin";
323 if (defined($variable{$var})) {
324 $retval = "$retval$variable{$var}";
326 # put back the origin piece.
327 $retval = "$retval\$\{$var\}";
331 $retval = "$retval$value";
333 # remove the space added in the beginning
340 my ($lvalue, $rvalue) = @_;
342 if (defined($opt{$lvalue})) {
343 die "Error: Option $lvalue defined more than once!\n";
345 if ($rvalue =~ /^\s*$/) {
346 delete $opt{$lvalue};
348 $rvalue = process_variables($rvalue);
349 $opt{$lvalue} = $rvalue;
354 my ($lvalue, $rvalue) = @_;
356 if ($rvalue =~ /^\s*$/) {
357 delete $variable{$lvalue};
359 $rvalue = process_variables($rvalue);
360 $variable{$lvalue} = $rvalue;
364 sub process_compare {
365 my ($lval, $cmp, $rval) = @_;
376 return $lval eq $rval;
377 } elsif ($cmp eq "!=") {
378 return $lval ne $rval;
381 my $statement = "$lval $cmp $rval";
382 my $ret = eval $statement;
384 # $@ stores error of eval
393 my ($name, $value) = @_;
395 my $val = process_variables($value);
397 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
398 my $ret = process_compare($1, $2, $3);
400 die "$name: $.: Unable to process comparison\n";
405 if ($val =~ /^\s*0\s*$/) {
407 } elsif ($val =~ /^\s*\d+\s*$/) {
411 die ("$name: $.: Undefined variable $val in if statement\n");
416 my ($config, $current_test_num) = @_;
419 open($in, $config) || die "can't read file $config";
422 $name =~ s,.*/(.*),$1,;
424 my $test_num = $$current_test_num;
427 my $num_tests_set = 0;
436 # ignore blank lines and comments
437 next if (/^\s*$/ || /\s*\#/);
439 if (/^\s*TEST_START(.*)/) {
443 if ($num_tests_set) {
444 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
447 my $old_test_num = $test_num;
448 my $old_repeat = $repeat;
450 $test_num += $repeat;
454 if ($rest =~ /\s+SKIP\b(.*)/) {
462 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
465 $repeat_tests{"$test_num"} = $repeat;
468 if ($rest =~ /\sIF\s+(.*)/) {
470 if (process_if($name, $1)) {
480 if ($rest !~ /^\s*$/) {
481 die "$name: $.: Gargbage found after TEST_START\n$_";
485 $test_num = $old_test_num;
486 $repeat = $old_repeat;
489 } elsif (/^\s*DEFAULTS(.*)$/) {
494 if ($rest =~ /\s+SKIP(.*)/) {
501 if ($rest =~ /\sIF\s+(.*)/) {
503 if (process_if($name, $1)) {
513 if ($rest !~ /^\s*$/) {
514 die "$name: $.: Gargbage found after DEFAULTS\n$_";
517 } elsif (/^\s*ELSE\b(.*)$/) {
519 die "$name: $.: ELSE found with out matching IF section\n$_";
528 if ($rest =~ /\sIF\s+(.*)/) {
529 # May be a ELSE IF section.
530 if (!process_if($name, $1)) {
539 if ($rest !~ /^\s*$/) {
540 die "$name: $.: Gargbage found after DEFAULTS\n$_";
543 } elsif (/^\s*INCLUDE\s+(\S+)/) {
548 die "$name: $.: INCLUDE can only be done in default sections\n$_";
551 my $file = process_variables($1);
553 if ($file !~ m,^/,) {
554 # check the path of the config file first
555 if ($config =~ m,(.*)/,) {
563 die "$name: $.: Can't read file $file\n$_";
566 if (__read_config($file, \$test_num)) {
570 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
578 ($lvalue eq "NUM_TESTS" ||
579 $lvalue eq "LOG_FILE" ||
580 $lvalue eq "CLEAR_LOG")) {
581 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
584 if ($lvalue eq "NUM_TESTS") {
586 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
589 die "$name: $.: NUM_TESTS must be set in default section\n";
594 if ($default || $lvalue =~ /\[\d+\]$/) {
595 set_value($lvalue, $rvalue);
597 my $val = "$lvalue\[$test_num\]";
598 set_value($val, $rvalue);
601 $repeats{$val} = $repeat;
604 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
610 # process config variables.
611 # Config variables are only active while reading the
612 # config and can be defined anywhere. They also ignore
613 # TEST_START and DEFAULTS, but are skipped if they are in
614 # on of these sections that have SKIP defined.
615 # The save variable can be
616 # defined multiple times and the new one simply overrides
618 set_variable($lvalue, $rvalue);
621 die "$name: $.: Garbage found in config\n$_";
626 $test_num += $repeat - 1;
627 $opt{"NUM_TESTS"} = $test_num;
632 $$current_test_num = $test_num;
643 $test_case = __read_config $config, \$test_num;
645 # make sure we have all mandatory configs
648 # was a test specified?
650 print "No test case specified.\n";
651 print "What test case would you like to run?\n";
654 $default{"TEST_TYPE"} = $ans;
659 foreach my $default (keys %default) {
660 if (!defined($opt{$default})) {
661 $opt{$default} = $default{$default};
667 my ($option, $i) = @_;
669 # Add space to evaluate the character before $
670 $option = " $option";
673 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
678 # Append beginning of line
679 $retval = "$retval$start";
681 # If the iteration option OPT[$i] exists, then use that.
682 # otherwise see if the default OPT (without [$i]) exists.
684 my $o = "$var\[$i\]";
686 if (defined($opt{$o})) {
688 $retval = "$retval$o";
689 } elsif (defined($opt{$var})) {
691 $retval = "$retval$o";
693 $retval = "$retval\$\{$var\}";
699 $retval = "$retval$option";
707 my ($option, $i) = @_;
711 # Since an option can evaluate to another option,
712 # keep iterating until we do not evaluate any more
715 while ($prev ne $option) {
716 # Check for recursive evaluations.
717 # 100 deep should be more than enough.
719 die "Over 100 evaluations accurred with $option\n" .
720 "Check for recursive variables\n";
723 $option = __eval_option($option, $i);
730 if (defined($opt{"LOG_FILE"})) {
731 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
738 if (defined($opt{"LOG_FILE"})) {
753 sub wait_for_monitor;
758 if (defined($time)) {
760 # flush out current monitor
761 # May contain the reboot success line
765 # try to reboot normally
766 if (run_command $reboot) {
767 if (defined($powercycle_after_reboot)) {
768 sleep $powercycle_after_reboot;
769 run_command "$power_cycle";
772 # nope? power cycle it.
773 run_command "$power_cycle";
776 if (defined($time)) {
777 wait_for_monitor($time, $reboot_success_line);
785 return $test_type eq "build" || $no_reboot ||
786 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
787 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
791 doprint "CRITICAL FAILURE... ", @_, "\n";
795 if ($reboot_on_error && !do_not_reboot) {
797 doprint "REBOOTING\n";
800 } elsif ($poweroff_on_error && defined($power_off)) {
801 doprint "POWERING OFF\n";
805 if (defined($opt{"LOG_FILE"})) {
806 print " See $opt{LOG_FILE} for more info.\n";
817 my $pid = open($fp, "$console|") or
818 dodie "Can't open console $console";
820 $flags = fcntl($fp, F_GETFL, 0) or
821 dodie "Can't get flags for the socket: $!";
822 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
823 dodie "Can't set flags for the socket: $!";
831 doprint "kill child process $pid\n";
839 if ($monitor_cnt++) {
842 $monitor_fp = \*MONFD;
843 $monitor_pid = open_console $monitor_fp;
847 open(MONFD, "Stop perl from warning about single use of MONFD");
851 if (--$monitor_cnt) {
854 close_console($monitor_fp, $monitor_pid);
857 sub wait_for_monitor {
858 my ($time, $stop) = @_;
863 doprint "** Wait for monitor to settle down **\n";
865 # read the monitor and wait for the system to calm down
867 $line = wait_for_input($monitor_fp, $time);
868 last if (!defined($line));
872 if (defined($stop) && $full_line =~ /$stop/) {
873 doprint "wait for monitor detected $stop\n";
881 print "** Monitor flushed **\n";
886 if ($die_on_failure) {
894 # no need to reboot for just building.
895 if (!do_not_reboot) {
896 doprint "REBOOTING\n";
902 if (defined($test_name)) {
903 $name = " ($test_name)";
906 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
907 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
908 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
909 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
910 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
912 return 1 if (!defined($store_failures));
915 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
916 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
918 my $type = $build_type;
919 if ($type =~ /useconfig/) {
923 my $dir = "$machine-$test_type-$type-fail-$date";
924 my $faildir = "$store_failures/$dir";
928 die "can't create $faildir";
930 if (-f "$output_config") {
931 cp "$output_config", "$faildir/config" or
932 die "failed to copy .config";
935 cp $buildlog, "$faildir/buildlog" or
936 die "failed to move $buildlog";
939 cp $dmesg, "$faildir/dmesg" or
940 die "failed to move $dmesg";
943 doprint "*** Saved info to $faildir ***\n";
954 $command =~ s/\$SSH_USER/$ssh_user/g;
955 $command =~ s/\$MACHINE/$machine/g;
957 doprint("$command ... ");
959 $pid = open(CMD, "$command 2>&1 |") or
960 (fail "unable to exec $command" and return 0);
962 if (defined($opt{"LOG_FILE"})) {
963 open(LOG, ">>$opt{LOG_FILE}") or
964 dodie "failed to write to log";
968 if (defined($redirect)) {
969 open (RD, ">$redirect") or
970 dodie "failed to write to redirect $redirect";
975 print LOG if ($dolog);
983 close(LOG) if ($dolog);
984 close(RD) if ($dord);
997 my $cp_exec = $ssh_exec;
999 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1000 return run_command "$cp_exec";
1004 my ($src, $dst) = @_;
1005 my $cp_scp = $scp_to_target;
1007 $cp_scp =~ s/\$SRC_FILE/$src/g;
1008 $cp_scp =~ s/\$DST_FILE/$dst/g;
1010 return run_command "$cp_scp";
1013 sub get_grub_index {
1015 if ($reboot_type ne "grub") {
1018 return if (defined($grub_number));
1020 doprint "Find grub menu ... ";
1023 my $ssh_grub = $ssh_exec;
1024 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1026 open(IN, "$ssh_grub |")
1027 or die "unable to get menu.lst";
1032 if (/^\s*title\s+$grub_menu\s*$/) {
1036 } elsif (/^\s*title\s/) {
1042 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1044 doprint "$grub_number\n";
1049 my ($fp, $time) = @_;
1055 if (!defined($time)) {
1060 vec($rin, fileno($fp), 1) = 1;
1061 $ready = select($rin, undef, undef, $time);
1065 # try to read one char at a time
1066 while (sysread $fp, $ch, 1) {
1068 last if ($ch eq "\n");
1071 if (!length($line)) {
1079 if ($reboot_type eq "grub") {
1080 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
1084 run_command "$reboot_script";
1090 doprint "git rev-list --max-count=1 $commit ... ";
1091 my $sha1 = `git rev-list --max-count=1 $commit`;
1098 dodie "Failed to get git $commit";
1111 my $skip_call_trace = 0;
1119 open(DMESG, "> $dmesg") or
1120 die "unable to write to $dmesg";
1126 my $monitor_start = time;
1128 my $version_found = 0;
1132 if ($bug && defined($stop_after_failure) &&
1133 $stop_after_failure >= 0) {
1134 my $time = $stop_after_failure - (time - $failure_start);
1135 $line = wait_for_input($monitor_fp, $time);
1136 if (!defined($line)) {
1137 doprint "bug timed out after $booted_timeout seconds\n";
1138 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1142 $line = wait_for_input($monitor_fp, $booted_timeout);
1143 if (!defined($line)) {
1144 my $s = $booted_timeout == 1 ? "" : "s";
1145 doprint "Successful boot found: break after $booted_timeout second$s\n";
1149 $line = wait_for_input($monitor_fp);
1150 if (!defined($line)) {
1151 my $s = $timeout == 1 ? "" : "s";
1152 doprint "Timed out after $timeout second$s\n";
1160 # we are not guaranteed to get a full line
1161 $full_line .= $line;
1163 if ($full_line =~ /$success_line/) {
1165 $success_start = time;
1168 if ($booted && defined($stop_after_success) &&
1169 $stop_after_success >= 0) {
1171 if ($now - $success_start >= $stop_after_success) {
1172 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1177 if ($full_line =~ /\[ backtrace testing \]/) {
1178 $skip_call_trace = 1;
1181 if ($full_line =~ /call trace:/i) {
1182 if (!$bug && !$skip_call_trace) {
1184 $failure_start = time;
1188 if ($bug && defined($stop_after_failure) &&
1189 $stop_after_failure >= 0) {
1191 if ($now - $failure_start >= $stop_after_failure) {
1192 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1197 if ($full_line =~ /\[ end of backtrace testing \]/) {
1198 $skip_call_trace = 0;
1201 if ($full_line =~ /Kernel panic -/) {
1202 $failure_start = time;
1206 # Detect triple faults by testing the banner
1207 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1208 if ($1 eq $version) {
1210 } elsif ($version_found && $detect_triplefault) {
1211 # We already booted into the kernel we are testing,
1212 # but now we booted into another kernel?
1213 # Consider this a triple fault.
1214 doprint "Aleady booted in Linux kernel $version, but now\n";
1215 doprint "we booted into Linux kernel $1.\n";
1216 doprint "Assuming that this is a triple fault.\n";
1217 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1222 if ($line =~ /\n/) {
1226 if ($stop_test_after > 0 && !$booted && !$bug) {
1227 if (time - $monitor_start > $stop_test_after) {
1228 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1237 return 0 if ($in_bisect);
1238 fail "failed - got a bug report" and return 0;
1242 return 0 if ($in_bisect);
1243 fail "failed - never got a boot prompt." and return 0;
1249 sub do_post_install {
1251 return if (!defined($post_install));
1253 my $cp_post_install = $post_install;
1254 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1255 run_command "$cp_post_install" or
1256 dodie "Failed to run post install";
1261 return if ($no_install);
1263 run_scp "$outputdir/$build_target", "$target_image" or
1264 dodie "failed to copy image";
1266 my $install_mods = 0;
1268 # should we process modules?
1270 open(IN, "$output_config") or dodie("Can't read config file");
1272 if (/CONFIG_MODULES(=y)?/) {
1273 $install_mods = 1 if (defined($1));
1279 if (!$install_mods) {
1281 doprint "No modules needed\n";
1285 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
1286 dodie "Failed to install modules";
1288 my $modlib = "/lib/modules/$version";
1289 my $modtar = "ktest-mods.tar.bz2";
1291 run_ssh "rm -rf $modlib" or
1292 dodie "failed to remove old mods: $modlib";
1294 # would be nice if scp -r did not follow symbolic links
1295 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1296 dodie "making tarball";
1298 run_scp "$tmpdir/$modtar", "/tmp" or
1299 dodie "failed to copy modules";
1301 unlink "$tmpdir/$modtar";
1303 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1304 dodie "failed to tar modules";
1306 run_ssh "rm -f /tmp/$modtar";
1312 # get the release name
1313 doprint "$make kernelrelease ... ";
1314 $version = `$make kernelrelease | tail -1`;
1316 doprint "$version\n";
1319 sub start_monitor_and_boot {
1328 sub check_buildlog {
1331 my @files = `git show $patch | diffstat -l`;
1333 open(IN, "git show $patch |") or
1334 dodie "failed to show $patch";
1336 if (m,^--- a/(.*),) {
1338 $files[$#files] = $1;
1343 open(IN, $buildlog) or dodie "Can't open $buildlog";
1345 if (/^\s*(.*?):.*(warning|error)/) {
1347 foreach my $file (@files) {
1348 my $fullpath = "$builddir/$file";
1349 if ($file eq $err || $fullpath eq $err) {
1350 fail "$file built with warnings" and return 0;
1360 sub apply_min_config {
1361 my $outconfig = "$output_config.new";
1363 # Read the config file and remove anything that
1364 # is in the force_config hash (from minconfig and others)
1365 # then add the force config back.
1367 doprint "Applying minimum configurations into $output_config.new\n";
1369 open (OUT, ">$outconfig") or
1370 dodie "Can't create $outconfig";
1372 if (-f $output_config) {
1373 open (IN, $output_config) or
1374 dodie "Failed to open $output_config";
1376 if (/^(# )?(CONFIG_[^\s=]*)/) {
1377 next if (defined($force_config{$2}));
1383 foreach my $config (keys %force_config) {
1384 print OUT "$force_config{$config}\n";
1388 run_command "mv $outconfig $output_config";
1391 sub make_oldconfig {
1393 my @force_list = keys %force_config;
1395 if ($#force_list >= 0) {
1399 if (!run_command "$make oldnoconfig") {
1400 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1401 # try a yes '' | oldconfig
1402 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1403 run_command "yes '' | $make oldconfig" or
1404 dodie "failed make config oldconfig";
1408 # read a config file and use this to force new configs.
1409 sub load_force_config {
1412 open(IN, $config) or
1413 dodie "failed to read $config";
1416 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1417 $force_config{$1} = $_;
1418 } elsif (/^# (CONFIG_\S*) is not set/) {
1419 $force_config{$1} = $_;
1430 # Failed builds should not reboot the target
1431 my $save_no_reboot = $no_reboot;
1434 if (defined($pre_build)) {
1435 my $ret = run_command $pre_build;
1436 if (!$ret && defined($pre_build_die) &&
1438 dodie "failed to pre_build\n";
1442 if ($type =~ /^useconfig:(.*)/) {
1443 run_command "cp $1 $output_config" or
1444 dodie "could not copy $1 to .config";
1446 $type = "oldconfig";
1449 # old config can ask questions
1450 if ($type eq "oldconfig") {
1451 $type = "oldnoconfig";
1453 # allow for empty configs
1454 run_command "touch $output_config";
1457 run_command "mv $output_config $outputdir/config_temp" or
1458 dodie "moving .config";
1460 run_command "$make mrproper" or dodie "make mrproper";
1462 run_command "mv $outputdir/config_temp $output_config" or
1463 dodie "moving config_temp";
1466 } elsif (!$noclean) {
1467 unlink "$output_config";
1468 run_command "$make mrproper" or
1469 dodie "make mrproper";
1472 # add something to distinguish this build
1473 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1474 print OUT "$localversion\n";
1477 if (defined($minconfig)) {
1478 load_force_config($minconfig);
1481 if ($type ne "oldnoconfig") {
1482 run_command "$make $type" or
1483 dodie "failed make config";
1485 # Run old config regardless, to enforce min configurations
1488 $redirect = "$buildlog";
1489 my $build_ret = run_command "$make $build_options";
1492 if (defined($post_build)) {
1493 my $ret = run_command $post_build;
1494 if (!$ret && defined($post_build_die) &&
1496 dodie "failed to post_build\n";
1501 # bisect may need this to pass
1503 $no_reboot = $save_no_reboot;
1506 fail "failed build" and return 0;
1509 $no_reboot = $save_no_reboot;
1515 if (!run_ssh "halt" or defined($power_off)) {
1516 if (defined($poweroff_after_halt)) {
1517 sleep $poweroff_after_halt;
1518 run_command "$power_off";
1522 run_command "$power_off";
1533 if (defined($test_name)) {
1534 $name = " ($test_name)";
1537 doprint "\n\n*******************************************\n";
1538 doprint "*******************************************\n";
1539 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1540 doprint "*******************************************\n";
1541 doprint "*******************************************\n";
1543 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1544 doprint "Reboot and wait $sleep_time seconds\n";
1551 doprint "Pass or fail? [p/f]";
1554 if ($ans eq "p" || $ans eq "P") {
1556 } elsif ($ans eq "f" || $ans eq "F") {
1559 print "Please answer 'P' or 'F'\n";
1564 sub child_run_test {
1567 # child should have no power
1568 $reboot_on_error = 0;
1569 $poweroff_on_error = 0;
1570 $die_on_failure = 1;
1572 run_command $run_test or $failed = 1;
1578 sub child_finished {
1591 doprint "run test $run_test\n";
1595 $SIG{CHLD} = qw(child_finished);
1599 child_run_test if (!$child_pid);
1604 $line = wait_for_input($monitor_fp, 1);
1605 if (defined($line)) {
1607 # we are not guaranteed to get a full line
1608 $full_line .= $line;
1611 if ($full_line =~ /call trace:/i) {
1615 if ($full_line =~ /Kernel panic -/) {
1619 if ($line =~ /\n/) {
1623 } while (!$child_done && !$bug);
1626 my $failure_start = time;
1629 $line = wait_for_input($monitor_fp, 1);
1630 if (defined($line)) {
1634 if ($now - $failure_start >= $stop_after_failure) {
1637 } while (defined($line));
1639 doprint "Detected kernel crash!\n";
1640 # kill the child with extreme prejudice
1644 waitpid $child_pid, 0;
1647 if ($bug || $child_exit) {
1648 return 0 if $in_bisect;
1649 fail "test failed" and return 0;
1654 sub run_git_bisect {
1657 doprint "$command ... ";
1659 my $output = `$command 2>&1`;
1666 dodie "Failed to git bisect";
1669 doprint "SUCCESS\n";
1670 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1671 doprint "$1 [$2]\n";
1672 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1674 doprint "Found bad commit... $1\n";
1677 # we already logged it, just print it now.
1685 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1686 reboot $bisect_sleep_time;
1689 # returns 1 on success, 0 on failure, -1 on skip
1690 sub run_bisect_test {
1691 my ($type, $buildtype) = @_;
1700 build $buildtype or $failed = 1;
1702 if ($type ne "build") {
1703 if ($failed && $bisect_skip) {
1707 dodie "Failed on build" if $failed;
1710 start_monitor_and_boot or $failed = 1;
1712 if ($type ne "boot") {
1713 if ($failed && $bisect_skip) {
1719 dodie "Failed on boot" if $failed;
1721 do_run_test or $failed = 1;
1732 # reboot the box to a kernel we can ssh to
1733 if ($type ne "build") {
1743 my $buildtype = "oldconfig";
1745 # We should have a minconfig to use?
1746 if (defined($minconfig)) {
1747 $buildtype = "useconfig:$minconfig";
1750 my $ret = run_bisect_test $type, $buildtype;
1752 if ($bisect_manual) {
1753 $ret = answer_bisect;
1756 # Are we looking for where it worked, not failed?
1757 if ($reverse_bisect) {
1763 } elsif ($ret == 0) {
1765 } elsif ($bisect_skip) {
1766 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1776 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1777 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1778 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1780 my $good = $opt{"BISECT_GOOD[$i]"};
1781 my $bad = $opt{"BISECT_BAD[$i]"};
1782 my $type = $opt{"BISECT_TYPE[$i]"};
1783 my $start = $opt{"BISECT_START[$i]"};
1784 my $replay = $opt{"BISECT_REPLAY[$i]"};
1785 my $start_files = $opt{"BISECT_FILES[$i]"};
1787 if (defined($start_files)) {
1788 $start_files = " -- " . $start_files;
1793 # convert to true sha1's
1794 $good = get_sha1($good);
1795 $bad = get_sha1($bad);
1797 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1798 $opt{"BISECT_REVERSE[$i]"} == 1) {
1799 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1800 $reverse_bisect = 1;
1802 $reverse_bisect = 0;
1805 # Can't have a test without having a test to run
1806 if ($type eq "test" && !defined($run_test)) {
1810 my $check = $opt{"BISECT_CHECK[$i]"};
1811 if (defined($check) && $check ne "0") {
1814 my $head = get_sha1("HEAD");
1816 if ($check ne "good") {
1817 doprint "TESTING BISECT BAD [$bad]\n";
1818 run_command "git checkout $bad" or
1819 die "Failed to checkout $bad";
1821 $result = run_bisect $type;
1823 if ($result ne "bad") {
1824 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1828 if ($check ne "bad") {
1829 doprint "TESTING BISECT GOOD [$good]\n";
1830 run_command "git checkout $good" or
1831 die "Failed to checkout $good";
1833 $result = run_bisect $type;
1835 if ($result ne "good") {
1836 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1840 # checkout where we started
1841 run_command "git checkout $head" or
1842 die "Failed to checkout $head";
1845 run_command "git bisect start$start_files" or
1846 dodie "could not start bisect";
1848 run_command "git bisect good $good" or
1849 dodie "could not set bisect good to $good";
1851 run_git_bisect "git bisect bad $bad" or
1852 dodie "could not set bisect bad to $bad";
1854 if (defined($replay)) {
1855 run_command "git bisect replay $replay" or
1856 dodie "failed to run replay";
1859 if (defined($start)) {
1860 run_command "git checkout $start" or
1861 dodie "failed to checkout $start";
1866 $result = run_bisect $type;
1867 $test = run_git_bisect "git bisect $result";
1870 run_command "git bisect log" or
1871 dodie "could not capture git bisect log";
1873 run_command "git bisect reset" or
1874 dodie "could not reset git bisect";
1876 doprint "Bad commit was [$bisect_bad]\n";
1889 sub assign_configs {
1890 my ($hash, $config) = @_;
1893 or dodie "Failed to read $config";
1896 if (/^((CONFIG\S*)=.*)/) {
1904 sub process_config_ignore {
1907 assign_configs \%config_ignore, $config;
1910 sub read_current_config {
1911 my ($config_ref) = @_;
1913 %{$config_ref} = ();
1914 undef %{$config_ref};
1916 my @key = keys %{$config_ref};
1918 print "did not delete!\n";
1921 open (IN, "$output_config");
1924 if (/^(CONFIG\S+)=(.*)/) {
1925 ${$config_ref}{$1} = $2;
1931 sub get_dependencies {
1934 my $arr = $dependency{$config};
1935 if (!defined($arr)) {
1941 foreach my $dep (@{$arr}) {
1942 print "ADD DEP $dep\n";
1943 @deps = (@deps, get_dependencies $dep);
1952 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1954 foreach my $config (@configs) {
1955 print OUT "$config_set{$config}\n";
1956 my @deps = get_dependencies $config;
1957 foreach my $dep (@deps) {
1958 print OUT "$config_set{$dep}\n";
1962 foreach my $config (keys %config_ignore) {
1963 print OUT "$config_ignore{$config}\n";
1971 sub compare_configs {
1974 foreach my $item (keys %a) {
1975 if (!defined($b{$item})) {
1976 print "diff $item\n";
1984 print "diff2 $keys[0]\n";
1986 return -1 if ($#keys >= 0);
1991 sub run_config_bisect_test {
1994 return run_bisect_test $type, "oldconfig";
1997 sub process_passed {
2000 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2001 # Passed! All these configs are part of a good compile.
2002 # Add them to the min options.
2003 foreach my $config (keys %configs) {
2004 if (defined($config_list{$config})) {
2005 doprint " removing $config\n";
2006 $config_ignore{$config} = $config_list{$config};
2007 delete $config_list{$config};
2010 doprint "config copied to $outputdir/config_good\n";
2011 run_command "cp -f $output_config $outputdir/config_good";
2014 sub process_failed {
2017 doprint "\n\n***************************************\n";
2018 doprint "Found bad config: $config\n";
2019 doprint "***************************************\n\n";
2022 sub run_config_bisect {
2024 my @start_list = keys %config_list;
2026 if ($#start_list < 0) {
2027 doprint "No more configs to test!!!\n";
2031 doprint "***** RUN TEST ***\n";
2032 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2036 my $count = $#start_list + 1;
2037 doprint " $count configs to test\n";
2039 my $half = int($#start_list / 2);
2042 my @tophalf = @start_list[0 .. $half];
2044 create_config @tophalf;
2045 read_current_config \%current_config;
2047 $count = $#tophalf + 1;
2048 doprint "Testing $count configs\n";
2050 # make sure we test something
2051 foreach my $config (@tophalf) {
2052 if (defined($current_config{$config})) {
2058 # try the other half
2059 doprint "Top half produced no set configs, trying bottom half\n";
2060 @tophalf = @start_list[$half + 1 .. $#start_list];
2061 create_config @tophalf;
2062 read_current_config \%current_config;
2063 foreach my $config (@tophalf) {
2064 if (defined($current_config{$config})) {
2070 doprint "Failed: Can't make new config with current configs\n";
2071 foreach my $config (@start_list) {
2072 doprint " CONFIG: $config\n";
2076 $count = $#tophalf + 1;
2077 doprint "Testing $count configs\n";
2080 $ret = run_config_bisect_test $type;
2081 if ($bisect_manual) {
2082 $ret = answer_bisect;
2085 process_passed %current_config;
2089 doprint "This config had a failure.\n";
2090 doprint "Removing these configs that were not set in this config:\n";
2091 doprint "config copied to $outputdir/config_bad\n";
2092 run_command "cp -f $output_config $outputdir/config_bad";
2094 # A config exists in this group that was bad.
2095 foreach my $config (keys %config_list) {
2096 if (!defined($current_config{$config})) {
2097 doprint " removing $config\n";
2098 delete $config_list{$config};
2102 @start_list = @tophalf;
2104 if ($#start_list == 0) {
2105 process_failed $start_list[0];
2109 # remove half the configs we are looking at and see if
2111 $half = int($#start_list / 2);
2112 } while ($#start_list > 0);
2114 # we found a single config, try it again unless we are running manually
2116 if ($bisect_manual) {
2117 process_failed $start_list[0];
2121 my @tophalf = @start_list[0 .. 0];
2123 $ret = run_config_bisect_test $type;
2125 process_passed %current_config;
2129 process_failed $start_list[0];
2136 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2138 my $tmpconfig = "$tmpdir/use_config";
2140 if (defined($config_bisect_good)) {
2141 process_config_ignore $config_bisect_good;
2144 # Make the file with the bad config and the min config
2145 if (defined($minconfig)) {
2146 # read the min config for things to ignore
2147 run_command "cp $minconfig $tmpconfig" or
2148 dodie "failed to copy $minconfig to $tmpconfig";
2153 if (-f $tmpconfig) {
2154 load_force_config($tmpconfig);
2155 process_config_ignore $tmpconfig;
2158 # now process the start config
2159 run_command "cp $start_config $output_config" or
2160 dodie "failed to copy $start_config to $output_config";
2162 # read directly what we want to check
2164 open (IN, $output_config)
2165 or dodie "faied to open $output_config";
2168 if (/^((CONFIG\S*)=.*)/) {
2169 $config_check{$2} = $1;
2174 # Now run oldconfig with the minconfig
2177 # check to see what we lost (or gained)
2178 open (IN, $output_config)
2179 or dodie "Failed to read $start_config";
2181 my %removed_configs;
2185 if (/^((CONFIG\S*)=.*)/) {
2186 # save off all options
2187 $config_set{$2} = $1;
2188 if (defined($config_check{$2})) {
2189 if (defined($config_ignore{$2})) {
2190 $removed_configs{$2} = $1;
2192 $config_list{$2} = $1;
2194 } elsif (!defined($config_ignore{$2})) {
2195 $added_configs{$2} = $1;
2196 $config_list{$2} = $1;
2202 my @confs = keys %removed_configs;
2204 doprint "Configs overridden by default configs and removed from check:\n";
2205 foreach my $config (@confs) {
2206 doprint " $config\n";
2209 @confs = keys %added_configs;
2211 doprint "Configs appearing in make oldconfig and added:\n";
2212 foreach my $config (@confs) {
2213 doprint " $config\n";
2220 # Sometimes kconfig does weird things. We must make sure
2221 # that the config we autocreate has everything we need
2222 # to test, otherwise we may miss testing configs, or
2223 # may not be able to create a new config.
2224 # Here we create a config with everything set.
2225 create_config (keys %config_list);
2226 read_current_config \%config_test;
2227 foreach my $config (keys %config_list) {
2228 if (!defined($config_test{$config})) {
2231 doprint "Configs not produced by kconfig (will not be checked):\n";
2233 doprint " $config\n";
2234 delete $config_list{$config};
2239 $ret = run_config_bisect;
2242 return $ret if ($ret < 0);
2247 sub patchcheck_reboot {
2248 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2249 reboot $patchcheck_sleep_time;
2255 die "PATCHCHECK_START[$i] not defined\n"
2256 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2257 die "PATCHCHECK_TYPE[$i] not defined\n"
2258 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2260 my $start = $opt{"PATCHCHECK_START[$i]"};
2263 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2264 $end = $opt{"PATCHCHECK_END[$i]"};
2267 # Get the true sha1's since we can use things like HEAD~3
2268 $start = get_sha1($start);
2269 $end = get_sha1($end);
2271 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2273 # Can't have a test without having a test to run
2274 if ($type eq "test" && !defined($run_test)) {
2278 open (IN, "git log --pretty=oneline $end|") or
2279 dodie "could not get git list";
2285 $list[$#list+1] = $_;
2286 last if (/^$start/);
2290 if ($list[$#list] !~ /^$start/) {
2291 fail "SHA1 $start not found";
2294 # go backwards in the list
2295 @list = reverse @list;
2297 my $save_clean = $noclean;
2298 my %ignored_warnings;
2300 if (defined($ignore_warnings)) {
2301 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2302 $ignored_warnings{$sha1} = 1;
2307 foreach my $item (@list) {
2309 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2311 doprint "\nProcessing commit $item\n\n";
2313 run_command "git checkout $sha1" or
2314 die "Failed to checkout $sha1";
2316 # only clean on the first and last patch
2317 if ($item eq $list[0] ||
2318 $item eq $list[$#list]) {
2319 $noclean = $save_clean;
2324 if (defined($minconfig)) {
2325 build "useconfig:$minconfig" or return 0;
2327 # ?? no config to use?
2328 build "oldconfig" or return 0;
2332 if (!defined($ignored_warnings{$sha1})) {
2333 check_buildlog $sha1 or return 0;
2336 next if ($type eq "build");
2340 start_monitor_and_boot or $failed = 1;
2342 if (!$failed && $type ne "boot"){
2343 do_run_test or $failed = 1;
2346 return 0 if ($failed);
2364 # taken from streamline_config.pl
2376 if (! -f $kconfig) {
2377 doprint "file $kconfig does not exist, skipping\n";
2381 open(KIN, "$kconfig")
2382 or die "Can't open $kconfig";
2386 # Make sure that lines ending with \ continue
2388 $_ = $line . " " . $_;
2399 # collect any Kconfig sources
2400 if (/^source\s*"(.*)"/) {
2401 $kconfigs[$#kconfigs+1] = $1;
2405 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2409 for (my $i = 0; $i < $iflevel; $i++) {
2411 $depends{$config} .= " " . $ifdeps[$i];
2413 $depends{$config} = $ifdeps[$i];
2418 # collect the depends for the config
2419 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2421 if (defined($depends{$1})) {
2422 $depends{$config} .= " " . $1;
2424 $depends{$config} = $1;
2427 # Get the configs that select this config
2428 } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
2429 if (defined($depends{$1})) {
2430 $depends{$1} .= " " . $config;
2432 $depends{$1} = $config;
2435 # Check for if statements
2436 } elsif (/^if\s+(.*\S)\s*$/) {
2438 # remove beginning and ending non text
2439 $deps =~ s/^[^a-zA-Z0-9_]*//;
2440 $deps =~ s/[^a-zA-Z0-9_]*$//;
2442 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2444 $ifdeps[$iflevel++] = join ':', @deps;
2446 } elsif (/^endif/) {
2448 $iflevel-- if ($iflevel);
2451 } elsif (/^\s*help\s*$/) {
2457 # read in any configs that were found.
2458 foreach $kconfig (@kconfigs) {
2459 if (!defined($read_kconfigs{$kconfig})) {
2460 $read_kconfigs{$kconfig} = 1;
2461 read_kconfig("$builddir/$kconfig");
2467 # find out which arch this is by the kconfig file
2468 open (IN, $output_config)
2469 or dodie "Failed to read $output_config";
2472 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2479 if (!defined($arch)) {
2480 doprint "Could not find arch from config file\n";
2481 doprint "no dependencies used\n";
2485 # arch is really the subarch, we need to know
2486 # what directory to look at.
2487 if ($arch eq "i386" || $arch eq "x86_64") {
2489 } elsif ($arch =~ /^tile/) {
2493 my $kconfig = "$builddir/arch/$arch/Kconfig";
2495 if (! -f $kconfig && $arch =~ /\d$/) {
2497 # some subarchs have numbers, truncate them
2499 $kconfig = "$builddir/arch/$arch/Kconfig";
2500 if (! -f $kconfig) {
2501 doprint "No idea what arch dir $orig is for\n";
2502 doprint "no dependencies used\n";
2507 read_kconfig($kconfig);
2510 sub read_config_list {
2514 or dodie "Failed to read $config";
2517 if (/^((CONFIG\S*)=.*)/) {
2518 if (!defined($config_ignore{$2})) {
2519 $config_list{$2} = $1;
2527 sub read_output_config {
2530 assign_configs \%config_ignore, $config;
2533 sub make_new_config {
2536 open (OUT, ">$output_config")
2537 or dodie "Failed to write $output_config";
2539 foreach my $config (@configs) {
2540 print OUT "$config\n";
2549 $kconfig =~ s/CONFIG_//;
2551 $dep = $depends{"$kconfig"};
2553 # the dep string we have saves the dependencies as they
2554 # were found, including expressions like ! && ||. We
2555 # want to split this out into just an array of configs.
2557 my $valid = "A-Za-z_0-9";
2561 while ($dep =~ /[$valid]/) {
2563 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2564 my $conf = "CONFIG_" . $1;
2566 $configs[$#configs + 1] = $conf;
2568 $dep =~ s/^[^$valid]*[$valid]+//;
2570 die "this should never happen";
2580 my %processed_configs;
2581 my %nochange_config;
2583 sub test_this_config {
2588 # if we already processed this config, skip it
2589 if (defined($processed_configs{$config})) {
2592 $processed_configs{$config} = 1;
2594 # if this config failed during this round, skip it
2595 if (defined($nochange_config{$config})) {
2599 my $kconfig = $config;
2600 $kconfig =~ s/CONFIG_//;
2602 # Test dependencies first
2603 if (defined($depends{"$kconfig"})) {
2604 my @parents = get_depends $config;
2605 foreach my $parent (@parents) {
2606 # if the parent is in the min config, check it first
2607 next if (!defined($min_configs{$parent}));
2608 $found = test_this_config($parent);
2609 if (defined($found)) {
2615 # Remove this config from the list of configs
2616 # do a make oldnoconfig and then read the resulting
2617 # .config to make sure it is missing the config that
2619 my %configs = %min_configs;
2620 delete $configs{$config};
2621 make_new_config ((values %configs), (values %keep_configs));
2624 assign_configs \%configs, $output_config;
2626 return $config if (!defined($configs{$config}));
2628 doprint "disabling config $config did not change .config\n";
2630 $nochange_config{$config} = 1;
2635 sub make_min_config {
2638 if (!defined($output_minconfig)) {
2639 fail "OUTPUT_MIN_CONFIG not defined" and return;
2642 # If output_minconfig exists, and the start_minconfig
2643 # came from min_config, than ask if we should use
2645 if (-f $output_minconfig && !$start_minconfig_defined) {
2646 print "$output_minconfig exists\n";
2647 if (read_yn " Use it as minconfig?") {
2648 $start_minconfig = $output_minconfig;
2652 if (!defined($start_minconfig)) {
2653 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2656 my $temp_config = "$tmpdir/temp_config";
2658 # First things first. We build an allnoconfig to find
2659 # out what the defaults are that we can't touch.
2660 # Some are selections, but we really can't handle selections.
2662 my $save_minconfig = $minconfig;
2665 run_command "$make allnoconfig" or return 0;
2669 process_config_ignore $output_config;
2671 undef %save_configs;
2674 if (defined($ignore_config)) {
2675 # make sure the file exists
2676 `touch $ignore_config`;
2677 assign_configs \%save_configs, $ignore_config;
2680 %keep_configs = %save_configs;
2682 doprint "Load initial configs from $start_minconfig\n";
2684 # Look at the current min configs, and save off all the
2685 # ones that were set via the allnoconfig
2686 assign_configs \%min_configs, $start_minconfig;
2688 my @config_keys = keys %min_configs;
2690 # Remove anything that was set by the make allnoconfig
2691 # we shouldn't need them as they get set for us anyway.
2692 foreach my $config (@config_keys) {
2693 # Remove anything in the ignore_config
2694 if (defined($keep_configs{$config})) {
2695 my $file = $ignore_config;
2696 $file =~ s,.*/(.*?)$,$1,;
2697 doprint "$config set by $file ... ignored\n";
2698 delete $min_configs{$config};
2701 # But make sure the settings are the same. If a min config
2702 # sets a selection, we do not want to get rid of it if
2703 # it is not the same as what we have. Just move it into
2705 if (defined($config_ignore{$config})) {
2706 if ($config_ignore{$config} ne $min_configs{$config}) {
2707 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2708 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2709 $keep_configs{$config} = $min_configs{$config};
2711 doprint "$config set by allnoconfig ... ignored\n";
2713 delete $min_configs{$config};
2725 # Now disable each config one by one and do a make oldconfig
2726 # till we find a config that changes our list.
2728 # Put configs that did not modify the config at the end.
2729 my @test_configs = keys %min_configs;
2731 for (my $i = 0; $i < $#test_configs; $i++) {
2732 if (!defined($nochange_config{$test_configs[0]})) {
2736 # This config didn't change the .config last time.
2737 # Place it at the end
2738 my $config = shift @test_configs;
2739 push @test_configs, $config;
2742 # if every test config has failed to modify the .config file
2743 # in the past, then reset and start over.
2745 undef %nochange_config;
2748 undef %processed_configs;
2750 foreach my $config (@test_configs) {
2752 $found = test_this_config $config;
2754 last if (defined($found));
2756 # oh well, try another config
2759 if (!defined($found)) {
2760 # we could have failed due to the nochange_config hash
2761 # reset and try again
2763 undef %nochange_config;
2767 doprint "No more configs found that we can disable\n";
2775 doprint "Test with $config disabled\n";
2777 # set in_bisect to keep build and monitor from dieing
2782 start_monitor_and_boot or $failed = 1;
2788 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
2789 # this config is needed, add it to the ignore list.
2790 $keep_configs{$config} = $min_configs{$config};
2791 $save_configs{$config} = $min_configs{$config};
2792 delete $min_configs{$config};
2794 # update new ignore configs
2795 if (defined($ignore_config)) {
2796 open (OUT, ">$temp_config")
2797 or die "Can't write to $temp_config";
2798 foreach my $config (keys %save_configs) {
2799 print OUT "$save_configs{$config}\n";
2802 run_command "mv $temp_config $ignore_config" or
2803 dodie "failed to copy update to $ignore_config";
2807 # We booted without this config, remove it from the minconfigs.
2808 doprint "$config is not needed, disabling\n";
2810 delete $min_configs{$config};
2812 # Also disable anything that is not enabled in this config
2814 assign_configs \%configs, $output_config;
2815 my @config_keys = keys %min_configs;
2816 foreach my $config (@config_keys) {
2817 if (!defined($configs{$config})) {
2818 doprint "$config is not set, disabling\n";
2819 delete $min_configs{$config};
2823 # Save off all the current mandidory configs
2824 open (OUT, ">$temp_config")
2825 or die "Can't write to $temp_config";
2826 foreach my $config (keys %keep_configs) {
2827 print OUT "$keep_configs{$config}\n";
2829 foreach my $config (keys %min_configs) {
2830 print OUT "$min_configs{$config}\n";
2834 run_command "mv $temp_config $output_minconfig" or
2835 dodie "failed to copy update to $output_minconfig";
2838 doprint "Reboot and wait $sleep_time seconds\n";
2846 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2849 $ktest_config = $ARGV[0];
2850 if (! -f $ktest_config) {
2851 print "$ktest_config does not exist.\n";
2852 if (!read_yn "Create it?") {
2857 $ktest_config = "ktest.conf";
2860 if (! -f $ktest_config) {
2861 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2863 # Generated by ktest.pl
2865 # Define each test with TEST_START
2866 # The config options below it will override the defaults
2874 read_config $ktest_config;
2876 if (defined($opt{"LOG_FILE"})) {
2877 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2880 # Append any configs entered in manually to the config file.
2881 my @new_configs = keys %entered_configs;
2882 if ($#new_configs >= 0) {
2883 print "\nAppending entered in configs to $ktest_config\n";
2884 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2885 foreach my $config (@new_configs) {
2886 print OUT "$config = $entered_configs{$config}\n";
2887 $opt{$config} = $entered_configs{$config};
2891 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2892 unlink $opt{"LOG_FILE"};
2895 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2897 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2900 doprint "DEFAULT OPTIONS:\n";
2902 doprint "\nTEST $i OPTIONS";
2903 if (defined($repeat_tests{$i})) {
2904 $repeat = $repeat_tests{$i};
2905 doprint " ITERATE $repeat";
2910 foreach my $option (sort keys %opt) {
2912 if ($option =~ /\[(\d+)\]$/) {
2918 doprint "$option = $opt{$option}\n";
2922 sub __set_test_option {
2923 my ($name, $i) = @_;
2925 my $option = "$name\[$i\]";
2927 if (defined($opt{$option})) {
2928 return $opt{$option};
2931 foreach my $test (keys %repeat_tests) {
2933 $i < $test + $repeat_tests{$test}) {
2934 $option = "$name\[$test\]";
2935 if (defined($opt{$option})) {
2936 return $opt{$option};
2941 if (defined($opt{$name})) {
2948 sub set_test_option {
2949 my ($name, $i) = @_;
2951 my $option = __set_test_option($name, $i);
2952 return $option if (!defined($option));
2954 return eval_option($option, $i);
2957 # First we need to do is the builds
2958 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
2960 # Do not reboot on failing test options
2965 my $makecmd = set_test_option("MAKE_CMD", $i);
2967 $machine = set_test_option("MACHINE", $i);
2968 $ssh_user = set_test_option("SSH_USER", $i);
2969 $tmpdir = set_test_option("TMP_DIR", $i);
2970 $outputdir = set_test_option("OUTPUT_DIR", $i);
2971 $builddir = set_test_option("BUILD_DIR", $i);
2972 $test_type = set_test_option("TEST_TYPE", $i);
2973 $build_type = set_test_option("BUILD_TYPE", $i);
2974 $build_options = set_test_option("BUILD_OPTIONS", $i);
2975 $pre_build = set_test_option("PRE_BUILD", $i);
2976 $post_build = set_test_option("POST_BUILD", $i);
2977 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
2978 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
2979 $power_cycle = set_test_option("POWER_CYCLE", $i);
2980 $reboot = set_test_option("REBOOT", $i);
2981 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2982 $minconfig = set_test_option("MIN_CONFIG", $i);
2983 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
2984 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
2985 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
2986 $run_test = set_test_option("TEST", $i);
2987 $addconfig = set_test_option("ADD_CONFIG", $i);
2988 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2989 $grub_menu = set_test_option("GRUB_MENU", $i);
2990 $post_install = set_test_option("POST_INSTALL", $i);
2991 $no_install = set_test_option("NO_INSTALL", $i);
2992 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2993 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2994 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2995 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2996 $power_off = set_test_option("POWER_OFF", $i);
2997 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2998 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
2999 $sleep_time = set_test_option("SLEEP_TIME", $i);
3000 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
3001 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
3002 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
3003 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
3004 $bisect_skip = set_test_option("BISECT_SKIP", $i);
3005 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
3006 $store_failures = set_test_option("STORE_FAILURES", $i);
3007 $test_name = set_test_option("TEST_NAME", $i);
3008 $timeout = set_test_option("TIMEOUT", $i);
3009 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3010 $console = set_test_option("CONSOLE", $i);
3011 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
3012 $success_line = set_test_option("SUCCESS_LINE", $i);
3013 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
3014 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3015 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
3016 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
3017 $build_target = set_test_option("BUILD_TARGET", $i);
3018 $ssh_exec = set_test_option("SSH_EXEC", $i);
3019 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
3020 $target_image = set_test_option("TARGET_IMAGE", $i);
3021 $localversion = set_test_option("LOCALVERSION", $i);
3023 $start_minconfig_defined = 1;
3025 if (!defined($start_minconfig)) {
3026 $start_minconfig_defined = 0;
3027 $start_minconfig = $minconfig;
3030 chdir $builddir || die "can't change directory to $builddir";
3032 foreach my $dir ($tmpdir, $outputdir) {
3035 die "can't create $dir";
3039 $ENV{"SSH_USER"} = $ssh_user;
3040 $ENV{"MACHINE"} = $machine;
3042 $target = "$ssh_user\@$machine";
3044 $buildlog = "$tmpdir/buildlog-$machine";
3045 $dmesg = "$tmpdir/dmesg-$machine";
3046 $make = "$makecmd O=$outputdir";
3047 $output_config = "$outputdir/.config";
3049 if ($reboot_type eq "grub") {
3050 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3051 } elsif (!defined($reboot_script)) {
3052 dodie "REBOOT_SCRIPT not defined"
3055 my $run_type = $build_type;
3056 if ($test_type eq "patchcheck") {
3057 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3058 } elsif ($test_type eq "bisect") {
3059 $run_type = $opt{"BISECT_TYPE[$i]"};
3060 } elsif ($test_type eq "config_bisect") {
3061 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
3064 if ($test_type eq "make_min_config") {
3068 # mistake in config file?
3069 if (!defined($run_type)) {
3070 $run_type = "ERROR";
3074 $installme = " no_install" if ($no_install);
3077 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3082 if (defined($addconfig)) {
3083 my $min = $minconfig;
3084 if (!defined($minconfig)) {
3087 run_command "cat $addconfig $min > $tmpdir/add_config" or
3088 dodie "Failed to create temp config";
3089 $minconfig = "$tmpdir/add_config";
3092 my $checkout = $opt{"CHECKOUT[$i]"};
3093 if (defined($checkout)) {
3094 run_command "git checkout $checkout" or
3095 die "failed to checkout $checkout";
3101 if ($test_type eq "bisect") {
3104 } elsif ($test_type eq "config_bisect") {
3107 } elsif ($test_type eq "patchcheck") {
3110 } elsif ($test_type eq "make_min_config") {
3115 if ($build_type ne "nobuild") {
3116 build $build_type or next;
3119 if ($test_type eq "install") {
3126 if ($test_type ne "build") {
3128 start_monitor_and_boot or $failed = 1;
3130 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3131 do_run_test or $failed = 1;
3140 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3142 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
3146 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";