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,
57 # required, and we will ask users if they don't have them but we keep the default
58 # value something that is common.
59 "REBOOT_TYPE" => "grub",
60 "LOCALVERSION" => "-test",
62 "BUILD_TARGET" => "arch/x86/boot/bzImage",
63 "TARGET_IMAGE" => "/boot/vmlinuz-test",
97 my $poweroff_on_error;
98 my $reboot_on_success;
100 my $powercycle_after_reboot;
101 my $poweroff_after_halt;
102 my $max_monitor_wait;
105 my $scp_to_target_install;
117 my $start_minconfig_defined;
118 my $output_minconfig;
120 my $use_output_minconfig;
125 my $bisect_bad_commit = "";
129 my $config_bisect_good;
133 my $bisect_ret_abort;
134 my $bisect_ret_default;
135 my $in_patchcheck = 0;
145 my $bisect_sleep_time;
146 my $patchcheck_sleep_time;
153 my $detect_triplefault;
155 my $reboot_success_line;
157 my $stop_after_success;
158 my $stop_after_failure;
177 my $config_bisect_type;
178 my $config_bisect_check;
181 my $patchcheck_start;
184 # set when a test is something other that just building or install
185 # which would require more options.
188 # set when creating a new config
195 # force_config is the list of configs that we force enabled (or disabled)
196 # in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
199 # do not force reboots on config problems
203 my $reboot_success = 0;
206 "MACHINE" => \$machine,
207 "SSH_USER" => \$ssh_user,
208 "TMP_DIR" => \$tmpdir,
209 "OUTPUT_DIR" => \$outputdir,
210 "BUILD_DIR" => \$builddir,
211 "TEST_TYPE" => \$test_type,
212 "PRE_KTEST" => \$pre_ktest,
213 "POST_KTEST" => \$post_ktest,
214 "PRE_TEST" => \$pre_test,
215 "POST_TEST" => \$post_test,
216 "BUILD_TYPE" => \$build_type,
217 "BUILD_OPTIONS" => \$build_options,
218 "PRE_BUILD" => \$pre_build,
219 "POST_BUILD" => \$post_build,
220 "PRE_BUILD_DIE" => \$pre_build_die,
221 "POST_BUILD_DIE" => \$post_build_die,
222 "POWER_CYCLE" => \$power_cycle,
223 "REBOOT" => \$reboot,
224 "BUILD_NOCLEAN" => \$noclean,
225 "MIN_CONFIG" => \$minconfig,
226 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
227 "START_MIN_CONFIG" => \$start_minconfig,
228 "MIN_CONFIG_TYPE" => \$minconfig_type,
229 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
230 "IGNORE_CONFIG" => \$ignore_config,
231 "TEST" => \$run_test,
232 "ADD_CONFIG" => \$addconfig,
233 "REBOOT_TYPE" => \$reboot_type,
234 "GRUB_MENU" => \$grub_menu,
235 "PRE_INSTALL" => \$pre_install,
236 "POST_INSTALL" => \$post_install,
237 "NO_INSTALL" => \$no_install,
238 "REBOOT_SCRIPT" => \$reboot_script,
239 "REBOOT_ON_ERROR" => \$reboot_on_error,
240 "SWITCH_TO_GOOD" => \$switch_to_good,
241 "SWITCH_TO_TEST" => \$switch_to_test,
242 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
243 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
244 "DIE_ON_FAILURE" => \$die_on_failure,
245 "POWER_OFF" => \$power_off,
246 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
247 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
248 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
249 "SLEEP_TIME" => \$sleep_time,
250 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
251 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
252 "IGNORE_WARNINGS" => \$ignore_warnings,
253 "IGNORE_ERRORS" => \$ignore_errors,
254 "BISECT_MANUAL" => \$bisect_manual,
255 "BISECT_SKIP" => \$bisect_skip,
256 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
257 "BISECT_RET_GOOD" => \$bisect_ret_good,
258 "BISECT_RET_BAD" => \$bisect_ret_bad,
259 "BISECT_RET_SKIP" => \$bisect_ret_skip,
260 "BISECT_RET_ABORT" => \$bisect_ret_abort,
261 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
262 "STORE_FAILURES" => \$store_failures,
263 "STORE_SUCCESSES" => \$store_successes,
264 "TEST_NAME" => \$test_name,
265 "TIMEOUT" => \$timeout,
266 "BOOTED_TIMEOUT" => \$booted_timeout,
267 "CONSOLE" => \$console,
268 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
269 "SUCCESS_LINE" => \$success_line,
270 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
271 "STOP_AFTER_SUCCESS" => \$stop_after_success,
272 "STOP_AFTER_FAILURE" => \$stop_after_failure,
273 "STOP_TEST_AFTER" => \$stop_test_after,
274 "BUILD_TARGET" => \$build_target,
275 "SSH_EXEC" => \$ssh_exec,
276 "SCP_TO_TARGET" => \$scp_to_target,
277 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
278 "CHECKOUT" => \$checkout,
279 "TARGET_IMAGE" => \$target_image,
280 "LOCALVERSION" => \$localversion,
282 "BISECT_GOOD" => \$bisect_good,
283 "BISECT_BAD" => \$bisect_bad,
284 "BISECT_TYPE" => \$bisect_type,
285 "BISECT_START" => \$bisect_start,
286 "BISECT_REPLAY" => \$bisect_replay,
287 "BISECT_FILES" => \$bisect_files,
288 "BISECT_REVERSE" => \$bisect_reverse,
289 "BISECT_CHECK" => \$bisect_check,
291 "CONFIG_BISECT" => \$config_bisect,
292 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
293 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
295 "PATCHCHECK_TYPE" => \$patchcheck_type,
296 "PATCHCHECK_START" => \$patchcheck_start,
297 "PATCHCHECK_END" => \$patchcheck_end,
300 # Options may be used by other options, record them.
303 # default variables that can be used
304 chomp ($variable{"PWD"} = `pwd`);
306 $config_help{"MACHINE"} = << "EOF"
307 The machine hostname that you will test.
308 For build only tests, it is still needed to differentiate log files.
311 $config_help{"SSH_USER"} = << "EOF"
312 The box is expected to have ssh on normal bootup, provide the user
313 (most likely root, since you need privileged operations)
316 $config_help{"BUILD_DIR"} = << "EOF"
317 The directory that contains the Linux source code (full path).
318 You can use \${PWD} that will be the path where ktest.pl is run, or use
319 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
322 $config_help{"OUTPUT_DIR"} = << "EOF"
323 The directory that the objects will be built (full path).
324 (can not be same as BUILD_DIR)
325 You can use \${PWD} that will be the path where ktest.pl is run, or use
326 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
329 $config_help{"BUILD_TARGET"} = << "EOF"
330 The location of the compiled file to copy to the target.
331 (relative to OUTPUT_DIR)
334 $config_help{"BUILD_OPTIONS"} = << "EOF"
335 Options to add to \"make\" when building.
339 $config_help{"TARGET_IMAGE"} = << "EOF"
340 The place to put your image on the test machine.
343 $config_help{"POWER_CYCLE"} = << "EOF"
344 A script or command to reboot the box.
346 Here is a digital loggers power switch example
347 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
349 Here is an example to reboot a virtual box on the current host
350 with the name "Guest".
351 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
354 $config_help{"CONSOLE"} = << "EOF"
355 The script or command that reads the console
357 If you use ttywatch server, something like the following would work.
358 CONSOLE = nc -d localhost 3001
360 For a virtual machine with guest name "Guest".
361 CONSOLE = virsh console Guest
364 $config_help{"LOCALVERSION"} = << "EOF"
365 Required version ending to differentiate the test
366 from other linux builds on the system.
369 $config_help{"REBOOT_TYPE"} = << "EOF"
370 Way to reboot the box to the test kernel.
371 Only valid options so far are "grub" and "script".
373 If you specify grub, it will assume grub version 1
374 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
375 and select that target to reboot to the kernel. If this is not
376 your setup, then specify "script" and have a command or script
377 specified in REBOOT_SCRIPT to boot to the target.
379 The entry in /boot/grub/menu.lst must be entered in manually.
380 The test will not modify that file.
383 $config_help{"GRUB_MENU"} = << "EOF"
384 The grub title name for the test kernel to boot
385 (Only mandatory if REBOOT_TYPE = grub)
387 Note, ktest.pl will not update the grub menu.lst, you need to
388 manually add an option for the test. ktest.pl will search
389 the grub menu.lst for this option to find what kernel to
392 For example, if in the /boot/grub/menu.lst the test kernel title has:
395 GRUB_MENU = Test Kernel
398 $config_help{"REBOOT_SCRIPT"} = << "EOF"
399 A script to reboot the target into the test kernel
400 (Only mandatory if REBOOT_TYPE = script)
405 my ($cancel, $prompt) = @_;
411 print "$prompt [y/n/C] ";
413 print "$prompt [Y/n] ";
417 if ($ans =~ /^\s*$/) {
424 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
426 last if ($ans =~ /^c$/i);
427 print "Please answer either 'y', 'n' or 'c'.\n";
429 print "Please answer either 'y' or 'n'.\n";
435 if ($ans !~ /^y$/i) {
444 return read_prompt 0, $prompt;
450 return read_prompt 1, $prompt;
453 sub get_ktest_config {
457 return if (defined($opt{$config}));
459 if (defined($config_help{$config})) {
461 print $config_help{$config};
466 if (defined($default{$config}) && length($default{$config})) {
467 print "\[$default{$config}\] ";
470 $ans =~ s/^\s*(.*\S)\s*$/$1/;
471 if ($ans =~ /^\s*$/) {
472 if ($default{$config}) {
473 $ans = $default{$config};
475 print "Your answer can not be blank\n";
479 $entered_configs{$config} = ${ans};
484 sub get_ktest_configs {
485 get_ktest_config("MACHINE");
486 get_ktest_config("BUILD_DIR");
487 get_ktest_config("OUTPUT_DIR");
490 get_ktest_config("BUILD_OPTIONS");
493 # options required for other than just building a kernel
495 get_ktest_config("POWER_CYCLE");
496 get_ktest_config("CONSOLE");
499 # options required for install and more
500 if ($buildonly != 1) {
501 get_ktest_config("SSH_USER");
502 get_ktest_config("BUILD_TARGET");
503 get_ktest_config("TARGET_IMAGE");
506 get_ktest_config("LOCALVERSION");
508 return if ($buildonly);
510 my $rtype = $opt{"REBOOT_TYPE"};
512 if (!defined($rtype)) {
513 if (!defined($opt{"GRUB_MENU"})) {
514 get_ktest_config("REBOOT_TYPE");
515 $rtype = $entered_configs{"REBOOT_TYPE"};
521 if ($rtype eq "grub") {
522 get_ktest_config("GRUB_MENU");
526 sub process_variables {
527 my ($value, $remove_undef) = @_;
530 # We want to check for '\', and it is just easier
531 # to check the previous characet of '$' and not need
532 # to worry if '$' is the first character. By adding
533 # a space to $value, we can just check [^\\]\$ and
534 # it will still work.
537 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
541 # append beginning of value to retval
542 $retval = "$retval$begin";
543 if (defined($variable{$var})) {
544 $retval = "$retval$variable{$var}";
545 } elsif (defined($remove_undef) && $remove_undef) {
546 # for if statements, any variable that is not defined,
547 # we simple convert to 0
548 $retval = "${retval}0";
550 # put back the origin piece.
551 $retval = "$retval\$\{$var\}";
552 # This could be an option that is used later, save
553 # it so we don't warn if this option is not one of
555 $used_options{$var} = 1;
559 $retval = "$retval$value";
561 # remove the space added in the beginning
568 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
570 my $prvalue = process_variables($rvalue);
572 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
573 # Note if a test is something other than build, then we
574 # will need other manditory options.
575 if ($prvalue ne "install") {
578 # install still limits some manditory options.
583 if (defined($opt{$lvalue})) {
584 if (!$override || defined(${$overrides}{$lvalue})) {
587 $extra = "In the same override section!\n";
589 die "$name: $.: Option $lvalue defined more than once!\n$extra";
591 ${$overrides}{$lvalue} = $prvalue;
593 if ($rvalue =~ /^\s*$/) {
594 delete $opt{$lvalue};
596 $opt{$lvalue} = $prvalue;
601 my ($lvalue, $rvalue) = @_;
603 if ($rvalue =~ /^\s*$/) {
604 delete $variable{$lvalue};
606 $rvalue = process_variables($rvalue);
607 $variable{$lvalue} = $rvalue;
611 sub process_compare {
612 my ($lval, $cmp, $rval) = @_;
623 return $lval eq $rval;
624 } elsif ($cmp eq "!=") {
625 return $lval ne $rval;
626 } elsif ($cmp eq "=~") {
627 return $lval =~ m/$rval/;
628 } elsif ($cmp eq "!~") {
629 return $lval !~ m/$rval/;
632 my $statement = "$lval $cmp $rval";
633 my $ret = eval $statement;
635 # $@ stores error of eval
646 return defined($variable{$2}) ||
651 sub process_expression {
652 my ($name, $val) = @_;
656 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
659 if (process_expression($name, $express)) {
660 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
662 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
670 while ($val =~ s/^(.*?)($OR|$AND)//) {
674 if (process_expression($name, $express)) {
685 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
686 my $ret = process_compare($1, $2, $3);
688 die "$name: $.: Unable to process comparison\n";
693 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
695 return !value_defined($2);
697 return value_defined($2);
701 if ($val =~ /^\s*0\s*$/) {
703 } elsif ($val =~ /^\s*\d+\s*$/) {
707 die ("$name: $.: Undefined content $val in if statement\n");
711 my ($name, $value) = @_;
713 # Convert variables and replace undefined ones with 0
714 my $val = process_variables($value, 1);
715 my $ret = process_expression $name, $val;
721 my ($config, $current_test_num) = @_;
724 open($in, $config) || die "can't read file $config";
727 $name =~ s,.*/(.*),$1,;
729 my $test_num = $$current_test_num;
732 my $num_tests_set = 0;
745 # ignore blank lines and comments
746 next if (/^\s*$/ || /\s*\#/);
748 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
758 if ($type eq "TEST_START") {
760 if ($num_tests_set) {
761 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
764 $old_test_num = $test_num;
765 $old_repeat = $repeat;
767 $test_num += $repeat;
774 # If SKIP is anywhere in the line, the command will be skipped
775 if ($rest =~ s/\s+SKIP\b//) {
782 if ($rest =~ s/\sELSE\b//) {
784 die "$name: $.: ELSE found with out matching IF section\n$_";
795 if ($rest =~ s/\sIF\s+(.*)//) {
796 if (process_if($name, $1)) {
808 if ($type eq "TEST_START") {
809 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
811 $repeat_tests{"$test_num"} = $repeat;
813 } elsif ($rest =~ s/\sOVERRIDE\b//) {
816 # Clear previous overrides
821 if (!$skip && $rest !~ /^\s*$/) {
822 die "$name: $.: Gargbage found after $type\n$_";
825 if ($skip && $type eq "TEST_START") {
826 $test_num = $old_test_num;
827 $repeat = $old_repeat;
830 } elsif (/^\s*ELSE\b(.*)$/) {
832 die "$name: $.: ELSE found with out matching IF section\n$_";
841 if ($rest =~ /\sIF\s+(.*)/) {
842 # May be a ELSE IF section.
843 if (process_if($name, $1)) {
854 if ($rest !~ /^\s*$/) {
855 die "$name: $.: Gargbage found after DEFAULTS\n$_";
858 } elsif (/^\s*INCLUDE\s+(\S+)/) {
863 die "$name: $.: INCLUDE can only be done in default sections\n$_";
866 my $file = process_variables($1);
868 if ($file !~ m,^/,) {
869 # check the path of the config file first
870 if ($config =~ m,(.*)/,) {
878 die "$name: $.: Can't read file $file\n$_";
881 if (__read_config($file, \$test_num)) {
885 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
893 ($lvalue eq "NUM_TESTS" ||
894 $lvalue eq "LOG_FILE" ||
895 $lvalue eq "CLEAR_LOG")) {
896 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
899 if ($lvalue eq "NUM_TESTS") {
901 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
904 die "$name: $.: NUM_TESTS must be set in default section\n";
909 if ($default || $lvalue =~ /\[\d+\]$/) {
910 set_value($lvalue, $rvalue, $override, \%overrides, $name);
912 my $val = "$lvalue\[$test_num\]";
913 set_value($val, $rvalue, $override, \%overrides, $name);
916 $repeats{$val} = $repeat;
919 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
925 # process config variables.
926 # Config variables are only active while reading the
927 # config and can be defined anywhere. They also ignore
928 # TEST_START and DEFAULTS, but are skipped if they are in
929 # on of these sections that have SKIP defined.
930 # The save variable can be
931 # defined multiple times and the new one simply overrides
933 set_variable($lvalue, $rvalue);
936 die "$name: $.: Garbage found in config\n$_";
941 $test_num += $repeat - 1;
942 $opt{"NUM_TESTS"} = $test_num;
947 $$current_test_num = $test_num;
953 print "What test case would you like to run?\n";
954 print " (build, install or boot)\n";
955 print " Other tests are available but require editing the config file\n";
958 $default{"TEST_TYPE"} = $ans;
967 $test_case = __read_config $config, \$test_num;
969 # make sure we have all mandatory configs
972 # was a test specified?
974 print "No test case specified.\n";
980 foreach my $default (keys %default) {
981 if (!defined($opt{$default})) {
982 $opt{$default} = $default{$default};
986 if ($opt{"IGNORE_UNUSED"} == 1) {
992 # check if there are any stragglers (typos?)
993 foreach my $option (keys %opt) {
995 # remove per test labels.
997 if (!exists($option_map{$op}) &&
998 !exists($default{$op}) &&
999 !exists($used_options{$op})) {
1006 $s = " is" if (keys %not_used == 1);
1007 print "The following option$s not used; could be a typo:\n";
1008 foreach my $option (keys %not_used) {
1011 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1012 if (!read_yn "Do you want to continue?") {
1019 my ($option, $i) = @_;
1021 # Add space to evaluate the character before $
1022 $option = " $option";
1027 foreach my $test (keys %repeat_tests) {
1029 $i < $test + $repeat_tests{$test}) {
1037 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1042 # Append beginning of line
1043 $retval = "$retval$start";
1045 # If the iteration option OPT[$i] exists, then use that.
1046 # otherwise see if the default OPT (without [$i]) exists.
1048 my $o = "$var\[$i\]";
1049 my $parento = "$var\[$parent\]";
1051 if (defined($opt{$o})) {
1053 $retval = "$retval$o";
1054 } elsif ($repeated && defined($opt{$parento})) {
1055 $o = $opt{$parento};
1056 $retval = "$retval$o";
1057 } elsif (defined($opt{$var})) {
1059 $retval = "$retval$o";
1061 $retval = "$retval\$\{$var\}";
1067 $retval = "$retval$option";
1075 my ($option, $i) = @_;
1079 # Since an option can evaluate to another option,
1080 # keep iterating until we do not evaluate any more
1083 while ($prev ne $option) {
1084 # Check for recursive evaluations.
1085 # 100 deep should be more than enough.
1087 die "Over 100 evaluations accurred with $option\n" .
1088 "Check for recursive variables\n";
1091 $option = __eval_option($option, $i);
1098 if (defined($opt{"LOG_FILE"})) {
1099 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1106 if (defined($opt{"LOG_FILE"})) {
1121 sub wait_for_monitor;
1126 if (defined($time)) {
1128 # flush out current monitor
1129 # May contain the reboot success line
1133 # try to reboot normally
1134 if (run_command $reboot) {
1135 if (defined($powercycle_after_reboot)) {
1136 sleep $powercycle_after_reboot;
1137 run_command "$power_cycle";
1140 # nope? power cycle it.
1141 run_command "$power_cycle";
1144 if (defined($time)) {
1145 if (wait_for_monitor($time, $reboot_success_line)) {
1147 doprint "Reboot did not finish. Forcing power cycle\n";
1148 run_command "$power_cycle";
1154 sub reboot_to_good {
1157 if (defined($switch_to_good)) {
1158 run_command $switch_to_good;
1167 return $test_type eq "build" || $no_reboot ||
1168 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1169 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1173 doprint "CRITICAL FAILURE... ", @_, "\n";
1177 if ($reboot_on_error && !do_not_reboot) {
1179 doprint "REBOOTING\n";
1182 } elsif ($poweroff_on_error && defined($power_off)) {
1183 doprint "POWERING OFF\n";
1187 if (defined($opt{"LOG_FILE"})) {
1188 print " See $opt{LOG_FILE} for more info.\n";
1199 my $pid = open($fp, "$console|") or
1200 dodie "Can't open console $console";
1202 $flags = fcntl($fp, F_GETFL, 0) or
1203 dodie "Can't get flags for the socket: $!";
1204 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1205 dodie "Can't set flags for the socket: $!";
1211 my ($fp, $pid) = @_;
1213 doprint "kill child process $pid\n";
1221 if ($monitor_cnt++) {
1224 $monitor_fp = \*MONFD;
1225 $monitor_pid = open_console $monitor_fp;
1229 open(MONFD, "Stop perl from warning about single use of MONFD");
1233 if (--$monitor_cnt) {
1236 close_console($monitor_fp, $monitor_pid);
1239 sub wait_for_monitor {
1240 my ($time, $stop) = @_;
1244 my $start_time = time;
1245 my $skip_call_trace = 0;
1247 my $bug_ignored = 0;
1250 doprint "** Wait for monitor to settle down **\n";
1252 # read the monitor and wait for the system to calm down
1254 $line = wait_for_input($monitor_fp, $time);
1255 last if (!defined($line));
1257 $full_line .= $line;
1259 if (defined($stop) && $full_line =~ /$stop/) {
1260 doprint "wait for monitor detected $stop\n";
1264 if ($full_line =~ /\[ backtrace testing \]/) {
1265 $skip_call_trace = 1;
1268 if ($full_line =~ /call trace:/i) {
1269 if (!$bug && !$skip_call_trace) {
1270 if ($ignore_errors) {
1278 if ($full_line =~ /\[ end of backtrace testing \]/) {
1279 $skip_call_trace = 0;
1282 if ($full_line =~ /Kernel panic -/) {
1286 if ($line =~ /\n/) {
1290 if ($now - $start_time >= $max_monitor_wait) {
1291 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1295 print "** Monitor flushed **\n";
1300 my ($result, $basedir) = @_;
1302 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1303 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1305 my $type = $build_type;
1306 if ($type =~ /useconfig/) {
1307 $type = "useconfig";
1310 my $dir = "$machine-$test_type-$type-$result-$date";
1312 $dir = "$basedir/$dir";
1316 die "can't create $dir";
1320 "config" => $output_config,
1321 "buildlog" => $buildlog,
1323 "testlog" => $testlog,
1326 while (my ($name, $source) = each(%files)) {
1328 cp "$source", "$dir/$name" or
1329 die "failed to copy $source";
1333 doprint "*** Saved info to $dir ***\n";
1338 if (defined($post_test)) {
1339 run_command $post_test;
1342 if ($die_on_failure) {
1350 # no need to reboot for just building.
1351 if (!do_not_reboot) {
1352 doprint "REBOOTING\n";
1353 reboot_to_good $sleep_time;
1358 if (defined($test_name)) {
1359 $name = " ($test_name)";
1362 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1363 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1364 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1365 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1366 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1368 if (defined($store_failures)) {
1369 save_logs "fail", $store_failures;
1381 $command =~ s/\$SSH_USER/$ssh_user/g;
1382 $command =~ s/\$MACHINE/$machine/g;
1384 doprint("$command ... ");
1386 $pid = open(CMD, "$command 2>&1 |") or
1387 (fail "unable to exec $command" and return 0);
1389 if (defined($opt{"LOG_FILE"})) {
1390 open(LOG, ">>$opt{LOG_FILE}") or
1391 dodie "failed to write to log";
1395 if (defined($redirect)) {
1396 open (RD, ">$redirect") or
1397 dodie "failed to write to redirect $redirect";
1402 print LOG if ($dolog);
1403 print RD if ($dord);
1410 close(LOG) if ($dolog);
1411 close(RD) if ($dord);
1414 doprint "FAILED!\n";
1416 doprint "SUCCESS\n";
1424 my $cp_exec = $ssh_exec;
1426 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1427 return run_command "$cp_exec";
1431 my ($src, $dst, $cp_scp) = @_;
1433 $cp_scp =~ s/\$SRC_FILE/$src/g;
1434 $cp_scp =~ s/\$DST_FILE/$dst/g;
1436 return run_command "$cp_scp";
1439 sub run_scp_install {
1440 my ($src, $dst) = @_;
1442 my $cp_scp = $scp_to_target_install;
1444 return run_scp($src, $dst, $cp_scp);
1448 my ($src, $dst) = @_;
1450 my $cp_scp = $scp_to_target;
1452 return run_scp($src, $dst, $cp_scp);
1455 sub get_grub_index {
1457 if ($reboot_type ne "grub") {
1460 return if (defined($grub_number));
1462 doprint "Find grub menu ... ";
1465 my $ssh_grub = $ssh_exec;
1466 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1468 open(IN, "$ssh_grub |")
1469 or die "unable to get menu.lst";
1474 if (/^\s*title\s+$grub_menu\s*$/) {
1478 } elsif (/^\s*title\s/) {
1484 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1486 doprint "$grub_number\n";
1491 my ($fp, $time) = @_;
1497 if (!defined($time)) {
1502 vec($rin, fileno($fp), 1) = 1;
1503 $ready = select($rin, undef, undef, $time);
1507 # try to read one char at a time
1508 while (sysread $fp, $ch, 1) {
1510 last if ($ch eq "\n");
1513 if (!length($line)) {
1521 if (defined($switch_to_test)) {
1522 run_command $switch_to_test;
1525 if ($reboot_type eq "grub") {
1526 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1527 } elsif (defined $reboot_script) {
1528 run_command "$reboot_script";
1536 doprint "git rev-list --max-count=1 $commit ... ";
1537 my $sha1 = `git rev-list --max-count=1 $commit`;
1544 dodie "Failed to get git $commit";
1557 my $bug_ignored = 0;
1558 my $skip_call_trace = 0;
1566 open(DMESG, "> $dmesg") or
1567 die "unable to write to $dmesg";
1573 my $monitor_start = time;
1575 my $version_found = 0;
1579 if ($bug && defined($stop_after_failure) &&
1580 $stop_after_failure >= 0) {
1581 my $time = $stop_after_failure - (time - $failure_start);
1582 $line = wait_for_input($monitor_fp, $time);
1583 if (!defined($line)) {
1584 doprint "bug timed out after $booted_timeout seconds\n";
1585 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1589 $line = wait_for_input($monitor_fp, $booted_timeout);
1590 if (!defined($line)) {
1591 my $s = $booted_timeout == 1 ? "" : "s";
1592 doprint "Successful boot found: break after $booted_timeout second$s\n";
1596 $line = wait_for_input($monitor_fp);
1597 if (!defined($line)) {
1598 my $s = $timeout == 1 ? "" : "s";
1599 doprint "Timed out after $timeout second$s\n";
1607 # we are not guaranteed to get a full line
1608 $full_line .= $line;
1610 if ($full_line =~ /$success_line/) {
1612 $success_start = time;
1615 if ($booted && defined($stop_after_success) &&
1616 $stop_after_success >= 0) {
1618 if ($now - $success_start >= $stop_after_success) {
1619 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1624 if ($full_line =~ /\[ backtrace testing \]/) {
1625 $skip_call_trace = 1;
1628 if ($full_line =~ /call trace:/i) {
1629 if (!$bug && !$skip_call_trace) {
1630 if ($ignore_errors) {
1634 $failure_start = time;
1639 if ($bug && defined($stop_after_failure) &&
1640 $stop_after_failure >= 0) {
1642 if ($now - $failure_start >= $stop_after_failure) {
1643 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1648 if ($full_line =~ /\[ end of backtrace testing \]/) {
1649 $skip_call_trace = 0;
1652 if ($full_line =~ /Kernel panic -/) {
1653 $failure_start = time;
1657 # Detect triple faults by testing the banner
1658 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1659 if ($1 eq $version) {
1661 } elsif ($version_found && $detect_triplefault) {
1662 # We already booted into the kernel we are testing,
1663 # but now we booted into another kernel?
1664 # Consider this a triple fault.
1665 doprint "Aleady booted in Linux kernel $version, but now\n";
1666 doprint "we booted into Linux kernel $1.\n";
1667 doprint "Assuming that this is a triple fault.\n";
1668 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1673 if ($line =~ /\n/) {
1677 if ($stop_test_after > 0 && !$booted && !$bug) {
1678 if (time - $monitor_start > $stop_test_after) {
1679 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1688 return 0 if ($in_bisect);
1689 fail "failed - got a bug report" and return 0;
1693 return 0 if ($in_bisect);
1694 fail "failed - never got a boot prompt." and return 0;
1698 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1704 sub eval_kernel_version {
1707 $option =~ s/\$KERNEL_VERSION/$version/g;
1712 sub do_post_install {
1714 return if (!defined($post_install));
1716 my $cp_post_install = eval_kernel_version $post_install;
1717 run_command "$cp_post_install" or
1718 dodie "Failed to run post install";
1723 return if ($no_install);
1725 if (defined($pre_install)) {
1726 my $cp_pre_install = eval_kernel_version $pre_install;
1727 run_command "$cp_pre_install" or
1728 dodie "Failed to run pre install";
1731 my $cp_target = eval_kernel_version $target_image;
1733 run_scp_install "$outputdir/$build_target", "$cp_target" or
1734 dodie "failed to copy image";
1736 my $install_mods = 0;
1738 # should we process modules?
1740 open(IN, "$output_config") or dodie("Can't read config file");
1742 if (/CONFIG_MODULES(=y)?/) {
1743 $install_mods = 1 if (defined($1));
1749 if (!$install_mods) {
1751 doprint "No modules needed\n";
1755 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1756 dodie "Failed to install modules";
1758 my $modlib = "/lib/modules/$version";
1759 my $modtar = "ktest-mods.tar.bz2";
1761 run_ssh "rm -rf $modlib" or
1762 dodie "failed to remove old mods: $modlib";
1764 # would be nice if scp -r did not follow symbolic links
1765 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1766 dodie "making tarball";
1768 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1769 dodie "failed to copy modules";
1771 unlink "$tmpdir/$modtar";
1773 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1774 dodie "failed to tar modules";
1776 run_ssh "rm -f /tmp/$modtar";
1782 # get the release name
1783 return if ($have_version);
1784 doprint "$make kernelrelease ... ";
1785 $version = `$make kernelrelease | tail -1`;
1787 doprint "$version\n";
1791 sub start_monitor_and_boot {
1792 # Make sure the stable kernel has finished booting
1805 sub check_buildlog {
1808 my @files = `git show $patch | diffstat -l`;
1810 open(IN, "git show $patch |") or
1811 dodie "failed to show $patch";
1813 if (m,^--- a/(.*),) {
1815 $files[$#files] = $1;
1820 open(IN, $buildlog) or dodie "Can't open $buildlog";
1822 if (/^\s*(.*?):.*(warning|error)/) {
1824 foreach my $file (@files) {
1825 my $fullpath = "$builddir/$file";
1826 if ($file eq $err || $fullpath eq $err) {
1827 fail "$file built with warnings" and return 0;
1837 sub apply_min_config {
1838 my $outconfig = "$output_config.new";
1840 # Read the config file and remove anything that
1841 # is in the force_config hash (from minconfig and others)
1842 # then add the force config back.
1844 doprint "Applying minimum configurations into $output_config.new\n";
1846 open (OUT, ">$outconfig") or
1847 dodie "Can't create $outconfig";
1849 if (-f $output_config) {
1850 open (IN, $output_config) or
1851 dodie "Failed to open $output_config";
1853 if (/^(# )?(CONFIG_[^\s=]*)/) {
1854 next if (defined($force_config{$2}));
1860 foreach my $config (keys %force_config) {
1861 print OUT "$force_config{$config}\n";
1865 run_command "mv $outconfig $output_config";
1868 sub make_oldconfig {
1870 my @force_list = keys %force_config;
1872 if ($#force_list >= 0) {
1876 if (!run_command "$make oldnoconfig") {
1877 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1878 # try a yes '' | oldconfig
1879 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1880 run_command "yes '' | $make oldconfig" or
1881 dodie "failed make config oldconfig";
1885 # read a config file and use this to force new configs.
1886 sub load_force_config {
1889 doprint "Loading force configs from $config\n";
1890 open(IN, $config) or
1891 dodie "failed to read $config";
1894 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1895 $force_config{$1} = $_;
1896 } elsif (/^# (CONFIG_\S*) is not set/) {
1897 $force_config{$1} = $_;
1908 # Failed builds should not reboot the target
1909 my $save_no_reboot = $no_reboot;
1912 # Calculate a new version from here.
1915 if (defined($pre_build)) {
1916 my $ret = run_command $pre_build;
1917 if (!$ret && defined($pre_build_die) &&
1919 dodie "failed to pre_build\n";
1923 if ($type =~ /^useconfig:(.*)/) {
1924 run_command "cp $1 $output_config" or
1925 dodie "could not copy $1 to .config";
1927 $type = "oldconfig";
1930 # old config can ask questions
1931 if ($type eq "oldconfig") {
1932 $type = "oldnoconfig";
1934 # allow for empty configs
1935 run_command "touch $output_config";
1938 run_command "mv $output_config $outputdir/config_temp" or
1939 dodie "moving .config";
1941 run_command "$make mrproper" or dodie "make mrproper";
1943 run_command "mv $outputdir/config_temp $output_config" or
1944 dodie "moving config_temp";
1947 } elsif (!$noclean) {
1948 unlink "$output_config";
1949 run_command "$make mrproper" or
1950 dodie "make mrproper";
1953 # add something to distinguish this build
1954 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1955 print OUT "$localversion\n";
1958 if (defined($minconfig)) {
1959 load_force_config($minconfig);
1962 if ($type ne "oldnoconfig") {
1963 run_command "$make $type" or
1964 dodie "failed make config";
1966 # Run old config regardless, to enforce min configurations
1969 $redirect = "$buildlog";
1970 my $build_ret = run_command "$make $build_options";
1973 if (defined($post_build)) {
1974 # Because a post build may change the kernel version
1977 my $ret = run_command $post_build;
1978 if (!$ret && defined($post_build_die) &&
1980 dodie "failed to post_build\n";
1985 # bisect may need this to pass
1987 $no_reboot = $save_no_reboot;
1990 fail "failed build" and return 0;
1993 $no_reboot = $save_no_reboot;
1999 if (!run_ssh "halt" or defined($power_off)) {
2000 if (defined($poweroff_after_halt)) {
2001 sleep $poweroff_after_halt;
2002 run_command "$power_off";
2006 run_command "$power_off";
2013 if (defined($post_test)) {
2014 run_command $post_test;
2021 if (defined($test_name)) {
2022 $name = " ($test_name)";
2025 doprint "\n\n*******************************************\n";
2026 doprint "*******************************************\n";
2027 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
2028 doprint "*******************************************\n";
2029 doprint "*******************************************\n";
2031 if (defined($store_successes)) {
2032 save_logs "success", $store_successes;
2035 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
2036 doprint "Reboot and wait $sleep_time seconds\n";
2037 reboot_to_good $sleep_time;
2043 doprint "Pass or fail? [p/f]";
2046 if ($ans eq "p" || $ans eq "P") {
2048 } elsif ($ans eq "f" || $ans eq "F") {
2051 print "Please answer 'P' or 'F'\n";
2056 sub child_run_test {
2059 # child should have no power
2060 $reboot_on_error = 0;
2061 $poweroff_on_error = 0;
2062 $die_on_failure = 1;
2064 $redirect = "$testlog";
2065 run_command $run_test or $failed = 1;
2073 sub child_finished {
2083 my $bug_ignored = 0;
2087 doprint "run test $run_test\n";
2091 $SIG{CHLD} = qw(child_finished);
2095 child_run_test if (!$child_pid);
2100 $line = wait_for_input($monitor_fp, 1);
2101 if (defined($line)) {
2103 # we are not guaranteed to get a full line
2104 $full_line .= $line;
2107 if ($full_line =~ /call trace:/i) {
2108 if ($ignore_errors) {
2115 if ($full_line =~ /Kernel panic -/) {
2119 if ($line =~ /\n/) {
2123 } while (!$child_done && !$bug);
2125 if (!$bug && $bug_ignored) {
2126 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2130 my $failure_start = time;
2133 $line = wait_for_input($monitor_fp, 1);
2134 if (defined($line)) {
2138 if ($now - $failure_start >= $stop_after_failure) {
2141 } while (defined($line));
2143 doprint "Detected kernel crash!\n";
2144 # kill the child with extreme prejudice
2148 waitpid $child_pid, 0;
2151 if (!$bug && $in_bisect) {
2152 if (defined($bisect_ret_good)) {
2153 if ($child_exit == $bisect_ret_good) {
2157 if (defined($bisect_ret_skip)) {
2158 if ($child_exit == $bisect_ret_skip) {
2162 if (defined($bisect_ret_abort)) {
2163 if ($child_exit == $bisect_ret_abort) {
2164 fail "test abort" and return -2;
2167 if (defined($bisect_ret_bad)) {
2168 if ($child_exit == $bisect_ret_skip) {
2172 if (defined($bisect_ret_default)) {
2173 if ($bisect_ret_default eq "good") {
2175 } elsif ($bisect_ret_default eq "bad") {
2177 } elsif ($bisect_ret_default eq "skip") {
2179 } elsif ($bisect_ret_default eq "abort") {
2182 fail "unknown default action: $bisect_ret_default"
2188 if ($bug || $child_exit) {
2189 return 0 if $in_bisect;
2190 fail "test failed" and return 0;
2195 sub run_git_bisect {
2198 doprint "$command ... ";
2200 my $output = `$command 2>&1`;
2207 dodie "Failed to git bisect";
2210 doprint "SUCCESS\n";
2211 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2212 doprint "$1 [$2]\n";
2213 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2214 $bisect_bad_commit = $1;
2215 doprint "Found bad commit... $1\n";
2218 # we already logged it, just print it now.
2226 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2227 reboot_to_good $bisect_sleep_time;
2230 # returns 1 on success, 0 on failure, -1 on skip
2231 sub run_bisect_test {
2232 my ($type, $buildtype) = @_;
2241 build $buildtype or $failed = 1;
2243 if ($type ne "build") {
2244 if ($failed && $bisect_skip) {
2248 dodie "Failed on build" if $failed;
2251 start_monitor_and_boot or $failed = 1;
2253 if ($type ne "boot") {
2254 if ($failed && $bisect_skip) {
2260 dodie "Failed on boot" if $failed;
2262 do_run_test or $failed = 1;
2273 # reboot the box to a kernel we can ssh to
2274 if ($type ne "build") {
2284 my $buildtype = "oldconfig";
2286 # We should have a minconfig to use?
2287 if (defined($minconfig)) {
2288 $buildtype = "useconfig:$minconfig";
2291 my $ret = run_bisect_test $type, $buildtype;
2293 if ($bisect_manual) {
2294 $ret = answer_bisect;
2297 # Are we looking for where it worked, not failed?
2298 if ($reverse_bisect && $ret >= 0) {
2304 } elsif ($ret == 0) {
2306 } elsif ($bisect_skip) {
2307 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2312 sub update_bisect_replay {
2313 my $tmp_log = "$tmpdir/ktest_bisect_log";
2314 run_command "git bisect log > $tmp_log" or
2315 die "can't create bisect log";
2324 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2325 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2326 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2328 my $good = $bisect_good;
2329 my $bad = $bisect_bad;
2330 my $type = $bisect_type;
2331 my $start = $bisect_start;
2332 my $replay = $bisect_replay;
2333 my $start_files = $bisect_files;
2335 if (defined($start_files)) {
2336 $start_files = " -- " . $start_files;
2341 # convert to true sha1's
2342 $good = get_sha1($good);
2343 $bad = get_sha1($bad);
2345 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2346 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2347 $reverse_bisect = 1;
2349 $reverse_bisect = 0;
2352 # Can't have a test without having a test to run
2353 if ($type eq "test" && !defined($run_test)) {
2357 # Check if a bisect was running
2358 my $bisect_start_file = "$builddir/.git/BISECT_START";
2360 my $check = $bisect_check;
2361 my $do_check = defined($check) && $check ne "0";
2363 if ( -f $bisect_start_file ) {
2364 print "Bisect in progress found\n";
2366 print " If you say yes, then no checks of good or bad will be done\n";
2368 if (defined($replay)) {
2369 print "** BISECT_REPLAY is defined in config file **";
2370 print " Ignore config option and perform new git bisect log?\n";
2371 if (read_ync " (yes, no, or cancel) ") {
2372 $replay = update_bisect_replay;
2375 } elsif (read_yn "read git log and continue?") {
2376 $replay = update_bisect_replay;
2384 my $head = get_sha1("HEAD");
2386 if ($check ne "good") {
2387 doprint "TESTING BISECT BAD [$bad]\n";
2388 run_command "git checkout $bad" or
2389 die "Failed to checkout $bad";
2391 $result = run_bisect $type;
2393 if ($result ne "bad") {
2394 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2398 if ($check ne "bad") {
2399 doprint "TESTING BISECT GOOD [$good]\n";
2400 run_command "git checkout $good" or
2401 die "Failed to checkout $good";
2403 $result = run_bisect $type;
2405 if ($result ne "good") {
2406 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2410 # checkout where we started
2411 run_command "git checkout $head" or
2412 die "Failed to checkout $head";
2415 run_command "git bisect start$start_files" or
2416 dodie "could not start bisect";
2418 run_command "git bisect good $good" or
2419 dodie "could not set bisect good to $good";
2421 run_git_bisect "git bisect bad $bad" or
2422 dodie "could not set bisect bad to $bad";
2424 if (defined($replay)) {
2425 run_command "git bisect replay $replay" or
2426 dodie "failed to run replay";
2429 if (defined($start)) {
2430 run_command "git checkout $start" or
2431 dodie "failed to checkout $start";
2436 $result = run_bisect $type;
2437 $test = run_git_bisect "git bisect $result";
2440 run_command "git bisect log" or
2441 dodie "could not capture git bisect log";
2443 run_command "git bisect reset" or
2444 dodie "could not reset git bisect";
2446 doprint "Bad commit was [$bisect_bad_commit]\n";
2451 # config_ignore holds the configs that were set (or unset) for
2452 # a good config and we will ignore these configs for the rest
2453 # of a config bisect. These configs stay as they were.
2456 # config_set holds what all configs were set as.
2459 # config_off holds the set of configs that the bad config had disabled.
2460 # We need to record them and set them in the .config when running
2461 # oldnoconfig, because oldnoconfig does not turn off new symbols, but
2462 # instead just keeps the defaults.
2465 # config_off_tmp holds a set of configs to turn off for now
2468 # config_list is the set of configs that are being tested
2474 sub assign_configs {
2475 my ($hash, $config) = @_;
2478 or dodie "Failed to read $config";
2481 if (/^((CONFIG\S*)=.*)/) {
2489 sub process_config_ignore {
2492 assign_configs \%config_ignore, $config;
2495 sub read_current_config {
2496 my ($config_ref) = @_;
2498 %{$config_ref} = ();
2499 undef %{$config_ref};
2501 my @key = keys %{$config_ref};
2503 print "did not delete!\n";
2506 open (IN, "$output_config");
2509 if (/^(CONFIG\S+)=(.*)/) {
2510 ${$config_ref}{$1} = $2;
2516 sub get_dependencies {
2519 my $arr = $dependency{$config};
2520 if (!defined($arr)) {
2526 foreach my $dep (@{$arr}) {
2527 print "ADD DEP $dep\n";
2528 @deps = (@deps, get_dependencies $dep);
2537 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2539 foreach my $config (@configs) {
2540 print OUT "$config_set{$config}\n";
2541 my @deps = get_dependencies $config;
2542 foreach my $dep (@deps) {
2543 print OUT "$config_set{$dep}\n";
2547 # turn off configs to keep off
2548 foreach my $config (keys %config_off) {
2549 print OUT "# $config is not set\n";
2552 # turn off configs that should be off for now
2553 foreach my $config (@config_off_tmp) {
2554 print OUT "# $config is not set\n";
2557 foreach my $config (keys %config_ignore) {
2558 print OUT "$config_ignore{$config}\n";
2565 sub compare_configs {
2568 foreach my $item (keys %a) {
2569 if (!defined($b{$item})) {
2570 print "diff $item\n";
2578 print "diff2 $keys[0]\n";
2580 return -1 if ($#keys >= 0);
2585 sub run_config_bisect_test {
2588 return run_bisect_test $type, "oldconfig";
2591 sub process_passed {
2594 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2595 # Passed! All these configs are part of a good compile.
2596 # Add them to the min options.
2597 foreach my $config (keys %configs) {
2598 if (defined($config_list{$config})) {
2599 doprint " removing $config\n";
2600 $config_ignore{$config} = $config_list{$config};
2601 delete $config_list{$config};
2604 doprint "config copied to $outputdir/config_good\n";
2605 run_command "cp -f $output_config $outputdir/config_good";
2608 sub process_failed {
2611 doprint "\n\n***************************************\n";
2612 doprint "Found bad config: $config\n";
2613 doprint "***************************************\n\n";
2616 sub run_config_bisect {
2618 my @start_list = keys %config_list;
2620 if ($#start_list < 0) {
2621 doprint "No more configs to test!!!\n";
2625 doprint "***** RUN TEST ***\n";
2626 my $type = $config_bisect_type;
2630 my $count = $#start_list + 1;
2631 doprint " $count configs to test\n";
2633 my $half = int($#start_list / 2);
2636 my @tophalf = @start_list[0 .. $half];
2638 # keep the bottom half off
2639 if ($half < $#start_list) {
2640 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2642 @config_off_tmp = ();
2645 create_config @tophalf;
2646 read_current_config \%current_config;
2648 $count = $#tophalf + 1;
2649 doprint "Testing $count configs\n";
2651 # make sure we test something
2652 foreach my $config (@tophalf) {
2653 if (defined($current_config{$config})) {
2659 # try the other half
2660 doprint "Top half produced no set configs, trying bottom half\n";
2662 # keep the top half off
2663 @config_off_tmp = @tophalf;
2664 @tophalf = @start_list[$half + 1 .. $#start_list];
2666 create_config @tophalf;
2667 read_current_config \%current_config;
2668 foreach my $config (@tophalf) {
2669 if (defined($current_config{$config})) {
2675 doprint "Failed: Can't make new config with current configs\n";
2676 foreach my $config (@start_list) {
2677 doprint " CONFIG: $config\n";
2681 $count = $#tophalf + 1;
2682 doprint "Testing $count configs\n";
2685 $ret = run_config_bisect_test $type;
2686 if ($bisect_manual) {
2687 $ret = answer_bisect;
2690 process_passed %current_config;
2694 doprint "This config had a failure.\n";
2695 doprint "Removing these configs that were not set in this config:\n";
2696 doprint "config copied to $outputdir/config_bad\n";
2697 run_command "cp -f $output_config $outputdir/config_bad";
2699 # A config exists in this group that was bad.
2700 foreach my $config (keys %config_list) {
2701 if (!defined($current_config{$config})) {
2702 doprint " removing $config\n";
2703 delete $config_list{$config};
2707 @start_list = @tophalf;
2709 if ($#start_list == 0) {
2710 process_failed $start_list[0];
2714 # remove half the configs we are looking at and see if
2716 $half = int($#start_list / 2);
2717 } while ($#start_list > 0);
2719 # we found a single config, try it again unless we are running manually
2721 if ($bisect_manual) {
2722 process_failed $start_list[0];
2726 my @tophalf = @start_list[0 .. 0];
2728 $ret = run_config_bisect_test $type;
2730 process_passed %current_config;
2734 process_failed $start_list[0];
2741 my $start_config = $config_bisect;
2743 my $tmpconfig = "$tmpdir/use_config";
2745 if (defined($config_bisect_good)) {
2746 process_config_ignore $config_bisect_good;
2749 # Make the file with the bad config and the min config
2750 if (defined($minconfig)) {
2751 # read the min config for things to ignore
2752 run_command "cp $minconfig $tmpconfig" or
2753 dodie "failed to copy $minconfig to $tmpconfig";
2758 if (-f $tmpconfig) {
2759 load_force_config($tmpconfig);
2760 process_config_ignore $tmpconfig;
2763 # now process the start config
2764 run_command "cp $start_config $output_config" or
2765 dodie "failed to copy $start_config to $output_config";
2767 # read directly what we want to check
2769 open (IN, $output_config)
2770 or dodie "failed to open $output_config";
2773 if (/^((CONFIG\S*)=.*)/) {
2774 $config_check{$2} = $1;
2779 # Now run oldconfig with the minconfig
2782 # check to see what we lost (or gained)
2783 open (IN, $output_config)
2784 or dodie "Failed to read $start_config";
2786 my %removed_configs;
2790 if (/^((CONFIG\S*)=.*)/) {
2791 # save off all options
2792 $config_set{$2} = $1;
2793 if (defined($config_check{$2})) {
2794 if (defined($config_ignore{$2})) {
2795 $removed_configs{$2} = $1;
2797 $config_list{$2} = $1;
2799 } elsif (!defined($config_ignore{$2})) {
2800 $added_configs{$2} = $1;
2801 $config_list{$2} = $1;
2803 } elsif (/^# ((CONFIG\S*).*)/) {
2804 # Keep these configs disabled
2805 $config_set{$2} = $1;
2806 $config_off{$2} = $1;
2811 my @confs = keys %removed_configs;
2813 doprint "Configs overridden by default configs and removed from check:\n";
2814 foreach my $config (@confs) {
2815 doprint " $config\n";
2818 @confs = keys %added_configs;
2820 doprint "Configs appearing in make oldconfig and added:\n";
2821 foreach my $config (@confs) {
2822 doprint " $config\n";
2829 @config_off_tmp = ();
2831 # Sometimes kconfig does weird things. We must make sure
2832 # that the config we autocreate has everything we need
2833 # to test, otherwise we may miss testing configs, or
2834 # may not be able to create a new config.
2835 # Here we create a config with everything set.
2836 create_config (keys %config_list);
2837 read_current_config \%config_test;
2838 foreach my $config (keys %config_list) {
2839 if (!defined($config_test{$config})) {
2842 doprint "Configs not produced by kconfig (will not be checked):\n";
2844 doprint " $config\n";
2845 delete $config_list{$config};
2850 if (defined($config_bisect_check) && $config_bisect_check) {
2851 doprint " Checking to make sure bad config with min config fails\n";
2852 create_config keys %config_list;
2853 $ret = run_config_bisect_test $config_bisect_type;
2855 doprint " FAILED! Bad config with min config boots fine\n";
2858 doprint " Bad config with min config fails as expected\n";
2862 $ret = run_config_bisect;
2865 return $ret if ($ret < 0);
2870 sub patchcheck_reboot {
2871 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2872 reboot_to_good $patchcheck_sleep_time;
2878 die "PATCHCHECK_START[$i] not defined\n"
2879 if (!defined($patchcheck_start));
2880 die "PATCHCHECK_TYPE[$i] not defined\n"
2881 if (!defined($patchcheck_type));
2883 my $start = $patchcheck_start;
2886 if (defined($patchcheck_end)) {
2887 $end = $patchcheck_end;
2890 # Get the true sha1's since we can use things like HEAD~3
2891 $start = get_sha1($start);
2892 $end = get_sha1($end);
2894 my $type = $patchcheck_type;
2896 # Can't have a test without having a test to run
2897 if ($type eq "test" && !defined($run_test)) {
2901 open (IN, "git log --pretty=oneline $end|") or
2902 dodie "could not get git list";
2908 $list[$#list+1] = $_;
2909 last if (/^$start/);
2913 if ($list[$#list] !~ /^$start/) {
2914 fail "SHA1 $start not found";
2917 # go backwards in the list
2918 @list = reverse @list;
2920 my $save_clean = $noclean;
2921 my %ignored_warnings;
2923 if (defined($ignore_warnings)) {
2924 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2925 $ignored_warnings{$sha1} = 1;
2930 foreach my $item (@list) {
2932 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2934 doprint "\nProcessing commit $item\n\n";
2936 run_command "git checkout $sha1" or
2937 die "Failed to checkout $sha1";
2939 # only clean on the first and last patch
2940 if ($item eq $list[0] ||
2941 $item eq $list[$#list]) {
2942 $noclean = $save_clean;
2947 if (defined($minconfig)) {
2948 build "useconfig:$minconfig" or return 0;
2950 # ?? no config to use?
2951 build "oldconfig" or return 0;
2955 if (!defined($ignored_warnings{$sha1})) {
2956 check_buildlog $sha1 or return 0;
2959 next if ($type eq "build");
2963 start_monitor_and_boot or $failed = 1;
2965 if (!$failed && $type ne "boot"){
2966 do_run_test or $failed = 1;
2969 return 0 if ($failed);
2989 # $config depends on $dep
2990 my ($config, $dep) = @_;
2992 if (defined($depends{$config})) {
2993 $depends{$config} .= " " . $dep;
2995 $depends{$config} = $dep;
2998 # record the number of configs depending on $dep
2999 if (defined $depcount{$dep}) {
3002 $depcount{$dep} = 1;
3006 # taken from streamline_config.pl
3018 if (! -f $kconfig) {
3019 doprint "file $kconfig does not exist, skipping\n";
3023 open(KIN, "$kconfig")
3024 or die "Can't open $kconfig";
3028 # Make sure that lines ending with \ continue
3030 $_ = $line . " " . $_;
3041 # collect any Kconfig sources
3042 if (/^source\s*"(.*)"/) {
3043 $kconfigs[$#kconfigs+1] = $1;
3047 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3051 for (my $i = 0; $i < $iflevel; $i++) {
3052 add_dep $config, $ifdeps[$i];
3055 # collect the depends for the config
3056 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3058 add_dep $config, $1;
3060 # Get the configs that select this config
3061 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3063 # selected by depends on config
3064 add_dep $1, $config;
3066 # Check for if statements
3067 } elsif (/^if\s+(.*\S)\s*$/) {
3069 # remove beginning and ending non text
3070 $deps =~ s/^[^a-zA-Z0-9_]*//;
3071 $deps =~ s/[^a-zA-Z0-9_]*$//;
3073 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3075 $ifdeps[$iflevel++] = join ':', @deps;
3077 } elsif (/^endif/) {
3079 $iflevel-- if ($iflevel);
3082 } elsif (/^\s*help\s*$/) {
3088 # read in any configs that were found.
3089 foreach $kconfig (@kconfigs) {
3090 if (!defined($read_kconfigs{$kconfig})) {
3091 $read_kconfigs{$kconfig} = 1;
3092 read_kconfig("$builddir/$kconfig");
3098 # find out which arch this is by the kconfig file
3099 open (IN, $output_config)
3100 or dodie "Failed to read $output_config";
3103 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3110 if (!defined($arch)) {
3111 doprint "Could not find arch from config file\n";
3112 doprint "no dependencies used\n";
3116 # arch is really the subarch, we need to know
3117 # what directory to look at.
3118 if ($arch eq "i386" || $arch eq "x86_64") {
3120 } elsif ($arch =~ /^tile/) {
3124 my $kconfig = "$builddir/arch/$arch/Kconfig";
3126 if (! -f $kconfig && $arch =~ /\d$/) {
3128 # some subarchs have numbers, truncate them
3130 $kconfig = "$builddir/arch/$arch/Kconfig";
3131 if (! -f $kconfig) {
3132 doprint "No idea what arch dir $orig is for\n";
3133 doprint "no dependencies used\n";
3138 read_kconfig($kconfig);
3141 sub read_config_list {
3145 or dodie "Failed to read $config";
3148 if (/^((CONFIG\S*)=.*)/) {
3149 if (!defined($config_ignore{$2})) {
3150 $config_list{$2} = $1;
3158 sub read_output_config {
3161 assign_configs \%config_ignore, $config;
3164 sub make_new_config {
3167 open (OUT, ">$output_config")
3168 or dodie "Failed to write $output_config";
3170 foreach my $config (@configs) {
3171 print OUT "$config\n";
3179 $config =~ s/CONFIG_//;
3187 my $kconfig = chomp_config $dep;
3189 $dep = $depends{"$kconfig"};
3191 # the dep string we have saves the dependencies as they
3192 # were found, including expressions like ! && ||. We
3193 # want to split this out into just an array of configs.
3195 my $valid = "A-Za-z_0-9";
3199 while ($dep =~ /[$valid]/) {
3201 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3202 my $conf = "CONFIG_" . $1;
3204 $configs[$#configs + 1] = $conf;
3206 $dep =~ s/^[^$valid]*[$valid]+//;
3208 die "this should never happen";
3218 my %processed_configs;
3219 my %nochange_config;
3221 sub test_this_config {
3226 # if we already processed this config, skip it
3227 if (defined($processed_configs{$config})) {
3230 $processed_configs{$config} = 1;
3232 # if this config failed during this round, skip it
3233 if (defined($nochange_config{$config})) {
3237 my $kconfig = chomp_config $config;
3239 # Test dependencies first
3240 if (defined($depends{"$kconfig"})) {
3241 my @parents = get_depends $config;
3242 foreach my $parent (@parents) {
3243 # if the parent is in the min config, check it first
3244 next if (!defined($min_configs{$parent}));
3245 $found = test_this_config($parent);
3246 if (defined($found)) {
3252 # Remove this config from the list of configs
3253 # do a make oldnoconfig and then read the resulting
3254 # .config to make sure it is missing the config that
3256 my %configs = %min_configs;
3257 delete $configs{$config};
3258 make_new_config ((values %configs), (values %keep_configs));
3261 assign_configs \%configs, $output_config;
3263 return $config if (!defined($configs{$config}));
3265 doprint "disabling config $config did not change .config\n";
3267 $nochange_config{$config} = 1;
3272 sub make_min_config {
3275 my $type = $minconfig_type;
3276 if ($type ne "boot" && $type ne "test") {
3277 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3278 " make_min_config works only with 'boot' and 'test'\n" and return;
3281 if (!defined($output_minconfig)) {
3282 fail "OUTPUT_MIN_CONFIG not defined" and return;
3285 # If output_minconfig exists, and the start_minconfig
3286 # came from min_config, than ask if we should use
3288 if (-f $output_minconfig && !$start_minconfig_defined) {
3289 print "$output_minconfig exists\n";
3290 if (!defined($use_output_minconfig)) {
3291 if (read_yn " Use it as minconfig?") {
3292 $start_minconfig = $output_minconfig;
3294 } elsif ($use_output_minconfig > 0) {
3295 doprint "Using $output_minconfig as MIN_CONFIG\n";
3296 $start_minconfig = $output_minconfig;
3298 doprint "Set to still use MIN_CONFIG as starting point\n";
3302 if (!defined($start_minconfig)) {
3303 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3306 my $temp_config = "$tmpdir/temp_config";
3308 # First things first. We build an allnoconfig to find
3309 # out what the defaults are that we can't touch.
3310 # Some are selections, but we really can't handle selections.
3312 my $save_minconfig = $minconfig;
3315 run_command "$make allnoconfig" or return 0;
3319 process_config_ignore $output_config;
3321 undef %save_configs;
3324 if (defined($ignore_config)) {
3325 # make sure the file exists
3326 `touch $ignore_config`;
3327 assign_configs \%save_configs, $ignore_config;
3330 %keep_configs = %save_configs;
3332 doprint "Load initial configs from $start_minconfig\n";
3334 # Look at the current min configs, and save off all the
3335 # ones that were set via the allnoconfig
3336 assign_configs \%min_configs, $start_minconfig;
3338 my @config_keys = keys %min_configs;
3340 # All configs need a depcount
3341 foreach my $config (@config_keys) {
3342 my $kconfig = chomp_config $config;
3343 if (!defined $depcount{$kconfig}) {
3344 $depcount{$kconfig} = 0;
3348 # Remove anything that was set by the make allnoconfig
3349 # we shouldn't need them as they get set for us anyway.
3350 foreach my $config (@config_keys) {
3351 # Remove anything in the ignore_config
3352 if (defined($keep_configs{$config})) {
3353 my $file = $ignore_config;
3354 $file =~ s,.*/(.*?)$,$1,;
3355 doprint "$config set by $file ... ignored\n";
3356 delete $min_configs{$config};
3359 # But make sure the settings are the same. If a min config
3360 # sets a selection, we do not want to get rid of it if
3361 # it is not the same as what we have. Just move it into
3363 if (defined($config_ignore{$config})) {
3364 if ($config_ignore{$config} ne $min_configs{$config}) {
3365 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3366 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3367 $keep_configs{$config} = $min_configs{$config};
3369 doprint "$config set by allnoconfig ... ignored\n";
3371 delete $min_configs{$config};
3383 # Now disable each config one by one and do a make oldconfig
3384 # till we find a config that changes our list.
3386 my @test_configs = keys %min_configs;
3388 # Sort keys by who is most dependent on
3389 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3392 # Put configs that did not modify the config at the end.
3394 for (my $i = 0; $i < $#test_configs; $i++) {
3395 if (!defined($nochange_config{$test_configs[0]})) {
3399 # This config didn't change the .config last time.
3400 # Place it at the end
3401 my $config = shift @test_configs;
3402 push @test_configs, $config;
3405 # if every test config has failed to modify the .config file
3406 # in the past, then reset and start over.
3408 undef %nochange_config;
3411 undef %processed_configs;
3413 foreach my $config (@test_configs) {
3415 $found = test_this_config $config;
3417 last if (defined($found));
3419 # oh well, try another config
3422 if (!defined($found)) {
3423 # we could have failed due to the nochange_config hash
3424 # reset and try again
3426 undef %nochange_config;
3430 doprint "No more configs found that we can disable\n";
3438 doprint "Test with $config disabled\n";
3440 # set in_bisect to keep build and monitor from dieing
3444 build "oldconfig" or $failed = 1;
3446 start_monitor_and_boot or $failed = 1;
3448 if ($type eq "test" && !$failed) {
3449 do_run_test or $failed = 1;
3458 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3459 # this config is needed, add it to the ignore list.
3460 $keep_configs{$config} = $min_configs{$config};
3461 $save_configs{$config} = $min_configs{$config};
3462 delete $min_configs{$config};
3464 # update new ignore configs
3465 if (defined($ignore_config)) {
3466 open (OUT, ">$temp_config")
3467 or die "Can't write to $temp_config";
3468 foreach my $config (keys %save_configs) {
3469 print OUT "$save_configs{$config}\n";
3472 run_command "mv $temp_config $ignore_config" or
3473 dodie "failed to copy update to $ignore_config";
3477 # We booted without this config, remove it from the minconfigs.
3478 doprint "$config is not needed, disabling\n";
3480 delete $min_configs{$config};
3482 # Also disable anything that is not enabled in this config
3484 assign_configs \%configs, $output_config;
3485 my @config_keys = keys %min_configs;
3486 foreach my $config (@config_keys) {
3487 if (!defined($configs{$config})) {
3488 doprint "$config is not set, disabling\n";
3489 delete $min_configs{$config};
3493 # Save off all the current mandidory configs
3494 open (OUT, ">$temp_config")
3495 or die "Can't write to $temp_config";
3496 foreach my $config (keys %keep_configs) {
3497 print OUT "$keep_configs{$config}\n";
3499 foreach my $config (keys %min_configs) {
3500 print OUT "$min_configs{$config}\n";
3504 run_command "mv $temp_config $output_minconfig" or
3505 dodie "failed to copy update to $output_minconfig";
3508 doprint "Reboot and wait $sleep_time seconds\n";
3509 reboot_to_good $sleep_time;
3516 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3519 $ktest_config = $ARGV[0];
3520 if (! -f $ktest_config) {
3521 print "$ktest_config does not exist.\n";
3522 if (!read_yn "Create it?") {
3527 $ktest_config = "ktest.conf";
3530 if (! -f $ktest_config) {
3533 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3535 # Generated by ktest.pl
3538 # PWD is a ktest.pl variable that will result in the process working
3539 # directory that ktest.pl is executed in.
3541 # THIS_DIR is automatically assigned the PWD of the path that generated
3542 # the config file. It is best to use this variable when assigning other
3543 # directory paths within this directory. This allows you to easily
3544 # move the test cases to other locations or to other machines.
3546 THIS_DIR := $variable{"PWD"}
3548 # Define each test with TEST_START
3549 # The config options below it will override the defaults
3551 TEST_TYPE = $default{"TEST_TYPE"}
3558 read_config $ktest_config;
3560 if (defined($opt{"LOG_FILE"})) {
3561 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3564 # Append any configs entered in manually to the config file.
3565 my @new_configs = keys %entered_configs;
3566 if ($#new_configs >= 0) {
3567 print "\nAppending entered in configs to $ktest_config\n";
3568 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3569 foreach my $config (@new_configs) {
3570 print OUT "$config = $entered_configs{$config}\n";
3571 $opt{$config} = process_variables($entered_configs{$config});
3575 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3576 unlink $opt{"LOG_FILE"};
3579 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3581 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3584 doprint "DEFAULT OPTIONS:\n";
3586 doprint "\nTEST $i OPTIONS";
3587 if (defined($repeat_tests{$i})) {
3588 $repeat = $repeat_tests{$i};
3589 doprint " ITERATE $repeat";
3594 foreach my $option (sort keys %opt) {
3596 if ($option =~ /\[(\d+)\]$/) {
3602 doprint "$option = $opt{$option}\n";
3606 sub __set_test_option {
3607 my ($name, $i) = @_;
3609 my $option = "$name\[$i\]";
3611 if (defined($opt{$option})) {
3612 return $opt{$option};
3615 foreach my $test (keys %repeat_tests) {
3617 $i < $test + $repeat_tests{$test}) {
3618 $option = "$name\[$test\]";
3619 if (defined($opt{$option})) {
3620 return $opt{$option};
3625 if (defined($opt{$name})) {
3632 sub set_test_option {
3633 my ($name, $i) = @_;
3635 my $option = __set_test_option($name, $i);
3636 return $option if (!defined($option));
3638 return eval_option($option, $i);
3641 # First we need to do is the builds
3642 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3644 # Do not reboot on failing test options
3646 $reboot_success = 0;
3652 undef %force_config;
3654 my $makecmd = set_test_option("MAKE_CMD", $i);
3656 # Load all the options into their mapped variable names
3657 foreach my $opt (keys %option_map) {
3658 ${$option_map{$opt}} = set_test_option($opt, $i);
3661 $start_minconfig_defined = 1;
3663 # The first test may override the PRE_KTEST option
3664 if (defined($pre_ktest) && $i == 1) {
3666 run_command $pre_ktest;
3669 # Any test can override the POST_KTEST option
3670 # The last test takes precedence.
3671 if (defined($post_ktest)) {
3672 $final_post_ktest = $post_ktest;
3675 if (!defined($start_minconfig)) {
3676 $start_minconfig_defined = 0;
3677 $start_minconfig = $minconfig;
3680 chdir $builddir || die "can't change directory to $builddir";
3682 foreach my $dir ($tmpdir, $outputdir) {
3685 die "can't create $dir";
3689 $ENV{"SSH_USER"} = $ssh_user;
3690 $ENV{"MACHINE"} = $machine;
3692 $buildlog = "$tmpdir/buildlog-$machine";
3693 $testlog = "$tmpdir/testlog-$machine";
3694 $dmesg = "$tmpdir/dmesg-$machine";
3695 $make = "$makecmd O=$outputdir";
3696 $output_config = "$outputdir/.config";
3699 $target = "$ssh_user\@$machine";
3700 if ($reboot_type eq "grub") {
3701 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3705 my $run_type = $build_type;
3706 if ($test_type eq "patchcheck") {
3707 $run_type = $patchcheck_type;
3708 } elsif ($test_type eq "bisect") {
3709 $run_type = $bisect_type;
3710 } elsif ($test_type eq "config_bisect") {
3711 $run_type = $config_bisect_type;
3714 if ($test_type eq "make_min_config") {
3718 # mistake in config file?
3719 if (!defined($run_type)) {
3720 $run_type = "ERROR";
3724 $installme = " no_install" if ($no_install);
3727 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3729 if (defined($pre_test)) {
3730 run_command $pre_test;
3737 if (defined($addconfig)) {
3738 my $min = $minconfig;
3739 if (!defined($minconfig)) {
3742 run_command "cat $addconfig $min > $tmpdir/add_config" or
3743 dodie "Failed to create temp config";
3744 $minconfig = "$tmpdir/add_config";
3747 if (defined($checkout)) {
3748 run_command "git checkout $checkout" or
3749 die "failed to checkout $checkout";
3754 # A test may opt to not reboot the box
3755 if ($reboot_on_success) {
3756 $reboot_success = 1;
3759 if ($test_type eq "bisect") {
3762 } elsif ($test_type eq "config_bisect") {
3765 } elsif ($test_type eq "patchcheck") {
3768 } elsif ($test_type eq "make_min_config") {
3773 if ($build_type ne "nobuild") {
3774 build $build_type or next;
3777 if ($test_type eq "install") {
3784 if ($test_type ne "build") {
3786 start_monitor_and_boot or $failed = 1;
3788 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3789 do_run_test or $failed = 1;
3798 if (defined($final_post_ktest)) {
3799 run_command $final_post_ktest;
3802 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3804 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
3806 } elsif (defined($switch_to_good)) {
3807 # still need to get to the good kernel
3808 run_command $switch_to_good;
3812 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";