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,
56 # required, and we will ask users if they don't have them but we keep the default
57 # value something that is common.
58 "REBOOT_TYPE" => "grub",
59 "LOCALVERSION" => "-test",
61 "BUILD_TARGET" => "arch/x86/boot/bzImage",
62 "TARGET_IMAGE" => "/boot/vmlinuz-test",
96 my $poweroff_on_error;
97 my $reboot_on_success;
99 my $powercycle_after_reboot;
100 my $poweroff_after_halt;
103 my $scp_to_target_install;
114 my $start_minconfig_defined;
115 my $output_minconfig;
117 my $use_output_minconfig;
122 my $bisect_bad_commit = "";
126 my $config_bisect_good;
130 my $bisect_ret_abort;
131 my $bisect_ret_default;
132 my $in_patchcheck = 0;
142 my $bisect_sleep_time;
143 my $patchcheck_sleep_time;
150 my $detect_triplefault;
152 my $reboot_success_line;
154 my $stop_after_success;
155 my $stop_after_failure;
174 my $config_bisect_type;
177 my $patchcheck_start;
180 # set when a test is something other that just building or install
181 # which would require more options.
184 # set when creating a new config
192 # do not force reboots on config problems
196 my $reboot_success = 0;
199 "MACHINE" => \$machine,
200 "SSH_USER" => \$ssh_user,
201 "TMP_DIR" => \$tmpdir,
202 "OUTPUT_DIR" => \$outputdir,
203 "BUILD_DIR" => \$builddir,
204 "TEST_TYPE" => \$test_type,
205 "PRE_KTEST" => \$pre_ktest,
206 "POST_KTEST" => \$post_ktest,
207 "PRE_TEST" => \$pre_test,
208 "POST_TEST" => \$post_test,
209 "BUILD_TYPE" => \$build_type,
210 "BUILD_OPTIONS" => \$build_options,
211 "PRE_BUILD" => \$pre_build,
212 "POST_BUILD" => \$post_build,
213 "PRE_BUILD_DIE" => \$pre_build_die,
214 "POST_BUILD_DIE" => \$post_build_die,
215 "POWER_CYCLE" => \$power_cycle,
216 "REBOOT" => \$reboot,
217 "BUILD_NOCLEAN" => \$noclean,
218 "MIN_CONFIG" => \$minconfig,
219 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
220 "START_MIN_CONFIG" => \$start_minconfig,
221 "MIN_CONFIG_TYPE" => \$minconfig_type,
222 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
223 "IGNORE_CONFIG" => \$ignore_config,
224 "TEST" => \$run_test,
225 "ADD_CONFIG" => \$addconfig,
226 "REBOOT_TYPE" => \$reboot_type,
227 "GRUB_MENU" => \$grub_menu,
228 "POST_INSTALL" => \$post_install,
229 "NO_INSTALL" => \$no_install,
230 "REBOOT_SCRIPT" => \$reboot_script,
231 "REBOOT_ON_ERROR" => \$reboot_on_error,
232 "SWITCH_TO_GOOD" => \$switch_to_good,
233 "SWITCH_TO_TEST" => \$switch_to_test,
234 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
235 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
236 "DIE_ON_FAILURE" => \$die_on_failure,
237 "POWER_OFF" => \$power_off,
238 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
239 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
240 "SLEEP_TIME" => \$sleep_time,
241 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
242 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
243 "IGNORE_WARNINGS" => \$ignore_warnings,
244 "IGNORE_ERRORS" => \$ignore_errors,
245 "BISECT_MANUAL" => \$bisect_manual,
246 "BISECT_SKIP" => \$bisect_skip,
247 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
248 "BISECT_RET_GOOD" => \$bisect_ret_good,
249 "BISECT_RET_BAD" => \$bisect_ret_bad,
250 "BISECT_RET_SKIP" => \$bisect_ret_skip,
251 "BISECT_RET_ABORT" => \$bisect_ret_abort,
252 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
253 "STORE_FAILURES" => \$store_failures,
254 "STORE_SUCCESSES" => \$store_successes,
255 "TEST_NAME" => \$test_name,
256 "TIMEOUT" => \$timeout,
257 "BOOTED_TIMEOUT" => \$booted_timeout,
258 "CONSOLE" => \$console,
259 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
260 "SUCCESS_LINE" => \$success_line,
261 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
262 "STOP_AFTER_SUCCESS" => \$stop_after_success,
263 "STOP_AFTER_FAILURE" => \$stop_after_failure,
264 "STOP_TEST_AFTER" => \$stop_test_after,
265 "BUILD_TARGET" => \$build_target,
266 "SSH_EXEC" => \$ssh_exec,
267 "SCP_TO_TARGET" => \$scp_to_target,
268 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
269 "CHECKOUT" => \$checkout,
270 "TARGET_IMAGE" => \$target_image,
271 "LOCALVERSION" => \$localversion,
273 "BISECT_GOOD" => \$bisect_good,
274 "BISECT_BAD" => \$bisect_bad,
275 "BISECT_TYPE" => \$bisect_type,
276 "BISECT_START" => \$bisect_start,
277 "BISECT_REPLAY" => \$bisect_replay,
278 "BISECT_FILES" => \$bisect_files,
279 "BISECT_REVERSE" => \$bisect_reverse,
280 "BISECT_CHECK" => \$bisect_check,
282 "CONFIG_BISECT" => \$config_bisect,
283 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
285 "PATCHCHECK_TYPE" => \$patchcheck_type,
286 "PATCHCHECK_START" => \$patchcheck_start,
287 "PATCHCHECK_END" => \$patchcheck_end,
290 # Options may be used by other options, record them.
293 # default variables that can be used
294 chomp ($variable{"PWD"} = `pwd`);
296 $config_help{"MACHINE"} = << "EOF"
297 The machine hostname that you will test.
298 For build only tests, it is still needed to differentiate log files.
301 $config_help{"SSH_USER"} = << "EOF"
302 The box is expected to have ssh on normal bootup, provide the user
303 (most likely root, since you need privileged operations)
306 $config_help{"BUILD_DIR"} = << "EOF"
307 The directory that contains the Linux source code (full path).
308 You can use \${PWD} that will be the path where ktest.pl is run, or use
309 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
312 $config_help{"OUTPUT_DIR"} = << "EOF"
313 The directory that the objects will be built (full path).
314 (can not be same as BUILD_DIR)
315 You can use \${PWD} that will be the path where ktest.pl is run, or use
316 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
319 $config_help{"BUILD_TARGET"} = << "EOF"
320 The location of the compiled file to copy to the target.
321 (relative to OUTPUT_DIR)
324 $config_help{"BUILD_OPTIONS"} = << "EOF"
325 Options to add to \"make\" when building.
329 $config_help{"TARGET_IMAGE"} = << "EOF"
330 The place to put your image on the test machine.
333 $config_help{"POWER_CYCLE"} = << "EOF"
334 A script or command to reboot the box.
336 Here is a digital loggers power switch example
337 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
339 Here is an example to reboot a virtual box on the current host
340 with the name "Guest".
341 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
344 $config_help{"CONSOLE"} = << "EOF"
345 The script or command that reads the console
347 If you use ttywatch server, something like the following would work.
348 CONSOLE = nc -d localhost 3001
350 For a virtual machine with guest name "Guest".
351 CONSOLE = virsh console Guest
354 $config_help{"LOCALVERSION"} = << "EOF"
355 Required version ending to differentiate the test
356 from other linux builds on the system.
359 $config_help{"REBOOT_TYPE"} = << "EOF"
360 Way to reboot the box to the test kernel.
361 Only valid options so far are "grub" and "script".
363 If you specify grub, it will assume grub version 1
364 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
365 and select that target to reboot to the kernel. If this is not
366 your setup, then specify "script" and have a command or script
367 specified in REBOOT_SCRIPT to boot to the target.
369 The entry in /boot/grub/menu.lst must be entered in manually.
370 The test will not modify that file.
373 $config_help{"GRUB_MENU"} = << "EOF"
374 The grub title name for the test kernel to boot
375 (Only mandatory if REBOOT_TYPE = grub)
377 Note, ktest.pl will not update the grub menu.lst, you need to
378 manually add an option for the test. ktest.pl will search
379 the grub menu.lst for this option to find what kernel to
382 For example, if in the /boot/grub/menu.lst the test kernel title has:
385 GRUB_MENU = Test Kernel
388 $config_help{"REBOOT_SCRIPT"} = << "EOF"
389 A script to reboot the target into the test kernel
390 (Only mandatory if REBOOT_TYPE = script)
395 my ($cancel, $prompt) = @_;
401 print "$prompt [y/n/C] ";
403 print "$prompt [Y/n] ";
407 if ($ans =~ /^\s*$/) {
414 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
416 last if ($ans =~ /^c$/i);
417 print "Please answer either 'y', 'n' or 'c'.\n";
419 print "Please answer either 'y' or 'n'.\n";
425 if ($ans !~ /^y$/i) {
434 return read_prompt 0, $prompt;
440 return read_prompt 1, $prompt;
443 sub get_ktest_config {
447 return if (defined($opt{$config}));
449 if (defined($config_help{$config})) {
451 print $config_help{$config};
456 if (defined($default{$config}) && length($default{$config})) {
457 print "\[$default{$config}\] ";
460 $ans =~ s/^\s*(.*\S)\s*$/$1/;
461 if ($ans =~ /^\s*$/) {
462 if ($default{$config}) {
463 $ans = $default{$config};
465 print "Your answer can not be blank\n";
469 $entered_configs{$config} = ${ans};
474 sub get_ktest_configs {
475 get_ktest_config("MACHINE");
476 get_ktest_config("BUILD_DIR");
477 get_ktest_config("OUTPUT_DIR");
480 get_ktest_config("BUILD_OPTIONS");
483 # options required for other than just building a kernel
485 get_ktest_config("POWER_CYCLE");
486 get_ktest_config("CONSOLE");
489 # options required for install and more
490 if ($buildonly != 1) {
491 get_ktest_config("SSH_USER");
492 get_ktest_config("BUILD_TARGET");
493 get_ktest_config("TARGET_IMAGE");
496 get_ktest_config("LOCALVERSION");
498 return if ($buildonly);
500 my $rtype = $opt{"REBOOT_TYPE"};
502 if (!defined($rtype)) {
503 if (!defined($opt{"GRUB_MENU"})) {
504 get_ktest_config("REBOOT_TYPE");
505 $rtype = $entered_configs{"REBOOT_TYPE"};
511 if ($rtype eq "grub") {
512 get_ktest_config("GRUB_MENU");
516 sub process_variables {
517 my ($value, $remove_undef) = @_;
520 # We want to check for '\', and it is just easier
521 # to check the previous characet of '$' and not need
522 # to worry if '$' is the first character. By adding
523 # a space to $value, we can just check [^\\]\$ and
524 # it will still work.
527 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
531 # append beginning of value to retval
532 $retval = "$retval$begin";
533 if (defined($variable{$var})) {
534 $retval = "$retval$variable{$var}";
535 } elsif (defined($remove_undef) && $remove_undef) {
536 # for if statements, any variable that is not defined,
537 # we simple convert to 0
538 $retval = "${retval}0";
540 # put back the origin piece.
541 $retval = "$retval\$\{$var\}";
542 # This could be an option that is used later, save
543 # it so we don't warn if this option is not one of
545 $used_options{$var} = 1;
549 $retval = "$retval$value";
551 # remove the space added in the beginning
558 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
560 my $prvalue = process_variables($rvalue);
562 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
563 # Note if a test is something other than build, then we
564 # will need other manditory options.
565 if ($prvalue ne "install") {
568 # install still limits some manditory options.
573 if (defined($opt{$lvalue})) {
574 if (!$override || defined(${$overrides}{$lvalue})) {
577 $extra = "In the same override section!\n";
579 die "$name: $.: Option $lvalue defined more than once!\n$extra";
581 ${$overrides}{$lvalue} = $prvalue;
583 if ($rvalue =~ /^\s*$/) {
584 delete $opt{$lvalue};
586 $opt{$lvalue} = $prvalue;
591 my ($lvalue, $rvalue) = @_;
593 if ($rvalue =~ /^\s*$/) {
594 delete $variable{$lvalue};
596 $rvalue = process_variables($rvalue);
597 $variable{$lvalue} = $rvalue;
601 sub process_compare {
602 my ($lval, $cmp, $rval) = @_;
613 return $lval eq $rval;
614 } elsif ($cmp eq "!=") {
615 return $lval ne $rval;
618 my $statement = "$lval $cmp $rval";
619 my $ret = eval $statement;
621 # $@ stores error of eval
632 return defined($variable{$2}) ||
637 sub process_expression {
638 my ($name, $val) = @_;
642 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
645 if (process_expression($name, $express)) {
646 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
648 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
656 while ($val =~ s/^(.*?)($OR|$AND)//) {
660 if (process_expression($name, $express)) {
671 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
672 my $ret = process_compare($1, $2, $3);
674 die "$name: $.: Unable to process comparison\n";
679 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
681 return !value_defined($2);
683 return value_defined($2);
687 if ($val =~ /^\s*0\s*$/) {
689 } elsif ($val =~ /^\s*\d+\s*$/) {
693 die ("$name: $.: Undefined content $val in if statement\n");
697 my ($name, $value) = @_;
699 # Convert variables and replace undefined ones with 0
700 my $val = process_variables($value, 1);
701 my $ret = process_expression $name, $val;
707 my ($config, $current_test_num) = @_;
710 open($in, $config) || die "can't read file $config";
713 $name =~ s,.*/(.*),$1,;
715 my $test_num = $$current_test_num;
718 my $num_tests_set = 0;
731 # ignore blank lines and comments
732 next if (/^\s*$/ || /\s*\#/);
734 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
744 if ($type eq "TEST_START") {
746 if ($num_tests_set) {
747 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
750 $old_test_num = $test_num;
751 $old_repeat = $repeat;
753 $test_num += $repeat;
760 # If SKIP is anywhere in the line, the command will be skipped
761 if ($rest =~ s/\s+SKIP\b//) {
768 if ($rest =~ s/\sELSE\b//) {
770 die "$name: $.: ELSE found with out matching IF section\n$_";
781 if ($rest =~ s/\sIF\s+(.*)//) {
782 if (process_if($name, $1)) {
794 if ($type eq "TEST_START") {
795 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
797 $repeat_tests{"$test_num"} = $repeat;
799 } elsif ($rest =~ s/\sOVERRIDE\b//) {
802 # Clear previous overrides
807 if (!$skip && $rest !~ /^\s*$/) {
808 die "$name: $.: Gargbage found after $type\n$_";
811 if ($skip && $type eq "TEST_START") {
812 $test_num = $old_test_num;
813 $repeat = $old_repeat;
816 } elsif (/^\s*ELSE\b(.*)$/) {
818 die "$name: $.: ELSE found with out matching IF section\n$_";
827 if ($rest =~ /\sIF\s+(.*)/) {
828 # May be a ELSE IF section.
829 if (!process_if($name, $1)) {
838 if ($rest !~ /^\s*$/) {
839 die "$name: $.: Gargbage found after DEFAULTS\n$_";
842 } elsif (/^\s*INCLUDE\s+(\S+)/) {
847 die "$name: $.: INCLUDE can only be done in default sections\n$_";
850 my $file = process_variables($1);
852 if ($file !~ m,^/,) {
853 # check the path of the config file first
854 if ($config =~ m,(.*)/,) {
862 die "$name: $.: Can't read file $file\n$_";
865 if (__read_config($file, \$test_num)) {
869 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
877 ($lvalue eq "NUM_TESTS" ||
878 $lvalue eq "LOG_FILE" ||
879 $lvalue eq "CLEAR_LOG")) {
880 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
883 if ($lvalue eq "NUM_TESTS") {
885 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
888 die "$name: $.: NUM_TESTS must be set in default section\n";
893 if ($default || $lvalue =~ /\[\d+\]$/) {
894 set_value($lvalue, $rvalue, $override, \%overrides, $name);
896 my $val = "$lvalue\[$test_num\]";
897 set_value($val, $rvalue, $override, \%overrides, $name);
900 $repeats{$val} = $repeat;
903 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
909 # process config variables.
910 # Config variables are only active while reading the
911 # config and can be defined anywhere. They also ignore
912 # TEST_START and DEFAULTS, but are skipped if they are in
913 # on of these sections that have SKIP defined.
914 # The save variable can be
915 # defined multiple times and the new one simply overrides
917 set_variable($lvalue, $rvalue);
920 die "$name: $.: Garbage found in config\n$_";
925 $test_num += $repeat - 1;
926 $opt{"NUM_TESTS"} = $test_num;
931 $$current_test_num = $test_num;
937 print "What test case would you like to run?\n";
938 print " (build, install or boot)\n";
939 print " Other tests are available but require editing the config file\n";
942 $default{"TEST_TYPE"} = $ans;
951 $test_case = __read_config $config, \$test_num;
953 # make sure we have all mandatory configs
956 # was a test specified?
958 print "No test case specified.\n";
964 foreach my $default (keys %default) {
965 if (!defined($opt{$default})) {
966 $opt{$default} = $default{$default};
970 if ($opt{"IGNORE_UNUSED"} == 1) {
976 # check if there are any stragglers (typos?)
977 foreach my $option (keys %opt) {
979 # remove per test labels.
981 if (!exists($option_map{$op}) &&
982 !exists($default{$op}) &&
983 !exists($used_options{$op})) {
990 $s = " is" if (keys %not_used == 1);
991 print "The following option$s not used; could be a typo:\n";
992 foreach my $option (keys %not_used) {
995 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
996 if (!read_yn "Do you want to continue?") {
1003 my ($option, $i) = @_;
1005 # Add space to evaluate the character before $
1006 $option = " $option";
1011 foreach my $test (keys %repeat_tests) {
1013 $i < $test + $repeat_tests{$test}) {
1021 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1026 # Append beginning of line
1027 $retval = "$retval$start";
1029 # If the iteration option OPT[$i] exists, then use that.
1030 # otherwise see if the default OPT (without [$i]) exists.
1032 my $o = "$var\[$i\]";
1033 my $parento = "$var\[$parent\]";
1035 if (defined($opt{$o})) {
1037 $retval = "$retval$o";
1038 } elsif ($repeated && defined($opt{$parento})) {
1039 $o = $opt{$parento};
1040 $retval = "$retval$o";
1041 } elsif (defined($opt{$var})) {
1043 $retval = "$retval$o";
1045 $retval = "$retval\$\{$var\}";
1051 $retval = "$retval$option";
1059 my ($option, $i) = @_;
1063 # Since an option can evaluate to another option,
1064 # keep iterating until we do not evaluate any more
1067 while ($prev ne $option) {
1068 # Check for recursive evaluations.
1069 # 100 deep should be more than enough.
1071 die "Over 100 evaluations accurred with $option\n" .
1072 "Check for recursive variables\n";
1075 $option = __eval_option($option, $i);
1082 if (defined($opt{"LOG_FILE"})) {
1083 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1090 if (defined($opt{"LOG_FILE"})) {
1105 sub wait_for_monitor;
1110 if (defined($time)) {
1112 # flush out current monitor
1113 # May contain the reboot success line
1117 # try to reboot normally
1118 if (run_command $reboot) {
1119 if (defined($powercycle_after_reboot)) {
1120 sleep $powercycle_after_reboot;
1121 run_command "$power_cycle";
1124 # nope? power cycle it.
1125 run_command "$power_cycle";
1128 if (defined($time)) {
1129 wait_for_monitor($time, $reboot_success_line);
1134 sub reboot_to_good {
1137 if (defined($switch_to_good)) {
1138 run_command $switch_to_good;
1147 return $test_type eq "build" || $no_reboot ||
1148 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1149 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1153 doprint "CRITICAL FAILURE... ", @_, "\n";
1157 if ($reboot_on_error && !do_not_reboot) {
1159 doprint "REBOOTING\n";
1162 } elsif ($poweroff_on_error && defined($power_off)) {
1163 doprint "POWERING OFF\n";
1167 if (defined($opt{"LOG_FILE"})) {
1168 print " See $opt{LOG_FILE} for more info.\n";
1179 my $pid = open($fp, "$console|") or
1180 dodie "Can't open console $console";
1182 $flags = fcntl($fp, F_GETFL, 0) or
1183 dodie "Can't get flags for the socket: $!";
1184 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
1185 dodie "Can't set flags for the socket: $!";
1191 my ($fp, $pid) = @_;
1193 doprint "kill child process $pid\n";
1201 if ($monitor_cnt++) {
1204 $monitor_fp = \*MONFD;
1205 $monitor_pid = open_console $monitor_fp;
1209 open(MONFD, "Stop perl from warning about single use of MONFD");
1213 if (--$monitor_cnt) {
1216 close_console($monitor_fp, $monitor_pid);
1219 sub wait_for_monitor {
1220 my ($time, $stop) = @_;
1225 doprint "** Wait for monitor to settle down **\n";
1227 # read the monitor and wait for the system to calm down
1229 $line = wait_for_input($monitor_fp, $time);
1230 last if (!defined($line));
1232 $full_line .= $line;
1234 if (defined($stop) && $full_line =~ /$stop/) {
1235 doprint "wait for monitor detected $stop\n";
1239 if ($line =~ /\n/) {
1243 print "** Monitor flushed **\n";
1247 my ($result, $basedir) = @_;
1249 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1250 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1252 my $type = $build_type;
1253 if ($type =~ /useconfig/) {
1254 $type = "useconfig";
1257 my $dir = "$machine-$test_type-$type-$result-$date";
1259 $dir = "$basedir/$dir";
1263 die "can't create $dir";
1267 "config" => $output_config,
1268 "buildlog" => $buildlog,
1270 "testlog" => $testlog,
1273 while (my ($name, $source) = each(%files)) {
1275 cp "$source", "$dir/$name" or
1276 die "failed to copy $source";
1280 doprint "*** Saved info to $dir ***\n";
1285 if (defined($post_test)) {
1286 run_command $post_test;
1289 if ($die_on_failure) {
1297 # no need to reboot for just building.
1298 if (!do_not_reboot) {
1299 doprint "REBOOTING\n";
1300 reboot_to_good $sleep_time;
1305 if (defined($test_name)) {
1306 $name = " ($test_name)";
1309 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1310 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1311 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
1312 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1313 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1315 if (defined($store_failures)) {
1316 save_logs "fail", $store_failures;
1328 $command =~ s/\$SSH_USER/$ssh_user/g;
1329 $command =~ s/\$MACHINE/$machine/g;
1331 doprint("$command ... ");
1333 $pid = open(CMD, "$command 2>&1 |") or
1334 (fail "unable to exec $command" and return 0);
1336 if (defined($opt{"LOG_FILE"})) {
1337 open(LOG, ">>$opt{LOG_FILE}") or
1338 dodie "failed to write to log";
1342 if (defined($redirect)) {
1343 open (RD, ">$redirect") or
1344 dodie "failed to write to redirect $redirect";
1349 print LOG if ($dolog);
1350 print RD if ($dord);
1357 close(LOG) if ($dolog);
1358 close(RD) if ($dord);
1361 doprint "FAILED!\n";
1363 doprint "SUCCESS\n";
1371 my $cp_exec = $ssh_exec;
1373 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1374 return run_command "$cp_exec";
1378 my ($src, $dst, $cp_scp) = @_;
1380 $cp_scp =~ s/\$SRC_FILE/$src/g;
1381 $cp_scp =~ s/\$DST_FILE/$dst/g;
1383 return run_command "$cp_scp";
1386 sub run_scp_install {
1387 my ($src, $dst) = @_;
1389 my $cp_scp = $scp_to_target_install;
1391 return run_scp($src, $dst, $cp_scp);
1395 my ($src, $dst) = @_;
1397 my $cp_scp = $scp_to_target;
1399 return run_scp($src, $dst, $cp_scp);
1402 sub get_grub_index {
1404 if ($reboot_type ne "grub") {
1407 return if (defined($grub_number));
1409 doprint "Find grub menu ... ";
1412 my $ssh_grub = $ssh_exec;
1413 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1415 open(IN, "$ssh_grub |")
1416 or die "unable to get menu.lst";
1421 if (/^\s*title\s+$grub_menu\s*$/) {
1425 } elsif (/^\s*title\s/) {
1431 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
1433 doprint "$grub_number\n";
1438 my ($fp, $time) = @_;
1444 if (!defined($time)) {
1449 vec($rin, fileno($fp), 1) = 1;
1450 $ready = select($rin, undef, undef, $time);
1454 # try to read one char at a time
1455 while (sysread $fp, $ch, 1) {
1457 last if ($ch eq "\n");
1460 if (!length($line)) {
1468 if (defined($switch_to_test)) {
1469 run_command $switch_to_test;
1472 if ($reboot_type eq "grub") {
1473 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1474 } elsif (defined $reboot_script) {
1475 run_command "$reboot_script";
1483 doprint "git rev-list --max-count=1 $commit ... ";
1484 my $sha1 = `git rev-list --max-count=1 $commit`;
1491 dodie "Failed to get git $commit";
1504 my $bug_ignored = 0;
1505 my $skip_call_trace = 0;
1513 open(DMESG, "> $dmesg") or
1514 die "unable to write to $dmesg";
1520 my $monitor_start = time;
1522 my $version_found = 0;
1526 if ($bug && defined($stop_after_failure) &&
1527 $stop_after_failure >= 0) {
1528 my $time = $stop_after_failure - (time - $failure_start);
1529 $line = wait_for_input($monitor_fp, $time);
1530 if (!defined($line)) {
1531 doprint "bug timed out after $booted_timeout seconds\n";
1532 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1536 $line = wait_for_input($monitor_fp, $booted_timeout);
1537 if (!defined($line)) {
1538 my $s = $booted_timeout == 1 ? "" : "s";
1539 doprint "Successful boot found: break after $booted_timeout second$s\n";
1543 $line = wait_for_input($monitor_fp);
1544 if (!defined($line)) {
1545 my $s = $timeout == 1 ? "" : "s";
1546 doprint "Timed out after $timeout second$s\n";
1554 # we are not guaranteed to get a full line
1555 $full_line .= $line;
1557 if ($full_line =~ /$success_line/) {
1559 $success_start = time;
1562 if ($booted && defined($stop_after_success) &&
1563 $stop_after_success >= 0) {
1565 if ($now - $success_start >= $stop_after_success) {
1566 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1571 if ($full_line =~ /\[ backtrace testing \]/) {
1572 $skip_call_trace = 1;
1575 if ($full_line =~ /call trace:/i) {
1576 if (!$bug && !$skip_call_trace) {
1577 if ($ignore_errors) {
1581 $failure_start = time;
1586 if ($bug && defined($stop_after_failure) &&
1587 $stop_after_failure >= 0) {
1589 if ($now - $failure_start >= $stop_after_failure) {
1590 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1595 if ($full_line =~ /\[ end of backtrace testing \]/) {
1596 $skip_call_trace = 0;
1599 if ($full_line =~ /Kernel panic -/) {
1600 $failure_start = time;
1604 # Detect triple faults by testing the banner
1605 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1606 if ($1 eq $version) {
1608 } elsif ($version_found && $detect_triplefault) {
1609 # We already booted into the kernel we are testing,
1610 # but now we booted into another kernel?
1611 # Consider this a triple fault.
1612 doprint "Aleady booted in Linux kernel $version, but now\n";
1613 doprint "we booted into Linux kernel $1.\n";
1614 doprint "Assuming that this is a triple fault.\n";
1615 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1620 if ($line =~ /\n/) {
1624 if ($stop_test_after > 0 && !$booted && !$bug) {
1625 if (time - $monitor_start > $stop_test_after) {
1626 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
1635 return 0 if ($in_bisect);
1636 fail "failed - got a bug report" and return 0;
1640 return 0 if ($in_bisect);
1641 fail "failed - never got a boot prompt." and return 0;
1645 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1651 sub eval_kernel_version {
1654 $option =~ s/\$KERNEL_VERSION/$version/g;
1659 sub do_post_install {
1661 return if (!defined($post_install));
1663 my $cp_post_install = eval_kernel_version $post_install;
1664 run_command "$cp_post_install" or
1665 dodie "Failed to run post install";
1670 return if ($no_install);
1672 my $cp_target = eval_kernel_version $target_image;
1674 run_scp_install "$outputdir/$build_target", "$cp_target" or
1675 dodie "failed to copy image";
1677 my $install_mods = 0;
1679 # should we process modules?
1681 open(IN, "$output_config") or dodie("Can't read config file");
1683 if (/CONFIG_MODULES(=y)?/) {
1684 $install_mods = 1 if (defined($1));
1690 if (!$install_mods) {
1692 doprint "No modules needed\n";
1696 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
1697 dodie "Failed to install modules";
1699 my $modlib = "/lib/modules/$version";
1700 my $modtar = "ktest-mods.tar.bz2";
1702 run_ssh "rm -rf $modlib" or
1703 dodie "failed to remove old mods: $modlib";
1705 # would be nice if scp -r did not follow symbolic links
1706 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
1707 dodie "making tarball";
1709 run_scp_mod "$tmpdir/$modtar", "/tmp" or
1710 dodie "failed to copy modules";
1712 unlink "$tmpdir/$modtar";
1714 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
1715 dodie "failed to tar modules";
1717 run_ssh "rm -f /tmp/$modtar";
1723 # get the release name
1724 return if ($have_version);
1725 doprint "$make kernelrelease ... ";
1726 $version = `$make kernelrelease | tail -1`;
1728 doprint "$version\n";
1732 sub start_monitor_and_boot {
1733 # Make sure the stable kernel has finished booting
1746 sub check_buildlog {
1749 my @files = `git show $patch | diffstat -l`;
1751 open(IN, "git show $patch |") or
1752 dodie "failed to show $patch";
1754 if (m,^--- a/(.*),) {
1756 $files[$#files] = $1;
1761 open(IN, $buildlog) or dodie "Can't open $buildlog";
1763 if (/^\s*(.*?):.*(warning|error)/) {
1765 foreach my $file (@files) {
1766 my $fullpath = "$builddir/$file";
1767 if ($file eq $err || $fullpath eq $err) {
1768 fail "$file built with warnings" and return 0;
1778 sub apply_min_config {
1779 my $outconfig = "$output_config.new";
1781 # Read the config file and remove anything that
1782 # is in the force_config hash (from minconfig and others)
1783 # then add the force config back.
1785 doprint "Applying minimum configurations into $output_config.new\n";
1787 open (OUT, ">$outconfig") or
1788 dodie "Can't create $outconfig";
1790 if (-f $output_config) {
1791 open (IN, $output_config) or
1792 dodie "Failed to open $output_config";
1794 if (/^(# )?(CONFIG_[^\s=]*)/) {
1795 next if (defined($force_config{$2}));
1801 foreach my $config (keys %force_config) {
1802 print OUT "$force_config{$config}\n";
1806 run_command "mv $outconfig $output_config";
1809 sub make_oldconfig {
1811 my @force_list = keys %force_config;
1813 if ($#force_list >= 0) {
1817 if (!run_command "$make oldnoconfig") {
1818 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1819 # try a yes '' | oldconfig
1820 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1821 run_command "yes '' | $make oldconfig" or
1822 dodie "failed make config oldconfig";
1826 # read a config file and use this to force new configs.
1827 sub load_force_config {
1830 open(IN, $config) or
1831 dodie "failed to read $config";
1834 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1835 $force_config{$1} = $_;
1836 } elsif (/^# (CONFIG_\S*) is not set/) {
1837 $force_config{$1} = $_;
1848 # Failed builds should not reboot the target
1849 my $save_no_reboot = $no_reboot;
1852 # Calculate a new version from here.
1855 if (defined($pre_build)) {
1856 my $ret = run_command $pre_build;
1857 if (!$ret && defined($pre_build_die) &&
1859 dodie "failed to pre_build\n";
1863 if ($type =~ /^useconfig:(.*)/) {
1864 run_command "cp $1 $output_config" or
1865 dodie "could not copy $1 to .config";
1867 $type = "oldconfig";
1870 # old config can ask questions
1871 if ($type eq "oldconfig") {
1872 $type = "oldnoconfig";
1874 # allow for empty configs
1875 run_command "touch $output_config";
1878 run_command "mv $output_config $outputdir/config_temp" or
1879 dodie "moving .config";
1881 run_command "$make mrproper" or dodie "make mrproper";
1883 run_command "mv $outputdir/config_temp $output_config" or
1884 dodie "moving config_temp";
1887 } elsif (!$noclean) {
1888 unlink "$output_config";
1889 run_command "$make mrproper" or
1890 dodie "make mrproper";
1893 # add something to distinguish this build
1894 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1895 print OUT "$localversion\n";
1898 if (defined($minconfig)) {
1899 load_force_config($minconfig);
1902 if ($type ne "oldnoconfig") {
1903 run_command "$make $type" or
1904 dodie "failed make config";
1906 # Run old config regardless, to enforce min configurations
1909 $redirect = "$buildlog";
1910 my $build_ret = run_command "$make $build_options";
1913 if (defined($post_build)) {
1914 # Because a post build may change the kernel version
1917 my $ret = run_command $post_build;
1918 if (!$ret && defined($post_build_die) &&
1920 dodie "failed to post_build\n";
1925 # bisect may need this to pass
1927 $no_reboot = $save_no_reboot;
1930 fail "failed build" and return 0;
1933 $no_reboot = $save_no_reboot;
1939 if (!run_ssh "halt" or defined($power_off)) {
1940 if (defined($poweroff_after_halt)) {
1941 sleep $poweroff_after_halt;
1942 run_command "$power_off";
1946 run_command "$power_off";
1953 if (defined($post_test)) {
1954 run_command $post_test;
1961 if (defined($test_name)) {
1962 $name = " ($test_name)";
1965 doprint "\n\n*******************************************\n";
1966 doprint "*******************************************\n";
1967 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
1968 doprint "*******************************************\n";
1969 doprint "*******************************************\n";
1971 if (defined($store_successes)) {
1972 save_logs "success", $store_successes;
1975 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
1976 doprint "Reboot and wait $sleep_time seconds\n";
1977 reboot_to_good $sleep_time;
1983 doprint "Pass or fail? [p/f]";
1986 if ($ans eq "p" || $ans eq "P") {
1988 } elsif ($ans eq "f" || $ans eq "F") {
1991 print "Please answer 'P' or 'F'\n";
1996 sub child_run_test {
1999 # child should have no power
2000 $reboot_on_error = 0;
2001 $poweroff_on_error = 0;
2002 $die_on_failure = 1;
2004 $redirect = "$testlog";
2005 run_command $run_test or $failed = 1;
2013 sub child_finished {
2026 doprint "run test $run_test\n";
2030 $SIG{CHLD} = qw(child_finished);
2034 child_run_test if (!$child_pid);
2039 $line = wait_for_input($monitor_fp, 1);
2040 if (defined($line)) {
2042 # we are not guaranteed to get a full line
2043 $full_line .= $line;
2046 if ($full_line =~ /call trace:/i) {
2050 if ($full_line =~ /Kernel panic -/) {
2054 if ($line =~ /\n/) {
2058 } while (!$child_done && !$bug);
2061 my $failure_start = time;
2064 $line = wait_for_input($monitor_fp, 1);
2065 if (defined($line)) {
2069 if ($now - $failure_start >= $stop_after_failure) {
2072 } while (defined($line));
2074 doprint "Detected kernel crash!\n";
2075 # kill the child with extreme prejudice
2079 waitpid $child_pid, 0;
2082 if (!$bug && $in_bisect) {
2083 if (defined($bisect_ret_good)) {
2084 if ($child_exit == $bisect_ret_good) {
2088 if (defined($bisect_ret_skip)) {
2089 if ($child_exit == $bisect_ret_skip) {
2093 if (defined($bisect_ret_abort)) {
2094 if ($child_exit == $bisect_ret_abort) {
2095 fail "test abort" and return -2;
2098 if (defined($bisect_ret_bad)) {
2099 if ($child_exit == $bisect_ret_skip) {
2103 if (defined($bisect_ret_default)) {
2104 if ($bisect_ret_default eq "good") {
2106 } elsif ($bisect_ret_default eq "bad") {
2108 } elsif ($bisect_ret_default eq "skip") {
2110 } elsif ($bisect_ret_default eq "abort") {
2113 fail "unknown default action: $bisect_ret_default"
2119 if ($bug || $child_exit) {
2120 return 0 if $in_bisect;
2121 fail "test failed" and return 0;
2126 sub run_git_bisect {
2129 doprint "$command ... ";
2131 my $output = `$command 2>&1`;
2138 dodie "Failed to git bisect";
2141 doprint "SUCCESS\n";
2142 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2143 doprint "$1 [$2]\n";
2144 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
2145 $bisect_bad_commit = $1;
2146 doprint "Found bad commit... $1\n";
2149 # we already logged it, just print it now.
2157 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
2158 reboot_to_good $bisect_sleep_time;
2161 # returns 1 on success, 0 on failure, -1 on skip
2162 sub run_bisect_test {
2163 my ($type, $buildtype) = @_;
2172 build $buildtype or $failed = 1;
2174 if ($type ne "build") {
2175 if ($failed && $bisect_skip) {
2179 dodie "Failed on build" if $failed;
2182 start_monitor_and_boot or $failed = 1;
2184 if ($type ne "boot") {
2185 if ($failed && $bisect_skip) {
2191 dodie "Failed on boot" if $failed;
2193 do_run_test or $failed = 1;
2204 # reboot the box to a kernel we can ssh to
2205 if ($type ne "build") {
2215 my $buildtype = "oldconfig";
2217 # We should have a minconfig to use?
2218 if (defined($minconfig)) {
2219 $buildtype = "useconfig:$minconfig";
2222 my $ret = run_bisect_test $type, $buildtype;
2224 if ($bisect_manual) {
2225 $ret = answer_bisect;
2228 # Are we looking for where it worked, not failed?
2229 if ($reverse_bisect && $ret >= 0) {
2235 } elsif ($ret == 0) {
2237 } elsif ($bisect_skip) {
2238 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2243 sub update_bisect_replay {
2244 my $tmp_log = "$tmpdir/ktest_bisect_log";
2245 run_command "git bisect log > $tmp_log" or
2246 die "can't create bisect log";
2255 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2256 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2257 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
2259 my $good = $bisect_good;
2260 my $bad = $bisect_bad;
2261 my $type = $bisect_type;
2262 my $start = $bisect_start;
2263 my $replay = $bisect_replay;
2264 my $start_files = $bisect_files;
2266 if (defined($start_files)) {
2267 $start_files = " -- " . $start_files;
2272 # convert to true sha1's
2273 $good = get_sha1($good);
2274 $bad = get_sha1($bad);
2276 if (defined($bisect_reverse) && $bisect_reverse == 1) {
2277 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2278 $reverse_bisect = 1;
2280 $reverse_bisect = 0;
2283 # Can't have a test without having a test to run
2284 if ($type eq "test" && !defined($run_test)) {
2288 # Check if a bisect was running
2289 my $bisect_start_file = "$builddir/.git/BISECT_START";
2291 my $check = $bisect_check;
2292 my $do_check = defined($check) && $check ne "0";
2294 if ( -f $bisect_start_file ) {
2295 print "Bisect in progress found\n";
2297 print " If you say yes, then no checks of good or bad will be done\n";
2299 if (defined($replay)) {
2300 print "** BISECT_REPLAY is defined in config file **";
2301 print " Ignore config option and perform new git bisect log?\n";
2302 if (read_ync " (yes, no, or cancel) ") {
2303 $replay = update_bisect_replay;
2306 } elsif (read_yn "read git log and continue?") {
2307 $replay = update_bisect_replay;
2315 my $head = get_sha1("HEAD");
2317 if ($check ne "good") {
2318 doprint "TESTING BISECT BAD [$bad]\n";
2319 run_command "git checkout $bad" or
2320 die "Failed to checkout $bad";
2322 $result = run_bisect $type;
2324 if ($result ne "bad") {
2325 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2329 if ($check ne "bad") {
2330 doprint "TESTING BISECT GOOD [$good]\n";
2331 run_command "git checkout $good" or
2332 die "Failed to checkout $good";
2334 $result = run_bisect $type;
2336 if ($result ne "good") {
2337 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2341 # checkout where we started
2342 run_command "git checkout $head" or
2343 die "Failed to checkout $head";
2346 run_command "git bisect start$start_files" or
2347 dodie "could not start bisect";
2349 run_command "git bisect good $good" or
2350 dodie "could not set bisect good to $good";
2352 run_git_bisect "git bisect bad $bad" or
2353 dodie "could not set bisect bad to $bad";
2355 if (defined($replay)) {
2356 run_command "git bisect replay $replay" or
2357 dodie "failed to run replay";
2360 if (defined($start)) {
2361 run_command "git checkout $start" or
2362 dodie "failed to checkout $start";
2367 $result = run_bisect $type;
2368 $test = run_git_bisect "git bisect $result";
2371 run_command "git bisect log" or
2372 dodie "could not capture git bisect log";
2374 run_command "git bisect reset" or
2375 dodie "could not reset git bisect";
2377 doprint "Bad commit was [$bisect_bad_commit]\n";
2390 sub assign_configs {
2391 my ($hash, $config) = @_;
2394 or dodie "Failed to read $config";
2397 if (/^((CONFIG\S*)=.*)/) {
2405 sub process_config_ignore {
2408 assign_configs \%config_ignore, $config;
2411 sub read_current_config {
2412 my ($config_ref) = @_;
2414 %{$config_ref} = ();
2415 undef %{$config_ref};
2417 my @key = keys %{$config_ref};
2419 print "did not delete!\n";
2422 open (IN, "$output_config");
2425 if (/^(CONFIG\S+)=(.*)/) {
2426 ${$config_ref}{$1} = $2;
2432 sub get_dependencies {
2435 my $arr = $dependency{$config};
2436 if (!defined($arr)) {
2442 foreach my $dep (@{$arr}) {
2443 print "ADD DEP $dep\n";
2444 @deps = (@deps, get_dependencies $dep);
2453 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2455 foreach my $config (@configs) {
2456 print OUT "$config_set{$config}\n";
2457 my @deps = get_dependencies $config;
2458 foreach my $dep (@deps) {
2459 print OUT "$config_set{$dep}\n";
2463 foreach my $config (keys %config_ignore) {
2464 print OUT "$config_ignore{$config}\n";
2471 sub compare_configs {
2474 foreach my $item (keys %a) {
2475 if (!defined($b{$item})) {
2476 print "diff $item\n";
2484 print "diff2 $keys[0]\n";
2486 return -1 if ($#keys >= 0);
2491 sub run_config_bisect_test {
2494 return run_bisect_test $type, "oldconfig";
2497 sub process_passed {
2500 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2501 # Passed! All these configs are part of a good compile.
2502 # Add them to the min options.
2503 foreach my $config (keys %configs) {
2504 if (defined($config_list{$config})) {
2505 doprint " removing $config\n";
2506 $config_ignore{$config} = $config_list{$config};
2507 delete $config_list{$config};
2510 doprint "config copied to $outputdir/config_good\n";
2511 run_command "cp -f $output_config $outputdir/config_good";
2514 sub process_failed {
2517 doprint "\n\n***************************************\n";
2518 doprint "Found bad config: $config\n";
2519 doprint "***************************************\n\n";
2522 sub run_config_bisect {
2524 my @start_list = keys %config_list;
2526 if ($#start_list < 0) {
2527 doprint "No more configs to test!!!\n";
2531 doprint "***** RUN TEST ***\n";
2532 my $type = $config_bisect_type;
2536 my $count = $#start_list + 1;
2537 doprint " $count configs to test\n";
2539 my $half = int($#start_list / 2);
2542 my @tophalf = @start_list[0 .. $half];
2544 create_config @tophalf;
2545 read_current_config \%current_config;
2547 $count = $#tophalf + 1;
2548 doprint "Testing $count configs\n";
2550 # make sure we test something
2551 foreach my $config (@tophalf) {
2552 if (defined($current_config{$config})) {
2558 # try the other half
2559 doprint "Top half produced no set configs, trying bottom half\n";
2560 @tophalf = @start_list[$half + 1 .. $#start_list];
2561 create_config @tophalf;
2562 read_current_config \%current_config;
2563 foreach my $config (@tophalf) {
2564 if (defined($current_config{$config})) {
2570 doprint "Failed: Can't make new config with current configs\n";
2571 foreach my $config (@start_list) {
2572 doprint " CONFIG: $config\n";
2576 $count = $#tophalf + 1;
2577 doprint "Testing $count configs\n";
2580 $ret = run_config_bisect_test $type;
2581 if ($bisect_manual) {
2582 $ret = answer_bisect;
2585 process_passed %current_config;
2589 doprint "This config had a failure.\n";
2590 doprint "Removing these configs that were not set in this config:\n";
2591 doprint "config copied to $outputdir/config_bad\n";
2592 run_command "cp -f $output_config $outputdir/config_bad";
2594 # A config exists in this group that was bad.
2595 foreach my $config (keys %config_list) {
2596 if (!defined($current_config{$config})) {
2597 doprint " removing $config\n";
2598 delete $config_list{$config};
2602 @start_list = @tophalf;
2604 if ($#start_list == 0) {
2605 process_failed $start_list[0];
2609 # remove half the configs we are looking at and see if
2611 $half = int($#start_list / 2);
2612 } while ($#start_list > 0);
2614 # we found a single config, try it again unless we are running manually
2616 if ($bisect_manual) {
2617 process_failed $start_list[0];
2621 my @tophalf = @start_list[0 .. 0];
2623 $ret = run_config_bisect_test $type;
2625 process_passed %current_config;
2629 process_failed $start_list[0];
2636 my $start_config = $config_bisect;
2638 my $tmpconfig = "$tmpdir/use_config";
2640 if (defined($config_bisect_good)) {
2641 process_config_ignore $config_bisect_good;
2644 # Make the file with the bad config and the min config
2645 if (defined($minconfig)) {
2646 # read the min config for things to ignore
2647 run_command "cp $minconfig $tmpconfig" or
2648 dodie "failed to copy $minconfig to $tmpconfig";
2653 if (-f $tmpconfig) {
2654 load_force_config($tmpconfig);
2655 process_config_ignore $tmpconfig;
2658 # now process the start config
2659 run_command "cp $start_config $output_config" or
2660 dodie "failed to copy $start_config to $output_config";
2662 # read directly what we want to check
2664 open (IN, $output_config)
2665 or dodie "failed to open $output_config";
2668 if (/^((CONFIG\S*)=.*)/) {
2669 $config_check{$2} = $1;
2674 # Now run oldconfig with the minconfig
2677 # check to see what we lost (or gained)
2678 open (IN, $output_config)
2679 or dodie "Failed to read $start_config";
2681 my %removed_configs;
2685 if (/^((CONFIG\S*)=.*)/) {
2686 # save off all options
2687 $config_set{$2} = $1;
2688 if (defined($config_check{$2})) {
2689 if (defined($config_ignore{$2})) {
2690 $removed_configs{$2} = $1;
2692 $config_list{$2} = $1;
2694 } elsif (!defined($config_ignore{$2})) {
2695 $added_configs{$2} = $1;
2696 $config_list{$2} = $1;
2702 my @confs = keys %removed_configs;
2704 doprint "Configs overridden by default configs and removed from check:\n";
2705 foreach my $config (@confs) {
2706 doprint " $config\n";
2709 @confs = keys %added_configs;
2711 doprint "Configs appearing in make oldconfig and added:\n";
2712 foreach my $config (@confs) {
2713 doprint " $config\n";
2720 # Sometimes kconfig does weird things. We must make sure
2721 # that the config we autocreate has everything we need
2722 # to test, otherwise we may miss testing configs, or
2723 # may not be able to create a new config.
2724 # Here we create a config with everything set.
2725 create_config (keys %config_list);
2726 read_current_config \%config_test;
2727 foreach my $config (keys %config_list) {
2728 if (!defined($config_test{$config})) {
2731 doprint "Configs not produced by kconfig (will not be checked):\n";
2733 doprint " $config\n";
2734 delete $config_list{$config};
2739 $ret = run_config_bisect;
2742 return $ret if ($ret < 0);
2747 sub patchcheck_reboot {
2748 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
2749 reboot_to_good $patchcheck_sleep_time;
2755 die "PATCHCHECK_START[$i] not defined\n"
2756 if (!defined($patchcheck_start));
2757 die "PATCHCHECK_TYPE[$i] not defined\n"
2758 if (!defined($patchcheck_type));
2760 my $start = $patchcheck_start;
2763 if (defined($patchcheck_end)) {
2764 $end = $patchcheck_end;
2767 # Get the true sha1's since we can use things like HEAD~3
2768 $start = get_sha1($start);
2769 $end = get_sha1($end);
2771 my $type = $patchcheck_type;
2773 # Can't have a test without having a test to run
2774 if ($type eq "test" && !defined($run_test)) {
2778 open (IN, "git log --pretty=oneline $end|") or
2779 dodie "could not get git list";
2785 $list[$#list+1] = $_;
2786 last if (/^$start/);
2790 if ($list[$#list] !~ /^$start/) {
2791 fail "SHA1 $start not found";
2794 # go backwards in the list
2795 @list = reverse @list;
2797 my $save_clean = $noclean;
2798 my %ignored_warnings;
2800 if (defined($ignore_warnings)) {
2801 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2802 $ignored_warnings{$sha1} = 1;
2807 foreach my $item (@list) {
2809 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2811 doprint "\nProcessing commit $item\n\n";
2813 run_command "git checkout $sha1" or
2814 die "Failed to checkout $sha1";
2816 # only clean on the first and last patch
2817 if ($item eq $list[0] ||
2818 $item eq $list[$#list]) {
2819 $noclean = $save_clean;
2824 if (defined($minconfig)) {
2825 build "useconfig:$minconfig" or return 0;
2827 # ?? no config to use?
2828 build "oldconfig" or return 0;
2832 if (!defined($ignored_warnings{$sha1})) {
2833 check_buildlog $sha1 or return 0;
2836 next if ($type eq "build");
2840 start_monitor_and_boot or $failed = 1;
2842 if (!$failed && $type ne "boot"){
2843 do_run_test or $failed = 1;
2846 return 0 if ($failed);
2866 # $config depends on $dep
2867 my ($config, $dep) = @_;
2869 if (defined($depends{$config})) {
2870 $depends{$config} .= " " . $dep;
2872 $depends{$config} = $dep;
2875 # record the number of configs depending on $dep
2876 if (defined $depcount{$dep}) {
2879 $depcount{$dep} = 1;
2883 # taken from streamline_config.pl
2895 if (! -f $kconfig) {
2896 doprint "file $kconfig does not exist, skipping\n";
2900 open(KIN, "$kconfig")
2901 or die "Can't open $kconfig";
2905 # Make sure that lines ending with \ continue
2907 $_ = $line . " " . $_;
2918 # collect any Kconfig sources
2919 if (/^source\s*"(.*)"/) {
2920 $kconfigs[$#kconfigs+1] = $1;
2924 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2928 for (my $i = 0; $i < $iflevel; $i++) {
2929 add_dep $config, $ifdeps[$i];
2932 # collect the depends for the config
2933 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2935 add_dep $config, $1;
2937 # Get the configs that select this config
2938 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2940 # selected by depends on config
2941 add_dep $1, $config;
2943 # Check for if statements
2944 } elsif (/^if\s+(.*\S)\s*$/) {
2946 # remove beginning and ending non text
2947 $deps =~ s/^[^a-zA-Z0-9_]*//;
2948 $deps =~ s/[^a-zA-Z0-9_]*$//;
2950 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2952 $ifdeps[$iflevel++] = join ':', @deps;
2954 } elsif (/^endif/) {
2956 $iflevel-- if ($iflevel);
2959 } elsif (/^\s*help\s*$/) {
2965 # read in any configs that were found.
2966 foreach $kconfig (@kconfigs) {
2967 if (!defined($read_kconfigs{$kconfig})) {
2968 $read_kconfigs{$kconfig} = 1;
2969 read_kconfig("$builddir/$kconfig");
2975 # find out which arch this is by the kconfig file
2976 open (IN, $output_config)
2977 or dodie "Failed to read $output_config";
2980 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2987 if (!defined($arch)) {
2988 doprint "Could not find arch from config file\n";
2989 doprint "no dependencies used\n";
2993 # arch is really the subarch, we need to know
2994 # what directory to look at.
2995 if ($arch eq "i386" || $arch eq "x86_64") {
2997 } elsif ($arch =~ /^tile/) {
3001 my $kconfig = "$builddir/arch/$arch/Kconfig";
3003 if (! -f $kconfig && $arch =~ /\d$/) {
3005 # some subarchs have numbers, truncate them
3007 $kconfig = "$builddir/arch/$arch/Kconfig";
3008 if (! -f $kconfig) {
3009 doprint "No idea what arch dir $orig is for\n";
3010 doprint "no dependencies used\n";
3015 read_kconfig($kconfig);
3018 sub read_config_list {
3022 or dodie "Failed to read $config";
3025 if (/^((CONFIG\S*)=.*)/) {
3026 if (!defined($config_ignore{$2})) {
3027 $config_list{$2} = $1;
3035 sub read_output_config {
3038 assign_configs \%config_ignore, $config;
3041 sub make_new_config {
3044 open (OUT, ">$output_config")
3045 or dodie "Failed to write $output_config";
3047 foreach my $config (@configs) {
3048 print OUT "$config\n";
3056 $config =~ s/CONFIG_//;
3064 my $kconfig = chomp_config $dep;
3066 $dep = $depends{"$kconfig"};
3068 # the dep string we have saves the dependencies as they
3069 # were found, including expressions like ! && ||. We
3070 # want to split this out into just an array of configs.
3072 my $valid = "A-Za-z_0-9";
3076 while ($dep =~ /[$valid]/) {
3078 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3079 my $conf = "CONFIG_" . $1;
3081 $configs[$#configs + 1] = $conf;
3083 $dep =~ s/^[^$valid]*[$valid]+//;
3085 die "this should never happen";
3095 my %processed_configs;
3096 my %nochange_config;
3098 sub test_this_config {
3103 # if we already processed this config, skip it
3104 if (defined($processed_configs{$config})) {
3107 $processed_configs{$config} = 1;
3109 # if this config failed during this round, skip it
3110 if (defined($nochange_config{$config})) {
3114 my $kconfig = chomp_config $config;
3116 # Test dependencies first
3117 if (defined($depends{"$kconfig"})) {
3118 my @parents = get_depends $config;
3119 foreach my $parent (@parents) {
3120 # if the parent is in the min config, check it first
3121 next if (!defined($min_configs{$parent}));
3122 $found = test_this_config($parent);
3123 if (defined($found)) {
3129 # Remove this config from the list of configs
3130 # do a make oldnoconfig and then read the resulting
3131 # .config to make sure it is missing the config that
3133 my %configs = %min_configs;
3134 delete $configs{$config};
3135 make_new_config ((values %configs), (values %keep_configs));
3138 assign_configs \%configs, $output_config;
3140 return $config if (!defined($configs{$config}));
3142 doprint "disabling config $config did not change .config\n";
3144 $nochange_config{$config} = 1;
3149 sub make_min_config {
3152 my $type = $minconfig_type;
3153 if ($type ne "boot" && $type ne "test") {
3154 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3155 " make_min_config works only with 'boot' and 'test'\n" and return;
3158 if (!defined($output_minconfig)) {
3159 fail "OUTPUT_MIN_CONFIG not defined" and return;
3162 # If output_minconfig exists, and the start_minconfig
3163 # came from min_config, than ask if we should use
3165 if (-f $output_minconfig && !$start_minconfig_defined) {
3166 print "$output_minconfig exists\n";
3167 if (!defined($use_output_minconfig)) {
3168 if (read_yn " Use it as minconfig?") {
3169 $start_minconfig = $output_minconfig;
3171 } elsif ($use_output_minconfig > 0) {
3172 doprint "Using $output_minconfig as MIN_CONFIG\n";
3173 $start_minconfig = $output_minconfig;
3175 doprint "Set to still use MIN_CONFIG as starting point\n";
3179 if (!defined($start_minconfig)) {
3180 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3183 my $temp_config = "$tmpdir/temp_config";
3185 # First things first. We build an allnoconfig to find
3186 # out what the defaults are that we can't touch.
3187 # Some are selections, but we really can't handle selections.
3189 my $save_minconfig = $minconfig;
3192 run_command "$make allnoconfig" or return 0;
3196 process_config_ignore $output_config;
3198 undef %save_configs;
3201 if (defined($ignore_config)) {
3202 # make sure the file exists
3203 `touch $ignore_config`;
3204 assign_configs \%save_configs, $ignore_config;
3207 %keep_configs = %save_configs;
3209 doprint "Load initial configs from $start_minconfig\n";
3211 # Look at the current min configs, and save off all the
3212 # ones that were set via the allnoconfig
3213 assign_configs \%min_configs, $start_minconfig;
3215 my @config_keys = keys %min_configs;
3217 # All configs need a depcount
3218 foreach my $config (@config_keys) {
3219 my $kconfig = chomp_config $config;
3220 if (!defined $depcount{$kconfig}) {
3221 $depcount{$kconfig} = 0;
3225 # Remove anything that was set by the make allnoconfig
3226 # we shouldn't need them as they get set for us anyway.
3227 foreach my $config (@config_keys) {
3228 # Remove anything in the ignore_config
3229 if (defined($keep_configs{$config})) {
3230 my $file = $ignore_config;
3231 $file =~ s,.*/(.*?)$,$1,;
3232 doprint "$config set by $file ... ignored\n";
3233 delete $min_configs{$config};
3236 # But make sure the settings are the same. If a min config
3237 # sets a selection, we do not want to get rid of it if
3238 # it is not the same as what we have. Just move it into
3240 if (defined($config_ignore{$config})) {
3241 if ($config_ignore{$config} ne $min_configs{$config}) {
3242 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3243 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3244 $keep_configs{$config} = $min_configs{$config};
3246 doprint "$config set by allnoconfig ... ignored\n";
3248 delete $min_configs{$config};
3260 # Now disable each config one by one and do a make oldconfig
3261 # till we find a config that changes our list.
3263 my @test_configs = keys %min_configs;
3265 # Sort keys by who is most dependent on
3266 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3269 # Put configs that did not modify the config at the end.
3271 for (my $i = 0; $i < $#test_configs; $i++) {
3272 if (!defined($nochange_config{$test_configs[0]})) {
3276 # This config didn't change the .config last time.
3277 # Place it at the end
3278 my $config = shift @test_configs;
3279 push @test_configs, $config;
3282 # if every test config has failed to modify the .config file
3283 # in the past, then reset and start over.
3285 undef %nochange_config;
3288 undef %processed_configs;
3290 foreach my $config (@test_configs) {
3292 $found = test_this_config $config;
3294 last if (defined($found));
3296 # oh well, try another config
3299 if (!defined($found)) {
3300 # we could have failed due to the nochange_config hash
3301 # reset and try again
3303 undef %nochange_config;
3307 doprint "No more configs found that we can disable\n";
3315 doprint "Test with $config disabled\n";
3317 # set in_bisect to keep build and monitor from dieing
3321 build "oldconfig" or $failed = 1;
3323 start_monitor_and_boot or $failed = 1;
3325 if ($type eq "test" && !$failed) {
3326 do_run_test or $failed = 1;
3335 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
3336 # this config is needed, add it to the ignore list.
3337 $keep_configs{$config} = $min_configs{$config};
3338 $save_configs{$config} = $min_configs{$config};
3339 delete $min_configs{$config};
3341 # update new ignore configs
3342 if (defined($ignore_config)) {
3343 open (OUT, ">$temp_config")
3344 or die "Can't write to $temp_config";
3345 foreach my $config (keys %save_configs) {
3346 print OUT "$save_configs{$config}\n";
3349 run_command "mv $temp_config $ignore_config" or
3350 dodie "failed to copy update to $ignore_config";
3354 # We booted without this config, remove it from the minconfigs.
3355 doprint "$config is not needed, disabling\n";
3357 delete $min_configs{$config};
3359 # Also disable anything that is not enabled in this config
3361 assign_configs \%configs, $output_config;
3362 my @config_keys = keys %min_configs;
3363 foreach my $config (@config_keys) {
3364 if (!defined($configs{$config})) {
3365 doprint "$config is not set, disabling\n";
3366 delete $min_configs{$config};
3370 # Save off all the current mandidory configs
3371 open (OUT, ">$temp_config")
3372 or die "Can't write to $temp_config";
3373 foreach my $config (keys %keep_configs) {
3374 print OUT "$keep_configs{$config}\n";
3376 foreach my $config (keys %min_configs) {
3377 print OUT "$min_configs{$config}\n";
3381 run_command "mv $temp_config $output_minconfig" or
3382 dodie "failed to copy update to $output_minconfig";
3385 doprint "Reboot and wait $sleep_time seconds\n";
3386 reboot_to_good $sleep_time;
3393 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3396 $ktest_config = $ARGV[0];
3397 if (! -f $ktest_config) {
3398 print "$ktest_config does not exist.\n";
3399 if (!read_yn "Create it?") {
3404 $ktest_config = "ktest.conf";
3407 if (! -f $ktest_config) {
3410 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3412 # Generated by ktest.pl
3415 # PWD is a ktest.pl variable that will result in the process working
3416 # directory that ktest.pl is executed in.
3418 # THIS_DIR is automatically assigned the PWD of the path that generated
3419 # the config file. It is best to use this variable when assigning other
3420 # directory paths within this directory. This allows you to easily
3421 # move the test cases to other locations or to other machines.
3423 THIS_DIR := $variable{"PWD"}
3425 # Define each test with TEST_START
3426 # The config options below it will override the defaults
3428 TEST_TYPE = $default{"TEST_TYPE"}
3435 read_config $ktest_config;
3437 if (defined($opt{"LOG_FILE"})) {
3438 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3441 # Append any configs entered in manually to the config file.
3442 my @new_configs = keys %entered_configs;
3443 if ($#new_configs >= 0) {
3444 print "\nAppending entered in configs to $ktest_config\n";
3445 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3446 foreach my $config (@new_configs) {
3447 print OUT "$config = $entered_configs{$config}\n";
3448 $opt{$config} = process_variables($entered_configs{$config});
3452 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3453 unlink $opt{"LOG_FILE"};
3456 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3458 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3461 doprint "DEFAULT OPTIONS:\n";
3463 doprint "\nTEST $i OPTIONS";
3464 if (defined($repeat_tests{$i})) {
3465 $repeat = $repeat_tests{$i};
3466 doprint " ITERATE $repeat";
3471 foreach my $option (sort keys %opt) {
3473 if ($option =~ /\[(\d+)\]$/) {
3479 doprint "$option = $opt{$option}\n";
3483 sub __set_test_option {
3484 my ($name, $i) = @_;
3486 my $option = "$name\[$i\]";
3488 if (defined($opt{$option})) {
3489 return $opt{$option};
3492 foreach my $test (keys %repeat_tests) {
3494 $i < $test + $repeat_tests{$test}) {
3495 $option = "$name\[$test\]";
3496 if (defined($opt{$option})) {
3497 return $opt{$option};
3502 if (defined($opt{$name})) {
3509 sub set_test_option {
3510 my ($name, $i) = @_;
3512 my $option = __set_test_option($name, $i);
3513 return $option if (!defined($option));
3515 return eval_option($option, $i);
3518 # First we need to do is the builds
3519 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3521 # Do not reboot on failing test options
3523 $reboot_success = 0;
3529 my $makecmd = set_test_option("MAKE_CMD", $i);
3531 # Load all the options into their mapped variable names
3532 foreach my $opt (keys %option_map) {
3533 ${$option_map{$opt}} = set_test_option($opt, $i);
3536 $start_minconfig_defined = 1;
3538 # The first test may override the PRE_KTEST option
3539 if (defined($pre_ktest) && $i == 1) {
3541 run_command $pre_ktest;
3544 # Any test can override the POST_KTEST option
3545 # The last test takes precedence.
3546 if (defined($post_ktest)) {
3547 $final_post_ktest = $post_ktest;
3550 if (!defined($start_minconfig)) {
3551 $start_minconfig_defined = 0;
3552 $start_minconfig = $minconfig;
3555 chdir $builddir || die "can't change directory to $builddir";
3557 foreach my $dir ($tmpdir, $outputdir) {
3560 die "can't create $dir";
3564 $ENV{"SSH_USER"} = $ssh_user;
3565 $ENV{"MACHINE"} = $machine;
3567 $buildlog = "$tmpdir/buildlog-$machine";
3568 $testlog = "$tmpdir/testlog-$machine";
3569 $dmesg = "$tmpdir/dmesg-$machine";
3570 $make = "$makecmd O=$outputdir";
3571 $output_config = "$outputdir/.config";
3574 $target = "$ssh_user\@$machine";
3575 if ($reboot_type eq "grub") {
3576 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3580 my $run_type = $build_type;
3581 if ($test_type eq "patchcheck") {
3582 $run_type = $patchcheck_type;
3583 } elsif ($test_type eq "bisect") {
3584 $run_type = $bisect_type;
3585 } elsif ($test_type eq "config_bisect") {
3586 $run_type = $config_bisect_type;
3589 if ($test_type eq "make_min_config") {
3593 # mistake in config file?
3594 if (!defined($run_type)) {
3595 $run_type = "ERROR";
3599 $installme = " no_install" if ($no_install);
3602 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
3604 if (defined($pre_test)) {
3605 run_command $pre_test;
3612 if (defined($addconfig)) {
3613 my $min = $minconfig;
3614 if (!defined($minconfig)) {
3617 run_command "cat $addconfig $min > $tmpdir/add_config" or
3618 dodie "Failed to create temp config";
3619 $minconfig = "$tmpdir/add_config";
3622 if (defined($checkout)) {
3623 run_command "git checkout $checkout" or
3624 die "failed to checkout $checkout";
3629 # A test may opt to not reboot the box
3630 if ($reboot_on_success) {
3631 $reboot_success = 1;
3634 if ($test_type eq "bisect") {
3637 } elsif ($test_type eq "config_bisect") {
3640 } elsif ($test_type eq "patchcheck") {
3643 } elsif ($test_type eq "make_min_config") {
3648 if ($build_type ne "nobuild") {
3649 build $build_type or next;
3652 if ($test_type eq "install") {
3659 if ($test_type ne "build") {
3661 start_monitor_and_boot or $failed = 1;
3663 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3664 do_run_test or $failed = 1;
3673 if (defined($final_post_ktest)) {
3674 run_command $final_post_ktest;
3677 if ($opt{"POWEROFF_ON_SUCCESS"}) {
3679 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
3681 } elsif (defined($switch_to_good)) {
3682 # still need to get to the good kernel
3683 run_command $switch_to_good;
3687 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";