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);
25 "TEST_TYPE" => "build",
26 "BUILD_TYPE" => "randconfig",
29 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
30 "SLEEP_TIME" => 60, # sleep time between tests
32 "REBOOT_ON_ERROR" => 0,
33 "POWEROFF_ON_ERROR" => 0,
34 "REBOOT_ON_SUCCESS" => 1,
35 "POWEROFF_ON_SUCCESS" => 0,
36 "BUILD_OPTIONS" => "",
37 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
38 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
42 "MIN_CONFIG_TYPE" => "boot",
43 "SUCCESS_LINE" => "login:",
44 "DETECT_TRIPLE_FAULT" => 1,
46 "BOOTED_TIMEOUT" => 1,
47 "DIE_ON_FAILURE" => 1,
48 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
49 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
50 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
51 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
52 "STOP_AFTER_SUCCESS" => 10,
53 "STOP_AFTER_FAILURE" => 60,
54 "STOP_TEST_AFTER" => 600,
55 "MAX_MONITOR_WAIT" => 1800,
56 "GRUB_REBOOT" => "grub2-reboot",
57 "SYSLINUX" => "extlinux",
58 "SYSLINUX_PATH" => "/boot/extlinux",
60 # required, and we will ask users if they don't have them but we keep the default
61 # value something that is common.
62 "REBOOT_TYPE" => "grub",
63 "LOCALVERSION" => "-test",
65 "BUILD_TARGET" => "arch/x86/boot/bzImage",
66 "TARGET_IMAGE" => "/boot/vmlinuz-test",
100 my $poweroff_on_error;
101 my $reboot_on_success;
103 my $powercycle_after_reboot;
104 my $poweroff_after_halt;
105 my $max_monitor_wait;
108 my $scp_to_target_install;
125 my $start_minconfig_defined;
126 my $output_minconfig;
128 my $use_output_minconfig;
134 my $bisect_bad_commit = "";
138 my $config_bisect_good;
142 my $bisect_ret_abort;
143 my $bisect_ret_default;
144 my $in_patchcheck = 0;
154 my $bisect_sleep_time;
155 my $patchcheck_sleep_time;
162 my $detect_triplefault;
164 my $reboot_success_line;
166 my $stop_after_success;
167 my $stop_after_failure;
186 my $config_bisect_type;
187 my $config_bisect_check;
190 my $patchcheck_start;
193 # set when a test is something other that just building or install
194 # which would require more options.
197 # tell build not to worry about warnings, even when WARNINGS_FILE is set
200 # set when creating a new config
207 # force_config is the list of configs that we force enabled (or disabled)
208 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
211 # do not force reboots on config problems
215 my $reboot_success = 0;
218 "MACHINE" => \$machine,
219 "SSH_USER" => \$ssh_user,
220 "TMP_DIR" => \$tmpdir,
221 "OUTPUT_DIR" => \$outputdir,
222 "BUILD_DIR" => \$builddir,
223 "TEST_TYPE" => \$test_type,
224 "PRE_KTEST" => \$pre_ktest,
225 "POST_KTEST" => \$post_ktest,
226 "PRE_TEST" => \$pre_test,
227 "POST_TEST" => \$post_test,
228 "BUILD_TYPE" => \$build_type,
229 "BUILD_OPTIONS" => \$build_options,
230 "PRE_BUILD" => \$pre_build,
231 "POST_BUILD" => \$post_build,
232 "PRE_BUILD_DIE" => \$pre_build_die,
233 "POST_BUILD_DIE" => \$post_build_die,
234 "POWER_CYCLE" => \$power_cycle,
235 "REBOOT" => \$reboot,
236 "BUILD_NOCLEAN" => \$noclean,
237 "MIN_CONFIG" => \$minconfig,
238 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
239 "START_MIN_CONFIG" => \$start_minconfig,
240 "MIN_CONFIG_TYPE" => \$minconfig_type,
241 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
242 "WARNINGS_FILE" => \$warnings_file,
243 "IGNORE_CONFIG" => \$ignore_config,
244 "TEST" => \$run_test,
245 "ADD_CONFIG" => \$addconfig,
246 "REBOOT_TYPE" => \$reboot_type,
247 "GRUB_MENU" => \$grub_menu,
248 "GRUB_FILE" => \$grub_file,
249 "GRUB_REBOOT" => \$grub_reboot,
250 "SYSLINUX" => \$syslinux,
251 "SYSLINUX_PATH" => \$syslinux_path,
252 "SYSLINUX_LABEL" => \$syslinux_label,
253 "PRE_INSTALL" => \$pre_install,
254 "POST_INSTALL" => \$post_install,
255 "NO_INSTALL" => \$no_install,
256 "REBOOT_SCRIPT" => \$reboot_script,
257 "REBOOT_ON_ERROR" => \$reboot_on_error,
258 "SWITCH_TO_GOOD" => \$switch_to_good,
259 "SWITCH_TO_TEST" => \$switch_to_test,
260 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
261 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
262 "DIE_ON_FAILURE" => \$die_on_failure,
263 "POWER_OFF" => \$power_off,
264 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
265 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
266 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
267 "SLEEP_TIME" => \$sleep_time,
268 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
269 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
270 "IGNORE_WARNINGS" => \$ignore_warnings,
271 "IGNORE_ERRORS" => \$ignore_errors,
272 "BISECT_MANUAL" => \$bisect_manual,
273 "BISECT_SKIP" => \$bisect_skip,
274 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
275 "BISECT_RET_GOOD" => \$bisect_ret_good,
276 "BISECT_RET_BAD" => \$bisect_ret_bad,
277 "BISECT_RET_SKIP" => \$bisect_ret_skip,
278 "BISECT_RET_ABORT" => \$bisect_ret_abort,
279 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
280 "STORE_FAILURES" => \$store_failures,
281 "STORE_SUCCESSES" => \$store_successes,
282 "TEST_NAME" => \$test_name,
283 "TIMEOUT" => \$timeout,
284 "BOOTED_TIMEOUT" => \$booted_timeout,
285 "CONSOLE" => \$console,
286 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
287 "SUCCESS_LINE" => \$success_line,
288 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
289 "STOP_AFTER_SUCCESS" => \$stop_after_success,
290 "STOP_AFTER_FAILURE" => \$stop_after_failure,
291 "STOP_TEST_AFTER" => \$stop_test_after,
292 "BUILD_TARGET" => \$build_target,
293 "SSH_EXEC" => \$ssh_exec,
294 "SCP_TO_TARGET" => \$scp_to_target,
295 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
296 "CHECKOUT" => \$checkout,
297 "TARGET_IMAGE" => \$target_image,
298 "LOCALVERSION" => \$localversion,
300 "BISECT_GOOD" => \$bisect_good,
301 "BISECT_BAD" => \$bisect_bad,
302 "BISECT_TYPE" => \$bisect_type,
303 "BISECT_START" => \$bisect_start,
304 "BISECT_REPLAY" => \$bisect_replay,
305 "BISECT_FILES" => \$bisect_files,
306 "BISECT_REVERSE" => \$bisect_reverse,
307 "BISECT_CHECK" => \$bisect_check,
309 "CONFIG_BISECT" => \$config_bisect,
310 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
311 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
313 "PATCHCHECK_TYPE" => \$patchcheck_type,
314 "PATCHCHECK_START" => \$patchcheck_start,
315 "PATCHCHECK_END" => \$patchcheck_end,
318 # Options may be used by other options, record them.
321 # default variables that can be used
322 chomp ($variable{"PWD"} = `pwd`);
324 $config_help{"MACHINE"} = << "EOF"
325 The machine hostname that you will test.
326 For build only tests, it is still needed to differentiate log files.
329 $config_help{"SSH_USER"} = << "EOF"
330 The box is expected to have ssh on normal bootup, provide the user
331 (most likely root, since you need privileged operations)
334 $config_help{"BUILD_DIR"} = << "EOF"
335 The directory that contains the Linux source code (full path).
336 You can use \${PWD} that will be the path where ktest.pl is run, or use
337 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
340 $config_help{"OUTPUT_DIR"} = << "EOF"
341 The directory that the objects will be built (full path).
342 (can not be same as BUILD_DIR)
343 You can use \${PWD} that will be the path where ktest.pl is run, or use
344 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
347 $config_help{"BUILD_TARGET"} = << "EOF"
348 The location of the compiled file to copy to the target.
349 (relative to OUTPUT_DIR)
352 $config_help{"BUILD_OPTIONS"} = << "EOF"
353 Options to add to \"make\" when building.
357 $config_help{"TARGET_IMAGE"} = << "EOF"
358 The place to put your image on the test machine.
361 $config_help{"POWER_CYCLE"} = << "EOF"
362 A script or command to reboot the box.
364 Here is a digital loggers power switch example
365 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
367 Here is an example to reboot a virtual box on the current host
368 with the name "Guest".
369 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
372 $config_help{"CONSOLE"} = << "EOF"
373 The script or command that reads the console
375 If you use ttywatch server, something like the following would work.
376 CONSOLE = nc -d localhost 3001
378 For a virtual machine with guest name "Guest".
379 CONSOLE = virsh console Guest
382 $config_help{"LOCALVERSION"} = << "EOF"
383 Required version ending to differentiate the test
384 from other linux builds on the system.
387 $config_help{"REBOOT_TYPE"} = << "EOF"
388 Way to reboot the box to the test kernel.
389 Only valid options so far are "grub", "grub2", "syslinux", and "script".
391 If you specify grub, it will assume grub version 1
392 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
393 and select that target to reboot to the kernel. If this is not
394 your setup, then specify "script" and have a command or script
395 specified in REBOOT_SCRIPT to boot to the target.
397 The entry in /boot/grub/menu.lst must be entered in manually.
398 The test will not modify that file.
400 If you specify grub2, then you also need to specify both \$GRUB_MENU
403 If you specify syslinux, then you may use SYSLINUX to define the syslinux
404 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
405 the syslinux install (defaults to /boot/extlinux). But you have to specify
406 SYSLINUX_LABEL to define the label to boot to for the test kernel.
409 $config_help{"GRUB_MENU"} = << "EOF"
410 The grub title name for the test kernel to boot
411 (Only mandatory if REBOOT_TYPE = grub or grub2)
413 Note, ktest.pl will not update the grub menu.lst, you need to
414 manually add an option for the test. ktest.pl will search
415 the grub menu.lst for this option to find what kernel to
418 For example, if in the /boot/grub/menu.lst the test kernel title has:
421 GRUB_MENU = Test Kernel
423 For grub2, a search of \$GRUB_FILE is performed for the lines
424 that begin with "menuentry". It will not detect submenus. The
425 menu must be a non-nested menu. Add the quotes used in the menu
426 to guarantee your selection, as the first menuentry with the content
427 of \$GRUB_MENU that is found will be used.
430 $config_help{"GRUB_FILE"} = << "EOF"
431 If grub2 is used, the full path for the grub.cfg file is placed
432 here. Use something like /boot/grub2/grub.cfg to search.
435 $config_help{"SYSLINUX_LABEL"} = << "EOF"
436 If syslinux is used, the label that boots the target kernel must
437 be specified with SYSLINUX_LABEL.
440 $config_help{"REBOOT_SCRIPT"} = << "EOF"
441 A script to reboot the target into the test kernel
442 (Only mandatory if REBOOT_TYPE = script)
447 my ($cancel, $prompt) = @_;
453 print "$prompt [y/n/C] ";
455 print "$prompt [Y/n] ";
459 if ($ans =~ /^\s*$/) {
466 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
468 last if ($ans =~ /^c$/i);
469 print "Please answer either 'y', 'n' or 'c'.\n";
471 print "Please answer either 'y' or 'n'.\n";
477 if ($ans !~ /^y$/i) {
486 return read_prompt 0, $prompt;
492 return read_prompt 1, $prompt;
495 sub get_ktest_config {
499 return if (defined($opt{$config}));
501 if (defined($config_help{$config})) {
503 print $config_help{$config};
508 if (defined($default{$config}) && length($default{$config})) {
509 print "\[$default{$config}\] ";
512 $ans =~ s/^\s*(.*\S)\s*$/$1/;
513 if ($ans =~ /^\s*$/) {
514 if ($default{$config}) {
515 $ans = $default{$config};
517 print "Your answer can not be blank\n";
521 $entered_configs{$config} = ${ans};
526 sub get_ktest_configs {
527 get_ktest_config("MACHINE");
528 get_ktest_config("BUILD_DIR");
529 get_ktest_config("OUTPUT_DIR");
532 get_ktest_config("BUILD_OPTIONS");
535 # options required for other than just building a kernel
537 get_ktest_config("POWER_CYCLE");
538 get_ktest_config("CONSOLE");
541 # options required for install and more
542 if ($buildonly != 1) {
543 get_ktest_config("SSH_USER");
544 get_ktest_config("BUILD_TARGET");
545 get_ktest_config("TARGET_IMAGE");
548 get_ktest_config("LOCALVERSION");
550 return if ($buildonly);
552 my $rtype = $opt{"REBOOT_TYPE"};
554 if (!defined($rtype)) {
555 if (!defined($opt{"GRUB_MENU"})) {
556 get_ktest_config("REBOOT_TYPE");
557 $rtype = $entered_configs{"REBOOT_TYPE"};
563 if ($rtype eq "grub") {
564 get_ktest_config("GRUB_MENU");
567 if ($rtype eq "grub2") {
568 get_ktest_config("GRUB_MENU");
569 get_ktest_config("GRUB_FILE");
572 if ($rtype eq "syslinux") {
573 get_ktest_config("SYSLINUX_LABEL");
577 sub process_variables {
578 my ($value, $remove_undef) = @_;
581 # We want to check for '\', and it is just easier
582 # to check the previous characet of '$' and not need
583 # to worry if '$' is the first character. By adding
584 # a space to $value, we can just check [^\\]\$ and
585 # it will still work.
588 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
592 # append beginning of value to retval
593 $retval = "$retval$begin";
594 if (defined($variable{$var})) {
595 $retval = "$retval$variable{$var}";
596 } elsif (defined($remove_undef) && $remove_undef) {
597 # for if statements, any variable that is not defined,
598 # we simple convert to 0
599 $retval = "${retval}0";
601 # put back the origin piece.
602 $retval = "$retval\$\{$var\}";
603 # This could be an option that is used later, save
604 # it so we don't warn if this option is not one of
606 $used_options{$var} = 1;
610 $retval = "$retval$value";
612 # remove the space added in the beginning
619 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
621 my $prvalue = process_variables($rvalue);
623 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
624 # Note if a test is something other than build, then we
625 # will need other manditory options.
626 if ($prvalue ne "install") {
627 # for bisect, we need to check BISECT_TYPE
628 if ($prvalue ne "bisect") {
632 # install still limits some manditory options.
637 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
638 if ($prvalue ne "install") {
641 # install still limits some manditory options.
646 if (defined($opt{$lvalue})) {
647 if (!$override || defined(${$overrides}{$lvalue})) {
650 $extra = "In the same override section!\n";
652 die "$name: $.: Option $lvalue defined more than once!\n$extra";
654 ${$overrides}{$lvalue} = $prvalue;
656 if ($rvalue =~ /^\s*$/) {
657 delete $opt{$lvalue};
659 $opt{$lvalue} = $prvalue;
664 my ($lvalue, $rvalue) = @_;
666 if ($rvalue =~ /^\s*$/) {
667 delete $variable{$lvalue};
669 $rvalue = process_variables($rvalue);
670 $variable{$lvalue} = $rvalue;
674 sub process_compare {
675 my ($lval, $cmp, $rval) = @_;
686 return $lval eq $rval;
687 } elsif ($cmp eq "!=") {
688 return $lval ne $rval;
689 } elsif ($cmp eq "=~") {
690 return $lval =~ m/$rval/;
691 } elsif ($cmp eq "!~") {
692 return $lval !~ m/$rval/;
695 my $statement = "$lval $cmp $rval";
696 my $ret = eval $statement;
698 # $@ stores error of eval
709 return defined($variable{$2}) ||
714 sub process_expression {
715 my ($name, $val) = @_;
719 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
722 if (process_expression($name, $express)) {
723 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
725 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
733 while ($val =~ s/^(.*?)($OR|$AND)//) {
737 if (process_expression($name, $express)) {
748 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
749 my $ret = process_compare($1, $2, $3);
751 die "$name: $.: Unable to process comparison\n";
756 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
758 return !value_defined($2);
760 return value_defined($2);
764 if ($val =~ /^\s*0\s*$/) {
766 } elsif ($val =~ /^\s*\d+\s*$/) {
770 die ("$name: $.: Undefined content $val in if statement\n");
774 my ($name, $value) = @_;
776 # Convert variables and replace undefined ones with 0
777 my $val = process_variables($value, 1);
778 my $ret = process_expression $name, $val;
784 my ($config, $current_test_num) = @_;
787 open($in, $config) || die "can't read file $config";
790 $name =~ s,.*/(.*),$1,;
792 my $test_num = $$current_test_num;
795 my $num_tests_set = 0;
808 # ignore blank lines and comments
809 next if (/^\s*$/ || /\s*\#/);
811 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
821 if ($type eq "TEST_START") {
823 if ($num_tests_set) {
824 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
827 $old_test_num = $test_num;
828 $old_repeat = $repeat;
830 $test_num += $repeat;
837 # If SKIP is anywhere in the line, the command will be skipped
838 if ($rest =~ s/\s+SKIP\b//) {
845 if ($rest =~ s/\sELSE\b//) {
847 die "$name: $.: ELSE found with out matching IF section\n$_";
858 if ($rest =~ s/\sIF\s+(.*)//) {
859 if (process_if($name, $1)) {
871 if ($type eq "TEST_START") {
872 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
874 $repeat_tests{"$test_num"} = $repeat;
876 } elsif ($rest =~ s/\sOVERRIDE\b//) {
879 # Clear previous overrides
884 if (!$skip && $rest !~ /^\s*$/) {
885 die "$name: $.: Gargbage found after $type\n$_";
888 if ($skip && $type eq "TEST_START") {
889 $test_num = $old_test_num;
890 $repeat = $old_repeat;
893 } elsif (/^\s*ELSE\b(.*)$/) {
895 die "$name: $.: ELSE found with out matching IF section\n$_";
904 if ($rest =~ /\sIF\s+(.*)/) {
905 # May be a ELSE IF section.
906 if (process_if($name, $1)) {
917 if ($rest !~ /^\s*$/) {
918 die "$name: $.: Gargbage found after DEFAULTS\n$_";
921 } elsif (/^\s*INCLUDE\s+(\S+)/) {
926 die "$name: $.: INCLUDE can only be done in default sections\n$_";
929 my $file = process_variables($1);
931 if ($file !~ m,^/,) {
932 # check the path of the config file first
933 if ($config =~ m,(.*)/,) {
941 die "$name: $.: Can't read file $file\n$_";
944 if (__read_config($file, \$test_num)) {
948 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
956 ($lvalue eq "NUM_TESTS" ||
957 $lvalue eq "LOG_FILE" ||
958 $lvalue eq "CLEAR_LOG")) {
959 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
962 if ($lvalue eq "NUM_TESTS") {
964 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
967 die "$name: $.: NUM_TESTS must be set in default section\n";
972 if ($default || $lvalue =~ /\[\d+\]$/) {
973 set_value($lvalue, $rvalue, $override, \%overrides, $name);
975 my $val = "$lvalue\[$test_num\]";
976 set_value($val, $rvalue, $override, \%overrides, $name);
979 $repeats{$val} = $repeat;
982 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
988 # process config variables.
989 # Config variables are only active while reading the
990 # config and can be defined anywhere. They also ignore
991 # TEST_START and DEFAULTS, but are skipped if they are in
992 # on of these sections that have SKIP defined.
993 # The save variable can be
994 # defined multiple times and the new one simply overrides
996 set_variable($lvalue, $rvalue);
999 die "$name: $.: Garbage found in config\n$_";
1004 $test_num += $repeat - 1;
1005 $opt{"NUM_TESTS"} = $test_num;
1010 $$current_test_num = $test_num;
1016 print "What test case would you like to run?\n";
1017 print " (build, install or boot)\n";
1018 print " Other tests are available but require editing the config file\n";
1021 $default{"TEST_TYPE"} = $ans;
1030 $test_case = __read_config $config, \$test_num;
1032 # make sure we have all mandatory configs
1035 # was a test specified?
1037 print "No test case specified.\n";
1043 foreach my $default (keys %default) {
1044 if (!defined($opt{$default})) {
1045 $opt{$default} = $default{$default};
1049 if ($opt{"IGNORE_UNUSED"} == 1) {
1055 # check if there are any stragglers (typos?)
1056 foreach my $option (keys %opt) {
1058 # remove per test labels.
1060 if (!exists($option_map{$op}) &&
1061 !exists($default{$op}) &&
1062 !exists($used_options{$op})) {
1069 $s = " is" if (keys %not_used == 1);
1070 print "The following option$s not used; could be a typo:\n";
1071 foreach my $option (keys %not_used) {
1074 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1075 if (!read_yn "Do you want to continue?") {
1082 my ($name, $option, $i) = @_;
1084 # Add space to evaluate the character before $
1085 $option = " $option";
1090 foreach my $test (keys %repeat_tests) {
1092 $i < $test + $repeat_tests{$test}) {
1100 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1105 # Append beginning of line
1106 $retval = "$retval$start";
1108 # If the iteration option OPT[$i] exists, then use that.
1109 # otherwise see if the default OPT (without [$i]) exists.
1111 my $o = "$var\[$i\]";
1112 my $parento = "$var\[$parent\]";
1114 # If a variable contains itself, use the default var
1115 if (($var eq $name) && defined($opt{$var})) {
1117 $retval = "$retval$o";
1118 } elsif (defined($opt{$o})) {
1120 $retval = "$retval$o";
1121 } elsif ($repeated && defined($opt{$parento})) {
1122 $o = $opt{$parento};
1123 $retval = "$retval$o";
1124 } elsif (defined($opt{$var})) {
1126 $retval = "$retval$o";
1128 $retval = "$retval\$\{$var\}";
1134 $retval = "$retval$option";
1142 my ($name, $option, $i) = @_;
1146 # Since an option can evaluate to another option,
1147 # keep iterating until we do not evaluate any more
1150 while ($prev ne $option) {
1151 # Check for recursive evaluations.
1152 # 100 deep should be more than enough.
1154 die "Over 100 evaluations accurred with $option\n" .
1155 "Check for recursive variables\n";
1158 $option = __eval_option($name, $option, $i);
1165 if (defined($opt{"LOG_FILE"})) {
1166 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1173 if (defined($opt{"LOG_FILE"})) {
1188 sub wait_for_monitor;
1193 # Make sure everything has been written to disk
1196 if (defined($time)) {
1198 # flush out current monitor
1199 # May contain the reboot success line
1203 # try to reboot normally
1204 if (run_command $reboot) {
1205 if (defined($powercycle_after_reboot)) {
1206 sleep $powercycle_after_reboot;
1207 run_command "$power_cycle";
1210 # nope? power cycle it.
1211 run_command "$power_cycle";
1214 if (defined($time)) {
1216 # We only want to get to the new kernel, don't fail
1217 # if we stumble over a call trace.
1218 my $save_ignore_errors = $ignore_errors;
1221 # Look for the good kernel to boot
1222 if (wait_for_monitor($time, "Linux version")) {
1224 doprint "Reboot did not finish. Forcing power cycle\n";
1225 run_command "$power_cycle";
1228 $ignore_errors = $save_ignore_errors;
1230 # Still need to wait for the reboot to finish
1231 wait_for_monitor($time, $reboot_success_line);
1237 sub reboot_to_good {
1240 if (defined($switch_to_good)) {
1241 run_command $switch_to_good;
1250 return $test_type eq "build" || $no_reboot ||
1251 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1252 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1256 doprint "CRITICAL FAILURE... ", @_, "\n";
1260 if ($reboot_on_error && !do_not_reboot) {
1262 doprint "REBOOTING\n";
1265 } elsif ($poweroff_on_error && defined($power_off)) {
1266 doprint "POWERING OFF\n";
1270 if (defined($opt{"LOG_FILE"})) {
1271 print " See $opt{LOG_FILE} for more info.\n";
1282 my $pid = open($fp, "$console|") or
1283 dodie "Can't open console $console";
1285 $flags = fcntl($fp, F_GETFL, 0) or
1286 dodie "Can't get flags for the socket: $!";
1287 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1288 dodie "Can't set flags for the socket: $!";
1294 my ($fp, $pid) = @_;
1296 doprint "kill child process $pid\n";
1304 if ($monitor_cnt++) {
1307 $monitor_fp = \*MONFD;
1308 $monitor_pid = open_console $monitor_fp;
1312 open(MONFD, "Stop perl from warning about single use of MONFD");
1316 return if (!defined $console);
1317 if (--$monitor_cnt) {
1320 close_console($monitor_fp, $monitor_pid);
1323 sub wait_for_monitor {
1324 my ($time, $stop) = @_;
1328 my $start_time = time;
1329 my $skip_call_trace = 0;
1331 my $bug_ignored = 0;
1334 doprint "** Wait for monitor to settle down **\n";
1336 # read the monitor and wait for the system to calm down
1338 $line = wait_for_input($monitor_fp, $time);
1339 last if (!defined($line));
1341 $full_line .= $line;
1343 if (defined($stop) && $full_line =~ /$stop/) {
1344 doprint "wait for monitor detected $stop\n";
1348 if ($full_line =~ /\[ backtrace testing \]/) {
1349 $skip_call_trace = 1;
1352 if ($full_line =~ /call trace:/i) {
1353 if (!$bug && !$skip_call_trace) {
1354 if ($ignore_errors) {
1362 if ($full_line =~ /\[ end of backtrace testing \]/) {
1363 $skip_call_trace = 0;
1366 if ($full_line =~ /Kernel panic -/) {
1370 if ($line =~ /\n/) {
1374 if ($now - $start_time >= $max_monitor_wait) {
1375 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1379 print "** Monitor flushed **\n";
1384 my ($result, $basedir) = @_;
1386 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1387 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1389 my $type = $build_type;
1390 if ($type =~ /useconfig/) {
1391 $type = "useconfig";
1394 my $dir = "$machine-$test_type-$type-$result-$date";
1396 $dir = "$basedir/$dir";
1400 die "can't create $dir";
1404 "config" => $output_config,
1405 "buildlog" => $buildlog,
1407 "testlog" => $testlog,
1410 while (my ($name, $source) = each(%files)) {
1412 cp "$source", "$dir/$name" or
1413 die "failed to copy $source";
1417 doprint "*** Saved info to $dir ***\n";
1422 if (defined($post_test)) {
1423 run_command $post_test;
1426 if ($die_on_failure) {
1434 # no need to reboot for just building.
1435 if (!do_not_reboot) {
1436 doprint "REBOOTING\n";
1437 reboot_to_good $sleep_time;
1442 if (defined($test_name)) {
1443 $name = " ($test_name)";
1446 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1447 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1448 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1449 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1450 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1452 if (defined($store_failures)) {
1453 save_logs "fail", $store_failures;
1465 $command =~ s/\$SSH_USER/$ssh_user/g;
1466 $command =~ s/\$MACHINE/$machine/g;
1468 doprint("$command ... ");
1470 $pid = open(CMD, "$command 2>&1 |") or
1471 (fail "unable to exec $command" and return 0);
1473 if (defined($opt{"LOG_FILE"})) {
1474 open(LOG, ">>$opt{LOG_FILE}") or
1475 dodie "failed to write to log";
1479 if (defined($redirect)) {
1480 open (RD, ">$redirect") or
1481 dodie "failed to write to redirect $redirect";
1486 print LOG if ($dolog);
1487 print RD if ($dord);
1494 close(LOG) if ($dolog);
1495 close(RD) if ($dord);
1498 doprint "FAILED!\n";
1500 doprint "SUCCESS\n";
1508 my $cp_exec = $ssh_exec;
1510 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1511 return run_command "$cp_exec";
1515 my ($src, $dst, $cp_scp) = @_;
1517 $cp_scp =~ s/\$SRC_FILE/$src/g;
1518 $cp_scp =~ s/\$DST_FILE/$dst/g;
1520 return run_command "$cp_scp";
1523 sub run_scp_install {
1524 my ($src, $dst) = @_;
1526 my $cp_scp = $scp_to_target_install;
1528 return run_scp($src, $dst, $cp_scp);
1532 my ($src, $dst) = @_;
1534 my $cp_scp = $scp_to_target;
1536 return run_scp($src, $dst, $cp_scp);
1539 sub get_grub2_index {
1541 return if (defined($grub_number));
1543 doprint "Find grub2 menu ... ";
1546 my $ssh_grub = $ssh_exec;
1547 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1549 open(IN, "$ssh_grub |")
1550 or die "unable to get $grub_file";
1555 if (/^menuentry.*$grub_menu/) {
1559 } elsif (/^menuentry\s/) {
1565 die "Could not find '$grub_menu' in $grub_file on $machine"
1567 doprint "$grub_number\n";
1570 sub get_grub_index {
1572 if ($reboot_type eq "grub2") {
1577 if ($reboot_type ne "grub") {
1580 return if (defined($grub_number));
1582 doprint "Find grub menu ... ";
1585 my $ssh_grub = $ssh_exec;
1586 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1588 open(IN, "$ssh_grub |")
1589 or die "unable to get menu.lst";
1594 if (/^\s*title\s+$grub_menu\s*$/) {
1598 } elsif (/^\s*title\s/) {
1604 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1606 doprint "$grub_number\n";
1611 my ($fp, $time) = @_;
1617 if (!defined($time)) {
1622 vec($rin, fileno($fp), 1) = 1;
1623 ($ready, $time) = select($rin, undef, undef, $time);
1627 # try to read one char at a time
1628 while (sysread $fp, $ch, 1) {
1630 last if ($ch eq "\n");
1633 if (!length($line)) {
1641 if (defined($switch_to_test)) {
1642 run_command $switch_to_test;
1645 if ($reboot_type eq "grub") {
1646 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1647 } elsif ($reboot_type eq "grub2") {
1648 run_ssh "$grub_reboot $grub_number";
1649 } elsif ($reboot_type eq "syslinux") {
1650 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
1651 } elsif (defined $reboot_script) {
1652 run_command "$reboot_script";
1660 doprint "git rev-list --max-count=1 $commit ... ";
1661 my $sha1 = `git rev-list --max-count=1 $commit`;
1668 dodie "Failed to get git $commit";
1681 my $bug_ignored = 0;
1682 my $skip_call_trace = 0;
1690 open(DMESG, "> $dmesg") or
1691 die "unable to write to $dmesg";
1697 my $monitor_start = time;
1699 my $version_found = 0;
1703 if ($bug && defined($stop_after_failure) &&
1704 $stop_after_failure >= 0) {
1705 my $time = $stop_after_failure - (time - $failure_start);
1706 $line = wait_for_input($monitor_fp, $time);
1707 if (!defined($line)) {
1708 doprint "bug timed out after $booted_timeout seconds\n";
1709 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1713 $line = wait_for_input($monitor_fp, $booted_timeout);
1714 if (!defined($line)) {
1715 my $s = $booted_timeout == 1 ? "" : "s";
1716 doprint "Successful boot found: break after $booted_timeout second$s\n";
1720 $line = wait_for_input($monitor_fp);
1721 if (!defined($line)) {
1722 my $s = $timeout == 1 ? "" : "s";
1723 doprint "Timed out after $timeout second$s\n";
1731 # we are not guaranteed to get a full line
1732 $full_line .= $line;
1734 if ($full_line =~ /$success_line/) {
1736 $success_start = time;
1739 if ($booted && defined($stop_after_success) &&
1740 $stop_after_success >= 0) {
1742 if ($now - $success_start >= $stop_after_success) {
1743 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1748 if ($full_line =~ /\[ backtrace testing \]/) {
1749 $skip_call_trace = 1;
1752 if ($full_line =~ /call trace:/i) {
1753 if (!$bug && !$skip_call_trace) {
1754 if ($ignore_errors) {
1758 $failure_start = time;
1763 if ($bug && defined($stop_after_failure) &&
1764 $stop_after_failure >= 0) {
1766 if ($now - $failure_start >= $stop_after_failure) {
1767 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1772 if ($full_line =~ /\[ end of backtrace testing \]/) {
1773 $skip_call_trace = 0;
1776 if ($full_line =~ /Kernel panic -/) {
1777 $failure_start = time;
1781 # Detect triple faults by testing the banner
1782 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1783 if ($1 eq $version) {
1785 } elsif ($version_found && $detect_triplefault) {
1786 # We already booted into the kernel we are testing,
1787 # but now we booted into another kernel?
1788 # Consider this a triple fault.
1789 doprint "Aleady booted in Linux kernel $version, but now\n";
1790 doprint "we booted into Linux kernel $1.\n";
1791 doprint "Assuming that this is a triple fault.\n";
1792 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1797 if ($line =~ /\n/) {
1801 if ($stop_test_after > 0 && !$booted && !$bug) {
1802 if (time - $monitor_start > $stop_test_after) {
1803 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1812 return 0 if ($in_bisect);
1813 fail "failed - got a bug report" and return 0;
1817 return 0 if ($in_bisect);
1818 fail "failed - never got a boot prompt." and return 0;
1822 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1828 sub eval_kernel_version {
1831 $option =~ s/\$KERNEL_VERSION/$version/g;
1836 sub do_post_install {
1838 return if (!defined($post_install));
1840 my $cp_post_install = eval_kernel_version $post_install;
1841 run_command "$cp_post_install" or
1842 dodie "Failed to run post install";
1845 # Sometimes the reboot fails, and will hang. We try to ssh to the box
1846 # and if we fail, we force another reboot, that should powercycle it.
1848 if (!run_ssh "echo testing connection") {
1855 return if ($no_install);
1857 if (defined($pre_install)) {
1858 my $cp_pre_install = eval_kernel_version $pre_install;
1859 run_command "$cp_pre_install" or
1860 dodie "Failed to run pre install";
1863 my $cp_target = eval_kernel_version $target_image;
1867 run_scp_install "$outputdir/$build_target", "$cp_target" or
1868 dodie "failed to copy image";
1870 my $install_mods = 0;
1872 # should we process modules?
1874 open(IN, "$output_config") or dodie("Can't read config file");
1876 if (/CONFIG_MODULES(=y)?/) {
1885 if (!$install_mods) {
1887 doprint "No modules needed\n";
1891 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1892 dodie "Failed to install modules";
1894 my $modlib = "/lib/modules/$version";
1895 my $modtar = "ktest-mods.tar.bz2";
1897 run_ssh "rm -rf $modlib" or
1898 dodie "failed to remove old mods: $modlib";
1900 # would be nice if scp -r did not follow symbolic links
1901 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1902 dodie "making tarball";
1904 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1905 dodie "failed to copy modules";
1907 unlink "$tmpdir/$modtar";
1909 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1910 dodie "failed to tar modules";
1912 run_ssh "rm -f /tmp/$modtar";
1918 # get the release name
1919 return if ($have_version);
1920 doprint "$make kernelrelease ... ";
1921 $version = `$make kernelrelease | tail -1`;
1923 doprint "$version\n";
1927 sub start_monitor_and_boot {
1928 # Make sure the stable kernel has finished booting
1930 # Install bisects, don't need console
1931 if (defined $console) {
1941 start_monitor if (defined $console);
1945 my $check_build_re = ".*:.*(warning|error|Error):.*";
1946 my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1948 sub process_warning_line {
1953 # for distcc heterogeneous systems, some compilers
1954 # do things differently causing warning lines
1955 # to be slightly different. This makes an attempt
1956 # to fixe those issues.
1958 # chop off the index into the line
1959 # using distcc, some compilers give different indexes
1960 # depending on white space
1961 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
1963 # Some compilers use UTF-8 extended for quotes and some don't.
1964 $line =~ s/$utf8_quote/'/g;
1969 # Read buildlog and check against warnings file for any
1974 sub check_buildlog {
1975 return 1 if (!defined $warnings_file);
1979 # Failed builds should not reboot the target
1980 my $save_no_reboot = $no_reboot;
1983 if (-f $warnings_file) {
1984 open(IN, $warnings_file) or
1985 dodie "Error opening $warnings_file";
1988 if (/$check_build_re/) {
1989 my $warning = process_warning_line $_;
1991 $warnings_list{$warning} = 1;
1997 # If warnings file didn't exist, and WARNINGS_FILE exist,
1998 # then we fail on any warning!
2000 open(IN, $buildlog) or dodie "Can't open $buildlog";
2002 if (/$check_build_re/) {
2003 my $warning = process_warning_line $_;
2005 if (!defined $warnings_list{$warning}) {
2006 fail "New warning found (not in $warnings_file)\n$_\n";
2007 $no_reboot = $save_no_reboot;
2012 $no_reboot = $save_no_reboot;
2016 sub check_patch_buildlog {
2019 my @files = `git show $patch | diffstat -l`;
2021 foreach my $file (@files) {
2025 open(IN, "git show $patch |") or
2026 dodie "failed to show $patch";
2028 if (m,^--- a/(.*),) {
2030 $files[$#files] = $1;
2035 open(IN, $buildlog) or dodie "Can't open $buildlog";
2037 if (/^\s*(.*?):.*(warning|error)/) {
2039 foreach my $file (@files) {
2040 my $fullpath = "$builddir/$file";
2041 if ($file eq $err || $fullpath eq $err) {
2042 fail "$file built with warnings" and return 0;
2052 sub apply_min_config {
2053 my $outconfig = "$output_config.new";
2055 # Read the config file and remove anything that
2056 # is in the force_config hash (from minconfig and others)
2057 # then add the force config back.
2059 doprint "Applying minimum configurations into $output_config.new\n";
2061 open (OUT, ">$outconfig") or
2062 dodie "Can't create $outconfig";
2064 if (-f $output_config) {
2065 open (IN, $output_config) or
2066 dodie "Failed to open $output_config";
2068 if (/^(# )?(CONFIG_[^\s=]*)/) {
2069 next if (defined($force_config{$2}));
2075 foreach my $config (keys %force_config) {
2076 print OUT "$force_config{$config}\n";
2080 run_command "mv $outconfig $output_config";
2083 sub make_oldconfig {
2085 my @force_list = keys %force_config;
2087 if ($#force_list >= 0) {
2091 if (!run_command "$make olddefconfig") {
2092 # Perhaps olddefconfig doesn't exist in this version of the kernel
2094 doprint "olddefconfig failed, trying make oldnoconfig\n";
2095 if (!run_command "$make oldnoconfig") {
2096 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2097 # try a yes '' | oldconfig
2098 run_command "yes '' | $make oldconfig" or
2099 dodie "failed make config oldconfig";
2104 # read a config file and use this to force new configs.
2105 sub load_force_config {
2108 doprint "Loading force configs from $config\n";
2109 open(IN, $config) or
2110 dodie "failed to read $config";
2113 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2114 $force_config{$1} = $_;
2115 } elsif (/^# (CONFIG_\S*) is not set/) {
2116 $force_config{$1} = $_;
2127 # Failed builds should not reboot the target
2128 my $save_no_reboot = $no_reboot;
2131 # Calculate a new version from here.
2134 if (defined($pre_build)) {
2135 my $ret = run_command $pre_build;
2136 if (!$ret && defined($pre_build_die) &&
2138 dodie "failed to pre_build\n";
2142 if ($type =~ /^useconfig:(.*)/) {
2143 run_command "cp $1 $output_config" or
2144 dodie "could not copy $1 to .config";
2146 $type = "oldconfig";
2149 # old config can ask questions
2150 if ($type eq "oldconfig") {
2151 $type = "olddefconfig";
2153 # allow for empty configs
2154 run_command "touch $output_config";
2157 run_command "mv $output_config $outputdir/config_temp" or
2158 dodie "moving .config";
2160 run_command "$make mrproper" or dodie "make mrproper";
2162 run_command "mv $outputdir/config_temp $output_config" or
2163 dodie "moving config_temp";
2166 } elsif (!$noclean) {
2167 unlink "$output_config";
2168 run_command "$make mrproper" or
2169 dodie "make mrproper";
2172 # add something to distinguish this build
2173 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2174 print OUT "$localversion\n";
2177 if (defined($minconfig)) {
2178 load_force_config($minconfig);
2181 if ($type ne "olddefconfig") {
2182 run_command "$make $type" or
2183 dodie "failed make config";
2185 # Run old config regardless, to enforce min configurations
2188 $redirect = "$buildlog";
2189 my $build_ret = run_command "$make $build_options";
2192 if (defined($post_build)) {
2193 # Because a post build may change the kernel version
2196 my $ret = run_command $post_build;
2197 if (!$ret && defined($post_build_die) &&
2199 dodie "failed to post_build\n";
2204 # bisect may need this to pass
2206 $no_reboot = $save_no_reboot;
2209 fail "failed build" and return 0;
2212 $no_reboot = $save_no_reboot;
2218 if (!run_ssh "halt" or defined($power_off)) {
2219 if (defined($poweroff_after_halt)) {
2220 sleep $poweroff_after_halt;
2221 run_command "$power_off";
2225 run_command "$power_off";
2232 if (defined($post_test)) {
2233 run_command $post_test;
2240 if (defined($test_name)) {
2241 $name = " ($test_name)";
2244 doprint "\n\n*******************************************\n";
2245 doprint "*******************************************\n";
2246 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2247 doprint "*******************************************\n";
2248 doprint "*******************************************\n";
2250 if (defined($store_successes)) {
2251 save_logs "success", $store_successes;
2254 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2255 doprint "Reboot and wait $sleep_time seconds\n";
2256 reboot_to_good $sleep_time;
2262 doprint "Pass or fail? [p/f]";
2265 if ($ans eq "p" || $ans eq "P") {
2267 } elsif ($ans eq "f" || $ans eq "F") {
2270 print "Please answer 'P' or 'F'\n";
2275 sub child_run_test {
2278 # child should have no power
2279 $reboot_on_error = 0;
2280 $poweroff_on_error = 0;
2281 $die_on_failure = 1;
2283 $redirect = "$testlog";
2284 run_command $run_test or $failed = 1;
2292 sub child_finished {
2302 my $bug_ignored = 0;
2306 doprint "run test $run_test\n";
2310 $SIG{CHLD} = qw(child_finished);
2314 child_run_test if (!$child_pid);
2319 $line = wait_for_input($monitor_fp, 1);
2320 if (defined($line)) {
2322 # we are not guaranteed to get a full line
2323 $full_line .= $line;
2326 if ($full_line =~ /call trace:/i) {
2327 if ($ignore_errors) {
2334 if ($full_line =~ /Kernel panic -/) {
2338 if ($line =~ /\n/) {
2342 } while (!$child_done && !$bug);
2344 if (!$bug && $bug_ignored) {
2345 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2349 my $failure_start = time;
2352 $line = wait_for_input($monitor_fp, 1);
2353 if (defined($line)) {
2357 if ($now - $failure_start >= $stop_after_failure) {
2360 } while (defined($line));
2362 doprint "Detected kernel crash!\n";
2363 # kill the child with extreme prejudice
2367 waitpid $child_pid, 0;
2370 if (!$bug && $in_bisect) {
2371 if (defined($bisect_ret_good)) {
2372 if ($child_exit == $bisect_ret_good) {
2376 if (defined($bisect_ret_skip)) {
2377 if ($child_exit == $bisect_ret_skip) {
2381 if (defined($bisect_ret_abort)) {
2382 if ($child_exit == $bisect_ret_abort) {
2383 fail "test abort" and return -2;
2386 if (defined($bisect_ret_bad)) {
2387 if ($child_exit == $bisect_ret_skip) {
2391 if (defined($bisect_ret_default)) {
2392 if ($bisect_ret_default eq "good") {
2394 } elsif ($bisect_ret_default eq "bad") {
2396 } elsif ($bisect_ret_default eq "skip") {
2398 } elsif ($bisect_ret_default eq "abort") {
2401 fail "unknown default action: $bisect_ret_default"
2407 if ($bug || $child_exit) {
2408 return 0 if $in_bisect;
2409 fail "test failed" and return 0;
2414 sub run_git_bisect {
2417 doprint "$command ... ";
2419 my $output = `$command 2>&1`;
2426 dodie "Failed to git bisect";
2429 doprint "SUCCESS\n";
2430 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2431 doprint "$1 [$2]\n";
2432 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2433 $bisect_bad_commit = $1;
2434 doprint "Found bad commit... $1\n";
2437 # we already logged it, just print it now.
2445 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2446 reboot_to_good $bisect_sleep_time;
2449 # returns 1 on success, 0 on failure, -1 on skip
2450 sub run_bisect_test {
2451 my ($type, $buildtype) = @_;
2460 build $buildtype or $failed = 1;
2462 if ($type ne "build") {
2463 if ($failed && $bisect_skip) {
2467 dodie "Failed on build" if $failed;
2470 start_monitor_and_boot or $failed = 1;
2472 if ($type ne "boot") {
2473 if ($failed && $bisect_skip) {
2479 dodie "Failed on boot" if $failed;
2481 do_run_test or $failed = 1;
2492 # reboot the box to a kernel we can ssh to
2493 if ($type ne "build") {
2503 my $buildtype = "oldconfig";
2505 # We should have a minconfig to use?
2506 if (defined($minconfig)) {
2507 $buildtype = "useconfig:$minconfig";
2510 my $ret = run_bisect_test $type, $buildtype;
2512 if ($bisect_manual) {
2513 $ret = answer_bisect;
2516 # Are we looking for where it worked, not failed?
2517 if ($reverse_bisect && $ret >= 0) {
2523 } elsif ($ret == 0) {
2525 } elsif ($bisect_skip) {
2526 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2531 sub update_bisect_replay {
2532 my $tmp_log = "$tmpdir/ktest_bisect_log";
2533 run_command "git bisect log > $tmp_log" or
2534 die "can't create bisect log";
2543 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2544 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2545 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2547 my $good = $bisect_good;
2548 my $bad = $bisect_bad;
2549 my $type = $bisect_type;
2550 my $start = $bisect_start;
2551 my $replay = $bisect_replay;
2552 my $start_files = $bisect_files;
2554 if (defined($start_files)) {
2555 $start_files = " -- " . $start_files;
2560 # convert to true sha1's
2561 $good = get_sha1($good);
2562 $bad = get_sha1($bad);
2564 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2565 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2566 $reverse_bisect = 1;
2568 $reverse_bisect = 0;
2571 # Can't have a test without having a test to run
2572 if ($type eq "test" && !defined($run_test)) {
2576 # Check if a bisect was running
2577 my $bisect_start_file = "$builddir/.git/BISECT_START";
2579 my $check = $bisect_check;
2580 my $do_check = defined($check) && $check ne "0";
2582 if ( -f $bisect_start_file ) {
2583 print "Bisect in progress found\n";
2585 print " If you say yes, then no checks of good or bad will be done\n";
2587 if (defined($replay)) {
2588 print "** BISECT_REPLAY is defined in config file **";
2589 print " Ignore config option and perform new git bisect log?\n";
2590 if (read_ync " (yes, no, or cancel) ") {
2591 $replay = update_bisect_replay;
2594 } elsif (read_yn "read git log and continue?") {
2595 $replay = update_bisect_replay;
2603 my $head = get_sha1("HEAD");
2605 if ($check ne "good") {
2606 doprint "TESTING BISECT BAD [$bad]\n";
2607 run_command "git checkout $bad" or
2608 die "Failed to checkout $bad";
2610 $result = run_bisect $type;
2612 if ($result ne "bad") {
2613 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2617 if ($check ne "bad") {
2618 doprint "TESTING BISECT GOOD [$good]\n";
2619 run_command "git checkout $good" or
2620 die "Failed to checkout $good";
2622 $result = run_bisect $type;
2624 if ($result ne "good") {
2625 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2629 # checkout where we started
2630 run_command "git checkout $head" or
2631 die "Failed to checkout $head";
2634 run_command "git bisect start$start_files" or
2635 dodie "could not start bisect";
2637 run_command "git bisect good $good" or
2638 dodie "could not set bisect good to $good";
2640 run_git_bisect "git bisect bad $bad" or
2641 dodie "could not set bisect bad to $bad";
2643 if (defined($replay)) {
2644 run_command "git bisect replay $replay" or
2645 dodie "failed to run replay";
2648 if (defined($start)) {
2649 run_command "git checkout $start" or
2650 dodie "failed to checkout $start";
2655 $result = run_bisect $type;
2656 $test = run_git_bisect "git bisect $result";
2659 run_command "git bisect log" or
2660 dodie "could not capture git bisect log";
2662 run_command "git bisect reset" or
2663 dodie "could not reset git bisect";
2665 doprint "Bad commit was [$bisect_bad_commit]\n";
2670 # config_ignore holds the configs that were set (or unset) for
2671 # a good config and we will ignore these configs for the rest
2672 # of a config bisect. These configs stay as they were.
2675 # config_set holds what all configs were set as.
2678 # config_off holds the set of configs that the bad config had disabled.
2679 # We need to record them and set them in the .config when running
2680 # olddefconfig, because olddefconfig keeps the defaults.
2683 # config_off_tmp holds a set of configs to turn off for now
2686 # config_list is the set of configs that are being tested
2692 sub assign_configs {
2693 my ($hash, $config) = @_;
2696 or dodie "Failed to read $config";
2699 if (/^((CONFIG\S*)=.*)/) {
2707 sub process_config_ignore {
2710 assign_configs \%config_ignore, $config;
2713 sub read_current_config {
2714 my ($config_ref) = @_;
2716 %{$config_ref} = ();
2717 undef %{$config_ref};
2719 my @key = keys %{$config_ref};
2721 print "did not delete!\n";
2724 open (IN, "$output_config");
2727 if (/^(CONFIG\S+)=(.*)/) {
2728 ${$config_ref}{$1} = $2;
2734 sub get_dependencies {
2737 my $arr = $dependency{$config};
2738 if (!defined($arr)) {
2744 foreach my $dep (@{$arr}) {
2745 print "ADD DEP $dep\n";
2746 @deps = (@deps, get_dependencies $dep);
2755 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2757 foreach my $config (@configs) {
2758 print OUT "$config_set{$config}\n";
2759 my @deps = get_dependencies $config;
2760 foreach my $dep (@deps) {
2761 print OUT "$config_set{$dep}\n";
2765 # turn off configs to keep off
2766 foreach my $config (keys %config_off) {
2767 print OUT "# $config is not set\n";
2770 # turn off configs that should be off for now
2771 foreach my $config (@config_off_tmp) {
2772 print OUT "# $config is not set\n";
2775 foreach my $config (keys %config_ignore) {
2776 print OUT "$config_ignore{$config}\n";
2783 sub compare_configs {
2786 foreach my $item (keys %a) {
2787 if (!defined($b{$item})) {
2788 print "diff $item\n";
2796 print "diff2 $keys[0]\n";
2798 return -1 if ($#keys >= 0);
2803 sub run_config_bisect_test {
2806 return run_bisect_test $type, "oldconfig";
2809 sub process_passed {
2812 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2813 # Passed! All these configs are part of a good compile.
2814 # Add them to the min options.
2815 foreach my $config (keys %configs) {
2816 if (defined($config_list{$config})) {
2817 doprint " removing $config\n";
2818 $config_ignore{$config} = $config_list{$config};
2819 delete $config_list{$config};
2822 doprint "config copied to $outputdir/config_good\n";
2823 run_command "cp -f $output_config $outputdir/config_good";
2826 sub process_failed {
2829 doprint "\n\n***************************************\n";
2830 doprint "Found bad config: $config\n";
2831 doprint "***************************************\n\n";
2834 sub run_config_bisect {
2836 my @start_list = keys %config_list;
2838 if ($#start_list < 0) {
2839 doprint "No more configs to test!!!\n";
2843 doprint "***** RUN TEST ***\n";
2844 my $type = $config_bisect_type;
2848 my $count = $#start_list + 1;
2849 doprint " $count configs to test\n";
2851 my $half = int($#start_list / 2);
2854 my @tophalf = @start_list[0 .. $half];
2856 # keep the bottom half off
2857 if ($half < $#start_list) {
2858 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2860 @config_off_tmp = ();
2863 create_config @tophalf;
2864 read_current_config \%current_config;
2866 $count = $#tophalf + 1;
2867 doprint "Testing $count configs\n";
2869 # make sure we test something
2870 foreach my $config (@tophalf) {
2871 if (defined($current_config{$config})) {
2877 # try the other half
2878 doprint "Top half produced no set configs, trying bottom half\n";
2880 # keep the top half off
2881 @config_off_tmp = @tophalf;
2882 @tophalf = @start_list[$half + 1 .. $#start_list];
2884 create_config @tophalf;
2885 read_current_config \%current_config;
2886 foreach my $config (@tophalf) {
2887 if (defined($current_config{$config})) {
2893 doprint "Failed: Can't make new config with current configs\n";
2894 foreach my $config (@start_list) {
2895 doprint " CONFIG: $config\n";
2899 $count = $#tophalf + 1;
2900 doprint "Testing $count configs\n";
2903 $ret = run_config_bisect_test $type;
2904 if ($bisect_manual) {
2905 $ret = answer_bisect;
2908 process_passed %current_config;
2912 doprint "This config had a failure.\n";
2913 doprint "Removing these configs that were not set in this config:\n";
2914 doprint "config copied to $outputdir/config_bad\n";
2915 run_command "cp -f $output_config $outputdir/config_bad";
2917 # A config exists in this group that was bad.
2918 foreach my $config (keys %config_list) {
2919 if (!defined($current_config{$config})) {
2920 doprint " removing $config\n";
2921 delete $config_list{$config};
2925 @start_list = @tophalf;
2927 if ($#start_list == 0) {
2928 process_failed $start_list[0];
2932 # remove half the configs we are looking at and see if
2934 $half = int($#start_list / 2);
2935 } while ($#start_list > 0);
2937 # we found a single config, try it again unless we are running manually
2939 if ($bisect_manual) {
2940 process_failed $start_list[0];
2944 my @tophalf = @start_list[0 .. 0];
2946 $ret = run_config_bisect_test $type;
2948 process_passed %current_config;
2952 process_failed $start_list[0];
2959 my $start_config = $config_bisect;
2961 my $tmpconfig = "$tmpdir/use_config";
2963 if (defined($config_bisect_good)) {
2964 process_config_ignore $config_bisect_good;
2967 # Make the file with the bad config and the min config
2968 if (defined($minconfig)) {
2969 # read the min config for things to ignore
2970 run_command "cp $minconfig $tmpconfig" or
2971 dodie "failed to copy $minconfig to $tmpconfig";
2976 if (-f $tmpconfig) {
2977 load_force_config($tmpconfig);
2978 process_config_ignore $tmpconfig;
2981 # now process the start config
2982 run_command "cp $start_config $output_config" or
2983 dodie "failed to copy $start_config to $output_config";
2985 # read directly what we want to check
2987 open (IN, $output_config)
2988 or dodie "failed to open $output_config";
2991 if (/^((CONFIG\S*)=.*)/) {
2992 $config_check{$2} = $1;
2997 # Now run oldconfig with the minconfig
3000 # check to see what we lost (or gained)
3001 open (IN, $output_config)
3002 or dodie "Failed to read $start_config";
3004 my %removed_configs;
3008 if (/^((CONFIG\S*)=.*)/) {
3009 # save off all options
3010 $config_set{$2} = $1;
3011 if (defined($config_check{$2})) {
3012 if (defined($config_ignore{$2})) {
3013 $removed_configs{$2} = $1;
3015 $config_list{$2} = $1;
3017 } elsif (!defined($config_ignore{$2})) {
3018 $added_configs{$2} = $1;
3019 $config_list{$2} = $1;
3021 } elsif (/^# ((CONFIG\S*).*)/) {
3022 # Keep these configs disabled
3023 $config_set{$2} = $1;
3024 $config_off{$2} = $1;
3029 my @confs = keys %removed_configs;
3031 doprint "Configs overridden by default configs and removed from check:\n";
3032 foreach my $config (@confs) {
3033 doprint " $config\n";
3036 @confs = keys %added_configs;
3038 doprint "Configs appearing in make oldconfig and added:\n";
3039 foreach my $config (@confs) {
3040 doprint " $config\n";
3047 @config_off_tmp = ();
3049 # Sometimes kconfig does weird things. We must make sure
3050 # that the config we autocreate has everything we need
3051 # to test, otherwise we may miss testing configs, or
3052 # may not be able to create a new config.
3053 # Here we create a config with everything set.
3054 create_config (keys %config_list);
3055 read_current_config \%config_test;
3056 foreach my $config (keys %config_list) {
3057 if (!defined($config_test{$config})) {
3060 doprint "Configs not produced by kconfig (will not be checked):\n";
3062 doprint " $config\n";
3063 delete $config_list{$config};
3068 if (defined($config_bisect_check) && $config_bisect_check) {
3069 doprint " Checking to make sure bad config with min config fails\n";
3070 create_config keys %config_list;
3071 $ret = run_config_bisect_test $config_bisect_type;
3073 doprint " FAILED! Bad config with min config boots fine\n";
3076 doprint " Bad config with min config fails as expected\n";
3080 $ret = run_config_bisect;
3083 return $ret if ($ret < 0);
3088 sub patchcheck_reboot {
3089 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3090 reboot_to_good $patchcheck_sleep_time;
3096 die "PATCHCHECK_START[$i] not defined\n"
3097 if (!defined($patchcheck_start));
3098 die "PATCHCHECK_TYPE[$i] not defined\n"
3099 if (!defined($patchcheck_type));
3101 my $start = $patchcheck_start;
3104 if (defined($patchcheck_end)) {
3105 $end = $patchcheck_end;
3108 # Get the true sha1's since we can use things like HEAD~3
3109 $start = get_sha1($start);
3110 $end = get_sha1($end);
3112 my $type = $patchcheck_type;
3114 # Can't have a test without having a test to run
3115 if ($type eq "test" && !defined($run_test)) {
3119 open (IN, "git log --pretty=oneline $end|") or
3120 dodie "could not get git list";
3126 $list[$#list+1] = $_;
3127 last if (/^$start/);
3131 if ($list[$#list] !~ /^$start/) {
3132 fail "SHA1 $start not found";
3135 # go backwards in the list
3136 @list = reverse @list;
3138 my $save_clean = $noclean;
3139 my %ignored_warnings;
3141 if (defined($ignore_warnings)) {
3142 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3143 $ignored_warnings{$sha1} = 1;
3148 foreach my $item (@list) {
3150 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3152 doprint "\nProcessing commit $item\n\n";
3154 run_command "git checkout $sha1" or
3155 die "Failed to checkout $sha1";
3157 # only clean on the first and last patch
3158 if ($item eq $list[0] ||
3159 $item eq $list[$#list]) {
3160 $noclean = $save_clean;
3165 if (defined($minconfig)) {
3166 build "useconfig:$minconfig" or return 0;
3168 # ?? no config to use?
3169 build "oldconfig" or return 0;
3172 # No need to do per patch checking if warnings file exists
3173 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3174 check_patch_buildlog $sha1 or return 0;
3177 check_buildlog or return 0;
3179 next if ($type eq "build");
3183 start_monitor_and_boot or $failed = 1;
3185 if (!$failed && $type ne "boot"){
3186 do_run_test or $failed = 1;
3189 return 0 if ($failed);
3209 # $config depends on $dep
3210 my ($config, $dep) = @_;
3212 if (defined($depends{$config})) {
3213 $depends{$config} .= " " . $dep;
3215 $depends{$config} = $dep;
3218 # record the number of configs depending on $dep
3219 if (defined $depcount{$dep}) {
3222 $depcount{$dep} = 1;
3226 # taken from streamline_config.pl
3238 if (! -f $kconfig) {
3239 doprint "file $kconfig does not exist, skipping\n";
3243 open(KIN, "$kconfig")
3244 or die "Can't open $kconfig";
3248 # Make sure that lines ending with \ continue
3250 $_ = $line . " " . $_;
3261 # collect any Kconfig sources
3262 if (/^source\s*"(.*)"/) {
3263 $kconfigs[$#kconfigs+1] = $1;
3267 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3271 for (my $i = 0; $i < $iflevel; $i++) {
3272 add_dep $config, $ifdeps[$i];
3275 # collect the depends for the config
3276 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3278 add_dep $config, $1;
3280 # Get the configs that select this config
3281 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3283 # selected by depends on config
3284 add_dep $1, $config;
3286 # Check for if statements
3287 } elsif (/^if\s+(.*\S)\s*$/) {
3289 # remove beginning and ending non text
3290 $deps =~ s/^[^a-zA-Z0-9_]*//;
3291 $deps =~ s/[^a-zA-Z0-9_]*$//;
3293 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3295 $ifdeps[$iflevel++] = join ':', @deps;
3297 } elsif (/^endif/) {
3299 $iflevel-- if ($iflevel);
3302 } elsif (/^\s*help\s*$/) {
3308 # read in any configs that were found.
3309 foreach $kconfig (@kconfigs) {
3310 if (!defined($read_kconfigs{$kconfig})) {
3311 $read_kconfigs{$kconfig} = 1;
3312 read_kconfig("$builddir/$kconfig");
3318 # find out which arch this is by the kconfig file
3319 open (IN, $output_config)
3320 or dodie "Failed to read $output_config";
3323 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3330 if (!defined($arch)) {
3331 doprint "Could not find arch from config file\n";
3332 doprint "no dependencies used\n";
3336 # arch is really the subarch, we need to know
3337 # what directory to look at.
3338 if ($arch eq "i386" || $arch eq "x86_64") {
3340 } elsif ($arch =~ /^tile/) {
3344 my $kconfig = "$builddir/arch/$arch/Kconfig";
3346 if (! -f $kconfig && $arch =~ /\d$/) {
3348 # some subarchs have numbers, truncate them
3350 $kconfig = "$builddir/arch/$arch/Kconfig";
3351 if (! -f $kconfig) {
3352 doprint "No idea what arch dir $orig is for\n";
3353 doprint "no dependencies used\n";
3358 read_kconfig($kconfig);
3361 sub read_config_list {
3365 or dodie "Failed to read $config";
3368 if (/^((CONFIG\S*)=.*)/) {
3369 if (!defined($config_ignore{$2})) {
3370 $config_list{$2} = $1;
3378 sub read_output_config {
3381 assign_configs \%config_ignore, $config;
3384 sub make_new_config {
3387 open (OUT, ">$output_config")
3388 or dodie "Failed to write $output_config";
3390 foreach my $config (@configs) {
3391 print OUT "$config\n";
3399 $config =~ s/CONFIG_//;
3407 my $kconfig = chomp_config $dep;
3409 $dep = $depends{"$kconfig"};
3411 # the dep string we have saves the dependencies as they
3412 # were found, including expressions like ! && ||. We
3413 # want to split this out into just an array of configs.
3415 my $valid = "A-Za-z_0-9";
3419 while ($dep =~ /[$valid]/) {
3421 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3422 my $conf = "CONFIG_" . $1;
3424 $configs[$#configs + 1] = $conf;
3426 $dep =~ s/^[^$valid]*[$valid]+//;
3428 die "this should never happen";
3438 my %processed_configs;
3439 my %nochange_config;
3441 sub test_this_config {
3446 # if we already processed this config, skip it
3447 if (defined($processed_configs{$config})) {
3450 $processed_configs{$config} = 1;
3452 # if this config failed during this round, skip it
3453 if (defined($nochange_config{$config})) {
3457 my $kconfig = chomp_config $config;
3459 # Test dependencies first
3460 if (defined($depends{"$kconfig"})) {
3461 my @parents = get_depends $config;
3462 foreach my $parent (@parents) {
3463 # if the parent is in the min config, check it first
3464 next if (!defined($min_configs{$parent}));
3465 $found = test_this_config($parent);
3466 if (defined($found)) {
3472 # Remove this config from the list of configs
3473 # do a make olddefconfig and then read the resulting
3474 # .config to make sure it is missing the config that
3476 my %configs = %min_configs;
3477 delete $configs{$config};
3478 make_new_config ((values %configs), (values %keep_configs));
3481 assign_configs \%configs, $output_config;
3483 return $config if (!defined($configs{$config}));
3485 doprint "disabling config $config did not change .config\n";
3487 $nochange_config{$config} = 1;
3492 sub make_min_config {
3495 my $type = $minconfig_type;
3496 if ($type ne "boot" && $type ne "test") {
3497 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3498 " make_min_config works only with 'boot' and 'test'\n" and return;
3501 if (!defined($output_minconfig)) {
3502 fail "OUTPUT_MIN_CONFIG not defined" and return;
3505 # If output_minconfig exists, and the start_minconfig
3506 # came from min_config, than ask if we should use
3508 if (-f $output_minconfig && !$start_minconfig_defined) {
3509 print "$output_minconfig exists\n";
3510 if (!defined($use_output_minconfig)) {
3511 if (read_yn " Use it as minconfig?") {
3512 $start_minconfig = $output_minconfig;
3514 } elsif ($use_output_minconfig > 0) {
3515 doprint "Using $output_minconfig as MIN_CONFIG\n";
3516 $start_minconfig = $output_minconfig;
3518 doprint "Set to still use MIN_CONFIG as starting point\n";
3522 if (!defined($start_minconfig)) {
3523 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3526 my $temp_config = "$tmpdir/temp_config";
3528 # First things first. We build an allnoconfig to find
3529 # out what the defaults are that we can't touch.
3530 # Some are selections, but we really can't handle selections.
3532 my $save_minconfig = $minconfig;
3535 run_command "$make allnoconfig" or return 0;
3539 process_config_ignore $output_config;
3541 undef %save_configs;
3544 if (defined($ignore_config)) {
3545 # make sure the file exists
3546 `touch $ignore_config`;
3547 assign_configs \%save_configs, $ignore_config;
3550 %keep_configs = %save_configs;
3552 doprint "Load initial configs from $start_minconfig\n";
3554 # Look at the current min configs, and save off all the
3555 # ones that were set via the allnoconfig
3556 assign_configs \%min_configs, $start_minconfig;
3558 my @config_keys = keys %min_configs;
3560 # All configs need a depcount
3561 foreach my $config (@config_keys) {
3562 my $kconfig = chomp_config $config;
3563 if (!defined $depcount{$kconfig}) {
3564 $depcount{$kconfig} = 0;
3568 # Remove anything that was set by the make allnoconfig
3569 # we shouldn't need them as they get set for us anyway.
3570 foreach my $config (@config_keys) {
3571 # Remove anything in the ignore_config
3572 if (defined($keep_configs{$config})) {
3573 my $file = $ignore_config;
3574 $file =~ s,.*/(.*?)$,$1,;
3575 doprint "$config set by $file ... ignored\n";
3576 delete $min_configs{$config};
3579 # But make sure the settings are the same. If a min config
3580 # sets a selection, we do not want to get rid of it if
3581 # it is not the same as what we have. Just move it into
3583 if (defined($config_ignore{$config})) {
3584 if ($config_ignore{$config} ne $min_configs{$config}) {
3585 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3586 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3587 $keep_configs{$config} = $min_configs{$config};
3589 doprint "$config set by allnoconfig ... ignored\n";
3591 delete $min_configs{$config};
3603 # Now disable each config one by one and do a make oldconfig
3604 # till we find a config that changes our list.
3606 my @test_configs = keys %min_configs;
3608 # Sort keys by who is most dependent on
3609 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3612 # Put configs that did not modify the config at the end.
3614 for (my $i = 0; $i < $#test_configs; $i++) {
3615 if (!defined($nochange_config{$test_configs[0]})) {
3619 # This config didn't change the .config last time.
3620 # Place it at the end
3621 my $config = shift @test_configs;
3622 push @test_configs, $config;
3625 # if every test config has failed to modify the .config file
3626 # in the past, then reset and start over.
3628 undef %nochange_config;
3631 undef %processed_configs;
3633 foreach my $config (@test_configs) {
3635 $found = test_this_config $config;
3637 last if (defined($found));
3639 # oh well, try another config
3642 if (!defined($found)) {
3643 # we could have failed due to the nochange_config hash
3644 # reset and try again
3646 undef %nochange_config;
3650 doprint "No more configs found that we can disable\n";
3658 doprint "Test with $config disabled\n";
3660 # set in_bisect to keep build and monitor from dieing
3664 build "oldconfig" or $failed = 1;
3666 start_monitor_and_boot or $failed = 1;
3668 if ($type eq "test" && !$failed) {
3669 do_run_test or $failed = 1;
3678 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3679 # this config is needed, add it to the ignore list.
3680 $keep_configs{$config} = $min_configs{$config};
3681 $save_configs{$config} = $min_configs{$config};
3682 delete $min_configs{$config};
3684 # update new ignore configs
3685 if (defined($ignore_config)) {
3686 open (OUT, ">$temp_config")
3687 or die "Can't write to $temp_config";
3688 foreach my $config (keys %save_configs) {
3689 print OUT "$save_configs{$config}\n";
3692 run_command "mv $temp_config $ignore_config" or
3693 dodie "failed to copy update to $ignore_config";
3697 # We booted without this config, remove it from the minconfigs.
3698 doprint "$config is not needed, disabling\n";
3700 delete $min_configs{$config};
3702 # Also disable anything that is not enabled in this config
3704 assign_configs \%configs, $output_config;
3705 my @config_keys = keys %min_configs;
3706 foreach my $config (@config_keys) {
3707 if (!defined($configs{$config})) {
3708 doprint "$config is not set, disabling\n";
3709 delete $min_configs{$config};
3713 # Save off all the current mandidory configs
3714 open (OUT, ">$temp_config")
3715 or die "Can't write to $temp_config";
3716 foreach my $config (keys %keep_configs) {
3717 print OUT "$keep_configs{$config}\n";
3719 foreach my $config (keys %min_configs) {
3720 print OUT "$min_configs{$config}\n";
3724 run_command "mv $temp_config $output_minconfig" or
3725 dodie "failed to copy update to $output_minconfig";
3728 doprint "Reboot and wait $sleep_time seconds\n";
3729 reboot_to_good $sleep_time;
3736 sub make_warnings_file {
3739 if (!defined($warnings_file)) {
3740 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3743 if ($build_type eq "nobuild") {
3744 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3747 build $build_type or dodie "Failed to build";
3749 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3751 open(IN, $buildlog) or dodie "Can't open $buildlog";
3754 # Some compilers use UTF-8 extended for quotes
3755 # for distcc heterogeneous systems, this causes issues
3758 if (/$check_build_re/) {
3769 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3772 $ktest_config = $ARGV[0];
3773 if (! -f $ktest_config) {
3774 print "$ktest_config does not exist.\n";
3775 if (!read_yn "Create it?") {
3780 $ktest_config = "ktest.conf";
3783 if (! -f $ktest_config) {
3786 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3788 # Generated by ktest.pl
3791 # PWD is a ktest.pl variable that will result in the process working
3792 # directory that ktest.pl is executed in.
3794 # THIS_DIR is automatically assigned the PWD of the path that generated
3795 # the config file. It is best to use this variable when assigning other
3796 # directory paths within this directory. This allows you to easily
3797 # move the test cases to other locations or to other machines.
3799 THIS_DIR := $variable{"PWD"}
3801 # Define each test with TEST_START
3802 # The config options below it will override the defaults
3804 TEST_TYPE = $default{"TEST_TYPE"}
3811 read_config $ktest_config;
3813 if (defined($opt{"LOG_FILE"})) {
3814 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
3817 # Append any configs entered in manually to the config file.
3818 my @new_configs = keys %entered_configs;
3819 if ($#new_configs >= 0) {
3820 print "\nAppending entered in configs to $ktest_config\n";
3821 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3822 foreach my $config (@new_configs) {
3823 print OUT "$config = $entered_configs{$config}\n";
3824 $opt{$config} = process_variables($entered_configs{$config});
3828 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3829 unlink $opt{"LOG_FILE"};
3832 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3834 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3837 doprint "DEFAULT OPTIONS:\n";
3839 doprint "\nTEST $i OPTIONS";
3840 if (defined($repeat_tests{$i})) {
3841 $repeat = $repeat_tests{$i};
3842 doprint " ITERATE $repeat";
3847 foreach my $option (sort keys %opt) {
3849 if ($option =~ /\[(\d+)\]$/) {
3855 doprint "$option = $opt{$option}\n";
3859 sub __set_test_option {
3860 my ($name, $i) = @_;
3862 my $option = "$name\[$i\]";
3864 if (defined($opt{$option})) {
3865 return $opt{$option};
3868 foreach my $test (keys %repeat_tests) {
3870 $i < $test + $repeat_tests{$test}) {
3871 $option = "$name\[$test\]";
3872 if (defined($opt{$option})) {
3873 return $opt{$option};
3878 if (defined($opt{$name})) {
3885 sub set_test_option {
3886 my ($name, $i) = @_;
3888 my $option = __set_test_option($name, $i);
3889 return $option if (!defined($option));
3891 return eval_option($name, $option, $i);
3894 # First we need to do is the builds
3895 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3897 # Do not reboot on failing test options
3899 $reboot_success = 0;
3905 undef %force_config;
3907 my $makecmd = set_test_option("MAKE_CMD", $i);
3909 # Load all the options into their mapped variable names
3910 foreach my $opt (keys %option_map) {
3911 ${$option_map{$opt}} = set_test_option($opt, $i);
3914 $start_minconfig_defined = 1;
3916 # The first test may override the PRE_KTEST option
3917 if (defined($pre_ktest) && $i == 1) {
3919 run_command $pre_ktest;
3922 # Any test can override the POST_KTEST option
3923 # The last test takes precedence.
3924 if (defined($post_ktest)) {
3925 $final_post_ktest = $post_ktest;
3928 if (!defined($start_minconfig)) {
3929 $start_minconfig_defined = 0;
3930 $start_minconfig = $minconfig;
3933 chdir $builddir || die "can't change directory to $builddir";
3935 foreach my $dir ($tmpdir, $outputdir) {
3938 die "can't create $dir";
3942 $ENV{"SSH_USER"} = $ssh_user;
3943 $ENV{"MACHINE"} = $machine;
3945 $buildlog = "$tmpdir/buildlog-$machine";
3946 $testlog = "$tmpdir/testlog-$machine";
3947 $dmesg = "$tmpdir/dmesg-$machine";
3948 $make = "$makecmd O=$outputdir";
3949 $output_config = "$outputdir/.config";
3952 $target = "$ssh_user\@$machine";
3953 if ($reboot_type eq "grub") {
3954 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3955 } elsif ($reboot_type eq "grub2") {
3956 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3957 dodie "GRUB_FILE not defined" if (!defined($grub_file));
3958 } elsif ($reboot_type eq "syslinux") {
3959 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
3963 my $run_type = $build_type;
3964 if ($test_type eq "patchcheck") {
3965 $run_type = $patchcheck_type;
3966 } elsif ($test_type eq "bisect") {
3967 $run_type = $bisect_type;
3968 } elsif ($test_type eq "config_bisect") {
3969 $run_type = $config_bisect_type;
3970 } elsif ($test_type eq "make_min_config") {
3972 } elsif ($test_type eq "make_warnings_file") {
3976 # mistake in config file?
3977 if (!defined($run_type)) {
3978 $run_type = "ERROR";
3982 $installme = " no_install" if ($no_install);
3985 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3987 if (defined($pre_test)) {
3988 run_command $pre_test;
3995 if (defined($addconfig)) {
3996 my $min = $minconfig;
3997 if (!defined($minconfig)) {
4000 run_command "cat $addconfig $min > $tmpdir/add_config" or
4001 dodie "Failed to create temp config";
4002 $minconfig = "$tmpdir/add_config";
4005 if (defined($checkout)) {
4006 run_command "git checkout $checkout" or
4007 die "failed to checkout $checkout";
4012 # A test may opt to not reboot the box
4013 if ($reboot_on_success) {
4014 $reboot_success = 1;
4017 if ($test_type eq "bisect") {
4020 } elsif ($test_type eq "config_bisect") {
4023 } elsif ($test_type eq "patchcheck") {
4026 } elsif ($test_type eq "make_min_config") {
4029 } elsif ($test_type eq "make_warnings_file") {
4031 make_warnings_file $i;
4035 if ($build_type ne "nobuild") {
4036 build $build_type or next;
4037 check_buildlog or next;
4040 if ($test_type eq "install") {
4047 if ($test_type ne "build") {
4049 start_monitor_and_boot or $failed = 1;
4051 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4052 do_run_test or $failed = 1;
4061 if (defined($final_post_ktest)) {
4062 run_command $final_post_ktest;
4065 if ($opt{"POWEROFF_ON_SUCCESS"}) {
4067 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4069 } elsif (defined($switch_to_good)) {
4070 # still need to get to the good kernel
4071 run_command $switch_to_good;
4075 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";