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",
63 # required, and we will ask users if they don't have them but we keep the default
64 # value something that is common.
65 "REBOOT_TYPE" => "grub",
66 "LOCALVERSION" => "-test",
68 "BUILD_TARGET" => "arch/x86/boot/bzImage",
69 "TARGET_IMAGE" => "/boot/vmlinuz-test",
75 my $ktest_config = "ktest.conf";
104 my $poweroff_on_error;
105 my $reboot_on_success;
107 my $powercycle_after_reboot;
108 my $poweroff_after_halt;
109 my $max_monitor_wait;
112 my $scp_to_target_install;
130 my $start_minconfig_defined;
131 my $output_minconfig;
133 my $use_output_minconfig;
139 my $bisect_bad_commit = "";
144 my $config_bisect_good;
148 my $bisect_ret_abort;
149 my $bisect_ret_default;
150 my $in_patchcheck = 0;
159 my $bisect_sleep_time;
160 my $patchcheck_sleep_time;
167 my $detect_triplefault;
169 my $close_console_signal;
170 my $reboot_success_line;
172 my $stop_after_success;
173 my $stop_after_failure;
193 my $config_bisect_type;
194 my $config_bisect_check;
197 my $patchcheck_start;
198 my $patchcheck_cherry;
201 # set when a test is something other that just building or install
202 # which would require more options.
205 # tell build not to worry about warnings, even when WARNINGS_FILE is set
208 # set when creating a new config
215 # force_config is the list of configs that we force enabled (or disabled)
216 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
219 # do not force reboots on config problems
223 my $reboot_success = 0;
226 "MACHINE" => \$machine,
227 "SSH_USER" => \$ssh_user,
228 "TMP_DIR" => \$tmpdir,
229 "OUTPUT_DIR" => \$outputdir,
230 "BUILD_DIR" => \$builddir,
231 "TEST_TYPE" => \$test_type,
232 "PRE_KTEST" => \$pre_ktest,
233 "POST_KTEST" => \$post_ktest,
234 "PRE_TEST" => \$pre_test,
235 "POST_TEST" => \$post_test,
236 "BUILD_TYPE" => \$build_type,
237 "BUILD_OPTIONS" => \$build_options,
238 "PRE_BUILD" => \$pre_build,
239 "POST_BUILD" => \$post_build,
240 "PRE_BUILD_DIE" => \$pre_build_die,
241 "POST_BUILD_DIE" => \$post_build_die,
242 "POWER_CYCLE" => \$power_cycle,
243 "REBOOT" => \$reboot,
244 "BUILD_NOCLEAN" => \$noclean,
245 "MIN_CONFIG" => \$minconfig,
246 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
247 "START_MIN_CONFIG" => \$start_minconfig,
248 "MIN_CONFIG_TYPE" => \$minconfig_type,
249 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
250 "WARNINGS_FILE" => \$warnings_file,
251 "IGNORE_CONFIG" => \$ignore_config,
252 "TEST" => \$run_test,
253 "ADD_CONFIG" => \$addconfig,
254 "REBOOT_TYPE" => \$reboot_type,
255 "GRUB_MENU" => \$grub_menu,
256 "GRUB_FILE" => \$grub_file,
257 "GRUB_REBOOT" => \$grub_reboot,
258 "SYSLINUX" => \$syslinux,
259 "SYSLINUX_PATH" => \$syslinux_path,
260 "SYSLINUX_LABEL" => \$syslinux_label,
261 "PRE_INSTALL" => \$pre_install,
262 "POST_INSTALL" => \$post_install,
263 "NO_INSTALL" => \$no_install,
264 "REBOOT_SCRIPT" => \$reboot_script,
265 "REBOOT_ON_ERROR" => \$reboot_on_error,
266 "SWITCH_TO_GOOD" => \$switch_to_good,
267 "SWITCH_TO_TEST" => \$switch_to_test,
268 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
269 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
270 "DIE_ON_FAILURE" => \$die_on_failure,
271 "POWER_OFF" => \$power_off,
272 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
273 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
274 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
275 "SLEEP_TIME" => \$sleep_time,
276 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
277 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
278 "IGNORE_WARNINGS" => \$ignore_warnings,
279 "IGNORE_ERRORS" => \$ignore_errors,
280 "BISECT_MANUAL" => \$bisect_manual,
281 "BISECT_SKIP" => \$bisect_skip,
282 "BISECT_TRIES" => \$bisect_tries,
283 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
284 "BISECT_RET_GOOD" => \$bisect_ret_good,
285 "BISECT_RET_BAD" => \$bisect_ret_bad,
286 "BISECT_RET_SKIP" => \$bisect_ret_skip,
287 "BISECT_RET_ABORT" => \$bisect_ret_abort,
288 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
289 "STORE_FAILURES" => \$store_failures,
290 "STORE_SUCCESSES" => \$store_successes,
291 "TEST_NAME" => \$test_name,
292 "TIMEOUT" => \$timeout,
293 "BOOTED_TIMEOUT" => \$booted_timeout,
294 "CONSOLE" => \$console,
295 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
296 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
297 "SUCCESS_LINE" => \$success_line,
298 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
299 "STOP_AFTER_SUCCESS" => \$stop_after_success,
300 "STOP_AFTER_FAILURE" => \$stop_after_failure,
301 "STOP_TEST_AFTER" => \$stop_test_after,
302 "BUILD_TARGET" => \$build_target,
303 "SSH_EXEC" => \$ssh_exec,
304 "SCP_TO_TARGET" => \$scp_to_target,
305 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
306 "CHECKOUT" => \$checkout,
307 "TARGET_IMAGE" => \$target_image,
308 "LOCALVERSION" => \$localversion,
310 "BISECT_GOOD" => \$bisect_good,
311 "BISECT_BAD" => \$bisect_bad,
312 "BISECT_TYPE" => \$bisect_type,
313 "BISECT_START" => \$bisect_start,
314 "BISECT_REPLAY" => \$bisect_replay,
315 "BISECT_FILES" => \$bisect_files,
316 "BISECT_REVERSE" => \$bisect_reverse,
317 "BISECT_CHECK" => \$bisect_check,
319 "CONFIG_BISECT" => \$config_bisect,
320 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
321 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
323 "PATCHCHECK_TYPE" => \$patchcheck_type,
324 "PATCHCHECK_START" => \$patchcheck_start,
325 "PATCHCHECK_CHERRY" => \$patchcheck_cherry,
326 "PATCHCHECK_END" => \$patchcheck_end,
329 # Options may be used by other options, record them.
332 # default variables that can be used
333 chomp ($variable{"PWD"} = `pwd`);
335 $config_help{"MACHINE"} = << "EOF"
336 The machine hostname that you will test.
337 For build only tests, it is still needed to differentiate log files.
340 $config_help{"SSH_USER"} = << "EOF"
341 The box is expected to have ssh on normal bootup, provide the user
342 (most likely root, since you need privileged operations)
345 $config_help{"BUILD_DIR"} = << "EOF"
346 The directory that contains the Linux source code (full path).
347 You can use \${PWD} that will be the path where ktest.pl is run, or use
348 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
351 $config_help{"OUTPUT_DIR"} = << "EOF"
352 The directory that the objects will be built (full path).
353 (can not be same as BUILD_DIR)
354 You can use \${PWD} that will be the path where ktest.pl is run, or use
355 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
358 $config_help{"BUILD_TARGET"} = << "EOF"
359 The location of the compiled file to copy to the target.
360 (relative to OUTPUT_DIR)
363 $config_help{"BUILD_OPTIONS"} = << "EOF"
364 Options to add to \"make\" when building.
368 $config_help{"TARGET_IMAGE"} = << "EOF"
369 The place to put your image on the test machine.
372 $config_help{"POWER_CYCLE"} = << "EOF"
373 A script or command to reboot the box.
375 Here is a digital loggers power switch example
376 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
378 Here is an example to reboot a virtual box on the current host
379 with the name "Guest".
380 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
383 $config_help{"CONSOLE"} = << "EOF"
384 The script or command that reads the console
386 If you use ttywatch server, something like the following would work.
387 CONSOLE = nc -d localhost 3001
389 For a virtual machine with guest name "Guest".
390 CONSOLE = virsh console Guest
393 $config_help{"LOCALVERSION"} = << "EOF"
394 Required version ending to differentiate the test
395 from other linux builds on the system.
398 $config_help{"REBOOT_TYPE"} = << "EOF"
399 Way to reboot the box to the test kernel.
400 Only valid options so far are "grub", "grub2", "syslinux", and "script".
402 If you specify grub, it will assume grub version 1
403 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
404 and select that target to reboot to the kernel. If this is not
405 your setup, then specify "script" and have a command or script
406 specified in REBOOT_SCRIPT to boot to the target.
408 The entry in /boot/grub/menu.lst must be entered in manually.
409 The test will not modify that file.
411 If you specify grub2, then you also need to specify both \$GRUB_MENU
414 If you specify syslinux, then you may use SYSLINUX to define the syslinux
415 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
416 the syslinux install (defaults to /boot/extlinux). But you have to specify
417 SYSLINUX_LABEL to define the label to boot to for the test kernel.
420 $config_help{"GRUB_MENU"} = << "EOF"
421 The grub title name for the test kernel to boot
422 (Only mandatory if REBOOT_TYPE = grub or grub2)
424 Note, ktest.pl will not update the grub menu.lst, you need to
425 manually add an option for the test. ktest.pl will search
426 the grub menu.lst for this option to find what kernel to
429 For example, if in the /boot/grub/menu.lst the test kernel title has:
432 GRUB_MENU = Test Kernel
434 For grub2, a search of \$GRUB_FILE is performed for the lines
435 that begin with "menuentry". It will not detect submenus. The
436 menu must be a non-nested menu. Add the quotes used in the menu
437 to guarantee your selection, as the first menuentry with the content
438 of \$GRUB_MENU that is found will be used.
441 $config_help{"GRUB_FILE"} = << "EOF"
442 If grub2 is used, the full path for the grub.cfg file is placed
443 here. Use something like /boot/grub2/grub.cfg to search.
446 $config_help{"SYSLINUX_LABEL"} = << "EOF"
447 If syslinux is used, the label that boots the target kernel must
448 be specified with SYSLINUX_LABEL.
451 $config_help{"REBOOT_SCRIPT"} = << "EOF"
452 A script to reboot the target into the test kernel
453 (Only mandatory if REBOOT_TYPE = script)
458 if (defined($opt{"LOG_FILE"})) {
459 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
466 if (defined($opt{"LOG_FILE"})) {
479 my ($cancel, $prompt) = @_;
485 print "$prompt [y/n/C] ";
487 print "$prompt [Y/n] ";
491 if ($ans =~ /^\s*$/) {
498 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
500 last if ($ans =~ /^c$/i);
501 print "Please answer either 'y', 'n' or 'c'.\n";
503 print "Please answer either 'y' or 'n'.\n";
509 if ($ans !~ /^y$/i) {
518 return read_prompt 0, $prompt;
524 return read_prompt 1, $prompt;
527 sub get_mandatory_config {
531 return if (defined($opt{$config}));
533 if (defined($config_help{$config})) {
535 print $config_help{$config};
540 if (defined($default{$config}) && length($default{$config})) {
541 print "\[$default{$config}\] ";
544 $ans =~ s/^\s*(.*\S)\s*$/$1/;
545 if ($ans =~ /^\s*$/) {
546 if ($default{$config}) {
547 $ans = $default{$config};
549 print "Your answer can not be blank\n";
553 $entered_configs{$config} = ${ans};
558 sub get_mandatory_configs {
559 get_mandatory_config("MACHINE");
560 get_mandatory_config("BUILD_DIR");
561 get_mandatory_config("OUTPUT_DIR");
564 get_mandatory_config("BUILD_OPTIONS");
567 # options required for other than just building a kernel
569 get_mandatory_config("POWER_CYCLE");
570 get_mandatory_config("CONSOLE");
573 # options required for install and more
574 if ($buildonly != 1) {
575 get_mandatory_config("SSH_USER");
576 get_mandatory_config("BUILD_TARGET");
577 get_mandatory_config("TARGET_IMAGE");
580 get_mandatory_config("LOCALVERSION");
582 return if ($buildonly);
584 my $rtype = $opt{"REBOOT_TYPE"};
586 if (!defined($rtype)) {
587 if (!defined($opt{"GRUB_MENU"})) {
588 get_mandatory_config("REBOOT_TYPE");
589 $rtype = $entered_configs{"REBOOT_TYPE"};
595 if ($rtype eq "grub") {
596 get_mandatory_config("GRUB_MENU");
599 if ($rtype eq "grub2") {
600 get_mandatory_config("GRUB_MENU");
601 get_mandatory_config("GRUB_FILE");
604 if ($rtype eq "syslinux") {
605 get_mandatory_config("SYSLINUX_LABEL");
609 sub process_variables {
610 my ($value, $remove_undef) = @_;
613 # We want to check for '\', and it is just easier
614 # to check the previous characet of '$' and not need
615 # to worry if '$' is the first character. By adding
616 # a space to $value, we can just check [^\\]\$ and
617 # it will still work.
620 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
624 # append beginning of value to retval
625 $retval = "$retval$begin";
626 if (defined($variable{$var})) {
627 $retval = "$retval$variable{$var}";
628 } elsif (defined($remove_undef) && $remove_undef) {
629 # for if statements, any variable that is not defined,
630 # we simple convert to 0
631 $retval = "${retval}0";
633 # put back the origin piece.
634 $retval = "$retval\$\{$var\}";
635 # This could be an option that is used later, save
636 # it so we don't warn if this option is not one of
638 $used_options{$var} = 1;
642 $retval = "$retval$value";
644 # remove the space added in the beginning
651 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
653 my $prvalue = process_variables($rvalue);
655 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
656 # Note if a test is something other than build, then we
657 # will need other manditory options.
658 if ($prvalue ne "install") {
659 # for bisect, we need to check BISECT_TYPE
660 if ($prvalue ne "bisect") {
664 # install still limits some manditory options.
669 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
670 if ($prvalue ne "install") {
673 # install still limits some manditory options.
678 if (defined($opt{$lvalue})) {
679 if (!$override || defined(${$overrides}{$lvalue})) {
682 $extra = "In the same override section!\n";
684 die "$name: $.: Option $lvalue defined more than once!\n$extra";
686 ${$overrides}{$lvalue} = $prvalue;
689 $opt{$lvalue} = $prvalue;
693 my ($lvalue, $rvalue, $name) = @_;
695 my $prvalue = process_variables($rvalue);
698 if (defined($evals{$lvalue})) {
699 $arr = $evals{$lvalue};
702 $evals{$lvalue} = $arr;
705 push @{$arr}, $rvalue;
709 my ($lvalue, $rvalue) = @_;
711 if ($rvalue =~ /^\s*$/) {
712 delete $variable{$lvalue};
714 $rvalue = process_variables($rvalue);
715 $variable{$lvalue} = $rvalue;
719 sub process_compare {
720 my ($lval, $cmp, $rval) = @_;
731 return $lval eq $rval;
732 } elsif ($cmp eq "!=") {
733 return $lval ne $rval;
734 } elsif ($cmp eq "=~") {
735 return $lval =~ m/$rval/;
736 } elsif ($cmp eq "!~") {
737 return $lval !~ m/$rval/;
740 my $statement = "$lval $cmp $rval";
741 my $ret = eval $statement;
743 # $@ stores error of eval
754 return defined($variable{$2}) ||
759 sub process_expression {
760 my ($name, $val) = @_;
764 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
767 if (process_expression($name, $express)) {
768 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
770 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
778 while ($val =~ s/^(.*?)($OR|$AND)//) {
782 if (process_expression($name, $express)) {
793 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
794 my $ret = process_compare($1, $2, $3);
796 die "$name: $.: Unable to process comparison\n";
801 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
803 return !value_defined($2);
805 return value_defined($2);
809 if ($val =~ /^\s*0\s*$/) {
811 } elsif ($val =~ /^\s*\d+\s*$/) {
815 die ("$name: $.: Undefined content $val in if statement\n");
819 my ($name, $value) = @_;
821 # Convert variables and replace undefined ones with 0
822 my $val = process_variables($value, 1);
823 my $ret = process_expression $name, $val;
829 my ($config, $current_test_num) = @_;
832 open($in, $config) || die "can't read file $config";
835 $name =~ s,.*/(.*),$1,;
837 my $test_num = $$current_test_num;
840 my $num_tests_set = 0;
853 # ignore blank lines and comments
854 next if (/^\s*$/ || /\s*\#/);
856 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
866 if ($type eq "TEST_START") {
868 if ($num_tests_set) {
869 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
872 $old_test_num = $test_num;
873 $old_repeat = $repeat;
875 $test_num += $repeat;
882 # If SKIP is anywhere in the line, the command will be skipped
883 if ($rest =~ s/\s+SKIP\b//) {
890 if ($rest =~ s/\sELSE\b//) {
892 die "$name: $.: ELSE found with out matching IF section\n$_";
903 if ($rest =~ s/\sIF\s+(.*)//) {
904 if (process_if($name, $1)) {
916 if ($type eq "TEST_START") {
917 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
919 $repeat_tests{"$test_num"} = $repeat;
921 } elsif ($rest =~ s/\sOVERRIDE\b//) {
924 # Clear previous overrides
929 if (!$skip && $rest !~ /^\s*$/) {
930 die "$name: $.: Gargbage found after $type\n$_";
933 if ($skip && $type eq "TEST_START") {
934 $test_num = $old_test_num;
935 $repeat = $old_repeat;
938 } elsif (/^\s*ELSE\b(.*)$/) {
940 die "$name: $.: ELSE found with out matching IF section\n$_";
949 if ($rest =~ /\sIF\s+(.*)/) {
950 # May be a ELSE IF section.
951 if (process_if($name, $1)) {
962 if ($rest !~ /^\s*$/) {
963 die "$name: $.: Gargbage found after DEFAULTS\n$_";
966 } elsif (/^\s*INCLUDE\s+(\S+)/) {
971 die "$name: $.: INCLUDE can only be done in default sections\n$_";
974 my $file = process_variables($1);
976 if ($file !~ m,^/,) {
977 # check the path of the config file first
978 if ($config =~ m,(.*)/,) {
986 die "$name: $.: Can't read file $file\n$_";
989 if (__read_config($file, \$test_num)) {
993 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1000 if ($default || $lvalue =~ /\[\d+\]$/) {
1001 set_eval($lvalue, $rvalue, $name);
1003 my $val = "$lvalue\[$test_num\]";
1004 set_eval($val, $rvalue, $name);
1007 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1015 ($lvalue eq "NUM_TESTS" ||
1016 $lvalue eq "LOG_FILE" ||
1017 $lvalue eq "CLEAR_LOG")) {
1018 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
1021 if ($lvalue eq "NUM_TESTS") {
1023 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1026 die "$name: $.: NUM_TESTS must be set in default section\n";
1031 if ($default || $lvalue =~ /\[\d+\]$/) {
1032 set_value($lvalue, $rvalue, $override, \%overrides, $name);
1034 my $val = "$lvalue\[$test_num\]";
1035 set_value($val, $rvalue, $override, \%overrides, $name);
1038 $repeats{$val} = $repeat;
1041 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1047 # process config variables.
1048 # Config variables are only active while reading the
1049 # config and can be defined anywhere. They also ignore
1050 # TEST_START and DEFAULTS, but are skipped if they are in
1051 # on of these sections that have SKIP defined.
1052 # The save variable can be
1053 # defined multiple times and the new one simply overrides
1055 set_variable($lvalue, $rvalue);
1058 die "$name: $.: Garbage found in config\n$_";
1063 $test_num += $repeat - 1;
1064 $opt{"NUM_TESTS"} = $test_num;
1069 $$current_test_num = $test_num;
1075 print "What test case would you like to run?\n";
1076 print " (build, install or boot)\n";
1077 print " Other tests are available but require editing the config file\n";
1080 $default{"TEST_TYPE"} = $ans;
1089 $test_case = __read_config $config, \$test_num;
1091 # make sure we have all mandatory configs
1092 get_mandatory_configs;
1094 # was a test specified?
1096 print "No test case specified.\n";
1102 foreach my $default (keys %default) {
1103 if (!defined($opt{$default})) {
1104 $opt{$default} = $default{$default};
1108 if ($opt{"IGNORE_UNUSED"} == 1) {
1114 # check if there are any stragglers (typos?)
1115 foreach my $option (keys %opt) {
1117 # remove per test labels.
1119 if (!exists($option_map{$op}) &&
1120 !exists($default{$op}) &&
1121 !exists($used_options{$op})) {
1128 $s = " is" if (keys %not_used == 1);
1129 print "The following option$s not used; could be a typo:\n";
1130 foreach my $option (keys %not_used) {
1133 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1134 if (!read_yn "Do you want to continue?") {
1141 my ($name, $option, $i) = @_;
1143 # Add space to evaluate the character before $
1144 $option = " $option";
1149 foreach my $test (keys %repeat_tests) {
1151 $i < $test + $repeat_tests{$test}) {
1159 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1164 # Append beginning of line
1165 $retval = "$retval$start";
1167 # If the iteration option OPT[$i] exists, then use that.
1168 # otherwise see if the default OPT (without [$i]) exists.
1170 my $o = "$var\[$i\]";
1171 my $parento = "$var\[$parent\]";
1173 # If a variable contains itself, use the default var
1174 if (($var eq $name) && defined($opt{$var})) {
1176 $retval = "$retval$o";
1177 } elsif (defined($opt{$o})) {
1179 $retval = "$retval$o";
1180 } elsif ($repeated && defined($opt{$parento})) {
1181 $o = $opt{$parento};
1182 $retval = "$retval$o";
1183 } elsif (defined($opt{$var})) {
1185 $retval = "$retval$o";
1186 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1187 # special option KERNEL_VERSION uses kernel version
1189 $retval = "$retval$version";
1191 $retval = "$retval\$\{$var\}";
1197 $retval = "$retval$option";
1205 my ($name, $option, $i) = @_;
1207 my $option_name = "$name\[$i\]";
1210 my $old_option = $option;
1212 if (defined($evals{$option_name})) {
1213 $ev = $evals{$option_name};
1214 } elsif (defined($evals{$name})) {
1215 $ev = $evals{$name};
1220 for my $e (@{$ev}) {
1221 eval "\$option =~ $e";
1224 if ($option ne $old_option) {
1225 doprint("$name changed from '$old_option' to '$option'\n");
1232 my ($name, $option, $i) = @_;
1236 # Since an option can evaluate to another option,
1237 # keep iterating until we do not evaluate any more
1240 while ($prev ne $option) {
1241 # Check for recursive evaluations.
1242 # 100 deep should be more than enough.
1244 die "Over 100 evaluations accurred with $option\n" .
1245 "Check for recursive variables\n";
1248 $option = __eval_option($name, $option, $i);
1251 $option = process_evals($name, $option, $i);
1259 sub wait_for_monitor;
1264 # Make sure everything has been written to disk
1267 if (defined($time)) {
1269 # flush out current monitor
1270 # May contain the reboot success line
1274 # try to reboot normally
1275 if (run_command $reboot) {
1276 if (defined($powercycle_after_reboot)) {
1277 sleep $powercycle_after_reboot;
1278 run_command "$power_cycle";
1281 # nope? power cycle it.
1282 run_command "$power_cycle";
1285 if (defined($time)) {
1287 # We only want to get to the new kernel, don't fail
1288 # if we stumble over a call trace.
1289 my $save_ignore_errors = $ignore_errors;
1292 # Look for the good kernel to boot
1293 if (wait_for_monitor($time, "Linux version")) {
1295 doprint "Reboot did not finish. Forcing power cycle\n";
1296 run_command "$power_cycle";
1299 $ignore_errors = $save_ignore_errors;
1301 # Still need to wait for the reboot to finish
1302 wait_for_monitor($time, $reboot_success_line);
1308 sub reboot_to_good {
1311 if (defined($switch_to_good)) {
1312 run_command $switch_to_good;
1321 return $test_type eq "build" || $no_reboot ||
1322 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1323 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1327 doprint "CRITICAL FAILURE... ", @_, "\n";
1331 if ($reboot_on_error && !do_not_reboot) {
1333 doprint "REBOOTING\n";
1336 } elsif ($poweroff_on_error && defined($power_off)) {
1337 doprint "POWERING OFF\n";
1341 if (defined($opt{"LOG_FILE"})) {
1342 print " See $opt{LOG_FILE} for more info.\n";
1353 # save terminal settings
1356 my $pid = open($fp, "$console|") or
1357 dodie "Can't open console $console";
1359 $flags = fcntl($fp, F_GETFL, 0) or
1360 dodie "Can't get flags for the socket: $!";
1361 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1362 dodie "Can't set flags for the socket: $!";
1368 my ($fp, $pid) = @_;
1370 doprint "kill child process $pid\n";
1371 kill $close_console_signal, $pid;
1376 # restore terminal settings
1377 system("stty $stty");
1381 if ($monitor_cnt++) {
1384 $monitor_fp = \*MONFD;
1385 $monitor_pid = open_console $monitor_fp;
1389 open(MONFD, "Stop perl from warning about single use of MONFD");
1393 return if (!defined $console);
1394 if (--$monitor_cnt) {
1397 close_console($monitor_fp, $monitor_pid);
1400 sub wait_for_monitor {
1401 my ($time, $stop) = @_;
1405 my $start_time = time;
1406 my $skip_call_trace = 0;
1408 my $bug_ignored = 0;
1411 doprint "** Wait for monitor to settle down **\n";
1413 # read the monitor and wait for the system to calm down
1415 $line = wait_for_input($monitor_fp, $time);
1416 last if (!defined($line));
1418 $full_line .= $line;
1420 if (defined($stop) && $full_line =~ /$stop/) {
1421 doprint "wait for monitor detected $stop\n";
1425 if ($full_line =~ /\[ backtrace testing \]/) {
1426 $skip_call_trace = 1;
1429 if ($full_line =~ /call trace:/i) {
1430 if (!$bug && !$skip_call_trace) {
1431 if ($ignore_errors) {
1439 if ($full_line =~ /\[ end of backtrace testing \]/) {
1440 $skip_call_trace = 0;
1443 if ($full_line =~ /Kernel panic -/) {
1447 if ($line =~ /\n/) {
1451 if ($now - $start_time >= $max_monitor_wait) {
1452 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1456 print "** Monitor flushed **\n";
1458 # if stop is defined but wasn't hit, return error
1459 # used by reboot (which wants to see a reboot)
1460 if (defined($stop) && !$booted) {
1467 my ($result, $basedir) = @_;
1469 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1470 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1472 my $type = $build_type;
1473 if ($type =~ /useconfig/) {
1474 $type = "useconfig";
1477 my $dir = "$machine-$test_type-$type-$result-$date";
1479 $dir = "$basedir/$dir";
1483 die "can't create $dir";
1487 "config" => $output_config,
1488 "buildlog" => $buildlog,
1490 "testlog" => $testlog,
1493 while (my ($name, $source) = each(%files)) {
1495 cp "$source", "$dir/$name" or
1496 die "failed to copy $source";
1500 doprint "*** Saved info to $dir ***\n";
1505 if (defined($post_test)) {
1506 run_command $post_test;
1509 if ($die_on_failure) {
1517 # no need to reboot for just building.
1518 if (!do_not_reboot) {
1519 doprint "REBOOTING\n";
1520 reboot_to_good $sleep_time;
1525 if (defined($test_name)) {
1526 $name = " ($test_name)";
1529 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1530 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1531 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1532 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1533 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1535 if (defined($store_failures)) {
1536 save_logs "fail", $store_failures;
1543 my ($command, $redirect) = @_;
1552 $command =~ s/\$SSH_USER/$ssh_user/g;
1553 $command =~ s/\$MACHINE/$machine/g;
1555 doprint("$command ... ");
1557 $pid = open(CMD, "$command 2>&1 |") or
1558 (fail "unable to exec $command" and return 0);
1560 if (defined($opt{"LOG_FILE"})) {
1561 open(LOG, ">>$opt{LOG_FILE}") or
1562 dodie "failed to write to log";
1566 if (defined($redirect)) {
1567 open (RD, ">$redirect") or
1568 dodie "failed to write to redirect $redirect";
1573 print LOG if ($dolog);
1574 print RD if ($dord);
1581 close(LOG) if ($dolog);
1582 close(RD) if ($dord);
1585 my $delta = $end_time - $start_time;
1588 doprint "[1 second] ";
1590 doprint "[$delta seconds] ";
1594 doprint "FAILED!\n";
1596 doprint "SUCCESS\n";
1604 my $cp_exec = $ssh_exec;
1606 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1607 return run_command "$cp_exec";
1611 my ($src, $dst, $cp_scp) = @_;
1613 $cp_scp =~ s/\$SRC_FILE/$src/g;
1614 $cp_scp =~ s/\$DST_FILE/$dst/g;
1616 return run_command "$cp_scp";
1619 sub run_scp_install {
1620 my ($src, $dst) = @_;
1622 my $cp_scp = $scp_to_target_install;
1624 return run_scp($src, $dst, $cp_scp);
1628 my ($src, $dst) = @_;
1630 my $cp_scp = $scp_to_target;
1632 return run_scp($src, $dst, $cp_scp);
1635 sub get_grub2_index {
1637 return if (defined($grub_number) && defined($last_grub_menu) &&
1638 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1639 $last_machine eq $machine);
1641 doprint "Find grub2 menu ... ";
1644 my $ssh_grub = $ssh_exec;
1645 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1647 open(IN, "$ssh_grub |")
1648 or die "unable to get $grub_file";
1653 if (/^menuentry.*$grub_menu/) {
1657 } elsif (/^menuentry\s/) {
1663 die "Could not find '$grub_menu' in $grub_file on $machine"
1665 doprint "$grub_number\n";
1666 $last_grub_menu = $grub_menu;
1667 $last_machine = $machine;
1670 sub get_grub_index {
1672 if ($reboot_type eq "grub2") {
1677 if ($reboot_type ne "grub") {
1680 return if (defined($grub_number) && defined($last_grub_menu) &&
1681 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1682 $last_machine eq $machine);
1684 doprint "Find grub menu ... ";
1687 my $ssh_grub = $ssh_exec;
1688 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1690 open(IN, "$ssh_grub |")
1691 or die "unable to get menu.lst";
1696 if (/^\s*title\s+$grub_menu\s*$/) {
1700 } elsif (/^\s*title\s/) {
1706 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1708 doprint "$grub_number\n";
1709 $last_grub_menu = $grub_menu;
1710 $last_machine = $machine;
1715 my ($fp, $time) = @_;
1721 if (!defined($time)) {
1726 vec($rin, fileno($fp), 1) = 1;
1727 ($ready, $time) = select($rin, undef, undef, $time);
1731 # try to read one char at a time
1732 while (sysread $fp, $ch, 1) {
1734 last if ($ch eq "\n");
1737 if (!length($line)) {
1745 if (defined($switch_to_test)) {
1746 run_command $switch_to_test;
1749 if ($reboot_type eq "grub") {
1750 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1751 } elsif ($reboot_type eq "grub2") {
1752 run_ssh "$grub_reboot $grub_number";
1753 } elsif ($reboot_type eq "syslinux") {
1754 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
1755 } elsif (defined $reboot_script) {
1756 run_command "$reboot_script";
1764 doprint "git rev-list --max-count=1 $commit ... ";
1765 my $sha1 = `git rev-list --max-count=1 $commit`;
1772 dodie "Failed to get git $commit";
1785 my $bug_ignored = 0;
1786 my $skip_call_trace = 0;
1794 open(DMESG, "> $dmesg") or
1795 die "unable to write to $dmesg";
1801 my $monitor_start = time;
1803 my $version_found = 0;
1807 if ($bug && defined($stop_after_failure) &&
1808 $stop_after_failure >= 0) {
1809 my $time = $stop_after_failure - (time - $failure_start);
1810 $line = wait_for_input($monitor_fp, $time);
1811 if (!defined($line)) {
1812 doprint "bug timed out after $booted_timeout seconds\n";
1813 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1817 $line = wait_for_input($monitor_fp, $booted_timeout);
1818 if (!defined($line)) {
1819 my $s = $booted_timeout == 1 ? "" : "s";
1820 doprint "Successful boot found: break after $booted_timeout second$s\n";
1824 $line = wait_for_input($monitor_fp);
1825 if (!defined($line)) {
1826 my $s = $timeout == 1 ? "" : "s";
1827 doprint "Timed out after $timeout second$s\n";
1835 # we are not guaranteed to get a full line
1836 $full_line .= $line;
1838 if ($full_line =~ /$success_line/) {
1840 $success_start = time;
1843 if ($booted && defined($stop_after_success) &&
1844 $stop_after_success >= 0) {
1846 if ($now - $success_start >= $stop_after_success) {
1847 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1852 if ($full_line =~ /\[ backtrace testing \]/) {
1853 $skip_call_trace = 1;
1856 if ($full_line =~ /call trace:/i) {
1857 if (!$bug && !$skip_call_trace) {
1858 if ($ignore_errors) {
1862 $failure_start = time;
1867 if ($bug && defined($stop_after_failure) &&
1868 $stop_after_failure >= 0) {
1870 if ($now - $failure_start >= $stop_after_failure) {
1871 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1876 if ($full_line =~ /\[ end of backtrace testing \]/) {
1877 $skip_call_trace = 0;
1880 if ($full_line =~ /Kernel panic -/) {
1881 $failure_start = time;
1885 # Detect triple faults by testing the banner
1886 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1887 if ($1 eq $version) {
1889 } elsif ($version_found && $detect_triplefault) {
1890 # We already booted into the kernel we are testing,
1891 # but now we booted into another kernel?
1892 # Consider this a triple fault.
1893 doprint "Already booted in Linux kernel $version, but now\n";
1894 doprint "we booted into Linux kernel $1.\n";
1895 doprint "Assuming that this is a triple fault.\n";
1896 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1901 if ($line =~ /\n/) {
1905 if ($stop_test_after > 0 && !$booted && !$bug) {
1906 if (time - $monitor_start > $stop_test_after) {
1907 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1916 return 0 if ($in_bisect);
1917 fail "failed - got a bug report" and return 0;
1921 return 0 if ($in_bisect);
1922 fail "failed - never got a boot prompt." and return 0;
1926 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1932 sub eval_kernel_version {
1935 $option =~ s/\$KERNEL_VERSION/$version/g;
1940 sub do_post_install {
1942 return if (!defined($post_install));
1944 my $cp_post_install = eval_kernel_version $post_install;
1945 run_command "$cp_post_install" or
1946 dodie "Failed to run post install";
1949 # Sometimes the reboot fails, and will hang. We try to ssh to the box
1950 # and if we fail, we force another reboot, that should powercycle it.
1952 if (!run_ssh "echo testing connection") {
1959 return if ($no_install);
1961 if (defined($pre_install)) {
1962 my $cp_pre_install = eval_kernel_version $pre_install;
1963 run_command "$cp_pre_install" or
1964 dodie "Failed to run pre install";
1967 my $cp_target = eval_kernel_version $target_image;
1971 run_scp_install "$outputdir/$build_target", "$cp_target" or
1972 dodie "failed to copy image";
1974 my $install_mods = 0;
1976 # should we process modules?
1978 open(IN, "$output_config") or dodie("Can't read config file");
1980 if (/CONFIG_MODULES(=y)?/) {
1989 if (!$install_mods) {
1991 doprint "No modules needed\n";
1995 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1996 dodie "Failed to install modules";
1998 my $modlib = "/lib/modules/$version";
1999 my $modtar = "ktest-mods.tar.bz2";
2001 run_ssh "rm -rf $modlib" or
2002 dodie "failed to remove old mods: $modlib";
2004 # would be nice if scp -r did not follow symbolic links
2005 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
2006 dodie "making tarball";
2008 run_scp_mod "$tmpdir/$modtar", "/tmp" or
2009 dodie "failed to copy modules";
2011 unlink "$tmpdir/$modtar";
2013 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
2014 dodie "failed to tar modules";
2016 run_ssh "rm -f /tmp/$modtar";
2022 # get the release name
2023 return if ($have_version);
2024 doprint "$make kernelrelease ... ";
2025 $version = `$make -s kernelrelease | tail -1`;
2027 doprint "$version\n";
2031 sub start_monitor_and_boot {
2032 # Make sure the stable kernel has finished booting
2034 # Install bisects, don't need console
2035 if (defined $console) {
2045 start_monitor if (defined $console);
2049 my $check_build_re = ".*:.*(warning|error|Error):.*";
2050 my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2052 sub process_warning_line {
2057 # for distcc heterogeneous systems, some compilers
2058 # do things differently causing warning lines
2059 # to be slightly different. This makes an attempt
2060 # to fixe those issues.
2062 # chop off the index into the line
2063 # using distcc, some compilers give different indexes
2064 # depending on white space
2065 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2067 # Some compilers use UTF-8 extended for quotes and some don't.
2068 $line =~ s/$utf8_quote/'/g;
2073 # Read buildlog and check against warnings file for any
2078 sub check_buildlog {
2079 return 1 if (!defined $warnings_file);
2083 # Failed builds should not reboot the target
2084 my $save_no_reboot = $no_reboot;
2087 if (-f $warnings_file) {
2088 open(IN, $warnings_file) or
2089 dodie "Error opening $warnings_file";
2092 if (/$check_build_re/) {
2093 my $warning = process_warning_line $_;
2095 $warnings_list{$warning} = 1;
2101 # If warnings file didn't exist, and WARNINGS_FILE exist,
2102 # then we fail on any warning!
2104 open(IN, $buildlog) or dodie "Can't open $buildlog";
2106 if (/$check_build_re/) {
2107 my $warning = process_warning_line $_;
2109 if (!defined $warnings_list{$warning}) {
2110 fail "New warning found (not in $warnings_file)\n$_\n";
2111 $no_reboot = $save_no_reboot;
2116 $no_reboot = $save_no_reboot;
2120 sub check_patch_buildlog {
2123 my @files = `git show $patch | diffstat -l`;
2125 foreach my $file (@files) {
2129 open(IN, "git show $patch |") or
2130 dodie "failed to show $patch";
2132 if (m,^--- a/(.*),) {
2134 $files[$#files] = $1;
2139 open(IN, $buildlog) or dodie "Can't open $buildlog";
2141 if (/^\s*(.*?):.*(warning|error)/) {
2143 foreach my $file (@files) {
2144 my $fullpath = "$builddir/$file";
2145 if ($file eq $err || $fullpath eq $err) {
2146 fail "$file built with warnings" and return 0;
2156 sub apply_min_config {
2157 my $outconfig = "$output_config.new";
2159 # Read the config file and remove anything that
2160 # is in the force_config hash (from minconfig and others)
2161 # then add the force config back.
2163 doprint "Applying minimum configurations into $output_config.new\n";
2165 open (OUT, ">$outconfig") or
2166 dodie "Can't create $outconfig";
2168 if (-f $output_config) {
2169 open (IN, $output_config) or
2170 dodie "Failed to open $output_config";
2172 if (/^(# )?(CONFIG_[^\s=]*)/) {
2173 next if (defined($force_config{$2}));
2179 foreach my $config (keys %force_config) {
2180 print OUT "$force_config{$config}\n";
2184 run_command "mv $outconfig $output_config";
2187 sub make_oldconfig {
2189 my @force_list = keys %force_config;
2191 if ($#force_list >= 0) {
2195 if (!run_command "$make olddefconfig") {
2196 # Perhaps olddefconfig doesn't exist in this version of the kernel
2198 doprint "olddefconfig failed, trying make oldnoconfig\n";
2199 if (!run_command "$make oldnoconfig") {
2200 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2201 # try a yes '' | oldconfig
2202 run_command "yes '' | $make oldconfig" or
2203 dodie "failed make config oldconfig";
2208 # read a config file and use this to force new configs.
2209 sub load_force_config {
2212 doprint "Loading force configs from $config\n";
2213 open(IN, $config) or
2214 dodie "failed to read $config";
2217 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2218 $force_config{$1} = $_;
2219 } elsif (/^# (CONFIG_\S*) is not set/) {
2220 $force_config{$1} = $_;
2231 # Failed builds should not reboot the target
2232 my $save_no_reboot = $no_reboot;
2235 # Calculate a new version from here.
2238 if (defined($pre_build)) {
2239 my $ret = run_command $pre_build;
2240 if (!$ret && defined($pre_build_die) &&
2242 dodie "failed to pre_build\n";
2246 if ($type =~ /^useconfig:(.*)/) {
2247 run_command "cp $1 $output_config" or
2248 dodie "could not copy $1 to .config";
2250 $type = "oldconfig";
2253 # old config can ask questions
2254 if ($type eq "oldconfig") {
2255 $type = "olddefconfig";
2257 # allow for empty configs
2258 run_command "touch $output_config";
2261 run_command "mv $output_config $outputdir/config_temp" or
2262 dodie "moving .config";
2264 run_command "$make mrproper" or dodie "make mrproper";
2266 run_command "mv $outputdir/config_temp $output_config" or
2267 dodie "moving config_temp";
2270 } elsif (!$noclean) {
2271 unlink "$output_config";
2272 run_command "$make mrproper" or
2273 dodie "make mrproper";
2276 # add something to distinguish this build
2277 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2278 print OUT "$localversion\n";
2281 if (defined($minconfig)) {
2282 load_force_config($minconfig);
2285 if ($type ne "olddefconfig") {
2286 run_command "$make $type" or
2287 dodie "failed make config";
2289 # Run old config regardless, to enforce min configurations
2292 my $build_ret = run_command "$make $build_options", $buildlog;
2294 if (defined($post_build)) {
2295 # Because a post build may change the kernel version
2298 my $ret = run_command $post_build;
2299 if (!$ret && defined($post_build_die) &&
2301 dodie "failed to post_build\n";
2306 # bisect may need this to pass
2308 $no_reboot = $save_no_reboot;
2311 fail "failed build" and return 0;
2314 $no_reboot = $save_no_reboot;
2320 if (!run_ssh "halt" or defined($power_off)) {
2321 if (defined($poweroff_after_halt)) {
2322 sleep $poweroff_after_halt;
2323 run_command "$power_off";
2327 run_command "$power_off";
2334 if (defined($post_test)) {
2335 run_command $post_test;
2342 if (defined($test_name)) {
2343 $name = " ($test_name)";
2346 doprint "\n\n*******************************************\n";
2347 doprint "*******************************************\n";
2348 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2349 doprint "*******************************************\n";
2350 doprint "*******************************************\n";
2352 if (defined($store_successes)) {
2353 save_logs "success", $store_successes;
2356 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2357 doprint "Reboot and wait $sleep_time seconds\n";
2358 reboot_to_good $sleep_time;
2364 doprint "Pass, fail, or skip? [p/f/s]";
2367 if ($ans eq "p" || $ans eq "P") {
2369 } elsif ($ans eq "f" || $ans eq "F") {
2371 } elsif ($ans eq "s" || $ans eq "S") {
2374 print "Please answer 'p', 'f', or 's'\n";
2379 sub child_run_test {
2382 # child should have no power
2383 $reboot_on_error = 0;
2384 $poweroff_on_error = 0;
2385 $die_on_failure = 1;
2387 run_command $run_test, $testlog or $failed = 1;
2394 sub child_finished {
2404 my $bug_ignored = 0;
2408 doprint "run test $run_test\n";
2412 $SIG{CHLD} = qw(child_finished);
2416 child_run_test if (!$child_pid);
2421 $line = wait_for_input($monitor_fp, 1);
2422 if (defined($line)) {
2424 # we are not guaranteed to get a full line
2425 $full_line .= $line;
2428 if ($full_line =~ /call trace:/i) {
2429 if ($ignore_errors) {
2436 if ($full_line =~ /Kernel panic -/) {
2440 if ($line =~ /\n/) {
2444 } while (!$child_done && !$bug);
2446 if (!$bug && $bug_ignored) {
2447 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2451 my $failure_start = time;
2454 $line = wait_for_input($monitor_fp, 1);
2455 if (defined($line)) {
2459 if ($now - $failure_start >= $stop_after_failure) {
2462 } while (defined($line));
2464 doprint "Detected kernel crash!\n";
2465 # kill the child with extreme prejudice
2469 waitpid $child_pid, 0;
2472 if (!$bug && $in_bisect) {
2473 if (defined($bisect_ret_good)) {
2474 if ($child_exit == $bisect_ret_good) {
2478 if (defined($bisect_ret_skip)) {
2479 if ($child_exit == $bisect_ret_skip) {
2483 if (defined($bisect_ret_abort)) {
2484 if ($child_exit == $bisect_ret_abort) {
2485 fail "test abort" and return -2;
2488 if (defined($bisect_ret_bad)) {
2489 if ($child_exit == $bisect_ret_skip) {
2493 if (defined($bisect_ret_default)) {
2494 if ($bisect_ret_default eq "good") {
2496 } elsif ($bisect_ret_default eq "bad") {
2498 } elsif ($bisect_ret_default eq "skip") {
2500 } elsif ($bisect_ret_default eq "abort") {
2503 fail "unknown default action: $bisect_ret_default"
2509 if ($bug || $child_exit) {
2510 return 0 if $in_bisect;
2511 fail "test failed" and return 0;
2516 sub run_git_bisect {
2519 doprint "$command ... ";
2521 my $output = `$command 2>&1`;
2528 dodie "Failed to git bisect";
2531 doprint "SUCCESS\n";
2532 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2533 doprint "$1 [$2]\n";
2534 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2535 $bisect_bad_commit = $1;
2536 doprint "Found bad commit... $1\n";
2539 # we already logged it, just print it now.
2547 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2548 reboot_to_good $bisect_sleep_time;
2551 # returns 1 on success, 0 on failure, -1 on skip
2552 sub run_bisect_test {
2553 my ($type, $buildtype) = @_;
2562 build $buildtype or $failed = 1;
2564 if ($type ne "build") {
2565 if ($failed && $bisect_skip) {
2569 dodie "Failed on build" if $failed;
2572 start_monitor_and_boot or $failed = 1;
2574 if ($type ne "boot") {
2575 if ($failed && $bisect_skip) {
2581 dodie "Failed on boot" if $failed;
2583 do_run_test or $failed = 1;
2594 # reboot the box to a kernel we can ssh to
2595 if ($type ne "build") {
2605 my $buildtype = "oldconfig";
2607 # We should have a minconfig to use?
2608 if (defined($minconfig)) {
2609 $buildtype = "useconfig:$minconfig";
2612 # If the user sets bisect_tries to less than 1, then no tries
2616 # Still let the user manually decide that though.
2617 if ($bisect_tries < 1 && $bisect_manual) {
2618 $ret = answer_bisect;
2621 for (my $i = 0; $i < $bisect_tries; $i++) {
2622 if ($bisect_tries > 1) {
2624 doprint("Running bisect trial $t of $bisect_tries:\n");
2626 $ret = run_bisect_test $type, $buildtype;
2628 if ($bisect_manual) {
2629 $ret = answer_bisect;
2635 # Are we looking for where it worked, not failed?
2636 if ($reverse_bisect && $ret >= 0) {
2642 } elsif ($ret == 0) {
2644 } elsif ($bisect_skip) {
2645 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2650 sub update_bisect_replay {
2651 my $tmp_log = "$tmpdir/ktest_bisect_log";
2652 run_command "git bisect log > $tmp_log" or
2653 die "can't create bisect log";
2662 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2663 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2664 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2666 my $good = $bisect_good;
2667 my $bad = $bisect_bad;
2668 my $type = $bisect_type;
2669 my $start = $bisect_start;
2670 my $replay = $bisect_replay;
2671 my $start_files = $bisect_files;
2673 if (defined($start_files)) {
2674 $start_files = " -- " . $start_files;
2679 # convert to true sha1's
2680 $good = get_sha1($good);
2681 $bad = get_sha1($bad);
2683 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2684 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2685 $reverse_bisect = 1;
2687 $reverse_bisect = 0;
2690 # Can't have a test without having a test to run
2691 if ($type eq "test" && !defined($run_test)) {
2695 # Check if a bisect was running
2696 my $bisect_start_file = "$builddir/.git/BISECT_START";
2698 my $check = $bisect_check;
2699 my $do_check = defined($check) && $check ne "0";
2701 if ( -f $bisect_start_file ) {
2702 print "Bisect in progress found\n";
2704 print " If you say yes, then no checks of good or bad will be done\n";
2706 if (defined($replay)) {
2707 print "** BISECT_REPLAY is defined in config file **";
2708 print " Ignore config option and perform new git bisect log?\n";
2709 if (read_ync " (yes, no, or cancel) ") {
2710 $replay = update_bisect_replay;
2713 } elsif (read_yn "read git log and continue?") {
2714 $replay = update_bisect_replay;
2722 my $head = get_sha1("HEAD");
2724 if ($check ne "good") {
2725 doprint "TESTING BISECT BAD [$bad]\n";
2726 run_command "git checkout $bad" or
2727 die "Failed to checkout $bad";
2729 $result = run_bisect $type;
2731 if ($result ne "bad") {
2732 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2736 if ($check ne "bad") {
2737 doprint "TESTING BISECT GOOD [$good]\n";
2738 run_command "git checkout $good" or
2739 die "Failed to checkout $good";
2741 $result = run_bisect $type;
2743 if ($result ne "good") {
2744 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2748 # checkout where we started
2749 run_command "git checkout $head" or
2750 die "Failed to checkout $head";
2753 run_command "git bisect start$start_files" or
2754 dodie "could not start bisect";
2756 if (defined($replay)) {
2757 run_command "git bisect replay $replay" or
2758 dodie "failed to run replay";
2761 run_command "git bisect good $good" or
2762 dodie "could not set bisect good to $good";
2764 run_git_bisect "git bisect bad $bad" or
2765 dodie "could not set bisect bad to $bad";
2769 if (defined($start)) {
2770 run_command "git checkout $start" or
2771 dodie "failed to checkout $start";
2776 $result = run_bisect $type;
2777 $test = run_git_bisect "git bisect $result";
2780 run_command "git bisect log" or
2781 dodie "could not capture git bisect log";
2783 run_command "git bisect reset" or
2784 dodie "could not reset git bisect";
2786 doprint "Bad commit was [$bisect_bad_commit]\n";
2791 # config_ignore holds the configs that were set (or unset) for
2792 # a good config and we will ignore these configs for the rest
2793 # of a config bisect. These configs stay as they were.
2796 # config_set holds what all configs were set as.
2799 # config_off holds the set of configs that the bad config had disabled.
2800 # We need to record them and set them in the .config when running
2801 # olddefconfig, because olddefconfig keeps the defaults.
2804 # config_off_tmp holds a set of configs to turn off for now
2807 # config_list is the set of configs that are being tested
2813 sub assign_configs {
2814 my ($hash, $config) = @_;
2816 doprint "Reading configs from $config\n";
2819 or dodie "Failed to read $config";
2823 if (/^((CONFIG\S*)=.*)/) {
2825 } elsif (/^(# (CONFIG\S*) is not set)/) {
2833 sub process_config_ignore {
2836 assign_configs \%config_ignore, $config;
2839 sub get_dependencies {
2842 my $arr = $dependency{$config};
2843 if (!defined($arr)) {
2849 foreach my $dep (@{$arr}) {
2850 print "ADD DEP $dep\n";
2851 @deps = (@deps, get_dependencies $dep);
2858 my ($pc, $file) = @_;
2860 my %configs = %{$pc};
2862 doprint "Saving configs into $file\n";
2864 open(OUT, ">$file") or dodie "Can not write to $file";
2866 foreach my $config (keys %configs) {
2867 print OUT "$configs{$config}\n";
2873 my ($name, $pc) = @_;
2875 doprint "Creating old config from $name configs\n";
2877 save_config $pc, $output_config;
2882 # compare two config hashes, and return configs with different vals.
2883 # It returns B's config values, but you can use A to see what A was.
2884 sub diff_config_vals {
2887 # crappy Perl way to pass in hashes.
2893 foreach my $item (keys %a) {
2894 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2895 $ret{$item} = $b{$item};
2902 # compare two config hashes and return the configs in B but not A
2908 # crappy Perl way to pass in hashes.
2912 foreach my $item (keys %b) {
2913 if (!defined($a{$item})) {
2914 $ret{$item} = $b{$item};
2921 # return if two configs are equal or not
2922 # 0 is equal +1 b has something a does not
2923 # +1 if a and b have a different item.
2924 # -1 if a has something b does not
2925 sub compare_configs {
2930 # crappy Perl way to pass in hashes.
2934 foreach my $item (keys %b) {
2935 if (!defined($a{$item})) {
2938 if ($a{$item} ne $b{$item}) {
2943 foreach my $item (keys %a) {
2944 if (!defined($b{$item})) {
2952 sub run_config_bisect_test {
2955 my $ret = run_bisect_test $type, "oldconfig";
2957 if ($bisect_manual) {
2958 $ret = answer_bisect;
2964 sub process_failed {
2967 doprint "\n\n***************************************\n";
2968 doprint "Found bad config: $config\n";
2969 doprint "***************************************\n\n";
2972 # used for config bisecting
2976 sub process_new_config {
2977 my ($tc, $nc, $gc, $bc) = @_;
2979 my %tmp_config = %{$tc};
2980 my %good_configs = %{$gc};
2981 my %bad_configs = %{$bc};
2988 create_config "tmp_configs", \%tmp_config;
2989 assign_configs \%new_configs, $output_config;
2991 $ret = compare_configs \%new_configs, \%bad_configs;
2993 doprint "New config equals bad config, try next test\n";
2998 $ret = compare_configs \%new_configs, \%good_configs;
3000 doprint "New config equals good config, try next test\n";
3005 %{$nc} = %new_configs;
3010 sub run_config_bisect {
3011 my ($pgood, $pbad) = @_;
3013 my $type = $config_bisect_type;
3015 my %good_configs = %{$pgood};
3016 my %bad_configs = %{$pbad};
3018 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
3019 my %b_configs = diff_configs \%good_configs, \%bad_configs;
3020 my %g_configs = diff_configs \%bad_configs, \%good_configs;
3022 my @diff_arr = keys %diff_configs;
3023 my $len_diff = $#diff_arr + 1;
3025 my @b_arr = keys %b_configs;
3026 my $len_b = $#b_arr + 1;
3028 my @g_arr = keys %g_configs;
3029 my $len_g = $#g_arr + 1;
3035 # First, lets get it down to a single subset.
3036 # Is the problem with a difference in values?
3037 # Is the problem with a missing config?
3038 # Is the problem with a config that breaks things?
3040 # Enable all of one set and see if we get a new bad
3043 # first set the good config to the bad values.
3045 doprint "d=$len_diff g=$len_g b=$len_b\n";
3047 # first lets enable things in bad config that are enabled in good config
3049 if ($len_diff > 0) {
3050 if ($len_b > 0 || $len_g > 0) {
3051 my %tmp_config = %bad_configs;
3053 doprint "Set tmp config to be bad config with good config values\n";
3054 foreach my $item (@diff_arr) {
3055 $tmp_config{$item} = $good_configs{$item};
3058 $runtest = process_new_config \%tmp_config, \%new_configs,
3059 \%good_configs, \%bad_configs;
3063 if (!$runtest && $len_diff > 0) {
3065 if ($len_diff == 1) {
3066 process_failed $diff_arr[0];
3069 my %tmp_config = %bad_configs;
3071 my $half = int($#diff_arr / 2);
3072 my @tophalf = @diff_arr[0 .. $half];
3074 doprint "Settings bisect with top half:\n";
3075 doprint "Set tmp config to be bad config with some good config values\n";
3076 foreach my $item (@tophalf) {
3077 $tmp_config{$item} = $good_configs{$item};
3080 $runtest = process_new_config \%tmp_config, \%new_configs,
3081 \%good_configs, \%bad_configs;
3084 my %tmp_config = %bad_configs;
3086 doprint "Try bottom half\n";
3088 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3090 foreach my $item (@bottomhalf) {
3091 $tmp_config{$item} = $good_configs{$item};
3094 $runtest = process_new_config \%tmp_config, \%new_configs,
3095 \%good_configs, \%bad_configs;
3100 $ret = run_config_bisect_test $type;
3102 doprint "NEW GOOD CONFIG\n";
3103 %good_configs = %new_configs;
3104 run_command "mv $good_config ${good_config}.last";
3105 save_config \%good_configs, $good_config;
3106 %{$pgood} = %good_configs;
3108 doprint "NEW BAD CONFIG\n";
3109 %bad_configs = %new_configs;
3110 run_command "mv $bad_config ${bad_config}.last";
3111 save_config \%bad_configs, $bad_config;
3112 %{$pbad} = %bad_configs;
3117 fail "Hmm, need to do a mix match?\n";
3124 my $type = $config_bisect_type;
3127 $bad_config = $config_bisect;
3129 if (defined($config_bisect_good)) {
3130 $good_config = $config_bisect_good;
3131 } elsif (defined($minconfig)) {
3132 $good_config = $minconfig;
3134 doprint "No config specified, checking if defconfig works";
3135 $ret = run_bisect_test $type, "defconfig";
3137 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3140 $good_config = $output_config;
3143 # we don't want min configs to cause issues here.
3144 doprint "Disabling 'MIN_CONFIG' for this test\n";
3151 doprint "Run good configs through make oldconfig\n";
3152 assign_configs \%tmp_configs, $good_config;
3153 create_config "$good_config", \%tmp_configs;
3154 assign_configs \%good_configs, $output_config;
3156 doprint "Run bad configs through make oldconfig\n";
3157 assign_configs \%tmp_configs, $bad_config;
3158 create_config "$bad_config", \%tmp_configs;
3159 assign_configs \%bad_configs, $output_config;
3161 $good_config = "$tmpdir/good_config";
3162 $bad_config = "$tmpdir/bad_config";
3164 save_config \%good_configs, $good_config;
3165 save_config \%bad_configs, $bad_config;
3168 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3169 if ($config_bisect_check ne "good") {
3170 doprint "Testing bad config\n";
3172 $ret = run_bisect_test $type, "useconfig:$bad_config";
3174 fail "Bad config succeeded when expected to fail!";
3178 if ($config_bisect_check ne "bad") {
3179 doprint "Testing good config\n";
3181 $ret = run_bisect_test $type, "useconfig:$good_config";
3183 fail "Good config failed when expected to succeed!";
3190 $ret = run_config_bisect \%good_configs, \%bad_configs;
3193 return $ret if ($ret < 0);
3198 sub patchcheck_reboot {
3199 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3200 reboot_to_good $patchcheck_sleep_time;
3206 die "PATCHCHECK_START[$i] not defined\n"
3207 if (!defined($patchcheck_start));
3208 die "PATCHCHECK_TYPE[$i] not defined\n"
3209 if (!defined($patchcheck_type));
3211 my $start = $patchcheck_start;
3213 my $cherry = $patchcheck_cherry;
3214 if (!defined($cherry)) {
3219 if (defined($patchcheck_end)) {
3220 $end = $patchcheck_end;
3222 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
3225 # Get the true sha1's since we can use things like HEAD~3
3226 $start = get_sha1($start);
3227 $end = get_sha1($end);
3229 my $type = $patchcheck_type;
3231 # Can't have a test without having a test to run
3232 if ($type eq "test" && !defined($run_test)) {
3237 open (IN, "git cherry -v $start $end|") or
3238 dodie "could not get git list";
3240 open (IN, "git log --pretty=oneline $end|") or
3241 dodie "could not get git list";
3248 # git cherry adds a '+' we want to remove
3250 $list[$#list+1] = $_;
3251 last if (/^$start/);
3256 if ($list[$#list] !~ /^$start/) {
3257 fail "SHA1 $start not found";
3260 # go backwards in the list
3261 @list = reverse @list;
3264 doprint("Going to test the following commits:\n");
3265 foreach my $l (@list) {
3269 my $save_clean = $noclean;
3270 my %ignored_warnings;
3272 if (defined($ignore_warnings)) {
3273 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3274 $ignored_warnings{$sha1} = 1;
3279 foreach my $item (@list) {
3281 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3283 doprint "\nProcessing commit $item\n\n";
3285 run_command "git checkout $sha1" or
3286 die "Failed to checkout $sha1";
3288 # only clean on the first and last patch
3289 if ($item eq $list[0] ||
3290 $item eq $list[$#list]) {
3291 $noclean = $save_clean;
3296 if (defined($minconfig)) {
3297 build "useconfig:$minconfig" or return 0;
3299 # ?? no config to use?
3300 build "oldconfig" or return 0;
3303 # No need to do per patch checking if warnings file exists
3304 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3305 check_patch_buildlog $sha1 or return 0;
3308 check_buildlog or return 0;
3310 next if ($type eq "build");
3314 start_monitor_and_boot or $failed = 1;
3316 if (!$failed && $type ne "boot"){
3317 do_run_test or $failed = 1;
3320 return 0 if ($failed);
3340 # $config depends on $dep
3341 my ($config, $dep) = @_;
3343 if (defined($depends{$config})) {
3344 $depends{$config} .= " " . $dep;
3346 $depends{$config} = $dep;
3349 # record the number of configs depending on $dep
3350 if (defined $depcount{$dep}) {
3353 $depcount{$dep} = 1;
3357 # taken from streamline_config.pl
3369 if (! -f $kconfig) {
3370 doprint "file $kconfig does not exist, skipping\n";
3374 open(KIN, "$kconfig")
3375 or die "Can't open $kconfig";
3379 # Make sure that lines ending with \ continue
3381 $_ = $line . " " . $_;
3392 # collect any Kconfig sources
3393 if (/^source\s*"(.*)"/) {
3394 $kconfigs[$#kconfigs+1] = $1;
3398 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3402 for (my $i = 0; $i < $iflevel; $i++) {
3403 add_dep $config, $ifdeps[$i];
3406 # collect the depends for the config
3407 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3409 add_dep $config, $1;
3411 # Get the configs that select this config
3412 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3414 # selected by depends on config
3415 add_dep $1, $config;
3417 # Check for if statements
3418 } elsif (/^if\s+(.*\S)\s*$/) {
3420 # remove beginning and ending non text
3421 $deps =~ s/^[^a-zA-Z0-9_]*//;
3422 $deps =~ s/[^a-zA-Z0-9_]*$//;
3424 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3426 $ifdeps[$iflevel++] = join ':', @deps;
3428 } elsif (/^endif/) {
3430 $iflevel-- if ($iflevel);
3433 } elsif (/^\s*help\s*$/) {
3439 # read in any configs that were found.
3440 foreach $kconfig (@kconfigs) {
3441 if (!defined($read_kconfigs{$kconfig})) {
3442 $read_kconfigs{$kconfig} = 1;
3443 read_kconfig("$builddir/$kconfig");
3449 # find out which arch this is by the kconfig file
3450 open (IN, $output_config)
3451 or dodie "Failed to read $output_config";
3454 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3461 if (!defined($arch)) {
3462 doprint "Could not find arch from config file\n";
3463 doprint "no dependencies used\n";
3467 # arch is really the subarch, we need to know
3468 # what directory to look at.
3469 if ($arch eq "i386" || $arch eq "x86_64") {
3471 } elsif ($arch =~ /^tile/) {
3475 my $kconfig = "$builddir/arch/$arch/Kconfig";
3477 if (! -f $kconfig && $arch =~ /\d$/) {
3479 # some subarchs have numbers, truncate them
3481 $kconfig = "$builddir/arch/$arch/Kconfig";
3482 if (! -f $kconfig) {
3483 doprint "No idea what arch dir $orig is for\n";
3484 doprint "no dependencies used\n";
3489 read_kconfig($kconfig);
3492 sub make_new_config {
3495 open (OUT, ">$output_config")
3496 or dodie "Failed to write $output_config";
3498 foreach my $config (@configs) {
3499 print OUT "$config\n";
3507 $config =~ s/CONFIG_//;
3515 my $kconfig = chomp_config $dep;
3517 $dep = $depends{"$kconfig"};
3519 # the dep string we have saves the dependencies as they
3520 # were found, including expressions like ! && ||. We
3521 # want to split this out into just an array of configs.
3523 my $valid = "A-Za-z_0-9";
3527 while ($dep =~ /[$valid]/) {
3529 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3530 my $conf = "CONFIG_" . $1;
3532 $configs[$#configs + 1] = $conf;
3534 $dep =~ s/^[^$valid]*[$valid]+//;
3536 die "this should never happen";
3546 my %processed_configs;
3547 my %nochange_config;
3549 sub test_this_config {
3554 # if we already processed this config, skip it
3555 if (defined($processed_configs{$config})) {
3558 $processed_configs{$config} = 1;
3560 # if this config failed during this round, skip it
3561 if (defined($nochange_config{$config})) {
3565 my $kconfig = chomp_config $config;
3567 # Test dependencies first
3568 if (defined($depends{"$kconfig"})) {
3569 my @parents = get_depends $config;
3570 foreach my $parent (@parents) {
3571 # if the parent is in the min config, check it first
3572 next if (!defined($min_configs{$parent}));
3573 $found = test_this_config($parent);
3574 if (defined($found)) {
3580 # Remove this config from the list of configs
3581 # do a make olddefconfig and then read the resulting
3582 # .config to make sure it is missing the config that
3584 my %configs = %min_configs;
3585 delete $configs{$config};
3586 make_new_config ((values %configs), (values %keep_configs));
3589 assign_configs \%configs, $output_config;
3591 if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
3595 doprint "disabling config $config did not change .config\n";
3597 $nochange_config{$config} = 1;
3602 sub make_min_config {
3605 my $type = $minconfig_type;
3606 if ($type ne "boot" && $type ne "test") {
3607 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3608 " make_min_config works only with 'boot' and 'test'\n" and return;
3611 if (!defined($output_minconfig)) {
3612 fail "OUTPUT_MIN_CONFIG not defined" and return;
3615 # If output_minconfig exists, and the start_minconfig
3616 # came from min_config, than ask if we should use
3618 if (-f $output_minconfig && !$start_minconfig_defined) {
3619 print "$output_minconfig exists\n";
3620 if (!defined($use_output_minconfig)) {
3621 if (read_yn " Use it as minconfig?") {
3622 $start_minconfig = $output_minconfig;
3624 } elsif ($use_output_minconfig > 0) {
3625 doprint "Using $output_minconfig as MIN_CONFIG\n";
3626 $start_minconfig = $output_minconfig;
3628 doprint "Set to still use MIN_CONFIG as starting point\n";
3632 if (!defined($start_minconfig)) {
3633 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3636 my $temp_config = "$tmpdir/temp_config";
3638 # First things first. We build an allnoconfig to find
3639 # out what the defaults are that we can't touch.
3640 # Some are selections, but we really can't handle selections.
3642 my $save_minconfig = $minconfig;
3645 run_command "$make allnoconfig" or return 0;
3649 process_config_ignore $output_config;
3651 undef %save_configs;
3654 if (defined($ignore_config)) {
3655 # make sure the file exists
3656 `touch $ignore_config`;
3657 assign_configs \%save_configs, $ignore_config;
3660 %keep_configs = %save_configs;
3662 doprint "Load initial configs from $start_minconfig\n";
3664 # Look at the current min configs, and save off all the
3665 # ones that were set via the allnoconfig
3666 assign_configs \%min_configs, $start_minconfig;
3668 my @config_keys = keys %min_configs;
3670 # All configs need a depcount
3671 foreach my $config (@config_keys) {
3672 my $kconfig = chomp_config $config;
3673 if (!defined $depcount{$kconfig}) {
3674 $depcount{$kconfig} = 0;
3678 # Remove anything that was set by the make allnoconfig
3679 # we shouldn't need them as they get set for us anyway.
3680 foreach my $config (@config_keys) {
3681 # Remove anything in the ignore_config
3682 if (defined($keep_configs{$config})) {
3683 my $file = $ignore_config;
3684 $file =~ s,.*/(.*?)$,$1,;
3685 doprint "$config set by $file ... ignored\n";
3686 delete $min_configs{$config};
3689 # But make sure the settings are the same. If a min config
3690 # sets a selection, we do not want to get rid of it if
3691 # it is not the same as what we have. Just move it into
3693 if (defined($config_ignore{$config})) {
3694 if ($config_ignore{$config} ne $min_configs{$config}) {
3695 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3696 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3697 $keep_configs{$config} = $min_configs{$config};
3699 doprint "$config set by allnoconfig ... ignored\n";
3701 delete $min_configs{$config};
3713 # Now disable each config one by one and do a make oldconfig
3714 # till we find a config that changes our list.
3716 my @test_configs = keys %min_configs;
3718 # Sort keys by who is most dependent on
3719 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3722 # Put configs that did not modify the config at the end.
3724 for (my $i = 0; $i < $#test_configs; $i++) {
3725 if (!defined($nochange_config{$test_configs[0]})) {
3729 # This config didn't change the .config last time.
3730 # Place it at the end
3731 my $config = shift @test_configs;
3732 push @test_configs, $config;
3735 # if every test config has failed to modify the .config file
3736 # in the past, then reset and start over.
3738 undef %nochange_config;
3741 undef %processed_configs;
3743 foreach my $config (@test_configs) {
3745 $found = test_this_config $config;
3747 last if (defined($found));
3749 # oh well, try another config
3752 if (!defined($found)) {
3753 # we could have failed due to the nochange_config hash
3754 # reset and try again
3756 undef %nochange_config;
3760 doprint "No more configs found that we can disable\n";
3768 doprint "Test with $config disabled\n";
3770 # set in_bisect to keep build and monitor from dieing
3774 build "oldconfig" or $failed = 1;
3776 start_monitor_and_boot or $failed = 1;
3778 if ($type eq "test" && !$failed) {
3779 do_run_test or $failed = 1;
3788 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3789 # this config is needed, add it to the ignore list.
3790 $keep_configs{$config} = $min_configs{$config};
3791 $save_configs{$config} = $min_configs{$config};
3792 delete $min_configs{$config};
3794 # update new ignore configs
3795 if (defined($ignore_config)) {
3796 open (OUT, ">$temp_config")
3797 or die "Can't write to $temp_config";
3798 foreach my $config (keys %save_configs) {
3799 print OUT "$save_configs{$config}\n";
3802 run_command "mv $temp_config $ignore_config" or
3803 dodie "failed to copy update to $ignore_config";
3807 # We booted without this config, remove it from the minconfigs.
3808 doprint "$config is not needed, disabling\n";
3810 delete $min_configs{$config};
3812 # Also disable anything that is not enabled in this config
3814 assign_configs \%configs, $output_config;
3815 my @config_keys = keys %min_configs;
3816 foreach my $config (@config_keys) {
3817 if (!defined($configs{$config})) {
3818 doprint "$config is not set, disabling\n";
3819 delete $min_configs{$config};
3823 # Save off all the current mandidory configs
3824 open (OUT, ">$temp_config")
3825 or die "Can't write to $temp_config";
3826 foreach my $config (keys %keep_configs) {
3827 print OUT "$keep_configs{$config}\n";
3829 foreach my $config (keys %min_configs) {
3830 print OUT "$min_configs{$config}\n";
3834 run_command "mv $temp_config $output_minconfig" or
3835 dodie "failed to copy update to $output_minconfig";
3838 doprint "Reboot and wait $sleep_time seconds\n";
3839 reboot_to_good $sleep_time;
3846 sub make_warnings_file {
3849 if (!defined($warnings_file)) {
3850 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3853 if ($build_type eq "nobuild") {
3854 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3857 build $build_type or dodie "Failed to build";
3859 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3861 open(IN, $buildlog) or dodie "Can't open $buildlog";
3864 # Some compilers use UTF-8 extended for quotes
3865 # for distcc heterogeneous systems, this causes issues
3868 if (/$check_build_re/) {
3879 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
3882 $ktest_config = $ARGV[0];
3883 if (! -f $ktest_config) {
3884 print "$ktest_config does not exist.\n";
3885 if (!read_yn "Create it?") {
3891 if (! -f $ktest_config) {
3894 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3896 # Generated by ktest.pl
3899 # PWD is a ktest.pl variable that will result in the process working
3900 # directory that ktest.pl is executed in.
3902 # THIS_DIR is automatically assigned the PWD of the path that generated
3903 # the config file. It is best to use this variable when assigning other
3904 # directory paths within this directory. This allows you to easily
3905 # move the test cases to other locations or to other machines.
3907 THIS_DIR := $variable{"PWD"}
3909 # Define each test with TEST_START
3910 # The config options below it will override the defaults
3912 TEST_TYPE = $default{"TEST_TYPE"}
3919 read_config $ktest_config;
3921 if (defined($opt{"LOG_FILE"})) {
3922 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
3925 # Append any configs entered in manually to the config file.
3926 my @new_configs = keys %entered_configs;
3927 if ($#new_configs >= 0) {
3928 print "\nAppending entered in configs to $ktest_config\n";
3929 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3930 foreach my $config (@new_configs) {
3931 print OUT "$config = $entered_configs{$config}\n";
3932 $opt{$config} = process_variables($entered_configs{$config});
3936 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3937 unlink $opt{"LOG_FILE"};
3940 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3942 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3945 doprint "DEFAULT OPTIONS:\n";
3947 doprint "\nTEST $i OPTIONS";
3948 if (defined($repeat_tests{$i})) {
3949 $repeat = $repeat_tests{$i};
3950 doprint " ITERATE $repeat";
3955 foreach my $option (sort keys %opt) {
3957 if ($option =~ /\[(\d+)\]$/) {
3963 doprint "$option = $opt{$option}\n";
3967 sub option_defined {
3970 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
3977 sub __set_test_option {
3978 my ($name, $i) = @_;
3980 my $option = "$name\[$i\]";
3982 if (option_defined($option)) {
3983 return $opt{$option};
3986 foreach my $test (keys %repeat_tests) {
3988 $i < $test + $repeat_tests{$test}) {
3989 $option = "$name\[$test\]";
3990 if (option_defined($option)) {
3991 return $opt{$option};
3996 if (option_defined($name)) {
4003 sub set_test_option {
4004 my ($name, $i) = @_;
4006 my $option = __set_test_option($name, $i);
4007 return $option if (!defined($option));
4009 return eval_option($name, $option, $i);
4012 # First we need to do is the builds
4013 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
4015 # Do not reboot on failing test options
4017 $reboot_success = 0;
4023 undef %force_config;
4025 my $makecmd = set_test_option("MAKE_CMD", $i);
4027 $outputdir = set_test_option("OUTPUT_DIR", $i);
4028 $builddir = set_test_option("BUILD_DIR", $i);
4030 chdir $builddir || die "can't change directory to $builddir";
4032 if (!-d $outputdir) {
4033 mkpath($outputdir) or
4034 die "can't create $outputdir";
4037 $make = "$makecmd O=$outputdir";
4039 # Load all the options into their mapped variable names
4040 foreach my $opt (keys %option_map) {
4041 ${$option_map{$opt}} = set_test_option($opt, $i);
4044 $start_minconfig_defined = 1;
4046 # The first test may override the PRE_KTEST option
4047 if (defined($pre_ktest) && $i == 1) {
4049 run_command $pre_ktest;
4052 # Any test can override the POST_KTEST option
4053 # The last test takes precedence.
4054 if (defined($post_ktest)) {
4055 $final_post_ktest = $post_ktest;
4058 if (!defined($start_minconfig)) {
4059 $start_minconfig_defined = 0;
4060 $start_minconfig = $minconfig;
4065 die "can't create $tmpdir";
4068 $ENV{"SSH_USER"} = $ssh_user;
4069 $ENV{"MACHINE"} = $machine;
4071 $buildlog = "$tmpdir/buildlog-$machine";
4072 $testlog = "$tmpdir/testlog-$machine";
4073 $dmesg = "$tmpdir/dmesg-$machine";
4074 $output_config = "$outputdir/.config";
4077 $target = "$ssh_user\@$machine";
4078 if ($reboot_type eq "grub") {
4079 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4080 } elsif ($reboot_type eq "grub2") {
4081 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4082 dodie "GRUB_FILE not defined" if (!defined($grub_file));
4083 } elsif ($reboot_type eq "syslinux") {
4084 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
4088 my $run_type = $build_type;
4089 if ($test_type eq "patchcheck") {
4090 $run_type = $patchcheck_type;
4091 } elsif ($test_type eq "bisect") {
4092 $run_type = $bisect_type;
4093 } elsif ($test_type eq "config_bisect") {
4094 $run_type = $config_bisect_type;
4095 } elsif ($test_type eq "make_min_config") {
4097 } elsif ($test_type eq "make_warnings_file") {
4101 # mistake in config file?
4102 if (!defined($run_type)) {
4103 $run_type = "ERROR";
4107 $installme = " no_install" if ($no_install);
4111 if (defined($test_name)) {
4112 $name = " ($test_name)";
4116 doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
4118 if (defined($pre_test)) {
4119 run_command $pre_test;
4126 if (defined($addconfig)) {
4127 my $min = $minconfig;
4128 if (!defined($minconfig)) {
4131 run_command "cat $addconfig $min > $tmpdir/add_config" or
4132 dodie "Failed to create temp config";
4133 $minconfig = "$tmpdir/add_config";
4136 if (defined($checkout)) {
4137 run_command "git checkout $checkout" or
4138 die "failed to checkout $checkout";
4143 # A test may opt to not reboot the box
4144 if ($reboot_on_success) {
4145 $reboot_success = 1;
4148 if ($test_type eq "bisect") {
4151 } elsif ($test_type eq "config_bisect") {
4154 } elsif ($test_type eq "patchcheck") {
4157 } elsif ($test_type eq "make_min_config") {
4160 } elsif ($test_type eq "make_warnings_file") {
4162 make_warnings_file $i;
4166 if ($build_type ne "nobuild") {
4167 build $build_type or next;
4168 check_buildlog or next;
4171 if ($test_type eq "install") {
4178 if ($test_type ne "build") {
4180 start_monitor_and_boot or $failed = 1;
4182 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4183 do_run_test or $failed = 1;
4192 if (defined($final_post_ktest)) {
4193 run_command $final_post_ktest;
4196 if ($opt{"POWEROFF_ON_SUCCESS"}) {
4198 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4200 } elsif (defined($switch_to_good)) {
4201 # still need to get to the good kernel
4202 run_command $switch_to_good;
4206 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";