3 # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4 # Licensed under the terms of the GNU GPL License version 2
9 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
10 use File::Path qw(mkpath);
11 use File::Copy qw(cp);
25 "TEST_TYPE" => "build",
26 "BUILD_TYPE" => "randconfig",
29 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
30 "SLEEP_TIME" => 60, # sleep time between tests
32 "REBOOT_ON_ERROR" => 0,
33 "POWEROFF_ON_ERROR" => 0,
34 "REBOOT_ON_SUCCESS" => 1,
35 "POWEROFF_ON_SUCCESS" => 0,
36 "BUILD_OPTIONS" => "",
37 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
38 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
42 "MIN_CONFIG_TYPE" => "boot",
43 "SUCCESS_LINE" => "login:",
44 "DETECT_TRIPLE_FAULT" => 1,
46 "BOOTED_TIMEOUT" => 1,
47 "DIE_ON_FAILURE" => 1,
48 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
49 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
50 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
51 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
52 "STOP_AFTER_SUCCESS" => 10,
53 "STOP_AFTER_FAILURE" => 60,
54 "STOP_TEST_AFTER" => 600,
55 "MAX_MONITOR_WAIT" => 1800,
56 "GRUB_REBOOT" => "grub2-reboot",
58 # required, and we will ask users if they don't have them but we keep the default
59 # value something that is common.
60 "REBOOT_TYPE" => "grub",
61 "LOCALVERSION" => "-test",
63 "BUILD_TARGET" => "arch/x86/boot/bzImage",
64 "TARGET_IMAGE" => "/boot/vmlinuz-test",
98 my $poweroff_on_error;
99 my $reboot_on_success;
101 my $powercycle_after_reboot;
102 my $poweroff_after_halt;
103 my $max_monitor_wait;
106 my $scp_to_target_install;
120 my $start_minconfig_defined;
121 my $output_minconfig;
123 my $use_output_minconfig;
128 my $bisect_bad_commit = "";
132 my $config_bisect_good;
136 my $bisect_ret_abort;
137 my $bisect_ret_default;
138 my $in_patchcheck = 0;
148 my $bisect_sleep_time;
149 my $patchcheck_sleep_time;
156 my $detect_triplefault;
158 my $reboot_success_line;
160 my $stop_after_success;
161 my $stop_after_failure;
180 my $config_bisect_type;
181 my $config_bisect_check;
184 my $patchcheck_start;
187 # set when a test is something other that just building or install
188 # which would require more options.
191 # set when creating a new config
198 # force_config is the list of configs that we force enabled (or disabled)
199 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
202 # do not force reboots on config problems
206 my $reboot_success = 0;
209 "MACHINE" => \$machine,
210 "SSH_USER" => \$ssh_user,
211 "TMP_DIR" => \$tmpdir,
212 "OUTPUT_DIR" => \$outputdir,
213 "BUILD_DIR" => \$builddir,
214 "TEST_TYPE" => \$test_type,
215 "PRE_KTEST" => \$pre_ktest,
216 "POST_KTEST" => \$post_ktest,
217 "PRE_TEST" => \$pre_test,
218 "POST_TEST" => \$post_test,
219 "BUILD_TYPE" => \$build_type,
220 "BUILD_OPTIONS" => \$build_options,
221 "PRE_BUILD" => \$pre_build,
222 "POST_BUILD" => \$post_build,
223 "PRE_BUILD_DIE" => \$pre_build_die,
224 "POST_BUILD_DIE" => \$post_build_die,
225 "POWER_CYCLE" => \$power_cycle,
226 "REBOOT" => \$reboot,
227 "BUILD_NOCLEAN" => \$noclean,
228 "MIN_CONFIG" => \$minconfig,
229 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
230 "START_MIN_CONFIG" => \$start_minconfig,
231 "MIN_CONFIG_TYPE" => \$minconfig_type,
232 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
233 "IGNORE_CONFIG" => \$ignore_config,
234 "TEST" => \$run_test,
235 "ADD_CONFIG" => \$addconfig,
236 "REBOOT_TYPE" => \$reboot_type,
237 "GRUB_MENU" => \$grub_menu,
238 "GRUB_FILE" => \$grub_file,
239 "GRUB_REBOOT" => \$grub_reboot,
240 "PRE_INSTALL" => \$pre_install,
241 "POST_INSTALL" => \$post_install,
242 "NO_INSTALL" => \$no_install,
243 "REBOOT_SCRIPT" => \$reboot_script,
244 "REBOOT_ON_ERROR" => \$reboot_on_error,
245 "SWITCH_TO_GOOD" => \$switch_to_good,
246 "SWITCH_TO_TEST" => \$switch_to_test,
247 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
248 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
249 "DIE_ON_FAILURE" => \$die_on_failure,
250 "POWER_OFF" => \$power_off,
251 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
252 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
253 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
254 "SLEEP_TIME" => \$sleep_time,
255 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
256 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
257 "IGNORE_WARNINGS" => \$ignore_warnings,
258 "IGNORE_ERRORS" => \$ignore_errors,
259 "BISECT_MANUAL" => \$bisect_manual,
260 "BISECT_SKIP" => \$bisect_skip,
261 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
262 "BISECT_RET_GOOD" => \$bisect_ret_good,
263 "BISECT_RET_BAD" => \$bisect_ret_bad,
264 "BISECT_RET_SKIP" => \$bisect_ret_skip,
265 "BISECT_RET_ABORT" => \$bisect_ret_abort,
266 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
267 "STORE_FAILURES" => \$store_failures,
268 "STORE_SUCCESSES" => \$store_successes,
269 "TEST_NAME" => \$test_name,
270 "TIMEOUT" => \$timeout,
271 "BOOTED_TIMEOUT" => \$booted_timeout,
272 "CONSOLE" => \$console,
273 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
274 "SUCCESS_LINE" => \$success_line,
275 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
276 "STOP_AFTER_SUCCESS" => \$stop_after_success,
277 "STOP_AFTER_FAILURE" => \$stop_after_failure,
278 "STOP_TEST_AFTER" => \$stop_test_after,
279 "BUILD_TARGET" => \$build_target,
280 "SSH_EXEC" => \$ssh_exec,
281 "SCP_TO_TARGET" => \$scp_to_target,
282 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
283 "CHECKOUT" => \$checkout,
284 "TARGET_IMAGE" => \$target_image,
285 "LOCALVERSION" => \$localversion,
287 "BISECT_GOOD" => \$bisect_good,
288 "BISECT_BAD" => \$bisect_bad,
289 "BISECT_TYPE" => \$bisect_type,
290 "BISECT_START" => \$bisect_start,
291 "BISECT_REPLAY" => \$bisect_replay,
292 "BISECT_FILES" => \$bisect_files,
293 "BISECT_REVERSE" => \$bisect_reverse,
294 "BISECT_CHECK" => \$bisect_check,
296 "CONFIG_BISECT" => \$config_bisect,
297 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
298 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
300 "PATCHCHECK_TYPE" => \$patchcheck_type,
301 "PATCHCHECK_START" => \$patchcheck_start,
302 "PATCHCHECK_END" => \$patchcheck_end,
305 # Options may be used by other options, record them.
308 # default variables that can be used
309 chomp ($variable{"PWD"} = `pwd`);
311 $config_help{"MACHINE"} = << "EOF"
312 The machine hostname that you will test.
313 For build only tests, it is still needed to differentiate log files.
316 $config_help{"SSH_USER"} = << "EOF"
317 The box is expected to have ssh on normal bootup, provide the user
318 (most likely root, since you need privileged operations)
321 $config_help{"BUILD_DIR"} = << "EOF"
322 The directory that contains the Linux source code (full path).
323 You can use \${PWD} that will be the path where ktest.pl is run, or use
324 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
327 $config_help{"OUTPUT_DIR"} = << "EOF"
328 The directory that the objects will be built (full path).
329 (can not be same as BUILD_DIR)
330 You can use \${PWD} that will be the path where ktest.pl is run, or use
331 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
334 $config_help{"BUILD_TARGET"} = << "EOF"
335 The location of the compiled file to copy to the target.
336 (relative to OUTPUT_DIR)
339 $config_help{"BUILD_OPTIONS"} = << "EOF"
340 Options to add to \"make\" when building.
344 $config_help{"TARGET_IMAGE"} = << "EOF"
345 The place to put your image on the test machine.
348 $config_help{"POWER_CYCLE"} = << "EOF"
349 A script or command to reboot the box.
351 Here is a digital loggers power switch example
352 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
354 Here is an example to reboot a virtual box on the current host
355 with the name "Guest".
356 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
359 $config_help{"CONSOLE"} = << "EOF"
360 The script or command that reads the console
362 If you use ttywatch server, something like the following would work.
363 CONSOLE = nc -d localhost 3001
365 For a virtual machine with guest name "Guest".
366 CONSOLE = virsh console Guest
369 $config_help{"LOCALVERSION"} = << "EOF"
370 Required version ending to differentiate the test
371 from other linux builds on the system.
374 $config_help{"REBOOT_TYPE"} = << "EOF"
375 Way to reboot the box to the test kernel.
376 Only valid options so far are "grub", "grub2", and "script".
378 If you specify grub, it will assume grub version 1
379 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
380 and select that target to reboot to the kernel. If this is not
381 your setup, then specify "script" and have a command or script
382 specified in REBOOT_SCRIPT to boot to the target.
384 The entry in /boot/grub/menu.lst must be entered in manually.
385 The test will not modify that file.
387 If you specify grub2, then you also need to specify both \$GRUB_MENU
391 $config_help{"GRUB_MENU"} = << "EOF"
392 The grub title name for the test kernel to boot
393 (Only mandatory if REBOOT_TYPE = grub or grub2)
395 Note, ktest.pl will not update the grub menu.lst, you need to
396 manually add an option for the test. ktest.pl will search
397 the grub menu.lst for this option to find what kernel to
400 For example, if in the /boot/grub/menu.lst the test kernel title has:
403 GRUB_MENU = Test Kernel
405 For grub2, a search of \$GRUB_FILE is performed for the lines
406 that begin with "menuentry". It will not detect submenus. The
407 menu must be a non-nested menu. Add the quotes used in the menu
408 to guarantee your selection, as the first menuentry with the content
409 of \$GRUB_MENU that is found will be used.
412 $config_help{"GRUB_FILE"} = << "EOF"
413 If grub2 is used, the full path for the grub.cfg file is placed
414 here. Use something like /boot/grub2/grub.cfg to search.
417 $config_help{"REBOOT_SCRIPT"} = << "EOF"
418 A script to reboot the target into the test kernel
419 (Only mandatory if REBOOT_TYPE = script)
424 my ($cancel, $prompt) = @_;
430 print "$prompt [y/n/C] ";
432 print "$prompt [Y/n] ";
436 if ($ans =~ /^\s*$/) {
443 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
445 last if ($ans =~ /^c$/i);
446 print "Please answer either 'y', 'n' or 'c'.\n";
448 print "Please answer either 'y' or 'n'.\n";
454 if ($ans !~ /^y$/i) {
463 return read_prompt 0, $prompt;
469 return read_prompt 1, $prompt;
472 sub get_ktest_config {
476 return if (defined($opt{$config}));
478 if (defined($config_help{$config})) {
480 print $config_help{$config};
485 if (defined($default{$config}) && length($default{$config})) {
486 print "\[$default{$config}\] ";
489 $ans =~ s/^\s*(.*\S)\s*$/$1/;
490 if ($ans =~ /^\s*$/) {
491 if ($default{$config}) {
492 $ans = $default{$config};
494 print "Your answer can not be blank\n";
498 $entered_configs{$config} = ${ans};
503 sub get_ktest_configs {
504 get_ktest_config("MACHINE");
505 get_ktest_config("BUILD_DIR");
506 get_ktest_config("OUTPUT_DIR");
509 get_ktest_config("BUILD_OPTIONS");
512 # options required for other than just building a kernel
514 get_ktest_config("POWER_CYCLE");
515 get_ktest_config("CONSOLE");
518 # options required for install and more
519 if ($buildonly != 1) {
520 get_ktest_config("SSH_USER");
521 get_ktest_config("BUILD_TARGET");
522 get_ktest_config("TARGET_IMAGE");
525 get_ktest_config("LOCALVERSION");
527 return if ($buildonly);
529 my $rtype = $opt{"REBOOT_TYPE"};
531 if (!defined($rtype)) {
532 if (!defined($opt{"GRUB_MENU"})) {
533 get_ktest_config("REBOOT_TYPE");
534 $rtype = $entered_configs{"REBOOT_TYPE"};
540 if ($rtype eq "grub") {
541 get_ktest_config("GRUB_MENU");
544 if ($rtype eq "grub2") {
545 get_ktest_config("GRUB_MENU");
546 get_ktest_config("GRUB_FILE");
550 sub process_variables {
551 my ($value, $remove_undef) = @_;
554 # We want to check for '\', and it is just easier
555 # to check the previous characet of '$' and not need
556 # to worry if '$' is the first character. By adding
557 # a space to $value, we can just check [^\\]\$ and
558 # it will still work.
561 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
565 # append beginning of value to retval
566 $retval = "$retval$begin";
567 if (defined($variable{$var})) {
568 $retval = "$retval$variable{$var}";
569 } elsif (defined($remove_undef) && $remove_undef) {
570 # for if statements, any variable that is not defined,
571 # we simple convert to 0
572 $retval = "${retval}0";
574 # put back the origin piece.
575 $retval = "$retval\$\{$var\}";
576 # This could be an option that is used later, save
577 # it so we don't warn if this option is not one of
579 $used_options{$var} = 1;
583 $retval = "$retval$value";
585 # remove the space added in the beginning
592 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
594 my $prvalue = process_variables($rvalue);
596 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
597 # Note if a test is something other than build, then we
598 # will need other manditory options.
599 if ($prvalue ne "install") {
602 # install still limits some manditory options.
607 if (defined($opt{$lvalue})) {
608 if (!$override || defined(${$overrides}{$lvalue})) {
611 $extra = "In the same override section!\n";
613 die "$name: $.: Option $lvalue defined more than once!\n$extra";
615 ${$overrides}{$lvalue} = $prvalue;
617 if ($rvalue =~ /^\s*$/) {
618 delete $opt{$lvalue};
620 $opt{$lvalue} = $prvalue;
625 my ($lvalue, $rvalue) = @_;
627 if ($rvalue =~ /^\s*$/) {
628 delete $variable{$lvalue};
630 $rvalue = process_variables($rvalue);
631 $variable{$lvalue} = $rvalue;
635 sub process_compare {
636 my ($lval, $cmp, $rval) = @_;
647 return $lval eq $rval;
648 } elsif ($cmp eq "!=") {
649 return $lval ne $rval;
650 } elsif ($cmp eq "=~") {
651 return $lval =~ m/$rval/;
652 } elsif ($cmp eq "!~") {
653 return $lval !~ m/$rval/;
656 my $statement = "$lval $cmp $rval";
657 my $ret = eval $statement;
659 # $@ stores error of eval
670 return defined($variable{$2}) ||
675 sub process_expression {
676 my ($name, $val) = @_;
680 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
683 if (process_expression($name, $express)) {
684 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
686 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
694 while ($val =~ s/^(.*?)($OR|$AND)//) {
698 if (process_expression($name, $express)) {
709 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
710 my $ret = process_compare($1, $2, $3);
712 die "$name: $.: Unable to process comparison\n";
717 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
719 return !value_defined($2);
721 return value_defined($2);
725 if ($val =~ /^\s*0\s*$/) {
727 } elsif ($val =~ /^\s*\d+\s*$/) {
731 die ("$name: $.: Undefined content $val in if statement\n");
735 my ($name, $value) = @_;
737 # Convert variables and replace undefined ones with 0
738 my $val = process_variables($value, 1);
739 my $ret = process_expression $name, $val;
745 my ($config, $current_test_num) = @_;
748 open($in, $config) || die "can't read file $config";
751 $name =~ s,.*/(.*),$1,;
753 my $test_num = $$current_test_num;
756 my $num_tests_set = 0;
769 # ignore blank lines and comments
770 next if (/^\s*$/ || /\s*\#/);
772 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
782 if ($type eq "TEST_START") {
784 if ($num_tests_set) {
785 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
788 $old_test_num = $test_num;
789 $old_repeat = $repeat;
791 $test_num += $repeat;
798 # If SKIP is anywhere in the line, the command will be skipped
799 if ($rest =~ s/\s+SKIP\b//) {
806 if ($rest =~ s/\sELSE\b//) {
808 die "$name: $.: ELSE found with out matching IF section\n$_";
819 if ($rest =~ s/\sIF\s+(.*)//) {
820 if (process_if($name, $1)) {
832 if ($type eq "TEST_START") {
833 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
835 $repeat_tests{"$test_num"} = $repeat;
837 } elsif ($rest =~ s/\sOVERRIDE\b//) {
840 # Clear previous overrides
845 if (!$skip && $rest !~ /^\s*$/) {
846 die "$name: $.: Gargbage found after $type\n$_";
849 if ($skip && $type eq "TEST_START") {
850 $test_num = $old_test_num;
851 $repeat = $old_repeat;
854 } elsif (/^\s*ELSE\b(.*)$/) {
856 die "$name: $.: ELSE found with out matching IF section\n$_";
865 if ($rest =~ /\sIF\s+(.*)/) {
866 # May be a ELSE IF section.
867 if (process_if($name, $1)) {
878 if ($rest !~ /^\s*$/) {
879 die "$name: $.: Gargbage found after DEFAULTS\n$_";
882 } elsif (/^\s*INCLUDE\s+(\S+)/) {
887 die "$name: $.: INCLUDE can only be done in default sections\n$_";
890 my $file = process_variables($1);
892 if ($file !~ m,^/,) {
893 # check the path of the config file first
894 if ($config =~ m,(.*)/,) {
902 die "$name: $.: Can't read file $file\n$_";
905 if (__read_config($file, \$test_num)) {
909 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
917 ($lvalue eq "NUM_TESTS" ||
918 $lvalue eq "LOG_FILE" ||
919 $lvalue eq "CLEAR_LOG")) {
920 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
923 if ($lvalue eq "NUM_TESTS") {
925 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
928 die "$name: $.: NUM_TESTS must be set in default section\n";
933 if ($default || $lvalue =~ /\[\d+\]$/) {
934 set_value($lvalue, $rvalue, $override, \%overrides, $name);
936 my $val = "$lvalue\[$test_num\]";
937 set_value($val, $rvalue, $override, \%overrides, $name);
940 $repeats{$val} = $repeat;
943 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
949 # process config variables.
950 # Config variables are only active while reading the
951 # config and can be defined anywhere. They also ignore
952 # TEST_START and DEFAULTS, but are skipped if they are in
953 # on of these sections that have SKIP defined.
954 # The save variable can be
955 # defined multiple times and the new one simply overrides
957 set_variable($lvalue, $rvalue);
960 die "$name: $.: Garbage found in config\n$_";
965 $test_num += $repeat - 1;
966 $opt{"NUM_TESTS"} = $test_num;
971 $$current_test_num = $test_num;
977 print "What test case would you like to run?\n";
978 print " (build, install or boot)\n";
979 print " Other tests are available but require editing the config file\n";
982 $default{"TEST_TYPE"} = $ans;
991 $test_case = __read_config $config, \$test_num;
993 # make sure we have all mandatory configs
996 # was a test specified?
998 print "No test case specified.\n";
1004 foreach my $default (keys %default) {
1005 if (!defined($opt{$default})) {
1006 $opt{$default} = $default{$default};
1010 if ($opt{"IGNORE_UNUSED"} == 1) {
1016 # check if there are any stragglers (typos?)
1017 foreach my $option (keys %opt) {
1019 # remove per test labels.
1021 if (!exists($option_map{$op}) &&
1022 !exists($default{$op}) &&
1023 !exists($used_options{$op})) {
1030 $s = " is" if (keys %not_used == 1);
1031 print "The following option$s not used; could be a typo:\n";
1032 foreach my $option (keys %not_used) {
1035 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1036 if (!read_yn "Do you want to continue?") {
1043 my ($option, $i) = @_;
1045 # Add space to evaluate the character before $
1046 $option = " $option";
1051 foreach my $test (keys %repeat_tests) {
1053 $i < $test + $repeat_tests{$test}) {
1061 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1066 # Append beginning of line
1067 $retval = "$retval$start";
1069 # If the iteration option OPT[$i] exists, then use that.
1070 # otherwise see if the default OPT (without [$i]) exists.
1072 my $o = "$var\[$i\]";
1073 my $parento = "$var\[$parent\]";
1075 if (defined($opt{$o})) {
1077 $retval = "$retval$o";
1078 } elsif ($repeated && defined($opt{$parento})) {
1079 $o = $opt{$parento};
1080 $retval = "$retval$o";
1081 } elsif (defined($opt{$var})) {
1083 $retval = "$retval$o";
1085 $retval = "$retval\$\{$var\}";
1091 $retval = "$retval$option";
1099 my ($option, $i) = @_;
1103 # Since an option can evaluate to another option,
1104 # keep iterating until we do not evaluate any more
1107 while ($prev ne $option) {
1108 # Check for recursive evaluations.
1109 # 100 deep should be more than enough.
1111 die "Over 100 evaluations accurred with $option\n" .
1112 "Check for recursive variables\n";
1115 $option = __eval_option($option, $i);
1122 if (defined($opt{"LOG_FILE"})) {
1123 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1130 if (defined($opt{"LOG_FILE"})) {
1145 sub wait_for_monitor;
1150 # Make sure everything has been written to disk
1153 if (defined($time)) {
1155 # flush out current monitor
1156 # May contain the reboot success line
1160 # try to reboot normally
1161 if (run_command $reboot) {
1162 if (defined($powercycle_after_reboot)) {
1163 sleep $powercycle_after_reboot;
1164 run_command "$power_cycle";
1167 # nope? power cycle it.
1168 run_command "$power_cycle";
1171 if (defined($time)) {
1172 if (wait_for_monitor($time, $reboot_success_line)) {
1174 doprint "Reboot did not finish. Forcing power cycle\n";
1175 run_command "$power_cycle";
1181 sub reboot_to_good {
1184 if (defined($switch_to_good)) {
1185 run_command $switch_to_good;
1194 return $test_type eq "build" || $no_reboot ||
1195 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1196 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1200 doprint "CRITICAL FAILURE... ", @_, "\n";
1204 if ($reboot_on_error && !do_not_reboot) {
1206 doprint "REBOOTING\n";
1209 } elsif ($poweroff_on_error && defined($power_off)) {
1210 doprint "POWERING OFF\n";
1214 if (defined($opt{"LOG_FILE"})) {
1215 print " See $opt{LOG_FILE} for more info.\n";
1226 my $pid = open($fp, "$console|") or
1227 dodie "Can't open console $console";
1229 $flags = fcntl($fp, F_GETFL, 0) or
1230 dodie "Can't get flags for the socket: $!";
1231 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1232 dodie "Can't set flags for the socket: $!";
1238 my ($fp, $pid) = @_;
1240 doprint "kill child process $pid\n";
1248 if ($monitor_cnt++) {
1251 $monitor_fp = \*MONFD;
1252 $monitor_pid = open_console $monitor_fp;
1256 open(MONFD, "Stop perl from warning about single use of MONFD");
1260 if (--$monitor_cnt) {
1263 close_console($monitor_fp, $monitor_pid);
1266 sub wait_for_monitor {
1267 my ($time, $stop) = @_;
1271 my $start_time = time;
1272 my $skip_call_trace = 0;
1274 my $bug_ignored = 0;
1277 doprint "** Wait for monitor to settle down **\n";
1279 # read the monitor and wait for the system to calm down
1281 $line = wait_for_input($monitor_fp, $time);
1282 last if (!defined($line));
1284 $full_line .= $line;
1286 if (defined($stop) && $full_line =~ /$stop/) {
1287 doprint "wait for monitor detected $stop\n";
1291 if ($full_line =~ /\[ backtrace testing \]/) {
1292 $skip_call_trace = 1;
1295 if ($full_line =~ /call trace:/i) {
1296 if (!$bug && !$skip_call_trace) {
1297 if ($ignore_errors) {
1305 if ($full_line =~ /\[ end of backtrace testing \]/) {
1306 $skip_call_trace = 0;
1309 if ($full_line =~ /Kernel panic -/) {
1313 if ($line =~ /\n/) {
1317 if ($now - $start_time >= $max_monitor_wait) {
1318 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1322 print "** Monitor flushed **\n";
1327 my ($result, $basedir) = @_;
1329 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1330 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1332 my $type = $build_type;
1333 if ($type =~ /useconfig/) {
1334 $type = "useconfig";
1337 my $dir = "$machine-$test_type-$type-$result-$date";
1339 $dir = "$basedir/$dir";
1343 die "can't create $dir";
1347 "config" => $output_config,
1348 "buildlog" => $buildlog,
1350 "testlog" => $testlog,
1353 while (my ($name, $source) = each(%files)) {
1355 cp "$source", "$dir/$name" or
1356 die "failed to copy $source";
1360 doprint "*** Saved info to $dir ***\n";
1365 if (defined($post_test)) {
1366 run_command $post_test;
1369 if ($die_on_failure) {
1377 # no need to reboot for just building.
1378 if (!do_not_reboot) {
1379 doprint "REBOOTING\n";
1380 reboot_to_good $sleep_time;
1385 if (defined($test_name)) {
1386 $name = " ($test_name)";
1389 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1390 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1391 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1392 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1393 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1395 if (defined($store_failures)) {
1396 save_logs "fail", $store_failures;
1408 $command =~ s/\$SSH_USER/$ssh_user/g;
1409 $command =~ s/\$MACHINE/$machine/g;
1411 doprint("$command ... ");
1413 $pid = open(CMD, "$command 2>&1 |") or
1414 (fail "unable to exec $command" and return 0);
1416 if (defined($opt{"LOG_FILE"})) {
1417 open(LOG, ">>$opt{LOG_FILE}") or
1418 dodie "failed to write to log";
1422 if (defined($redirect)) {
1423 open (RD, ">$redirect") or
1424 dodie "failed to write to redirect $redirect";
1429 print LOG if ($dolog);
1430 print RD if ($dord);
1437 close(LOG) if ($dolog);
1438 close(RD) if ($dord);
1441 doprint "FAILED!\n";
1443 doprint "SUCCESS\n";
1451 my $cp_exec = $ssh_exec;
1453 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1454 return run_command "$cp_exec";
1458 my ($src, $dst, $cp_scp) = @_;
1460 $cp_scp =~ s/\$SRC_FILE/$src/g;
1461 $cp_scp =~ s/\$DST_FILE/$dst/g;
1463 return run_command "$cp_scp";
1466 sub run_scp_install {
1467 my ($src, $dst) = @_;
1469 my $cp_scp = $scp_to_target_install;
1471 return run_scp($src, $dst, $cp_scp);
1475 my ($src, $dst) = @_;
1477 my $cp_scp = $scp_to_target;
1479 return run_scp($src, $dst, $cp_scp);
1482 sub get_grub2_index {
1484 return if (defined($grub_number));
1486 doprint "Find grub2 menu ... ";
1489 my $ssh_grub = $ssh_exec;
1490 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1492 open(IN, "$ssh_grub |")
1493 or die "unable to get $grub_file";
1498 if (/^menuentry.*$grub_menu/) {
1502 } elsif (/^menuentry\s/) {
1508 die "Could not find '$grub_menu' in $grub_file on $machine"
1510 doprint "$grub_number\n";
1513 sub get_grub_index {
1515 if ($reboot_type eq "grub2") {
1520 if ($reboot_type ne "grub") {
1523 return if (defined($grub_number));
1525 doprint "Find grub menu ... ";
1528 my $ssh_grub = $ssh_exec;
1529 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1531 open(IN, "$ssh_grub |")
1532 or die "unable to get menu.lst";
1537 if (/^\s*title\s+$grub_menu\s*$/) {
1541 } elsif (/^\s*title\s/) {
1547 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1549 doprint "$grub_number\n";
1554 my ($fp, $time) = @_;
1560 if (!defined($time)) {
1565 vec($rin, fileno($fp), 1) = 1;
1566 $ready = select($rin, undef, undef, $time);
1570 # try to read one char at a time
1571 while (sysread $fp, $ch, 1) {
1573 last if ($ch eq "\n");
1576 if (!length($line)) {
1584 if (defined($switch_to_test)) {
1585 run_command $switch_to_test;
1588 if ($reboot_type eq "grub") {
1589 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1590 } elsif ($reboot_type eq "grub2") {
1591 run_ssh "$grub_reboot $grub_number";
1592 } elsif (defined $reboot_script) {
1593 run_command "$reboot_script";
1601 doprint "git rev-list --max-count=1 $commit ... ";
1602 my $sha1 = `git rev-list --max-count=1 $commit`;
1609 dodie "Failed to get git $commit";
1622 my $bug_ignored = 0;
1623 my $skip_call_trace = 0;
1631 open(DMESG, "> $dmesg") or
1632 die "unable to write to $dmesg";
1638 my $monitor_start = time;
1640 my $version_found = 0;
1644 if ($bug && defined($stop_after_failure) &&
1645 $stop_after_failure >= 0) {
1646 my $time = $stop_after_failure - (time - $failure_start);
1647 $line = wait_for_input($monitor_fp, $time);
1648 if (!defined($line)) {
1649 doprint "bug timed out after $booted_timeout seconds\n";
1650 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1654 $line = wait_for_input($monitor_fp, $booted_timeout);
1655 if (!defined($line)) {
1656 my $s = $booted_timeout == 1 ? "" : "s";
1657 doprint "Successful boot found: break after $booted_timeout second$s\n";
1661 $line = wait_for_input($monitor_fp);
1662 if (!defined($line)) {
1663 my $s = $timeout == 1 ? "" : "s";
1664 doprint "Timed out after $timeout second$s\n";
1672 # we are not guaranteed to get a full line
1673 $full_line .= $line;
1675 if ($full_line =~ /$success_line/) {
1677 $success_start = time;
1680 if ($booted && defined($stop_after_success) &&
1681 $stop_after_success >= 0) {
1683 if ($now - $success_start >= $stop_after_success) {
1684 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1689 if ($full_line =~ /\[ backtrace testing \]/) {
1690 $skip_call_trace = 1;
1693 if ($full_line =~ /call trace:/i) {
1694 if (!$bug && !$skip_call_trace) {
1695 if ($ignore_errors) {
1699 $failure_start = time;
1704 if ($bug && defined($stop_after_failure) &&
1705 $stop_after_failure >= 0) {
1707 if ($now - $failure_start >= $stop_after_failure) {
1708 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1713 if ($full_line =~ /\[ end of backtrace testing \]/) {
1714 $skip_call_trace = 0;
1717 if ($full_line =~ /Kernel panic -/) {
1718 $failure_start = time;
1722 # Detect triple faults by testing the banner
1723 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1724 if ($1 eq $version) {
1726 } elsif ($version_found && $detect_triplefault) {
1727 # We already booted into the kernel we are testing,
1728 # but now we booted into another kernel?
1729 # Consider this a triple fault.
1730 doprint "Aleady booted in Linux kernel $version, but now\n";
1731 doprint "we booted into Linux kernel $1.\n";
1732 doprint "Assuming that this is a triple fault.\n";
1733 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1738 if ($line =~ /\n/) {
1742 if ($stop_test_after > 0 && !$booted && !$bug) {
1743 if (time - $monitor_start > $stop_test_after) {
1744 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1753 return 0 if ($in_bisect);
1754 fail "failed - got a bug report" and return 0;
1758 return 0 if ($in_bisect);
1759 fail "failed - never got a boot prompt." and return 0;
1763 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1769 sub eval_kernel_version {
1772 $option =~ s/\$KERNEL_VERSION/$version/g;
1777 sub do_post_install {
1779 return if (!defined($post_install));
1781 my $cp_post_install = eval_kernel_version $post_install;
1782 run_command "$cp_post_install" or
1783 dodie "Failed to run post install";
1788 return if ($no_install);
1790 if (defined($pre_install)) {
1791 my $cp_pre_install = eval_kernel_version $pre_install;
1792 run_command "$cp_pre_install" or
1793 dodie "Failed to run pre install";
1796 my $cp_target = eval_kernel_version $target_image;
1798 run_scp_install "$outputdir/$build_target", "$cp_target" or
1799 dodie "failed to copy image";
1801 my $install_mods = 0;
1803 # should we process modules?
1805 open(IN, "$output_config") or dodie("Can't read config file");
1807 if (/CONFIG_MODULES(=y)?/) {
1816 if (!$install_mods) {
1818 doprint "No modules needed\n";
1822 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1823 dodie "Failed to install modules";
1825 my $modlib = "/lib/modules/$version";
1826 my $modtar = "ktest-mods.tar.bz2";
1828 run_ssh "rm -rf $modlib" or
1829 dodie "failed to remove old mods: $modlib";
1831 # would be nice if scp -r did not follow symbolic links
1832 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1833 dodie "making tarball";
1835 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1836 dodie "failed to copy modules";
1838 unlink "$tmpdir/$modtar";
1840 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1841 dodie "failed to tar modules";
1843 run_ssh "rm -f /tmp/$modtar";
1849 # get the release name
1850 return if ($have_version);
1851 doprint "$make kernelrelease ... ";
1852 $version = `$make kernelrelease | tail -1`;
1854 doprint "$version\n";
1858 sub start_monitor_and_boot {
1859 # Make sure the stable kernel has finished booting
1872 sub check_buildlog {
1875 my @files = `git show $patch | diffstat -l`;
1877 open(IN, "git show $patch |") or
1878 dodie "failed to show $patch";
1880 if (m,^--- a/(.*),) {
1882 $files[$#files] = $1;
1887 open(IN, $buildlog) or dodie "Can't open $buildlog";
1889 if (/^\s*(.*?):.*(warning|error)/) {
1891 foreach my $file (@files) {
1892 my $fullpath = "$builddir/$file";
1893 if ($file eq $err || $fullpath eq $err) {
1894 fail "$file built with warnings" and return 0;
1904 sub apply_min_config {
1905 my $outconfig = "$output_config.new";
1907 # Read the config file and remove anything that
1908 # is in the force_config hash (from minconfig and others)
1909 # then add the force config back.
1911 doprint "Applying minimum configurations into $output_config.new\n";
1913 open (OUT, ">$outconfig") or
1914 dodie "Can't create $outconfig";
1916 if (-f $output_config) {
1917 open (IN, $output_config) or
1918 dodie "Failed to open $output_config";
1920 if (/^(# )?(CONFIG_[^\s=]*)/) {
1921 next if (defined($force_config{$2}));
1927 foreach my $config (keys %force_config) {
1928 print OUT "$force_config{$config}\n";
1932 run_command "mv $outconfig $output_config";
1935 sub make_oldconfig {
1937 my @force_list = keys %force_config;
1939 if ($#force_list >= 0) {
1943 if (!run_command "$make olddefconfig") {
1944 # Perhaps olddefconfig doesn't exist in this version of the kernel
1945 # try a yes '' | oldconfig
1946 doprint "olddefconfig failed, trying yes '' | make oldconfig\n";
1947 run_command "yes '' | $make oldconfig" or
1948 dodie "failed make config oldconfig";
1952 # read a config file and use this to force new configs.
1953 sub load_force_config {
1956 doprint "Loading force configs from $config\n";
1957 open(IN, $config) or
1958 dodie "failed to read $config";
1961 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1962 $force_config{$1} = $_;
1963 } elsif (/^# (CONFIG_\S*) is not set/) {
1964 $force_config{$1} = $_;
1975 # Failed builds should not reboot the target
1976 my $save_no_reboot = $no_reboot;
1979 # Calculate a new version from here.
1982 if (defined($pre_build)) {
1983 my $ret = run_command $pre_build;
1984 if (!$ret && defined($pre_build_die) &&
1986 dodie "failed to pre_build\n";
1990 if ($type =~ /^useconfig:(.*)/) {
1991 run_command "cp $1 $output_config" or
1992 dodie "could not copy $1 to .config";
1994 $type = "oldconfig";
1997 # old config can ask questions
1998 if ($type eq "oldconfig") {
1999 $type = "olddefconfig";
2001 # allow for empty configs
2002 run_command "touch $output_config";
2005 run_command "mv $output_config $outputdir/config_temp" or
2006 dodie "moving .config";
2008 run_command "$make mrproper" or dodie "make mrproper";
2010 run_command "mv $outputdir/config_temp $output_config" or
2011 dodie "moving config_temp";
2014 } elsif (!$noclean) {
2015 unlink "$output_config";
2016 run_command "$make mrproper" or
2017 dodie "make mrproper";
2020 # add something to distinguish this build
2021 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2022 print OUT "$localversion\n";
2025 if (defined($minconfig)) {
2026 load_force_config($minconfig);
2029 if ($type ne "olddefconfig") {
2030 run_command "$make $type" or
2031 dodie "failed make config";
2033 # Run old config regardless, to enforce min configurations
2036 $redirect = "$buildlog";
2037 my $build_ret = run_command "$make $build_options";
2040 if (defined($post_build)) {
2041 # Because a post build may change the kernel version
2044 my $ret = run_command $post_build;
2045 if (!$ret && defined($post_build_die) &&
2047 dodie "failed to post_build\n";
2052 # bisect may need this to pass
2054 $no_reboot = $save_no_reboot;
2057 fail "failed build" and return 0;
2060 $no_reboot = $save_no_reboot;
2066 if (!run_ssh "halt" or defined($power_off)) {
2067 if (defined($poweroff_after_halt)) {
2068 sleep $poweroff_after_halt;
2069 run_command "$power_off";
2073 run_command "$power_off";
2080 if (defined($post_test)) {
2081 run_command $post_test;
2088 if (defined($test_name)) {
2089 $name = " ($test_name)";
2092 doprint "\n\n*******************************************\n";
2093 doprint "*******************************************\n";
2094 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2095 doprint "*******************************************\n";
2096 doprint "*******************************************\n";
2098 if (defined($store_successes)) {
2099 save_logs "success", $store_successes;
2102 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2103 doprint "Reboot and wait $sleep_time seconds\n";
2104 reboot_to_good $sleep_time;
2110 doprint "Pass or fail? [p/f]";
2113 if ($ans eq "p" || $ans eq "P") {
2115 } elsif ($ans eq "f" || $ans eq "F") {
2118 print "Please answer 'P' or 'F'\n";
2123 sub child_run_test {
2126 # child should have no power
2127 $reboot_on_error = 0;
2128 $poweroff_on_error = 0;
2129 $die_on_failure = 1;
2131 $redirect = "$testlog";
2132 run_command $run_test or $failed = 1;
2140 sub child_finished {
2150 my $bug_ignored = 0;
2154 doprint "run test $run_test\n";
2158 $SIG{CHLD} = qw(child_finished);
2162 child_run_test if (!$child_pid);
2167 $line = wait_for_input($monitor_fp, 1);
2168 if (defined($line)) {
2170 # we are not guaranteed to get a full line
2171 $full_line .= $line;
2174 if ($full_line =~ /call trace:/i) {
2175 if ($ignore_errors) {
2182 if ($full_line =~ /Kernel panic -/) {
2186 if ($line =~ /\n/) {
2190 } while (!$child_done && !$bug);
2192 if (!$bug && $bug_ignored) {
2193 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2197 my $failure_start = time;
2200 $line = wait_for_input($monitor_fp, 1);
2201 if (defined($line)) {
2205 if ($now - $failure_start >= $stop_after_failure) {
2208 } while (defined($line));
2210 doprint "Detected kernel crash!\n";
2211 # kill the child with extreme prejudice
2215 waitpid $child_pid, 0;
2218 if (!$bug && $in_bisect) {
2219 if (defined($bisect_ret_good)) {
2220 if ($child_exit == $bisect_ret_good) {
2224 if (defined($bisect_ret_skip)) {
2225 if ($child_exit == $bisect_ret_skip) {
2229 if (defined($bisect_ret_abort)) {
2230 if ($child_exit == $bisect_ret_abort) {
2231 fail "test abort" and return -2;
2234 if (defined($bisect_ret_bad)) {
2235 if ($child_exit == $bisect_ret_skip) {
2239 if (defined($bisect_ret_default)) {
2240 if ($bisect_ret_default eq "good") {
2242 } elsif ($bisect_ret_default eq "bad") {
2244 } elsif ($bisect_ret_default eq "skip") {
2246 } elsif ($bisect_ret_default eq "abort") {
2249 fail "unknown default action: $bisect_ret_default"
2255 if ($bug || $child_exit) {
2256 return 0 if $in_bisect;
2257 fail "test failed" and return 0;
2262 sub run_git_bisect {
2265 doprint "$command ... ";
2267 my $output = `$command 2>&1`;
2274 dodie "Failed to git bisect";
2277 doprint "SUCCESS\n";
2278 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2279 doprint "$1 [$2]\n";
2280 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2281 $bisect_bad_commit = $1;
2282 doprint "Found bad commit... $1\n";
2285 # we already logged it, just print it now.
2293 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2294 reboot_to_good $bisect_sleep_time;
2297 # returns 1 on success, 0 on failure, -1 on skip
2298 sub run_bisect_test {
2299 my ($type, $buildtype) = @_;
2308 build $buildtype or $failed = 1;
2310 if ($type ne "build") {
2311 if ($failed && $bisect_skip) {
2315 dodie "Failed on build" if $failed;
2318 start_monitor_and_boot or $failed = 1;
2320 if ($type ne "boot") {
2321 if ($failed && $bisect_skip) {
2327 dodie "Failed on boot" if $failed;
2329 do_run_test or $failed = 1;
2340 # reboot the box to a kernel we can ssh to
2341 if ($type ne "build") {
2351 my $buildtype = "oldconfig";
2353 # We should have a minconfig to use?
2354 if (defined($minconfig)) {
2355 $buildtype = "useconfig:$minconfig";
2358 my $ret = run_bisect_test $type, $buildtype;
2360 if ($bisect_manual) {
2361 $ret = answer_bisect;
2364 # Are we looking for where it worked, not failed?
2365 if ($reverse_bisect && $ret >= 0) {
2371 } elsif ($ret == 0) {
2373 } elsif ($bisect_skip) {
2374 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2379 sub update_bisect_replay {
2380 my $tmp_log = "$tmpdir/ktest_bisect_log";
2381 run_command "git bisect log > $tmp_log" or
2382 die "can't create bisect log";
2391 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2392 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2393 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2395 my $good = $bisect_good;
2396 my $bad = $bisect_bad;
2397 my $type = $bisect_type;
2398 my $start = $bisect_start;
2399 my $replay = $bisect_replay;
2400 my $start_files = $bisect_files;
2402 if (defined($start_files)) {
2403 $start_files = " -- " . $start_files;
2408 # convert to true sha1's
2409 $good = get_sha1($good);
2410 $bad = get_sha1($bad);
2412 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2413 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2414 $reverse_bisect = 1;
2416 $reverse_bisect = 0;
2419 # Can't have a test without having a test to run
2420 if ($type eq "test" && !defined($run_test)) {
2424 # Check if a bisect was running
2425 my $bisect_start_file = "$builddir/.git/BISECT_START";
2427 my $check = $bisect_check;
2428 my $do_check = defined($check) && $check ne "0";
2430 if ( -f $bisect_start_file ) {
2431 print "Bisect in progress found\n";
2433 print " If you say yes, then no checks of good or bad will be done\n";
2435 if (defined($replay)) {
2436 print "** BISECT_REPLAY is defined in config file **";
2437 print " Ignore config option and perform new git bisect log?\n";
2438 if (read_ync " (yes, no, or cancel) ") {
2439 $replay = update_bisect_replay;
2442 } elsif (read_yn "read git log and continue?") {
2443 $replay = update_bisect_replay;
2451 my $head = get_sha1("HEAD");
2453 if ($check ne "good") {
2454 doprint "TESTING BISECT BAD [$bad]\n";
2455 run_command "git checkout $bad" or
2456 die "Failed to checkout $bad";
2458 $result = run_bisect $type;
2460 if ($result ne "bad") {
2461 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2465 if ($check ne "bad") {
2466 doprint "TESTING BISECT GOOD [$good]\n";
2467 run_command "git checkout $good" or
2468 die "Failed to checkout $good";
2470 $result = run_bisect $type;
2472 if ($result ne "good") {
2473 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2477 # checkout where we started
2478 run_command "git checkout $head" or
2479 die "Failed to checkout $head";
2482 run_command "git bisect start$start_files" or
2483 dodie "could not start bisect";
2485 run_command "git bisect good $good" or
2486 dodie "could not set bisect good to $good";
2488 run_git_bisect "git bisect bad $bad" or
2489 dodie "could not set bisect bad to $bad";
2491 if (defined($replay)) {
2492 run_command "git bisect replay $replay" or
2493 dodie "failed to run replay";
2496 if (defined($start)) {
2497 run_command "git checkout $start" or
2498 dodie "failed to checkout $start";
2503 $result = run_bisect $type;
2504 $test = run_git_bisect "git bisect $result";
2507 run_command "git bisect log" or
2508 dodie "could not capture git bisect log";
2510 run_command "git bisect reset" or
2511 dodie "could not reset git bisect";
2513 doprint "Bad commit was [$bisect_bad_commit]\n";
2518 # config_ignore holds the configs that were set (or unset) for
2519 # a good config and we will ignore these configs for the rest
2520 # of a config bisect. These configs stay as they were.
2523 # config_set holds what all configs were set as.
2526 # config_off holds the set of configs that the bad config had disabled.
2527 # We need to record them and set them in the .config when running
2528 # olddefconfig, because olddefconfig keeps the defaults.
2531 # config_off_tmp holds a set of configs to turn off for now
2534 # config_list is the set of configs that are being tested
2540 sub assign_configs {
2541 my ($hash, $config) = @_;
2544 or dodie "Failed to read $config";
2547 if (/^((CONFIG\S*)=.*)/) {
2555 sub process_config_ignore {
2558 assign_configs \%config_ignore, $config;
2561 sub read_current_config {
2562 my ($config_ref) = @_;
2564 %{$config_ref} = ();
2565 undef %{$config_ref};
2567 my @key = keys %{$config_ref};
2569 print "did not delete!\n";
2572 open (IN, "$output_config");
2575 if (/^(CONFIG\S+)=(.*)/) {
2576 ${$config_ref}{$1} = $2;
2582 sub get_dependencies {
2585 my $arr = $dependency{$config};
2586 if (!defined($arr)) {
2592 foreach my $dep (@{$arr}) {
2593 print "ADD DEP $dep\n";
2594 @deps = (@deps, get_dependencies $dep);
2603 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2605 foreach my $config (@configs) {
2606 print OUT "$config_set{$config}\n";
2607 my @deps = get_dependencies $config;
2608 foreach my $dep (@deps) {
2609 print OUT "$config_set{$dep}\n";
2613 # turn off configs to keep off
2614 foreach my $config (keys %config_off) {
2615 print OUT "# $config is not set\n";
2618 # turn off configs that should be off for now
2619 foreach my $config (@config_off_tmp) {
2620 print OUT "# $config is not set\n";
2623 foreach my $config (keys %config_ignore) {
2624 print OUT "$config_ignore{$config}\n";
2631 sub compare_configs {
2634 foreach my $item (keys %a) {
2635 if (!defined($b{$item})) {
2636 print "diff $item\n";
2644 print "diff2 $keys[0]\n";
2646 return -1 if ($#keys >= 0);
2651 sub run_config_bisect_test {
2654 return run_bisect_test $type, "oldconfig";
2657 sub process_passed {
2660 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2661 # Passed! All these configs are part of a good compile.
2662 # Add them to the min options.
2663 foreach my $config (keys %configs) {
2664 if (defined($config_list{$config})) {
2665 doprint " removing $config\n";
2666 $config_ignore{$config} = $config_list{$config};
2667 delete $config_list{$config};
2670 doprint "config copied to $outputdir/config_good\n";
2671 run_command "cp -f $output_config $outputdir/config_good";
2674 sub process_failed {
2677 doprint "\n\n***************************************\n";
2678 doprint "Found bad config: $config\n";
2679 doprint "***************************************\n\n";
2682 sub run_config_bisect {
2684 my @start_list = keys %config_list;
2686 if ($#start_list < 0) {
2687 doprint "No more configs to test!!!\n";
2691 doprint "***** RUN TEST ***\n";
2692 my $type = $config_bisect_type;
2696 my $count = $#start_list + 1;
2697 doprint " $count configs to test\n";
2699 my $half = int($#start_list / 2);
2702 my @tophalf = @start_list[0 .. $half];
2704 # keep the bottom half off
2705 if ($half < $#start_list) {
2706 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2708 @config_off_tmp = ();
2711 create_config @tophalf;
2712 read_current_config \%current_config;
2714 $count = $#tophalf + 1;
2715 doprint "Testing $count configs\n";
2717 # make sure we test something
2718 foreach my $config (@tophalf) {
2719 if (defined($current_config{$config})) {
2725 # try the other half
2726 doprint "Top half produced no set configs, trying bottom half\n";
2728 # keep the top half off
2729 @config_off_tmp = @tophalf;
2730 @tophalf = @start_list[$half + 1 .. $#start_list];
2732 create_config @tophalf;
2733 read_current_config \%current_config;
2734 foreach my $config (@tophalf) {
2735 if (defined($current_config{$config})) {
2741 doprint "Failed: Can't make new config with current configs\n";
2742 foreach my $config (@start_list) {
2743 doprint " CONFIG: $config\n";
2747 $count = $#tophalf + 1;
2748 doprint "Testing $count configs\n";
2751 $ret = run_config_bisect_test $type;
2752 if ($bisect_manual) {
2753 $ret = answer_bisect;
2756 process_passed %current_config;
2760 doprint "This config had a failure.\n";
2761 doprint "Removing these configs that were not set in this config:\n";
2762 doprint "config copied to $outputdir/config_bad\n";
2763 run_command "cp -f $output_config $outputdir/config_bad";
2765 # A config exists in this group that was bad.
2766 foreach my $config (keys %config_list) {
2767 if (!defined($current_config{$config})) {
2768 doprint " removing $config\n";
2769 delete $config_list{$config};
2773 @start_list = @tophalf;
2775 if ($#start_list == 0) {
2776 process_failed $start_list[0];
2780 # remove half the configs we are looking at and see if
2782 $half = int($#start_list / 2);
2783 } while ($#start_list > 0);
2785 # we found a single config, try it again unless we are running manually
2787 if ($bisect_manual) {
2788 process_failed $start_list[0];
2792 my @tophalf = @start_list[0 .. 0];
2794 $ret = run_config_bisect_test $type;
2796 process_passed %current_config;
2800 process_failed $start_list[0];
2807 my $start_config = $config_bisect;
2809 my $tmpconfig = "$tmpdir/use_config";
2811 if (defined($config_bisect_good)) {
2812 process_config_ignore $config_bisect_good;
2815 # Make the file with the bad config and the min config
2816 if (defined($minconfig)) {
2817 # read the min config for things to ignore
2818 run_command "cp $minconfig $tmpconfig" or
2819 dodie "failed to copy $minconfig to $tmpconfig";
2824 if (-f $tmpconfig) {
2825 load_force_config($tmpconfig);
2826 process_config_ignore $tmpconfig;
2829 # now process the start config
2830 run_command "cp $start_config $output_config" or
2831 dodie "failed to copy $start_config to $output_config";
2833 # read directly what we want to check
2835 open (IN, $output_config)
2836 or dodie "failed to open $output_config";
2839 if (/^((CONFIG\S*)=.*)/) {
2840 $config_check{$2} = $1;
2845 # Now run oldconfig with the minconfig
2848 # check to see what we lost (or gained)
2849 open (IN, $output_config)
2850 or dodie "Failed to read $start_config";
2852 my %removed_configs;
2856 if (/^((CONFIG\S*)=.*)/) {
2857 # save off all options
2858 $config_set{$2} = $1;
2859 if (defined($config_check{$2})) {
2860 if (defined($config_ignore{$2})) {
2861 $removed_configs{$2} = $1;
2863 $config_list{$2} = $1;
2865 } elsif (!defined($config_ignore{$2})) {
2866 $added_configs{$2} = $1;
2867 $config_list{$2} = $1;
2869 } elsif (/^# ((CONFIG\S*).*)/) {
2870 # Keep these configs disabled
2871 $config_set{$2} = $1;
2872 $config_off{$2} = $1;
2877 my @confs = keys %removed_configs;
2879 doprint "Configs overridden by default configs and removed from check:\n";
2880 foreach my $config (@confs) {
2881 doprint " $config\n";
2884 @confs = keys %added_configs;
2886 doprint "Configs appearing in make oldconfig and added:\n";
2887 foreach my $config (@confs) {
2888 doprint " $config\n";
2895 @config_off_tmp = ();
2897 # Sometimes kconfig does weird things. We must make sure
2898 # that the config we autocreate has everything we need
2899 # to test, otherwise we may miss testing configs, or
2900 # may not be able to create a new config.
2901 # Here we create a config with everything set.
2902 create_config (keys %config_list);
2903 read_current_config \%config_test;
2904 foreach my $config (keys %config_list) {
2905 if (!defined($config_test{$config})) {
2908 doprint "Configs not produced by kconfig (will not be checked):\n";
2910 doprint " $config\n";
2911 delete $config_list{$config};
2916 if (defined($config_bisect_check) && $config_bisect_check) {
2917 doprint " Checking to make sure bad config with min config fails\n";
2918 create_config keys %config_list;
2919 $ret = run_config_bisect_test $config_bisect_type;
2921 doprint " FAILED! Bad config with min config boots fine\n";
2924 doprint " Bad config with min config fails as expected\n";
2928 $ret = run_config_bisect;
2931 return $ret if ($ret < 0);
2936 sub patchcheck_reboot {
2937 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2938 reboot_to_good $patchcheck_sleep_time;
2944 die "PATCHCHECK_START[$i] not defined\n"
2945 if (!defined($patchcheck_start));
2946 die "PATCHCHECK_TYPE[$i] not defined\n"
2947 if (!defined($patchcheck_type));
2949 my $start = $patchcheck_start;
2952 if (defined($patchcheck_end)) {
2953 $end = $patchcheck_end;
2956 # Get the true sha1's since we can use things like HEAD~3
2957 $start = get_sha1($start);
2958 $end = get_sha1($end);
2960 my $type = $patchcheck_type;
2962 # Can't have a test without having a test to run
2963 if ($type eq "test" && !defined($run_test)) {
2967 open (IN, "git log --pretty=oneline $end|") or
2968 dodie "could not get git list";
2974 $list[$#list+1] = $_;
2975 last if (/^$start/);
2979 if ($list[$#list] !~ /^$start/) {
2980 fail "SHA1 $start not found";
2983 # go backwards in the list
2984 @list = reverse @list;
2986 my $save_clean = $noclean;
2987 my %ignored_warnings;
2989 if (defined($ignore_warnings)) {
2990 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2991 $ignored_warnings{$sha1} = 1;
2996 foreach my $item (@list) {
2998 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3000 doprint "\nProcessing commit $item\n\n";
3002 run_command "git checkout $sha1" or
3003 die "Failed to checkout $sha1";
3005 # only clean on the first and last patch
3006 if ($item eq $list[0] ||
3007 $item eq $list[$#list]) {
3008 $noclean = $save_clean;
3013 if (defined($minconfig)) {
3014 build "useconfig:$minconfig" or return 0;
3016 # ?? no config to use?
3017 build "oldconfig" or return 0;
3021 if (!defined($ignored_warnings{$sha1})) {
3022 check_buildlog $sha1 or return 0;
3025 next if ($type eq "build");
3029 start_monitor_and_boot or $failed = 1;
3031 if (!$failed && $type ne "boot"){
3032 do_run_test or $failed = 1;
3035 return 0 if ($failed);
3055 # $config depends on $dep
3056 my ($config, $dep) = @_;
3058 if (defined($depends{$config})) {
3059 $depends{$config} .= " " . $dep;
3061 $depends{$config} = $dep;
3064 # record the number of configs depending on $dep
3065 if (defined $depcount{$dep}) {
3068 $depcount{$dep} = 1;
3072 # taken from streamline_config.pl
3084 if (! -f $kconfig) {
3085 doprint "file $kconfig does not exist, skipping\n";
3089 open(KIN, "$kconfig")
3090 or die "Can't open $kconfig";
3094 # Make sure that lines ending with \ continue
3096 $_ = $line . " " . $_;
3107 # collect any Kconfig sources
3108 if (/^source\s*"(.*)"/) {
3109 $kconfigs[$#kconfigs+1] = $1;
3113 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3117 for (my $i = 0; $i < $iflevel; $i++) {
3118 add_dep $config, $ifdeps[$i];
3121 # collect the depends for the config
3122 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3124 add_dep $config, $1;
3126 # Get the configs that select this config
3127 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3129 # selected by depends on config
3130 add_dep $1, $config;
3132 # Check for if statements
3133 } elsif (/^if\s+(.*\S)\s*$/) {
3135 # remove beginning and ending non text
3136 $deps =~ s/^[^a-zA-Z0-9_]*//;
3137 $deps =~ s/[^a-zA-Z0-9_]*$//;
3139 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3141 $ifdeps[$iflevel++] = join ':', @deps;
3143 } elsif (/^endif/) {
3145 $iflevel-- if ($iflevel);
3148 } elsif (/^\s*help\s*$/) {
3154 # read in any configs that were found.
3155 foreach $kconfig (@kconfigs) {
3156 if (!defined($read_kconfigs{$kconfig})) {
3157 $read_kconfigs{$kconfig} = 1;
3158 read_kconfig("$builddir/$kconfig");
3164 # find out which arch this is by the kconfig file
3165 open (IN, $output_config)
3166 or dodie "Failed to read $output_config";
3169 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3176 if (!defined($arch)) {
3177 doprint "Could not find arch from config file\n";
3178 doprint "no dependencies used\n";
3182 # arch is really the subarch, we need to know
3183 # what directory to look at.
3184 if ($arch eq "i386" || $arch eq "x86_64") {
3186 } elsif ($arch =~ /^tile/) {
3190 my $kconfig = "$builddir/arch/$arch/Kconfig";
3192 if (! -f $kconfig && $arch =~ /\d$/) {
3194 # some subarchs have numbers, truncate them
3196 $kconfig = "$builddir/arch/$arch/Kconfig";
3197 if (! -f $kconfig) {
3198 doprint "No idea what arch dir $orig is for\n";
3199 doprint "no dependencies used\n";
3204 read_kconfig($kconfig);
3207 sub read_config_list {
3211 or dodie "Failed to read $config";
3214 if (/^((CONFIG\S*)=.*)/) {
3215 if (!defined($config_ignore{$2})) {
3216 $config_list{$2} = $1;
3224 sub read_output_config {
3227 assign_configs \%config_ignore, $config;
3230 sub make_new_config {
3233 open (OUT, ">$output_config")
3234 or dodie "Failed to write $output_config";
3236 foreach my $config (@configs) {
3237 print OUT "$config\n";
3245 $config =~ s/CONFIG_//;
3253 my $kconfig = chomp_config $dep;
3255 $dep = $depends{"$kconfig"};
3257 # the dep string we have saves the dependencies as they
3258 # were found, including expressions like ! && ||. We
3259 # want to split this out into just an array of configs.
3261 my $valid = "A-Za-z_0-9";
3265 while ($dep =~ /[$valid]/) {
3267 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3268 my $conf = "CONFIG_" . $1;
3270 $configs[$#configs + 1] = $conf;
3272 $dep =~ s/^[^$valid]*[$valid]+//;
3274 die "this should never happen";
3284 my %processed_configs;
3285 my %nochange_config;
3287 sub test_this_config {
3292 # if we already processed this config, skip it
3293 if (defined($processed_configs{$config})) {
3296 $processed_configs{$config} = 1;
3298 # if this config failed during this round, skip it
3299 if (defined($nochange_config{$config})) {
3303 my $kconfig = chomp_config $config;
3305 # Test dependencies first
3306 if (defined($depends{"$kconfig"})) {
3307 my @parents = get_depends $config;
3308 foreach my $parent (@parents) {
3309 # if the parent is in the min config, check it first
3310 next if (!defined($min_configs{$parent}));
3311 $found = test_this_config($parent);
3312 if (defined($found)) {
3318 # Remove this config from the list of configs
3319 # do a make olddefconfig and then read the resulting
3320 # .config to make sure it is missing the config that
3322 my %configs = %min_configs;
3323 delete $configs{$config};
3324 make_new_config ((values %configs), (values %keep_configs));
3327 assign_configs \%configs, $output_config;
3329 return $config if (!defined($configs{$config}));
3331 doprint "disabling config $config did not change .config\n";
3333 $nochange_config{$config} = 1;
3338 sub make_min_config {
3341 my $type = $minconfig_type;
3342 if ($type ne "boot" && $type ne "test") {
3343 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3344 " make_min_config works only with 'boot' and 'test'\n" and return;
3347 if (!defined($output_minconfig)) {
3348 fail "OUTPUT_MIN_CONFIG not defined" and return;
3351 # If output_minconfig exists, and the start_minconfig
3352 # came from min_config, than ask if we should use
3354 if (-f $output_minconfig && !$start_minconfig_defined) {
3355 print "$output_minconfig exists\n";
3356 if (!defined($use_output_minconfig)) {
3357 if (read_yn " Use it as minconfig?") {
3358 $start_minconfig = $output_minconfig;
3360 } elsif ($use_output_minconfig > 0) {
3361 doprint "Using $output_minconfig as MIN_CONFIG\n";
3362 $start_minconfig = $output_minconfig;
3364 doprint "Set to still use MIN_CONFIG as starting point\n";
3368 if (!defined($start_minconfig)) {
3369 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3372 my $temp_config = "$tmpdir/temp_config";
3374 # First things first. We build an allnoconfig to find
3375 # out what the defaults are that we can't touch.
3376 # Some are selections, but we really can't handle selections.
3378 my $save_minconfig = $minconfig;
3381 run_command "$make allnoconfig" or return 0;
3385 process_config_ignore $output_config;
3387 undef %save_configs;
3390 if (defined($ignore_config)) {
3391 # make sure the file exists
3392 `touch $ignore_config`;
3393 assign_configs \%save_configs, $ignore_config;
3396 %keep_configs = %save_configs;
3398 doprint "Load initial configs from $start_minconfig\n";
3400 # Look at the current min configs, and save off all the
3401 # ones that were set via the allnoconfig
3402 assign_configs \%min_configs, $start_minconfig;
3404 my @config_keys = keys %min_configs;
3406 # All configs need a depcount
3407 foreach my $config (@config_keys) {
3408 my $kconfig = chomp_config $config;
3409 if (!defined $depcount{$kconfig}) {
3410 $depcount{$kconfig} = 0;
3414 # Remove anything that was set by the make allnoconfig
3415 # we shouldn't need them as they get set for us anyway.
3416 foreach my $config (@config_keys) {
3417 # Remove anything in the ignore_config
3418 if (defined($keep_configs{$config})) {
3419 my $file = $ignore_config;
3420 $file =~ s,.*/(.*?)$,$1,;
3421 doprint "$config set by $file ... ignored\n";
3422 delete $min_configs{$config};
3425 # But make sure the settings are the same. If a min config
3426 # sets a selection, we do not want to get rid of it if
3427 # it is not the same as what we have. Just move it into
3429 if (defined($config_ignore{$config})) {
3430 if ($config_ignore{$config} ne $min_configs{$config}) {
3431 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3432 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3433 $keep_configs{$config} = $min_configs{$config};
3435 doprint "$config set by allnoconfig ... ignored\n";
3437 delete $min_configs{$config};
3449 # Now disable each config one by one and do a make oldconfig
3450 # till we find a config that changes our list.
3452 my @test_configs = keys %min_configs;
3454 # Sort keys by who is most dependent on
3455 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3458 # Put configs that did not modify the config at the end.
3460 for (my $i = 0; $i < $#test_configs; $i++) {
3461 if (!defined($nochange_config{$test_configs[0]})) {
3465 # This config didn't change the .config last time.
3466 # Place it at the end
3467 my $config = shift @test_configs;
3468 push @test_configs, $config;
3471 # if every test config has failed to modify the .config file
3472 # in the past, then reset and start over.
3474 undef %nochange_config;
3477 undef %processed_configs;
3479 foreach my $config (@test_configs) {
3481 $found = test_this_config $config;
3483 last if (defined($found));
3485 # oh well, try another config
3488 if (!defined($found)) {
3489 # we could have failed due to the nochange_config hash
3490 # reset and try again
3492 undef %nochange_config;
3496 doprint "No more configs found that we can disable\n";
3504 doprint "Test with $config disabled\n";
3506 # set in_bisect to keep build and monitor from dieing
3510 build "oldconfig" or $failed = 1;
3512 start_monitor_and_boot or $failed = 1;
3514 if ($type eq "test" && !$failed) {
3515 do_run_test or $failed = 1;
3524 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3525 # this config is needed, add it to the ignore list.
3526 $keep_configs{$config} = $min_configs{$config};
3527 $save_configs{$config} = $min_configs{$config};
3528 delete $min_configs{$config};
3530 # update new ignore configs
3531 if (defined($ignore_config)) {
3532 open (OUT, ">$temp_config")
3533 or die "Can't write to $temp_config";
3534 foreach my $config (keys %save_configs) {
3535 print OUT "$save_configs{$config}\n";
3538 run_command "mv $temp_config $ignore_config" or
3539 dodie "failed to copy update to $ignore_config";
3543 # We booted without this config, remove it from the minconfigs.
3544 doprint "$config is not needed, disabling\n";
3546 delete $min_configs{$config};
3548 # Also disable anything that is not enabled in this config
3550 assign_configs \%configs, $output_config;
3551 my @config_keys = keys %min_configs;
3552 foreach my $config (@config_keys) {
3553 if (!defined($configs{$config})) {
3554 doprint "$config is not set, disabling\n";
3555 delete $min_configs{$config};
3559 # Save off all the current mandidory configs
3560 open (OUT, ">$temp_config")
3561 or die "Can't write to $temp_config";
3562 foreach my $config (keys %keep_configs) {
3563 print OUT "$keep_configs{$config}\n";
3565 foreach my $config (keys %min_configs) {
3566 print OUT "$min_configs{$config}\n";
3570 run_command "mv $temp_config $output_minconfig" or
3571 dodie "failed to copy update to $output_minconfig";
3574 doprint "Reboot and wait $sleep_time seconds\n";
3575 reboot_to_good $sleep_time;
3582 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3585 $ktest_config = $ARGV[0];
3586 if (! -f $ktest_config) {
3587 print "$ktest_config does not exist.\n";
3588 if (!read_yn "Create it?") {
3593 $ktest_config = "ktest.conf";
3596 if (! -f $ktest_config) {
3599 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3601 # Generated by ktest.pl
3604 # PWD is a ktest.pl variable that will result in the process working
3605 # directory that ktest.pl is executed in.
3607 # THIS_DIR is automatically assigned the PWD of the path that generated
3608 # the config file. It is best to use this variable when assigning other
3609 # directory paths within this directory. This allows you to easily
3610 # move the test cases to other locations or to other machines.
3612 THIS_DIR := $variable{"PWD"}
3614 # Define each test with TEST_START
3615 # The config options below it will override the defaults
3617 TEST_TYPE = $default{"TEST_TYPE"}
3624 read_config $ktest_config;
3626 if (defined($opt{"LOG_FILE"})) {
3627 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3630 # Append any configs entered in manually to the config file.
3631 my @new_configs = keys %entered_configs;
3632 if ($#new_configs >= 0) {
3633 print "\nAppending entered in configs to $ktest_config\n";
3634 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3635 foreach my $config (@new_configs) {
3636 print OUT "$config = $entered_configs{$config}\n";
3637 $opt{$config} = process_variables($entered_configs{$config});
3641 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3642 unlink $opt{"LOG_FILE"};
3645 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3647 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3650 doprint "DEFAULT OPTIONS:\n";
3652 doprint "\nTEST $i OPTIONS";
3653 if (defined($repeat_tests{$i})) {
3654 $repeat = $repeat_tests{$i};
3655 doprint " ITERATE $repeat";
3660 foreach my $option (sort keys %opt) {
3662 if ($option =~ /\[(\d+)\]$/) {
3668 doprint "$option = $opt{$option}\n";
3672 sub __set_test_option {
3673 my ($name, $i) = @_;
3675 my $option = "$name\[$i\]";
3677 if (defined($opt{$option})) {
3678 return $opt{$option};
3681 foreach my $test (keys %repeat_tests) {
3683 $i < $test + $repeat_tests{$test}) {
3684 $option = "$name\[$test\]";
3685 if (defined($opt{$option})) {
3686 return $opt{$option};
3691 if (defined($opt{$name})) {
3698 sub set_test_option {
3699 my ($name, $i) = @_;
3701 my $option = __set_test_option($name, $i);
3702 return $option if (!defined($option));
3704 return eval_option($option, $i);
3707 # First we need to do is the builds
3708 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3710 # Do not reboot on failing test options
3712 $reboot_success = 0;
3718 undef %force_config;
3720 my $makecmd = set_test_option("MAKE_CMD", $i);
3722 # Load all the options into their mapped variable names
3723 foreach my $opt (keys %option_map) {
3724 ${$option_map{$opt}} = set_test_option($opt, $i);
3727 $start_minconfig_defined = 1;
3729 # The first test may override the PRE_KTEST option
3730 if (defined($pre_ktest) && $i == 1) {
3732 run_command $pre_ktest;
3735 # Any test can override the POST_KTEST option
3736 # The last test takes precedence.
3737 if (defined($post_ktest)) {
3738 $final_post_ktest = $post_ktest;
3741 if (!defined($start_minconfig)) {
3742 $start_minconfig_defined = 0;
3743 $start_minconfig = $minconfig;
3746 chdir $builddir || die "can't change directory to $builddir";
3748 foreach my $dir ($tmpdir, $outputdir) {
3751 die "can't create $dir";
3755 $ENV{"SSH_USER"} = $ssh_user;
3756 $ENV{"MACHINE"} = $machine;
3758 $buildlog = "$tmpdir/buildlog-$machine";
3759 $testlog = "$tmpdir/testlog-$machine";
3760 $dmesg = "$tmpdir/dmesg-$machine";
3761 $make = "$makecmd O=$outputdir";
3762 $output_config = "$outputdir/.config";
3765 $target = "$ssh_user\@$machine";
3766 if ($reboot_type eq "grub") {
3767 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3768 } elsif ($reboot_type eq "grub2") {
3769 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3770 dodie "GRUB_FILE not defined" if (!defined($grub_file));
3774 my $run_type = $build_type;
3775 if ($test_type eq "patchcheck") {
3776 $run_type = $patchcheck_type;
3777 } elsif ($test_type eq "bisect") {
3778 $run_type = $bisect_type;
3779 } elsif ($test_type eq "config_bisect") {
3780 $run_type = $config_bisect_type;
3783 if ($test_type eq "make_min_config") {
3787 # mistake in config file?
3788 if (!defined($run_type)) {
3789 $run_type = "ERROR";
3793 $installme = " no_install" if ($no_install);
3796 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3798 if (defined($pre_test)) {
3799 run_command $pre_test;
3806 if (defined($addconfig)) {
3807 my $min = $minconfig;
3808 if (!defined($minconfig)) {
3811 run_command "cat $addconfig $min > $tmpdir/add_config" or
3812 dodie "Failed to create temp config";
3813 $minconfig = "$tmpdir/add_config";
3816 if (defined($checkout)) {
3817 run_command "git checkout $checkout" or
3818 die "failed to checkout $checkout";
3823 # A test may opt to not reboot the box
3824 if ($reboot_on_success) {
3825 $reboot_success = 1;
3828 if ($test_type eq "bisect") {
3831 } elsif ($test_type eq "config_bisect") {
3834 } elsif ($test_type eq "patchcheck") {
3837 } elsif ($test_type eq "make_min_config") {
3842 if ($build_type ne "nobuild") {
3843 build $build_type or next;
3846 if ($test_type eq "install") {
3853 if ($test_type ne "build") {
3855 start_monitor_and_boot or $failed = 1;
3857 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3858 do_run_test or $failed = 1;
3867 if (defined($final_post_ktest)) {
3868 run_command $final_post_ktest;
3871 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3873 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
3875 } elsif (defined($switch_to_good)) {
3876 # still need to get to the good kernel
3877 run_command $switch_to_good;
3881 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";