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",
57 "SYSLINUX" => "extlinux",
58 "SYSLINUX_PATH" => "/boot/extlinux",
60 # required, and we will ask users if they don't have them but we keep the default
61 # value something that is common.
62 "REBOOT_TYPE" => "grub",
63 "LOCALVERSION" => "-test",
65 "BUILD_TARGET" => "arch/x86/boot/bzImage",
66 "TARGET_IMAGE" => "/boot/vmlinuz-test",
100 my $poweroff_on_error;
101 my $reboot_on_success;
103 my $powercycle_after_reboot;
104 my $poweroff_after_halt;
105 my $max_monitor_wait;
108 my $scp_to_target_install;
125 my $start_minconfig_defined;
126 my $output_minconfig;
128 my $use_output_minconfig;
133 my $bisect_bad_commit = "";
137 my $config_bisect_good;
141 my $bisect_ret_abort;
142 my $bisect_ret_default;
143 my $in_patchcheck = 0;
153 my $bisect_sleep_time;
154 my $patchcheck_sleep_time;
161 my $detect_triplefault;
163 my $reboot_success_line;
165 my $stop_after_success;
166 my $stop_after_failure;
185 my $config_bisect_type;
186 my $config_bisect_check;
189 my $patchcheck_start;
192 # set when a test is something other that just building or install
193 # which would require more options.
196 # set when creating a new config
203 # force_config is the list of configs that we force enabled (or disabled)
204 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
207 # do not force reboots on config problems
211 my $reboot_success = 0;
214 "MACHINE" => \$machine,
215 "SSH_USER" => \$ssh_user,
216 "TMP_DIR" => \$tmpdir,
217 "OUTPUT_DIR" => \$outputdir,
218 "BUILD_DIR" => \$builddir,
219 "TEST_TYPE" => \$test_type,
220 "PRE_KTEST" => \$pre_ktest,
221 "POST_KTEST" => \$post_ktest,
222 "PRE_TEST" => \$pre_test,
223 "POST_TEST" => \$post_test,
224 "BUILD_TYPE" => \$build_type,
225 "BUILD_OPTIONS" => \$build_options,
226 "PRE_BUILD" => \$pre_build,
227 "POST_BUILD" => \$post_build,
228 "PRE_BUILD_DIE" => \$pre_build_die,
229 "POST_BUILD_DIE" => \$post_build_die,
230 "POWER_CYCLE" => \$power_cycle,
231 "REBOOT" => \$reboot,
232 "BUILD_NOCLEAN" => \$noclean,
233 "MIN_CONFIG" => \$minconfig,
234 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
235 "START_MIN_CONFIG" => \$start_minconfig,
236 "MIN_CONFIG_TYPE" => \$minconfig_type,
237 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
238 "IGNORE_CONFIG" => \$ignore_config,
239 "TEST" => \$run_test,
240 "ADD_CONFIG" => \$addconfig,
241 "REBOOT_TYPE" => \$reboot_type,
242 "GRUB_MENU" => \$grub_menu,
243 "GRUB_FILE" => \$grub_file,
244 "GRUB_REBOOT" => \$grub_reboot,
245 "SYSLINUX" => \$syslinux,
246 "SYSLINUX_PATH" => \$syslinux_path,
247 "SYSLINUX_LABEL" => \$syslinux_label,
248 "PRE_INSTALL" => \$pre_install,
249 "POST_INSTALL" => \$post_install,
250 "NO_INSTALL" => \$no_install,
251 "REBOOT_SCRIPT" => \$reboot_script,
252 "REBOOT_ON_ERROR" => \$reboot_on_error,
253 "SWITCH_TO_GOOD" => \$switch_to_good,
254 "SWITCH_TO_TEST" => \$switch_to_test,
255 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
256 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
257 "DIE_ON_FAILURE" => \$die_on_failure,
258 "POWER_OFF" => \$power_off,
259 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
260 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
261 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
262 "SLEEP_TIME" => \$sleep_time,
263 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
264 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
265 "IGNORE_WARNINGS" => \$ignore_warnings,
266 "IGNORE_ERRORS" => \$ignore_errors,
267 "BISECT_MANUAL" => \$bisect_manual,
268 "BISECT_SKIP" => \$bisect_skip,
269 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
270 "BISECT_RET_GOOD" => \$bisect_ret_good,
271 "BISECT_RET_BAD" => \$bisect_ret_bad,
272 "BISECT_RET_SKIP" => \$bisect_ret_skip,
273 "BISECT_RET_ABORT" => \$bisect_ret_abort,
274 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
275 "STORE_FAILURES" => \$store_failures,
276 "STORE_SUCCESSES" => \$store_successes,
277 "TEST_NAME" => \$test_name,
278 "TIMEOUT" => \$timeout,
279 "BOOTED_TIMEOUT" => \$booted_timeout,
280 "CONSOLE" => \$console,
281 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
282 "SUCCESS_LINE" => \$success_line,
283 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
284 "STOP_AFTER_SUCCESS" => \$stop_after_success,
285 "STOP_AFTER_FAILURE" => \$stop_after_failure,
286 "STOP_TEST_AFTER" => \$stop_test_after,
287 "BUILD_TARGET" => \$build_target,
288 "SSH_EXEC" => \$ssh_exec,
289 "SCP_TO_TARGET" => \$scp_to_target,
290 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
291 "CHECKOUT" => \$checkout,
292 "TARGET_IMAGE" => \$target_image,
293 "LOCALVERSION" => \$localversion,
295 "BISECT_GOOD" => \$bisect_good,
296 "BISECT_BAD" => \$bisect_bad,
297 "BISECT_TYPE" => \$bisect_type,
298 "BISECT_START" => \$bisect_start,
299 "BISECT_REPLAY" => \$bisect_replay,
300 "BISECT_FILES" => \$bisect_files,
301 "BISECT_REVERSE" => \$bisect_reverse,
302 "BISECT_CHECK" => \$bisect_check,
304 "CONFIG_BISECT" => \$config_bisect,
305 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
306 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
308 "PATCHCHECK_TYPE" => \$patchcheck_type,
309 "PATCHCHECK_START" => \$patchcheck_start,
310 "PATCHCHECK_END" => \$patchcheck_end,
313 # Options may be used by other options, record them.
316 # default variables that can be used
317 chomp ($variable{"PWD"} = `pwd`);
319 $config_help{"MACHINE"} = << "EOF"
320 The machine hostname that you will test.
321 For build only tests, it is still needed to differentiate log files.
324 $config_help{"SSH_USER"} = << "EOF"
325 The box is expected to have ssh on normal bootup, provide the user
326 (most likely root, since you need privileged operations)
329 $config_help{"BUILD_DIR"} = << "EOF"
330 The directory that contains the Linux source code (full path).
331 You can use \${PWD} that will be the path where ktest.pl is run, or use
332 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
335 $config_help{"OUTPUT_DIR"} = << "EOF"
336 The directory that the objects will be built (full path).
337 (can not be same as BUILD_DIR)
338 You can use \${PWD} that will be the path where ktest.pl is run, or use
339 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
342 $config_help{"BUILD_TARGET"} = << "EOF"
343 The location of the compiled file to copy to the target.
344 (relative to OUTPUT_DIR)
347 $config_help{"BUILD_OPTIONS"} = << "EOF"
348 Options to add to \"make\" when building.
352 $config_help{"TARGET_IMAGE"} = << "EOF"
353 The place to put your image on the test machine.
356 $config_help{"POWER_CYCLE"} = << "EOF"
357 A script or command to reboot the box.
359 Here is a digital loggers power switch example
360 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
362 Here is an example to reboot a virtual box on the current host
363 with the name "Guest".
364 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
367 $config_help{"CONSOLE"} = << "EOF"
368 The script or command that reads the console
370 If you use ttywatch server, something like the following would work.
371 CONSOLE = nc -d localhost 3001
373 For a virtual machine with guest name "Guest".
374 CONSOLE = virsh console Guest
377 $config_help{"LOCALVERSION"} = << "EOF"
378 Required version ending to differentiate the test
379 from other linux builds on the system.
382 $config_help{"REBOOT_TYPE"} = << "EOF"
383 Way to reboot the box to the test kernel.
384 Only valid options so far are "grub", "grub2", "syslinux", and "script".
386 If you specify grub, it will assume grub version 1
387 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
388 and select that target to reboot to the kernel. If this is not
389 your setup, then specify "script" and have a command or script
390 specified in REBOOT_SCRIPT to boot to the target.
392 The entry in /boot/grub/menu.lst must be entered in manually.
393 The test will not modify that file.
395 If you specify grub2, then you also need to specify both \$GRUB_MENU
398 If you specify syslinux, then you may use SYSLINUX to define the syslinux
399 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
400 the syslinux install (defaults to /boot/extlinux). But you have to specify
401 SYSLINUX_LABEL to define the label to boot to for the test kernel.
404 $config_help{"GRUB_MENU"} = << "EOF"
405 The grub title name for the test kernel to boot
406 (Only mandatory if REBOOT_TYPE = grub or grub2)
408 Note, ktest.pl will not update the grub menu.lst, you need to
409 manually add an option for the test. ktest.pl will search
410 the grub menu.lst for this option to find what kernel to
413 For example, if in the /boot/grub/menu.lst the test kernel title has:
416 GRUB_MENU = Test Kernel
418 For grub2, a search of \$GRUB_FILE is performed for the lines
419 that begin with "menuentry". It will not detect submenus. The
420 menu must be a non-nested menu. Add the quotes used in the menu
421 to guarantee your selection, as the first menuentry with the content
422 of \$GRUB_MENU that is found will be used.
425 $config_help{"GRUB_FILE"} = << "EOF"
426 If grub2 is used, the full path for the grub.cfg file is placed
427 here. Use something like /boot/grub2/grub.cfg to search.
430 $config_help{"SYSLINUX_LABEL"} = << "EOF"
431 If syslinux is used, the label that boots the target kernel must
432 be specified with SYSLINUX_LABEL.
435 $config_help{"REBOOT_SCRIPT"} = << "EOF"
436 A script to reboot the target into the test kernel
437 (Only mandatory if REBOOT_TYPE = script)
442 my ($cancel, $prompt) = @_;
448 print "$prompt [y/n/C] ";
450 print "$prompt [Y/n] ";
454 if ($ans =~ /^\s*$/) {
461 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
463 last if ($ans =~ /^c$/i);
464 print "Please answer either 'y', 'n' or 'c'.\n";
466 print "Please answer either 'y' or 'n'.\n";
472 if ($ans !~ /^y$/i) {
481 return read_prompt 0, $prompt;
487 return read_prompt 1, $prompt;
490 sub get_ktest_config {
494 return if (defined($opt{$config}));
496 if (defined($config_help{$config})) {
498 print $config_help{$config};
503 if (defined($default{$config}) && length($default{$config})) {
504 print "\[$default{$config}\] ";
507 $ans =~ s/^\s*(.*\S)\s*$/$1/;
508 if ($ans =~ /^\s*$/) {
509 if ($default{$config}) {
510 $ans = $default{$config};
512 print "Your answer can not be blank\n";
516 $entered_configs{$config} = ${ans};
521 sub get_ktest_configs {
522 get_ktest_config("MACHINE");
523 get_ktest_config("BUILD_DIR");
524 get_ktest_config("OUTPUT_DIR");
527 get_ktest_config("BUILD_OPTIONS");
530 # options required for other than just building a kernel
532 get_ktest_config("POWER_CYCLE");
533 get_ktest_config("CONSOLE");
536 # options required for install and more
537 if ($buildonly != 1) {
538 get_ktest_config("SSH_USER");
539 get_ktest_config("BUILD_TARGET");
540 get_ktest_config("TARGET_IMAGE");
543 get_ktest_config("LOCALVERSION");
545 return if ($buildonly);
547 my $rtype = $opt{"REBOOT_TYPE"};
549 if (!defined($rtype)) {
550 if (!defined($opt{"GRUB_MENU"})) {
551 get_ktest_config("REBOOT_TYPE");
552 $rtype = $entered_configs{"REBOOT_TYPE"};
558 if ($rtype eq "grub") {
559 get_ktest_config("GRUB_MENU");
562 if ($rtype eq "grub2") {
563 get_ktest_config("GRUB_MENU");
564 get_ktest_config("GRUB_FILE");
567 if ($rtype eq "syslinux") {
568 get_ktest_config("SYSLINUX_LABEL");
572 sub process_variables {
573 my ($value, $remove_undef) = @_;
576 # We want to check for '\', and it is just easier
577 # to check the previous characet of '$' and not need
578 # to worry if '$' is the first character. By adding
579 # a space to $value, we can just check [^\\]\$ and
580 # it will still work.
583 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
587 # append beginning of value to retval
588 $retval = "$retval$begin";
589 if (defined($variable{$var})) {
590 $retval = "$retval$variable{$var}";
591 } elsif (defined($remove_undef) && $remove_undef) {
592 # for if statements, any variable that is not defined,
593 # we simple convert to 0
594 $retval = "${retval}0";
596 # put back the origin piece.
597 $retval = "$retval\$\{$var\}";
598 # This could be an option that is used later, save
599 # it so we don't warn if this option is not one of
601 $used_options{$var} = 1;
605 $retval = "$retval$value";
607 # remove the space added in the beginning
614 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
616 my $prvalue = process_variables($rvalue);
618 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
619 # Note if a test is something other than build, then we
620 # will need other manditory options.
621 if ($prvalue ne "install") {
624 # install still limits some manditory options.
629 if (defined($opt{$lvalue})) {
630 if (!$override || defined(${$overrides}{$lvalue})) {
633 $extra = "In the same override section!\n";
635 die "$name: $.: Option $lvalue defined more than once!\n$extra";
637 ${$overrides}{$lvalue} = $prvalue;
639 if ($rvalue =~ /^\s*$/) {
640 delete $opt{$lvalue};
642 $opt{$lvalue} = $prvalue;
647 my ($lvalue, $rvalue) = @_;
649 if ($rvalue =~ /^\s*$/) {
650 delete $variable{$lvalue};
652 $rvalue = process_variables($rvalue);
653 $variable{$lvalue} = $rvalue;
657 sub process_compare {
658 my ($lval, $cmp, $rval) = @_;
669 return $lval eq $rval;
670 } elsif ($cmp eq "!=") {
671 return $lval ne $rval;
672 } elsif ($cmp eq "=~") {
673 return $lval =~ m/$rval/;
674 } elsif ($cmp eq "!~") {
675 return $lval !~ m/$rval/;
678 my $statement = "$lval $cmp $rval";
679 my $ret = eval $statement;
681 # $@ stores error of eval
692 return defined($variable{$2}) ||
697 sub process_expression {
698 my ($name, $val) = @_;
702 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
705 if (process_expression($name, $express)) {
706 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
708 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
716 while ($val =~ s/^(.*?)($OR|$AND)//) {
720 if (process_expression($name, $express)) {
731 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
732 my $ret = process_compare($1, $2, $3);
734 die "$name: $.: Unable to process comparison\n";
739 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
741 return !value_defined($2);
743 return value_defined($2);
747 if ($val =~ /^\s*0\s*$/) {
749 } elsif ($val =~ /^\s*\d+\s*$/) {
753 die ("$name: $.: Undefined content $val in if statement\n");
757 my ($name, $value) = @_;
759 # Convert variables and replace undefined ones with 0
760 my $val = process_variables($value, 1);
761 my $ret = process_expression $name, $val;
767 my ($config, $current_test_num) = @_;
770 open($in, $config) || die "can't read file $config";
773 $name =~ s,.*/(.*),$1,;
775 my $test_num = $$current_test_num;
778 my $num_tests_set = 0;
791 # ignore blank lines and comments
792 next if (/^\s*$/ || /\s*\#/);
794 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
804 if ($type eq "TEST_START") {
806 if ($num_tests_set) {
807 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
810 $old_test_num = $test_num;
811 $old_repeat = $repeat;
813 $test_num += $repeat;
820 # If SKIP is anywhere in the line, the command will be skipped
821 if ($rest =~ s/\s+SKIP\b//) {
828 if ($rest =~ s/\sELSE\b//) {
830 die "$name: $.: ELSE found with out matching IF section\n$_";
841 if ($rest =~ s/\sIF\s+(.*)//) {
842 if (process_if($name, $1)) {
854 if ($type eq "TEST_START") {
855 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
857 $repeat_tests{"$test_num"} = $repeat;
859 } elsif ($rest =~ s/\sOVERRIDE\b//) {
862 # Clear previous overrides
867 if (!$skip && $rest !~ /^\s*$/) {
868 die "$name: $.: Gargbage found after $type\n$_";
871 if ($skip && $type eq "TEST_START") {
872 $test_num = $old_test_num;
873 $repeat = $old_repeat;
876 } elsif (/^\s*ELSE\b(.*)$/) {
878 die "$name: $.: ELSE found with out matching IF section\n$_";
887 if ($rest =~ /\sIF\s+(.*)/) {
888 # May be a ELSE IF section.
889 if (process_if($name, $1)) {
900 if ($rest !~ /^\s*$/) {
901 die "$name: $.: Gargbage found after DEFAULTS\n$_";
904 } elsif (/^\s*INCLUDE\s+(\S+)/) {
909 die "$name: $.: INCLUDE can only be done in default sections\n$_";
912 my $file = process_variables($1);
914 if ($file !~ m,^/,) {
915 # check the path of the config file first
916 if ($config =~ m,(.*)/,) {
924 die "$name: $.: Can't read file $file\n$_";
927 if (__read_config($file, \$test_num)) {
931 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
939 ($lvalue eq "NUM_TESTS" ||
940 $lvalue eq "LOG_FILE" ||
941 $lvalue eq "CLEAR_LOG")) {
942 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
945 if ($lvalue eq "NUM_TESTS") {
947 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
950 die "$name: $.: NUM_TESTS must be set in default section\n";
955 if ($default || $lvalue =~ /\[\d+\]$/) {
956 set_value($lvalue, $rvalue, $override, \%overrides, $name);
958 my $val = "$lvalue\[$test_num\]";
959 set_value($val, $rvalue, $override, \%overrides, $name);
962 $repeats{$val} = $repeat;
965 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
971 # process config variables.
972 # Config variables are only active while reading the
973 # config and can be defined anywhere. They also ignore
974 # TEST_START and DEFAULTS, but are skipped if they are in
975 # on of these sections that have SKIP defined.
976 # The save variable can be
977 # defined multiple times and the new one simply overrides
979 set_variable($lvalue, $rvalue);
982 die "$name: $.: Garbage found in config\n$_";
987 $test_num += $repeat - 1;
988 $opt{"NUM_TESTS"} = $test_num;
993 $$current_test_num = $test_num;
999 print "What test case would you like to run?\n";
1000 print " (build, install or boot)\n";
1001 print " Other tests are available but require editing the config file\n";
1004 $default{"TEST_TYPE"} = $ans;
1013 $test_case = __read_config $config, \$test_num;
1015 # make sure we have all mandatory configs
1018 # was a test specified?
1020 print "No test case specified.\n";
1026 foreach my $default (keys %default) {
1027 if (!defined($opt{$default})) {
1028 $opt{$default} = $default{$default};
1032 if ($opt{"IGNORE_UNUSED"} == 1) {
1038 # check if there are any stragglers (typos?)
1039 foreach my $option (keys %opt) {
1041 # remove per test labels.
1043 if (!exists($option_map{$op}) &&
1044 !exists($default{$op}) &&
1045 !exists($used_options{$op})) {
1052 $s = " is" if (keys %not_used == 1);
1053 print "The following option$s not used; could be a typo:\n";
1054 foreach my $option (keys %not_used) {
1057 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1058 if (!read_yn "Do you want to continue?") {
1065 my ($option, $i) = @_;
1067 # Add space to evaluate the character before $
1068 $option = " $option";
1073 foreach my $test (keys %repeat_tests) {
1075 $i < $test + $repeat_tests{$test}) {
1083 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1088 # Append beginning of line
1089 $retval = "$retval$start";
1091 # If the iteration option OPT[$i] exists, then use that.
1092 # otherwise see if the default OPT (without [$i]) exists.
1094 my $o = "$var\[$i\]";
1095 my $parento = "$var\[$parent\]";
1097 if (defined($opt{$o})) {
1099 $retval = "$retval$o";
1100 } elsif ($repeated && defined($opt{$parento})) {
1101 $o = $opt{$parento};
1102 $retval = "$retval$o";
1103 } elsif (defined($opt{$var})) {
1105 $retval = "$retval$o";
1107 $retval = "$retval\$\{$var\}";
1113 $retval = "$retval$option";
1121 my ($option, $i) = @_;
1125 # Since an option can evaluate to another option,
1126 # keep iterating until we do not evaluate any more
1129 while ($prev ne $option) {
1130 # Check for recursive evaluations.
1131 # 100 deep should be more than enough.
1133 die "Over 100 evaluations accurred with $option\n" .
1134 "Check for recursive variables\n";
1137 $option = __eval_option($option, $i);
1144 if (defined($opt{"LOG_FILE"})) {
1145 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1152 if (defined($opt{"LOG_FILE"})) {
1167 sub wait_for_monitor;
1172 # Make sure everything has been written to disk
1175 if (defined($time)) {
1177 # flush out current monitor
1178 # May contain the reboot success line
1182 # try to reboot normally
1183 if (run_command $reboot) {
1184 if (defined($powercycle_after_reboot)) {
1185 sleep $powercycle_after_reboot;
1186 run_command "$power_cycle";
1189 # nope? power cycle it.
1190 run_command "$power_cycle";
1193 if (defined($time)) {
1194 if (wait_for_monitor($time, $reboot_success_line)) {
1196 doprint "Reboot did not finish. Forcing power cycle\n";
1197 run_command "$power_cycle";
1203 sub reboot_to_good {
1206 if (defined($switch_to_good)) {
1207 run_command $switch_to_good;
1216 return $test_type eq "build" || $no_reboot ||
1217 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1218 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1222 doprint "CRITICAL FAILURE... ", @_, "\n";
1226 if ($reboot_on_error && !do_not_reboot) {
1228 doprint "REBOOTING\n";
1231 } elsif ($poweroff_on_error && defined($power_off)) {
1232 doprint "POWERING OFF\n";
1236 if (defined($opt{"LOG_FILE"})) {
1237 print " See $opt{LOG_FILE} for more info.\n";
1248 my $pid = open($fp, "$console|") or
1249 dodie "Can't open console $console";
1251 $flags = fcntl($fp, F_GETFL, 0) or
1252 dodie "Can't get flags for the socket: $!";
1253 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1254 dodie "Can't set flags for the socket: $!";
1260 my ($fp, $pid) = @_;
1262 doprint "kill child process $pid\n";
1270 if ($monitor_cnt++) {
1273 $monitor_fp = \*MONFD;
1274 $monitor_pid = open_console $monitor_fp;
1278 open(MONFD, "Stop perl from warning about single use of MONFD");
1282 if (--$monitor_cnt) {
1285 close_console($monitor_fp, $monitor_pid);
1288 sub wait_for_monitor {
1289 my ($time, $stop) = @_;
1293 my $start_time = time;
1294 my $skip_call_trace = 0;
1296 my $bug_ignored = 0;
1299 doprint "** Wait for monitor to settle down **\n";
1301 # read the monitor and wait for the system to calm down
1303 $line = wait_for_input($monitor_fp, $time);
1304 last if (!defined($line));
1306 $full_line .= $line;
1308 if (defined($stop) && $full_line =~ /$stop/) {
1309 doprint "wait for monitor detected $stop\n";
1313 if ($full_line =~ /\[ backtrace testing \]/) {
1314 $skip_call_trace = 1;
1317 if ($full_line =~ /call trace:/i) {
1318 if (!$bug && !$skip_call_trace) {
1319 if ($ignore_errors) {
1327 if ($full_line =~ /\[ end of backtrace testing \]/) {
1328 $skip_call_trace = 0;
1331 if ($full_line =~ /Kernel panic -/) {
1335 if ($line =~ /\n/) {
1339 if ($now - $start_time >= $max_monitor_wait) {
1340 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1344 print "** Monitor flushed **\n";
1349 my ($result, $basedir) = @_;
1351 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1352 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1354 my $type = $build_type;
1355 if ($type =~ /useconfig/) {
1356 $type = "useconfig";
1359 my $dir = "$machine-$test_type-$type-$result-$date";
1361 $dir = "$basedir/$dir";
1365 die "can't create $dir";
1369 "config" => $output_config,
1370 "buildlog" => $buildlog,
1372 "testlog" => $testlog,
1375 while (my ($name, $source) = each(%files)) {
1377 cp "$source", "$dir/$name" or
1378 die "failed to copy $source";
1382 doprint "*** Saved info to $dir ***\n";
1387 if (defined($post_test)) {
1388 run_command $post_test;
1391 if ($die_on_failure) {
1399 # no need to reboot for just building.
1400 if (!do_not_reboot) {
1401 doprint "REBOOTING\n";
1402 reboot_to_good $sleep_time;
1407 if (defined($test_name)) {
1408 $name = " ($test_name)";
1411 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1412 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1413 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1414 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1415 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1417 if (defined($store_failures)) {
1418 save_logs "fail", $store_failures;
1430 $command =~ s/\$SSH_USER/$ssh_user/g;
1431 $command =~ s/\$MACHINE/$machine/g;
1433 doprint("$command ... ");
1435 $pid = open(CMD, "$command 2>&1 |") or
1436 (fail "unable to exec $command" and return 0);
1438 if (defined($opt{"LOG_FILE"})) {
1439 open(LOG, ">>$opt{LOG_FILE}") or
1440 dodie "failed to write to log";
1444 if (defined($redirect)) {
1445 open (RD, ">$redirect") or
1446 dodie "failed to write to redirect $redirect";
1451 print LOG if ($dolog);
1452 print RD if ($dord);
1459 close(LOG) if ($dolog);
1460 close(RD) if ($dord);
1463 doprint "FAILED!\n";
1465 doprint "SUCCESS\n";
1473 my $cp_exec = $ssh_exec;
1475 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1476 return run_command "$cp_exec";
1480 my ($src, $dst, $cp_scp) = @_;
1482 $cp_scp =~ s/\$SRC_FILE/$src/g;
1483 $cp_scp =~ s/\$DST_FILE/$dst/g;
1485 return run_command "$cp_scp";
1488 sub run_scp_install {
1489 my ($src, $dst) = @_;
1491 my $cp_scp = $scp_to_target_install;
1493 return run_scp($src, $dst, $cp_scp);
1497 my ($src, $dst) = @_;
1499 my $cp_scp = $scp_to_target;
1501 return run_scp($src, $dst, $cp_scp);
1504 sub get_grub2_index {
1506 return if (defined($grub_number));
1508 doprint "Find grub2 menu ... ";
1511 my $ssh_grub = $ssh_exec;
1512 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1514 open(IN, "$ssh_grub |")
1515 or die "unable to get $grub_file";
1520 if (/^menuentry.*$grub_menu/) {
1524 } elsif (/^menuentry\s/) {
1530 die "Could not find '$grub_menu' in $grub_file on $machine"
1532 doprint "$grub_number\n";
1535 sub get_grub_index {
1537 if ($reboot_type eq "grub2") {
1542 if ($reboot_type ne "grub") {
1545 return if (defined($grub_number));
1547 doprint "Find grub menu ... ";
1550 my $ssh_grub = $ssh_exec;
1551 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1553 open(IN, "$ssh_grub |")
1554 or die "unable to get menu.lst";
1559 if (/^\s*title\s+$grub_menu\s*$/) {
1563 } elsif (/^\s*title\s/) {
1569 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1571 doprint "$grub_number\n";
1576 my ($fp, $time) = @_;
1582 if (!defined($time)) {
1587 vec($rin, fileno($fp), 1) = 1;
1588 $ready = select($rin, undef, undef, $time);
1592 # try to read one char at a time
1593 while (sysread $fp, $ch, 1) {
1595 last if ($ch eq "\n");
1598 if (!length($line)) {
1606 if (defined($switch_to_test)) {
1607 run_command $switch_to_test;
1610 if ($reboot_type eq "grub") {
1611 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1612 } elsif ($reboot_type eq "grub2") {
1613 run_ssh "$grub_reboot $grub_number";
1614 } elsif ($reboot_type eq "syslinux") {
1615 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
1616 } elsif (defined $reboot_script) {
1617 run_command "$reboot_script";
1625 doprint "git rev-list --max-count=1 $commit ... ";
1626 my $sha1 = `git rev-list --max-count=1 $commit`;
1633 dodie "Failed to get git $commit";
1646 my $bug_ignored = 0;
1647 my $skip_call_trace = 0;
1655 open(DMESG, "> $dmesg") or
1656 die "unable to write to $dmesg";
1662 my $monitor_start = time;
1664 my $version_found = 0;
1668 if ($bug && defined($stop_after_failure) &&
1669 $stop_after_failure >= 0) {
1670 my $time = $stop_after_failure - (time - $failure_start);
1671 $line = wait_for_input($monitor_fp, $time);
1672 if (!defined($line)) {
1673 doprint "bug timed out after $booted_timeout seconds\n";
1674 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1678 $line = wait_for_input($monitor_fp, $booted_timeout);
1679 if (!defined($line)) {
1680 my $s = $booted_timeout == 1 ? "" : "s";
1681 doprint "Successful boot found: break after $booted_timeout second$s\n";
1685 $line = wait_for_input($monitor_fp);
1686 if (!defined($line)) {
1687 my $s = $timeout == 1 ? "" : "s";
1688 doprint "Timed out after $timeout second$s\n";
1696 # we are not guaranteed to get a full line
1697 $full_line .= $line;
1699 if ($full_line =~ /$success_line/) {
1701 $success_start = time;
1704 if ($booted && defined($stop_after_success) &&
1705 $stop_after_success >= 0) {
1707 if ($now - $success_start >= $stop_after_success) {
1708 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1713 if ($full_line =~ /\[ backtrace testing \]/) {
1714 $skip_call_trace = 1;
1717 if ($full_line =~ /call trace:/i) {
1718 if (!$bug && !$skip_call_trace) {
1719 if ($ignore_errors) {
1723 $failure_start = time;
1728 if ($bug && defined($stop_after_failure) &&
1729 $stop_after_failure >= 0) {
1731 if ($now - $failure_start >= $stop_after_failure) {
1732 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1737 if ($full_line =~ /\[ end of backtrace testing \]/) {
1738 $skip_call_trace = 0;
1741 if ($full_line =~ /Kernel panic -/) {
1742 $failure_start = time;
1746 # Detect triple faults by testing the banner
1747 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1748 if ($1 eq $version) {
1750 } elsif ($version_found && $detect_triplefault) {
1751 # We already booted into the kernel we are testing,
1752 # but now we booted into another kernel?
1753 # Consider this a triple fault.
1754 doprint "Aleady booted in Linux kernel $version, but now\n";
1755 doprint "we booted into Linux kernel $1.\n";
1756 doprint "Assuming that this is a triple fault.\n";
1757 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1762 if ($line =~ /\n/) {
1766 if ($stop_test_after > 0 && !$booted && !$bug) {
1767 if (time - $monitor_start > $stop_test_after) {
1768 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1777 return 0 if ($in_bisect);
1778 fail "failed - got a bug report" and return 0;
1782 return 0 if ($in_bisect);
1783 fail "failed - never got a boot prompt." and return 0;
1787 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1793 sub eval_kernel_version {
1796 $option =~ s/\$KERNEL_VERSION/$version/g;
1801 sub do_post_install {
1803 return if (!defined($post_install));
1805 my $cp_post_install = eval_kernel_version $post_install;
1806 run_command "$cp_post_install" or
1807 dodie "Failed to run post install";
1810 # Sometimes the reboot fails, and will hang. We try to ssh to the box
1811 # and if we fail, we force another reboot, that should powercycle it.
1813 if (!run_ssh "echo testing connection") {
1820 return if ($no_install);
1822 if (defined($pre_install)) {
1823 my $cp_pre_install = eval_kernel_version $pre_install;
1824 run_command "$cp_pre_install" or
1825 dodie "Failed to run pre install";
1828 my $cp_target = eval_kernel_version $target_image;
1832 run_scp_install "$outputdir/$build_target", "$cp_target" or
1833 dodie "failed to copy image";
1835 my $install_mods = 0;
1837 # should we process modules?
1839 open(IN, "$output_config") or dodie("Can't read config file");
1841 if (/CONFIG_MODULES(=y)?/) {
1850 if (!$install_mods) {
1852 doprint "No modules needed\n";
1856 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1857 dodie "Failed to install modules";
1859 my $modlib = "/lib/modules/$version";
1860 my $modtar = "ktest-mods.tar.bz2";
1862 run_ssh "rm -rf $modlib" or
1863 dodie "failed to remove old mods: $modlib";
1865 # would be nice if scp -r did not follow symbolic links
1866 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1867 dodie "making tarball";
1869 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1870 dodie "failed to copy modules";
1872 unlink "$tmpdir/$modtar";
1874 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1875 dodie "failed to tar modules";
1877 run_ssh "rm -f /tmp/$modtar";
1883 # get the release name
1884 return if ($have_version);
1885 doprint "$make kernelrelease ... ";
1886 $version = `$make kernelrelease | tail -1`;
1888 doprint "$version\n";
1892 sub start_monitor_and_boot {
1893 # Make sure the stable kernel has finished booting
1906 sub check_buildlog {
1909 my @files = `git show $patch | diffstat -l`;
1911 open(IN, "git show $patch |") or
1912 dodie "failed to show $patch";
1914 if (m,^--- a/(.*),) {
1916 $files[$#files] = $1;
1921 open(IN, $buildlog) or dodie "Can't open $buildlog";
1923 if (/^\s*(.*?):.*(warning|error)/) {
1925 foreach my $file (@files) {
1926 my $fullpath = "$builddir/$file";
1927 if ($file eq $err || $fullpath eq $err) {
1928 fail "$file built with warnings" and return 0;
1938 sub apply_min_config {
1939 my $outconfig = "$output_config.new";
1941 # Read the config file and remove anything that
1942 # is in the force_config hash (from minconfig and others)
1943 # then add the force config back.
1945 doprint "Applying minimum configurations into $output_config.new\n";
1947 open (OUT, ">$outconfig") or
1948 dodie "Can't create $outconfig";
1950 if (-f $output_config) {
1951 open (IN, $output_config) or
1952 dodie "Failed to open $output_config";
1954 if (/^(# )?(CONFIG_[^\s=]*)/) {
1955 next if (defined($force_config{$2}));
1961 foreach my $config (keys %force_config) {
1962 print OUT "$force_config{$config}\n";
1966 run_command "mv $outconfig $output_config";
1969 sub make_oldconfig {
1971 my @force_list = keys %force_config;
1973 if ($#force_list >= 0) {
1977 if (!run_command "$make olddefconfig") {
1978 # Perhaps olddefconfig doesn't exist in this version of the kernel
1980 doprint "olddefconfig failed, trying make oldnoconfig\n";
1981 if (!run_command "$make oldnoconfig") {
1982 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1983 # try a yes '' | oldconfig
1984 run_command "yes '' | $make oldconfig" or
1985 dodie "failed make config oldconfig";
1990 # read a config file and use this to force new configs.
1991 sub load_force_config {
1994 doprint "Loading force configs from $config\n";
1995 open(IN, $config) or
1996 dodie "failed to read $config";
1999 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2000 $force_config{$1} = $_;
2001 } elsif (/^# (CONFIG_\S*) is not set/) {
2002 $force_config{$1} = $_;
2013 # Failed builds should not reboot the target
2014 my $save_no_reboot = $no_reboot;
2017 # Calculate a new version from here.
2020 if (defined($pre_build)) {
2021 my $ret = run_command $pre_build;
2022 if (!$ret && defined($pre_build_die) &&
2024 dodie "failed to pre_build\n";
2028 if ($type =~ /^useconfig:(.*)/) {
2029 run_command "cp $1 $output_config" or
2030 dodie "could not copy $1 to .config";
2032 $type = "oldconfig";
2035 # old config can ask questions
2036 if ($type eq "oldconfig") {
2037 $type = "olddefconfig";
2039 # allow for empty configs
2040 run_command "touch $output_config";
2043 run_command "mv $output_config $outputdir/config_temp" or
2044 dodie "moving .config";
2046 run_command "$make mrproper" or dodie "make mrproper";
2048 run_command "mv $outputdir/config_temp $output_config" or
2049 dodie "moving config_temp";
2052 } elsif (!$noclean) {
2053 unlink "$output_config";
2054 run_command "$make mrproper" or
2055 dodie "make mrproper";
2058 # add something to distinguish this build
2059 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2060 print OUT "$localversion\n";
2063 if (defined($minconfig)) {
2064 load_force_config($minconfig);
2067 if ($type ne "olddefconfig") {
2068 run_command "$make $type" or
2069 dodie "failed make config";
2071 # Run old config regardless, to enforce min configurations
2074 $redirect = "$buildlog";
2075 my $build_ret = run_command "$make $build_options";
2078 if (defined($post_build)) {
2079 # Because a post build may change the kernel version
2082 my $ret = run_command $post_build;
2083 if (!$ret && defined($post_build_die) &&
2085 dodie "failed to post_build\n";
2090 # bisect may need this to pass
2092 $no_reboot = $save_no_reboot;
2095 fail "failed build" and return 0;
2098 $no_reboot = $save_no_reboot;
2104 if (!run_ssh "halt" or defined($power_off)) {
2105 if (defined($poweroff_after_halt)) {
2106 sleep $poweroff_after_halt;
2107 run_command "$power_off";
2111 run_command "$power_off";
2118 if (defined($post_test)) {
2119 run_command $post_test;
2126 if (defined($test_name)) {
2127 $name = " ($test_name)";
2130 doprint "\n\n*******************************************\n";
2131 doprint "*******************************************\n";
2132 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2133 doprint "*******************************************\n";
2134 doprint "*******************************************\n";
2136 if (defined($store_successes)) {
2137 save_logs "success", $store_successes;
2140 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2141 doprint "Reboot and wait $sleep_time seconds\n";
2142 reboot_to_good $sleep_time;
2148 doprint "Pass or fail? [p/f]";
2151 if ($ans eq "p" || $ans eq "P") {
2153 } elsif ($ans eq "f" || $ans eq "F") {
2156 print "Please answer 'P' or 'F'\n";
2161 sub child_run_test {
2164 # child should have no power
2165 $reboot_on_error = 0;
2166 $poweroff_on_error = 0;
2167 $die_on_failure = 1;
2169 $redirect = "$testlog";
2170 run_command $run_test or $failed = 1;
2178 sub child_finished {
2188 my $bug_ignored = 0;
2192 doprint "run test $run_test\n";
2196 $SIG{CHLD} = qw(child_finished);
2200 child_run_test if (!$child_pid);
2205 $line = wait_for_input($monitor_fp, 1);
2206 if (defined($line)) {
2208 # we are not guaranteed to get a full line
2209 $full_line .= $line;
2212 if ($full_line =~ /call trace:/i) {
2213 if ($ignore_errors) {
2220 if ($full_line =~ /Kernel panic -/) {
2224 if ($line =~ /\n/) {
2228 } while (!$child_done && !$bug);
2230 if (!$bug && $bug_ignored) {
2231 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2235 my $failure_start = time;
2238 $line = wait_for_input($monitor_fp, 1);
2239 if (defined($line)) {
2243 if ($now - $failure_start >= $stop_after_failure) {
2246 } while (defined($line));
2248 doprint "Detected kernel crash!\n";
2249 # kill the child with extreme prejudice
2253 waitpid $child_pid, 0;
2256 if (!$bug && $in_bisect) {
2257 if (defined($bisect_ret_good)) {
2258 if ($child_exit == $bisect_ret_good) {
2262 if (defined($bisect_ret_skip)) {
2263 if ($child_exit == $bisect_ret_skip) {
2267 if (defined($bisect_ret_abort)) {
2268 if ($child_exit == $bisect_ret_abort) {
2269 fail "test abort" and return -2;
2272 if (defined($bisect_ret_bad)) {
2273 if ($child_exit == $bisect_ret_skip) {
2277 if (defined($bisect_ret_default)) {
2278 if ($bisect_ret_default eq "good") {
2280 } elsif ($bisect_ret_default eq "bad") {
2282 } elsif ($bisect_ret_default eq "skip") {
2284 } elsif ($bisect_ret_default eq "abort") {
2287 fail "unknown default action: $bisect_ret_default"
2293 if ($bug || $child_exit) {
2294 return 0 if $in_bisect;
2295 fail "test failed" and return 0;
2300 sub run_git_bisect {
2303 doprint "$command ... ";
2305 my $output = `$command 2>&1`;
2312 dodie "Failed to git bisect";
2315 doprint "SUCCESS\n";
2316 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2317 doprint "$1 [$2]\n";
2318 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2319 $bisect_bad_commit = $1;
2320 doprint "Found bad commit... $1\n";
2323 # we already logged it, just print it now.
2331 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2332 reboot_to_good $bisect_sleep_time;
2335 # returns 1 on success, 0 on failure, -1 on skip
2336 sub run_bisect_test {
2337 my ($type, $buildtype) = @_;
2346 build $buildtype or $failed = 1;
2348 if ($type ne "build") {
2349 if ($failed && $bisect_skip) {
2353 dodie "Failed on build" if $failed;
2356 start_monitor_and_boot or $failed = 1;
2358 if ($type ne "boot") {
2359 if ($failed && $bisect_skip) {
2365 dodie "Failed on boot" if $failed;
2367 do_run_test or $failed = 1;
2378 # reboot the box to a kernel we can ssh to
2379 if ($type ne "build") {
2389 my $buildtype = "oldconfig";
2391 # We should have a minconfig to use?
2392 if (defined($minconfig)) {
2393 $buildtype = "useconfig:$minconfig";
2396 my $ret = run_bisect_test $type, $buildtype;
2398 if ($bisect_manual) {
2399 $ret = answer_bisect;
2402 # Are we looking for where it worked, not failed?
2403 if ($reverse_bisect && $ret >= 0) {
2409 } elsif ($ret == 0) {
2411 } elsif ($bisect_skip) {
2412 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2417 sub update_bisect_replay {
2418 my $tmp_log = "$tmpdir/ktest_bisect_log";
2419 run_command "git bisect log > $tmp_log" or
2420 die "can't create bisect log";
2429 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2430 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2431 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2433 my $good = $bisect_good;
2434 my $bad = $bisect_bad;
2435 my $type = $bisect_type;
2436 my $start = $bisect_start;
2437 my $replay = $bisect_replay;
2438 my $start_files = $bisect_files;
2440 if (defined($start_files)) {
2441 $start_files = " -- " . $start_files;
2446 # convert to true sha1's
2447 $good = get_sha1($good);
2448 $bad = get_sha1($bad);
2450 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2451 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2452 $reverse_bisect = 1;
2454 $reverse_bisect = 0;
2457 # Can't have a test without having a test to run
2458 if ($type eq "test" && !defined($run_test)) {
2462 # Check if a bisect was running
2463 my $bisect_start_file = "$builddir/.git/BISECT_START";
2465 my $check = $bisect_check;
2466 my $do_check = defined($check) && $check ne "0";
2468 if ( -f $bisect_start_file ) {
2469 print "Bisect in progress found\n";
2471 print " If you say yes, then no checks of good or bad will be done\n";
2473 if (defined($replay)) {
2474 print "** BISECT_REPLAY is defined in config file **";
2475 print " Ignore config option and perform new git bisect log?\n";
2476 if (read_ync " (yes, no, or cancel) ") {
2477 $replay = update_bisect_replay;
2480 } elsif (read_yn "read git log and continue?") {
2481 $replay = update_bisect_replay;
2489 my $head = get_sha1("HEAD");
2491 if ($check ne "good") {
2492 doprint "TESTING BISECT BAD [$bad]\n";
2493 run_command "git checkout $bad" or
2494 die "Failed to checkout $bad";
2496 $result = run_bisect $type;
2498 if ($result ne "bad") {
2499 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2503 if ($check ne "bad") {
2504 doprint "TESTING BISECT GOOD [$good]\n";
2505 run_command "git checkout $good" or
2506 die "Failed to checkout $good";
2508 $result = run_bisect $type;
2510 if ($result ne "good") {
2511 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2515 # checkout where we started
2516 run_command "git checkout $head" or
2517 die "Failed to checkout $head";
2520 run_command "git bisect start$start_files" or
2521 dodie "could not start bisect";
2523 run_command "git bisect good $good" or
2524 dodie "could not set bisect good to $good";
2526 run_git_bisect "git bisect bad $bad" or
2527 dodie "could not set bisect bad to $bad";
2529 if (defined($replay)) {
2530 run_command "git bisect replay $replay" or
2531 dodie "failed to run replay";
2534 if (defined($start)) {
2535 run_command "git checkout $start" or
2536 dodie "failed to checkout $start";
2541 $result = run_bisect $type;
2542 $test = run_git_bisect "git bisect $result";
2545 run_command "git bisect log" or
2546 dodie "could not capture git bisect log";
2548 run_command "git bisect reset" or
2549 dodie "could not reset git bisect";
2551 doprint "Bad commit was [$bisect_bad_commit]\n";
2556 # config_ignore holds the configs that were set (or unset) for
2557 # a good config and we will ignore these configs for the rest
2558 # of a config bisect. These configs stay as they were.
2561 # config_set holds what all configs were set as.
2564 # config_off holds the set of configs that the bad config had disabled.
2565 # We need to record them and set them in the .config when running
2566 # olddefconfig, because olddefconfig keeps the defaults.
2569 # config_off_tmp holds a set of configs to turn off for now
2572 # config_list is the set of configs that are being tested
2578 sub assign_configs {
2579 my ($hash, $config) = @_;
2582 or dodie "Failed to read $config";
2585 if (/^((CONFIG\S*)=.*)/) {
2593 sub process_config_ignore {
2596 assign_configs \%config_ignore, $config;
2599 sub read_current_config {
2600 my ($config_ref) = @_;
2602 %{$config_ref} = ();
2603 undef %{$config_ref};
2605 my @key = keys %{$config_ref};
2607 print "did not delete!\n";
2610 open (IN, "$output_config");
2613 if (/^(CONFIG\S+)=(.*)/) {
2614 ${$config_ref}{$1} = $2;
2620 sub get_dependencies {
2623 my $arr = $dependency{$config};
2624 if (!defined($arr)) {
2630 foreach my $dep (@{$arr}) {
2631 print "ADD DEP $dep\n";
2632 @deps = (@deps, get_dependencies $dep);
2641 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2643 foreach my $config (@configs) {
2644 print OUT "$config_set{$config}\n";
2645 my @deps = get_dependencies $config;
2646 foreach my $dep (@deps) {
2647 print OUT "$config_set{$dep}\n";
2651 # turn off configs to keep off
2652 foreach my $config (keys %config_off) {
2653 print OUT "# $config is not set\n";
2656 # turn off configs that should be off for now
2657 foreach my $config (@config_off_tmp) {
2658 print OUT "# $config is not set\n";
2661 foreach my $config (keys %config_ignore) {
2662 print OUT "$config_ignore{$config}\n";
2669 sub compare_configs {
2672 foreach my $item (keys %a) {
2673 if (!defined($b{$item})) {
2674 print "diff $item\n";
2682 print "diff2 $keys[0]\n";
2684 return -1 if ($#keys >= 0);
2689 sub run_config_bisect_test {
2692 return run_bisect_test $type, "oldconfig";
2695 sub process_passed {
2698 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2699 # Passed! All these configs are part of a good compile.
2700 # Add them to the min options.
2701 foreach my $config (keys %configs) {
2702 if (defined($config_list{$config})) {
2703 doprint " removing $config\n";
2704 $config_ignore{$config} = $config_list{$config};
2705 delete $config_list{$config};
2708 doprint "config copied to $outputdir/config_good\n";
2709 run_command "cp -f $output_config $outputdir/config_good";
2712 sub process_failed {
2715 doprint "\n\n***************************************\n";
2716 doprint "Found bad config: $config\n";
2717 doprint "***************************************\n\n";
2720 sub run_config_bisect {
2722 my @start_list = keys %config_list;
2724 if ($#start_list < 0) {
2725 doprint "No more configs to test!!!\n";
2729 doprint "***** RUN TEST ***\n";
2730 my $type = $config_bisect_type;
2734 my $count = $#start_list + 1;
2735 doprint " $count configs to test\n";
2737 my $half = int($#start_list / 2);
2740 my @tophalf = @start_list[0 .. $half];
2742 # keep the bottom half off
2743 if ($half < $#start_list) {
2744 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2746 @config_off_tmp = ();
2749 create_config @tophalf;
2750 read_current_config \%current_config;
2752 $count = $#tophalf + 1;
2753 doprint "Testing $count configs\n";
2755 # make sure we test something
2756 foreach my $config (@tophalf) {
2757 if (defined($current_config{$config})) {
2763 # try the other half
2764 doprint "Top half produced no set configs, trying bottom half\n";
2766 # keep the top half off
2767 @config_off_tmp = @tophalf;
2768 @tophalf = @start_list[$half + 1 .. $#start_list];
2770 create_config @tophalf;
2771 read_current_config \%current_config;
2772 foreach my $config (@tophalf) {
2773 if (defined($current_config{$config})) {
2779 doprint "Failed: Can't make new config with current configs\n";
2780 foreach my $config (@start_list) {
2781 doprint " CONFIG: $config\n";
2785 $count = $#tophalf + 1;
2786 doprint "Testing $count configs\n";
2789 $ret = run_config_bisect_test $type;
2790 if ($bisect_manual) {
2791 $ret = answer_bisect;
2794 process_passed %current_config;
2798 doprint "This config had a failure.\n";
2799 doprint "Removing these configs that were not set in this config:\n";
2800 doprint "config copied to $outputdir/config_bad\n";
2801 run_command "cp -f $output_config $outputdir/config_bad";
2803 # A config exists in this group that was bad.
2804 foreach my $config (keys %config_list) {
2805 if (!defined($current_config{$config})) {
2806 doprint " removing $config\n";
2807 delete $config_list{$config};
2811 @start_list = @tophalf;
2813 if ($#start_list == 0) {
2814 process_failed $start_list[0];
2818 # remove half the configs we are looking at and see if
2820 $half = int($#start_list / 2);
2821 } while ($#start_list > 0);
2823 # we found a single config, try it again unless we are running manually
2825 if ($bisect_manual) {
2826 process_failed $start_list[0];
2830 my @tophalf = @start_list[0 .. 0];
2832 $ret = run_config_bisect_test $type;
2834 process_passed %current_config;
2838 process_failed $start_list[0];
2845 my $start_config = $config_bisect;
2847 my $tmpconfig = "$tmpdir/use_config";
2849 if (defined($config_bisect_good)) {
2850 process_config_ignore $config_bisect_good;
2853 # Make the file with the bad config and the min config
2854 if (defined($minconfig)) {
2855 # read the min config for things to ignore
2856 run_command "cp $minconfig $tmpconfig" or
2857 dodie "failed to copy $minconfig to $tmpconfig";
2862 if (-f $tmpconfig) {
2863 load_force_config($tmpconfig);
2864 process_config_ignore $tmpconfig;
2867 # now process the start config
2868 run_command "cp $start_config $output_config" or
2869 dodie "failed to copy $start_config to $output_config";
2871 # read directly what we want to check
2873 open (IN, $output_config)
2874 or dodie "failed to open $output_config";
2877 if (/^((CONFIG\S*)=.*)/) {
2878 $config_check{$2} = $1;
2883 # Now run oldconfig with the minconfig
2886 # check to see what we lost (or gained)
2887 open (IN, $output_config)
2888 or dodie "Failed to read $start_config";
2890 my %removed_configs;
2894 if (/^((CONFIG\S*)=.*)/) {
2895 # save off all options
2896 $config_set{$2} = $1;
2897 if (defined($config_check{$2})) {
2898 if (defined($config_ignore{$2})) {
2899 $removed_configs{$2} = $1;
2901 $config_list{$2} = $1;
2903 } elsif (!defined($config_ignore{$2})) {
2904 $added_configs{$2} = $1;
2905 $config_list{$2} = $1;
2907 } elsif (/^# ((CONFIG\S*).*)/) {
2908 # Keep these configs disabled
2909 $config_set{$2} = $1;
2910 $config_off{$2} = $1;
2915 my @confs = keys %removed_configs;
2917 doprint "Configs overridden by default configs and removed from check:\n";
2918 foreach my $config (@confs) {
2919 doprint " $config\n";
2922 @confs = keys %added_configs;
2924 doprint "Configs appearing in make oldconfig and added:\n";
2925 foreach my $config (@confs) {
2926 doprint " $config\n";
2933 @config_off_tmp = ();
2935 # Sometimes kconfig does weird things. We must make sure
2936 # that the config we autocreate has everything we need
2937 # to test, otherwise we may miss testing configs, or
2938 # may not be able to create a new config.
2939 # Here we create a config with everything set.
2940 create_config (keys %config_list);
2941 read_current_config \%config_test;
2942 foreach my $config (keys %config_list) {
2943 if (!defined($config_test{$config})) {
2946 doprint "Configs not produced by kconfig (will not be checked):\n";
2948 doprint " $config\n";
2949 delete $config_list{$config};
2954 if (defined($config_bisect_check) && $config_bisect_check) {
2955 doprint " Checking to make sure bad config with min config fails\n";
2956 create_config keys %config_list;
2957 $ret = run_config_bisect_test $config_bisect_type;
2959 doprint " FAILED! Bad config with min config boots fine\n";
2962 doprint " Bad config with min config fails as expected\n";
2966 $ret = run_config_bisect;
2969 return $ret if ($ret < 0);
2974 sub patchcheck_reboot {
2975 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2976 reboot_to_good $patchcheck_sleep_time;
2982 die "PATCHCHECK_START[$i] not defined\n"
2983 if (!defined($patchcheck_start));
2984 die "PATCHCHECK_TYPE[$i] not defined\n"
2985 if (!defined($patchcheck_type));
2987 my $start = $patchcheck_start;
2990 if (defined($patchcheck_end)) {
2991 $end = $patchcheck_end;
2994 # Get the true sha1's since we can use things like HEAD~3
2995 $start = get_sha1($start);
2996 $end = get_sha1($end);
2998 my $type = $patchcheck_type;
3000 # Can't have a test without having a test to run
3001 if ($type eq "test" && !defined($run_test)) {
3005 open (IN, "git log --pretty=oneline $end|") or
3006 dodie "could not get git list";
3012 $list[$#list+1] = $_;
3013 last if (/^$start/);
3017 if ($list[$#list] !~ /^$start/) {
3018 fail "SHA1 $start not found";
3021 # go backwards in the list
3022 @list = reverse @list;
3024 my $save_clean = $noclean;
3025 my %ignored_warnings;
3027 if (defined($ignore_warnings)) {
3028 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3029 $ignored_warnings{$sha1} = 1;
3034 foreach my $item (@list) {
3036 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3038 doprint "\nProcessing commit $item\n\n";
3040 run_command "git checkout $sha1" or
3041 die "Failed to checkout $sha1";
3043 # only clean on the first and last patch
3044 if ($item eq $list[0] ||
3045 $item eq $list[$#list]) {
3046 $noclean = $save_clean;
3051 if (defined($minconfig)) {
3052 build "useconfig:$minconfig" or return 0;
3054 # ?? no config to use?
3055 build "oldconfig" or return 0;
3059 if (!defined($ignored_warnings{$sha1})) {
3060 check_buildlog $sha1 or return 0;
3063 next if ($type eq "build");
3067 start_monitor_and_boot or $failed = 1;
3069 if (!$failed && $type ne "boot"){
3070 do_run_test or $failed = 1;
3073 return 0 if ($failed);
3093 # $config depends on $dep
3094 my ($config, $dep) = @_;
3096 if (defined($depends{$config})) {
3097 $depends{$config} .= " " . $dep;
3099 $depends{$config} = $dep;
3102 # record the number of configs depending on $dep
3103 if (defined $depcount{$dep}) {
3106 $depcount{$dep} = 1;
3110 # taken from streamline_config.pl
3122 if (! -f $kconfig) {
3123 doprint "file $kconfig does not exist, skipping\n";
3127 open(KIN, "$kconfig")
3128 or die "Can't open $kconfig";
3132 # Make sure that lines ending with \ continue
3134 $_ = $line . " " . $_;
3145 # collect any Kconfig sources
3146 if (/^source\s*"(.*)"/) {
3147 $kconfigs[$#kconfigs+1] = $1;
3151 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3155 for (my $i = 0; $i < $iflevel; $i++) {
3156 add_dep $config, $ifdeps[$i];
3159 # collect the depends for the config
3160 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3162 add_dep $config, $1;
3164 # Get the configs that select this config
3165 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3167 # selected by depends on config
3168 add_dep $1, $config;
3170 # Check for if statements
3171 } elsif (/^if\s+(.*\S)\s*$/) {
3173 # remove beginning and ending non text
3174 $deps =~ s/^[^a-zA-Z0-9_]*//;
3175 $deps =~ s/[^a-zA-Z0-9_]*$//;
3177 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3179 $ifdeps[$iflevel++] = join ':', @deps;
3181 } elsif (/^endif/) {
3183 $iflevel-- if ($iflevel);
3186 } elsif (/^\s*help\s*$/) {
3192 # read in any configs that were found.
3193 foreach $kconfig (@kconfigs) {
3194 if (!defined($read_kconfigs{$kconfig})) {
3195 $read_kconfigs{$kconfig} = 1;
3196 read_kconfig("$builddir/$kconfig");
3202 # find out which arch this is by the kconfig file
3203 open (IN, $output_config)
3204 or dodie "Failed to read $output_config";
3207 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3214 if (!defined($arch)) {
3215 doprint "Could not find arch from config file\n";
3216 doprint "no dependencies used\n";
3220 # arch is really the subarch, we need to know
3221 # what directory to look at.
3222 if ($arch eq "i386" || $arch eq "x86_64") {
3224 } elsif ($arch =~ /^tile/) {
3228 my $kconfig = "$builddir/arch/$arch/Kconfig";
3230 if (! -f $kconfig && $arch =~ /\d$/) {
3232 # some subarchs have numbers, truncate them
3234 $kconfig = "$builddir/arch/$arch/Kconfig";
3235 if (! -f $kconfig) {
3236 doprint "No idea what arch dir $orig is for\n";
3237 doprint "no dependencies used\n";
3242 read_kconfig($kconfig);
3245 sub read_config_list {
3249 or dodie "Failed to read $config";
3252 if (/^((CONFIG\S*)=.*)/) {
3253 if (!defined($config_ignore{$2})) {
3254 $config_list{$2} = $1;
3262 sub read_output_config {
3265 assign_configs \%config_ignore, $config;
3268 sub make_new_config {
3271 open (OUT, ">$output_config")
3272 or dodie "Failed to write $output_config";
3274 foreach my $config (@configs) {
3275 print OUT "$config\n";
3283 $config =~ s/CONFIG_//;
3291 my $kconfig = chomp_config $dep;
3293 $dep = $depends{"$kconfig"};
3295 # the dep string we have saves the dependencies as they
3296 # were found, including expressions like ! && ||. We
3297 # want to split this out into just an array of configs.
3299 my $valid = "A-Za-z_0-9";
3303 while ($dep =~ /[$valid]/) {
3305 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3306 my $conf = "CONFIG_" . $1;
3308 $configs[$#configs + 1] = $conf;
3310 $dep =~ s/^[^$valid]*[$valid]+//;
3312 die "this should never happen";
3322 my %processed_configs;
3323 my %nochange_config;
3325 sub test_this_config {
3330 # if we already processed this config, skip it
3331 if (defined($processed_configs{$config})) {
3334 $processed_configs{$config} = 1;
3336 # if this config failed during this round, skip it
3337 if (defined($nochange_config{$config})) {
3341 my $kconfig = chomp_config $config;
3343 # Test dependencies first
3344 if (defined($depends{"$kconfig"})) {
3345 my @parents = get_depends $config;
3346 foreach my $parent (@parents) {
3347 # if the parent is in the min config, check it first
3348 next if (!defined($min_configs{$parent}));
3349 $found = test_this_config($parent);
3350 if (defined($found)) {
3356 # Remove this config from the list of configs
3357 # do a make olddefconfig and then read the resulting
3358 # .config to make sure it is missing the config that
3360 my %configs = %min_configs;
3361 delete $configs{$config};
3362 make_new_config ((values %configs), (values %keep_configs));
3365 assign_configs \%configs, $output_config;
3367 return $config if (!defined($configs{$config}));
3369 doprint "disabling config $config did not change .config\n";
3371 $nochange_config{$config} = 1;
3376 sub make_min_config {
3379 my $type = $minconfig_type;
3380 if ($type ne "boot" && $type ne "test") {
3381 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3382 " make_min_config works only with 'boot' and 'test'\n" and return;
3385 if (!defined($output_minconfig)) {
3386 fail "OUTPUT_MIN_CONFIG not defined" and return;
3389 # If output_minconfig exists, and the start_minconfig
3390 # came from min_config, than ask if we should use
3392 if (-f $output_minconfig && !$start_minconfig_defined) {
3393 print "$output_minconfig exists\n";
3394 if (!defined($use_output_minconfig)) {
3395 if (read_yn " Use it as minconfig?") {
3396 $start_minconfig = $output_minconfig;
3398 } elsif ($use_output_minconfig > 0) {
3399 doprint "Using $output_minconfig as MIN_CONFIG\n";
3400 $start_minconfig = $output_minconfig;
3402 doprint "Set to still use MIN_CONFIG as starting point\n";
3406 if (!defined($start_minconfig)) {
3407 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3410 my $temp_config = "$tmpdir/temp_config";
3412 # First things first. We build an allnoconfig to find
3413 # out what the defaults are that we can't touch.
3414 # Some are selections, but we really can't handle selections.
3416 my $save_minconfig = $minconfig;
3419 run_command "$make allnoconfig" or return 0;
3423 process_config_ignore $output_config;
3425 undef %save_configs;
3428 if (defined($ignore_config)) {
3429 # make sure the file exists
3430 `touch $ignore_config`;
3431 assign_configs \%save_configs, $ignore_config;
3434 %keep_configs = %save_configs;
3436 doprint "Load initial configs from $start_minconfig\n";
3438 # Look at the current min configs, and save off all the
3439 # ones that were set via the allnoconfig
3440 assign_configs \%min_configs, $start_minconfig;
3442 my @config_keys = keys %min_configs;
3444 # All configs need a depcount
3445 foreach my $config (@config_keys) {
3446 my $kconfig = chomp_config $config;
3447 if (!defined $depcount{$kconfig}) {
3448 $depcount{$kconfig} = 0;
3452 # Remove anything that was set by the make allnoconfig
3453 # we shouldn't need them as they get set for us anyway.
3454 foreach my $config (@config_keys) {
3455 # Remove anything in the ignore_config
3456 if (defined($keep_configs{$config})) {
3457 my $file = $ignore_config;
3458 $file =~ s,.*/(.*?)$,$1,;
3459 doprint "$config set by $file ... ignored\n";
3460 delete $min_configs{$config};
3463 # But make sure the settings are the same. If a min config
3464 # sets a selection, we do not want to get rid of it if
3465 # it is not the same as what we have. Just move it into
3467 if (defined($config_ignore{$config})) {
3468 if ($config_ignore{$config} ne $min_configs{$config}) {
3469 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3470 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3471 $keep_configs{$config} = $min_configs{$config};
3473 doprint "$config set by allnoconfig ... ignored\n";
3475 delete $min_configs{$config};
3487 # Now disable each config one by one and do a make oldconfig
3488 # till we find a config that changes our list.
3490 my @test_configs = keys %min_configs;
3492 # Sort keys by who is most dependent on
3493 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3496 # Put configs that did not modify the config at the end.
3498 for (my $i = 0; $i < $#test_configs; $i++) {
3499 if (!defined($nochange_config{$test_configs[0]})) {
3503 # This config didn't change the .config last time.
3504 # Place it at the end
3505 my $config = shift @test_configs;
3506 push @test_configs, $config;
3509 # if every test config has failed to modify the .config file
3510 # in the past, then reset and start over.
3512 undef %nochange_config;
3515 undef %processed_configs;
3517 foreach my $config (@test_configs) {
3519 $found = test_this_config $config;
3521 last if (defined($found));
3523 # oh well, try another config
3526 if (!defined($found)) {
3527 # we could have failed due to the nochange_config hash
3528 # reset and try again
3530 undef %nochange_config;
3534 doprint "No more configs found that we can disable\n";
3542 doprint "Test with $config disabled\n";
3544 # set in_bisect to keep build and monitor from dieing
3548 build "oldconfig" or $failed = 1;
3550 start_monitor_and_boot or $failed = 1;
3552 if ($type eq "test" && !$failed) {
3553 do_run_test or $failed = 1;
3562 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3563 # this config is needed, add it to the ignore list.
3564 $keep_configs{$config} = $min_configs{$config};
3565 $save_configs{$config} = $min_configs{$config};
3566 delete $min_configs{$config};
3568 # update new ignore configs
3569 if (defined($ignore_config)) {
3570 open (OUT, ">$temp_config")
3571 or die "Can't write to $temp_config";
3572 foreach my $config (keys %save_configs) {
3573 print OUT "$save_configs{$config}\n";
3576 run_command "mv $temp_config $ignore_config" or
3577 dodie "failed to copy update to $ignore_config";
3581 # We booted without this config, remove it from the minconfigs.
3582 doprint "$config is not needed, disabling\n";
3584 delete $min_configs{$config};
3586 # Also disable anything that is not enabled in this config
3588 assign_configs \%configs, $output_config;
3589 my @config_keys = keys %min_configs;
3590 foreach my $config (@config_keys) {
3591 if (!defined($configs{$config})) {
3592 doprint "$config is not set, disabling\n";
3593 delete $min_configs{$config};
3597 # Save off all the current mandidory configs
3598 open (OUT, ">$temp_config")
3599 or die "Can't write to $temp_config";
3600 foreach my $config (keys %keep_configs) {
3601 print OUT "$keep_configs{$config}\n";
3603 foreach my $config (keys %min_configs) {
3604 print OUT "$min_configs{$config}\n";
3608 run_command "mv $temp_config $output_minconfig" or
3609 dodie "failed to copy update to $output_minconfig";
3612 doprint "Reboot and wait $sleep_time seconds\n";
3613 reboot_to_good $sleep_time;
3620 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3623 $ktest_config = $ARGV[0];
3624 if (! -f $ktest_config) {
3625 print "$ktest_config does not exist.\n";
3626 if (!read_yn "Create it?") {
3631 $ktest_config = "ktest.conf";
3634 if (! -f $ktest_config) {
3637 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3639 # Generated by ktest.pl
3642 # PWD is a ktest.pl variable that will result in the process working
3643 # directory that ktest.pl is executed in.
3645 # THIS_DIR is automatically assigned the PWD of the path that generated
3646 # the config file. It is best to use this variable when assigning other
3647 # directory paths within this directory. This allows you to easily
3648 # move the test cases to other locations or to other machines.
3650 THIS_DIR := $variable{"PWD"}
3652 # Define each test with TEST_START
3653 # The config options below it will override the defaults
3655 TEST_TYPE = $default{"TEST_TYPE"}
3662 read_config $ktest_config;
3664 if (defined($opt{"LOG_FILE"})) {
3665 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3668 # Append any configs entered in manually to the config file.
3669 my @new_configs = keys %entered_configs;
3670 if ($#new_configs >= 0) {
3671 print "\nAppending entered in configs to $ktest_config\n";
3672 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3673 foreach my $config (@new_configs) {
3674 print OUT "$config = $entered_configs{$config}\n";
3675 $opt{$config} = process_variables($entered_configs{$config});
3679 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3680 unlink $opt{"LOG_FILE"};
3683 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3685 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3688 doprint "DEFAULT OPTIONS:\n";
3690 doprint "\nTEST $i OPTIONS";
3691 if (defined($repeat_tests{$i})) {
3692 $repeat = $repeat_tests{$i};
3693 doprint " ITERATE $repeat";
3698 foreach my $option (sort keys %opt) {
3700 if ($option =~ /\[(\d+)\]$/) {
3706 doprint "$option = $opt{$option}\n";
3710 sub __set_test_option {
3711 my ($name, $i) = @_;
3713 my $option = "$name\[$i\]";
3715 if (defined($opt{$option})) {
3716 return $opt{$option};
3719 foreach my $test (keys %repeat_tests) {
3721 $i < $test + $repeat_tests{$test}) {
3722 $option = "$name\[$test\]";
3723 if (defined($opt{$option})) {
3724 return $opt{$option};
3729 if (defined($opt{$name})) {
3736 sub set_test_option {
3737 my ($name, $i) = @_;
3739 my $option = __set_test_option($name, $i);
3740 return $option if (!defined($option));
3742 return eval_option($option, $i);
3745 # First we need to do is the builds
3746 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3748 # Do not reboot on failing test options
3750 $reboot_success = 0;
3756 undef %force_config;
3758 my $makecmd = set_test_option("MAKE_CMD", $i);
3760 # Load all the options into their mapped variable names
3761 foreach my $opt (keys %option_map) {
3762 ${$option_map{$opt}} = set_test_option($opt, $i);
3765 $start_minconfig_defined = 1;
3767 # The first test may override the PRE_KTEST option
3768 if (defined($pre_ktest) && $i == 1) {
3770 run_command $pre_ktest;
3773 # Any test can override the POST_KTEST option
3774 # The last test takes precedence.
3775 if (defined($post_ktest)) {
3776 $final_post_ktest = $post_ktest;
3779 if (!defined($start_minconfig)) {
3780 $start_minconfig_defined = 0;
3781 $start_minconfig = $minconfig;
3784 chdir $builddir || die "can't change directory to $builddir";
3786 foreach my $dir ($tmpdir, $outputdir) {
3789 die "can't create $dir";
3793 $ENV{"SSH_USER"} = $ssh_user;
3794 $ENV{"MACHINE"} = $machine;
3796 $buildlog = "$tmpdir/buildlog-$machine";
3797 $testlog = "$tmpdir/testlog-$machine";
3798 $dmesg = "$tmpdir/dmesg-$machine";
3799 $make = "$makecmd O=$outputdir";
3800 $output_config = "$outputdir/.config";
3803 $target = "$ssh_user\@$machine";
3804 if ($reboot_type eq "grub") {
3805 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3806 } elsif ($reboot_type eq "grub2") {
3807 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3808 dodie "GRUB_FILE not defined" if (!defined($grub_file));
3809 } elsif ($reboot_type eq "syslinux") {
3810 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
3814 my $run_type = $build_type;
3815 if ($test_type eq "patchcheck") {
3816 $run_type = $patchcheck_type;
3817 } elsif ($test_type eq "bisect") {
3818 $run_type = $bisect_type;
3819 } elsif ($test_type eq "config_bisect") {
3820 $run_type = $config_bisect_type;
3823 if ($test_type eq "make_min_config") {
3827 # mistake in config file?
3828 if (!defined($run_type)) {
3829 $run_type = "ERROR";
3833 $installme = " no_install" if ($no_install);
3836 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3838 if (defined($pre_test)) {
3839 run_command $pre_test;
3846 if (defined($addconfig)) {
3847 my $min = $minconfig;
3848 if (!defined($minconfig)) {
3851 run_command "cat $addconfig $min > $tmpdir/add_config" or
3852 dodie "Failed to create temp config";
3853 $minconfig = "$tmpdir/add_config";
3856 if (defined($checkout)) {
3857 run_command "git checkout $checkout" or
3858 die "failed to checkout $checkout";
3863 # A test may opt to not reboot the box
3864 if ($reboot_on_success) {
3865 $reboot_success = 1;
3868 if ($test_type eq "bisect") {
3871 } elsif ($test_type eq "config_bisect") {
3874 } elsif ($test_type eq "patchcheck") {
3877 } elsif ($test_type eq "make_min_config") {
3882 if ($build_type ne "nobuild") {
3883 build $build_type or next;
3886 if ($test_type eq "install") {
3893 if ($test_type ne "build") {
3895 start_monitor_and_boot or $failed = 1;
3897 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3898 do_run_test or $failed = 1;
3907 if (defined($final_post_ktest)) {
3908 run_command $final_post_ktest;
3911 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3913 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
3915 } elsif (defined($switch_to_good)) {
3916 # still need to get to the good kernel
3917 run_command $switch_to_good;
3921 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";