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);
26 "TEST_TYPE" => "build",
27 "BUILD_TYPE" => "randconfig",
29 "CLOSE_CONSOLE_SIGNAL" => "INT",
31 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
32 "SLEEP_TIME" => 60, # sleep time between tests
34 "REBOOT_ON_ERROR" => 0,
35 "POWEROFF_ON_ERROR" => 0,
36 "REBOOT_ON_SUCCESS" => 1,
37 "POWEROFF_ON_SUCCESS" => 0,
38 "BUILD_OPTIONS" => "",
39 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
40 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
45 "MIN_CONFIG_TYPE" => "boot",
46 "SUCCESS_LINE" => "login:",
47 "DETECT_TRIPLE_FAULT" => 1,
49 "BOOTED_TIMEOUT" => 1,
50 "DIE_ON_FAILURE" => 1,
51 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
52 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
53 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
54 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
55 "STOP_AFTER_SUCCESS" => 10,
56 "STOP_AFTER_FAILURE" => 60,
57 "STOP_TEST_AFTER" => 600,
58 "MAX_MONITOR_WAIT" => 1800,
59 "GRUB_REBOOT" => "grub2-reboot",
60 "SYSLINUX" => "extlinux",
61 "SYSLINUX_PATH" => "/boot/extlinux",
62 "CONNECT_TIMEOUT" => 25,
64 # required, and we will ask users if they don't have them but we keep the default
65 # value something that is common.
66 "REBOOT_TYPE" => "grub",
67 "LOCALVERSION" => "-test",
69 "BUILD_TARGET" => "arch/x86/boot/bzImage",
70 "TARGET_IMAGE" => "/boot/vmlinuz-test",
76 my $ktest_config = "ktest.conf";
105 my $poweroff_on_error;
106 my $reboot_on_success;
108 my $powercycle_after_reboot;
109 my $poweroff_after_halt;
110 my $max_monitor_wait;
113 my $scp_to_target_install;
131 my $start_minconfig_defined;
132 my $output_minconfig;
134 my $use_output_minconfig;
140 my $bisect_bad_commit = "";
145 my $config_bisect_good;
149 my $bisect_ret_abort;
150 my $bisect_ret_default;
151 my $in_patchcheck = 0;
160 my $bisect_sleep_time;
161 my $patchcheck_sleep_time;
169 my $detect_triplefault;
171 my $close_console_signal;
172 my $reboot_success_line;
174 my $stop_after_success;
175 my $stop_after_failure;
184 my $run_command_status = 0;
196 my $config_bisect_type;
197 my $config_bisect_check;
200 my $patchcheck_start;
201 my $patchcheck_cherry;
209 # set when a test is something other that just building or install
210 # which would require more options.
213 # tell build not to worry about warnings, even when WARNINGS_FILE is set
216 # set when creating a new config
223 # force_config is the list of configs that we force enabled (or disabled)
224 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
227 # do not force reboots on config problems
231 my $reboot_success = 0;
234 "MACHINE" => \$machine,
235 "SSH_USER" => \$ssh_user,
236 "TMP_DIR" => \$tmpdir,
237 "OUTPUT_DIR" => \$outputdir,
238 "BUILD_DIR" => \$builddir,
239 "TEST_TYPE" => \$test_type,
240 "PRE_KTEST" => \$pre_ktest,
241 "POST_KTEST" => \$post_ktest,
242 "PRE_TEST" => \$pre_test,
243 "POST_TEST" => \$post_test,
244 "BUILD_TYPE" => \$build_type,
245 "BUILD_OPTIONS" => \$build_options,
246 "PRE_BUILD" => \$pre_build,
247 "POST_BUILD" => \$post_build,
248 "PRE_BUILD_DIE" => \$pre_build_die,
249 "POST_BUILD_DIE" => \$post_build_die,
250 "POWER_CYCLE" => \$power_cycle,
251 "REBOOT" => \$reboot,
252 "BUILD_NOCLEAN" => \$noclean,
253 "MIN_CONFIG" => \$minconfig,
254 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
255 "START_MIN_CONFIG" => \$start_minconfig,
256 "MIN_CONFIG_TYPE" => \$minconfig_type,
257 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
258 "WARNINGS_FILE" => \$warnings_file,
259 "IGNORE_CONFIG" => \$ignore_config,
260 "TEST" => \$run_test,
261 "ADD_CONFIG" => \$addconfig,
262 "REBOOT_TYPE" => \$reboot_type,
263 "GRUB_MENU" => \$grub_menu,
264 "GRUB_FILE" => \$grub_file,
265 "GRUB_REBOOT" => \$grub_reboot,
266 "SYSLINUX" => \$syslinux,
267 "SYSLINUX_PATH" => \$syslinux_path,
268 "SYSLINUX_LABEL" => \$syslinux_label,
269 "PRE_INSTALL" => \$pre_install,
270 "POST_INSTALL" => \$post_install,
271 "NO_INSTALL" => \$no_install,
272 "REBOOT_SCRIPT" => \$reboot_script,
273 "REBOOT_ON_ERROR" => \$reboot_on_error,
274 "SWITCH_TO_GOOD" => \$switch_to_good,
275 "SWITCH_TO_TEST" => \$switch_to_test,
276 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
277 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
278 "DIE_ON_FAILURE" => \$die_on_failure,
279 "POWER_OFF" => \$power_off,
280 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
281 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
282 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
283 "SLEEP_TIME" => \$sleep_time,
284 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
285 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
286 "IGNORE_WARNINGS" => \$ignore_warnings,
287 "IGNORE_ERRORS" => \$ignore_errors,
288 "BISECT_MANUAL" => \$bisect_manual,
289 "BISECT_SKIP" => \$bisect_skip,
290 "BISECT_TRIES" => \$bisect_tries,
291 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
292 "BISECT_RET_GOOD" => \$bisect_ret_good,
293 "BISECT_RET_BAD" => \$bisect_ret_bad,
294 "BISECT_RET_SKIP" => \$bisect_ret_skip,
295 "BISECT_RET_ABORT" => \$bisect_ret_abort,
296 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
297 "STORE_FAILURES" => \$store_failures,
298 "STORE_SUCCESSES" => \$store_successes,
299 "TEST_NAME" => \$test_name,
300 "TIMEOUT" => \$timeout,
301 "CONNECT_TIMEOUT" => \$connect_timeout,
302 "BOOTED_TIMEOUT" => \$booted_timeout,
303 "CONSOLE" => \$console,
304 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
305 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
306 "SUCCESS_LINE" => \$success_line,
307 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
308 "STOP_AFTER_SUCCESS" => \$stop_after_success,
309 "STOP_AFTER_FAILURE" => \$stop_after_failure,
310 "STOP_TEST_AFTER" => \$stop_test_after,
311 "BUILD_TARGET" => \$build_target,
312 "SSH_EXEC" => \$ssh_exec,
313 "SCP_TO_TARGET" => \$scp_to_target,
314 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
315 "CHECKOUT" => \$checkout,
316 "TARGET_IMAGE" => \$target_image,
317 "LOCALVERSION" => \$localversion,
319 "BISECT_GOOD" => \$bisect_good,
320 "BISECT_BAD" => \$bisect_bad,
321 "BISECT_TYPE" => \$bisect_type,
322 "BISECT_START" => \$bisect_start,
323 "BISECT_REPLAY" => \$bisect_replay,
324 "BISECT_FILES" => \$bisect_files,
325 "BISECT_REVERSE" => \$bisect_reverse,
326 "BISECT_CHECK" => \$bisect_check,
328 "CONFIG_BISECT" => \$config_bisect,
329 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
330 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
332 "PATCHCHECK_TYPE" => \$patchcheck_type,
333 "PATCHCHECK_START" => \$patchcheck_start,
334 "PATCHCHECK_CHERRY" => \$patchcheck_cherry,
335 "PATCHCHECK_END" => \$patchcheck_end,
338 # Options may be used by other options, record them.
341 # default variables that can be used
342 chomp ($variable{"PWD"} = `pwd`);
344 $config_help{"MACHINE"} = << "EOF"
345 The machine hostname that you will test.
346 For build only tests, it is still needed to differentiate log files.
349 $config_help{"SSH_USER"} = << "EOF"
350 The box is expected to have ssh on normal bootup, provide the user
351 (most likely root, since you need privileged operations)
354 $config_help{"BUILD_DIR"} = << "EOF"
355 The directory that contains the Linux source code (full path).
356 You can use \${PWD} that will be the path where ktest.pl is run, or use
357 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
360 $config_help{"OUTPUT_DIR"} = << "EOF"
361 The directory that the objects will be built (full path).
362 (can not be same as BUILD_DIR)
363 You can use \${PWD} that will be the path where ktest.pl is run, or use
364 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
367 $config_help{"BUILD_TARGET"} = << "EOF"
368 The location of the compiled file to copy to the target.
369 (relative to OUTPUT_DIR)
372 $config_help{"BUILD_OPTIONS"} = << "EOF"
373 Options to add to \"make\" when building.
377 $config_help{"TARGET_IMAGE"} = << "EOF"
378 The place to put your image on the test machine.
381 $config_help{"POWER_CYCLE"} = << "EOF"
382 A script or command to reboot the box.
384 Here is a digital loggers power switch example
385 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
387 Here is an example to reboot a virtual box on the current host
388 with the name "Guest".
389 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
392 $config_help{"CONSOLE"} = << "EOF"
393 The script or command that reads the console
395 If you use ttywatch server, something like the following would work.
396 CONSOLE = nc -d localhost 3001
398 For a virtual machine with guest name "Guest".
399 CONSOLE = virsh console Guest
402 $config_help{"LOCALVERSION"} = << "EOF"
403 Required version ending to differentiate the test
404 from other linux builds on the system.
407 $config_help{"REBOOT_TYPE"} = << "EOF"
408 Way to reboot the box to the test kernel.
409 Only valid options so far are "grub", "grub2", "syslinux", and "script".
411 If you specify grub, it will assume grub version 1
412 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
413 and select that target to reboot to the kernel. If this is not
414 your setup, then specify "script" and have a command or script
415 specified in REBOOT_SCRIPT to boot to the target.
417 The entry in /boot/grub/menu.lst must be entered in manually.
418 The test will not modify that file.
420 If you specify grub2, then you also need to specify both \$GRUB_MENU
423 If you specify syslinux, then you may use SYSLINUX to define the syslinux
424 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
425 the syslinux install (defaults to /boot/extlinux). But you have to specify
426 SYSLINUX_LABEL to define the label to boot to for the test kernel.
429 $config_help{"GRUB_MENU"} = << "EOF"
430 The grub title name for the test kernel to boot
431 (Only mandatory if REBOOT_TYPE = grub or grub2)
433 Note, ktest.pl will not update the grub menu.lst, you need to
434 manually add an option for the test. ktest.pl will search
435 the grub menu.lst for this option to find what kernel to
438 For example, if in the /boot/grub/menu.lst the test kernel title has:
441 GRUB_MENU = Test Kernel
443 For grub2, a search of \$GRUB_FILE is performed for the lines
444 that begin with "menuentry". It will not detect submenus. The
445 menu must be a non-nested menu. Add the quotes used in the menu
446 to guarantee your selection, as the first menuentry with the content
447 of \$GRUB_MENU that is found will be used.
450 $config_help{"GRUB_FILE"} = << "EOF"
451 If grub2 is used, the full path for the grub.cfg file is placed
452 here. Use something like /boot/grub2/grub.cfg to search.
455 $config_help{"SYSLINUX_LABEL"} = << "EOF"
456 If syslinux is used, the label that boots the target kernel must
457 be specified with SYSLINUX_LABEL.
460 $config_help{"REBOOT_SCRIPT"} = << "EOF"
461 A script to reboot the target into the test kernel
462 (Only mandatory if REBOOT_TYPE = script)
467 if (defined($opt{"LOG_FILE"})) {
468 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
475 if (defined($opt{"LOG_FILE"})) {
488 my ($cancel, $prompt) = @_;
494 print "$prompt [y/n/C] ";
496 print "$prompt [Y/n] ";
500 if ($ans =~ /^\s*$/) {
507 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
509 last if ($ans =~ /^c$/i);
510 print "Please answer either 'y', 'n' or 'c'.\n";
512 print "Please answer either 'y' or 'n'.\n";
518 if ($ans !~ /^y$/i) {
527 return read_prompt 0, $prompt;
533 return read_prompt 1, $prompt;
536 sub get_mandatory_config {
540 return if (defined($opt{$config}));
542 if (defined($config_help{$config})) {
544 print $config_help{$config};
549 if (defined($default{$config}) && length($default{$config})) {
550 print "\[$default{$config}\] ";
553 $ans =~ s/^\s*(.*\S)\s*$/$1/;
554 if ($ans =~ /^\s*$/) {
555 if ($default{$config}) {
556 $ans = $default{$config};
558 print "Your answer can not be blank\n";
562 $entered_configs{$config} = ${ans};
574 $hours = int($time / 3600);
575 $time -= $hours * 3600;
578 $minutes = int($time / 60);
579 $time -= $minutes * 60;
583 doprint "$hours hour";
584 doprint "s" if ($hours > 1);
589 doprint "$minutes minute";
590 doprint "s" if ($minutes > 1);
594 doprint "$time second";
595 doprint "s" if ($time != 1);
601 doprint "Build time: ";
602 show_time($build_time);
606 doprint "Install time: ";
607 show_time($install_time);
611 doprint "Reboot time: ";
612 show_time($reboot_time);
616 doprint "Test time: ";
617 show_time($test_time);
620 # reset for iterations like bisect
627 sub get_mandatory_configs {
628 get_mandatory_config("MACHINE");
629 get_mandatory_config("BUILD_DIR");
630 get_mandatory_config("OUTPUT_DIR");
633 get_mandatory_config("BUILD_OPTIONS");
636 # options required for other than just building a kernel
638 get_mandatory_config("POWER_CYCLE");
639 get_mandatory_config("CONSOLE");
642 # options required for install and more
643 if ($buildonly != 1) {
644 get_mandatory_config("SSH_USER");
645 get_mandatory_config("BUILD_TARGET");
646 get_mandatory_config("TARGET_IMAGE");
649 get_mandatory_config("LOCALVERSION");
651 return if ($buildonly);
653 my $rtype = $opt{"REBOOT_TYPE"};
655 if (!defined($rtype)) {
656 if (!defined($opt{"GRUB_MENU"})) {
657 get_mandatory_config("REBOOT_TYPE");
658 $rtype = $entered_configs{"REBOOT_TYPE"};
664 if ($rtype eq "grub") {
665 get_mandatory_config("GRUB_MENU");
668 if ($rtype eq "grub2") {
669 get_mandatory_config("GRUB_MENU");
670 get_mandatory_config("GRUB_FILE");
673 if ($rtype eq "syslinux") {
674 get_mandatory_config("SYSLINUX_LABEL");
678 sub process_variables {
679 my ($value, $remove_undef) = @_;
682 # We want to check for '\', and it is just easier
683 # to check the previous characet of '$' and not need
684 # to worry if '$' is the first character. By adding
685 # a space to $value, we can just check [^\\]\$ and
686 # it will still work.
689 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
693 # append beginning of value to retval
694 $retval = "$retval$begin";
695 if (defined($variable{$var})) {
696 $retval = "$retval$variable{$var}";
697 } elsif (defined($remove_undef) && $remove_undef) {
698 # for if statements, any variable that is not defined,
699 # we simple convert to 0
700 $retval = "${retval}0";
702 # put back the origin piece.
703 $retval = "$retval\$\{$var\}";
704 # This could be an option that is used later, save
705 # it so we don't warn if this option is not one of
707 $used_options{$var} = 1;
711 $retval = "$retval$value";
713 # remove the space added in the beginning
720 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
722 my $prvalue = process_variables($rvalue);
724 if ($lvalue =~ /^(TEST|BISECT|CONFIG_BISECT)_TYPE(\[.*\])?$/ &&
725 $prvalue !~ /^(config_|)bisect$/ &&
726 $prvalue !~ /^build$/ &&
729 # Note if a test is something other than build, then we
730 # will need other mandatory options.
731 if ($prvalue ne "install") {
734 # install still limits some mandatory options.
739 if (defined($opt{$lvalue})) {
740 if (!$override || defined(${$overrides}{$lvalue})) {
743 $extra = "In the same override section!\n";
745 die "$name: $.: Option $lvalue defined more than once!\n$extra";
747 ${$overrides}{$lvalue} = $prvalue;
750 $opt{$lvalue} = $prvalue;
754 my ($lvalue, $rvalue, $name) = @_;
756 my $prvalue = process_variables($rvalue);
759 if (defined($evals{$lvalue})) {
760 $arr = $evals{$lvalue};
763 $evals{$lvalue} = $arr;
766 push @{$arr}, $rvalue;
770 my ($lvalue, $rvalue) = @_;
772 if ($rvalue =~ /^\s*$/) {
773 delete $variable{$lvalue};
775 $rvalue = process_variables($rvalue);
776 $variable{$lvalue} = $rvalue;
780 sub process_compare {
781 my ($lval, $cmp, $rval) = @_;
792 return $lval eq $rval;
793 } elsif ($cmp eq "!=") {
794 return $lval ne $rval;
795 } elsif ($cmp eq "=~") {
796 return $lval =~ m/$rval/;
797 } elsif ($cmp eq "!~") {
798 return $lval !~ m/$rval/;
801 my $statement = "$lval $cmp $rval";
802 my $ret = eval $statement;
804 # $@ stores error of eval
815 return defined($variable{$2}) ||
820 sub process_expression {
821 my ($name, $val) = @_;
825 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
828 if (process_expression($name, $express)) {
829 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
831 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
839 while ($val =~ s/^(.*?)($OR|$AND)//) {
843 if (process_expression($name, $express)) {
854 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
855 my $ret = process_compare($1, $2, $3);
857 die "$name: $.: Unable to process comparison\n";
862 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
864 return !value_defined($2);
866 return value_defined($2);
870 if ($val =~ /^\s*0\s*$/) {
872 } elsif ($val =~ /^\s*\d+\s*$/) {
876 die ("$name: $.: Undefined content $val in if statement\n");
880 my ($name, $value) = @_;
882 # Convert variables and replace undefined ones with 0
883 my $val = process_variables($value, 1);
884 my $ret = process_expression $name, $val;
890 my ($config, $current_test_num) = @_;
893 open($in, $config) || die "can't read file $config";
896 $name =~ s,.*/(.*),$1,;
898 my $test_num = $$current_test_num;
901 my $num_tests_set = 0;
914 # ignore blank lines and comments
915 next if (/^\s*$/ || /\s*\#/);
917 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
927 if ($type eq "TEST_START") {
929 if ($num_tests_set) {
930 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
933 $old_test_num = $test_num;
934 $old_repeat = $repeat;
936 $test_num += $repeat;
943 # If SKIP is anywhere in the line, the command will be skipped
944 if ($rest =~ s/\s+SKIP\b//) {
951 if ($rest =~ s/\sELSE\b//) {
953 die "$name: $.: ELSE found with out matching IF section\n$_";
964 if ($rest =~ s/\sIF\s+(.*)//) {
965 if (process_if($name, $1)) {
977 if ($type eq "TEST_START") {
978 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
980 $repeat_tests{"$test_num"} = $repeat;
982 } elsif ($rest =~ s/\sOVERRIDE\b//) {
985 # Clear previous overrides
990 if (!$skip && $rest !~ /^\s*$/) {
991 die "$name: $.: Gargbage found after $type\n$_";
994 if ($skip && $type eq "TEST_START") {
995 $test_num = $old_test_num;
996 $repeat = $old_repeat;
999 } elsif (/^\s*ELSE\b(.*)$/) {
1001 die "$name: $.: ELSE found with out matching IF section\n$_";
1010 if ($rest =~ /\sIF\s+(.*)/) {
1011 # May be a ELSE IF section.
1012 if (process_if($name, $1)) {
1023 if ($rest !~ /^\s*$/) {
1024 die "$name: $.: Gargbage found after DEFAULTS\n$_";
1027 } elsif (/^\s*INCLUDE\s+(\S+)/) {
1032 die "$name: $.: INCLUDE can only be done in default sections\n$_";
1035 my $file = process_variables($1);
1037 if ($file !~ m,^/,) {
1038 # check the path of the config file first
1039 if ($config =~ m,(.*)/,) {
1040 if (-f "$1/$file") {
1047 die "$name: $.: Can't read file $file\n$_";
1050 if (__read_config($file, \$test_num)) {
1054 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1061 if ($default || $lvalue =~ /\[\d+\]$/) {
1062 set_eval($lvalue, $rvalue, $name);
1064 my $val = "$lvalue\[$test_num\]";
1065 set_eval($val, $rvalue, $name);
1068 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1076 ($lvalue eq "NUM_TESTS" ||
1077 $lvalue eq "LOG_FILE" ||
1078 $lvalue eq "CLEAR_LOG")) {
1079 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
1082 if ($lvalue eq "NUM_TESTS") {
1084 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1087 die "$name: $.: NUM_TESTS must be set in default section\n";
1092 if ($default || $lvalue =~ /\[\d+\]$/) {
1093 set_value($lvalue, $rvalue, $override, \%overrides, $name);
1095 my $val = "$lvalue\[$test_num\]";
1096 set_value($val, $rvalue, $override, \%overrides, $name);
1099 $repeats{$val} = $repeat;
1102 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1108 # process config variables.
1109 # Config variables are only active while reading the
1110 # config and can be defined anywhere. They also ignore
1111 # TEST_START and DEFAULTS, but are skipped if they are in
1112 # on of these sections that have SKIP defined.
1113 # The save variable can be
1114 # defined multiple times and the new one simply overrides
1116 set_variable($lvalue, $rvalue);
1119 die "$name: $.: Garbage found in config\n$_";
1124 $test_num += $repeat - 1;
1125 $opt{"NUM_TESTS"} = $test_num;
1130 $$current_test_num = $test_num;
1136 print "What test case would you like to run?\n";
1137 print " (build, install or boot)\n";
1138 print " Other tests are available but require editing ktest.conf\n";
1139 print " (see tools/testing/ktest/sample.conf)\n";
1142 $default{"TEST_TYPE"} = $ans;
1151 $test_case = __read_config $config, \$test_num;
1153 # make sure we have all mandatory configs
1154 get_mandatory_configs;
1156 # was a test specified?
1158 print "No test case specified.\n";
1164 foreach my $default (keys %default) {
1165 if (!defined($opt{$default})) {
1166 $opt{$default} = $default{$default};
1170 if ($opt{"IGNORE_UNUSED"} == 1) {
1176 # check if there are any stragglers (typos?)
1177 foreach my $option (keys %opt) {
1179 # remove per test labels.
1181 if (!exists($option_map{$op}) &&
1182 !exists($default{$op}) &&
1183 !exists($used_options{$op})) {
1190 $s = " is" if (keys %not_used == 1);
1191 print "The following option$s not used; could be a typo:\n";
1192 foreach my $option (keys %not_used) {
1195 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1196 if (!read_yn "Do you want to continue?") {
1203 my ($name, $option, $i) = @_;
1205 # Add space to evaluate the character before $
1206 $option = " $option";
1211 foreach my $test (keys %repeat_tests) {
1213 $i < $test + $repeat_tests{$test}) {
1221 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1226 # Append beginning of line
1227 $retval = "$retval$start";
1229 # If the iteration option OPT[$i] exists, then use that.
1230 # otherwise see if the default OPT (without [$i]) exists.
1232 my $o = "$var\[$i\]";
1233 my $parento = "$var\[$parent\]";
1235 # If a variable contains itself, use the default var
1236 if (($var eq $name) && defined($opt{$var})) {
1238 $retval = "$retval$o";
1239 } elsif (defined($opt{$o})) {
1241 $retval = "$retval$o";
1242 } elsif ($repeated && defined($opt{$parento})) {
1243 $o = $opt{$parento};
1244 $retval = "$retval$o";
1245 } elsif (defined($opt{$var})) {
1247 $retval = "$retval$o";
1248 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1249 # special option KERNEL_VERSION uses kernel version
1251 $retval = "$retval$version";
1253 $retval = "$retval\$\{$var\}";
1259 $retval = "$retval$option";
1267 my ($name, $option, $i) = @_;
1269 my $option_name = "$name\[$i\]";
1272 my $old_option = $option;
1274 if (defined($evals{$option_name})) {
1275 $ev = $evals{$option_name};
1276 } elsif (defined($evals{$name})) {
1277 $ev = $evals{$name};
1282 for my $e (@{$ev}) {
1283 eval "\$option =~ $e";
1286 if ($option ne $old_option) {
1287 doprint("$name changed from '$old_option' to '$option'\n");
1294 my ($name, $option, $i) = @_;
1298 # Since an option can evaluate to another option,
1299 # keep iterating until we do not evaluate any more
1302 while ($prev ne $option) {
1303 # Check for recursive evaluations.
1304 # 100 deep should be more than enough.
1306 die "Over 100 evaluations accurred with $option\n" .
1307 "Check for recursive variables\n";
1310 $option = __eval_option($name, $option, $i);
1313 $option = process_evals($name, $option, $i);
1321 sub wait_for_monitor;
1327 # test if the machine can be connected to within a few seconds
1328 my $stat = run_ssh("echo check machine status", $connect_timeout);
1330 doprint("power cycle\n");
1335 run_command "$power_cycle";
1338 # flush out current monitor
1339 # May contain the reboot success line
1343 # Make sure everything has been written to disk
1346 if (defined($time)) {
1348 # flush out current monitor
1349 # May contain the reboot success line
1353 # try to reboot normally
1354 if (run_command $reboot) {
1355 if (defined($powercycle_after_reboot)) {
1356 sleep $powercycle_after_reboot;
1357 run_command "$power_cycle";
1360 # nope? power cycle it.
1361 run_command "$power_cycle";
1365 if (defined($time)) {
1367 # We only want to get to the new kernel, don't fail
1368 # if we stumble over a call trace.
1369 my $save_ignore_errors = $ignore_errors;
1372 # Look for the good kernel to boot
1373 if (wait_for_monitor($time, "Linux version")) {
1375 doprint "Reboot did not finish. Forcing power cycle\n";
1376 run_command "$power_cycle";
1379 $ignore_errors = $save_ignore_errors;
1381 # Still need to wait for the reboot to finish
1382 wait_for_monitor($time, $reboot_success_line);
1388 sub reboot_to_good {
1391 if (defined($switch_to_good)) {
1392 run_command $switch_to_good;
1401 return $test_type eq "build" || $no_reboot ||
1402 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1403 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build") ||
1404 ($test_type eq "config_bisect" && $opt{"CONFIG_BISECT_TYPE[$i]"} eq "build");
1408 doprint "CRITICAL FAILURE... ", @_, "\n";
1412 if ($reboot_on_error && !do_not_reboot) {
1414 doprint "REBOOTING\n";
1417 } elsif ($poweroff_on_error && defined($power_off)) {
1418 doprint "POWERING OFF\n";
1422 if (defined($opt{"LOG_FILE"})) {
1423 print " See $opt{LOG_FILE} for more info.\n";
1427 # restore terminal settings
1428 system("stty $stty_orig");
1431 if (defined($post_test)) {
1432 run_command $post_test;
1439 my ($ptm, $pts) = @_;
1441 my $TIOCSPTLCK = 0x40045431;
1442 my $TIOCGPTN = 0x80045430;
1444 sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
1445 dodie "Cant open /dev/ptmx";
1448 $tmp = pack("i", 0);
1449 ioctl($ptm, $TIOCSPTLCK, $tmp) or
1450 dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
1453 ioctl($ptm, $TIOCGPTN, $tmp) or
1454 dodie "ioctl TIOCGPTN for /dev/ptmx failed";
1455 $tmp = unpack("i", $tmp);
1457 sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
1458 dodie "Can't open /dev/pts/$tmp";
1462 my ($ptm, $pts) = @_;
1470 open(\*STDIN, '<&', $pts);
1471 open(\*STDOUT, '>&', $pts);
1472 open(\*STDERR, '>&', $pts);
1477 die "Can't open console $console";
1485 # save terminal settings
1486 $stty_orig = `stty -g`;
1488 # place terminal in cbreak mode so that stdin can be read one character at
1489 # a time without having to wait for a newline
1490 system("stty -icanon -echo -icrnl");
1492 create_pty($ptm, $pts);
1498 exec_console($ptm, $pts)
1506 open(PTSFD, "Stop perl from warning about single use of PTSFD");
1510 my ($fp, $pid) = @_;
1512 doprint "kill child process $pid\n";
1513 kill $close_console_signal, $pid;
1515 doprint "wait for child process $pid to exit\n";
1521 # restore terminal settings
1522 system("stty $stty_orig");
1526 if ($monitor_cnt++) {
1529 $monitor_fp = \*MONFD;
1530 $monitor_pid = open_console $monitor_fp;
1534 open(MONFD, "Stop perl from warning about single use of MONFD");
1538 return if (!defined $console);
1539 if (--$monitor_cnt) {
1542 close_console($monitor_fp, $monitor_pid);
1545 sub wait_for_monitor {
1546 my ($time, $stop) = @_;
1550 my $start_time = time;
1551 my $skip_call_trace = 0;
1553 my $bug_ignored = 0;
1556 doprint "** Wait for monitor to settle down **\n";
1558 # read the monitor and wait for the system to calm down
1560 $line = wait_for_input($monitor_fp, $time);
1561 last if (!defined($line));
1563 $full_line .= $line;
1565 if (defined($stop) && $full_line =~ /$stop/) {
1566 doprint "wait for monitor detected $stop\n";
1570 if ($full_line =~ /\[ backtrace testing \]/) {
1571 $skip_call_trace = 1;
1574 if ($full_line =~ /call trace:/i) {
1575 if (!$bug && !$skip_call_trace) {
1576 if ($ignore_errors) {
1584 if ($full_line =~ /\[ end of backtrace testing \]/) {
1585 $skip_call_trace = 0;
1588 if ($full_line =~ /Kernel panic -/) {
1592 if ($line =~ /\n/) {
1596 if ($now - $start_time >= $max_monitor_wait) {
1597 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1601 print "** Monitor flushed **\n";
1603 # if stop is defined but wasn't hit, return error
1604 # used by reboot (which wants to see a reboot)
1605 if (defined($stop) && !$booted) {
1612 my ($result, $basedir) = @_;
1614 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1615 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1617 my $type = $build_type;
1618 if ($type =~ /useconfig/) {
1619 $type = "useconfig";
1622 my $dir = "$machine-$test_type-$type-$result-$date";
1624 $dir = "$basedir/$dir";
1628 die "can't create $dir";
1632 "config" => $output_config,
1633 "buildlog" => $buildlog,
1635 "testlog" => $testlog,
1638 while (my ($name, $source) = each(%files)) {
1640 cp "$source", "$dir/$name" or
1641 die "failed to copy $source";
1645 doprint "*** Saved info to $dir ***\n";
1650 if ($die_on_failure) {
1658 # no need to reboot for just building.
1659 if (!do_not_reboot) {
1660 doprint "REBOOTING\n";
1661 reboot_to_good $sleep_time;
1666 if (defined($test_name)) {
1667 $name = " ($test_name)";
1672 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1673 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1674 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1675 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1676 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1678 if (defined($store_failures)) {
1679 save_logs "fail", $store_failures;
1682 if (defined($post_test)) {
1683 run_command $post_test;
1690 my ($command, $redirect, $timeout) = @_;
1698 $command =~ s/\$SSH_USER/$ssh_user/g;
1699 $command =~ s/\$MACHINE/$machine/g;
1701 doprint("$command ... ");
1704 $pid = open(CMD, "$command 2>&1 |") or
1705 (fail "unable to exec $command" and return 0);
1707 if (defined($opt{"LOG_FILE"})) {
1708 open(LOG, ">>$opt{LOG_FILE}") or
1709 dodie "failed to write to log";
1713 if (defined($redirect)) {
1714 if ($redirect eq 1) {
1716 # Have the output of the command on its own line
1719 open (RD, ">$redirect") or
1720 dodie "failed to write to redirect $redirect";
1725 my $hit_timeout = 0;
1729 if (defined($timeout)) {
1730 doprint "timeout = $timeout\n";
1732 my $line = wait_for_input($fp, $timeout);
1733 if (!defined($line)) {
1735 if (defined($timeout) && (($now - $start_time) >= $timeout)) {
1736 doprint "Hit timeout of $timeout, killing process\n";
1742 print LOG $line if ($dolog);
1743 print RD $line if ($dord);
1744 print $line if ($dostdout);
1748 # shift 8 for real exit status
1749 $run_command_status = $? >> 8;
1752 close(LOG) if ($dolog);
1753 close(RD) if ($dord);
1756 my $delta = $end_time - $start_time;
1759 doprint "[1 second] ";
1761 doprint "[$delta seconds] ";
1765 $run_command_status = 1;
1768 if ($run_command_status) {
1769 doprint "FAILED!\n";
1771 doprint "SUCCESS\n";
1774 return !$run_command_status;
1778 my ($cmd, $timeout) = @_;
1779 my $cp_exec = $ssh_exec;
1781 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1782 return run_command "$cp_exec", undef , $timeout;
1786 my ($src, $dst, $cp_scp) = @_;
1788 $cp_scp =~ s/\$SRC_FILE/$src/g;
1789 $cp_scp =~ s/\$DST_FILE/$dst/g;
1791 return run_command "$cp_scp";
1794 sub run_scp_install {
1795 my ($src, $dst) = @_;
1797 my $cp_scp = $scp_to_target_install;
1799 return run_scp($src, $dst, $cp_scp);
1803 my ($src, $dst) = @_;
1805 my $cp_scp = $scp_to_target;
1807 return run_scp($src, $dst, $cp_scp);
1810 sub get_grub2_index {
1812 return if (defined($grub_number) && defined($last_grub_menu) &&
1813 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1814 $last_machine eq $machine);
1816 doprint "Find grub2 menu ... ";
1819 my $ssh_grub = $ssh_exec;
1820 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1822 open(IN, "$ssh_grub |")
1823 or die "unable to get $grub_file";
1828 if (/^menuentry.*$grub_menu/) {
1832 } elsif (/^menuentry\s/) {
1838 die "Could not find '$grub_menu' in $grub_file on $machine"
1840 doprint "$grub_number\n";
1841 $last_grub_menu = $grub_menu;
1842 $last_machine = $machine;
1845 sub get_grub_index {
1847 if ($reboot_type eq "grub2") {
1852 if ($reboot_type ne "grub") {
1855 return if (defined($grub_number) && defined($last_grub_menu) &&
1856 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1857 $last_machine eq $machine);
1859 doprint "Find grub menu ... ";
1862 my $ssh_grub = $ssh_exec;
1863 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1865 open(IN, "$ssh_grub |")
1866 or die "unable to get menu.lst";
1871 if (/^\s*title\s+$grub_menu\s*$/) {
1875 } elsif (/^\s*title\s/) {
1881 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1883 doprint "$grub_number\n";
1884 $last_grub_menu = $grub_menu;
1885 $last_machine = $machine;
1890 my ($fp, $time) = @_;
1899 if (!defined($time)) {
1904 vec($rin, fileno($fp), 1) = 1;
1905 vec($rin, fileno(\*STDIN), 1) = 1;
1910 $nr = select($rout=$rin, undef, undef, $time);
1914 # copy data from stdin to the console
1915 if (vec($rout, fileno(\*STDIN), 1) == 1) {
1916 $nr = sysread(\*STDIN, $buf, 1000);
1917 syswrite($fp, $buf, $nr) if ($nr > 0);
1920 # The timeout is based on time waiting for the fp data
1921 if (vec($rout, fileno($fp), 1) != 1) {
1922 last if (defined($time) && (time - $start_time > $time));
1928 # try to read one char at a time
1929 while (sysread $fp, $ch, 1) {
1931 last if ($ch eq "\n");
1934 last if (!length($line));
1942 if (defined($switch_to_test)) {
1943 run_command $switch_to_test;
1946 if ($reboot_type eq "grub") {
1947 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1948 } elsif ($reboot_type eq "grub2") {
1949 run_ssh "$grub_reboot $grub_number";
1950 } elsif ($reboot_type eq "syslinux") {
1951 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
1952 } elsif (defined $reboot_script) {
1953 run_command "$reboot_script";
1961 doprint "git rev-list --max-count=1 $commit ... ";
1962 my $sha1 = `git rev-list --max-count=1 $commit`;
1969 dodie "Failed to get git $commit";
1982 my $bug_ignored = 0;
1983 my $skip_call_trace = 0;
1986 my $start_time = time;
1993 open(DMESG, "> $dmesg") or
1994 die "unable to write to $dmesg";
2000 my $monitor_start = time;
2002 my $version_found = 0;
2006 if ($bug && defined($stop_after_failure) &&
2007 $stop_after_failure >= 0) {
2008 my $time = $stop_after_failure - (time - $failure_start);
2009 $line = wait_for_input($monitor_fp, $time);
2010 if (!defined($line)) {
2011 doprint "bug timed out after $booted_timeout seconds\n";
2012 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
2016 $line = wait_for_input($monitor_fp, $booted_timeout);
2017 if (!defined($line)) {
2018 my $s = $booted_timeout == 1 ? "" : "s";
2019 doprint "Successful boot found: break after $booted_timeout second$s\n";
2023 $line = wait_for_input($monitor_fp);
2024 if (!defined($line)) {
2025 my $s = $timeout == 1 ? "" : "s";
2026 doprint "Timed out after $timeout second$s\n";
2034 # we are not guaranteed to get a full line
2035 $full_line .= $line;
2037 if ($full_line =~ /$success_line/) {
2039 $success_start = time;
2042 if ($booted && defined($stop_after_success) &&
2043 $stop_after_success >= 0) {
2045 if ($now - $success_start >= $stop_after_success) {
2046 doprint "Test forced to stop after $stop_after_success seconds after success\n";
2051 if ($full_line =~ /\[ backtrace testing \]/) {
2052 $skip_call_trace = 1;
2055 if ($full_line =~ /call trace:/i) {
2056 if (!$bug && !$skip_call_trace) {
2057 if ($ignore_errors) {
2061 $failure_start = time;
2066 if ($bug && defined($stop_after_failure) &&
2067 $stop_after_failure >= 0) {
2069 if ($now - $failure_start >= $stop_after_failure) {
2070 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
2075 if ($full_line =~ /\[ end of backtrace testing \]/) {
2076 $skip_call_trace = 0;
2079 if ($full_line =~ /Kernel panic -/) {
2080 $failure_start = time;
2084 # Detect triple faults by testing the banner
2085 if ($full_line =~ /\bLinux version (\S+).*\n/) {
2086 if ($1 eq $version) {
2088 } elsif ($version_found && $detect_triplefault) {
2089 # We already booted into the kernel we are testing,
2090 # but now we booted into another kernel?
2091 # Consider this a triple fault.
2092 doprint "Already booted in Linux kernel $version, but now\n";
2093 doprint "we booted into Linux kernel $1.\n";
2094 doprint "Assuming that this is a triple fault.\n";
2095 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
2100 if ($line =~ /\n/) {
2104 if ($stop_test_after > 0 && !$booted && !$bug) {
2105 if (time - $monitor_start > $stop_test_after) {
2106 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
2112 my $end_time = time;
2113 $reboot_time = $end_time - $start_time;
2118 return 0 if ($in_bisect);
2119 fail "failed - got a bug report" and return 0;
2123 return 0 if ($in_bisect);
2124 fail "failed - never got a boot prompt." and return 0;
2128 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2134 sub eval_kernel_version {
2137 $option =~ s/\$KERNEL_VERSION/$version/g;
2142 sub do_post_install {
2144 return if (!defined($post_install));
2146 my $cp_post_install = eval_kernel_version $post_install;
2147 run_command "$cp_post_install" or
2148 dodie "Failed to run post install";
2151 # Sometimes the reboot fails, and will hang. We try to ssh to the box
2152 # and if we fail, we force another reboot, that should powercycle it.
2154 if (!run_ssh "echo testing connection") {
2161 return if ($no_install);
2163 my $start_time = time;
2165 if (defined($pre_install)) {
2166 my $cp_pre_install = eval_kernel_version $pre_install;
2167 run_command "$cp_pre_install" or
2168 dodie "Failed to run pre install";
2171 my $cp_target = eval_kernel_version $target_image;
2175 run_scp_install "$outputdir/$build_target", "$cp_target" or
2176 dodie "failed to copy image";
2178 my $install_mods = 0;
2180 # should we process modules?
2182 open(IN, "$output_config") or dodie("Can't read config file");
2184 if (/CONFIG_MODULES(=y)?/) {
2193 if (!$install_mods) {
2195 doprint "No modules needed\n";
2196 my $end_time = time;
2197 $install_time = $end_time - $start_time;
2201 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
2202 dodie "Failed to install modules";
2204 my $modlib = "/lib/modules/$version";
2205 my $modtar = "ktest-mods.tar.bz2";
2207 run_ssh "rm -rf $modlib" or
2208 dodie "failed to remove old mods: $modlib";
2210 # would be nice if scp -r did not follow symbolic links
2211 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
2212 dodie "making tarball";
2214 run_scp_mod "$tmpdir/$modtar", "/tmp" or
2215 dodie "failed to copy modules";
2217 unlink "$tmpdir/$modtar";
2219 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
2220 dodie "failed to tar modules";
2222 run_ssh "rm -f /tmp/$modtar";
2226 my $end_time = time;
2227 $install_time = $end_time - $start_time;
2231 # get the release name
2232 return if ($have_version);
2233 doprint "$make kernelrelease ... ";
2234 $version = `$make -s kernelrelease | tail -1`;
2236 doprint "$version\n";
2240 sub start_monitor_and_install {
2241 # Make sure the stable kernel has finished booting
2243 # Install bisects, don't need console
2244 if (defined $console) {
2254 start_monitor if (defined $console);
2258 my $check_build_re = ".*:.*(warning|error|Error):.*";
2259 my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2261 sub process_warning_line {
2266 # for distcc heterogeneous systems, some compilers
2267 # do things differently causing warning lines
2268 # to be slightly different. This makes an attempt
2269 # to fixe those issues.
2271 # chop off the index into the line
2272 # using distcc, some compilers give different indexes
2273 # depending on white space
2274 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2276 # Some compilers use UTF-8 extended for quotes and some don't.
2277 $line =~ s/$utf8_quote/'/g;
2282 # Read buildlog and check against warnings file for any
2287 sub check_buildlog {
2288 return 1 if (!defined $warnings_file);
2292 # Failed builds should not reboot the target
2293 my $save_no_reboot = $no_reboot;
2296 if (-f $warnings_file) {
2297 open(IN, $warnings_file) or
2298 dodie "Error opening $warnings_file";
2301 if (/$check_build_re/) {
2302 my $warning = process_warning_line $_;
2304 $warnings_list{$warning} = 1;
2310 # If warnings file didn't exist, and WARNINGS_FILE exist,
2311 # then we fail on any warning!
2313 open(IN, $buildlog) or dodie "Can't open $buildlog";
2315 if (/$check_build_re/) {
2316 my $warning = process_warning_line $_;
2318 if (!defined $warnings_list{$warning}) {
2319 fail "New warning found (not in $warnings_file)\n$_\n";
2320 $no_reboot = $save_no_reboot;
2325 $no_reboot = $save_no_reboot;
2329 sub check_patch_buildlog {
2332 my @files = `git show $patch | diffstat -l`;
2334 foreach my $file (@files) {
2338 open(IN, "git show $patch |") or
2339 dodie "failed to show $patch";
2341 if (m,^--- a/(.*),) {
2343 $files[$#files] = $1;
2348 open(IN, $buildlog) or dodie "Can't open $buildlog";
2350 if (/^\s*(.*?):.*(warning|error)/) {
2352 foreach my $file (@files) {
2353 my $fullpath = "$builddir/$file";
2354 if ($file eq $err || $fullpath eq $err) {
2355 fail "$file built with warnings" and return 0;
2365 sub apply_min_config {
2366 my $outconfig = "$output_config.new";
2368 # Read the config file and remove anything that
2369 # is in the force_config hash (from minconfig and others)
2370 # then add the force config back.
2372 doprint "Applying minimum configurations into $output_config.new\n";
2374 open (OUT, ">$outconfig") or
2375 dodie "Can't create $outconfig";
2377 if (-f $output_config) {
2378 open (IN, $output_config) or
2379 dodie "Failed to open $output_config";
2381 if (/^(# )?(CONFIG_[^\s=]*)/) {
2382 next if (defined($force_config{$2}));
2388 foreach my $config (keys %force_config) {
2389 print OUT "$force_config{$config}\n";
2393 run_command "mv $outconfig $output_config";
2396 sub make_oldconfig {
2398 my @force_list = keys %force_config;
2400 if ($#force_list >= 0) {
2404 if (!run_command "$make olddefconfig") {
2405 # Perhaps olddefconfig doesn't exist in this version of the kernel
2407 doprint "olddefconfig failed, trying make oldnoconfig\n";
2408 if (!run_command "$make oldnoconfig") {
2409 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2410 # try a yes '' | oldconfig
2411 run_command "yes '' | $make oldconfig" or
2412 dodie "failed make config oldconfig";
2417 # read a config file and use this to force new configs.
2418 sub load_force_config {
2421 doprint "Loading force configs from $config\n";
2422 open(IN, $config) or
2423 dodie "failed to read $config";
2426 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2427 $force_config{$1} = $_;
2428 } elsif (/^# (CONFIG_\S*) is not set/) {
2429 $force_config{$1} = $_;
2440 my $start_time = time;
2442 # Failed builds should not reboot the target
2443 my $save_no_reboot = $no_reboot;
2446 # Calculate a new version from here.
2449 if (defined($pre_build)) {
2450 my $ret = run_command $pre_build;
2451 if (!$ret && defined($pre_build_die) &&
2453 dodie "failed to pre_build\n";
2457 if ($type =~ /^useconfig:(.*)/) {
2458 run_command "cp $1 $output_config" or
2459 dodie "could not copy $1 to .config";
2461 $type = "oldconfig";
2464 # old config can ask questions
2465 if ($type eq "oldconfig") {
2466 $type = "olddefconfig";
2468 # allow for empty configs
2469 run_command "touch $output_config";
2472 run_command "mv $output_config $outputdir/config_temp" or
2473 dodie "moving .config";
2475 run_command "$make mrproper" or dodie "make mrproper";
2477 run_command "mv $outputdir/config_temp $output_config" or
2478 dodie "moving config_temp";
2481 } elsif (!$noclean) {
2482 unlink "$output_config";
2483 run_command "$make mrproper" or
2484 dodie "make mrproper";
2487 # add something to distinguish this build
2488 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2489 print OUT "$localversion\n";
2492 if (defined($minconfig)) {
2493 load_force_config($minconfig);
2496 if ($type ne "olddefconfig") {
2497 run_command "$make $type" or
2498 dodie "failed make config";
2500 # Run old config regardless, to enforce min configurations
2503 my $build_ret = run_command "$make $build_options", $buildlog;
2505 if (defined($post_build)) {
2506 # Because a post build may change the kernel version
2509 my $ret = run_command $post_build;
2510 if (!$ret && defined($post_build_die) &&
2512 dodie "failed to post_build\n";
2517 # bisect may need this to pass
2519 $no_reboot = $save_no_reboot;
2522 fail "failed build" and return 0;
2525 $no_reboot = $save_no_reboot;
2527 my $end_time = time;
2528 $build_time = $end_time - $start_time;
2534 if (!run_ssh "halt" or defined($power_off)) {
2535 if (defined($poweroff_after_halt)) {
2536 sleep $poweroff_after_halt;
2537 run_command "$power_off";
2541 run_command "$power_off";
2552 if (defined($test_name)) {
2553 $name = " ($test_name)";
2558 doprint "\n\n*******************************************\n";
2559 doprint "*******************************************\n";
2560 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2561 doprint "*******************************************\n";
2562 doprint "*******************************************\n";
2564 if (defined($store_successes)) {
2565 save_logs "success", $store_successes;
2568 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2569 doprint "Reboot and wait $sleep_time seconds\n";
2570 reboot_to_good $sleep_time;
2573 if (defined($post_test)) {
2574 run_command $post_test;
2580 doprint "Pass, fail, or skip? [p/f/s]";
2583 if ($ans eq "p" || $ans eq "P") {
2585 } elsif ($ans eq "f" || $ans eq "F") {
2587 } elsif ($ans eq "s" || $ans eq "S") {
2590 print "Please answer 'p', 'f', or 's'\n";
2595 sub child_run_test {
2597 # child should have no power
2598 $reboot_on_error = 0;
2599 $poweroff_on_error = 0;
2600 $die_on_failure = 1;
2602 run_command $run_test, $testlog;
2604 exit $run_command_status;
2609 sub child_finished {
2619 my $bug_ignored = 0;
2621 my $start_time = time;
2625 doprint "run test $run_test\n";
2629 $SIG{CHLD} = qw(child_finished);
2633 child_run_test if (!$child_pid);
2638 $line = wait_for_input($monitor_fp, 1);
2639 if (defined($line)) {
2641 # we are not guaranteed to get a full line
2642 $full_line .= $line;
2645 if ($full_line =~ /call trace:/i) {
2646 if ($ignore_errors) {
2653 if ($full_line =~ /Kernel panic -/) {
2657 if ($line =~ /\n/) {
2661 } while (!$child_done && !$bug);
2663 if (!$bug && $bug_ignored) {
2664 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2668 my $failure_start = time;
2671 $line = wait_for_input($monitor_fp, 1);
2672 if (defined($line)) {
2676 if ($now - $failure_start >= $stop_after_failure) {
2679 } while (defined($line));
2681 doprint "Detected kernel crash!\n";
2682 # kill the child with extreme prejudice
2686 waitpid $child_pid, 0;
2687 $child_exit = $? >> 8;
2689 my $end_time = time;
2690 $test_time = $end_time - $start_time;
2692 if (!$bug && $in_bisect) {
2693 if (defined($bisect_ret_good)) {
2694 if ($child_exit == $bisect_ret_good) {
2698 if (defined($bisect_ret_skip)) {
2699 if ($child_exit == $bisect_ret_skip) {
2703 if (defined($bisect_ret_abort)) {
2704 if ($child_exit == $bisect_ret_abort) {
2705 fail "test abort" and return -2;
2708 if (defined($bisect_ret_bad)) {
2709 if ($child_exit == $bisect_ret_skip) {
2713 if (defined($bisect_ret_default)) {
2714 if ($bisect_ret_default eq "good") {
2716 } elsif ($bisect_ret_default eq "bad") {
2718 } elsif ($bisect_ret_default eq "skip") {
2720 } elsif ($bisect_ret_default eq "abort") {
2723 fail "unknown default action: $bisect_ret_default"
2729 if ($bug || $child_exit) {
2730 return 0 if $in_bisect;
2731 fail "test failed" and return 0;
2736 sub run_git_bisect {
2739 doprint "$command ... ";
2741 my $output = `$command 2>&1`;
2748 dodie "Failed to git bisect";
2751 doprint "SUCCESS\n";
2752 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2753 doprint "$1 [$2]\n";
2754 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2755 $bisect_bad_commit = $1;
2756 doprint "Found bad commit... $1\n";
2759 # we already logged it, just print it now.
2767 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2768 reboot_to_good $bisect_sleep_time;
2771 # returns 1 on success, 0 on failure, -1 on skip
2772 sub run_bisect_test {
2773 my ($type, $buildtype) = @_;
2782 build $buildtype or $failed = 1;
2784 if ($type ne "build") {
2785 if ($failed && $bisect_skip) {
2789 dodie "Failed on build" if $failed;
2792 start_monitor_and_install or $failed = 1;
2794 if ($type ne "boot") {
2795 if ($failed && $bisect_skip) {
2801 dodie "Failed on boot" if $failed;
2803 do_run_test or $failed = 1;
2814 # reboot the box to a kernel we can ssh to
2815 if ($type ne "build") {
2825 my $buildtype = "oldconfig";
2827 # We should have a minconfig to use?
2828 if (defined($minconfig)) {
2829 $buildtype = "useconfig:$minconfig";
2832 # If the user sets bisect_tries to less than 1, then no tries
2836 # Still let the user manually decide that though.
2837 if ($bisect_tries < 1 && $bisect_manual) {
2838 $ret = answer_bisect;
2841 for (my $i = 0; $i < $bisect_tries; $i++) {
2842 if ($bisect_tries > 1) {
2844 doprint("Running bisect trial $t of $bisect_tries:\n");
2846 $ret = run_bisect_test $type, $buildtype;
2848 if ($bisect_manual) {
2849 $ret = answer_bisect;
2855 # Are we looking for where it worked, not failed?
2856 if ($reverse_bisect && $ret >= 0) {
2862 } elsif ($ret == 0) {
2864 } elsif ($bisect_skip) {
2865 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2870 sub update_bisect_replay {
2871 my $tmp_log = "$tmpdir/ktest_bisect_log";
2872 run_command "git bisect log > $tmp_log" or
2873 die "can't create bisect log";
2882 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2883 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2884 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2886 my $good = $bisect_good;
2887 my $bad = $bisect_bad;
2888 my $type = $bisect_type;
2889 my $start = $bisect_start;
2890 my $replay = $bisect_replay;
2891 my $start_files = $bisect_files;
2893 if (defined($start_files)) {
2894 $start_files = " -- " . $start_files;
2899 # convert to true sha1's
2900 $good = get_sha1($good);
2901 $bad = get_sha1($bad);
2903 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2904 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2905 $reverse_bisect = 1;
2907 $reverse_bisect = 0;
2910 # Can't have a test without having a test to run
2911 if ($type eq "test" && !defined($run_test)) {
2915 # Check if a bisect was running
2916 my $bisect_start_file = "$builddir/.git/BISECT_START";
2918 my $check = $bisect_check;
2919 my $do_check = defined($check) && $check ne "0";
2921 if ( -f $bisect_start_file ) {
2922 print "Bisect in progress found\n";
2924 print " If you say yes, then no checks of good or bad will be done\n";
2926 if (defined($replay)) {
2927 print "** BISECT_REPLAY is defined in config file **";
2928 print " Ignore config option and perform new git bisect log?\n";
2929 if (read_ync " (yes, no, or cancel) ") {
2930 $replay = update_bisect_replay;
2933 } elsif (read_yn "read git log and continue?") {
2934 $replay = update_bisect_replay;
2942 my $head = get_sha1("HEAD");
2944 if ($check ne "good") {
2945 doprint "TESTING BISECT BAD [$bad]\n";
2946 run_command "git checkout $bad" or
2947 die "Failed to checkout $bad";
2949 $result = run_bisect $type;
2951 if ($result ne "bad") {
2952 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2956 if ($check ne "bad") {
2957 doprint "TESTING BISECT GOOD [$good]\n";
2958 run_command "git checkout $good" or
2959 die "Failed to checkout $good";
2961 $result = run_bisect $type;
2963 if ($result ne "good") {
2964 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2968 # checkout where we started
2969 run_command "git checkout $head" or
2970 die "Failed to checkout $head";
2973 run_command "git bisect start$start_files" or
2974 dodie "could not start bisect";
2976 if (defined($replay)) {
2977 run_command "git bisect replay $replay" or
2978 dodie "failed to run replay";
2981 run_command "git bisect good $good" or
2982 dodie "could not set bisect good to $good";
2984 run_git_bisect "git bisect bad $bad" or
2985 dodie "could not set bisect bad to $bad";
2989 if (defined($start)) {
2990 run_command "git checkout $start" or
2991 dodie "failed to checkout $start";
2996 $result = run_bisect $type;
2997 $test = run_git_bisect "git bisect $result";
3001 run_command "git bisect log" or
3002 dodie "could not capture git bisect log";
3004 run_command "git bisect reset" or
3005 dodie "could not reset git bisect";
3007 doprint "Bad commit was [$bisect_bad_commit]\n";
3012 # config_ignore holds the configs that were set (or unset) for
3013 # a good config and we will ignore these configs for the rest
3014 # of a config bisect. These configs stay as they were.
3017 # config_set holds what all configs were set as.
3020 # config_off holds the set of configs that the bad config had disabled.
3021 # We need to record them and set them in the .config when running
3022 # olddefconfig, because olddefconfig keeps the defaults.
3025 # config_off_tmp holds a set of configs to turn off for now
3028 # config_list is the set of configs that are being tested
3034 sub assign_configs {
3035 my ($hash, $config) = @_;
3037 doprint "Reading configs from $config\n";
3040 or dodie "Failed to read $config";
3044 if (/^((CONFIG\S*)=.*)/) {
3046 } elsif (/^(# (CONFIG\S*) is not set)/) {
3054 sub process_config_ignore {
3057 assign_configs \%config_ignore, $config;
3060 sub get_dependencies {
3063 my $arr = $dependency{$config};
3064 if (!defined($arr)) {
3070 foreach my $dep (@{$arr}) {
3071 print "ADD DEP $dep\n";
3072 @deps = (@deps, get_dependencies $dep);
3079 my ($pc, $file) = @_;
3081 my %configs = %{$pc};
3083 doprint "Saving configs into $file\n";
3085 open(OUT, ">$file") or dodie "Can not write to $file";
3087 foreach my $config (keys %configs) {
3088 print OUT "$configs{$config}\n";
3094 my ($name, $pc) = @_;
3096 doprint "Creating old config from $name configs\n";
3098 save_config $pc, $output_config;
3103 sub run_config_bisect_test {
3106 my $ret = run_bisect_test $type, "oldconfig";
3108 if ($bisect_manual) {
3109 $ret = answer_bisect;
3115 sub config_bisect_end {
3116 my ($good, $bad) = @_;
3117 my $diffexec = "diff -u";
3119 if (-f "$builddir/scripts/diffconfig") {
3120 $diffexec = "$builddir/scripts/diffconfig";
3122 doprint "\n\n***************************************\n";
3123 doprint "No more config bisecting possible.\n";
3124 run_command "$diffexec $good $bad", 1;
3125 doprint "***************************************\n\n";
3128 sub run_config_bisect {
3129 my ($good, $bad, $last_result) = @_;
3134 if (!length($last_result)) {
3137 run_command "$builddir/tools/testing/ktest/config-bisect.pl $reset -b $outputdir $good $bad $last_result", 1;
3139 # config-bisect returns:
3140 # 0 if there is more to bisect
3141 # 1 for finding a good config
3142 # 2 if it can not find any more configs
3144 if ($run_command_status) {
3145 return $run_command_status;
3148 $ret = run_config_bisect_test $config_bisect_type;
3150 doprint "NEW GOOD CONFIG\n";
3151 # Return 3 for good config
3154 doprint "NEW BAD CONFIG\n";
3155 # Return 4 for bad config
3166 my $type = $config_bisect_type;
3169 $bad_config = $config_bisect;
3171 if (defined($config_bisect_good)) {
3172 $good_config = $config_bisect_good;
3173 } elsif (defined($minconfig)) {
3174 $good_config = $minconfig;
3176 doprint "No config specified, checking if defconfig works";
3177 $ret = run_bisect_test $type, "defconfig";
3179 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3182 $good_config = $output_config;
3185 # we don't want min configs to cause issues here.
3186 doprint "Disabling 'MIN_CONFIG' for this test\n";
3193 doprint "Run good configs through make oldconfig\n";
3194 assign_configs \%tmp_configs, $good_config;
3195 create_config "$good_config", \%tmp_configs;
3196 $good_config = "$tmpdir/good_config";
3197 system("cp $output_config $good_config") == 0 or dodie "cp good config";
3199 doprint "Run bad configs through make oldconfig\n";
3200 assign_configs \%tmp_configs, $bad_config;
3201 create_config "$bad_config", \%tmp_configs;
3202 $bad_config = "$tmpdir/bad_config";
3203 system("cp $output_config $bad_config") == 0 or dodie "cp bad config";
3205 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3206 if ($config_bisect_check ne "good") {
3207 doprint "Testing bad config\n";
3209 $ret = run_bisect_test $type, "useconfig:$bad_config";
3211 fail "Bad config succeeded when expected to fail!";
3215 if ($config_bisect_check ne "bad") {
3216 doprint "Testing good config\n";
3218 $ret = run_bisect_test $type, "useconfig:$good_config";
3220 fail "Good config failed when expected to succeed!";
3229 $ret = run_config_bisect $good_config, $bad_config, $last_run;
3232 } elsif ($ret == 4) {
3236 } while ($ret == 3 || $ret == 4);
3239 config_bisect_end "$good_config.tmp", "$bad_config.tmp";
3242 return $ret if ($ret < 0);
3247 sub patchcheck_reboot {
3248 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3249 reboot_to_good $patchcheck_sleep_time;
3255 die "PATCHCHECK_START[$i] not defined\n"
3256 if (!defined($patchcheck_start));
3257 die "PATCHCHECK_TYPE[$i] not defined\n"
3258 if (!defined($patchcheck_type));
3260 my $start = $patchcheck_start;
3262 my $cherry = $patchcheck_cherry;
3263 if (!defined($cherry)) {
3268 if (defined($patchcheck_end)) {
3269 $end = $patchcheck_end;
3271 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
3274 # Get the true sha1's since we can use things like HEAD~3
3275 $start = get_sha1($start);
3276 $end = get_sha1($end);
3278 my $type = $patchcheck_type;
3280 # Can't have a test without having a test to run
3281 if ($type eq "test" && !defined($run_test)) {
3286 open (IN, "git cherry -v $start $end|") or
3287 dodie "could not get git list";
3289 open (IN, "git log --pretty=oneline $end|") or
3290 dodie "could not get git list";
3297 # git cherry adds a '+' we want to remove
3299 $list[$#list+1] = $_;
3300 last if (/^$start/);
3305 if ($list[$#list] !~ /^$start/) {
3306 fail "SHA1 $start not found";
3309 # go backwards in the list
3310 @list = reverse @list;
3313 doprint("Going to test the following commits:\n");
3314 foreach my $l (@list) {
3318 my $save_clean = $noclean;
3319 my %ignored_warnings;
3321 if (defined($ignore_warnings)) {
3322 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3323 $ignored_warnings{$sha1} = 1;
3328 foreach my $item (@list) {
3330 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3332 doprint "\nProcessing commit \"$item\"\n\n";
3334 run_command "git checkout $sha1" or
3335 die "Failed to checkout $sha1";
3337 # only clean on the first and last patch
3338 if ($item eq $list[0] ||
3339 $item eq $list[$#list]) {
3340 $noclean = $save_clean;
3345 if (defined($minconfig)) {
3346 build "useconfig:$minconfig" or return 0;
3348 # ?? no config to use?
3349 build "oldconfig" or return 0;
3352 # No need to do per patch checking if warnings file exists
3353 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3354 check_patch_buildlog $sha1 or return 0;
3357 check_buildlog or return 0;
3359 next if ($type eq "build");
3363 start_monitor_and_install or $failed = 1;
3365 if (!$failed && $type ne "boot"){
3366 do_run_test or $failed = 1;
3391 # $config depends on $dep
3392 my ($config, $dep) = @_;
3394 if (defined($depends{$config})) {
3395 $depends{$config} .= " " . $dep;
3397 $depends{$config} = $dep;
3400 # record the number of configs depending on $dep
3401 if (defined $depcount{$dep}) {
3404 $depcount{$dep} = 1;
3408 # taken from streamline_config.pl
3420 if (! -f $kconfig) {
3421 doprint "file $kconfig does not exist, skipping\n";
3425 open(KIN, "$kconfig")
3426 or die "Can't open $kconfig";
3430 # Make sure that lines ending with \ continue
3432 $_ = $line . " " . $_;
3443 # collect any Kconfig sources
3444 if (/^source\s*"(.*)"/) {
3445 $kconfigs[$#kconfigs+1] = $1;
3449 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3453 for (my $i = 0; $i < $iflevel; $i++) {
3454 add_dep $config, $ifdeps[$i];
3457 # collect the depends for the config
3458 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3460 add_dep $config, $1;
3462 # Get the configs that select this config
3463 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3465 # selected by depends on config
3466 add_dep $1, $config;
3468 # Check for if statements
3469 } elsif (/^if\s+(.*\S)\s*$/) {
3471 # remove beginning and ending non text
3472 $deps =~ s/^[^a-zA-Z0-9_]*//;
3473 $deps =~ s/[^a-zA-Z0-9_]*$//;
3475 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3477 $ifdeps[$iflevel++] = join ':', @deps;
3479 } elsif (/^endif/) {
3481 $iflevel-- if ($iflevel);
3484 } elsif (/^\s*help\s*$/) {
3490 # read in any configs that were found.
3491 foreach $kconfig (@kconfigs) {
3492 if (!defined($read_kconfigs{$kconfig})) {
3493 $read_kconfigs{$kconfig} = 1;
3494 read_kconfig("$builddir/$kconfig");
3500 # find out which arch this is by the kconfig file
3501 open (IN, $output_config)
3502 or dodie "Failed to read $output_config";
3505 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3512 if (!defined($arch)) {
3513 doprint "Could not find arch from config file\n";
3514 doprint "no dependencies used\n";
3518 # arch is really the subarch, we need to know
3519 # what directory to look at.
3520 if ($arch eq "i386" || $arch eq "x86_64") {
3522 } elsif ($arch =~ /^tile/) {
3526 my $kconfig = "$builddir/arch/$arch/Kconfig";
3528 if (! -f $kconfig && $arch =~ /\d$/) {
3530 # some subarchs have numbers, truncate them
3532 $kconfig = "$builddir/arch/$arch/Kconfig";
3533 if (! -f $kconfig) {
3534 doprint "No idea what arch dir $orig is for\n";
3535 doprint "no dependencies used\n";
3540 read_kconfig($kconfig);
3543 sub make_new_config {
3546 open (OUT, ">$output_config")
3547 or dodie "Failed to write $output_config";
3549 foreach my $config (@configs) {
3550 print OUT "$config\n";
3558 $config =~ s/CONFIG_//;
3566 my $kconfig = chomp_config $dep;
3568 $dep = $depends{"$kconfig"};
3570 # the dep string we have saves the dependencies as they
3571 # were found, including expressions like ! && ||. We
3572 # want to split this out into just an array of configs.
3574 my $valid = "A-Za-z_0-9";
3578 while ($dep =~ /[$valid]/) {
3580 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3581 my $conf = "CONFIG_" . $1;
3583 $configs[$#configs + 1] = $conf;
3585 $dep =~ s/^[^$valid]*[$valid]+//;
3587 die "this should never happen";
3597 my %processed_configs;
3598 my %nochange_config;
3600 sub test_this_config {
3605 # if we already processed this config, skip it
3606 if (defined($processed_configs{$config})) {
3609 $processed_configs{$config} = 1;
3611 # if this config failed during this round, skip it
3612 if (defined($nochange_config{$config})) {
3616 my $kconfig = chomp_config $config;
3618 # Test dependencies first
3619 if (defined($depends{"$kconfig"})) {
3620 my @parents = get_depends $config;
3621 foreach my $parent (@parents) {
3622 # if the parent is in the min config, check it first
3623 next if (!defined($min_configs{$parent}));
3624 $found = test_this_config($parent);
3625 if (defined($found)) {
3631 # Remove this config from the list of configs
3632 # do a make olddefconfig and then read the resulting
3633 # .config to make sure it is missing the config that
3635 my %configs = %min_configs;
3636 delete $configs{$config};
3637 make_new_config ((values %configs), (values %keep_configs));
3640 assign_configs \%configs, $output_config;
3642 if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
3646 doprint "disabling config $config did not change .config\n";
3648 $nochange_config{$config} = 1;
3653 sub make_min_config {
3656 my $type = $minconfig_type;
3657 if ($type ne "boot" && $type ne "test") {
3658 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3659 " make_min_config works only with 'boot' and 'test'\n" and return;
3662 if (!defined($output_minconfig)) {
3663 fail "OUTPUT_MIN_CONFIG not defined" and return;
3666 # If output_minconfig exists, and the start_minconfig
3667 # came from min_config, than ask if we should use
3669 if (-f $output_minconfig && !$start_minconfig_defined) {
3670 print "$output_minconfig exists\n";
3671 if (!defined($use_output_minconfig)) {
3672 if (read_yn " Use it as minconfig?") {
3673 $start_minconfig = $output_minconfig;
3675 } elsif ($use_output_minconfig > 0) {
3676 doprint "Using $output_minconfig as MIN_CONFIG\n";
3677 $start_minconfig = $output_minconfig;
3679 doprint "Set to still use MIN_CONFIG as starting point\n";
3683 if (!defined($start_minconfig)) {
3684 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3687 my $temp_config = "$tmpdir/temp_config";
3689 # First things first. We build an allnoconfig to find
3690 # out what the defaults are that we can't touch.
3691 # Some are selections, but we really can't handle selections.
3693 my $save_minconfig = $minconfig;
3696 run_command "$make allnoconfig" or return 0;
3700 process_config_ignore $output_config;
3702 undef %save_configs;
3705 if (defined($ignore_config)) {
3706 # make sure the file exists
3707 `touch $ignore_config`;
3708 assign_configs \%save_configs, $ignore_config;
3711 %keep_configs = %save_configs;
3713 doprint "Load initial configs from $start_minconfig\n";
3715 # Look at the current min configs, and save off all the
3716 # ones that were set via the allnoconfig
3717 assign_configs \%min_configs, $start_minconfig;
3719 my @config_keys = keys %min_configs;
3721 # All configs need a depcount
3722 foreach my $config (@config_keys) {
3723 my $kconfig = chomp_config $config;
3724 if (!defined $depcount{$kconfig}) {
3725 $depcount{$kconfig} = 0;
3729 # Remove anything that was set by the make allnoconfig
3730 # we shouldn't need them as they get set for us anyway.
3731 foreach my $config (@config_keys) {
3732 # Remove anything in the ignore_config
3733 if (defined($keep_configs{$config})) {
3734 my $file = $ignore_config;
3735 $file =~ s,.*/(.*?)$,$1,;
3736 doprint "$config set by $file ... ignored\n";
3737 delete $min_configs{$config};
3740 # But make sure the settings are the same. If a min config
3741 # sets a selection, we do not want to get rid of it if
3742 # it is not the same as what we have. Just move it into
3744 if (defined($config_ignore{$config})) {
3745 if ($config_ignore{$config} ne $min_configs{$config}) {
3746 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3747 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3748 $keep_configs{$config} = $min_configs{$config};
3750 doprint "$config set by allnoconfig ... ignored\n";
3752 delete $min_configs{$config};
3764 # Now disable each config one by one and do a make oldconfig
3765 # till we find a config that changes our list.
3767 my @test_configs = keys %min_configs;
3769 # Sort keys by who is most dependent on
3770 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3773 # Put configs that did not modify the config at the end.
3775 for (my $i = 0; $i < $#test_configs; $i++) {
3776 if (!defined($nochange_config{$test_configs[0]})) {
3780 # This config didn't change the .config last time.
3781 # Place it at the end
3782 my $config = shift @test_configs;
3783 push @test_configs, $config;
3786 # if every test config has failed to modify the .config file
3787 # in the past, then reset and start over.
3789 undef %nochange_config;
3792 undef %processed_configs;
3794 foreach my $config (@test_configs) {
3796 $found = test_this_config $config;
3798 last if (defined($found));
3800 # oh well, try another config
3803 if (!defined($found)) {
3804 # we could have failed due to the nochange_config hash
3805 # reset and try again
3807 undef %nochange_config;
3811 doprint "No more configs found that we can disable\n";
3819 doprint "Test with $config disabled\n";
3821 # set in_bisect to keep build and monitor from dieing
3825 build "oldconfig" or $failed = 1;
3827 start_monitor_and_install or $failed = 1;
3829 if ($type eq "test" && !$failed) {
3830 do_run_test or $failed = 1;
3839 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3840 # this config is needed, add it to the ignore list.
3841 $keep_configs{$config} = $min_configs{$config};
3842 $save_configs{$config} = $min_configs{$config};
3843 delete $min_configs{$config};
3845 # update new ignore configs
3846 if (defined($ignore_config)) {
3847 open (OUT, ">$temp_config")
3848 or die "Can't write to $temp_config";
3849 foreach my $config (keys %save_configs) {
3850 print OUT "$save_configs{$config}\n";
3853 run_command "mv $temp_config $ignore_config" or
3854 dodie "failed to copy update to $ignore_config";
3858 # We booted without this config, remove it from the minconfigs.
3859 doprint "$config is not needed, disabling\n";
3861 delete $min_configs{$config};
3863 # Also disable anything that is not enabled in this config
3865 assign_configs \%configs, $output_config;
3866 my @config_keys = keys %min_configs;
3867 foreach my $config (@config_keys) {
3868 if (!defined($configs{$config})) {
3869 doprint "$config is not set, disabling\n";
3870 delete $min_configs{$config};
3874 # Save off all the current mandatory configs
3875 open (OUT, ">$temp_config")
3876 or die "Can't write to $temp_config";
3877 foreach my $config (keys %keep_configs) {
3878 print OUT "$keep_configs{$config}\n";
3880 foreach my $config (keys %min_configs) {
3881 print OUT "$min_configs{$config}\n";
3885 run_command "mv $temp_config $output_minconfig" or
3886 dodie "failed to copy update to $output_minconfig";
3889 doprint "Reboot and wait $sleep_time seconds\n";
3890 reboot_to_good $sleep_time;
3897 sub make_warnings_file {
3900 if (!defined($warnings_file)) {
3901 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3904 if ($build_type eq "nobuild") {
3905 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3908 build $build_type or dodie "Failed to build";
3910 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3912 open(IN, $buildlog) or dodie "Can't open $buildlog";
3915 # Some compilers use UTF-8 extended for quotes
3916 # for distcc heterogeneous systems, this causes issues
3919 if (/$check_build_re/) {
3930 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
3933 $ktest_config = $ARGV[0];
3934 if (! -f $ktest_config) {
3935 print "$ktest_config does not exist.\n";
3936 if (!read_yn "Create it?") {
3942 if (! -f $ktest_config) {
3945 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3947 # Generated by ktest.pl
3950 # PWD is a ktest.pl variable that will result in the process working
3951 # directory that ktest.pl is executed in.
3953 # THIS_DIR is automatically assigned the PWD of the path that generated
3954 # the config file. It is best to use this variable when assigning other
3955 # directory paths within this directory. This allows you to easily
3956 # move the test cases to other locations or to other machines.
3958 THIS_DIR := $variable{"PWD"}
3960 # Define each test with TEST_START
3961 # The config options below it will override the defaults
3963 TEST_TYPE = $default{"TEST_TYPE"}
3970 read_config $ktest_config;
3972 if (defined($opt{"LOG_FILE"})) {
3973 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
3976 # Append any configs entered in manually to the config file.
3977 my @new_configs = keys %entered_configs;
3978 if ($#new_configs >= 0) {
3979 print "\nAppending entered in configs to $ktest_config\n";
3980 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3981 foreach my $config (@new_configs) {
3982 print OUT "$config = $entered_configs{$config}\n";
3983 $opt{$config} = process_variables($entered_configs{$config});
3987 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3988 unlink $opt{"LOG_FILE"};
3991 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3993 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3996 doprint "DEFAULT OPTIONS:\n";
3998 doprint "\nTEST $i OPTIONS";
3999 if (defined($repeat_tests{$i})) {
4000 $repeat = $repeat_tests{$i};
4001 doprint " ITERATE $repeat";
4006 foreach my $option (sort keys %opt) {
4008 if ($option =~ /\[(\d+)\]$/) {
4014 doprint "$option = $opt{$option}\n";
4018 sub option_defined {
4021 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
4028 sub __set_test_option {
4029 my ($name, $i) = @_;
4031 my $option = "$name\[$i\]";
4033 if (option_defined($option)) {
4034 return $opt{$option};
4037 foreach my $test (keys %repeat_tests) {
4039 $i < $test + $repeat_tests{$test}) {
4040 $option = "$name\[$test\]";
4041 if (option_defined($option)) {
4042 return $opt{$option};
4047 if (option_defined($name)) {
4054 sub set_test_option {
4055 my ($name, $i) = @_;
4057 my $option = __set_test_option($name, $i);
4058 return $option if (!defined($option));
4060 return eval_option($name, $option, $i);
4063 # First we need to do is the builds
4064 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
4066 # Do not reboot on failing test options
4068 $reboot_success = 0;
4079 undef %force_config;
4081 my $makecmd = set_test_option("MAKE_CMD", $i);
4083 $outputdir = set_test_option("OUTPUT_DIR", $i);
4084 $builddir = set_test_option("BUILD_DIR", $i);
4086 chdir $builddir || die "can't change directory to $builddir";
4088 if (!-d $outputdir) {
4089 mkpath($outputdir) or
4090 die "can't create $outputdir";
4093 $make = "$makecmd O=$outputdir";
4095 # Load all the options into their mapped variable names
4096 foreach my $opt (keys %option_map) {
4097 ${$option_map{$opt}} = set_test_option($opt, $i);
4100 $start_minconfig_defined = 1;
4102 # The first test may override the PRE_KTEST option
4103 if (defined($pre_ktest) && $i == 1) {
4105 run_command $pre_ktest;
4108 # Any test can override the POST_KTEST option
4109 # The last test takes precedence.
4110 if (defined($post_ktest)) {
4111 $final_post_ktest = $post_ktest;
4114 if (!defined($start_minconfig)) {
4115 $start_minconfig_defined = 0;
4116 $start_minconfig = $minconfig;
4121 die "can't create $tmpdir";
4124 $ENV{"SSH_USER"} = $ssh_user;
4125 $ENV{"MACHINE"} = $machine;
4127 $buildlog = "$tmpdir/buildlog-$machine";
4128 $testlog = "$tmpdir/testlog-$machine";
4129 $dmesg = "$tmpdir/dmesg-$machine";
4130 $output_config = "$outputdir/.config";
4133 $target = "$ssh_user\@$machine";
4134 if ($reboot_type eq "grub") {
4135 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4136 } elsif ($reboot_type eq "grub2") {
4137 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4138 dodie "GRUB_FILE not defined" if (!defined($grub_file));
4139 } elsif ($reboot_type eq "syslinux") {
4140 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
4144 my $run_type = $build_type;
4145 if ($test_type eq "patchcheck") {
4146 $run_type = $patchcheck_type;
4147 } elsif ($test_type eq "bisect") {
4148 $run_type = $bisect_type;
4149 } elsif ($test_type eq "config_bisect") {
4150 $run_type = $config_bisect_type;
4151 } elsif ($test_type eq "make_min_config") {
4153 } elsif ($test_type eq "make_warnings_file") {
4157 # mistake in config file?
4158 if (!defined($run_type)) {
4159 $run_type = "ERROR";
4163 $installme = " no_install" if ($no_install);
4167 if (defined($test_name)) {
4168 $name = " ($test_name)";
4172 doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
4174 if (defined($pre_test)) {
4175 run_command $pre_test;
4182 if (defined($addconfig)) {
4183 my $min = $minconfig;
4184 if (!defined($minconfig)) {
4187 run_command "cat $addconfig $min > $tmpdir/add_config" or
4188 dodie "Failed to create temp config";
4189 $minconfig = "$tmpdir/add_config";
4192 if (defined($checkout)) {
4193 run_command "git checkout $checkout" or
4194 die "failed to checkout $checkout";
4199 # A test may opt to not reboot the box
4200 if ($reboot_on_success) {
4201 $reboot_success = 1;
4204 if ($test_type eq "bisect") {
4207 } elsif ($test_type eq "config_bisect") {
4210 } elsif ($test_type eq "patchcheck") {
4213 } elsif ($test_type eq "make_min_config") {
4216 } elsif ($test_type eq "make_warnings_file") {
4218 make_warnings_file $i;
4222 if ($build_type ne "nobuild") {
4223 build $build_type or next;
4224 check_buildlog or next;
4227 if ($test_type eq "install") {
4234 if ($test_type ne "build") {
4236 start_monitor_and_install or $failed = 1;
4238 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4239 do_run_test or $failed = 1;
4253 if (defined($final_post_ktest)) {
4254 run_command $final_post_ktest;
4257 if ($opt{"POWEROFF_ON_SUCCESS"}) {
4259 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4261 } elsif (defined($switch_to_good)) {
4262 # still need to get to the good kernel
4263 run_command $switch_to_good;
4267 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";