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;
192 my $config_bisect_type;
193 my $config_bisect_check;
196 my $patchcheck_start;
197 my $patchcheck_cherry;
200 # set when a test is something other that just building or install
201 # which would require more options.
204 # tell build not to worry about warnings, even when WARNINGS_FILE is set
207 # set when creating a new config
214 # force_config is the list of configs that we force enabled (or disabled)
215 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
218 # do not force reboots on config problems
222 my $reboot_success = 0;
225 "MACHINE" => \$machine,
226 "SSH_USER" => \$ssh_user,
227 "TMP_DIR" => \$tmpdir,
228 "OUTPUT_DIR" => \$outputdir,
229 "BUILD_DIR" => \$builddir,
230 "TEST_TYPE" => \$test_type,
231 "PRE_KTEST" => \$pre_ktest,
232 "POST_KTEST" => \$post_ktest,
233 "PRE_TEST" => \$pre_test,
234 "POST_TEST" => \$post_test,
235 "BUILD_TYPE" => \$build_type,
236 "BUILD_OPTIONS" => \$build_options,
237 "PRE_BUILD" => \$pre_build,
238 "POST_BUILD" => \$post_build,
239 "PRE_BUILD_DIE" => \$pre_build_die,
240 "POST_BUILD_DIE" => \$post_build_die,
241 "POWER_CYCLE" => \$power_cycle,
242 "REBOOT" => \$reboot,
243 "BUILD_NOCLEAN" => \$noclean,
244 "MIN_CONFIG" => \$minconfig,
245 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
246 "START_MIN_CONFIG" => \$start_minconfig,
247 "MIN_CONFIG_TYPE" => \$minconfig_type,
248 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
249 "WARNINGS_FILE" => \$warnings_file,
250 "IGNORE_CONFIG" => \$ignore_config,
251 "TEST" => \$run_test,
252 "ADD_CONFIG" => \$addconfig,
253 "REBOOT_TYPE" => \$reboot_type,
254 "GRUB_MENU" => \$grub_menu,
255 "GRUB_FILE" => \$grub_file,
256 "GRUB_REBOOT" => \$grub_reboot,
257 "SYSLINUX" => \$syslinux,
258 "SYSLINUX_PATH" => \$syslinux_path,
259 "SYSLINUX_LABEL" => \$syslinux_label,
260 "PRE_INSTALL" => \$pre_install,
261 "POST_INSTALL" => \$post_install,
262 "NO_INSTALL" => \$no_install,
263 "REBOOT_SCRIPT" => \$reboot_script,
264 "REBOOT_ON_ERROR" => \$reboot_on_error,
265 "SWITCH_TO_GOOD" => \$switch_to_good,
266 "SWITCH_TO_TEST" => \$switch_to_test,
267 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
268 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
269 "DIE_ON_FAILURE" => \$die_on_failure,
270 "POWER_OFF" => \$power_off,
271 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
272 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
273 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
274 "SLEEP_TIME" => \$sleep_time,
275 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
276 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
277 "IGNORE_WARNINGS" => \$ignore_warnings,
278 "IGNORE_ERRORS" => \$ignore_errors,
279 "BISECT_MANUAL" => \$bisect_manual,
280 "BISECT_SKIP" => \$bisect_skip,
281 "BISECT_TRIES" => \$bisect_tries,
282 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
283 "BISECT_RET_GOOD" => \$bisect_ret_good,
284 "BISECT_RET_BAD" => \$bisect_ret_bad,
285 "BISECT_RET_SKIP" => \$bisect_ret_skip,
286 "BISECT_RET_ABORT" => \$bisect_ret_abort,
287 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
288 "STORE_FAILURES" => \$store_failures,
289 "STORE_SUCCESSES" => \$store_successes,
290 "TEST_NAME" => \$test_name,
291 "TIMEOUT" => \$timeout,
292 "BOOTED_TIMEOUT" => \$booted_timeout,
293 "CONSOLE" => \$console,
294 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
295 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
296 "SUCCESS_LINE" => \$success_line,
297 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
298 "STOP_AFTER_SUCCESS" => \$stop_after_success,
299 "STOP_AFTER_FAILURE" => \$stop_after_failure,
300 "STOP_TEST_AFTER" => \$stop_test_after,
301 "BUILD_TARGET" => \$build_target,
302 "SSH_EXEC" => \$ssh_exec,
303 "SCP_TO_TARGET" => \$scp_to_target,
304 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
305 "CHECKOUT" => \$checkout,
306 "TARGET_IMAGE" => \$target_image,
307 "LOCALVERSION" => \$localversion,
309 "BISECT_GOOD" => \$bisect_good,
310 "BISECT_BAD" => \$bisect_bad,
311 "BISECT_TYPE" => \$bisect_type,
312 "BISECT_START" => \$bisect_start,
313 "BISECT_REPLAY" => \$bisect_replay,
314 "BISECT_FILES" => \$bisect_files,
315 "BISECT_REVERSE" => \$bisect_reverse,
316 "BISECT_CHECK" => \$bisect_check,
318 "CONFIG_BISECT" => \$config_bisect,
319 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
320 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
322 "PATCHCHECK_TYPE" => \$patchcheck_type,
323 "PATCHCHECK_START" => \$patchcheck_start,
324 "PATCHCHECK_CHERRY" => \$patchcheck_cherry,
325 "PATCHCHECK_END" => \$patchcheck_end,
328 # Options may be used by other options, record them.
331 # default variables that can be used
332 chomp ($variable{"PWD"} = `pwd`);
334 $config_help{"MACHINE"} = << "EOF"
335 The machine hostname that you will test.
336 For build only tests, it is still needed to differentiate log files.
339 $config_help{"SSH_USER"} = << "EOF"
340 The box is expected to have ssh on normal bootup, provide the user
341 (most likely root, since you need privileged operations)
344 $config_help{"BUILD_DIR"} = << "EOF"
345 The directory that contains the Linux source code (full path).
346 You can use \${PWD} that will be the path where ktest.pl is run, or use
347 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
350 $config_help{"OUTPUT_DIR"} = << "EOF"
351 The directory that the objects will be built (full path).
352 (can not be same as BUILD_DIR)
353 You can use \${PWD} that will be the path where ktest.pl is run, or use
354 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
357 $config_help{"BUILD_TARGET"} = << "EOF"
358 The location of the compiled file to copy to the target.
359 (relative to OUTPUT_DIR)
362 $config_help{"BUILD_OPTIONS"} = << "EOF"
363 Options to add to \"make\" when building.
367 $config_help{"TARGET_IMAGE"} = << "EOF"
368 The place to put your image on the test machine.
371 $config_help{"POWER_CYCLE"} = << "EOF"
372 A script or command to reboot the box.
374 Here is a digital loggers power switch example
375 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
377 Here is an example to reboot a virtual box on the current host
378 with the name "Guest".
379 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
382 $config_help{"CONSOLE"} = << "EOF"
383 The script or command that reads the console
385 If you use ttywatch server, something like the following would work.
386 CONSOLE = nc -d localhost 3001
388 For a virtual machine with guest name "Guest".
389 CONSOLE = virsh console Guest
392 $config_help{"LOCALVERSION"} = << "EOF"
393 Required version ending to differentiate the test
394 from other linux builds on the system.
397 $config_help{"REBOOT_TYPE"} = << "EOF"
398 Way to reboot the box to the test kernel.
399 Only valid options so far are "grub", "grub2", "syslinux", and "script".
401 If you specify grub, it will assume grub version 1
402 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
403 and select that target to reboot to the kernel. If this is not
404 your setup, then specify "script" and have a command or script
405 specified in REBOOT_SCRIPT to boot to the target.
407 The entry in /boot/grub/menu.lst must be entered in manually.
408 The test will not modify that file.
410 If you specify grub2, then you also need to specify both \$GRUB_MENU
413 If you specify syslinux, then you may use SYSLINUX to define the syslinux
414 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
415 the syslinux install (defaults to /boot/extlinux). But you have to specify
416 SYSLINUX_LABEL to define the label to boot to for the test kernel.
419 $config_help{"GRUB_MENU"} = << "EOF"
420 The grub title name for the test kernel to boot
421 (Only mandatory if REBOOT_TYPE = grub or grub2)
423 Note, ktest.pl will not update the grub menu.lst, you need to
424 manually add an option for the test. ktest.pl will search
425 the grub menu.lst for this option to find what kernel to
428 For example, if in the /boot/grub/menu.lst the test kernel title has:
431 GRUB_MENU = Test Kernel
433 For grub2, a search of \$GRUB_FILE is performed for the lines
434 that begin with "menuentry". It will not detect submenus. The
435 menu must be a non-nested menu. Add the quotes used in the menu
436 to guarantee your selection, as the first menuentry with the content
437 of \$GRUB_MENU that is found will be used.
440 $config_help{"GRUB_FILE"} = << "EOF"
441 If grub2 is used, the full path for the grub.cfg file is placed
442 here. Use something like /boot/grub2/grub.cfg to search.
445 $config_help{"SYSLINUX_LABEL"} = << "EOF"
446 If syslinux is used, the label that boots the target kernel must
447 be specified with SYSLINUX_LABEL.
450 $config_help{"REBOOT_SCRIPT"} = << "EOF"
451 A script to reboot the target into the test kernel
452 (Only mandatory if REBOOT_TYPE = script)
457 if (defined($opt{"LOG_FILE"})) {
458 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
465 if (defined($opt{"LOG_FILE"})) {
478 my ($cancel, $prompt) = @_;
484 print "$prompt [y/n/C] ";
486 print "$prompt [Y/n] ";
490 if ($ans =~ /^\s*$/) {
497 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
499 last if ($ans =~ /^c$/i);
500 print "Please answer either 'y', 'n' or 'c'.\n";
502 print "Please answer either 'y' or 'n'.\n";
508 if ($ans !~ /^y$/i) {
517 return read_prompt 0, $prompt;
523 return read_prompt 1, $prompt;
526 sub get_mandatory_config {
530 return if (defined($opt{$config}));
532 if (defined($config_help{$config})) {
534 print $config_help{$config};
539 if (defined($default{$config}) && length($default{$config})) {
540 print "\[$default{$config}\] ";
543 $ans =~ s/^\s*(.*\S)\s*$/$1/;
544 if ($ans =~ /^\s*$/) {
545 if ($default{$config}) {
546 $ans = $default{$config};
548 print "Your answer can not be blank\n";
552 $entered_configs{$config} = ${ans};
557 sub get_mandatory_configs {
558 get_mandatory_config("MACHINE");
559 get_mandatory_config("BUILD_DIR");
560 get_mandatory_config("OUTPUT_DIR");
563 get_mandatory_config("BUILD_OPTIONS");
566 # options required for other than just building a kernel
568 get_mandatory_config("POWER_CYCLE");
569 get_mandatory_config("CONSOLE");
572 # options required for install and more
573 if ($buildonly != 1) {
574 get_mandatory_config("SSH_USER");
575 get_mandatory_config("BUILD_TARGET");
576 get_mandatory_config("TARGET_IMAGE");
579 get_mandatory_config("LOCALVERSION");
581 return if ($buildonly);
583 my $rtype = $opt{"REBOOT_TYPE"};
585 if (!defined($rtype)) {
586 if (!defined($opt{"GRUB_MENU"})) {
587 get_mandatory_config("REBOOT_TYPE");
588 $rtype = $entered_configs{"REBOOT_TYPE"};
594 if ($rtype eq "grub") {
595 get_mandatory_config("GRUB_MENU");
598 if ($rtype eq "grub2") {
599 get_mandatory_config("GRUB_MENU");
600 get_mandatory_config("GRUB_FILE");
603 if ($rtype eq "syslinux") {
604 get_mandatory_config("SYSLINUX_LABEL");
608 sub process_variables {
609 my ($value, $remove_undef) = @_;
612 # We want to check for '\', and it is just easier
613 # to check the previous characet of '$' and not need
614 # to worry if '$' is the first character. By adding
615 # a space to $value, we can just check [^\\]\$ and
616 # it will still work.
619 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
623 # append beginning of value to retval
624 $retval = "$retval$begin";
625 if (defined($variable{$var})) {
626 $retval = "$retval$variable{$var}";
627 } elsif (defined($remove_undef) && $remove_undef) {
628 # for if statements, any variable that is not defined,
629 # we simple convert to 0
630 $retval = "${retval}0";
632 # put back the origin piece.
633 $retval = "$retval\$\{$var\}";
634 # This could be an option that is used later, save
635 # it so we don't warn if this option is not one of
637 $used_options{$var} = 1;
641 $retval = "$retval$value";
643 # remove the space added in the beginning
650 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
652 my $prvalue = process_variables($rvalue);
654 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
655 # Note if a test is something other than build, then we
656 # will need other manditory options.
657 if ($prvalue ne "install") {
658 # for bisect, we need to check BISECT_TYPE
659 if ($prvalue ne "bisect") {
663 # install still limits some manditory options.
668 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
669 if ($prvalue ne "install") {
672 # install still limits some manditory options.
677 if (defined($opt{$lvalue})) {
678 if (!$override || defined(${$overrides}{$lvalue})) {
681 $extra = "In the same override section!\n";
683 die "$name: $.: Option $lvalue defined more than once!\n$extra";
685 ${$overrides}{$lvalue} = $prvalue;
687 if ($rvalue =~ /^\s*$/) {
688 delete $opt{$lvalue};
690 $opt{$lvalue} = $prvalue;
695 my ($lvalue, $rvalue, $name) = @_;
697 my $prvalue = process_variables($rvalue);
700 if (defined($evals{$lvalue})) {
701 $arr = $evals{$lvalue};
704 $evals{$lvalue} = $arr;
707 push @{$arr}, $rvalue;
711 my ($lvalue, $rvalue) = @_;
713 if ($rvalue =~ /^\s*$/) {
714 delete $variable{$lvalue};
716 $rvalue = process_variables($rvalue);
717 $variable{$lvalue} = $rvalue;
721 sub process_compare {
722 my ($lval, $cmp, $rval) = @_;
733 return $lval eq $rval;
734 } elsif ($cmp eq "!=") {
735 return $lval ne $rval;
736 } elsif ($cmp eq "=~") {
737 return $lval =~ m/$rval/;
738 } elsif ($cmp eq "!~") {
739 return $lval !~ m/$rval/;
742 my $statement = "$lval $cmp $rval";
743 my $ret = eval $statement;
745 # $@ stores error of eval
756 return defined($variable{$2}) ||
761 sub process_expression {
762 my ($name, $val) = @_;
766 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
769 if (process_expression($name, $express)) {
770 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
772 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
780 while ($val =~ s/^(.*?)($OR|$AND)//) {
784 if (process_expression($name, $express)) {
795 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
796 my $ret = process_compare($1, $2, $3);
798 die "$name: $.: Unable to process comparison\n";
803 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
805 return !value_defined($2);
807 return value_defined($2);
811 if ($val =~ /^\s*0\s*$/) {
813 } elsif ($val =~ /^\s*\d+\s*$/) {
817 die ("$name: $.: Undefined content $val in if statement\n");
821 my ($name, $value) = @_;
823 # Convert variables and replace undefined ones with 0
824 my $val = process_variables($value, 1);
825 my $ret = process_expression $name, $val;
831 my ($config, $current_test_num) = @_;
834 open($in, $config) || die "can't read file $config";
837 $name =~ s,.*/(.*),$1,;
839 my $test_num = $$current_test_num;
842 my $num_tests_set = 0;
855 # ignore blank lines and comments
856 next if (/^\s*$/ || /\s*\#/);
858 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
868 if ($type eq "TEST_START") {
870 if ($num_tests_set) {
871 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
874 $old_test_num = $test_num;
875 $old_repeat = $repeat;
877 $test_num += $repeat;
884 # If SKIP is anywhere in the line, the command will be skipped
885 if ($rest =~ s/\s+SKIP\b//) {
892 if ($rest =~ s/\sELSE\b//) {
894 die "$name: $.: ELSE found with out matching IF section\n$_";
905 if ($rest =~ s/\sIF\s+(.*)//) {
906 if (process_if($name, $1)) {
918 if ($type eq "TEST_START") {
919 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
921 $repeat_tests{"$test_num"} = $repeat;
923 } elsif ($rest =~ s/\sOVERRIDE\b//) {
926 # Clear previous overrides
931 if (!$skip && $rest !~ /^\s*$/) {
932 die "$name: $.: Gargbage found after $type\n$_";
935 if ($skip && $type eq "TEST_START") {
936 $test_num = $old_test_num;
937 $repeat = $old_repeat;
940 } elsif (/^\s*ELSE\b(.*)$/) {
942 die "$name: $.: ELSE found with out matching IF section\n$_";
951 if ($rest =~ /\sIF\s+(.*)/) {
952 # May be a ELSE IF section.
953 if (process_if($name, $1)) {
964 if ($rest !~ /^\s*$/) {
965 die "$name: $.: Gargbage found after DEFAULTS\n$_";
968 } elsif (/^\s*INCLUDE\s+(\S+)/) {
973 die "$name: $.: INCLUDE can only be done in default sections\n$_";
976 my $file = process_variables($1);
978 if ($file !~ m,^/,) {
979 # check the path of the config file first
980 if ($config =~ m,(.*)/,) {
988 die "$name: $.: Can't read file $file\n$_";
991 if (__read_config($file, \$test_num)) {
995 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1002 if ($default || $lvalue =~ /\[\d+\]$/) {
1003 set_eval($lvalue, $rvalue, $name);
1005 my $val = "$lvalue\[$test_num\]";
1006 set_eval($val, $rvalue, $name);
1009 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1017 ($lvalue eq "NUM_TESTS" ||
1018 $lvalue eq "LOG_FILE" ||
1019 $lvalue eq "CLEAR_LOG")) {
1020 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
1023 if ($lvalue eq "NUM_TESTS") {
1025 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1028 die "$name: $.: NUM_TESTS must be set in default section\n";
1033 if ($default || $lvalue =~ /\[\d+\]$/) {
1034 set_value($lvalue, $rvalue, $override, \%overrides, $name);
1036 my $val = "$lvalue\[$test_num\]";
1037 set_value($val, $rvalue, $override, \%overrides, $name);
1040 $repeats{$val} = $repeat;
1043 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1049 # process config variables.
1050 # Config variables are only active while reading the
1051 # config and can be defined anywhere. They also ignore
1052 # TEST_START and DEFAULTS, but are skipped if they are in
1053 # on of these sections that have SKIP defined.
1054 # The save variable can be
1055 # defined multiple times and the new one simply overrides
1057 set_variable($lvalue, $rvalue);
1060 die "$name: $.: Garbage found in config\n$_";
1065 $test_num += $repeat - 1;
1066 $opt{"NUM_TESTS"} = $test_num;
1071 $$current_test_num = $test_num;
1077 print "What test case would you like to run?\n";
1078 print " (build, install or boot)\n";
1079 print " Other tests are available but require editing the config file\n";
1082 $default{"TEST_TYPE"} = $ans;
1091 $test_case = __read_config $config, \$test_num;
1093 # make sure we have all mandatory configs
1094 get_mandatory_configs;
1096 # was a test specified?
1098 print "No test case specified.\n";
1104 foreach my $default (keys %default) {
1105 if (!defined($opt{$default})) {
1106 $opt{$default} = $default{$default};
1110 if ($opt{"IGNORE_UNUSED"} == 1) {
1116 # check if there are any stragglers (typos?)
1117 foreach my $option (keys %opt) {
1119 # remove per test labels.
1121 if (!exists($option_map{$op}) &&
1122 !exists($default{$op}) &&
1123 !exists($used_options{$op})) {
1130 $s = " is" if (keys %not_used == 1);
1131 print "The following option$s not used; could be a typo:\n";
1132 foreach my $option (keys %not_used) {
1135 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1136 if (!read_yn "Do you want to continue?") {
1143 my ($name, $option, $i) = @_;
1145 # Add space to evaluate the character before $
1146 $option = " $option";
1151 foreach my $test (keys %repeat_tests) {
1153 $i < $test + $repeat_tests{$test}) {
1161 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1166 # Append beginning of line
1167 $retval = "$retval$start";
1169 # If the iteration option OPT[$i] exists, then use that.
1170 # otherwise see if the default OPT (without [$i]) exists.
1172 my $o = "$var\[$i\]";
1173 my $parento = "$var\[$parent\]";
1175 # If a variable contains itself, use the default var
1176 if (($var eq $name) && defined($opt{$var})) {
1178 $retval = "$retval$o";
1179 } elsif (defined($opt{$o})) {
1181 $retval = "$retval$o";
1182 } elsif ($repeated && defined($opt{$parento})) {
1183 $o = $opt{$parento};
1184 $retval = "$retval$o";
1185 } elsif (defined($opt{$var})) {
1187 $retval = "$retval$o";
1188 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1189 # special option KERNEL_VERSION uses kernel version
1191 $retval = "$retval$version";
1193 $retval = "$retval\$\{$var\}";
1199 $retval = "$retval$option";
1207 my ($name, $option, $i) = @_;
1209 my $option_name = "$name\[$i\]";
1212 my $old_option = $option;
1214 if (defined($evals{$option_name})) {
1215 $ev = $evals{$option_name};
1216 } elsif (defined($evals{$name})) {
1217 $ev = $evals{$name};
1222 for my $e (@{$ev}) {
1223 eval "\$option =~ $e";
1226 if ($option ne $old_option) {
1227 doprint("$name changed from '$old_option' to '$option'\n");
1234 my ($name, $option, $i) = @_;
1238 # Since an option can evaluate to another option,
1239 # keep iterating until we do not evaluate any more
1242 while ($prev ne $option) {
1243 # Check for recursive evaluations.
1244 # 100 deep should be more than enough.
1246 die "Over 100 evaluations accurred with $option\n" .
1247 "Check for recursive variables\n";
1250 $option = __eval_option($name, $option, $i);
1253 $option = process_evals($name, $option, $i);
1261 sub wait_for_monitor;
1266 # Make sure everything has been written to disk
1269 if (defined($time)) {
1271 # flush out current monitor
1272 # May contain the reboot success line
1276 # try to reboot normally
1277 if (run_command $reboot) {
1278 if (defined($powercycle_after_reboot)) {
1279 sleep $powercycle_after_reboot;
1280 run_command "$power_cycle";
1283 # nope? power cycle it.
1284 run_command "$power_cycle";
1287 if (defined($time)) {
1289 # We only want to get to the new kernel, don't fail
1290 # if we stumble over a call trace.
1291 my $save_ignore_errors = $ignore_errors;
1294 # Look for the good kernel to boot
1295 if (wait_for_monitor($time, "Linux version")) {
1297 doprint "Reboot did not finish. Forcing power cycle\n";
1298 run_command "$power_cycle";
1301 $ignore_errors = $save_ignore_errors;
1303 # Still need to wait for the reboot to finish
1304 wait_for_monitor($time, $reboot_success_line);
1310 sub reboot_to_good {
1313 if (defined($switch_to_good)) {
1314 run_command $switch_to_good;
1323 return $test_type eq "build" || $no_reboot ||
1324 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1325 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1329 doprint "CRITICAL FAILURE... ", @_, "\n";
1333 if ($reboot_on_error && !do_not_reboot) {
1335 doprint "REBOOTING\n";
1338 } elsif ($poweroff_on_error && defined($power_off)) {
1339 doprint "POWERING OFF\n";
1343 if (defined($opt{"LOG_FILE"})) {
1344 print " See $opt{LOG_FILE} for more info.\n";
1355 my $pid = open($fp, "$console|") or
1356 dodie "Can't open console $console";
1358 $flags = fcntl($fp, F_GETFL, 0) or
1359 dodie "Can't get flags for the socket: $!";
1360 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1361 dodie "Can't set flags for the socket: $!";
1367 my ($fp, $pid) = @_;
1369 doprint "kill child process $pid\n";
1370 kill $close_console_signal, $pid;
1377 if ($monitor_cnt++) {
1380 $monitor_fp = \*MONFD;
1381 $monitor_pid = open_console $monitor_fp;
1385 open(MONFD, "Stop perl from warning about single use of MONFD");
1389 return if (!defined $console);
1390 if (--$monitor_cnt) {
1393 close_console($monitor_fp, $monitor_pid);
1396 sub wait_for_monitor {
1397 my ($time, $stop) = @_;
1401 my $start_time = time;
1402 my $skip_call_trace = 0;
1404 my $bug_ignored = 0;
1407 doprint "** Wait for monitor to settle down **\n";
1409 # read the monitor and wait for the system to calm down
1411 $line = wait_for_input($monitor_fp, $time);
1412 last if (!defined($line));
1414 $full_line .= $line;
1416 if (defined($stop) && $full_line =~ /$stop/) {
1417 doprint "wait for monitor detected $stop\n";
1421 if ($full_line =~ /\[ backtrace testing \]/) {
1422 $skip_call_trace = 1;
1425 if ($full_line =~ /call trace:/i) {
1426 if (!$bug && !$skip_call_trace) {
1427 if ($ignore_errors) {
1435 if ($full_line =~ /\[ end of backtrace testing \]/) {
1436 $skip_call_trace = 0;
1439 if ($full_line =~ /Kernel panic -/) {
1443 if ($line =~ /\n/) {
1447 if ($now - $start_time >= $max_monitor_wait) {
1448 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1452 print "** Monitor flushed **\n";
1454 # if stop is defined but wasn't hit, return error
1455 # used by reboot (which wants to see a reboot)
1456 if (defined($stop) && !$booted) {
1463 my ($result, $basedir) = @_;
1465 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1466 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1468 my $type = $build_type;
1469 if ($type =~ /useconfig/) {
1470 $type = "useconfig";
1473 my $dir = "$machine-$test_type-$type-$result-$date";
1475 $dir = "$basedir/$dir";
1479 die "can't create $dir";
1483 "config" => $output_config,
1484 "buildlog" => $buildlog,
1486 "testlog" => $testlog,
1489 while (my ($name, $source) = each(%files)) {
1491 cp "$source", "$dir/$name" or
1492 die "failed to copy $source";
1496 doprint "*** Saved info to $dir ***\n";
1501 if (defined($post_test)) {
1502 run_command $post_test;
1505 if ($die_on_failure) {
1513 # no need to reboot for just building.
1514 if (!do_not_reboot) {
1515 doprint "REBOOTING\n";
1516 reboot_to_good $sleep_time;
1521 if (defined($test_name)) {
1522 $name = " ($test_name)";
1525 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1526 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1527 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1528 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1529 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1531 if (defined($store_failures)) {
1532 save_logs "fail", $store_failures;
1539 my ($command, $redirect) = @_;
1544 $command =~ s/\$SSH_USER/$ssh_user/g;
1545 $command =~ s/\$MACHINE/$machine/g;
1547 doprint("$command ... ");
1549 $pid = open(CMD, "$command 2>&1 |") or
1550 (fail "unable to exec $command" and return 0);
1552 if (defined($opt{"LOG_FILE"})) {
1553 open(LOG, ">>$opt{LOG_FILE}") or
1554 dodie "failed to write to log";
1558 if (defined($redirect)) {
1559 open (RD, ">$redirect") or
1560 dodie "failed to write to redirect $redirect";
1565 print LOG if ($dolog);
1566 print RD if ($dord);
1573 close(LOG) if ($dolog);
1574 close(RD) if ($dord);
1577 doprint "FAILED!\n";
1579 doprint "SUCCESS\n";
1587 my $cp_exec = $ssh_exec;
1589 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1590 return run_command "$cp_exec";
1594 my ($src, $dst, $cp_scp) = @_;
1596 $cp_scp =~ s/\$SRC_FILE/$src/g;
1597 $cp_scp =~ s/\$DST_FILE/$dst/g;
1599 return run_command "$cp_scp";
1602 sub run_scp_install {
1603 my ($src, $dst) = @_;
1605 my $cp_scp = $scp_to_target_install;
1607 return run_scp($src, $dst, $cp_scp);
1611 my ($src, $dst) = @_;
1613 my $cp_scp = $scp_to_target;
1615 return run_scp($src, $dst, $cp_scp);
1618 sub get_grub2_index {
1620 return if (defined($grub_number) && defined($last_grub_menu) &&
1621 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1622 $last_machine eq $machine);
1624 doprint "Find grub2 menu ... ";
1627 my $ssh_grub = $ssh_exec;
1628 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1630 open(IN, "$ssh_grub |")
1631 or die "unable to get $grub_file";
1636 if (/^menuentry.*$grub_menu/) {
1640 } elsif (/^menuentry\s/) {
1646 die "Could not find '$grub_menu' in $grub_file on $machine"
1648 doprint "$grub_number\n";
1649 $last_grub_menu = $grub_menu;
1650 $last_machine = $machine;
1653 sub get_grub_index {
1655 if ($reboot_type eq "grub2") {
1660 if ($reboot_type ne "grub") {
1663 return if (defined($grub_number) && defined($last_grub_menu) &&
1664 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1665 $last_machine eq $machine);
1667 doprint "Find grub menu ... ";
1670 my $ssh_grub = $ssh_exec;
1671 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1673 open(IN, "$ssh_grub |")
1674 or die "unable to get menu.lst";
1679 if (/^\s*title\s+$grub_menu\s*$/) {
1683 } elsif (/^\s*title\s/) {
1689 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1691 doprint "$grub_number\n";
1692 $last_grub_menu = $grub_menu;
1693 $last_machine = $machine;
1698 my ($fp, $time) = @_;
1704 if (!defined($time)) {
1709 vec($rin, fileno($fp), 1) = 1;
1710 ($ready, $time) = select($rin, undef, undef, $time);
1714 # try to read one char at a time
1715 while (sysread $fp, $ch, 1) {
1717 last if ($ch eq "\n");
1720 if (!length($line)) {
1728 if (defined($switch_to_test)) {
1729 run_command $switch_to_test;
1732 if ($reboot_type eq "grub") {
1733 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1734 } elsif ($reboot_type eq "grub2") {
1735 run_ssh "$grub_reboot $grub_number";
1736 } elsif ($reboot_type eq "syslinux") {
1737 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
1738 } elsif (defined $reboot_script) {
1739 run_command "$reboot_script";
1747 doprint "git rev-list --max-count=1 $commit ... ";
1748 my $sha1 = `git rev-list --max-count=1 $commit`;
1755 dodie "Failed to get git $commit";
1768 my $bug_ignored = 0;
1769 my $skip_call_trace = 0;
1777 open(DMESG, "> $dmesg") or
1778 die "unable to write to $dmesg";
1784 my $monitor_start = time;
1786 my $version_found = 0;
1790 if ($bug && defined($stop_after_failure) &&
1791 $stop_after_failure >= 0) {
1792 my $time = $stop_after_failure - (time - $failure_start);
1793 $line = wait_for_input($monitor_fp, $time);
1794 if (!defined($line)) {
1795 doprint "bug timed out after $booted_timeout seconds\n";
1796 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1800 $line = wait_for_input($monitor_fp, $booted_timeout);
1801 if (!defined($line)) {
1802 my $s = $booted_timeout == 1 ? "" : "s";
1803 doprint "Successful boot found: break after $booted_timeout second$s\n";
1807 $line = wait_for_input($monitor_fp);
1808 if (!defined($line)) {
1809 my $s = $timeout == 1 ? "" : "s";
1810 doprint "Timed out after $timeout second$s\n";
1818 # we are not guaranteed to get a full line
1819 $full_line .= $line;
1821 if ($full_line =~ /$success_line/) {
1823 $success_start = time;
1826 if ($booted && defined($stop_after_success) &&
1827 $stop_after_success >= 0) {
1829 if ($now - $success_start >= $stop_after_success) {
1830 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1835 if ($full_line =~ /\[ backtrace testing \]/) {
1836 $skip_call_trace = 1;
1839 if ($full_line =~ /call trace:/i) {
1840 if (!$bug && !$skip_call_trace) {
1841 if ($ignore_errors) {
1845 $failure_start = time;
1850 if ($bug && defined($stop_after_failure) &&
1851 $stop_after_failure >= 0) {
1853 if ($now - $failure_start >= $stop_after_failure) {
1854 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1859 if ($full_line =~ /\[ end of backtrace testing \]/) {
1860 $skip_call_trace = 0;
1863 if ($full_line =~ /Kernel panic -/) {
1864 $failure_start = time;
1868 # Detect triple faults by testing the banner
1869 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1870 if ($1 eq $version) {
1872 } elsif ($version_found && $detect_triplefault) {
1873 # We already booted into the kernel we are testing,
1874 # but now we booted into another kernel?
1875 # Consider this a triple fault.
1876 doprint "Already booted in Linux kernel $version, but now\n";
1877 doprint "we booted into Linux kernel $1.\n";
1878 doprint "Assuming that this is a triple fault.\n";
1879 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1884 if ($line =~ /\n/) {
1888 if ($stop_test_after > 0 && !$booted && !$bug) {
1889 if (time - $monitor_start > $stop_test_after) {
1890 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1899 return 0 if ($in_bisect);
1900 fail "failed - got a bug report" and return 0;
1904 return 0 if ($in_bisect);
1905 fail "failed - never got a boot prompt." and return 0;
1909 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1915 sub eval_kernel_version {
1918 $option =~ s/\$KERNEL_VERSION/$version/g;
1923 sub do_post_install {
1925 return if (!defined($post_install));
1927 my $cp_post_install = eval_kernel_version $post_install;
1928 run_command "$cp_post_install" or
1929 dodie "Failed to run post install";
1932 # Sometimes the reboot fails, and will hang. We try to ssh to the box
1933 # and if we fail, we force another reboot, that should powercycle it.
1935 if (!run_ssh "echo testing connection") {
1942 return if ($no_install);
1944 if (defined($pre_install)) {
1945 my $cp_pre_install = eval_kernel_version $pre_install;
1946 run_command "$cp_pre_install" or
1947 dodie "Failed to run pre install";
1950 my $cp_target = eval_kernel_version $target_image;
1954 run_scp_install "$outputdir/$build_target", "$cp_target" or
1955 dodie "failed to copy image";
1957 my $install_mods = 0;
1959 # should we process modules?
1961 open(IN, "$output_config") or dodie("Can't read config file");
1963 if (/CONFIG_MODULES(=y)?/) {
1972 if (!$install_mods) {
1974 doprint "No modules needed\n";
1978 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1979 dodie "Failed to install modules";
1981 my $modlib = "/lib/modules/$version";
1982 my $modtar = "ktest-mods.tar.bz2";
1984 run_ssh "rm -rf $modlib" or
1985 dodie "failed to remove old mods: $modlib";
1987 # would be nice if scp -r did not follow symbolic links
1988 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1989 dodie "making tarball";
1991 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1992 dodie "failed to copy modules";
1994 unlink "$tmpdir/$modtar";
1996 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1997 dodie "failed to tar modules";
1999 run_ssh "rm -f /tmp/$modtar";
2005 # get the release name
2006 return if ($have_version);
2007 doprint "$make kernelrelease ... ";
2008 $version = `$make kernelrelease | tail -1`;
2010 doprint "$version\n";
2014 sub start_monitor_and_boot {
2015 # Make sure the stable kernel has finished booting
2017 # Install bisects, don't need console
2018 if (defined $console) {
2028 start_monitor if (defined $console);
2032 my $check_build_re = ".*:.*(warning|error|Error):.*";
2033 my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2035 sub process_warning_line {
2040 # for distcc heterogeneous systems, some compilers
2041 # do things differently causing warning lines
2042 # to be slightly different. This makes an attempt
2043 # to fixe those issues.
2045 # chop off the index into the line
2046 # using distcc, some compilers give different indexes
2047 # depending on white space
2048 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2050 # Some compilers use UTF-8 extended for quotes and some don't.
2051 $line =~ s/$utf8_quote/'/g;
2056 # Read buildlog and check against warnings file for any
2061 sub check_buildlog {
2062 return 1 if (!defined $warnings_file);
2066 # Failed builds should not reboot the target
2067 my $save_no_reboot = $no_reboot;
2070 if (-f $warnings_file) {
2071 open(IN, $warnings_file) or
2072 dodie "Error opening $warnings_file";
2075 if (/$check_build_re/) {
2076 my $warning = process_warning_line $_;
2078 $warnings_list{$warning} = 1;
2084 # If warnings file didn't exist, and WARNINGS_FILE exist,
2085 # then we fail on any warning!
2087 open(IN, $buildlog) or dodie "Can't open $buildlog";
2089 if (/$check_build_re/) {
2090 my $warning = process_warning_line $_;
2092 if (!defined $warnings_list{$warning}) {
2093 fail "New warning found (not in $warnings_file)\n$_\n";
2094 $no_reboot = $save_no_reboot;
2099 $no_reboot = $save_no_reboot;
2103 sub check_patch_buildlog {
2106 my @files = `git show $patch | diffstat -l`;
2108 foreach my $file (@files) {
2112 open(IN, "git show $patch |") or
2113 dodie "failed to show $patch";
2115 if (m,^--- a/(.*),) {
2117 $files[$#files] = $1;
2122 open(IN, $buildlog) or dodie "Can't open $buildlog";
2124 if (/^\s*(.*?):.*(warning|error)/) {
2126 foreach my $file (@files) {
2127 my $fullpath = "$builddir/$file";
2128 if ($file eq $err || $fullpath eq $err) {
2129 fail "$file built with warnings" and return 0;
2139 sub apply_min_config {
2140 my $outconfig = "$output_config.new";
2142 # Read the config file and remove anything that
2143 # is in the force_config hash (from minconfig and others)
2144 # then add the force config back.
2146 doprint "Applying minimum configurations into $output_config.new\n";
2148 open (OUT, ">$outconfig") or
2149 dodie "Can't create $outconfig";
2151 if (-f $output_config) {
2152 open (IN, $output_config) or
2153 dodie "Failed to open $output_config";
2155 if (/^(# )?(CONFIG_[^\s=]*)/) {
2156 next if (defined($force_config{$2}));
2162 foreach my $config (keys %force_config) {
2163 print OUT "$force_config{$config}\n";
2167 run_command "mv $outconfig $output_config";
2170 sub make_oldconfig {
2172 my @force_list = keys %force_config;
2174 if ($#force_list >= 0) {
2178 if (!run_command "$make olddefconfig") {
2179 # Perhaps olddefconfig doesn't exist in this version of the kernel
2181 doprint "olddefconfig failed, trying make oldnoconfig\n";
2182 if (!run_command "$make oldnoconfig") {
2183 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2184 # try a yes '' | oldconfig
2185 run_command "yes '' | $make oldconfig" or
2186 dodie "failed make config oldconfig";
2191 # read a config file and use this to force new configs.
2192 sub load_force_config {
2195 doprint "Loading force configs from $config\n";
2196 open(IN, $config) or
2197 dodie "failed to read $config";
2200 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2201 $force_config{$1} = $_;
2202 } elsif (/^# (CONFIG_\S*) is not set/) {
2203 $force_config{$1} = $_;
2214 # Failed builds should not reboot the target
2215 my $save_no_reboot = $no_reboot;
2218 # Calculate a new version from here.
2221 if (defined($pre_build)) {
2222 my $ret = run_command $pre_build;
2223 if (!$ret && defined($pre_build_die) &&
2225 dodie "failed to pre_build\n";
2229 if ($type =~ /^useconfig:(.*)/) {
2230 run_command "cp $1 $output_config" or
2231 dodie "could not copy $1 to .config";
2233 $type = "oldconfig";
2236 # old config can ask questions
2237 if ($type eq "oldconfig") {
2238 $type = "olddefconfig";
2240 # allow for empty configs
2241 run_command "touch $output_config";
2244 run_command "mv $output_config $outputdir/config_temp" or
2245 dodie "moving .config";
2247 run_command "$make mrproper" or dodie "make mrproper";
2249 run_command "mv $outputdir/config_temp $output_config" or
2250 dodie "moving config_temp";
2253 } elsif (!$noclean) {
2254 unlink "$output_config";
2255 run_command "$make mrproper" or
2256 dodie "make mrproper";
2259 # add something to distinguish this build
2260 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2261 print OUT "$localversion\n";
2264 if (defined($minconfig)) {
2265 load_force_config($minconfig);
2268 if ($type ne "olddefconfig") {
2269 run_command "$make $type" or
2270 dodie "failed make config";
2272 # Run old config regardless, to enforce min configurations
2275 my $build_ret = run_command "$make $build_options", $buildlog;
2277 if (defined($post_build)) {
2278 # Because a post build may change the kernel version
2281 my $ret = run_command $post_build;
2282 if (!$ret && defined($post_build_die) &&
2284 dodie "failed to post_build\n";
2289 # bisect may need this to pass
2291 $no_reboot = $save_no_reboot;
2294 fail "failed build" and return 0;
2297 $no_reboot = $save_no_reboot;
2303 if (!run_ssh "halt" or defined($power_off)) {
2304 if (defined($poweroff_after_halt)) {
2305 sleep $poweroff_after_halt;
2306 run_command "$power_off";
2310 run_command "$power_off";
2317 if (defined($post_test)) {
2318 run_command $post_test;
2325 if (defined($test_name)) {
2326 $name = " ($test_name)";
2329 doprint "\n\n*******************************************\n";
2330 doprint "*******************************************\n";
2331 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2332 doprint "*******************************************\n";
2333 doprint "*******************************************\n";
2335 if (defined($store_successes)) {
2336 save_logs "success", $store_successes;
2339 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2340 doprint "Reboot and wait $sleep_time seconds\n";
2341 reboot_to_good $sleep_time;
2347 doprint "Pass, fail, or skip? [p/f/s]";
2350 if ($ans eq "p" || $ans eq "P") {
2352 } elsif ($ans eq "f" || $ans eq "F") {
2354 } elsif ($ans eq "s" || $ans eq "S") {
2357 print "Please answer 'p', 'f', or 's'\n";
2362 sub child_run_test {
2365 # child should have no power
2366 $reboot_on_error = 0;
2367 $poweroff_on_error = 0;
2368 $die_on_failure = 1;
2370 run_command $run_test, $testlog or $failed = 1;
2377 sub child_finished {
2387 my $bug_ignored = 0;
2391 doprint "run test $run_test\n";
2395 $SIG{CHLD} = qw(child_finished);
2399 child_run_test if (!$child_pid);
2404 $line = wait_for_input($monitor_fp, 1);
2405 if (defined($line)) {
2407 # we are not guaranteed to get a full line
2408 $full_line .= $line;
2411 if ($full_line =~ /call trace:/i) {
2412 if ($ignore_errors) {
2419 if ($full_line =~ /Kernel panic -/) {
2423 if ($line =~ /\n/) {
2427 } while (!$child_done && !$bug);
2429 if (!$bug && $bug_ignored) {
2430 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2434 my $failure_start = time;
2437 $line = wait_for_input($monitor_fp, 1);
2438 if (defined($line)) {
2442 if ($now - $failure_start >= $stop_after_failure) {
2445 } while (defined($line));
2447 doprint "Detected kernel crash!\n";
2448 # kill the child with extreme prejudice
2452 waitpid $child_pid, 0;
2455 if (!$bug && $in_bisect) {
2456 if (defined($bisect_ret_good)) {
2457 if ($child_exit == $bisect_ret_good) {
2461 if (defined($bisect_ret_skip)) {
2462 if ($child_exit == $bisect_ret_skip) {
2466 if (defined($bisect_ret_abort)) {
2467 if ($child_exit == $bisect_ret_abort) {
2468 fail "test abort" and return -2;
2471 if (defined($bisect_ret_bad)) {
2472 if ($child_exit == $bisect_ret_skip) {
2476 if (defined($bisect_ret_default)) {
2477 if ($bisect_ret_default eq "good") {
2479 } elsif ($bisect_ret_default eq "bad") {
2481 } elsif ($bisect_ret_default eq "skip") {
2483 } elsif ($bisect_ret_default eq "abort") {
2486 fail "unknown default action: $bisect_ret_default"
2492 if ($bug || $child_exit) {
2493 return 0 if $in_bisect;
2494 fail "test failed" and return 0;
2499 sub run_git_bisect {
2502 doprint "$command ... ";
2504 my $output = `$command 2>&1`;
2511 dodie "Failed to git bisect";
2514 doprint "SUCCESS\n";
2515 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2516 doprint "$1 [$2]\n";
2517 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2518 $bisect_bad_commit = $1;
2519 doprint "Found bad commit... $1\n";
2522 # we already logged it, just print it now.
2530 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2531 reboot_to_good $bisect_sleep_time;
2534 # returns 1 on success, 0 on failure, -1 on skip
2535 sub run_bisect_test {
2536 my ($type, $buildtype) = @_;
2545 build $buildtype or $failed = 1;
2547 if ($type ne "build") {
2548 if ($failed && $bisect_skip) {
2552 dodie "Failed on build" if $failed;
2555 start_monitor_and_boot or $failed = 1;
2557 if ($type ne "boot") {
2558 if ($failed && $bisect_skip) {
2564 dodie "Failed on boot" if $failed;
2566 do_run_test or $failed = 1;
2577 # reboot the box to a kernel we can ssh to
2578 if ($type ne "build") {
2588 my $buildtype = "oldconfig";
2590 # We should have a minconfig to use?
2591 if (defined($minconfig)) {
2592 $buildtype = "useconfig:$minconfig";
2595 # If the user sets bisect_tries to less than 1, then no tries
2599 # Still let the user manually decide that though.
2600 if ($bisect_tries < 1 && $bisect_manual) {
2601 $ret = answer_bisect;
2604 for (my $i = 0; $i < $bisect_tries; $i++) {
2605 if ($bisect_tries > 1) {
2607 doprint("Running bisect trial $t of $bisect_tries:\n");
2609 $ret = run_bisect_test $type, $buildtype;
2611 if ($bisect_manual) {
2612 $ret = answer_bisect;
2618 # Are we looking for where it worked, not failed?
2619 if ($reverse_bisect && $ret >= 0) {
2625 } elsif ($ret == 0) {
2627 } elsif ($bisect_skip) {
2628 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2633 sub update_bisect_replay {
2634 my $tmp_log = "$tmpdir/ktest_bisect_log";
2635 run_command "git bisect log > $tmp_log" or
2636 die "can't create bisect log";
2645 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2646 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2647 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2649 my $good = $bisect_good;
2650 my $bad = $bisect_bad;
2651 my $type = $bisect_type;
2652 my $start = $bisect_start;
2653 my $replay = $bisect_replay;
2654 my $start_files = $bisect_files;
2656 if (defined($start_files)) {
2657 $start_files = " -- " . $start_files;
2662 # convert to true sha1's
2663 $good = get_sha1($good);
2664 $bad = get_sha1($bad);
2666 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2667 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2668 $reverse_bisect = 1;
2670 $reverse_bisect = 0;
2673 # Can't have a test without having a test to run
2674 if ($type eq "test" && !defined($run_test)) {
2678 # Check if a bisect was running
2679 my $bisect_start_file = "$builddir/.git/BISECT_START";
2681 my $check = $bisect_check;
2682 my $do_check = defined($check) && $check ne "0";
2684 if ( -f $bisect_start_file ) {
2685 print "Bisect in progress found\n";
2687 print " If you say yes, then no checks of good or bad will be done\n";
2689 if (defined($replay)) {
2690 print "** BISECT_REPLAY is defined in config file **";
2691 print " Ignore config option and perform new git bisect log?\n";
2692 if (read_ync " (yes, no, or cancel) ") {
2693 $replay = update_bisect_replay;
2696 } elsif (read_yn "read git log and continue?") {
2697 $replay = update_bisect_replay;
2705 my $head = get_sha1("HEAD");
2707 if ($check ne "good") {
2708 doprint "TESTING BISECT BAD [$bad]\n";
2709 run_command "git checkout $bad" or
2710 die "Failed to checkout $bad";
2712 $result = run_bisect $type;
2714 if ($result ne "bad") {
2715 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2719 if ($check ne "bad") {
2720 doprint "TESTING BISECT GOOD [$good]\n";
2721 run_command "git checkout $good" or
2722 die "Failed to checkout $good";
2724 $result = run_bisect $type;
2726 if ($result ne "good") {
2727 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2731 # checkout where we started
2732 run_command "git checkout $head" or
2733 die "Failed to checkout $head";
2736 run_command "git bisect start$start_files" or
2737 dodie "could not start bisect";
2739 if (defined($replay)) {
2740 run_command "git bisect replay $replay" or
2741 dodie "failed to run replay";
2744 run_command "git bisect good $good" or
2745 dodie "could not set bisect good to $good";
2747 run_git_bisect "git bisect bad $bad" or
2748 dodie "could not set bisect bad to $bad";
2752 if (defined($start)) {
2753 run_command "git checkout $start" or
2754 dodie "failed to checkout $start";
2759 $result = run_bisect $type;
2760 $test = run_git_bisect "git bisect $result";
2763 run_command "git bisect log" or
2764 dodie "could not capture git bisect log";
2766 run_command "git bisect reset" or
2767 dodie "could not reset git bisect";
2769 doprint "Bad commit was [$bisect_bad_commit]\n";
2774 # config_ignore holds the configs that were set (or unset) for
2775 # a good config and we will ignore these configs for the rest
2776 # of a config bisect. These configs stay as they were.
2779 # config_set holds what all configs were set as.
2782 # config_off holds the set of configs that the bad config had disabled.
2783 # We need to record them and set them in the .config when running
2784 # olddefconfig, because olddefconfig keeps the defaults.
2787 # config_off_tmp holds a set of configs to turn off for now
2790 # config_list is the set of configs that are being tested
2796 sub assign_configs {
2797 my ($hash, $config) = @_;
2799 doprint "Reading configs from $config\n";
2802 or dodie "Failed to read $config";
2806 if (/^((CONFIG\S*)=.*)/) {
2808 } elsif (/^(# (CONFIG\S*) is not set)/) {
2816 sub process_config_ignore {
2819 assign_configs \%config_ignore, $config;
2822 sub get_dependencies {
2825 my $arr = $dependency{$config};
2826 if (!defined($arr)) {
2832 foreach my $dep (@{$arr}) {
2833 print "ADD DEP $dep\n";
2834 @deps = (@deps, get_dependencies $dep);
2841 my ($pc, $file) = @_;
2843 my %configs = %{$pc};
2845 doprint "Saving configs into $file\n";
2847 open(OUT, ">$file") or dodie "Can not write to $file";
2849 foreach my $config (keys %configs) {
2850 print OUT "$configs{$config}\n";
2856 my ($name, $pc) = @_;
2858 doprint "Creating old config from $name configs\n";
2860 save_config $pc, $output_config;
2865 # compare two config hashes, and return configs with different vals.
2866 # It returns B's config values, but you can use A to see what A was.
2867 sub diff_config_vals {
2870 # crappy Perl way to pass in hashes.
2876 foreach my $item (keys %a) {
2877 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2878 $ret{$item} = $b{$item};
2885 # compare two config hashes and return the configs in B but not A
2891 # crappy Perl way to pass in hashes.
2895 foreach my $item (keys %b) {
2896 if (!defined($a{$item})) {
2897 $ret{$item} = $b{$item};
2904 # return if two configs are equal or not
2905 # 0 is equal +1 b has something a does not
2906 # +1 if a and b have a different item.
2907 # -1 if a has something b does not
2908 sub compare_configs {
2913 # crappy Perl way to pass in hashes.
2917 foreach my $item (keys %b) {
2918 if (!defined($a{$item})) {
2921 if ($a{$item} ne $b{$item}) {
2926 foreach my $item (keys %a) {
2927 if (!defined($b{$item})) {
2935 sub run_config_bisect_test {
2938 my $ret = run_bisect_test $type, "oldconfig";
2940 if ($bisect_manual) {
2941 $ret = answer_bisect;
2947 sub process_failed {
2950 doprint "\n\n***************************************\n";
2951 doprint "Found bad config: $config\n";
2952 doprint "***************************************\n\n";
2955 # used for config bisecting
2959 sub process_new_config {
2960 my ($tc, $nc, $gc, $bc) = @_;
2962 my %tmp_config = %{$tc};
2963 my %good_configs = %{$gc};
2964 my %bad_configs = %{$bc};
2971 create_config "tmp_configs", \%tmp_config;
2972 assign_configs \%new_configs, $output_config;
2974 $ret = compare_configs \%new_configs, \%bad_configs;
2976 doprint "New config equals bad config, try next test\n";
2981 $ret = compare_configs \%new_configs, \%good_configs;
2983 doprint "New config equals good config, try next test\n";
2988 %{$nc} = %new_configs;
2993 sub run_config_bisect {
2994 my ($pgood, $pbad) = @_;
2996 my $type = $config_bisect_type;
2998 my %good_configs = %{$pgood};
2999 my %bad_configs = %{$pbad};
3001 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
3002 my %b_configs = diff_configs \%good_configs, \%bad_configs;
3003 my %g_configs = diff_configs \%bad_configs, \%good_configs;
3005 my @diff_arr = keys %diff_configs;
3006 my $len_diff = $#diff_arr + 1;
3008 my @b_arr = keys %b_configs;
3009 my $len_b = $#b_arr + 1;
3011 my @g_arr = keys %g_configs;
3012 my $len_g = $#g_arr + 1;
3018 # First, lets get it down to a single subset.
3019 # Is the problem with a difference in values?
3020 # Is the problem with a missing config?
3021 # Is the problem with a config that breaks things?
3023 # Enable all of one set and see if we get a new bad
3026 # first set the good config to the bad values.
3028 doprint "d=$len_diff g=$len_g b=$len_b\n";
3030 # first lets enable things in bad config that are enabled in good config
3032 if ($len_diff > 0) {
3033 if ($len_b > 0 || $len_g > 0) {
3034 my %tmp_config = %bad_configs;
3036 doprint "Set tmp config to be bad config with good config values\n";
3037 foreach my $item (@diff_arr) {
3038 $tmp_config{$item} = $good_configs{$item};
3041 $runtest = process_new_config \%tmp_config, \%new_configs,
3042 \%good_configs, \%bad_configs;
3046 if (!$runtest && $len_diff > 0) {
3048 if ($len_diff == 1) {
3049 process_failed $diff_arr[0];
3052 my %tmp_config = %bad_configs;
3054 my $half = int($#diff_arr / 2);
3055 my @tophalf = @diff_arr[0 .. $half];
3057 doprint "Settings bisect with top half:\n";
3058 doprint "Set tmp config to be bad config with some good config values\n";
3059 foreach my $item (@tophalf) {
3060 $tmp_config{$item} = $good_configs{$item};
3063 $runtest = process_new_config \%tmp_config, \%new_configs,
3064 \%good_configs, \%bad_configs;
3067 my %tmp_config = %bad_configs;
3069 doprint "Try bottom half\n";
3071 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3073 foreach my $item (@bottomhalf) {
3074 $tmp_config{$item} = $good_configs{$item};
3077 $runtest = process_new_config \%tmp_config, \%new_configs,
3078 \%good_configs, \%bad_configs;
3083 $ret = run_config_bisect_test $type;
3085 doprint "NEW GOOD CONFIG\n";
3086 %good_configs = %new_configs;
3087 run_command "mv $good_config ${good_config}.last";
3088 save_config \%good_configs, $good_config;
3089 %{$pgood} = %good_configs;
3091 doprint "NEW BAD CONFIG\n";
3092 %bad_configs = %new_configs;
3093 run_command "mv $bad_config ${bad_config}.last";
3094 save_config \%bad_configs, $bad_config;
3095 %{$pbad} = %bad_configs;
3100 fail "Hmm, need to do a mix match?\n";
3107 my $type = $config_bisect_type;
3110 $bad_config = $config_bisect;
3112 if (defined($config_bisect_good)) {
3113 $good_config = $config_bisect_good;
3114 } elsif (defined($minconfig)) {
3115 $good_config = $minconfig;
3117 doprint "No config specified, checking if defconfig works";
3118 $ret = run_bisect_test $type, "defconfig";
3120 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3123 $good_config = $output_config;
3126 # we don't want min configs to cause issues here.
3127 doprint "Disabling 'MIN_CONFIG' for this test\n";
3134 doprint "Run good configs through make oldconfig\n";
3135 assign_configs \%tmp_configs, $good_config;
3136 create_config "$good_config", \%tmp_configs;
3137 assign_configs \%good_configs, $output_config;
3139 doprint "Run bad configs through make oldconfig\n";
3140 assign_configs \%tmp_configs, $bad_config;
3141 create_config "$bad_config", \%tmp_configs;
3142 assign_configs \%bad_configs, $output_config;
3144 $good_config = "$tmpdir/good_config";
3145 $bad_config = "$tmpdir/bad_config";
3147 save_config \%good_configs, $good_config;
3148 save_config \%bad_configs, $bad_config;
3151 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3152 if ($config_bisect_check ne "good") {
3153 doprint "Testing bad config\n";
3155 $ret = run_bisect_test $type, "useconfig:$bad_config";
3157 fail "Bad config succeeded when expected to fail!";
3161 if ($config_bisect_check ne "bad") {
3162 doprint "Testing good config\n";
3164 $ret = run_bisect_test $type, "useconfig:$good_config";
3166 fail "Good config failed when expected to succeed!";
3173 $ret = run_config_bisect \%good_configs, \%bad_configs;
3176 return $ret if ($ret < 0);
3181 sub patchcheck_reboot {
3182 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
3183 reboot_to_good $patchcheck_sleep_time;
3189 die "PATCHCHECK_START[$i] not defined\n"
3190 if (!defined($patchcheck_start));
3191 die "PATCHCHECK_TYPE[$i] not defined\n"
3192 if (!defined($patchcheck_type));
3194 my $start = $patchcheck_start;
3196 my $cherry = $patchcheck_cherry;
3197 if (!defined($cherry)) {
3202 if (defined($patchcheck_end)) {
3203 $end = $patchcheck_end;
3205 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
3208 # Get the true sha1's since we can use things like HEAD~3
3209 $start = get_sha1($start);
3210 $end = get_sha1($end);
3212 my $type = $patchcheck_type;
3214 # Can't have a test without having a test to run
3215 if ($type eq "test" && !defined($run_test)) {
3220 open (IN, "git cherry -v $start $end|") or
3221 dodie "could not get git list";
3223 open (IN, "git log --pretty=oneline $end|") or
3224 dodie "could not get git list";
3231 # git cherry adds a '+' we want to remove
3233 $list[$#list+1] = $_;
3234 last if (/^$start/);
3239 if ($list[$#list] !~ /^$start/) {
3240 fail "SHA1 $start not found";
3243 # go backwards in the list
3244 @list = reverse @list;
3247 doprint("Going to test the following commits:\n");
3248 foreach my $l (@list) {
3252 my $save_clean = $noclean;
3253 my %ignored_warnings;
3255 if (defined($ignore_warnings)) {
3256 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3257 $ignored_warnings{$sha1} = 1;
3262 foreach my $item (@list) {
3264 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3266 doprint "\nProcessing commit $item\n\n";
3268 run_command "git checkout $sha1" or
3269 die "Failed to checkout $sha1";
3271 # only clean on the first and last patch
3272 if ($item eq $list[0] ||
3273 $item eq $list[$#list]) {
3274 $noclean = $save_clean;
3279 if (defined($minconfig)) {
3280 build "useconfig:$minconfig" or return 0;
3282 # ?? no config to use?
3283 build "oldconfig" or return 0;
3286 # No need to do per patch checking if warnings file exists
3287 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3288 check_patch_buildlog $sha1 or return 0;
3291 check_buildlog or return 0;
3293 next if ($type eq "build");
3297 start_monitor_and_boot or $failed = 1;
3299 if (!$failed && $type ne "boot"){
3300 do_run_test or $failed = 1;
3303 return 0 if ($failed);
3323 # $config depends on $dep
3324 my ($config, $dep) = @_;
3326 if (defined($depends{$config})) {
3327 $depends{$config} .= " " . $dep;
3329 $depends{$config} = $dep;
3332 # record the number of configs depending on $dep
3333 if (defined $depcount{$dep}) {
3336 $depcount{$dep} = 1;
3340 # taken from streamline_config.pl
3352 if (! -f $kconfig) {
3353 doprint "file $kconfig does not exist, skipping\n";
3357 open(KIN, "$kconfig")
3358 or die "Can't open $kconfig";
3362 # Make sure that lines ending with \ continue
3364 $_ = $line . " " . $_;
3375 # collect any Kconfig sources
3376 if (/^source\s*"(.*)"/) {
3377 $kconfigs[$#kconfigs+1] = $1;
3381 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3385 for (my $i = 0; $i < $iflevel; $i++) {
3386 add_dep $config, $ifdeps[$i];
3389 # collect the depends for the config
3390 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3392 add_dep $config, $1;
3394 # Get the configs that select this config
3395 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3397 # selected by depends on config
3398 add_dep $1, $config;
3400 # Check for if statements
3401 } elsif (/^if\s+(.*\S)\s*$/) {
3403 # remove beginning and ending non text
3404 $deps =~ s/^[^a-zA-Z0-9_]*//;
3405 $deps =~ s/[^a-zA-Z0-9_]*$//;
3407 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3409 $ifdeps[$iflevel++] = join ':', @deps;
3411 } elsif (/^endif/) {
3413 $iflevel-- if ($iflevel);
3416 } elsif (/^\s*help\s*$/) {
3422 # read in any configs that were found.
3423 foreach $kconfig (@kconfigs) {
3424 if (!defined($read_kconfigs{$kconfig})) {
3425 $read_kconfigs{$kconfig} = 1;
3426 read_kconfig("$builddir/$kconfig");
3432 # find out which arch this is by the kconfig file
3433 open (IN, $output_config)
3434 or dodie "Failed to read $output_config";
3437 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3444 if (!defined($arch)) {
3445 doprint "Could not find arch from config file\n";
3446 doprint "no dependencies used\n";
3450 # arch is really the subarch, we need to know
3451 # what directory to look at.
3452 if ($arch eq "i386" || $arch eq "x86_64") {
3454 } elsif ($arch =~ /^tile/) {
3458 my $kconfig = "$builddir/arch/$arch/Kconfig";
3460 if (! -f $kconfig && $arch =~ /\d$/) {
3462 # some subarchs have numbers, truncate them
3464 $kconfig = "$builddir/arch/$arch/Kconfig";
3465 if (! -f $kconfig) {
3466 doprint "No idea what arch dir $orig is for\n";
3467 doprint "no dependencies used\n";
3472 read_kconfig($kconfig);
3475 sub make_new_config {
3478 open (OUT, ">$output_config")
3479 or dodie "Failed to write $output_config";
3481 foreach my $config (@configs) {
3482 print OUT "$config\n";
3490 $config =~ s/CONFIG_//;
3498 my $kconfig = chomp_config $dep;
3500 $dep = $depends{"$kconfig"};
3502 # the dep string we have saves the dependencies as they
3503 # were found, including expressions like ! && ||. We
3504 # want to split this out into just an array of configs.
3506 my $valid = "A-Za-z_0-9";
3510 while ($dep =~ /[$valid]/) {
3512 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3513 my $conf = "CONFIG_" . $1;
3515 $configs[$#configs + 1] = $conf;
3517 $dep =~ s/^[^$valid]*[$valid]+//;
3519 die "this should never happen";
3529 my %processed_configs;
3530 my %nochange_config;
3532 sub test_this_config {
3537 # if we already processed this config, skip it
3538 if (defined($processed_configs{$config})) {
3541 $processed_configs{$config} = 1;
3543 # if this config failed during this round, skip it
3544 if (defined($nochange_config{$config})) {
3548 my $kconfig = chomp_config $config;
3550 # Test dependencies first
3551 if (defined($depends{"$kconfig"})) {
3552 my @parents = get_depends $config;
3553 foreach my $parent (@parents) {
3554 # if the parent is in the min config, check it first
3555 next if (!defined($min_configs{$parent}));
3556 $found = test_this_config($parent);
3557 if (defined($found)) {
3563 # Remove this config from the list of configs
3564 # do a make olddefconfig and then read the resulting
3565 # .config to make sure it is missing the config that
3567 my %configs = %min_configs;
3568 delete $configs{$config};
3569 make_new_config ((values %configs), (values %keep_configs));
3572 assign_configs \%configs, $output_config;
3574 return $config if (!defined($configs{$config}));
3576 doprint "disabling config $config did not change .config\n";
3578 $nochange_config{$config} = 1;
3583 sub make_min_config {
3586 my $type = $minconfig_type;
3587 if ($type ne "boot" && $type ne "test") {
3588 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3589 " make_min_config works only with 'boot' and 'test'\n" and return;
3592 if (!defined($output_minconfig)) {
3593 fail "OUTPUT_MIN_CONFIG not defined" and return;
3596 # If output_minconfig exists, and the start_minconfig
3597 # came from min_config, than ask if we should use
3599 if (-f $output_minconfig && !$start_minconfig_defined) {
3600 print "$output_minconfig exists\n";
3601 if (!defined($use_output_minconfig)) {
3602 if (read_yn " Use it as minconfig?") {
3603 $start_minconfig = $output_minconfig;
3605 } elsif ($use_output_minconfig > 0) {
3606 doprint "Using $output_minconfig as MIN_CONFIG\n";
3607 $start_minconfig = $output_minconfig;
3609 doprint "Set to still use MIN_CONFIG as starting point\n";
3613 if (!defined($start_minconfig)) {
3614 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3617 my $temp_config = "$tmpdir/temp_config";
3619 # First things first. We build an allnoconfig to find
3620 # out what the defaults are that we can't touch.
3621 # Some are selections, but we really can't handle selections.
3623 my $save_minconfig = $minconfig;
3626 run_command "$make allnoconfig" or return 0;
3630 process_config_ignore $output_config;
3632 undef %save_configs;
3635 if (defined($ignore_config)) {
3636 # make sure the file exists
3637 `touch $ignore_config`;
3638 assign_configs \%save_configs, $ignore_config;
3641 %keep_configs = %save_configs;
3643 doprint "Load initial configs from $start_minconfig\n";
3645 # Look at the current min configs, and save off all the
3646 # ones that were set via the allnoconfig
3647 assign_configs \%min_configs, $start_minconfig;
3649 my @config_keys = keys %min_configs;
3651 # All configs need a depcount
3652 foreach my $config (@config_keys) {
3653 my $kconfig = chomp_config $config;
3654 if (!defined $depcount{$kconfig}) {
3655 $depcount{$kconfig} = 0;
3659 # Remove anything that was set by the make allnoconfig
3660 # we shouldn't need them as they get set for us anyway.
3661 foreach my $config (@config_keys) {
3662 # Remove anything in the ignore_config
3663 if (defined($keep_configs{$config})) {
3664 my $file = $ignore_config;
3665 $file =~ s,.*/(.*?)$,$1,;
3666 doprint "$config set by $file ... ignored\n";
3667 delete $min_configs{$config};
3670 # But make sure the settings are the same. If a min config
3671 # sets a selection, we do not want to get rid of it if
3672 # it is not the same as what we have. Just move it into
3674 if (defined($config_ignore{$config})) {
3675 if ($config_ignore{$config} ne $min_configs{$config}) {
3676 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3677 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3678 $keep_configs{$config} = $min_configs{$config};
3680 doprint "$config set by allnoconfig ... ignored\n";
3682 delete $min_configs{$config};
3694 # Now disable each config one by one and do a make oldconfig
3695 # till we find a config that changes our list.
3697 my @test_configs = keys %min_configs;
3699 # Sort keys by who is most dependent on
3700 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3703 # Put configs that did not modify the config at the end.
3705 for (my $i = 0; $i < $#test_configs; $i++) {
3706 if (!defined($nochange_config{$test_configs[0]})) {
3710 # This config didn't change the .config last time.
3711 # Place it at the end
3712 my $config = shift @test_configs;
3713 push @test_configs, $config;
3716 # if every test config has failed to modify the .config file
3717 # in the past, then reset and start over.
3719 undef %nochange_config;
3722 undef %processed_configs;
3724 foreach my $config (@test_configs) {
3726 $found = test_this_config $config;
3728 last if (defined($found));
3730 # oh well, try another config
3733 if (!defined($found)) {
3734 # we could have failed due to the nochange_config hash
3735 # reset and try again
3737 undef %nochange_config;
3741 doprint "No more configs found that we can disable\n";
3749 doprint "Test with $config disabled\n";
3751 # set in_bisect to keep build and monitor from dieing
3755 build "oldconfig" or $failed = 1;
3757 start_monitor_and_boot or $failed = 1;
3759 if ($type eq "test" && !$failed) {
3760 do_run_test or $failed = 1;
3769 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3770 # this config is needed, add it to the ignore list.
3771 $keep_configs{$config} = $min_configs{$config};
3772 $save_configs{$config} = $min_configs{$config};
3773 delete $min_configs{$config};
3775 # update new ignore configs
3776 if (defined($ignore_config)) {
3777 open (OUT, ">$temp_config")
3778 or die "Can't write to $temp_config";
3779 foreach my $config (keys %save_configs) {
3780 print OUT "$save_configs{$config}\n";
3783 run_command "mv $temp_config $ignore_config" or
3784 dodie "failed to copy update to $ignore_config";
3788 # We booted without this config, remove it from the minconfigs.
3789 doprint "$config is not needed, disabling\n";
3791 delete $min_configs{$config};
3793 # Also disable anything that is not enabled in this config
3795 assign_configs \%configs, $output_config;
3796 my @config_keys = keys %min_configs;
3797 foreach my $config (@config_keys) {
3798 if (!defined($configs{$config})) {
3799 doprint "$config is not set, disabling\n";
3800 delete $min_configs{$config};
3804 # Save off all the current mandidory configs
3805 open (OUT, ">$temp_config")
3806 or die "Can't write to $temp_config";
3807 foreach my $config (keys %keep_configs) {
3808 print OUT "$keep_configs{$config}\n";
3810 foreach my $config (keys %min_configs) {
3811 print OUT "$min_configs{$config}\n";
3815 run_command "mv $temp_config $output_minconfig" or
3816 dodie "failed to copy update to $output_minconfig";
3819 doprint "Reboot and wait $sleep_time seconds\n";
3820 reboot_to_good $sleep_time;
3827 sub make_warnings_file {
3830 if (!defined($warnings_file)) {
3831 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3834 if ($build_type eq "nobuild") {
3835 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3838 build $build_type or dodie "Failed to build";
3840 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3842 open(IN, $buildlog) or dodie "Can't open $buildlog";
3845 # Some compilers use UTF-8 extended for quotes
3846 # for distcc heterogeneous systems, this causes issues
3849 if (/$check_build_re/) {
3860 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
3863 $ktest_config = $ARGV[0];
3864 if (! -f $ktest_config) {
3865 print "$ktest_config does not exist.\n";
3866 if (!read_yn "Create it?") {
3872 if (! -f $ktest_config) {
3875 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3877 # Generated by ktest.pl
3880 # PWD is a ktest.pl variable that will result in the process working
3881 # directory that ktest.pl is executed in.
3883 # THIS_DIR is automatically assigned the PWD of the path that generated
3884 # the config file. It is best to use this variable when assigning other
3885 # directory paths within this directory. This allows you to easily
3886 # move the test cases to other locations or to other machines.
3888 THIS_DIR := $variable{"PWD"}
3890 # Define each test with TEST_START
3891 # The config options below it will override the defaults
3893 TEST_TYPE = $default{"TEST_TYPE"}
3900 read_config $ktest_config;
3902 if (defined($opt{"LOG_FILE"})) {
3903 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
3906 # Append any configs entered in manually to the config file.
3907 my @new_configs = keys %entered_configs;
3908 if ($#new_configs >= 0) {
3909 print "\nAppending entered in configs to $ktest_config\n";
3910 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3911 foreach my $config (@new_configs) {
3912 print OUT "$config = $entered_configs{$config}\n";
3913 $opt{$config} = process_variables($entered_configs{$config});
3917 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3918 unlink $opt{"LOG_FILE"};
3921 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3923 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3926 doprint "DEFAULT OPTIONS:\n";
3928 doprint "\nTEST $i OPTIONS";
3929 if (defined($repeat_tests{$i})) {
3930 $repeat = $repeat_tests{$i};
3931 doprint " ITERATE $repeat";
3936 foreach my $option (sort keys %opt) {
3938 if ($option =~ /\[(\d+)\]$/) {
3944 doprint "$option = $opt{$option}\n";
3948 sub __set_test_option {
3949 my ($name, $i) = @_;
3951 my $option = "$name\[$i\]";
3953 if (defined($opt{$option})) {
3954 return $opt{$option};
3957 foreach my $test (keys %repeat_tests) {
3959 $i < $test + $repeat_tests{$test}) {
3960 $option = "$name\[$test\]";
3961 if (defined($opt{$option})) {
3962 return $opt{$option};
3967 if (defined($opt{$name})) {
3974 sub set_test_option {
3975 my ($name, $i) = @_;
3977 my $option = __set_test_option($name, $i);
3978 return $option if (!defined($option));
3980 return eval_option($name, $option, $i);
3983 # First we need to do is the builds
3984 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3986 # Do not reboot on failing test options
3988 $reboot_success = 0;
3994 undef %force_config;
3996 my $makecmd = set_test_option("MAKE_CMD", $i);
3998 $outputdir = set_test_option("OUTPUT_DIR", $i);
3999 $builddir = set_test_option("BUILD_DIR", $i);
4001 chdir $builddir || die "can't change directory to $builddir";
4003 if (!-d $outputdir) {
4004 mkpath($outputdir) or
4005 die "can't create $outputdir";
4008 $make = "$makecmd O=$outputdir";
4010 # Load all the options into their mapped variable names
4011 foreach my $opt (keys %option_map) {
4012 ${$option_map{$opt}} = set_test_option($opt, $i);
4015 $start_minconfig_defined = 1;
4017 # The first test may override the PRE_KTEST option
4018 if (defined($pre_ktest) && $i == 1) {
4020 run_command $pre_ktest;
4023 # Any test can override the POST_KTEST option
4024 # The last test takes precedence.
4025 if (defined($post_ktest)) {
4026 $final_post_ktest = $post_ktest;
4029 if (!defined($start_minconfig)) {
4030 $start_minconfig_defined = 0;
4031 $start_minconfig = $minconfig;
4036 die "can't create $tmpdir";
4039 $ENV{"SSH_USER"} = $ssh_user;
4040 $ENV{"MACHINE"} = $machine;
4042 $buildlog = "$tmpdir/buildlog-$machine";
4043 $testlog = "$tmpdir/testlog-$machine";
4044 $dmesg = "$tmpdir/dmesg-$machine";
4045 $output_config = "$outputdir/.config";
4048 $target = "$ssh_user\@$machine";
4049 if ($reboot_type eq "grub") {
4050 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4051 } elsif ($reboot_type eq "grub2") {
4052 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4053 dodie "GRUB_FILE not defined" if (!defined($grub_file));
4054 } elsif ($reboot_type eq "syslinux") {
4055 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
4059 my $run_type = $build_type;
4060 if ($test_type eq "patchcheck") {
4061 $run_type = $patchcheck_type;
4062 } elsif ($test_type eq "bisect") {
4063 $run_type = $bisect_type;
4064 } elsif ($test_type eq "config_bisect") {
4065 $run_type = $config_bisect_type;
4066 } elsif ($test_type eq "make_min_config") {
4068 } elsif ($test_type eq "make_warnings_file") {
4072 # mistake in config file?
4073 if (!defined($run_type)) {
4074 $run_type = "ERROR";
4078 $installme = " no_install" if ($no_install);
4081 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
4083 if (defined($pre_test)) {
4084 run_command $pre_test;
4091 if (defined($addconfig)) {
4092 my $min = $minconfig;
4093 if (!defined($minconfig)) {
4096 run_command "cat $addconfig $min > $tmpdir/add_config" or
4097 dodie "Failed to create temp config";
4098 $minconfig = "$tmpdir/add_config";
4101 if (defined($checkout)) {
4102 run_command "git checkout $checkout" or
4103 die "failed to checkout $checkout";
4108 # A test may opt to not reboot the box
4109 if ($reboot_on_success) {
4110 $reboot_success = 1;
4113 if ($test_type eq "bisect") {
4116 } elsif ($test_type eq "config_bisect") {
4119 } elsif ($test_type eq "patchcheck") {
4122 } elsif ($test_type eq "make_min_config") {
4125 } elsif ($test_type eq "make_warnings_file") {
4127 make_warnings_file $i;
4131 if ($build_type ne "nobuild") {
4132 build $build_type or next;
4133 check_buildlog or next;
4136 if ($test_type eq "install") {
4143 if ($test_type ne "build") {
4145 start_monitor_and_boot or $failed = 1;
4147 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4148 do_run_test or $failed = 1;
4157 if (defined($final_post_ktest)) {
4158 run_command $final_post_ktest;
4161 if ($opt{"POWEROFF_ON_SUCCESS"}) {
4163 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
4165 } elsif (defined($switch_to_good)) {
4166 # still need to get to the good kernel
4167 run_command $switch_to_good;
4171 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";