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",
101 my $poweroff_on_error;
102 my $reboot_on_success;
104 my $powercycle_after_reboot;
105 my $poweroff_after_halt;
106 my $max_monitor_wait;
109 my $scp_to_target_install;
127 my $start_minconfig_defined;
128 my $output_minconfig;
130 my $use_output_minconfig;
136 my $bisect_bad_commit = "";
140 my $config_bisect_good;
144 my $bisect_ret_abort;
145 my $bisect_ret_default;
146 my $in_patchcheck = 0;
156 my $bisect_sleep_time;
157 my $patchcheck_sleep_time;
164 my $detect_triplefault;
166 my $reboot_success_line;
168 my $stop_after_success;
169 my $stop_after_failure;
188 my $config_bisect_type;
189 my $config_bisect_check;
192 my $patchcheck_start;
195 # set when a test is something other that just building or install
196 # which would require more options.
199 # tell build not to worry about warnings, even when WARNINGS_FILE is set
202 # set when creating a new config
209 # force_config is the list of configs that we force enabled (or disabled)
210 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
213 # do not force reboots on config problems
217 my $reboot_success = 0;
220 "MACHINE" => \$machine,
221 "SSH_USER" => \$ssh_user,
222 "TMP_DIR" => \$tmpdir,
223 "OUTPUT_DIR" => \$outputdir,
224 "BUILD_DIR" => \$builddir,
225 "TEST_TYPE" => \$test_type,
226 "PRE_KTEST" => \$pre_ktest,
227 "POST_KTEST" => \$post_ktest,
228 "PRE_TEST" => \$pre_test,
229 "POST_TEST" => \$post_test,
230 "BUILD_TYPE" => \$build_type,
231 "BUILD_OPTIONS" => \$build_options,
232 "PRE_BUILD" => \$pre_build,
233 "POST_BUILD" => \$post_build,
234 "PRE_BUILD_DIE" => \$pre_build_die,
235 "POST_BUILD_DIE" => \$post_build_die,
236 "POWER_CYCLE" => \$power_cycle,
237 "REBOOT" => \$reboot,
238 "BUILD_NOCLEAN" => \$noclean,
239 "MIN_CONFIG" => \$minconfig,
240 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
241 "START_MIN_CONFIG" => \$start_minconfig,
242 "MIN_CONFIG_TYPE" => \$minconfig_type,
243 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
244 "WARNINGS_FILE" => \$warnings_file,
245 "IGNORE_CONFIG" => \$ignore_config,
246 "TEST" => \$run_test,
247 "ADD_CONFIG" => \$addconfig,
248 "REBOOT_TYPE" => \$reboot_type,
249 "GRUB_MENU" => \$grub_menu,
250 "GRUB_FILE" => \$grub_file,
251 "GRUB_REBOOT" => \$grub_reboot,
252 "SYSLINUX" => \$syslinux,
253 "SYSLINUX_PATH" => \$syslinux_path,
254 "SYSLINUX_LABEL" => \$syslinux_label,
255 "PRE_INSTALL" => \$pre_install,
256 "POST_INSTALL" => \$post_install,
257 "NO_INSTALL" => \$no_install,
258 "REBOOT_SCRIPT" => \$reboot_script,
259 "REBOOT_ON_ERROR" => \$reboot_on_error,
260 "SWITCH_TO_GOOD" => \$switch_to_good,
261 "SWITCH_TO_TEST" => \$switch_to_test,
262 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
263 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
264 "DIE_ON_FAILURE" => \$die_on_failure,
265 "POWER_OFF" => \$power_off,
266 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
267 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
268 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
269 "SLEEP_TIME" => \$sleep_time,
270 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
271 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
272 "IGNORE_WARNINGS" => \$ignore_warnings,
273 "IGNORE_ERRORS" => \$ignore_errors,
274 "BISECT_MANUAL" => \$bisect_manual,
275 "BISECT_SKIP" => \$bisect_skip,
276 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
277 "BISECT_RET_GOOD" => \$bisect_ret_good,
278 "BISECT_RET_BAD" => \$bisect_ret_bad,
279 "BISECT_RET_SKIP" => \$bisect_ret_skip,
280 "BISECT_RET_ABORT" => \$bisect_ret_abort,
281 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
282 "STORE_FAILURES" => \$store_failures,
283 "STORE_SUCCESSES" => \$store_successes,
284 "TEST_NAME" => \$test_name,
285 "TIMEOUT" => \$timeout,
286 "BOOTED_TIMEOUT" => \$booted_timeout,
287 "CONSOLE" => \$console,
288 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
289 "SUCCESS_LINE" => \$success_line,
290 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
291 "STOP_AFTER_SUCCESS" => \$stop_after_success,
292 "STOP_AFTER_FAILURE" => \$stop_after_failure,
293 "STOP_TEST_AFTER" => \$stop_test_after,
294 "BUILD_TARGET" => \$build_target,
295 "SSH_EXEC" => \$ssh_exec,
296 "SCP_TO_TARGET" => \$scp_to_target,
297 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
298 "CHECKOUT" => \$checkout,
299 "TARGET_IMAGE" => \$target_image,
300 "LOCALVERSION" => \$localversion,
302 "BISECT_GOOD" => \$bisect_good,
303 "BISECT_BAD" => \$bisect_bad,
304 "BISECT_TYPE" => \$bisect_type,
305 "BISECT_START" => \$bisect_start,
306 "BISECT_REPLAY" => \$bisect_replay,
307 "BISECT_FILES" => \$bisect_files,
308 "BISECT_REVERSE" => \$bisect_reverse,
309 "BISECT_CHECK" => \$bisect_check,
311 "CONFIG_BISECT" => \$config_bisect,
312 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
313 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
315 "PATCHCHECK_TYPE" => \$patchcheck_type,
316 "PATCHCHECK_START" => \$patchcheck_start,
317 "PATCHCHECK_END" => \$patchcheck_end,
320 # Options may be used by other options, record them.
323 # default variables that can be used
324 chomp ($variable{"PWD"} = `pwd`);
326 $config_help{"MACHINE"} = << "EOF"
327 The machine hostname that you will test.
328 For build only tests, it is still needed to differentiate log files.
331 $config_help{"SSH_USER"} = << "EOF"
332 The box is expected to have ssh on normal bootup, provide the user
333 (most likely root, since you need privileged operations)
336 $config_help{"BUILD_DIR"} = << "EOF"
337 The directory that contains the Linux source code (full path).
338 You can use \${PWD} that will be the path where ktest.pl is run, or use
339 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
342 $config_help{"OUTPUT_DIR"} = << "EOF"
343 The directory that the objects will be built (full path).
344 (can not be same as BUILD_DIR)
345 You can use \${PWD} that will be the path where ktest.pl is run, or use
346 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
349 $config_help{"BUILD_TARGET"} = << "EOF"
350 The location of the compiled file to copy to the target.
351 (relative to OUTPUT_DIR)
354 $config_help{"BUILD_OPTIONS"} = << "EOF"
355 Options to add to \"make\" when building.
359 $config_help{"TARGET_IMAGE"} = << "EOF"
360 The place to put your image on the test machine.
363 $config_help{"POWER_CYCLE"} = << "EOF"
364 A script or command to reboot the box.
366 Here is a digital loggers power switch example
367 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
369 Here is an example to reboot a virtual box on the current host
370 with the name "Guest".
371 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
374 $config_help{"CONSOLE"} = << "EOF"
375 The script or command that reads the console
377 If you use ttywatch server, something like the following would work.
378 CONSOLE = nc -d localhost 3001
380 For a virtual machine with guest name "Guest".
381 CONSOLE = virsh console Guest
384 $config_help{"LOCALVERSION"} = << "EOF"
385 Required version ending to differentiate the test
386 from other linux builds on the system.
389 $config_help{"REBOOT_TYPE"} = << "EOF"
390 Way to reboot the box to the test kernel.
391 Only valid options so far are "grub", "grub2", "syslinux", and "script".
393 If you specify grub, it will assume grub version 1
394 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
395 and select that target to reboot to the kernel. If this is not
396 your setup, then specify "script" and have a command or script
397 specified in REBOOT_SCRIPT to boot to the target.
399 The entry in /boot/grub/menu.lst must be entered in manually.
400 The test will not modify that file.
402 If you specify grub2, then you also need to specify both \$GRUB_MENU
405 If you specify syslinux, then you may use SYSLINUX to define the syslinux
406 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
407 the syslinux install (defaults to /boot/extlinux). But you have to specify
408 SYSLINUX_LABEL to define the label to boot to for the test kernel.
411 $config_help{"GRUB_MENU"} = << "EOF"
412 The grub title name for the test kernel to boot
413 (Only mandatory if REBOOT_TYPE = grub or grub2)
415 Note, ktest.pl will not update the grub menu.lst, you need to
416 manually add an option for the test. ktest.pl will search
417 the grub menu.lst for this option to find what kernel to
420 For example, if in the /boot/grub/menu.lst the test kernel title has:
423 GRUB_MENU = Test Kernel
425 For grub2, a search of \$GRUB_FILE is performed for the lines
426 that begin with "menuentry". It will not detect submenus. The
427 menu must be a non-nested menu. Add the quotes used in the menu
428 to guarantee your selection, as the first menuentry with the content
429 of \$GRUB_MENU that is found will be used.
432 $config_help{"GRUB_FILE"} = << "EOF"
433 If grub2 is used, the full path for the grub.cfg file is placed
434 here. Use something like /boot/grub2/grub.cfg to search.
437 $config_help{"SYSLINUX_LABEL"} = << "EOF"
438 If syslinux is used, the label that boots the target kernel must
439 be specified with SYSLINUX_LABEL.
442 $config_help{"REBOOT_SCRIPT"} = << "EOF"
443 A script to reboot the target into the test kernel
444 (Only mandatory if REBOOT_TYPE = script)
449 my ($cancel, $prompt) = @_;
455 print "$prompt [y/n/C] ";
457 print "$prompt [Y/n] ";
461 if ($ans =~ /^\s*$/) {
468 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
470 last if ($ans =~ /^c$/i);
471 print "Please answer either 'y', 'n' or 'c'.\n";
473 print "Please answer either 'y' or 'n'.\n";
479 if ($ans !~ /^y$/i) {
488 return read_prompt 0, $prompt;
494 return read_prompt 1, $prompt;
497 sub get_ktest_config {
501 return if (defined($opt{$config}));
503 if (defined($config_help{$config})) {
505 print $config_help{$config};
510 if (defined($default{$config}) && length($default{$config})) {
511 print "\[$default{$config}\] ";
514 $ans =~ s/^\s*(.*\S)\s*$/$1/;
515 if ($ans =~ /^\s*$/) {
516 if ($default{$config}) {
517 $ans = $default{$config};
519 print "Your answer can not be blank\n";
523 $entered_configs{$config} = ${ans};
528 sub get_ktest_configs {
529 get_ktest_config("MACHINE");
530 get_ktest_config("BUILD_DIR");
531 get_ktest_config("OUTPUT_DIR");
534 get_ktest_config("BUILD_OPTIONS");
537 # options required for other than just building a kernel
539 get_ktest_config("POWER_CYCLE");
540 get_ktest_config("CONSOLE");
543 # options required for install and more
544 if ($buildonly != 1) {
545 get_ktest_config("SSH_USER");
546 get_ktest_config("BUILD_TARGET");
547 get_ktest_config("TARGET_IMAGE");
550 get_ktest_config("LOCALVERSION");
552 return if ($buildonly);
554 my $rtype = $opt{"REBOOT_TYPE"};
556 if (!defined($rtype)) {
557 if (!defined($opt{"GRUB_MENU"})) {
558 get_ktest_config("REBOOT_TYPE");
559 $rtype = $entered_configs{"REBOOT_TYPE"};
565 if ($rtype eq "grub") {
566 get_ktest_config("GRUB_MENU");
569 if ($rtype eq "grub2") {
570 get_ktest_config("GRUB_MENU");
571 get_ktest_config("GRUB_FILE");
574 if ($rtype eq "syslinux") {
575 get_ktest_config("SYSLINUX_LABEL");
579 sub process_variables {
580 my ($value, $remove_undef) = @_;
583 # We want to check for '\', and it is just easier
584 # to check the previous characet of '$' and not need
585 # to worry if '$' is the first character. By adding
586 # a space to $value, we can just check [^\\]\$ and
587 # it will still work.
590 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
594 # append beginning of value to retval
595 $retval = "$retval$begin";
596 if (defined($variable{$var})) {
597 $retval = "$retval$variable{$var}";
598 } elsif (defined($remove_undef) && $remove_undef) {
599 # for if statements, any variable that is not defined,
600 # we simple convert to 0
601 $retval = "${retval}0";
603 # put back the origin piece.
604 $retval = "$retval\$\{$var\}";
605 # This could be an option that is used later, save
606 # it so we don't warn if this option is not one of
608 $used_options{$var} = 1;
612 $retval = "$retval$value";
614 # remove the space added in the beginning
621 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
623 my $prvalue = process_variables($rvalue);
625 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
626 # Note if a test is something other than build, then we
627 # will need other manditory options.
628 if ($prvalue ne "install") {
629 # for bisect, we need to check BISECT_TYPE
630 if ($prvalue ne "bisect") {
634 # install still limits some manditory options.
639 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
640 if ($prvalue ne "install") {
643 # install still limits some manditory options.
648 if (defined($opt{$lvalue})) {
649 if (!$override || defined(${$overrides}{$lvalue})) {
652 $extra = "In the same override section!\n";
654 die "$name: $.: Option $lvalue defined more than once!\n$extra";
656 ${$overrides}{$lvalue} = $prvalue;
658 if ($rvalue =~ /^\s*$/) {
659 delete $opt{$lvalue};
661 $opt{$lvalue} = $prvalue;
666 my ($lvalue, $rvalue) = @_;
668 if ($rvalue =~ /^\s*$/) {
669 delete $variable{$lvalue};
671 $rvalue = process_variables($rvalue);
672 $variable{$lvalue} = $rvalue;
676 sub process_compare {
677 my ($lval, $cmp, $rval) = @_;
688 return $lval eq $rval;
689 } elsif ($cmp eq "!=") {
690 return $lval ne $rval;
691 } elsif ($cmp eq "=~") {
692 return $lval =~ m/$rval/;
693 } elsif ($cmp eq "!~") {
694 return $lval !~ m/$rval/;
697 my $statement = "$lval $cmp $rval";
698 my $ret = eval $statement;
700 # $@ stores error of eval
711 return defined($variable{$2}) ||
716 sub process_expression {
717 my ($name, $val) = @_;
721 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
724 if (process_expression($name, $express)) {
725 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
727 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
735 while ($val =~ s/^(.*?)($OR|$AND)//) {
739 if (process_expression($name, $express)) {
750 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
751 my $ret = process_compare($1, $2, $3);
753 die "$name: $.: Unable to process comparison\n";
758 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
760 return !value_defined($2);
762 return value_defined($2);
766 if ($val =~ /^\s*0\s*$/) {
768 } elsif ($val =~ /^\s*\d+\s*$/) {
772 die ("$name: $.: Undefined content $val in if statement\n");
776 my ($name, $value) = @_;
778 # Convert variables and replace undefined ones with 0
779 my $val = process_variables($value, 1);
780 my $ret = process_expression $name, $val;
786 my ($config, $current_test_num) = @_;
789 open($in, $config) || die "can't read file $config";
792 $name =~ s,.*/(.*),$1,;
794 my $test_num = $$current_test_num;
797 my $num_tests_set = 0;
810 # ignore blank lines and comments
811 next if (/^\s*$/ || /\s*\#/);
813 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
823 if ($type eq "TEST_START") {
825 if ($num_tests_set) {
826 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
829 $old_test_num = $test_num;
830 $old_repeat = $repeat;
832 $test_num += $repeat;
839 # If SKIP is anywhere in the line, the command will be skipped
840 if ($rest =~ s/\s+SKIP\b//) {
847 if ($rest =~ s/\sELSE\b//) {
849 die "$name: $.: ELSE found with out matching IF section\n$_";
860 if ($rest =~ s/\sIF\s+(.*)//) {
861 if (process_if($name, $1)) {
873 if ($type eq "TEST_START") {
874 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
876 $repeat_tests{"$test_num"} = $repeat;
878 } elsif ($rest =~ s/\sOVERRIDE\b//) {
881 # Clear previous overrides
886 if (!$skip && $rest !~ /^\s*$/) {
887 die "$name: $.: Gargbage found after $type\n$_";
890 if ($skip && $type eq "TEST_START") {
891 $test_num = $old_test_num;
892 $repeat = $old_repeat;
895 } elsif (/^\s*ELSE\b(.*)$/) {
897 die "$name: $.: ELSE found with out matching IF section\n$_";
906 if ($rest =~ /\sIF\s+(.*)/) {
907 # May be a ELSE IF section.
908 if (process_if($name, $1)) {
919 if ($rest !~ /^\s*$/) {
920 die "$name: $.: Gargbage found after DEFAULTS\n$_";
923 } elsif (/^\s*INCLUDE\s+(\S+)/) {
928 die "$name: $.: INCLUDE can only be done in default sections\n$_";
931 my $file = process_variables($1);
933 if ($file !~ m,^/,) {
934 # check the path of the config file first
935 if ($config =~ m,(.*)/,) {
943 die "$name: $.: Can't read file $file\n$_";
946 if (__read_config($file, \$test_num)) {
950 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
958 ($lvalue eq "NUM_TESTS" ||
959 $lvalue eq "LOG_FILE" ||
960 $lvalue eq "CLEAR_LOG")) {
961 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
964 if ($lvalue eq "NUM_TESTS") {
966 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
969 die "$name: $.: NUM_TESTS must be set in default section\n";
974 if ($default || $lvalue =~ /\[\d+\]$/) {
975 set_value($lvalue, $rvalue, $override, \%overrides, $name);
977 my $val = "$lvalue\[$test_num\]";
978 set_value($val, $rvalue, $override, \%overrides, $name);
981 $repeats{$val} = $repeat;
984 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
990 # process config variables.
991 # Config variables are only active while reading the
992 # config and can be defined anywhere. They also ignore
993 # TEST_START and DEFAULTS, but are skipped if they are in
994 # on of these sections that have SKIP defined.
995 # The save variable can be
996 # defined multiple times and the new one simply overrides
998 set_variable($lvalue, $rvalue);
1001 die "$name: $.: Garbage found in config\n$_";
1006 $test_num += $repeat - 1;
1007 $opt{"NUM_TESTS"} = $test_num;
1012 $$current_test_num = $test_num;
1018 print "What test case would you like to run?\n";
1019 print " (build, install or boot)\n";
1020 print " Other tests are available but require editing the config file\n";
1023 $default{"TEST_TYPE"} = $ans;
1032 $test_case = __read_config $config, \$test_num;
1034 # make sure we have all mandatory configs
1037 # was a test specified?
1039 print "No test case specified.\n";
1045 foreach my $default (keys %default) {
1046 if (!defined($opt{$default})) {
1047 $opt{$default} = $default{$default};
1051 if ($opt{"IGNORE_UNUSED"} == 1) {
1057 # check if there are any stragglers (typos?)
1058 foreach my $option (keys %opt) {
1060 # remove per test labels.
1062 if (!exists($option_map{$op}) &&
1063 !exists($default{$op}) &&
1064 !exists($used_options{$op})) {
1071 $s = " is" if (keys %not_used == 1);
1072 print "The following option$s not used; could be a typo:\n";
1073 foreach my $option (keys %not_used) {
1076 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1077 if (!read_yn "Do you want to continue?") {
1084 my ($name, $option, $i) = @_;
1086 # Add space to evaluate the character before $
1087 $option = " $option";
1092 foreach my $test (keys %repeat_tests) {
1094 $i < $test + $repeat_tests{$test}) {
1102 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1107 # Append beginning of line
1108 $retval = "$retval$start";
1110 # If the iteration option OPT[$i] exists, then use that.
1111 # otherwise see if the default OPT (without [$i]) exists.
1113 my $o = "$var\[$i\]";
1114 my $parento = "$var\[$parent\]";
1116 # If a variable contains itself, use the default var
1117 if (($var eq $name) && defined($opt{$var})) {
1119 $retval = "$retval$o";
1120 } elsif (defined($opt{$o})) {
1122 $retval = "$retval$o";
1123 } elsif ($repeated && defined($opt{$parento})) {
1124 $o = $opt{$parento};
1125 $retval = "$retval$o";
1126 } elsif (defined($opt{$var})) {
1128 $retval = "$retval$o";
1130 $retval = "$retval\$\{$var\}";
1136 $retval = "$retval$option";
1144 my ($name, $option, $i) = @_;
1148 # Since an option can evaluate to another option,
1149 # keep iterating until we do not evaluate any more
1152 while ($prev ne $option) {
1153 # Check for recursive evaluations.
1154 # 100 deep should be more than enough.
1156 die "Over 100 evaluations accurred with $option\n" .
1157 "Check for recursive variables\n";
1160 $option = __eval_option($name, $option, $i);
1167 if (defined($opt{"LOG_FILE"})) {
1168 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1175 if (defined($opt{"LOG_FILE"})) {
1190 sub wait_for_monitor;
1195 # Make sure everything has been written to disk
1198 if (defined($time)) {
1200 # flush out current monitor
1201 # May contain the reboot success line
1205 # try to reboot normally
1206 if (run_command $reboot) {
1207 if (defined($powercycle_after_reboot)) {
1208 sleep $powercycle_after_reboot;
1209 run_command "$power_cycle";
1212 # nope? power cycle it.
1213 run_command "$power_cycle";
1216 if (defined($time)) {
1218 # We only want to get to the new kernel, don't fail
1219 # if we stumble over a call trace.
1220 my $save_ignore_errors = $ignore_errors;
1223 # Look for the good kernel to boot
1224 if (wait_for_monitor($time, "Linux version")) {
1226 doprint "Reboot did not finish. Forcing power cycle\n";
1227 run_command "$power_cycle";
1230 $ignore_errors = $save_ignore_errors;
1232 # Still need to wait for the reboot to finish
1233 wait_for_monitor($time, $reboot_success_line);
1239 sub reboot_to_good {
1242 if (defined($switch_to_good)) {
1243 run_command $switch_to_good;
1252 return $test_type eq "build" || $no_reboot ||
1253 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1254 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1258 doprint "CRITICAL FAILURE... ", @_, "\n";
1262 if ($reboot_on_error && !do_not_reboot) {
1264 doprint "REBOOTING\n";
1267 } elsif ($poweroff_on_error && defined($power_off)) {
1268 doprint "POWERING OFF\n";
1272 if (defined($opt{"LOG_FILE"})) {
1273 print " See $opt{LOG_FILE} for more info.\n";
1284 my $pid = open($fp, "$console|") or
1285 dodie "Can't open console $console";
1287 $flags = fcntl($fp, F_GETFL, 0) or
1288 dodie "Can't get flags for the socket: $!";
1289 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1290 dodie "Can't set flags for the socket: $!";
1296 my ($fp, $pid) = @_;
1298 doprint "kill child process $pid\n";
1306 if ($monitor_cnt++) {
1309 $monitor_fp = \*MONFD;
1310 $monitor_pid = open_console $monitor_fp;
1314 open(MONFD, "Stop perl from warning about single use of MONFD");
1318 return if (!defined $console);
1319 if (--$monitor_cnt) {
1322 close_console($monitor_fp, $monitor_pid);
1325 sub wait_for_monitor {
1326 my ($time, $stop) = @_;
1330 my $start_time = time;
1331 my $skip_call_trace = 0;
1333 my $bug_ignored = 0;
1336 doprint "** Wait for monitor to settle down **\n";
1338 # read the monitor and wait for the system to calm down
1340 $line = wait_for_input($monitor_fp, $time);
1341 last if (!defined($line));
1343 $full_line .= $line;
1345 if (defined($stop) && $full_line =~ /$stop/) {
1346 doprint "wait for monitor detected $stop\n";
1350 if ($full_line =~ /\[ backtrace testing \]/) {
1351 $skip_call_trace = 1;
1354 if ($full_line =~ /call trace:/i) {
1355 if (!$bug && !$skip_call_trace) {
1356 if ($ignore_errors) {
1364 if ($full_line =~ /\[ end of backtrace testing \]/) {
1365 $skip_call_trace = 0;
1368 if ($full_line =~ /Kernel panic -/) {
1372 if ($line =~ /\n/) {
1376 if ($now - $start_time >= $max_monitor_wait) {
1377 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1381 print "** Monitor flushed **\n";
1386 my ($result, $basedir) = @_;
1388 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1389 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1391 my $type = $build_type;
1392 if ($type =~ /useconfig/) {
1393 $type = "useconfig";
1396 my $dir = "$machine-$test_type-$type-$result-$date";
1398 $dir = "$basedir/$dir";
1402 die "can't create $dir";
1406 "config" => $output_config,
1407 "buildlog" => $buildlog,
1409 "testlog" => $testlog,
1412 while (my ($name, $source) = each(%files)) {
1414 cp "$source", "$dir/$name" or
1415 die "failed to copy $source";
1419 doprint "*** Saved info to $dir ***\n";
1424 if (defined($post_test)) {
1425 run_command $post_test;
1428 if ($die_on_failure) {
1436 # no need to reboot for just building.
1437 if (!do_not_reboot) {
1438 doprint "REBOOTING\n";
1439 reboot_to_good $sleep_time;
1444 if (defined($test_name)) {
1445 $name = " ($test_name)";
1448 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1449 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1450 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1451 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1452 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1454 if (defined($store_failures)) {
1455 save_logs "fail", $store_failures;
1467 $command =~ s/\$SSH_USER/$ssh_user/g;
1468 $command =~ s/\$MACHINE/$machine/g;
1470 doprint("$command ... ");
1472 $pid = open(CMD, "$command 2>&1 |") or
1473 (fail "unable to exec $command" and return 0);
1475 if (defined($opt{"LOG_FILE"})) {
1476 open(LOG, ">>$opt{LOG_FILE}") or
1477 dodie "failed to write to log";
1481 if (defined($redirect)) {
1482 open (RD, ">$redirect") or
1483 dodie "failed to write to redirect $redirect";
1488 print LOG if ($dolog);
1489 print RD if ($dord);
1496 close(LOG) if ($dolog);
1497 close(RD) if ($dord);
1500 doprint "FAILED!\n";
1502 doprint "SUCCESS\n";
1510 my $cp_exec = $ssh_exec;
1512 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1513 return run_command "$cp_exec";
1517 my ($src, $dst, $cp_scp) = @_;
1519 $cp_scp =~ s/\$SRC_FILE/$src/g;
1520 $cp_scp =~ s/\$DST_FILE/$dst/g;
1522 return run_command "$cp_scp";
1525 sub run_scp_install {
1526 my ($src, $dst) = @_;
1528 my $cp_scp = $scp_to_target_install;
1530 return run_scp($src, $dst, $cp_scp);
1534 my ($src, $dst) = @_;
1536 my $cp_scp = $scp_to_target;
1538 return run_scp($src, $dst, $cp_scp);
1541 sub get_grub2_index {
1543 return if (defined($grub_number) && defined($last_grub_menu) &&
1544 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1545 $last_machine eq $machine);
1547 doprint "Find grub2 menu ... ";
1550 my $ssh_grub = $ssh_exec;
1551 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1553 open(IN, "$ssh_grub |")
1554 or die "unable to get $grub_file";
1559 if (/^menuentry.*$grub_menu/) {
1563 } elsif (/^menuentry\s/) {
1569 die "Could not find '$grub_menu' in $grub_file on $machine"
1571 doprint "$grub_number\n";
1572 $last_grub_menu = $grub_menu;
1573 $last_machine = $machine;
1576 sub get_grub_index {
1578 if ($reboot_type eq "grub2") {
1583 if ($reboot_type ne "grub") {
1586 return if (defined($grub_number) && defined($last_grub_menu) &&
1587 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1588 $last_machine eq $machine);
1590 doprint "Find grub menu ... ";
1593 my $ssh_grub = $ssh_exec;
1594 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1596 open(IN, "$ssh_grub |")
1597 or die "unable to get menu.lst";
1602 if (/^\s*title\s+$grub_menu\s*$/) {
1606 } elsif (/^\s*title\s/) {
1612 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1614 doprint "$grub_number\n";
1615 $last_grub_menu = $grub_menu;
1616 $last_machine = $machine;
1621 my ($fp, $time) = @_;
1627 if (!defined($time)) {
1632 vec($rin, fileno($fp), 1) = 1;
1633 ($ready, $time) = select($rin, undef, undef, $time);
1637 # try to read one char at a time
1638 while (sysread $fp, $ch, 1) {
1640 last if ($ch eq "\n");
1643 if (!length($line)) {
1651 if (defined($switch_to_test)) {
1652 run_command $switch_to_test;
1655 if ($reboot_type eq "grub") {
1656 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1657 } elsif ($reboot_type eq "grub2") {
1658 run_ssh "$grub_reboot $grub_number";
1659 } elsif ($reboot_type eq "syslinux") {
1660 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
1661 } elsif (defined $reboot_script) {
1662 run_command "$reboot_script";
1670 doprint "git rev-list --max-count=1 $commit ... ";
1671 my $sha1 = `git rev-list --max-count=1 $commit`;
1678 dodie "Failed to get git $commit";
1691 my $bug_ignored = 0;
1692 my $skip_call_trace = 0;
1700 open(DMESG, "> $dmesg") or
1701 die "unable to write to $dmesg";
1707 my $monitor_start = time;
1709 my $version_found = 0;
1713 if ($bug && defined($stop_after_failure) &&
1714 $stop_after_failure >= 0) {
1715 my $time = $stop_after_failure - (time - $failure_start);
1716 $line = wait_for_input($monitor_fp, $time);
1717 if (!defined($line)) {
1718 doprint "bug timed out after $booted_timeout seconds\n";
1719 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1723 $line = wait_for_input($monitor_fp, $booted_timeout);
1724 if (!defined($line)) {
1725 my $s = $booted_timeout == 1 ? "" : "s";
1726 doprint "Successful boot found: break after $booted_timeout second$s\n";
1730 $line = wait_for_input($monitor_fp);
1731 if (!defined($line)) {
1732 my $s = $timeout == 1 ? "" : "s";
1733 doprint "Timed out after $timeout second$s\n";
1741 # we are not guaranteed to get a full line
1742 $full_line .= $line;
1744 if ($full_line =~ /$success_line/) {
1746 $success_start = time;
1749 if ($booted && defined($stop_after_success) &&
1750 $stop_after_success >= 0) {
1752 if ($now - $success_start >= $stop_after_success) {
1753 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1758 if ($full_line =~ /\[ backtrace testing \]/) {
1759 $skip_call_trace = 1;
1762 if ($full_line =~ /call trace:/i) {
1763 if (!$bug && !$skip_call_trace) {
1764 if ($ignore_errors) {
1768 $failure_start = time;
1773 if ($bug && defined($stop_after_failure) &&
1774 $stop_after_failure >= 0) {
1776 if ($now - $failure_start >= $stop_after_failure) {
1777 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1782 if ($full_line =~ /\[ end of backtrace testing \]/) {
1783 $skip_call_trace = 0;
1786 if ($full_line =~ /Kernel panic -/) {
1787 $failure_start = time;
1791 # Detect triple faults by testing the banner
1792 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1793 if ($1 eq $version) {
1795 } elsif ($version_found && $detect_triplefault) {
1796 # We already booted into the kernel we are testing,
1797 # but now we booted into another kernel?
1798 # Consider this a triple fault.
1799 doprint "Already booted in Linux kernel $version, but now\n";
1800 doprint "we booted into Linux kernel $1.\n";
1801 doprint "Assuming that this is a triple fault.\n";
1802 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1807 if ($line =~ /\n/) {
1811 if ($stop_test_after > 0 && !$booted && !$bug) {
1812 if (time - $monitor_start > $stop_test_after) {
1813 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1822 return 0 if ($in_bisect);
1823 fail "failed - got a bug report" and return 0;
1827 return 0 if ($in_bisect);
1828 fail "failed - never got a boot prompt." and return 0;
1832 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1838 sub eval_kernel_version {
1841 $option =~ s/\$KERNEL_VERSION/$version/g;
1846 sub do_post_install {
1848 return if (!defined($post_install));
1850 my $cp_post_install = eval_kernel_version $post_install;
1851 run_command "$cp_post_install" or
1852 dodie "Failed to run post install";
1855 # Sometimes the reboot fails, and will hang. We try to ssh to the box
1856 # and if we fail, we force another reboot, that should powercycle it.
1858 if (!run_ssh "echo testing connection") {
1865 return if ($no_install);
1867 if (defined($pre_install)) {
1868 my $cp_pre_install = eval_kernel_version $pre_install;
1869 run_command "$cp_pre_install" or
1870 dodie "Failed to run pre install";
1873 my $cp_target = eval_kernel_version $target_image;
1877 run_scp_install "$outputdir/$build_target", "$cp_target" or
1878 dodie "failed to copy image";
1880 my $install_mods = 0;
1882 # should we process modules?
1884 open(IN, "$output_config") or dodie("Can't read config file");
1886 if (/CONFIG_MODULES(=y)?/) {
1895 if (!$install_mods) {
1897 doprint "No modules needed\n";
1901 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1902 dodie "Failed to install modules";
1904 my $modlib = "/lib/modules/$version";
1905 my $modtar = "ktest-mods.tar.bz2";
1907 run_ssh "rm -rf $modlib" or
1908 dodie "failed to remove old mods: $modlib";
1910 # would be nice if scp -r did not follow symbolic links
1911 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1912 dodie "making tarball";
1914 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1915 dodie "failed to copy modules";
1917 unlink "$tmpdir/$modtar";
1919 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1920 dodie "failed to tar modules";
1922 run_ssh "rm -f /tmp/$modtar";
1928 # get the release name
1929 return if ($have_version);
1930 doprint "$make kernelrelease ... ";
1931 $version = `$make kernelrelease | tail -1`;
1933 doprint "$version\n";
1937 sub start_monitor_and_boot {
1938 # Make sure the stable kernel has finished booting
1940 # Install bisects, don't need console
1941 if (defined $console) {
1951 start_monitor if (defined $console);
1955 my $check_build_re = ".*:.*(warning|error|Error):.*";
1956 my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1958 sub process_warning_line {
1963 # for distcc heterogeneous systems, some compilers
1964 # do things differently causing warning lines
1965 # to be slightly different. This makes an attempt
1966 # to fixe those issues.
1968 # chop off the index into the line
1969 # using distcc, some compilers give different indexes
1970 # depending on white space
1971 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
1973 # Some compilers use UTF-8 extended for quotes and some don't.
1974 $line =~ s/$utf8_quote/'/g;
1979 # Read buildlog and check against warnings file for any
1984 sub check_buildlog {
1985 return 1 if (!defined $warnings_file);
1989 # Failed builds should not reboot the target
1990 my $save_no_reboot = $no_reboot;
1993 if (-f $warnings_file) {
1994 open(IN, $warnings_file) or
1995 dodie "Error opening $warnings_file";
1998 if (/$check_build_re/) {
1999 my $warning = process_warning_line $_;
2001 $warnings_list{$warning} = 1;
2007 # If warnings file didn't exist, and WARNINGS_FILE exist,
2008 # then we fail on any warning!
2010 open(IN, $buildlog) or dodie "Can't open $buildlog";
2012 if (/$check_build_re/) {
2013 my $warning = process_warning_line $_;
2015 if (!defined $warnings_list{$warning}) {
2016 fail "New warning found (not in $warnings_file)\n$_\n";
2017 $no_reboot = $save_no_reboot;
2022 $no_reboot = $save_no_reboot;
2026 sub check_patch_buildlog {
2029 my @files = `git show $patch | diffstat -l`;
2031 foreach my $file (@files) {
2035 open(IN, "git show $patch |") or
2036 dodie "failed to show $patch";
2038 if (m,^--- a/(.*),) {
2040 $files[$#files] = $1;
2045 open(IN, $buildlog) or dodie "Can't open $buildlog";
2047 if (/^\s*(.*?):.*(warning|error)/) {
2049 foreach my $file (@files) {
2050 my $fullpath = "$builddir/$file";
2051 if ($file eq $err || $fullpath eq $err) {
2052 fail "$file built with warnings" and return 0;
2062 sub apply_min_config {
2063 my $outconfig = "$output_config.new";
2065 # Read the config file and remove anything that
2066 # is in the force_config hash (from minconfig and others)
2067 # then add the force config back.
2069 doprint "Applying minimum configurations into $output_config.new\n";
2071 open (OUT, ">$outconfig") or
2072 dodie "Can't create $outconfig";
2074 if (-f $output_config) {
2075 open (IN, $output_config) or
2076 dodie "Failed to open $output_config";
2078 if (/^(# )?(CONFIG_[^\s=]*)/) {
2079 next if (defined($force_config{$2}));
2085 foreach my $config (keys %force_config) {
2086 print OUT "$force_config{$config}\n";
2090 run_command "mv $outconfig $output_config";
2093 sub make_oldconfig {
2095 my @force_list = keys %force_config;
2097 if ($#force_list >= 0) {
2101 if (!run_command "$make olddefconfig") {
2102 # Perhaps olddefconfig doesn't exist in this version of the kernel
2104 doprint "olddefconfig failed, trying make oldnoconfig\n";
2105 if (!run_command "$make oldnoconfig") {
2106 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2107 # try a yes '' | oldconfig
2108 run_command "yes '' | $make oldconfig" or
2109 dodie "failed make config oldconfig";
2114 # read a config file and use this to force new configs.
2115 sub load_force_config {
2118 doprint "Loading force configs from $config\n";
2119 open(IN, $config) or
2120 dodie "failed to read $config";
2123 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2124 $force_config{$1} = $_;
2125 } elsif (/^# (CONFIG_\S*) is not set/) {
2126 $force_config{$1} = $_;
2137 # Failed builds should not reboot the target
2138 my $save_no_reboot = $no_reboot;
2141 # Calculate a new version from here.
2144 if (defined($pre_build)) {
2145 my $ret = run_command $pre_build;
2146 if (!$ret && defined($pre_build_die) &&
2148 dodie "failed to pre_build\n";
2152 if ($type =~ /^useconfig:(.*)/) {
2153 run_command "cp $1 $output_config" or
2154 dodie "could not copy $1 to .config";
2156 $type = "oldconfig";
2159 # old config can ask questions
2160 if ($type eq "oldconfig") {
2161 $type = "olddefconfig";
2163 # allow for empty configs
2164 run_command "touch $output_config";
2167 run_command "mv $output_config $outputdir/config_temp" or
2168 dodie "moving .config";
2170 run_command "$make mrproper" or dodie "make mrproper";
2172 run_command "mv $outputdir/config_temp $output_config" or
2173 dodie "moving config_temp";
2176 } elsif (!$noclean) {
2177 unlink "$output_config";
2178 run_command "$make mrproper" or
2179 dodie "make mrproper";
2182 # add something to distinguish this build
2183 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2184 print OUT "$localversion\n";
2187 if (defined($minconfig)) {
2188 load_force_config($minconfig);
2191 if ($type ne "olddefconfig") {
2192 run_command "$make $type" or
2193 dodie "failed make config";
2195 # Run old config regardless, to enforce min configurations
2198 $redirect = "$buildlog";
2199 my $build_ret = run_command "$make $build_options";
2202 if (defined($post_build)) {
2203 # Because a post build may change the kernel version
2206 my $ret = run_command $post_build;
2207 if (!$ret && defined($post_build_die) &&
2209 dodie "failed to post_build\n";
2214 # bisect may need this to pass
2216 $no_reboot = $save_no_reboot;
2219 fail "failed build" and return 0;
2222 $no_reboot = $save_no_reboot;
2228 if (!run_ssh "halt" or defined($power_off)) {
2229 if (defined($poweroff_after_halt)) {
2230 sleep $poweroff_after_halt;
2231 run_command "$power_off";
2235 run_command "$power_off";
2242 if (defined($post_test)) {
2243 run_command $post_test;
2250 if (defined($test_name)) {
2251 $name = " ($test_name)";
2254 doprint "\n\n*******************************************\n";
2255 doprint "*******************************************\n";
2256 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2257 doprint "*******************************************\n";
2258 doprint "*******************************************\n";
2260 if (defined($store_successes)) {
2261 save_logs "success", $store_successes;
2264 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2265 doprint "Reboot and wait $sleep_time seconds\n";
2266 reboot_to_good $sleep_time;
2272 doprint "Pass or fail? [p/f]";
2275 if ($ans eq "p" || $ans eq "P") {
2277 } elsif ($ans eq "f" || $ans eq "F") {
2280 print "Please answer 'P' or 'F'\n";
2285 sub child_run_test {
2288 # child should have no power
2289 $reboot_on_error = 0;
2290 $poweroff_on_error = 0;
2291 $die_on_failure = 1;
2293 $redirect = "$testlog";
2294 run_command $run_test or $failed = 1;
2302 sub child_finished {
2312 my $bug_ignored = 0;
2316 doprint "run test $run_test\n";
2320 $SIG{CHLD} = qw(child_finished);
2324 child_run_test if (!$child_pid);
2329 $line = wait_for_input($monitor_fp, 1);
2330 if (defined($line)) {
2332 # we are not guaranteed to get a full line
2333 $full_line .= $line;
2336 if ($full_line =~ /call trace:/i) {
2337 if ($ignore_errors) {
2344 if ($full_line =~ /Kernel panic -/) {
2348 if ($line =~ /\n/) {
2352 } while (!$child_done && !$bug);
2354 if (!$bug && $bug_ignored) {
2355 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2359 my $failure_start = time;
2362 $line = wait_for_input($monitor_fp, 1);
2363 if (defined($line)) {
2367 if ($now - $failure_start >= $stop_after_failure) {
2370 } while (defined($line));
2372 doprint "Detected kernel crash!\n";
2373 # kill the child with extreme prejudice
2377 waitpid $child_pid, 0;
2380 if (!$bug && $in_bisect) {
2381 if (defined($bisect_ret_good)) {
2382 if ($child_exit == $bisect_ret_good) {
2386 if (defined($bisect_ret_skip)) {
2387 if ($child_exit == $bisect_ret_skip) {
2391 if (defined($bisect_ret_abort)) {
2392 if ($child_exit == $bisect_ret_abort) {
2393 fail "test abort" and return -2;
2396 if (defined($bisect_ret_bad)) {
2397 if ($child_exit == $bisect_ret_skip) {
2401 if (defined($bisect_ret_default)) {
2402 if ($bisect_ret_default eq "good") {
2404 } elsif ($bisect_ret_default eq "bad") {
2406 } elsif ($bisect_ret_default eq "skip") {
2408 } elsif ($bisect_ret_default eq "abort") {
2411 fail "unknown default action: $bisect_ret_default"
2417 if ($bug || $child_exit) {
2418 return 0 if $in_bisect;
2419 fail "test failed" and return 0;
2424 sub run_git_bisect {
2427 doprint "$command ... ";
2429 my $output = `$command 2>&1`;
2436 dodie "Failed to git bisect";
2439 doprint "SUCCESS\n";
2440 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2441 doprint "$1 [$2]\n";
2442 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2443 $bisect_bad_commit = $1;
2444 doprint "Found bad commit... $1\n";
2447 # we already logged it, just print it now.
2455 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2456 reboot_to_good $bisect_sleep_time;
2459 # returns 1 on success, 0 on failure, -1 on skip
2460 sub run_bisect_test {
2461 my ($type, $buildtype) = @_;
2470 build $buildtype or $failed = 1;
2472 if ($type ne "build") {
2473 if ($failed && $bisect_skip) {
2477 dodie "Failed on build" if $failed;
2480 start_monitor_and_boot or $failed = 1;
2482 if ($type ne "boot") {
2483 if ($failed && $bisect_skip) {
2489 dodie "Failed on boot" if $failed;
2491 do_run_test or $failed = 1;
2502 # reboot the box to a kernel we can ssh to
2503 if ($type ne "build") {
2513 my $buildtype = "oldconfig";
2515 # We should have a minconfig to use?
2516 if (defined($minconfig)) {
2517 $buildtype = "useconfig:$minconfig";
2520 my $ret = run_bisect_test $type, $buildtype;
2522 if ($bisect_manual) {
2523 $ret = answer_bisect;
2526 # Are we looking for where it worked, not failed?
2527 if ($reverse_bisect && $ret >= 0) {
2533 } elsif ($ret == 0) {
2535 } elsif ($bisect_skip) {
2536 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2541 sub update_bisect_replay {
2542 my $tmp_log = "$tmpdir/ktest_bisect_log";
2543 run_command "git bisect log > $tmp_log" or
2544 die "can't create bisect log";
2553 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2554 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2555 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2557 my $good = $bisect_good;
2558 my $bad = $bisect_bad;
2559 my $type = $bisect_type;
2560 my $start = $bisect_start;
2561 my $replay = $bisect_replay;
2562 my $start_files = $bisect_files;
2564 if (defined($start_files)) {
2565 $start_files = " -- " . $start_files;
2570 # convert to true sha1's
2571 $good = get_sha1($good);
2572 $bad = get_sha1($bad);
2574 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2575 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2576 $reverse_bisect = 1;
2578 $reverse_bisect = 0;
2581 # Can't have a test without having a test to run
2582 if ($type eq "test" && !defined($run_test)) {
2586 # Check if a bisect was running
2587 my $bisect_start_file = "$builddir/.git/BISECT_START";
2589 my $check = $bisect_check;
2590 my $do_check = defined($check) && $check ne "0";
2592 if ( -f $bisect_start_file ) {
2593 print "Bisect in progress found\n";
2595 print " If you say yes, then no checks of good or bad will be done\n";
2597 if (defined($replay)) {
2598 print "** BISECT_REPLAY is defined in config file **";
2599 print " Ignore config option and perform new git bisect log?\n";
2600 if (read_ync " (yes, no, or cancel) ") {
2601 $replay = update_bisect_replay;
2604 } elsif (read_yn "read git log and continue?") {
2605 $replay = update_bisect_replay;
2613 my $head = get_sha1("HEAD");
2615 if ($check ne "good") {
2616 doprint "TESTING BISECT BAD [$bad]\n";
2617 run_command "git checkout $bad" or
2618 die "Failed to checkout $bad";
2620 $result = run_bisect $type;
2622 if ($result ne "bad") {
2623 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2627 if ($check ne "bad") {
2628 doprint "TESTING BISECT GOOD [$good]\n";
2629 run_command "git checkout $good" or
2630 die "Failed to checkout $good";
2632 $result = run_bisect $type;
2634 if ($result ne "good") {
2635 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2639 # checkout where we started
2640 run_command "git checkout $head" or
2641 die "Failed to checkout $head";
2644 run_command "git bisect start$start_files" or
2645 dodie "could not start bisect";
2647 run_command "git bisect good $good" or
2648 dodie "could not set bisect good to $good";
2650 run_git_bisect "git bisect bad $bad" or
2651 dodie "could not set bisect bad to $bad";
2653 if (defined($replay)) {
2654 run_command "git bisect replay $replay" or
2655 dodie "failed to run replay";
2658 if (defined($start)) {
2659 run_command "git checkout $start" or
2660 dodie "failed to checkout $start";
2665 $result = run_bisect $type;
2666 $test = run_git_bisect "git bisect $result";
2669 run_command "git bisect log" or
2670 dodie "could not capture git bisect log";
2672 run_command "git bisect reset" or
2673 dodie "could not reset git bisect";
2675 doprint "Bad commit was [$bisect_bad_commit]\n";
2680 # config_ignore holds the configs that were set (or unset) for
2681 # a good config and we will ignore these configs for the rest
2682 # of a config bisect. These configs stay as they were.
2685 # config_set holds what all configs were set as.
2688 # config_off holds the set of configs that the bad config had disabled.
2689 # We need to record them and set them in the .config when running
2690 # olddefconfig, because olddefconfig keeps the defaults.
2693 # config_off_tmp holds a set of configs to turn off for now
2696 # config_list is the set of configs that are being tested
2702 sub assign_configs {
2703 my ($hash, $config) = @_;
2706 or dodie "Failed to read $config";
2709 if (/^((CONFIG\S*)=.*)/) {
2717 sub process_config_ignore {
2720 assign_configs \%config_ignore, $config;
2723 sub read_current_config {
2724 my ($config_ref) = @_;
2726 %{$config_ref} = ();
2727 undef %{$config_ref};
2729 my @key = keys %{$config_ref};
2731 print "did not delete!\n";
2734 open (IN, "$output_config");
2737 if (/^(CONFIG\S+)=(.*)/) {
2738 ${$config_ref}{$1} = $2;
2744 sub get_dependencies {
2747 my $arr = $dependency{$config};
2748 if (!defined($arr)) {
2754 foreach my $dep (@{$arr}) {
2755 print "ADD DEP $dep\n";
2756 @deps = (@deps, get_dependencies $dep);
2765 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2767 foreach my $config (@configs) {
2768 print OUT "$config_set{$config}\n";
2769 my @deps = get_dependencies $config;
2770 foreach my $dep (@deps) {
2771 print OUT "$config_set{$dep}\n";
2775 # turn off configs to keep off
2776 foreach my $config (keys %config_off) {
2777 print OUT "# $config is not set\n";
2780 # turn off configs that should be off for now
2781 foreach my $config (@config_off_tmp) {
2782 print OUT "# $config is not set\n";
2785 foreach my $config (keys %config_ignore) {
2786 print OUT "$config_ignore{$config}\n";
2793 sub compare_configs {
2796 foreach my $item (keys %a) {
2797 if (!defined($b{$item})) {
2798 print "diff $item\n";
2806 print "diff2 $keys[0]\n";
2808 return -1 if ($#keys >= 0);
2813 sub run_config_bisect_test {
2816 return run_bisect_test $type, "oldconfig";
2819 sub process_passed {
2822 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2823 # Passed! All these configs are part of a good compile.
2824 # Add them to the min options.
2825 foreach my $config (keys %configs) {
2826 if (defined($config_list{$config})) {
2827 doprint " removing $config\n";
2828 $config_ignore{$config} = $config_list{$config};
2829 delete $config_list{$config};
2832 doprint "config copied to $outputdir/config_good\n";
2833 run_command "cp -f $output_config $outputdir/config_good";
2836 sub process_failed {
2839 doprint "\n\n***************************************\n";
2840 doprint "Found bad config: $config\n";
2841 doprint "***************************************\n\n";
2844 sub run_config_bisect {
2846 my @start_list = keys %config_list;
2848 if ($#start_list < 0) {
2849 doprint "No more configs to test!!!\n";
2853 doprint "***** RUN TEST ***\n";
2854 my $type = $config_bisect_type;
2858 my $count = $#start_list + 1;
2859 doprint " $count configs to test\n";
2861 my $half = int($#start_list / 2);
2864 my @tophalf = @start_list[0 .. $half];
2866 # keep the bottom half off
2867 if ($half < $#start_list) {
2868 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2870 @config_off_tmp = ();
2873 create_config @tophalf;
2874 read_current_config \%current_config;
2876 $count = $#tophalf + 1;
2877 doprint "Testing $count configs\n";
2879 # make sure we test something
2880 foreach my $config (@tophalf) {
2881 if (defined($current_config{$config})) {
2887 # try the other half
2888 doprint "Top half produced no set configs, trying bottom half\n";
2890 # keep the top half off
2891 @config_off_tmp = @tophalf;
2892 @tophalf = @start_list[$half + 1 .. $#start_list];
2894 create_config @tophalf;
2895 read_current_config \%current_config;
2896 foreach my $config (@tophalf) {
2897 if (defined($current_config{$config})) {
2903 doprint "Failed: Can't make new config with current configs\n";
2904 foreach my $config (@start_list) {
2905 doprint " CONFIG: $config\n";
2909 $count = $#tophalf + 1;
2910 doprint "Testing $count configs\n";
2913 $ret = run_config_bisect_test $type;
2914 if ($bisect_manual) {
2915 $ret = answer_bisect;
2918 process_passed %current_config;
2922 doprint "This config had a failure.\n";
2923 doprint "Removing these configs that were not set in this config:\n";
2924 doprint "config copied to $outputdir/config_bad\n";
2925 run_command "cp -f $output_config $outputdir/config_bad";
2927 # A config exists in this group that was bad.
2928 foreach my $config (keys %config_list) {
2929 if (!defined($current_config{$config})) {
2930 doprint " removing $config\n";
2931 delete $config_list{$config};
2935 @start_list = @tophalf;
2937 if ($#start_list == 0) {
2938 process_failed $start_list[0];
2942 # remove half the configs we are looking at and see if
2944 $half = int($#start_list / 2);
2945 } while ($#start_list > 0);
2947 # we found a single config, try it again unless we are running manually
2949 if ($bisect_manual) {
2950 process_failed $start_list[0];
2954 my @tophalf = @start_list[0 .. 0];
2956 $ret = run_config_bisect_test $type;
2958 process_passed %current_config;
2962 process_failed $start_list[0];
2969 my $start_config = $config_bisect;
2971 my $tmpconfig = "$tmpdir/use_config";
2973 if (defined($config_bisect_good)) {
2974 process_config_ignore $config_bisect_good;
2977 # Make the file with the bad config and the min config
2978 if (defined($minconfig)) {
2979 # read the min config for things to ignore
2980 run_command "cp $minconfig $tmpconfig" or
2981 dodie "failed to copy $minconfig to $tmpconfig";
2986 if (-f $tmpconfig) {
2987 load_force_config($tmpconfig);
2988 process_config_ignore $tmpconfig;
2991 # now process the start config
2992 run_command "cp $start_config $output_config" or
2993 dodie "failed to copy $start_config to $output_config";
2995 # read directly what we want to check
2997 open (IN, $output_config)
2998 or dodie "failed to open $output_config";
3001 if (/^((CONFIG\S*)=.*)/) {
3002 $config_check{$2} = $1;
3007 # Now run oldconfig with the minconfig
3010 # check to see what we lost (or gained)
3011 open (IN, $output_config)
3012 or dodie "Failed to read $start_config";
3014 my %removed_configs;
3018 if (/^((CONFIG\S*)=.*)/) {
3019 # save off all options
3020 $config_set{$2} = $1;
3021 if (defined($config_check{$2})) {
3022 if (defined($config_ignore{$2})) {
3023 $removed_configs{$2} = $1;
3025 $config_list{$2} = $1;
3027 } elsif (!defined($config_ignore{$2})) {
3028 $added_configs{$2} = $1;
3029 $config_list{$2} = $1;
3031 } elsif (/^# ((CONFIG\S*).*)/) {
3032 # Keep these configs disabled
3033 $config_set{$2} = $1;
3034 $config_off{$2} = $1;
3039 my @confs = keys %removed_configs;
3041 doprint "Configs overridden by default configs and removed from check:\n";
3042 foreach my $config (@confs) {
3043 doprint " $config\n";
3046 @confs = keys %added_configs;
3048 doprint "Configs appearing in make oldconfig and added:\n";
3049 foreach my $config (@confs) {
3050 doprint " $config\n";
3057 @config_off_tmp = ();
3059 # Sometimes kconfig does weird things. We must make sure
3060 # that the config we autocreate has everything we need
3061 # to test, otherwise we may miss testing configs, or
3062 # may not be able to create a new config.
3063 # Here we create a config with everything set.
3064 create_config (keys %config_list);
3065 read_current_config \%config_test;
3066 foreach my $config (keys %config_list) {
3067 if (!defined($config_test{$config})) {
3070 doprint "Configs not produced by kconfig (will not be checked):\n";
3072 doprint " $config\n";
3073 delete $config_list{$config};
3078 if (defined($config_bisect_check) && $config_bisect_check) {
3079 doprint " Checking to make sure bad config with min config fails\n";
3080 create_config keys %config_list;
3081 $ret = run_config_bisect_test $config_bisect_type;
3083 doprint " FAILED! Bad config with min config boots fine\n";
3086 doprint " Bad config with min config fails as expected\n";
3090 $ret = run_config_bisect;
3093 return $ret if ($ret < 0);
3098 sub patchcheck_reboot {
3099 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3100 reboot_to_good $patchcheck_sleep_time;
3106 die "PATCHCHECK_START[$i] not defined\n"
3107 if (!defined($patchcheck_start));
3108 die "PATCHCHECK_TYPE[$i] not defined\n"
3109 if (!defined($patchcheck_type));
3111 my $start = $patchcheck_start;
3114 if (defined($patchcheck_end)) {
3115 $end = $patchcheck_end;
3118 # Get the true sha1's since we can use things like HEAD~3
3119 $start = get_sha1($start);
3120 $end = get_sha1($end);
3122 my $type = $patchcheck_type;
3124 # Can't have a test without having a test to run
3125 if ($type eq "test" && !defined($run_test)) {
3129 open (IN, "git log --pretty=oneline $end|") or
3130 dodie "could not get git list";
3136 $list[$#list+1] = $_;
3137 last if (/^$start/);
3141 if ($list[$#list] !~ /^$start/) {
3142 fail "SHA1 $start not found";
3145 # go backwards in the list
3146 @list = reverse @list;
3148 my $save_clean = $noclean;
3149 my %ignored_warnings;
3151 if (defined($ignore_warnings)) {
3152 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3153 $ignored_warnings{$sha1} = 1;
3158 foreach my $item (@list) {
3160 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3162 doprint "\nProcessing commit $item\n\n";
3164 run_command "git checkout $sha1" or
3165 die "Failed to checkout $sha1";
3167 # only clean on the first and last patch
3168 if ($item eq $list[0] ||
3169 $item eq $list[$#list]) {
3170 $noclean = $save_clean;
3175 if (defined($minconfig)) {
3176 build "useconfig:$minconfig" or return 0;
3178 # ?? no config to use?
3179 build "oldconfig" or return 0;
3182 # No need to do per patch checking if warnings file exists
3183 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3184 check_patch_buildlog $sha1 or return 0;
3187 check_buildlog or return 0;
3189 next if ($type eq "build");
3193 start_monitor_and_boot or $failed = 1;
3195 if (!$failed && $type ne "boot"){
3196 do_run_test or $failed = 1;
3199 return 0 if ($failed);
3219 # $config depends on $dep
3220 my ($config, $dep) = @_;
3222 if (defined($depends{$config})) {
3223 $depends{$config} .= " " . $dep;
3225 $depends{$config} = $dep;
3228 # record the number of configs depending on $dep
3229 if (defined $depcount{$dep}) {
3232 $depcount{$dep} = 1;
3236 # taken from streamline_config.pl
3248 if (! -f $kconfig) {
3249 doprint "file $kconfig does not exist, skipping\n";
3253 open(KIN, "$kconfig")
3254 or die "Can't open $kconfig";
3258 # Make sure that lines ending with \ continue
3260 $_ = $line . " " . $_;
3271 # collect any Kconfig sources
3272 if (/^source\s*"(.*)"/) {
3273 $kconfigs[$#kconfigs+1] = $1;
3277 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3281 for (my $i = 0; $i < $iflevel; $i++) {
3282 add_dep $config, $ifdeps[$i];
3285 # collect the depends for the config
3286 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3288 add_dep $config, $1;
3290 # Get the configs that select this config
3291 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3293 # selected by depends on config
3294 add_dep $1, $config;
3296 # Check for if statements
3297 } elsif (/^if\s+(.*\S)\s*$/) {
3299 # remove beginning and ending non text
3300 $deps =~ s/^[^a-zA-Z0-9_]*//;
3301 $deps =~ s/[^a-zA-Z0-9_]*$//;
3303 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3305 $ifdeps[$iflevel++] = join ':', @deps;
3307 } elsif (/^endif/) {
3309 $iflevel-- if ($iflevel);
3312 } elsif (/^\s*help\s*$/) {
3318 # read in any configs that were found.
3319 foreach $kconfig (@kconfigs) {
3320 if (!defined($read_kconfigs{$kconfig})) {
3321 $read_kconfigs{$kconfig} = 1;
3322 read_kconfig("$builddir/$kconfig");
3328 # find out which arch this is by the kconfig file
3329 open (IN, $output_config)
3330 or dodie "Failed to read $output_config";
3333 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3340 if (!defined($arch)) {
3341 doprint "Could not find arch from config file\n";
3342 doprint "no dependencies used\n";
3346 # arch is really the subarch, we need to know
3347 # what directory to look at.
3348 if ($arch eq "i386" || $arch eq "x86_64") {
3350 } elsif ($arch =~ /^tile/) {
3354 my $kconfig = "$builddir/arch/$arch/Kconfig";
3356 if (! -f $kconfig && $arch =~ /\d$/) {
3358 # some subarchs have numbers, truncate them
3360 $kconfig = "$builddir/arch/$arch/Kconfig";
3361 if (! -f $kconfig) {
3362 doprint "No idea what arch dir $orig is for\n";
3363 doprint "no dependencies used\n";
3368 read_kconfig($kconfig);
3371 sub read_config_list {
3375 or dodie "Failed to read $config";
3378 if (/^((CONFIG\S*)=.*)/) {
3379 if (!defined($config_ignore{$2})) {
3380 $config_list{$2} = $1;
3388 sub read_output_config {
3391 assign_configs \%config_ignore, $config;
3394 sub make_new_config {
3397 open (OUT, ">$output_config")
3398 or dodie "Failed to write $output_config";
3400 foreach my $config (@configs) {
3401 print OUT "$config\n";
3409 $config =~ s/CONFIG_//;
3417 my $kconfig = chomp_config $dep;
3419 $dep = $depends{"$kconfig"};
3421 # the dep string we have saves the dependencies as they
3422 # were found, including expressions like ! && ||. We
3423 # want to split this out into just an array of configs.
3425 my $valid = "A-Za-z_0-9";
3429 while ($dep =~ /[$valid]/) {
3431 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3432 my $conf = "CONFIG_" . $1;
3434 $configs[$#configs + 1] = $conf;
3436 $dep =~ s/^[^$valid]*[$valid]+//;
3438 die "this should never happen";
3448 my %processed_configs;
3449 my %nochange_config;
3451 sub test_this_config {
3456 # if we already processed this config, skip it
3457 if (defined($processed_configs{$config})) {
3460 $processed_configs{$config} = 1;
3462 # if this config failed during this round, skip it
3463 if (defined($nochange_config{$config})) {
3467 my $kconfig = chomp_config $config;
3469 # Test dependencies first
3470 if (defined($depends{"$kconfig"})) {
3471 my @parents = get_depends $config;
3472 foreach my $parent (@parents) {
3473 # if the parent is in the min config, check it first
3474 next if (!defined($min_configs{$parent}));
3475 $found = test_this_config($parent);
3476 if (defined($found)) {
3482 # Remove this config from the list of configs
3483 # do a make olddefconfig and then read the resulting
3484 # .config to make sure it is missing the config that
3486 my %configs = %min_configs;
3487 delete $configs{$config};
3488 make_new_config ((values %configs), (values %keep_configs));
3491 assign_configs \%configs, $output_config;
3493 return $config if (!defined($configs{$config}));
3495 doprint "disabling config $config did not change .config\n";
3497 $nochange_config{$config} = 1;
3502 sub make_min_config {
3505 my $type = $minconfig_type;
3506 if ($type ne "boot" && $type ne "test") {
3507 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3508 " make_min_config works only with 'boot' and 'test'\n" and return;
3511 if (!defined($output_minconfig)) {
3512 fail "OUTPUT_MIN_CONFIG not defined" and return;
3515 # If output_minconfig exists, and the start_minconfig
3516 # came from min_config, than ask if we should use
3518 if (-f $output_minconfig && !$start_minconfig_defined) {
3519 print "$output_minconfig exists\n";
3520 if (!defined($use_output_minconfig)) {
3521 if (read_yn " Use it as minconfig?") {
3522 $start_minconfig = $output_minconfig;
3524 } elsif ($use_output_minconfig > 0) {
3525 doprint "Using $output_minconfig as MIN_CONFIG\n";
3526 $start_minconfig = $output_minconfig;
3528 doprint "Set to still use MIN_CONFIG as starting point\n";
3532 if (!defined($start_minconfig)) {
3533 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3536 my $temp_config = "$tmpdir/temp_config";
3538 # First things first. We build an allnoconfig to find
3539 # out what the defaults are that we can't touch.
3540 # Some are selections, but we really can't handle selections.
3542 my $save_minconfig = $minconfig;
3545 run_command "$make allnoconfig" or return 0;
3549 process_config_ignore $output_config;
3551 undef %save_configs;
3554 if (defined($ignore_config)) {
3555 # make sure the file exists
3556 `touch $ignore_config`;
3557 assign_configs \%save_configs, $ignore_config;
3560 %keep_configs = %save_configs;
3562 doprint "Load initial configs from $start_minconfig\n";
3564 # Look at the current min configs, and save off all the
3565 # ones that were set via the allnoconfig
3566 assign_configs \%min_configs, $start_minconfig;
3568 my @config_keys = keys %min_configs;
3570 # All configs need a depcount
3571 foreach my $config (@config_keys) {
3572 my $kconfig = chomp_config $config;
3573 if (!defined $depcount{$kconfig}) {
3574 $depcount{$kconfig} = 0;
3578 # Remove anything that was set by the make allnoconfig
3579 # we shouldn't need them as they get set for us anyway.
3580 foreach my $config (@config_keys) {
3581 # Remove anything in the ignore_config
3582 if (defined($keep_configs{$config})) {
3583 my $file = $ignore_config;
3584 $file =~ s,.*/(.*?)$,$1,;
3585 doprint "$config set by $file ... ignored\n";
3586 delete $min_configs{$config};
3589 # But make sure the settings are the same. If a min config
3590 # sets a selection, we do not want to get rid of it if
3591 # it is not the same as what we have. Just move it into
3593 if (defined($config_ignore{$config})) {
3594 if ($config_ignore{$config} ne $min_configs{$config}) {
3595 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3596 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3597 $keep_configs{$config} = $min_configs{$config};
3599 doprint "$config set by allnoconfig ... ignored\n";
3601 delete $min_configs{$config};
3613 # Now disable each config one by one and do a make oldconfig
3614 # till we find a config that changes our list.
3616 my @test_configs = keys %min_configs;
3618 # Sort keys by who is most dependent on
3619 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3622 # Put configs that did not modify the config at the end.
3624 for (my $i = 0; $i < $#test_configs; $i++) {
3625 if (!defined($nochange_config{$test_configs[0]})) {
3629 # This config didn't change the .config last time.
3630 # Place it at the end
3631 my $config = shift @test_configs;
3632 push @test_configs, $config;
3635 # if every test config has failed to modify the .config file
3636 # in the past, then reset and start over.
3638 undef %nochange_config;
3641 undef %processed_configs;
3643 foreach my $config (@test_configs) {
3645 $found = test_this_config $config;
3647 last if (defined($found));
3649 # oh well, try another config
3652 if (!defined($found)) {
3653 # we could have failed due to the nochange_config hash
3654 # reset and try again
3656 undef %nochange_config;
3660 doprint "No more configs found that we can disable\n";
3668 doprint "Test with $config disabled\n";
3670 # set in_bisect to keep build and monitor from dieing
3674 build "oldconfig" or $failed = 1;
3676 start_monitor_and_boot or $failed = 1;
3678 if ($type eq "test" && !$failed) {
3679 do_run_test or $failed = 1;
3688 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3689 # this config is needed, add it to the ignore list.
3690 $keep_configs{$config} = $min_configs{$config};
3691 $save_configs{$config} = $min_configs{$config};
3692 delete $min_configs{$config};
3694 # update new ignore configs
3695 if (defined($ignore_config)) {
3696 open (OUT, ">$temp_config")
3697 or die "Can't write to $temp_config";
3698 foreach my $config (keys %save_configs) {
3699 print OUT "$save_configs{$config}\n";
3702 run_command "mv $temp_config $ignore_config" or
3703 dodie "failed to copy update to $ignore_config";
3707 # We booted without this config, remove it from the minconfigs.
3708 doprint "$config is not needed, disabling\n";
3710 delete $min_configs{$config};
3712 # Also disable anything that is not enabled in this config
3714 assign_configs \%configs, $output_config;
3715 my @config_keys = keys %min_configs;
3716 foreach my $config (@config_keys) {
3717 if (!defined($configs{$config})) {
3718 doprint "$config is not set, disabling\n";
3719 delete $min_configs{$config};
3723 # Save off all the current mandidory configs
3724 open (OUT, ">$temp_config")
3725 or die "Can't write to $temp_config";
3726 foreach my $config (keys %keep_configs) {
3727 print OUT "$keep_configs{$config}\n";
3729 foreach my $config (keys %min_configs) {
3730 print OUT "$min_configs{$config}\n";
3734 run_command "mv $temp_config $output_minconfig" or
3735 dodie "failed to copy update to $output_minconfig";
3738 doprint "Reboot and wait $sleep_time seconds\n";
3739 reboot_to_good $sleep_time;
3746 sub make_warnings_file {
3749 if (!defined($warnings_file)) {
3750 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3753 if ($build_type eq "nobuild") {
3754 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3757 build $build_type or dodie "Failed to build";
3759 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3761 open(IN, $buildlog) or dodie "Can't open $buildlog";
3764 # Some compilers use UTF-8 extended for quotes
3765 # for distcc heterogeneous systems, this causes issues
3768 if (/$check_build_re/) {
3779 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3782 $ktest_config = $ARGV[0];
3783 if (! -f $ktest_config) {
3784 print "$ktest_config does not exist.\n";
3785 if (!read_yn "Create it?") {
3790 $ktest_config = "ktest.conf";
3793 if (! -f $ktest_config) {
3796 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3798 # Generated by ktest.pl
3801 # PWD is a ktest.pl variable that will result in the process working
3802 # directory that ktest.pl is executed in.
3804 # THIS_DIR is automatically assigned the PWD of the path that generated
3805 # the config file. It is best to use this variable when assigning other
3806 # directory paths within this directory. This allows you to easily
3807 # move the test cases to other locations or to other machines.
3809 THIS_DIR := $variable{"PWD"}
3811 # Define each test with TEST_START
3812 # The config options below it will override the defaults
3814 TEST_TYPE = $default{"TEST_TYPE"}
3821 read_config $ktest_config;
3823 if (defined($opt{"LOG_FILE"})) {
3824 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
3827 # Append any configs entered in manually to the config file.
3828 my @new_configs = keys %entered_configs;
3829 if ($#new_configs >= 0) {
3830 print "\nAppending entered in configs to $ktest_config\n";
3831 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3832 foreach my $config (@new_configs) {
3833 print OUT "$config = $entered_configs{$config}\n";
3834 $opt{$config} = process_variables($entered_configs{$config});
3838 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3839 unlink $opt{"LOG_FILE"};
3842 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3844 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3847 doprint "DEFAULT OPTIONS:\n";
3849 doprint "\nTEST $i OPTIONS";
3850 if (defined($repeat_tests{$i})) {
3851 $repeat = $repeat_tests{$i};
3852 doprint " ITERATE $repeat";
3857 foreach my $option (sort keys %opt) {
3859 if ($option =~ /\[(\d+)\]$/) {
3865 doprint "$option = $opt{$option}\n";
3869 sub __set_test_option {
3870 my ($name, $i) = @_;
3872 my $option = "$name\[$i\]";
3874 if (defined($opt{$option})) {
3875 return $opt{$option};
3878 foreach my $test (keys %repeat_tests) {
3880 $i < $test + $repeat_tests{$test}) {
3881 $option = "$name\[$test\]";
3882 if (defined($opt{$option})) {
3883 return $opt{$option};
3888 if (defined($opt{$name})) {
3895 sub set_test_option {
3896 my ($name, $i) = @_;
3898 my $option = __set_test_option($name, $i);
3899 return $option if (!defined($option));
3901 return eval_option($name, $option, $i);
3904 # First we need to do is the builds
3905 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3907 # Do not reboot on failing test options
3909 $reboot_success = 0;
3915 undef %force_config;
3917 my $makecmd = set_test_option("MAKE_CMD", $i);
3919 # Load all the options into their mapped variable names
3920 foreach my $opt (keys %option_map) {
3921 ${$option_map{$opt}} = set_test_option($opt, $i);
3924 $start_minconfig_defined = 1;
3926 # The first test may override the PRE_KTEST option
3927 if (defined($pre_ktest) && $i == 1) {
3929 run_command $pre_ktest;
3932 # Any test can override the POST_KTEST option
3933 # The last test takes precedence.
3934 if (defined($post_ktest)) {
3935 $final_post_ktest = $post_ktest;
3938 if (!defined($start_minconfig)) {
3939 $start_minconfig_defined = 0;
3940 $start_minconfig = $minconfig;
3943 chdir $builddir || die "can't change directory to $builddir";
3945 foreach my $dir ($tmpdir, $outputdir) {
3948 die "can't create $dir";
3952 $ENV{"SSH_USER"} = $ssh_user;
3953 $ENV{"MACHINE"} = $machine;
3955 $buildlog = "$tmpdir/buildlog-$machine";
3956 $testlog = "$tmpdir/testlog-$machine";
3957 $dmesg = "$tmpdir/dmesg-$machine";
3958 $make = "$makecmd O=$outputdir";
3959 $output_config = "$outputdir/.config";
3962 $target = "$ssh_user\@$machine";
3963 if ($reboot_type eq "grub") {
3964 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3965 } elsif ($reboot_type eq "grub2") {
3966 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3967 dodie "GRUB_FILE not defined" if (!defined($grub_file));
3968 } elsif ($reboot_type eq "syslinux") {
3969 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
3973 my $run_type = $build_type;
3974 if ($test_type eq "patchcheck") {
3975 $run_type = $patchcheck_type;
3976 } elsif ($test_type eq "bisect") {
3977 $run_type = $bisect_type;
3978 } elsif ($test_type eq "config_bisect") {
3979 $run_type = $config_bisect_type;
3980 } elsif ($test_type eq "make_min_config") {
3982 } elsif ($test_type eq "make_warnings_file") {
3986 # mistake in config file?
3987 if (!defined($run_type)) {
3988 $run_type = "ERROR";
3992 $installme = " no_install" if ($no_install);
3995 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3997 if (defined($pre_test)) {
3998 run_command $pre_test;
4005 if (defined($addconfig)) {
4006 my $min = $minconfig;
4007 if (!defined($minconfig)) {
4010 run_command "cat $addconfig $min > $tmpdir/add_config" or
4011 dodie "Failed to create temp config";
4012 $minconfig = "$tmpdir/add_config";
4015 if (defined($checkout)) {
4016 run_command "git checkout $checkout" or
4017 die "failed to checkout $checkout";
4022 # A test may opt to not reboot the box
4023 if ($reboot_on_success) {
4024 $reboot_success = 1;
4027 if ($test_type eq "bisect") {
4030 } elsif ($test_type eq "config_bisect") {
4033 } elsif ($test_type eq "patchcheck") {
4036 } elsif ($test_type eq "make_min_config") {
4039 } elsif ($test_type eq "make_warnings_file") {
4041 make_warnings_file $i;
4045 if ($build_type ne "nobuild") {
4046 build $build_type or next;
4047 check_buildlog or next;
4050 if ($test_type eq "install") {
4057 if ($test_type ne "build") {
4059 start_monitor_and_boot or $failed = 1;
4061 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4062 do_run_test or $failed = 1;
4071 if (defined($final_post_ktest)) {
4072 run_command $final_post_ktest;
4075 if ($opt{"POWEROFF_ON_SUCCESS"}) {
4077 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4079 } elsif (defined($switch_to_good)) {
4080 # still need to get to the good kernel
4081 run_command $switch_to_good;
4085 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";