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
44 "MIN_CONFIG_TYPE" => "boot",
45 "SUCCESS_LINE" => "login:",
46 "DETECT_TRIPLE_FAULT" => 1,
48 "BOOTED_TIMEOUT" => 1,
49 "DIE_ON_FAILURE" => 1,
50 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
51 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
52 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
53 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
54 "STOP_AFTER_SUCCESS" => 10,
55 "STOP_AFTER_FAILURE" => 60,
56 "STOP_TEST_AFTER" => 600,
57 "MAX_MONITOR_WAIT" => 1800,
58 "GRUB_REBOOT" => "grub2-reboot",
59 "SYSLINUX" => "extlinux",
60 "SYSLINUX_PATH" => "/boot/extlinux",
62 # required, and we will ask users if they don't have them but we keep the default
63 # value something that is common.
64 "REBOOT_TYPE" => "grub",
65 "LOCALVERSION" => "-test",
67 "BUILD_TARGET" => "arch/x86/boot/bzImage",
68 "TARGET_IMAGE" => "/boot/vmlinuz-test",
103 my $poweroff_on_error;
104 my $reboot_on_success;
106 my $powercycle_after_reboot;
107 my $poweroff_after_halt;
108 my $max_monitor_wait;
111 my $scp_to_target_install;
129 my $start_minconfig_defined;
130 my $output_minconfig;
132 my $use_output_minconfig;
138 my $bisect_bad_commit = "";
142 my $config_bisect_good;
146 my $bisect_ret_abort;
147 my $bisect_ret_default;
148 my $in_patchcheck = 0;
158 my $bisect_sleep_time;
159 my $patchcheck_sleep_time;
166 my $detect_triplefault;
168 my $close_console_signal;
169 my $reboot_success_line;
171 my $stop_after_success;
172 my $stop_after_failure;
191 my $config_bisect_type;
192 my $config_bisect_check;
195 my $patchcheck_start;
198 # set when a test is something other that just building or install
199 # which would require more options.
202 # tell build not to worry about warnings, even when WARNINGS_FILE is set
205 # set when creating a new config
212 # force_config is the list of configs that we force enabled (or disabled)
213 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
216 # do not force reboots on config problems
220 my $reboot_success = 0;
223 "MACHINE" => \$machine,
224 "SSH_USER" => \$ssh_user,
225 "TMP_DIR" => \$tmpdir,
226 "OUTPUT_DIR" => \$outputdir,
227 "BUILD_DIR" => \$builddir,
228 "TEST_TYPE" => \$test_type,
229 "PRE_KTEST" => \$pre_ktest,
230 "POST_KTEST" => \$post_ktest,
231 "PRE_TEST" => \$pre_test,
232 "POST_TEST" => \$post_test,
233 "BUILD_TYPE" => \$build_type,
234 "BUILD_OPTIONS" => \$build_options,
235 "PRE_BUILD" => \$pre_build,
236 "POST_BUILD" => \$post_build,
237 "PRE_BUILD_DIE" => \$pre_build_die,
238 "POST_BUILD_DIE" => \$post_build_die,
239 "POWER_CYCLE" => \$power_cycle,
240 "REBOOT" => \$reboot,
241 "BUILD_NOCLEAN" => \$noclean,
242 "MIN_CONFIG" => \$minconfig,
243 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
244 "START_MIN_CONFIG" => \$start_minconfig,
245 "MIN_CONFIG_TYPE" => \$minconfig_type,
246 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
247 "WARNINGS_FILE" => \$warnings_file,
248 "IGNORE_CONFIG" => \$ignore_config,
249 "TEST" => \$run_test,
250 "ADD_CONFIG" => \$addconfig,
251 "REBOOT_TYPE" => \$reboot_type,
252 "GRUB_MENU" => \$grub_menu,
253 "GRUB_FILE" => \$grub_file,
254 "GRUB_REBOOT" => \$grub_reboot,
255 "SYSLINUX" => \$syslinux,
256 "SYSLINUX_PATH" => \$syslinux_path,
257 "SYSLINUX_LABEL" => \$syslinux_label,
258 "PRE_INSTALL" => \$pre_install,
259 "POST_INSTALL" => \$post_install,
260 "NO_INSTALL" => \$no_install,
261 "REBOOT_SCRIPT" => \$reboot_script,
262 "REBOOT_ON_ERROR" => \$reboot_on_error,
263 "SWITCH_TO_GOOD" => \$switch_to_good,
264 "SWITCH_TO_TEST" => \$switch_to_test,
265 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
266 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
267 "DIE_ON_FAILURE" => \$die_on_failure,
268 "POWER_OFF" => \$power_off,
269 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
270 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
271 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
272 "SLEEP_TIME" => \$sleep_time,
273 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
274 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
275 "IGNORE_WARNINGS" => \$ignore_warnings,
276 "IGNORE_ERRORS" => \$ignore_errors,
277 "BISECT_MANUAL" => \$bisect_manual,
278 "BISECT_SKIP" => \$bisect_skip,
279 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
280 "BISECT_RET_GOOD" => \$bisect_ret_good,
281 "BISECT_RET_BAD" => \$bisect_ret_bad,
282 "BISECT_RET_SKIP" => \$bisect_ret_skip,
283 "BISECT_RET_ABORT" => \$bisect_ret_abort,
284 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
285 "STORE_FAILURES" => \$store_failures,
286 "STORE_SUCCESSES" => \$store_successes,
287 "TEST_NAME" => \$test_name,
288 "TIMEOUT" => \$timeout,
289 "BOOTED_TIMEOUT" => \$booted_timeout,
290 "CONSOLE" => \$console,
291 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
292 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
293 "SUCCESS_LINE" => \$success_line,
294 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
295 "STOP_AFTER_SUCCESS" => \$stop_after_success,
296 "STOP_AFTER_FAILURE" => \$stop_after_failure,
297 "STOP_TEST_AFTER" => \$stop_test_after,
298 "BUILD_TARGET" => \$build_target,
299 "SSH_EXEC" => \$ssh_exec,
300 "SCP_TO_TARGET" => \$scp_to_target,
301 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
302 "CHECKOUT" => \$checkout,
303 "TARGET_IMAGE" => \$target_image,
304 "LOCALVERSION" => \$localversion,
306 "BISECT_GOOD" => \$bisect_good,
307 "BISECT_BAD" => \$bisect_bad,
308 "BISECT_TYPE" => \$bisect_type,
309 "BISECT_START" => \$bisect_start,
310 "BISECT_REPLAY" => \$bisect_replay,
311 "BISECT_FILES" => \$bisect_files,
312 "BISECT_REVERSE" => \$bisect_reverse,
313 "BISECT_CHECK" => \$bisect_check,
315 "CONFIG_BISECT" => \$config_bisect,
316 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
317 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
319 "PATCHCHECK_TYPE" => \$patchcheck_type,
320 "PATCHCHECK_START" => \$patchcheck_start,
321 "PATCHCHECK_END" => \$patchcheck_end,
324 # Options may be used by other options, record them.
327 # default variables that can be used
328 chomp ($variable{"PWD"} = `pwd`);
330 $config_help{"MACHINE"} = << "EOF"
331 The machine hostname that you will test.
332 For build only tests, it is still needed to differentiate log files.
335 $config_help{"SSH_USER"} = << "EOF"
336 The box is expected to have ssh on normal bootup, provide the user
337 (most likely root, since you need privileged operations)
340 $config_help{"BUILD_DIR"} = << "EOF"
341 The directory that contains the Linux source code (full path).
342 You can use \${PWD} that will be the path where ktest.pl is run, or use
343 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
346 $config_help{"OUTPUT_DIR"} = << "EOF"
347 The directory that the objects will be built (full path).
348 (can not be same as BUILD_DIR)
349 You can use \${PWD} that will be the path where ktest.pl is run, or use
350 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
353 $config_help{"BUILD_TARGET"} = << "EOF"
354 The location of the compiled file to copy to the target.
355 (relative to OUTPUT_DIR)
358 $config_help{"BUILD_OPTIONS"} = << "EOF"
359 Options to add to \"make\" when building.
363 $config_help{"TARGET_IMAGE"} = << "EOF"
364 The place to put your image on the test machine.
367 $config_help{"POWER_CYCLE"} = << "EOF"
368 A script or command to reboot the box.
370 Here is a digital loggers power switch example
371 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
373 Here is an example to reboot a virtual box on the current host
374 with the name "Guest".
375 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
378 $config_help{"CONSOLE"} = << "EOF"
379 The script or command that reads the console
381 If you use ttywatch server, something like the following would work.
382 CONSOLE = nc -d localhost 3001
384 For a virtual machine with guest name "Guest".
385 CONSOLE = virsh console Guest
388 $config_help{"LOCALVERSION"} = << "EOF"
389 Required version ending to differentiate the test
390 from other linux builds on the system.
393 $config_help{"REBOOT_TYPE"} = << "EOF"
394 Way to reboot the box to the test kernel.
395 Only valid options so far are "grub", "grub2", "syslinux", and "script".
397 If you specify grub, it will assume grub version 1
398 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
399 and select that target to reboot to the kernel. If this is not
400 your setup, then specify "script" and have a command or script
401 specified in REBOOT_SCRIPT to boot to the target.
403 The entry in /boot/grub/menu.lst must be entered in manually.
404 The test will not modify that file.
406 If you specify grub2, then you also need to specify both \$GRUB_MENU
409 If you specify syslinux, then you may use SYSLINUX to define the syslinux
410 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
411 the syslinux install (defaults to /boot/extlinux). But you have to specify
412 SYSLINUX_LABEL to define the label to boot to for the test kernel.
415 $config_help{"GRUB_MENU"} = << "EOF"
416 The grub title name for the test kernel to boot
417 (Only mandatory if REBOOT_TYPE = grub or grub2)
419 Note, ktest.pl will not update the grub menu.lst, you need to
420 manually add an option for the test. ktest.pl will search
421 the grub menu.lst for this option to find what kernel to
424 For example, if in the /boot/grub/menu.lst the test kernel title has:
427 GRUB_MENU = Test Kernel
429 For grub2, a search of \$GRUB_FILE is performed for the lines
430 that begin with "menuentry". It will not detect submenus. The
431 menu must be a non-nested menu. Add the quotes used in the menu
432 to guarantee your selection, as the first menuentry with the content
433 of \$GRUB_MENU that is found will be used.
436 $config_help{"GRUB_FILE"} = << "EOF"
437 If grub2 is used, the full path for the grub.cfg file is placed
438 here. Use something like /boot/grub2/grub.cfg to search.
441 $config_help{"SYSLINUX_LABEL"} = << "EOF"
442 If syslinux is used, the label that boots the target kernel must
443 be specified with SYSLINUX_LABEL.
446 $config_help{"REBOOT_SCRIPT"} = << "EOF"
447 A script to reboot the target into the test kernel
448 (Only mandatory if REBOOT_TYPE = script)
453 if (defined($opt{"LOG_FILE"})) {
454 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
461 if (defined($opt{"LOG_FILE"})) {
474 my ($cancel, $prompt) = @_;
480 print "$prompt [y/n/C] ";
482 print "$prompt [Y/n] ";
486 if ($ans =~ /^\s*$/) {
493 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
495 last if ($ans =~ /^c$/i);
496 print "Please answer either 'y', 'n' or 'c'.\n";
498 print "Please answer either 'y' or 'n'.\n";
504 if ($ans !~ /^y$/i) {
513 return read_prompt 0, $prompt;
519 return read_prompt 1, $prompt;
522 sub get_ktest_config {
526 return if (defined($opt{$config}));
528 if (defined($config_help{$config})) {
530 print $config_help{$config};
535 if (defined($default{$config}) && length($default{$config})) {
536 print "\[$default{$config}\] ";
539 $ans =~ s/^\s*(.*\S)\s*$/$1/;
540 if ($ans =~ /^\s*$/) {
541 if ($default{$config}) {
542 $ans = $default{$config};
544 print "Your answer can not be blank\n";
548 $entered_configs{$config} = ${ans};
553 sub get_ktest_configs {
554 get_ktest_config("MACHINE");
555 get_ktest_config("BUILD_DIR");
556 get_ktest_config("OUTPUT_DIR");
559 get_ktest_config("BUILD_OPTIONS");
562 # options required for other than just building a kernel
564 get_ktest_config("POWER_CYCLE");
565 get_ktest_config("CONSOLE");
568 # options required for install and more
569 if ($buildonly != 1) {
570 get_ktest_config("SSH_USER");
571 get_ktest_config("BUILD_TARGET");
572 get_ktest_config("TARGET_IMAGE");
575 get_ktest_config("LOCALVERSION");
577 return if ($buildonly);
579 my $rtype = $opt{"REBOOT_TYPE"};
581 if (!defined($rtype)) {
582 if (!defined($opt{"GRUB_MENU"})) {
583 get_ktest_config("REBOOT_TYPE");
584 $rtype = $entered_configs{"REBOOT_TYPE"};
590 if ($rtype eq "grub") {
591 get_ktest_config("GRUB_MENU");
594 if ($rtype eq "grub2") {
595 get_ktest_config("GRUB_MENU");
596 get_ktest_config("GRUB_FILE");
599 if ($rtype eq "syslinux") {
600 get_ktest_config("SYSLINUX_LABEL");
604 sub process_variables {
605 my ($value, $remove_undef) = @_;
608 # We want to check for '\', and it is just easier
609 # to check the previous characet of '$' and not need
610 # to worry if '$' is the first character. By adding
611 # a space to $value, we can just check [^\\]\$ and
612 # it will still work.
615 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
619 # append beginning of value to retval
620 $retval = "$retval$begin";
621 if (defined($variable{$var})) {
622 $retval = "$retval$variable{$var}";
623 } elsif (defined($remove_undef) && $remove_undef) {
624 # for if statements, any variable that is not defined,
625 # we simple convert to 0
626 $retval = "${retval}0";
628 # put back the origin piece.
629 $retval = "$retval\$\{$var\}";
630 # This could be an option that is used later, save
631 # it so we don't warn if this option is not one of
633 $used_options{$var} = 1;
637 $retval = "$retval$value";
639 # remove the space added in the beginning
646 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
648 my $prvalue = process_variables($rvalue);
650 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
651 # Note if a test is something other than build, then we
652 # will need other manditory options.
653 if ($prvalue ne "install") {
654 # for bisect, we need to check BISECT_TYPE
655 if ($prvalue ne "bisect") {
659 # install still limits some manditory options.
664 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
665 if ($prvalue ne "install") {
668 # install still limits some manditory options.
673 if (defined($opt{$lvalue})) {
674 if (!$override || defined(${$overrides}{$lvalue})) {
677 $extra = "In the same override section!\n";
679 die "$name: $.: Option $lvalue defined more than once!\n$extra";
681 ${$overrides}{$lvalue} = $prvalue;
683 if ($rvalue =~ /^\s*$/) {
684 delete $opt{$lvalue};
686 $opt{$lvalue} = $prvalue;
691 my ($lvalue, $rvalue, $name) = @_;
693 my $prvalue = process_variables($rvalue);
696 if (defined($evals{$lvalue})) {
697 $arr = $evals{$lvalue};
700 $evals{$lvalue} = $arr;
703 push @{$arr}, $rvalue;
707 my ($lvalue, $rvalue) = @_;
709 if ($rvalue =~ /^\s*$/) {
710 delete $variable{$lvalue};
712 $rvalue = process_variables($rvalue);
713 $variable{$lvalue} = $rvalue;
717 sub process_compare {
718 my ($lval, $cmp, $rval) = @_;
729 return $lval eq $rval;
730 } elsif ($cmp eq "!=") {
731 return $lval ne $rval;
732 } elsif ($cmp eq "=~") {
733 return $lval =~ m/$rval/;
734 } elsif ($cmp eq "!~") {
735 return $lval !~ m/$rval/;
738 my $statement = "$lval $cmp $rval";
739 my $ret = eval $statement;
741 # $@ stores error of eval
752 return defined($variable{$2}) ||
757 sub process_expression {
758 my ($name, $val) = @_;
762 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
765 if (process_expression($name, $express)) {
766 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
768 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
776 while ($val =~ s/^(.*?)($OR|$AND)//) {
780 if (process_expression($name, $express)) {
791 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
792 my $ret = process_compare($1, $2, $3);
794 die "$name: $.: Unable to process comparison\n";
799 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
801 return !value_defined($2);
803 return value_defined($2);
807 if ($val =~ /^\s*0\s*$/) {
809 } elsif ($val =~ /^\s*\d+\s*$/) {
813 die ("$name: $.: Undefined content $val in if statement\n");
817 my ($name, $value) = @_;
819 # Convert variables and replace undefined ones with 0
820 my $val = process_variables($value, 1);
821 my $ret = process_expression $name, $val;
827 my ($config, $current_test_num) = @_;
830 open($in, $config) || die "can't read file $config";
833 $name =~ s,.*/(.*),$1,;
835 my $test_num = $$current_test_num;
838 my $num_tests_set = 0;
851 # ignore blank lines and comments
852 next if (/^\s*$/ || /\s*\#/);
854 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
864 if ($type eq "TEST_START") {
866 if ($num_tests_set) {
867 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
870 $old_test_num = $test_num;
871 $old_repeat = $repeat;
873 $test_num += $repeat;
880 # If SKIP is anywhere in the line, the command will be skipped
881 if ($rest =~ s/\s+SKIP\b//) {
888 if ($rest =~ s/\sELSE\b//) {
890 die "$name: $.: ELSE found with out matching IF section\n$_";
901 if ($rest =~ s/\sIF\s+(.*)//) {
902 if (process_if($name, $1)) {
914 if ($type eq "TEST_START") {
915 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
917 $repeat_tests{"$test_num"} = $repeat;
919 } elsif ($rest =~ s/\sOVERRIDE\b//) {
922 # Clear previous overrides
927 if (!$skip && $rest !~ /^\s*$/) {
928 die "$name: $.: Gargbage found after $type\n$_";
931 if ($skip && $type eq "TEST_START") {
932 $test_num = $old_test_num;
933 $repeat = $old_repeat;
936 } elsif (/^\s*ELSE\b(.*)$/) {
938 die "$name: $.: ELSE found with out matching IF section\n$_";
947 if ($rest =~ /\sIF\s+(.*)/) {
948 # May be a ELSE IF section.
949 if (process_if($name, $1)) {
960 if ($rest !~ /^\s*$/) {
961 die "$name: $.: Gargbage found after DEFAULTS\n$_";
964 } elsif (/^\s*INCLUDE\s+(\S+)/) {
969 die "$name: $.: INCLUDE can only be done in default sections\n$_";
972 my $file = process_variables($1);
974 if ($file !~ m,^/,) {
975 # check the path of the config file first
976 if ($config =~ m,(.*)/,) {
984 die "$name: $.: Can't read file $file\n$_";
987 if (__read_config($file, \$test_num)) {
991 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
998 if ($default || $lvalue =~ /\[\d+\]$/) {
999 set_eval($lvalue, $rvalue, $name);
1001 my $val = "$lvalue\[$test_num\]";
1002 set_eval($val, $rvalue, $name);
1005 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1013 ($lvalue eq "NUM_TESTS" ||
1014 $lvalue eq "LOG_FILE" ||
1015 $lvalue eq "CLEAR_LOG")) {
1016 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
1019 if ($lvalue eq "NUM_TESTS") {
1021 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1024 die "$name: $.: NUM_TESTS must be set in default section\n";
1029 if ($default || $lvalue =~ /\[\d+\]$/) {
1030 set_value($lvalue, $rvalue, $override, \%overrides, $name);
1032 my $val = "$lvalue\[$test_num\]";
1033 set_value($val, $rvalue, $override, \%overrides, $name);
1036 $repeats{$val} = $repeat;
1039 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1045 # process config variables.
1046 # Config variables are only active while reading the
1047 # config and can be defined anywhere. They also ignore
1048 # TEST_START and DEFAULTS, but are skipped if they are in
1049 # on of these sections that have SKIP defined.
1050 # The save variable can be
1051 # defined multiple times and the new one simply overrides
1053 set_variable($lvalue, $rvalue);
1056 die "$name: $.: Garbage found in config\n$_";
1061 $test_num += $repeat - 1;
1062 $opt{"NUM_TESTS"} = $test_num;
1067 $$current_test_num = $test_num;
1073 print "What test case would you like to run?\n";
1074 print " (build, install or boot)\n";
1075 print " Other tests are available but require editing the config file\n";
1078 $default{"TEST_TYPE"} = $ans;
1087 $test_case = __read_config $config, \$test_num;
1089 # make sure we have all mandatory configs
1092 # was a test specified?
1094 print "No test case specified.\n";
1100 foreach my $default (keys %default) {
1101 if (!defined($opt{$default})) {
1102 $opt{$default} = $default{$default};
1106 if ($opt{"IGNORE_UNUSED"} == 1) {
1112 # check if there are any stragglers (typos?)
1113 foreach my $option (keys %opt) {
1115 # remove per test labels.
1117 if (!exists($option_map{$op}) &&
1118 !exists($default{$op}) &&
1119 !exists($used_options{$op})) {
1126 $s = " is" if (keys %not_used == 1);
1127 print "The following option$s not used; could be a typo:\n";
1128 foreach my $option (keys %not_used) {
1131 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1132 if (!read_yn "Do you want to continue?") {
1139 my ($name, $option, $i) = @_;
1141 # Add space to evaluate the character before $
1142 $option = " $option";
1147 foreach my $test (keys %repeat_tests) {
1149 $i < $test + $repeat_tests{$test}) {
1157 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1162 # Append beginning of line
1163 $retval = "$retval$start";
1165 # If the iteration option OPT[$i] exists, then use that.
1166 # otherwise see if the default OPT (without [$i]) exists.
1168 my $o = "$var\[$i\]";
1169 my $parento = "$var\[$parent\]";
1171 # If a variable contains itself, use the default var
1172 if (($var eq $name) && defined($opt{$var})) {
1174 $retval = "$retval$o";
1175 } elsif (defined($opt{$o})) {
1177 $retval = "$retval$o";
1178 } elsif ($repeated && defined($opt{$parento})) {
1179 $o = $opt{$parento};
1180 $retval = "$retval$o";
1181 } elsif (defined($opt{$var})) {
1183 $retval = "$retval$o";
1184 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1185 # special option KERNEL_VERSION uses kernel version
1187 $retval = "$retval$version";
1189 $retval = "$retval\$\{$var\}";
1195 $retval = "$retval$option";
1203 my ($name, $option, $i) = @_;
1205 my $option_name = "$name\[$i\]";
1208 my $old_option = $option;
1210 if (defined($evals{$option_name})) {
1211 $ev = $evals{$option_name};
1212 } elsif (defined($evals{$name})) {
1213 $ev = $evals{$name};
1218 for my $e (@{$ev}) {
1219 eval "\$option =~ $e";
1222 if ($option ne $old_option) {
1223 doprint("$name changed from '$old_option' to '$option'\n");
1230 my ($name, $option, $i) = @_;
1234 # Since an option can evaluate to another option,
1235 # keep iterating until we do not evaluate any more
1238 while ($prev ne $option) {
1239 # Check for recursive evaluations.
1240 # 100 deep should be more than enough.
1242 die "Over 100 evaluations accurred with $option\n" .
1243 "Check for recursive variables\n";
1246 $option = __eval_option($name, $option, $i);
1249 $option = process_evals($name, $option, $i);
1257 sub wait_for_monitor;
1262 # Make sure everything has been written to disk
1265 if (defined($time)) {
1267 # flush out current monitor
1268 # May contain the reboot success line
1272 # try to reboot normally
1273 if (run_command $reboot) {
1274 if (defined($powercycle_after_reboot)) {
1275 sleep $powercycle_after_reboot;
1276 run_command "$power_cycle";
1279 # nope? power cycle it.
1280 run_command "$power_cycle";
1283 if (defined($time)) {
1285 # We only want to get to the new kernel, don't fail
1286 # if we stumble over a call trace.
1287 my $save_ignore_errors = $ignore_errors;
1290 # Look for the good kernel to boot
1291 if (wait_for_monitor($time, "Linux version")) {
1293 doprint "Reboot did not finish. Forcing power cycle\n";
1294 run_command "$power_cycle";
1297 $ignore_errors = $save_ignore_errors;
1299 # Still need to wait for the reboot to finish
1300 wait_for_monitor($time, $reboot_success_line);
1306 sub reboot_to_good {
1309 if (defined($switch_to_good)) {
1310 run_command $switch_to_good;
1319 return $test_type eq "build" || $no_reboot ||
1320 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1321 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1325 doprint "CRITICAL FAILURE... ", @_, "\n";
1329 if ($reboot_on_error && !do_not_reboot) {
1331 doprint "REBOOTING\n";
1334 } elsif ($poweroff_on_error && defined($power_off)) {
1335 doprint "POWERING OFF\n";
1339 if (defined($opt{"LOG_FILE"})) {
1340 print " See $opt{LOG_FILE} for more info.\n";
1351 my $pid = open($fp, "$console|") or
1352 dodie "Can't open console $console";
1354 $flags = fcntl($fp, F_GETFL, 0) or
1355 dodie "Can't get flags for the socket: $!";
1356 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1357 dodie "Can't set flags for the socket: $!";
1363 my ($fp, $pid) = @_;
1365 doprint "kill child process $pid\n";
1366 kill $close_console_signal, $pid;
1373 if ($monitor_cnt++) {
1376 $monitor_fp = \*MONFD;
1377 $monitor_pid = open_console $monitor_fp;
1381 open(MONFD, "Stop perl from warning about single use of MONFD");
1385 return if (!defined $console);
1386 if (--$monitor_cnt) {
1389 close_console($monitor_fp, $monitor_pid);
1392 sub wait_for_monitor {
1393 my ($time, $stop) = @_;
1397 my $start_time = time;
1398 my $skip_call_trace = 0;
1400 my $bug_ignored = 0;
1403 doprint "** Wait for monitor to settle down **\n";
1405 # read the monitor and wait for the system to calm down
1407 $line = wait_for_input($monitor_fp, $time);
1408 last if (!defined($line));
1410 $full_line .= $line;
1412 if (defined($stop) && $full_line =~ /$stop/) {
1413 doprint "wait for monitor detected $stop\n";
1417 if ($full_line =~ /\[ backtrace testing \]/) {
1418 $skip_call_trace = 1;
1421 if ($full_line =~ /call trace:/i) {
1422 if (!$bug && !$skip_call_trace) {
1423 if ($ignore_errors) {
1431 if ($full_line =~ /\[ end of backtrace testing \]/) {
1432 $skip_call_trace = 0;
1435 if ($full_line =~ /Kernel panic -/) {
1439 if ($line =~ /\n/) {
1443 if ($now - $start_time >= $max_monitor_wait) {
1444 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1448 print "** Monitor flushed **\n";
1453 my ($result, $basedir) = @_;
1455 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1456 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1458 my $type = $build_type;
1459 if ($type =~ /useconfig/) {
1460 $type = "useconfig";
1463 my $dir = "$machine-$test_type-$type-$result-$date";
1465 $dir = "$basedir/$dir";
1469 die "can't create $dir";
1473 "config" => $output_config,
1474 "buildlog" => $buildlog,
1476 "testlog" => $testlog,
1479 while (my ($name, $source) = each(%files)) {
1481 cp "$source", "$dir/$name" or
1482 die "failed to copy $source";
1486 doprint "*** Saved info to $dir ***\n";
1491 if (defined($post_test)) {
1492 run_command $post_test;
1495 if ($die_on_failure) {
1503 # no need to reboot for just building.
1504 if (!do_not_reboot) {
1505 doprint "REBOOTING\n";
1506 reboot_to_good $sleep_time;
1511 if (defined($test_name)) {
1512 $name = " ($test_name)";
1515 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1516 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1517 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1518 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1519 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1521 if (defined($store_failures)) {
1522 save_logs "fail", $store_failures;
1534 $command =~ s/\$SSH_USER/$ssh_user/g;
1535 $command =~ s/\$MACHINE/$machine/g;
1537 doprint("$command ... ");
1539 $pid = open(CMD, "$command 2>&1 |") or
1540 (fail "unable to exec $command" and return 0);
1542 if (defined($opt{"LOG_FILE"})) {
1543 open(LOG, ">>$opt{LOG_FILE}") or
1544 dodie "failed to write to log";
1548 if (defined($redirect)) {
1549 open (RD, ">$redirect") or
1550 dodie "failed to write to redirect $redirect";
1555 print LOG if ($dolog);
1556 print RD if ($dord);
1563 close(LOG) if ($dolog);
1564 close(RD) if ($dord);
1567 doprint "FAILED!\n";
1569 doprint "SUCCESS\n";
1577 my $cp_exec = $ssh_exec;
1579 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1580 return run_command "$cp_exec";
1584 my ($src, $dst, $cp_scp) = @_;
1586 $cp_scp =~ s/\$SRC_FILE/$src/g;
1587 $cp_scp =~ s/\$DST_FILE/$dst/g;
1589 return run_command "$cp_scp";
1592 sub run_scp_install {
1593 my ($src, $dst) = @_;
1595 my $cp_scp = $scp_to_target_install;
1597 return run_scp($src, $dst, $cp_scp);
1601 my ($src, $dst) = @_;
1603 my $cp_scp = $scp_to_target;
1605 return run_scp($src, $dst, $cp_scp);
1608 sub get_grub2_index {
1610 return if (defined($grub_number) && defined($last_grub_menu) &&
1611 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1612 $last_machine eq $machine);
1614 doprint "Find grub2 menu ... ";
1617 my $ssh_grub = $ssh_exec;
1618 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1620 open(IN, "$ssh_grub |")
1621 or die "unable to get $grub_file";
1626 if (/^menuentry.*$grub_menu/) {
1630 } elsif (/^menuentry\s/) {
1636 die "Could not find '$grub_menu' in $grub_file on $machine"
1638 doprint "$grub_number\n";
1639 $last_grub_menu = $grub_menu;
1640 $last_machine = $machine;
1643 sub get_grub_index {
1645 if ($reboot_type eq "grub2") {
1650 if ($reboot_type ne "grub") {
1653 return if (defined($grub_number) && defined($last_grub_menu) &&
1654 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1655 $last_machine eq $machine);
1657 doprint "Find grub menu ... ";
1660 my $ssh_grub = $ssh_exec;
1661 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1663 open(IN, "$ssh_grub |")
1664 or die "unable to get menu.lst";
1669 if (/^\s*title\s+$grub_menu\s*$/) {
1673 } elsif (/^\s*title\s/) {
1679 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1681 doprint "$grub_number\n";
1682 $last_grub_menu = $grub_menu;
1683 $last_machine = $machine;
1688 my ($fp, $time) = @_;
1694 if (!defined($time)) {
1699 vec($rin, fileno($fp), 1) = 1;
1700 ($ready, $time) = select($rin, undef, undef, $time);
1704 # try to read one char at a time
1705 while (sysread $fp, $ch, 1) {
1707 last if ($ch eq "\n");
1710 if (!length($line)) {
1718 if (defined($switch_to_test)) {
1719 run_command $switch_to_test;
1722 if ($reboot_type eq "grub") {
1723 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1724 } elsif ($reboot_type eq "grub2") {
1725 run_ssh "$grub_reboot $grub_number";
1726 } elsif ($reboot_type eq "syslinux") {
1727 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
1728 } elsif (defined $reboot_script) {
1729 run_command "$reboot_script";
1737 doprint "git rev-list --max-count=1 $commit ... ";
1738 my $sha1 = `git rev-list --max-count=1 $commit`;
1745 dodie "Failed to get git $commit";
1758 my $bug_ignored = 0;
1759 my $skip_call_trace = 0;
1767 open(DMESG, "> $dmesg") or
1768 die "unable to write to $dmesg";
1774 my $monitor_start = time;
1776 my $version_found = 0;
1780 if ($bug && defined($stop_after_failure) &&
1781 $stop_after_failure >= 0) {
1782 my $time = $stop_after_failure - (time - $failure_start);
1783 $line = wait_for_input($monitor_fp, $time);
1784 if (!defined($line)) {
1785 doprint "bug timed out after $booted_timeout seconds\n";
1786 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1790 $line = wait_for_input($monitor_fp, $booted_timeout);
1791 if (!defined($line)) {
1792 my $s = $booted_timeout == 1 ? "" : "s";
1793 doprint "Successful boot found: break after $booted_timeout second$s\n";
1797 $line = wait_for_input($monitor_fp);
1798 if (!defined($line)) {
1799 my $s = $timeout == 1 ? "" : "s";
1800 doprint "Timed out after $timeout second$s\n";
1808 # we are not guaranteed to get a full line
1809 $full_line .= $line;
1811 if ($full_line =~ /$success_line/) {
1813 $success_start = time;
1816 if ($booted && defined($stop_after_success) &&
1817 $stop_after_success >= 0) {
1819 if ($now - $success_start >= $stop_after_success) {
1820 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1825 if ($full_line =~ /\[ backtrace testing \]/) {
1826 $skip_call_trace = 1;
1829 if ($full_line =~ /call trace:/i) {
1830 if (!$bug && !$skip_call_trace) {
1831 if ($ignore_errors) {
1835 $failure_start = time;
1840 if ($bug && defined($stop_after_failure) &&
1841 $stop_after_failure >= 0) {
1843 if ($now - $failure_start >= $stop_after_failure) {
1844 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1849 if ($full_line =~ /\[ end of backtrace testing \]/) {
1850 $skip_call_trace = 0;
1853 if ($full_line =~ /Kernel panic -/) {
1854 $failure_start = time;
1858 # Detect triple faults by testing the banner
1859 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1860 if ($1 eq $version) {
1862 } elsif ($version_found && $detect_triplefault) {
1863 # We already booted into the kernel we are testing,
1864 # but now we booted into another kernel?
1865 # Consider this a triple fault.
1866 doprint "Aleady booted in Linux kernel $version, but now\n";
1867 doprint "we booted into Linux kernel $1.\n";
1868 doprint "Assuming that this is a triple fault.\n";
1869 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1874 if ($line =~ /\n/) {
1878 if ($stop_test_after > 0 && !$booted && !$bug) {
1879 if (time - $monitor_start > $stop_test_after) {
1880 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1889 return 0 if ($in_bisect);
1890 fail "failed - got a bug report" and return 0;
1894 return 0 if ($in_bisect);
1895 fail "failed - never got a boot prompt." and return 0;
1899 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1905 sub eval_kernel_version {
1908 $option =~ s/\$KERNEL_VERSION/$version/g;
1913 sub do_post_install {
1915 return if (!defined($post_install));
1917 my $cp_post_install = eval_kernel_version $post_install;
1918 run_command "$cp_post_install" or
1919 dodie "Failed to run post install";
1922 # Sometimes the reboot fails, and will hang. We try to ssh to the box
1923 # and if we fail, we force another reboot, that should powercycle it.
1925 if (!run_ssh "echo testing connection") {
1932 return if ($no_install);
1934 if (defined($pre_install)) {
1935 my $cp_pre_install = eval_kernel_version $pre_install;
1936 run_command "$cp_pre_install" or
1937 dodie "Failed to run pre install";
1940 my $cp_target = eval_kernel_version $target_image;
1944 run_scp_install "$outputdir/$build_target", "$cp_target" or
1945 dodie "failed to copy image";
1947 my $install_mods = 0;
1949 # should we process modules?
1951 open(IN, "$output_config") or dodie("Can't read config file");
1953 if (/CONFIG_MODULES(=y)?/) {
1962 if (!$install_mods) {
1964 doprint "No modules needed\n";
1968 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1969 dodie "Failed to install modules";
1971 my $modlib = "/lib/modules/$version";
1972 my $modtar = "ktest-mods.tar.bz2";
1974 run_ssh "rm -rf $modlib" or
1975 dodie "failed to remove old mods: $modlib";
1977 # would be nice if scp -r did not follow symbolic links
1978 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1979 dodie "making tarball";
1981 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1982 dodie "failed to copy modules";
1984 unlink "$tmpdir/$modtar";
1986 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1987 dodie "failed to tar modules";
1989 run_ssh "rm -f /tmp/$modtar";
1995 # get the release name
1996 return if ($have_version);
1997 doprint "$make kernelrelease ... ";
1998 $version = `$make kernelrelease | tail -1`;
2000 doprint "$version\n";
2004 sub start_monitor_and_boot {
2005 # Make sure the stable kernel has finished booting
2007 # Install bisects, don't need console
2008 if (defined $console) {
2018 start_monitor if (defined $console);
2022 my $check_build_re = ".*:.*(warning|error|Error):.*";
2023 my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2025 sub process_warning_line {
2030 # for distcc heterogeneous systems, some compilers
2031 # do things differently causing warning lines
2032 # to be slightly different. This makes an attempt
2033 # to fixe those issues.
2035 # chop off the index into the line
2036 # using distcc, some compilers give different indexes
2037 # depending on white space
2038 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2040 # Some compilers use UTF-8 extended for quotes and some don't.
2041 $line =~ s/$utf8_quote/'/g;
2046 # Read buildlog and check against warnings file for any
2051 sub check_buildlog {
2052 return 1 if (!defined $warnings_file);
2056 # Failed builds should not reboot the target
2057 my $save_no_reboot = $no_reboot;
2060 if (-f $warnings_file) {
2061 open(IN, $warnings_file) or
2062 dodie "Error opening $warnings_file";
2065 if (/$check_build_re/) {
2066 my $warning = process_warning_line $_;
2068 $warnings_list{$warning} = 1;
2074 # If warnings file didn't exist, and WARNINGS_FILE exist,
2075 # then we fail on any warning!
2077 open(IN, $buildlog) or dodie "Can't open $buildlog";
2079 if (/$check_build_re/) {
2080 my $warning = process_warning_line $_;
2082 if (!defined $warnings_list{$warning}) {
2083 fail "New warning found (not in $warnings_file)\n$_\n";
2084 $no_reboot = $save_no_reboot;
2089 $no_reboot = $save_no_reboot;
2093 sub check_patch_buildlog {
2096 my @files = `git show $patch | diffstat -l`;
2098 foreach my $file (@files) {
2102 open(IN, "git show $patch |") or
2103 dodie "failed to show $patch";
2105 if (m,^--- a/(.*),) {
2107 $files[$#files] = $1;
2112 open(IN, $buildlog) or dodie "Can't open $buildlog";
2114 if (/^\s*(.*?):.*(warning|error)/) {
2116 foreach my $file (@files) {
2117 my $fullpath = "$builddir/$file";
2118 if ($file eq $err || $fullpath eq $err) {
2119 fail "$file built with warnings" and return 0;
2129 sub apply_min_config {
2130 my $outconfig = "$output_config.new";
2132 # Read the config file and remove anything that
2133 # is in the force_config hash (from minconfig and others)
2134 # then add the force config back.
2136 doprint "Applying minimum configurations into $output_config.new\n";
2138 open (OUT, ">$outconfig") or
2139 dodie "Can't create $outconfig";
2141 if (-f $output_config) {
2142 open (IN, $output_config) or
2143 dodie "Failed to open $output_config";
2145 if (/^(# )?(CONFIG_[^\s=]*)/) {
2146 next if (defined($force_config{$2}));
2152 foreach my $config (keys %force_config) {
2153 print OUT "$force_config{$config}\n";
2157 run_command "mv $outconfig $output_config";
2160 sub make_oldconfig {
2162 my @force_list = keys %force_config;
2164 if ($#force_list >= 0) {
2168 if (!run_command "$make olddefconfig") {
2169 # Perhaps olddefconfig doesn't exist in this version of the kernel
2171 doprint "olddefconfig failed, trying make oldnoconfig\n";
2172 if (!run_command "$make oldnoconfig") {
2173 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2174 # try a yes '' | oldconfig
2175 run_command "yes '' | $make oldconfig" or
2176 dodie "failed make config oldconfig";
2181 # read a config file and use this to force new configs.
2182 sub load_force_config {
2185 doprint "Loading force configs from $config\n";
2186 open(IN, $config) or
2187 dodie "failed to read $config";
2190 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2191 $force_config{$1} = $_;
2192 } elsif (/^# (CONFIG_\S*) is not set/) {
2193 $force_config{$1} = $_;
2204 # Failed builds should not reboot the target
2205 my $save_no_reboot = $no_reboot;
2208 # Calculate a new version from here.
2211 if (defined($pre_build)) {
2212 my $ret = run_command $pre_build;
2213 if (!$ret && defined($pre_build_die) &&
2215 dodie "failed to pre_build\n";
2219 if ($type =~ /^useconfig:(.*)/) {
2220 run_command "cp $1 $output_config" or
2221 dodie "could not copy $1 to .config";
2223 $type = "oldconfig";
2226 # old config can ask questions
2227 if ($type eq "oldconfig") {
2228 $type = "olddefconfig";
2230 # allow for empty configs
2231 run_command "touch $output_config";
2234 run_command "mv $output_config $outputdir/config_temp" or
2235 dodie "moving .config";
2237 run_command "$make mrproper" or dodie "make mrproper";
2239 run_command "mv $outputdir/config_temp $output_config" or
2240 dodie "moving config_temp";
2243 } elsif (!$noclean) {
2244 unlink "$output_config";
2245 run_command "$make mrproper" or
2246 dodie "make mrproper";
2249 # add something to distinguish this build
2250 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2251 print OUT "$localversion\n";
2254 if (defined($minconfig)) {
2255 load_force_config($minconfig);
2258 if ($type ne "olddefconfig") {
2259 run_command "$make $type" or
2260 dodie "failed make config";
2262 # Run old config regardless, to enforce min configurations
2265 $redirect = "$buildlog";
2266 my $build_ret = run_command "$make $build_options";
2269 if (defined($post_build)) {
2270 # Because a post build may change the kernel version
2273 my $ret = run_command $post_build;
2274 if (!$ret && defined($post_build_die) &&
2276 dodie "failed to post_build\n";
2281 # bisect may need this to pass
2283 $no_reboot = $save_no_reboot;
2286 fail "failed build" and return 0;
2289 $no_reboot = $save_no_reboot;
2295 if (!run_ssh "halt" or defined($power_off)) {
2296 if (defined($poweroff_after_halt)) {
2297 sleep $poweroff_after_halt;
2298 run_command "$power_off";
2302 run_command "$power_off";
2309 if (defined($post_test)) {
2310 run_command $post_test;
2317 if (defined($test_name)) {
2318 $name = " ($test_name)";
2321 doprint "\n\n*******************************************\n";
2322 doprint "*******************************************\n";
2323 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2324 doprint "*******************************************\n";
2325 doprint "*******************************************\n";
2327 if (defined($store_successes)) {
2328 save_logs "success", $store_successes;
2331 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2332 doprint "Reboot and wait $sleep_time seconds\n";
2333 reboot_to_good $sleep_time;
2339 doprint "Pass or fail? [p/f]";
2342 if ($ans eq "p" || $ans eq "P") {
2344 } elsif ($ans eq "f" || $ans eq "F") {
2347 print "Please answer 'P' or 'F'\n";
2352 sub child_run_test {
2355 # child should have no power
2356 $reboot_on_error = 0;
2357 $poweroff_on_error = 0;
2358 $die_on_failure = 1;
2360 $redirect = "$testlog";
2361 run_command $run_test or $failed = 1;
2369 sub child_finished {
2379 my $bug_ignored = 0;
2383 doprint "run test $run_test\n";
2387 $SIG{CHLD} = qw(child_finished);
2391 child_run_test if (!$child_pid);
2396 $line = wait_for_input($monitor_fp, 1);
2397 if (defined($line)) {
2399 # we are not guaranteed to get a full line
2400 $full_line .= $line;
2403 if ($full_line =~ /call trace:/i) {
2404 if ($ignore_errors) {
2411 if ($full_line =~ /Kernel panic -/) {
2415 if ($line =~ /\n/) {
2419 } while (!$child_done && !$bug);
2421 if (!$bug && $bug_ignored) {
2422 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2426 my $failure_start = time;
2429 $line = wait_for_input($monitor_fp, 1);
2430 if (defined($line)) {
2434 if ($now - $failure_start >= $stop_after_failure) {
2437 } while (defined($line));
2439 doprint "Detected kernel crash!\n";
2440 # kill the child with extreme prejudice
2444 waitpid $child_pid, 0;
2447 if (!$bug && $in_bisect) {
2448 if (defined($bisect_ret_good)) {
2449 if ($child_exit == $bisect_ret_good) {
2453 if (defined($bisect_ret_skip)) {
2454 if ($child_exit == $bisect_ret_skip) {
2458 if (defined($bisect_ret_abort)) {
2459 if ($child_exit == $bisect_ret_abort) {
2460 fail "test abort" and return -2;
2463 if (defined($bisect_ret_bad)) {
2464 if ($child_exit == $bisect_ret_skip) {
2468 if (defined($bisect_ret_default)) {
2469 if ($bisect_ret_default eq "good") {
2471 } elsif ($bisect_ret_default eq "bad") {
2473 } elsif ($bisect_ret_default eq "skip") {
2475 } elsif ($bisect_ret_default eq "abort") {
2478 fail "unknown default action: $bisect_ret_default"
2484 if ($bug || $child_exit) {
2485 return 0 if $in_bisect;
2486 fail "test failed" and return 0;
2491 sub run_git_bisect {
2494 doprint "$command ... ";
2496 my $output = `$command 2>&1`;
2503 dodie "Failed to git bisect";
2506 doprint "SUCCESS\n";
2507 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2508 doprint "$1 [$2]\n";
2509 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2510 $bisect_bad_commit = $1;
2511 doprint "Found bad commit... $1\n";
2514 # we already logged it, just print it now.
2522 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2523 reboot_to_good $bisect_sleep_time;
2526 # returns 1 on success, 0 on failure, -1 on skip
2527 sub run_bisect_test {
2528 my ($type, $buildtype) = @_;
2537 build $buildtype or $failed = 1;
2539 if ($type ne "build") {
2540 if ($failed && $bisect_skip) {
2544 dodie "Failed on build" if $failed;
2547 start_monitor_and_boot or $failed = 1;
2549 if ($type ne "boot") {
2550 if ($failed && $bisect_skip) {
2556 dodie "Failed on boot" if $failed;
2558 do_run_test or $failed = 1;
2569 # reboot the box to a kernel we can ssh to
2570 if ($type ne "build") {
2580 my $buildtype = "oldconfig";
2582 # We should have a minconfig to use?
2583 if (defined($minconfig)) {
2584 $buildtype = "useconfig:$minconfig";
2587 my $ret = run_bisect_test $type, $buildtype;
2589 if ($bisect_manual) {
2590 $ret = answer_bisect;
2593 # Are we looking for where it worked, not failed?
2594 if ($reverse_bisect && $ret >= 0) {
2600 } elsif ($ret == 0) {
2602 } elsif ($bisect_skip) {
2603 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2608 sub update_bisect_replay {
2609 my $tmp_log = "$tmpdir/ktest_bisect_log";
2610 run_command "git bisect log > $tmp_log" or
2611 die "can't create bisect log";
2620 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2621 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2622 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2624 my $good = $bisect_good;
2625 my $bad = $bisect_bad;
2626 my $type = $bisect_type;
2627 my $start = $bisect_start;
2628 my $replay = $bisect_replay;
2629 my $start_files = $bisect_files;
2631 if (defined($start_files)) {
2632 $start_files = " -- " . $start_files;
2637 # convert to true sha1's
2638 $good = get_sha1($good);
2639 $bad = get_sha1($bad);
2641 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2642 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2643 $reverse_bisect = 1;
2645 $reverse_bisect = 0;
2648 # Can't have a test without having a test to run
2649 if ($type eq "test" && !defined($run_test)) {
2653 # Check if a bisect was running
2654 my $bisect_start_file = "$builddir/.git/BISECT_START";
2656 my $check = $bisect_check;
2657 my $do_check = defined($check) && $check ne "0";
2659 if ( -f $bisect_start_file ) {
2660 print "Bisect in progress found\n";
2662 print " If you say yes, then no checks of good or bad will be done\n";
2664 if (defined($replay)) {
2665 print "** BISECT_REPLAY is defined in config file **";
2666 print " Ignore config option and perform new git bisect log?\n";
2667 if (read_ync " (yes, no, or cancel) ") {
2668 $replay = update_bisect_replay;
2671 } elsif (read_yn "read git log and continue?") {
2672 $replay = update_bisect_replay;
2680 my $head = get_sha1("HEAD");
2682 if ($check ne "good") {
2683 doprint "TESTING BISECT BAD [$bad]\n";
2684 run_command "git checkout $bad" or
2685 die "Failed to checkout $bad";
2687 $result = run_bisect $type;
2689 if ($result ne "bad") {
2690 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2694 if ($check ne "bad") {
2695 doprint "TESTING BISECT GOOD [$good]\n";
2696 run_command "git checkout $good" or
2697 die "Failed to checkout $good";
2699 $result = run_bisect $type;
2701 if ($result ne "good") {
2702 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2706 # checkout where we started
2707 run_command "git checkout $head" or
2708 die "Failed to checkout $head";
2711 run_command "git bisect start$start_files" or
2712 dodie "could not start bisect";
2714 run_command "git bisect good $good" or
2715 dodie "could not set bisect good to $good";
2717 run_git_bisect "git bisect bad $bad" or
2718 dodie "could not set bisect bad to $bad";
2720 if (defined($replay)) {
2721 run_command "git bisect replay $replay" or
2722 dodie "failed to run replay";
2725 if (defined($start)) {
2726 run_command "git checkout $start" or
2727 dodie "failed to checkout $start";
2732 $result = run_bisect $type;
2733 $test = run_git_bisect "git bisect $result";
2736 run_command "git bisect log" or
2737 dodie "could not capture git bisect log";
2739 run_command "git bisect reset" or
2740 dodie "could not reset git bisect";
2742 doprint "Bad commit was [$bisect_bad_commit]\n";
2747 # config_ignore holds the configs that were set (or unset) for
2748 # a good config and we will ignore these configs for the rest
2749 # of a config bisect. These configs stay as they were.
2752 # config_set holds what all configs were set as.
2755 # config_off holds the set of configs that the bad config had disabled.
2756 # We need to record them and set them in the .config when running
2757 # olddefconfig, because olddefconfig keeps the defaults.
2760 # config_off_tmp holds a set of configs to turn off for now
2763 # config_list is the set of configs that are being tested
2769 sub assign_configs {
2770 my ($hash, $config) = @_;
2773 or dodie "Failed to read $config";
2776 if (/^((CONFIG\S*)=.*)/) {
2784 sub process_config_ignore {
2787 assign_configs \%config_ignore, $config;
2790 sub read_current_config {
2791 my ($config_ref) = @_;
2793 %{$config_ref} = ();
2794 undef %{$config_ref};
2796 my @key = keys %{$config_ref};
2798 print "did not delete!\n";
2801 open (IN, "$output_config");
2804 if (/^(CONFIG\S+)=(.*)/) {
2805 ${$config_ref}{$1} = $2;
2811 sub get_dependencies {
2814 my $arr = $dependency{$config};
2815 if (!defined($arr)) {
2821 foreach my $dep (@{$arr}) {
2822 print "ADD DEP $dep\n";
2823 @deps = (@deps, get_dependencies $dep);
2832 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2834 foreach my $config (@configs) {
2835 print OUT "$config_set{$config}\n";
2836 my @deps = get_dependencies $config;
2837 foreach my $dep (@deps) {
2838 print OUT "$config_set{$dep}\n";
2842 # turn off configs to keep off
2843 foreach my $config (keys %config_off) {
2844 print OUT "# $config is not set\n";
2847 # turn off configs that should be off for now
2848 foreach my $config (@config_off_tmp) {
2849 print OUT "# $config is not set\n";
2852 foreach my $config (keys %config_ignore) {
2853 print OUT "$config_ignore{$config}\n";
2860 sub compare_configs {
2863 foreach my $item (keys %a) {
2864 if (!defined($b{$item})) {
2865 print "diff $item\n";
2873 print "diff2 $keys[0]\n";
2875 return -1 if ($#keys >= 0);
2880 sub run_config_bisect_test {
2883 return run_bisect_test $type, "oldconfig";
2886 sub process_passed {
2889 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2890 # Passed! All these configs are part of a good compile.
2891 # Add them to the min options.
2892 foreach my $config (keys %configs) {
2893 if (defined($config_list{$config})) {
2894 doprint " removing $config\n";
2895 $config_ignore{$config} = $config_list{$config};
2896 delete $config_list{$config};
2899 doprint "config copied to $outputdir/config_good\n";
2900 run_command "cp -f $output_config $outputdir/config_good";
2903 sub process_failed {
2906 doprint "\n\n***************************************\n";
2907 doprint "Found bad config: $config\n";
2908 doprint "***************************************\n\n";
2911 sub run_config_bisect {
2913 my @start_list = keys %config_list;
2915 if ($#start_list < 0) {
2916 doprint "No more configs to test!!!\n";
2920 doprint "***** RUN TEST ***\n";
2921 my $type = $config_bisect_type;
2925 my $count = $#start_list + 1;
2926 doprint " $count configs to test\n";
2928 my $half = int($#start_list / 2);
2931 my @tophalf = @start_list[0 .. $half];
2933 # keep the bottom half off
2934 if ($half < $#start_list) {
2935 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2937 @config_off_tmp = ();
2940 create_config @tophalf;
2941 read_current_config \%current_config;
2943 $count = $#tophalf + 1;
2944 doprint "Testing $count configs\n";
2946 # make sure we test something
2947 foreach my $config (@tophalf) {
2948 if (defined($current_config{$config})) {
2954 # try the other half
2955 doprint "Top half produced no set configs, trying bottom half\n";
2957 # keep the top half off
2958 @config_off_tmp = @tophalf;
2959 @tophalf = @start_list[$half + 1 .. $#start_list];
2961 create_config @tophalf;
2962 read_current_config \%current_config;
2963 foreach my $config (@tophalf) {
2964 if (defined($current_config{$config})) {
2970 doprint "Failed: Can't make new config with current configs\n";
2971 foreach my $config (@start_list) {
2972 doprint " CONFIG: $config\n";
2976 $count = $#tophalf + 1;
2977 doprint "Testing $count configs\n";
2980 $ret = run_config_bisect_test $type;
2981 if ($bisect_manual) {
2982 $ret = answer_bisect;
2985 process_passed %current_config;
2989 doprint "This config had a failure.\n";
2990 doprint "Removing these configs that were not set in this config:\n";
2991 doprint "config copied to $outputdir/config_bad\n";
2992 run_command "cp -f $output_config $outputdir/config_bad";
2994 # A config exists in this group that was bad.
2995 foreach my $config (keys %config_list) {
2996 if (!defined($current_config{$config})) {
2997 doprint " removing $config\n";
2998 delete $config_list{$config};
3002 @start_list = @tophalf;
3004 if ($#start_list == 0) {
3005 process_failed $start_list[0];
3009 # remove half the configs we are looking at and see if
3011 $half = int($#start_list / 2);
3012 } while ($#start_list > 0);
3014 # we found a single config, try it again unless we are running manually
3016 if ($bisect_manual) {
3017 process_failed $start_list[0];
3021 my @tophalf = @start_list[0 .. 0];
3023 $ret = run_config_bisect_test $type;
3025 process_passed %current_config;
3029 process_failed $start_list[0];
3036 my $start_config = $config_bisect;
3038 my $tmpconfig = "$tmpdir/use_config";
3040 if (defined($config_bisect_good)) {
3041 process_config_ignore $config_bisect_good;
3044 # Make the file with the bad config and the min config
3045 if (defined($minconfig)) {
3046 # read the min config for things to ignore
3047 run_command "cp $minconfig $tmpconfig" or
3048 dodie "failed to copy $minconfig to $tmpconfig";
3053 if (-f $tmpconfig) {
3054 load_force_config($tmpconfig);
3055 process_config_ignore $tmpconfig;
3058 # now process the start config
3059 run_command "cp $start_config $output_config" or
3060 dodie "failed to copy $start_config to $output_config";
3062 # read directly what we want to check
3064 open (IN, $output_config)
3065 or dodie "failed to open $output_config";
3068 if (/^((CONFIG\S*)=.*)/) {
3069 $config_check{$2} = $1;
3074 # Now run oldconfig with the minconfig
3077 # check to see what we lost (or gained)
3078 open (IN, $output_config)
3079 or dodie "Failed to read $start_config";
3081 my %removed_configs;
3085 if (/^((CONFIG\S*)=.*)/) {
3086 # save off all options
3087 $config_set{$2} = $1;
3088 if (defined($config_check{$2})) {
3089 if (defined($config_ignore{$2})) {
3090 $removed_configs{$2} = $1;
3092 $config_list{$2} = $1;
3094 } elsif (!defined($config_ignore{$2})) {
3095 $added_configs{$2} = $1;
3096 $config_list{$2} = $1;
3098 } elsif (/^# ((CONFIG\S*).*)/) {
3099 # Keep these configs disabled
3100 $config_set{$2} = $1;
3101 $config_off{$2} = $1;
3106 my @confs = keys %removed_configs;
3108 doprint "Configs overridden by default configs and removed from check:\n";
3109 foreach my $config (@confs) {
3110 doprint " $config\n";
3113 @confs = keys %added_configs;
3115 doprint "Configs appearing in make oldconfig and added:\n";
3116 foreach my $config (@confs) {
3117 doprint " $config\n";
3124 @config_off_tmp = ();
3126 # Sometimes kconfig does weird things. We must make sure
3127 # that the config we autocreate has everything we need
3128 # to test, otherwise we may miss testing configs, or
3129 # may not be able to create a new config.
3130 # Here we create a config with everything set.
3131 create_config (keys %config_list);
3132 read_current_config \%config_test;
3133 foreach my $config (keys %config_list) {
3134 if (!defined($config_test{$config})) {
3137 doprint "Configs not produced by kconfig (will not be checked):\n";
3139 doprint " $config\n";
3140 delete $config_list{$config};
3145 if (defined($config_bisect_check) && $config_bisect_check) {
3146 doprint " Checking to make sure bad config with min config fails\n";
3147 create_config keys %config_list;
3148 $ret = run_config_bisect_test $config_bisect_type;
3150 doprint " FAILED! Bad config with min config boots fine\n";
3153 doprint " Bad config with min config fails as expected\n";
3157 $ret = run_config_bisect;
3160 return $ret if ($ret < 0);
3165 sub patchcheck_reboot {
3166 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3167 reboot_to_good $patchcheck_sleep_time;
3173 die "PATCHCHECK_START[$i] not defined\n"
3174 if (!defined($patchcheck_start));
3175 die "PATCHCHECK_TYPE[$i] not defined\n"
3176 if (!defined($patchcheck_type));
3178 my $start = $patchcheck_start;
3181 if (defined($patchcheck_end)) {
3182 $end = $patchcheck_end;
3185 # Get the true sha1's since we can use things like HEAD~3
3186 $start = get_sha1($start);
3187 $end = get_sha1($end);
3189 my $type = $patchcheck_type;
3191 # Can't have a test without having a test to run
3192 if ($type eq "test" && !defined($run_test)) {
3196 open (IN, "git log --pretty=oneline $end|") or
3197 dodie "could not get git list";
3203 $list[$#list+1] = $_;
3204 last if (/^$start/);
3208 if ($list[$#list] !~ /^$start/) {
3209 fail "SHA1 $start not found";
3212 # go backwards in the list
3213 @list = reverse @list;
3215 my $save_clean = $noclean;
3216 my %ignored_warnings;
3218 if (defined($ignore_warnings)) {
3219 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3220 $ignored_warnings{$sha1} = 1;
3225 foreach my $item (@list) {
3227 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3229 doprint "\nProcessing commit $item\n\n";
3231 run_command "git checkout $sha1" or
3232 die "Failed to checkout $sha1";
3234 # only clean on the first and last patch
3235 if ($item eq $list[0] ||
3236 $item eq $list[$#list]) {
3237 $noclean = $save_clean;
3242 if (defined($minconfig)) {
3243 build "useconfig:$minconfig" or return 0;
3245 # ?? no config to use?
3246 build "oldconfig" or return 0;
3249 # No need to do per patch checking if warnings file exists
3250 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3251 check_patch_buildlog $sha1 or return 0;
3254 check_buildlog or return 0;
3256 next if ($type eq "build");
3260 start_monitor_and_boot or $failed = 1;
3262 if (!$failed && $type ne "boot"){
3263 do_run_test or $failed = 1;
3266 return 0 if ($failed);
3286 # $config depends on $dep
3287 my ($config, $dep) = @_;
3289 if (defined($depends{$config})) {
3290 $depends{$config} .= " " . $dep;
3292 $depends{$config} = $dep;
3295 # record the number of configs depending on $dep
3296 if (defined $depcount{$dep}) {
3299 $depcount{$dep} = 1;
3303 # taken from streamline_config.pl
3315 if (! -f $kconfig) {
3316 doprint "file $kconfig does not exist, skipping\n";
3320 open(KIN, "$kconfig")
3321 or die "Can't open $kconfig";
3325 # Make sure that lines ending with \ continue
3327 $_ = $line . " " . $_;
3338 # collect any Kconfig sources
3339 if (/^source\s*"(.*)"/) {
3340 $kconfigs[$#kconfigs+1] = $1;
3344 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3348 for (my $i = 0; $i < $iflevel; $i++) {
3349 add_dep $config, $ifdeps[$i];
3352 # collect the depends for the config
3353 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3355 add_dep $config, $1;
3357 # Get the configs that select this config
3358 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3360 # selected by depends on config
3361 add_dep $1, $config;
3363 # Check for if statements
3364 } elsif (/^if\s+(.*\S)\s*$/) {
3366 # remove beginning and ending non text
3367 $deps =~ s/^[^a-zA-Z0-9_]*//;
3368 $deps =~ s/[^a-zA-Z0-9_]*$//;
3370 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3372 $ifdeps[$iflevel++] = join ':', @deps;
3374 } elsif (/^endif/) {
3376 $iflevel-- if ($iflevel);
3379 } elsif (/^\s*help\s*$/) {
3385 # read in any configs that were found.
3386 foreach $kconfig (@kconfigs) {
3387 if (!defined($read_kconfigs{$kconfig})) {
3388 $read_kconfigs{$kconfig} = 1;
3389 read_kconfig("$builddir/$kconfig");
3395 # find out which arch this is by the kconfig file
3396 open (IN, $output_config)
3397 or dodie "Failed to read $output_config";
3400 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3407 if (!defined($arch)) {
3408 doprint "Could not find arch from config file\n";
3409 doprint "no dependencies used\n";
3413 # arch is really the subarch, we need to know
3414 # what directory to look at.
3415 if ($arch eq "i386" || $arch eq "x86_64") {
3417 } elsif ($arch =~ /^tile/) {
3421 my $kconfig = "$builddir/arch/$arch/Kconfig";
3423 if (! -f $kconfig && $arch =~ /\d$/) {
3425 # some subarchs have numbers, truncate them
3427 $kconfig = "$builddir/arch/$arch/Kconfig";
3428 if (! -f $kconfig) {
3429 doprint "No idea what arch dir $orig is for\n";
3430 doprint "no dependencies used\n";
3435 read_kconfig($kconfig);
3438 sub read_config_list {
3442 or dodie "Failed to read $config";
3445 if (/^((CONFIG\S*)=.*)/) {
3446 if (!defined($config_ignore{$2})) {
3447 $config_list{$2} = $1;
3455 sub read_output_config {
3458 assign_configs \%config_ignore, $config;
3461 sub make_new_config {
3464 open (OUT, ">$output_config")
3465 or dodie "Failed to write $output_config";
3467 foreach my $config (@configs) {
3468 print OUT "$config\n";
3476 $config =~ s/CONFIG_//;
3484 my $kconfig = chomp_config $dep;
3486 $dep = $depends{"$kconfig"};
3488 # the dep string we have saves the dependencies as they
3489 # were found, including expressions like ! && ||. We
3490 # want to split this out into just an array of configs.
3492 my $valid = "A-Za-z_0-9";
3496 while ($dep =~ /[$valid]/) {
3498 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3499 my $conf = "CONFIG_" . $1;
3501 $configs[$#configs + 1] = $conf;
3503 $dep =~ s/^[^$valid]*[$valid]+//;
3505 die "this should never happen";
3515 my %processed_configs;
3516 my %nochange_config;
3518 sub test_this_config {
3523 # if we already processed this config, skip it
3524 if (defined($processed_configs{$config})) {
3527 $processed_configs{$config} = 1;
3529 # if this config failed during this round, skip it
3530 if (defined($nochange_config{$config})) {
3534 my $kconfig = chomp_config $config;
3536 # Test dependencies first
3537 if (defined($depends{"$kconfig"})) {
3538 my @parents = get_depends $config;
3539 foreach my $parent (@parents) {
3540 # if the parent is in the min config, check it first
3541 next if (!defined($min_configs{$parent}));
3542 $found = test_this_config($parent);
3543 if (defined($found)) {
3549 # Remove this config from the list of configs
3550 # do a make olddefconfig and then read the resulting
3551 # .config to make sure it is missing the config that
3553 my %configs = %min_configs;
3554 delete $configs{$config};
3555 make_new_config ((values %configs), (values %keep_configs));
3558 assign_configs \%configs, $output_config;
3560 return $config if (!defined($configs{$config}));
3562 doprint "disabling config $config did not change .config\n";
3564 $nochange_config{$config} = 1;
3569 sub make_min_config {
3572 my $type = $minconfig_type;
3573 if ($type ne "boot" && $type ne "test") {
3574 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3575 " make_min_config works only with 'boot' and 'test'\n" and return;
3578 if (!defined($output_minconfig)) {
3579 fail "OUTPUT_MIN_CONFIG not defined" and return;
3582 # If output_minconfig exists, and the start_minconfig
3583 # came from min_config, than ask if we should use
3585 if (-f $output_minconfig && !$start_minconfig_defined) {
3586 print "$output_minconfig exists\n";
3587 if (!defined($use_output_minconfig)) {
3588 if (read_yn " Use it as minconfig?") {
3589 $start_minconfig = $output_minconfig;
3591 } elsif ($use_output_minconfig > 0) {
3592 doprint "Using $output_minconfig as MIN_CONFIG\n";
3593 $start_minconfig = $output_minconfig;
3595 doprint "Set to still use MIN_CONFIG as starting point\n";
3599 if (!defined($start_minconfig)) {
3600 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3603 my $temp_config = "$tmpdir/temp_config";
3605 # First things first. We build an allnoconfig to find
3606 # out what the defaults are that we can't touch.
3607 # Some are selections, but we really can't handle selections.
3609 my $save_minconfig = $minconfig;
3612 run_command "$make allnoconfig" or return 0;
3616 process_config_ignore $output_config;
3618 undef %save_configs;
3621 if (defined($ignore_config)) {
3622 # make sure the file exists
3623 `touch $ignore_config`;
3624 assign_configs \%save_configs, $ignore_config;
3627 %keep_configs = %save_configs;
3629 doprint "Load initial configs from $start_minconfig\n";
3631 # Look at the current min configs, and save off all the
3632 # ones that were set via the allnoconfig
3633 assign_configs \%min_configs, $start_minconfig;
3635 my @config_keys = keys %min_configs;
3637 # All configs need a depcount
3638 foreach my $config (@config_keys) {
3639 my $kconfig = chomp_config $config;
3640 if (!defined $depcount{$kconfig}) {
3641 $depcount{$kconfig} = 0;
3645 # Remove anything that was set by the make allnoconfig
3646 # we shouldn't need them as they get set for us anyway.
3647 foreach my $config (@config_keys) {
3648 # Remove anything in the ignore_config
3649 if (defined($keep_configs{$config})) {
3650 my $file = $ignore_config;
3651 $file =~ s,.*/(.*?)$,$1,;
3652 doprint "$config set by $file ... ignored\n";
3653 delete $min_configs{$config};
3656 # But make sure the settings are the same. If a min config
3657 # sets a selection, we do not want to get rid of it if
3658 # it is not the same as what we have. Just move it into
3660 if (defined($config_ignore{$config})) {
3661 if ($config_ignore{$config} ne $min_configs{$config}) {
3662 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3663 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3664 $keep_configs{$config} = $min_configs{$config};
3666 doprint "$config set by allnoconfig ... ignored\n";
3668 delete $min_configs{$config};
3680 # Now disable each config one by one and do a make oldconfig
3681 # till we find a config that changes our list.
3683 my @test_configs = keys %min_configs;
3685 # Sort keys by who is most dependent on
3686 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3689 # Put configs that did not modify the config at the end.
3691 for (my $i = 0; $i < $#test_configs; $i++) {
3692 if (!defined($nochange_config{$test_configs[0]})) {
3696 # This config didn't change the .config last time.
3697 # Place it at the end
3698 my $config = shift @test_configs;
3699 push @test_configs, $config;
3702 # if every test config has failed to modify the .config file
3703 # in the past, then reset and start over.
3705 undef %nochange_config;
3708 undef %processed_configs;
3710 foreach my $config (@test_configs) {
3712 $found = test_this_config $config;
3714 last if (defined($found));
3716 # oh well, try another config
3719 if (!defined($found)) {
3720 # we could have failed due to the nochange_config hash
3721 # reset and try again
3723 undef %nochange_config;
3727 doprint "No more configs found that we can disable\n";
3735 doprint "Test with $config disabled\n";
3737 # set in_bisect to keep build and monitor from dieing
3741 build "oldconfig" or $failed = 1;
3743 start_monitor_and_boot or $failed = 1;
3745 if ($type eq "test" && !$failed) {
3746 do_run_test or $failed = 1;
3755 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3756 # this config is needed, add it to the ignore list.
3757 $keep_configs{$config} = $min_configs{$config};
3758 $save_configs{$config} = $min_configs{$config};
3759 delete $min_configs{$config};
3761 # update new ignore configs
3762 if (defined($ignore_config)) {
3763 open (OUT, ">$temp_config")
3764 or die "Can't write to $temp_config";
3765 foreach my $config (keys %save_configs) {
3766 print OUT "$save_configs{$config}\n";
3769 run_command "mv $temp_config $ignore_config" or
3770 dodie "failed to copy update to $ignore_config";
3774 # We booted without this config, remove it from the minconfigs.
3775 doprint "$config is not needed, disabling\n";
3777 delete $min_configs{$config};
3779 # Also disable anything that is not enabled in this config
3781 assign_configs \%configs, $output_config;
3782 my @config_keys = keys %min_configs;
3783 foreach my $config (@config_keys) {
3784 if (!defined($configs{$config})) {
3785 doprint "$config is not set, disabling\n";
3786 delete $min_configs{$config};
3790 # Save off all the current mandidory configs
3791 open (OUT, ">$temp_config")
3792 or die "Can't write to $temp_config";
3793 foreach my $config (keys %keep_configs) {
3794 print OUT "$keep_configs{$config}\n";
3796 foreach my $config (keys %min_configs) {
3797 print OUT "$min_configs{$config}\n";
3801 run_command "mv $temp_config $output_minconfig" or
3802 dodie "failed to copy update to $output_minconfig";
3805 doprint "Reboot and wait $sleep_time seconds\n";
3806 reboot_to_good $sleep_time;
3813 sub make_warnings_file {
3816 if (!defined($warnings_file)) {
3817 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3820 if ($build_type eq "nobuild") {
3821 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3824 build $build_type or dodie "Failed to build";
3826 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3828 open(IN, $buildlog) or dodie "Can't open $buildlog";
3831 # Some compilers use UTF-8 extended for quotes
3832 # for distcc heterogeneous systems, this causes issues
3835 if (/$check_build_re/) {
3846 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3849 $ktest_config = $ARGV[0];
3850 if (! -f $ktest_config) {
3851 print "$ktest_config does not exist.\n";
3852 if (!read_yn "Create it?") {
3857 $ktest_config = "ktest.conf";
3860 if (! -f $ktest_config) {
3863 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3865 # Generated by ktest.pl
3868 # PWD is a ktest.pl variable that will result in the process working
3869 # directory that ktest.pl is executed in.
3871 # THIS_DIR is automatically assigned the PWD of the path that generated
3872 # the config file. It is best to use this variable when assigning other
3873 # directory paths within this directory. This allows you to easily
3874 # move the test cases to other locations or to other machines.
3876 THIS_DIR := $variable{"PWD"}
3878 # Define each test with TEST_START
3879 # The config options below it will override the defaults
3881 TEST_TYPE = $default{"TEST_TYPE"}
3888 read_config $ktest_config;
3890 if (defined($opt{"LOG_FILE"})) {
3891 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
3894 # Append any configs entered in manually to the config file.
3895 my @new_configs = keys %entered_configs;
3896 if ($#new_configs >= 0) {
3897 print "\nAppending entered in configs to $ktest_config\n";
3898 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3899 foreach my $config (@new_configs) {
3900 print OUT "$config = $entered_configs{$config}\n";
3901 $opt{$config} = process_variables($entered_configs{$config});
3905 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3906 unlink $opt{"LOG_FILE"};
3909 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3911 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3914 doprint "DEFAULT OPTIONS:\n";
3916 doprint "\nTEST $i OPTIONS";
3917 if (defined($repeat_tests{$i})) {
3918 $repeat = $repeat_tests{$i};
3919 doprint " ITERATE $repeat";
3924 foreach my $option (sort keys %opt) {
3926 if ($option =~ /\[(\d+)\]$/) {
3932 doprint "$option = $opt{$option}\n";
3936 sub __set_test_option {
3937 my ($name, $i) = @_;
3939 my $option = "$name\[$i\]";
3941 if (defined($opt{$option})) {
3942 return $opt{$option};
3945 foreach my $test (keys %repeat_tests) {
3947 $i < $test + $repeat_tests{$test}) {
3948 $option = "$name\[$test\]";
3949 if (defined($opt{$option})) {
3950 return $opt{$option};
3955 if (defined($opt{$name})) {
3962 sub set_test_option {
3963 my ($name, $i) = @_;
3965 my $option = __set_test_option($name, $i);
3966 return $option if (!defined($option));
3968 return eval_option($name, $option, $i);
3971 # First we need to do is the builds
3972 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3974 # Do not reboot on failing test options
3976 $reboot_success = 0;
3982 undef %force_config;
3984 my $makecmd = set_test_option("MAKE_CMD", $i);
3986 $outputdir = set_test_option("OUTPUT_DIR", $i);
3987 $builddir = set_test_option("BUILD_DIR", $i);
3989 chdir $builddir || die "can't change directory to $builddir";
3991 if (!-d $outputdir) {
3992 mkpath($outputdir) or
3993 die "can't create $outputdir";
3996 $make = "$makecmd O=$outputdir";
3998 # Load all the options into their mapped variable names
3999 foreach my $opt (keys %option_map) {
4000 ${$option_map{$opt}} = set_test_option($opt, $i);
4003 $start_minconfig_defined = 1;
4005 # The first test may override the PRE_KTEST option
4006 if (defined($pre_ktest) && $i == 1) {
4008 run_command $pre_ktest;
4011 # Any test can override the POST_KTEST option
4012 # The last test takes precedence.
4013 if (defined($post_ktest)) {
4014 $final_post_ktest = $post_ktest;
4017 if (!defined($start_minconfig)) {
4018 $start_minconfig_defined = 0;
4019 $start_minconfig = $minconfig;
4024 die "can't create $tmpdir";
4027 $ENV{"SSH_USER"} = $ssh_user;
4028 $ENV{"MACHINE"} = $machine;
4030 $buildlog = "$tmpdir/buildlog-$machine";
4031 $testlog = "$tmpdir/testlog-$machine";
4032 $dmesg = "$tmpdir/dmesg-$machine";
4033 $output_config = "$outputdir/.config";
4036 $target = "$ssh_user\@$machine";
4037 if ($reboot_type eq "grub") {
4038 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4039 } elsif ($reboot_type eq "grub2") {
4040 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4041 dodie "GRUB_FILE not defined" if (!defined($grub_file));
4042 } elsif ($reboot_type eq "syslinux") {
4043 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
4047 my $run_type = $build_type;
4048 if ($test_type eq "patchcheck") {
4049 $run_type = $patchcheck_type;
4050 } elsif ($test_type eq "bisect") {
4051 $run_type = $bisect_type;
4052 } elsif ($test_type eq "config_bisect") {
4053 $run_type = $config_bisect_type;
4054 } elsif ($test_type eq "make_min_config") {
4056 } elsif ($test_type eq "make_warnings_file") {
4060 # mistake in config file?
4061 if (!defined($run_type)) {
4062 $run_type = "ERROR";
4066 $installme = " no_install" if ($no_install);
4069 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
4071 if (defined($pre_test)) {
4072 run_command $pre_test;
4079 if (defined($addconfig)) {
4080 my $min = $minconfig;
4081 if (!defined($minconfig)) {
4084 run_command "cat $addconfig $min > $tmpdir/add_config" or
4085 dodie "Failed to create temp config";
4086 $minconfig = "$tmpdir/add_config";
4089 if (defined($checkout)) {
4090 run_command "git checkout $checkout" or
4091 die "failed to checkout $checkout";
4096 # A test may opt to not reboot the box
4097 if ($reboot_on_success) {
4098 $reboot_success = 1;
4101 if ($test_type eq "bisect") {
4104 } elsif ($test_type eq "config_bisect") {
4107 } elsif ($test_type eq "patchcheck") {
4110 } elsif ($test_type eq "make_min_config") {
4113 } elsif ($test_type eq "make_warnings_file") {
4115 make_warnings_file $i;
4119 if ($build_type ne "nobuild") {
4120 build $build_type or next;
4121 check_buildlog or next;
4124 if ($test_type eq "install") {
4131 if ($test_type ne "build") {
4133 start_monitor_and_boot or $failed = 1;
4135 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4136 do_run_test or $failed = 1;
4145 if (defined($final_post_ktest)) {
4146 run_command $final_post_ktest;
4149 if ($opt{"POWEROFF_ON_SUCCESS"}) {
4151 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4153 } elsif (defined($switch_to_good)) {
4154 # still need to get to the good kernel
4155 run_command $switch_to_good;
4159 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";