3 # Copywrite 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);
16 $#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
26 $default{"NUM_TESTS"} = 1;
27 $default{"REBOOT_TYPE"} = "grub";
28 $default{"TEST_TYPE"} = "test";
29 $default{"BUILD_TYPE"} = "randconfig";
30 $default{"MAKE_CMD"} = "make";
31 $default{"TIMEOUT"} = 120;
32 $default{"TMP_DIR"} = "/tmp/ktest";
33 $default{"SLEEP_TIME"} = 60; # sleep time between tests
34 $default{"BUILD_NOCLEAN"} = 0;
35 $default{"REBOOT_ON_ERROR"} = 0;
36 $default{"POWEROFF_ON_ERROR"} = 0;
37 $default{"REBOOT_ON_SUCCESS"} = 1;
38 $default{"POWEROFF_ON_SUCCESS"} = 0;
39 $default{"BUILD_OPTIONS"} = "";
40 $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
41 $default{"CLEAR_LOG"} = 0;
42 $default{"SUCCESS_LINE"} = "login:";
43 $default{"BOOTED_TIMEOUT"} = 1;
44 $default{"DIE_ON_FAILURE"} = 1;
45 $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
46 $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
47 $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
48 $default{"STOP_AFTER_SUCCESS"} = 10;
49 $default{"STOP_AFTER_FAILURE"} = 60;
66 my $poweroff_on_error;
68 my $powercycle_after_reboot;
69 my $poweroff_after_halt;
84 my $in_patchcheck = 0;
93 my $bisect_sleep_time;
99 my $stop_after_success;
100 my $stop_after_failure;
108 my ($lvalue, $rvalue) = @_;
110 if (defined($opt{$lvalue})) {
111 die "Error: Option $lvalue defined more than once!\n";
113 if ($rvalue =~ /^\s*$/) {
114 delete $opt{$lvalue};
116 $opt{$lvalue} = $rvalue;
123 open(IN, $config) || die "can't read file $config";
126 $name =~ s,.*/(.*),$1,;
131 my $num_tests_set = 0;
137 # ignore blank lines and comments
138 next if (/^\s*$/ || /\s*\#/);
140 if (/^\s*TEST_START(.*)/) {
144 if ($num_tests_set) {
145 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
148 my $old_test_num = $test_num;
149 my $old_repeat = $repeat;
151 $test_num += $repeat;
155 if ($rest =~ /\s+SKIP(.*)/) {
162 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
165 $repeat_tests{"$test_num"} = $repeat;
168 if ($rest =~ /\s+SKIP(.*)/) {
173 if ($rest !~ /^\s*$/) {
174 die "$name: $.: Gargbage found after TEST_START\n$_";
178 $test_num = $old_test_num;
179 $repeat = $old_repeat;
182 } elsif (/^\s*DEFAULTS(.*)$/) {
187 if ($rest =~ /\s+SKIP(.*)/) {
194 if ($rest !~ /^\s*$/) {
195 die "$name: $.: Gargbage found after DEFAULTS\n$_";
198 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
206 ($lvalue eq "NUM_TESTS" ||
207 $lvalue eq "LOG_FILE" ||
208 $lvalue eq "CLEAR_LOG")) {
209 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
212 if ($lvalue eq "NUM_TESTS") {
214 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
217 die "$name: $.: NUM_TESTS must be set in default section\n";
222 if ($default || $lvalue =~ /\[\d+\]$/) {
223 set_value($lvalue, $rvalue);
225 my $val = "$lvalue\[$test_num\]";
226 set_value($val, $rvalue);
229 $repeats{$val} = $repeat;
233 die "$name: $.: Garbage found in config\n$_";
240 $test_num += $repeat - 1;
241 $opt{"NUM_TESTS"} = $test_num;
246 foreach my $default (keys %default) {
247 if (!defined($opt{$default})) {
248 $opt{$default} = $default{$default};
254 if (defined($opt{"LOG_FILE"})) {
255 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
262 if (defined($opt{"LOG_FILE"})) {
277 # try to reboot normally
278 if (run_command $reboot) {
279 if (defined($powercycle_after_reboot)) {
280 sleep $powercycle_after_reboot;
281 run_command "$power_cycle";
284 # nope? power cycle it.
285 run_command "$power_cycle";
292 return $test_type eq "build" ||
293 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
294 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
298 doprint "CRITICAL FAILURE... ", @_, "\n";
302 if ($reboot_on_error && !do_not_reboot) {
304 doprint "REBOOTING\n";
307 } elsif ($poweroff_on_error && defined($power_off)) {
308 doprint "POWERING OFF\n";
320 my $pid = open($fp, "$console|") or
321 dodie "Can't open console $console";
323 $flags = fcntl($fp, F_GETFL, 0) or
324 dodie "Can't get flags for the socket: $!";
325 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
326 dodie "Can't set flags for the socket: $!";
334 doprint "kill child process $pid\n";
342 if ($monitor_cnt++) {
345 $monitor_fp = \*MONFD;
346 $monitor_pid = open_console $monitor_fp;
350 open(MONFD, "Stop perl from warning about single use of MONFD");
354 if (--$monitor_cnt) {
357 close_console($monitor_fp, $monitor_pid);
360 sub wait_for_monitor {
364 doprint "** Wait for monitor to settle down **\n";
366 # read the monitor and wait for the system to calm down
368 $line = wait_for_input($monitor_fp, $time);
369 print "$line" if (defined($line));
370 } while (defined($line));
371 print "** Monitor flushed **\n";
376 if ($die_on_failure) {
384 # no need to reboot for just building.
385 if (!do_not_reboot) {
386 doprint "REBOOTING\n";
389 wait_for_monitor $sleep_time;
393 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
394 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
395 doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n";
396 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
397 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
399 return 1 if (!defined($store_failures));
402 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
403 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
405 my $type = $build_type;
406 if ($type =~ /useconfig/) {
410 my $dir = "$machine-$test_type-$type-fail-$date";
411 my $faildir = "$store_failures/$dir";
415 die "can't create $faildir";
417 if (-f "$output_config") {
418 cp "$output_config", "$faildir/config" or
419 die "failed to copy .config";
422 cp $buildlog, "$faildir/buildlog" or
423 die "failed to move $buildlog";
426 cp $dmesg, "$faildir/dmesg" or
427 die "failed to move $dmesg";
430 doprint "*** Saved info to $faildir ***\n";
441 $command =~ s/\$SSH_USER/$ssh_user/g;
442 $command =~ s/\$MACHINE/$machine/g;
444 doprint("$command ... ");
446 $pid = open(CMD, "$command 2>&1 |") or
447 (fail "unable to exec $command" and return 0);
449 if (defined($opt{"LOG_FILE"})) {
450 open(LOG, ">>$opt{LOG_FILE}") or
451 dodie "failed to write to log";
455 if (defined($redirect)) {
456 open (RD, ">$redirect") or
457 dodie "failed to write to redirect $redirect";
462 print LOG if ($dolog);
470 close(LOG) if ($dolog);
471 close(RD) if ($dord);
484 my $cp_exec = $ssh_exec;
486 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
487 return run_command "$cp_exec";
491 my ($src, $dst) = @_;
492 my $cp_scp = $scp_to_target;
494 $cp_scp =~ s/\$SRC_FILE/$src/g;
495 $cp_scp =~ s/\$DST_FILE/$dst/g;
497 return run_command "$cp_scp";
502 if ($reboot_type ne "grub") {
505 return if (defined($grub_number));
507 doprint "Find grub menu ... ";
510 my $ssh_grub = $ssh_exec;
511 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
513 open(IN, "$ssh_grub |")
514 or die "unable to get menu.lst";
517 if (/^\s*title\s+$grub_menu\s*$/) {
520 } elsif (/^\s*title\s/) {
526 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
527 if ($grub_number < 0);
528 doprint "$grub_number\n";
533 my ($fp, $time) = @_;
539 if (!defined($time)) {
544 vec($rin, fileno($fp), 1) = 1;
545 $ready = select($rin, undef, undef, $time);
549 # try to read one char at a time
550 while (sysread $fp, $ch, 1) {
552 last if ($ch eq "\n");
555 if (!length($line)) {
563 if ($reboot_type eq "grub") {
564 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
568 run_command "$reboot_script";
574 doprint "git rev-list --max-count=1 $commit ... ";
575 my $sha1 = `git rev-list --max-count=1 $commit`;
582 dodie "Failed to get git $commit";
595 my $skip_call_trace = 0;
603 open(DMESG, "> $dmesg") or
604 die "unable to write to $dmesg";
614 $line = wait_for_input($monitor_fp, $booted_timeout);
616 $line = wait_for_input($monitor_fp);
619 last if (!defined($line));
624 # we are not guaranteed to get a full line
627 if ($full_line =~ /$success_line/) {
629 $success_start = time;
632 if ($booted && defined($stop_after_success) &&
633 $stop_after_success >= 0) {
635 if ($now - $success_start >= $stop_after_success) {
636 doprint "Test forced to stop after $stop_after_success seconds after success\n";
641 if ($full_line =~ /\[ backtrace testing \]/) {
642 $skip_call_trace = 1;
645 if ($full_line =~ /call trace:/i) {
646 if (!$skip_call_trace) {
648 $failure_start = time;
652 if ($bug && defined($stop_after_failure) &&
653 $stop_after_failure >= 0) {
655 if ($now - $failure_start >= $stop_after_failure) {
656 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
661 if ($full_line =~ /\[ end of backtrace testing \]/) {
662 $skip_call_trace = 0;
665 if ($full_line =~ /Kernel panic -/) {
677 return 0 if ($in_bisect);
678 fail "failed - got a bug report" and return 0;
682 return 0 if ($in_bisect);
683 fail "failed - never got a boot prompt." and return 0;
691 run_scp "$outputdir/$build_target", "$target_image" or
692 dodie "failed to copy image";
694 my $install_mods = 0;
696 # should we process modules?
698 open(IN, "$output_config") or dodie("Can't read config file");
700 if (/CONFIG_MODULES(=y)?/) {
701 $install_mods = 1 if (defined($1));
707 if (!$install_mods) {
708 doprint "No modules needed\n";
712 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
713 dodie "Failed to install modules";
715 my $modlib = "/lib/modules/$version";
716 my $modtar = "ktest-mods.tar.bz2";
718 run_ssh "rm -rf $modlib" or
719 dodie "failed to remove old mods: $modlib";
721 # would be nice if scp -r did not follow symbolic links
722 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
723 dodie "making tarball";
725 run_scp "$tmpdir/$modtar", "/tmp" or
726 dodie "failed to copy modules";
728 unlink "$tmpdir/$modtar";
730 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
731 dodie "failed to tar modules";
733 run_ssh "rm -f /tmp/$modtar";
735 return if (!defined($post_install));
737 my $cp_post_install = $post_install;
738 $cp_post_install = s/\$KERNEL_VERSION/$version/g;
739 run_command "$cp_post_install" or
740 dodie "Failed to run post install";
746 my @files = `git show $patch | diffstat -l`;
748 open(IN, "git show $patch |") or
749 dodie "failed to show $patch";
751 if (m,^--- a/(.*),) {
753 $files[$#files] = $1;
758 open(IN, $buildlog) or dodie "Can't open $buildlog";
760 if (/^\s*(.*?):.*(warning|error)/) {
762 foreach my $file (@files) {
763 my $fullpath = "$builddir/$file";
764 if ($file eq $err || $fullpath eq $err) {
765 fail "$file built with warnings" and return 0;
781 if ($type =~ /^useconfig:(.*)/) {
782 run_command "cp $1 $output_config" or
783 dodie "could not copy $1 to .config";
788 # old config can ask questions
789 if ($type eq "oldconfig") {
790 $type = "oldnoconfig";
792 # allow for empty configs
793 run_command "touch $output_config";
795 run_command "mv $output_config $outputdir/config_temp" or
796 dodie "moving .config";
798 if (!$noclean && !run_command "$make mrproper") {
799 dodie "make mrproper";
802 run_command "mv $outputdir/config_temp $output_config" or
803 dodie "moving config_temp";
805 } elsif (!$noclean) {
806 unlink "$output_config";
807 run_command "$make mrproper" or
808 dodie "make mrproper";
811 # add something to distinguish this build
812 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
813 print OUT "$localversion\n";
816 if (defined($minconfig)) {
817 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
820 run_command "$defconfig $make $type" or
821 dodie "failed make config";
823 $redirect = "$buildlog";
824 if (!run_command "$make $build_options") {
826 # bisect may need this to pass
827 return 0 if ($in_bisect);
828 fail "failed build" and return 0;
836 if (!run_ssh "halt" or defined($power_off)) {
837 if (defined($poweroff_after_halt)) {
838 sleep $poweroff_after_halt;
839 run_command "$power_off";
843 run_command "$power_off";
852 doprint "\n\n*******************************************\n";
853 doprint "*******************************************\n";
854 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
855 doprint "*******************************************\n";
856 doprint "*******************************************\n";
858 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
859 doprint "Reboot and wait $sleep_time seconds\n";
862 wait_for_monitor $sleep_time;
868 # get the release name
869 doprint "$make kernelrelease ... ";
870 $version = `$make kernelrelease | tail -1`;
872 doprint "$version\n";
878 # child should have no power
879 $reboot_on_error = 0;
880 $poweroff_on_error = 0;
883 run_command $run_test or $failed = 1;
902 doprint "run test $run_test\n";
906 $SIG{CHLD} = qw(child_finished);
910 child_run_test if (!$child_pid);
915 $line = wait_for_input($monitor_fp, 1);
916 if (defined($line)) {
918 # we are not guaranteed to get a full line
921 if ($full_line =~ /call trace:/i) {
925 if ($full_line =~ /Kernel panic -/) {
933 } while (!$child_done && !$bug);
936 doprint "Detected kernel crash!\n";
937 # kill the child with extreme prejudice
941 waitpid $child_pid, 0;
944 if ($bug || $child_exit) {
945 return 0 if $in_bisect;
946 fail "test failed" and return 0;
954 doprint "$command ... ";
956 my $output = `$command 2>&1`;
963 dodie "Failed to git bisect";
967 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
969 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
971 doprint "Found bad commit... $1\n";
974 # we already logged it, just print it now.
981 # returns 1 on success, 0 on failure
982 sub run_bisect_test {
983 my ($type, $buildtype) = @_;
992 build $buildtype or $failed = 1;
994 if ($type ne "build") {
995 dodie "Failed on build" if $failed;
1003 monitor or $failed = 1;
1005 if ($type ne "boot") {
1006 dodie "Failed on boot" if $failed;
1008 do_run_test or $failed = 1;
1016 # reboot the box to a good kernel
1017 if ($type ne "build") {
1018 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1021 wait_for_monitor $bisect_sleep_time;
1034 my $buildtype = "oldconfig";
1036 # We should have a minconfig to use?
1037 if (defined($minconfig)) {
1038 $buildtype = "useconfig:$minconfig";
1041 my $ret = run_bisect_test $type, $buildtype;
1044 # Are we looking for where it worked, not failed?
1045 if ($reverse_bisect) {
1061 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1062 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1063 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1065 my $good = $opt{"BISECT_GOOD[$i]"};
1066 my $bad = $opt{"BISECT_BAD[$i]"};
1067 my $type = $opt{"BISECT_TYPE[$i]"};
1068 my $start = $opt{"BISECT_START[$i]"};
1069 my $replay = $opt{"BISECT_REPLAY[$i]"};
1071 # convert to true sha1's
1072 $good = get_sha1($good);
1073 $bad = get_sha1($bad);
1075 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1076 $opt{"BISECT_REVERSE[$i]"} == 1) {
1077 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1078 $reverse_bisect = 1;
1080 $reverse_bisect = 0;
1083 # Can't have a test without having a test to run
1084 if ($type eq "test" && !defined($run_test)) {
1088 my $check = $opt{"BISECT_CHECK[$i]"};
1089 if (defined($check) && $check ne "0") {
1092 my $head = get_sha1("HEAD");
1094 if ($check ne "good") {
1095 doprint "TESTING BISECT BAD [$bad]\n";
1096 run_command "git checkout $bad" or
1097 die "Failed to checkout $bad";
1099 $result = run_bisect $type;
1101 if ($result ne "bad") {
1102 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1106 if ($check ne "bad") {
1107 doprint "TESTING BISECT GOOD [$good]\n";
1108 run_command "git checkout $good" or
1109 die "Failed to checkout $good";
1111 $result = run_bisect $type;
1113 if ($result ne "good") {
1114 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1118 # checkout where we started
1119 run_command "git checkout $head" or
1120 die "Failed to checkout $head";
1123 run_command "git bisect start" or
1124 dodie "could not start bisect";
1126 run_command "git bisect good $good" or
1127 dodie "could not set bisect good to $good";
1129 run_git_bisect "git bisect bad $bad" or
1130 dodie "could not set bisect bad to $bad";
1132 if (defined($replay)) {
1133 run_command "git bisect replay $replay" or
1134 dodie "failed to run replay";
1137 if (defined($start)) {
1138 run_command "git checkout $start" or
1139 dodie "failed to checkout $start";
1144 $result = run_bisect $type;
1145 $test = run_git_bisect "git bisect $result";
1148 run_command "git bisect log" or
1149 dodie "could not capture git bisect log";
1151 run_command "git bisect reset" or
1152 dodie "could not reset git bisect";
1154 doprint "Bad commit was [$bisect_bad]\n";
1167 sub process_config_ignore {
1171 or dodie "Failed to read $config";
1174 if (/^(.*?(CONFIG\S*)(=.*| is not set))/) {
1175 $config_ignore{$2} = $1;
1182 sub read_current_config {
1183 my ($config_ref) = @_;
1185 %{$config_ref} = ();
1186 undef %{$config_ref};
1188 my @key = keys %{$config_ref};
1190 print "did not delete!\n";
1193 open (IN, "$output_config");
1196 if (/^(CONFIG\S+)=(.*)/) {
1197 ${$config_ref}{$1} = $2;
1203 sub get_dependencies {
1206 my $arr = $dependency{$config};
1207 if (!defined($arr)) {
1213 foreach my $dep (@{$arr}) {
1214 print "ADD DEP $dep\n";
1215 @deps = (@deps, get_dependencies $dep);
1224 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1226 foreach my $config (@configs) {
1227 print OUT "$config_set{$config}\n";
1228 my @deps = get_dependencies $config;
1229 foreach my $dep (@deps) {
1230 print OUT "$config_set{$dep}\n";
1234 foreach my $config (keys %config_ignore) {
1235 print OUT "$config_ignore{$config}\n";
1240 run_command "$make oldnoconfig" or
1241 dodie "failed make config oldconfig";
1245 sub compare_configs {
1248 foreach my $item (keys %a) {
1249 if (!defined($b{$item})) {
1250 print "diff $item\n";
1258 print "diff2 $keys[0]\n";
1260 return -1 if ($#keys >= 0);
1265 sub run_config_bisect_test {
1268 return run_bisect_test $type, "oldconfig";
1271 sub process_passed {
1274 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1275 # Passed! All these configs are part of a good compile.
1276 # Add them to the min options.
1277 foreach my $config (keys %configs) {
1278 if (defined($config_list{$config})) {
1279 doprint " removing $config\n";
1280 $config_ignore{$config} = $config_list{$config};
1281 delete $config_list{$config};
1286 sub process_failed {
1289 doprint "\n\n***************************************\n";
1290 doprint "Found bad config: $config\n";
1291 doprint "***************************************\n\n";
1294 sub run_config_bisect {
1296 my @start_list = keys %config_list;
1298 if ($#start_list < 0) {
1299 doprint "No more configs to test!!!\n";
1303 doprint "***** RUN TEST ***\n";
1304 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1308 my $count = $#start_list + 1;
1309 doprint " $count configs to test\n";
1311 my $half = int($#start_list / 2);
1314 my @tophalf = @start_list[0 .. $half];
1316 create_config @tophalf;
1317 read_current_config \%current_config;
1319 $count = $#tophalf + 1;
1320 doprint "Testing $count configs\n";
1322 # make sure we test something
1323 foreach my $config (@tophalf) {
1324 if (defined($current_config{$config})) {
1330 # try the other half
1331 doprint "Top half produced no set configs, trying bottom half\n";
1332 @tophalf = @start_list[$half .. $#start_list];
1333 create_config @tophalf;
1334 read_current_config \%current_config;
1335 foreach my $config (@tophalf) {
1336 if (defined($current_config{$config})) {
1342 doprint "Failed: Can't make new config with current configs\n";
1343 foreach my $config (@start_list) {
1344 doprint " CONFIG: $config\n";
1348 $count = $#tophalf + 1;
1349 doprint "Testing $count configs\n";
1352 $ret = run_config_bisect_test $type;
1355 process_passed %current_config;
1359 doprint "This config had a failure.\n";
1360 doprint "Removing these configs that were not set in this config:\n";
1362 # A config exists in this group that was bad.
1363 foreach my $config (keys %config_list) {
1364 if (!defined($current_config{$config})) {
1365 doprint " removing $config\n";
1366 delete $config_list{$config};
1370 @start_list = @tophalf;
1372 if ($#start_list == 0) {
1373 process_failed $start_list[0];
1377 # remove half the configs we are looking at and see if
1379 $half = int($#start_list / 2);
1380 } while ($half > 0);
1382 # we found a single config, try it again
1383 my @tophalf = @start_list[0 .. 0];
1385 $ret = run_config_bisect_test $type;
1387 process_passed %current_config;
1391 process_failed $start_list[0];
1398 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1400 my $tmpconfig = "$tmpdir/use_config";
1402 # Make the file with the bad config and the min config
1403 if (defined($minconfig)) {
1404 # read the min config for things to ignore
1405 run_command "cp $minconfig $tmpconfig" or
1406 dodie "failed to copy $minconfig to $tmpconfig";
1412 if (defined($addconfig)) {
1413 run_command "cat $addconfig >> $tmpconfig" or
1414 dodie "failed to append $addconfig";
1418 if (-f $tmpconfig) {
1419 $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
1420 process_config_ignore $tmpconfig;
1423 # now process the start config
1424 run_command "cp $start_config $output_config" or
1425 dodie "failed to copy $start_config to $output_config";
1427 # read directly what we want to check
1429 open (IN, $output_config)
1430 or dodie "faied to open $output_config";
1433 if (/^((CONFIG\S*)=.*)/) {
1434 $config_check{$2} = $1;
1439 # Now run oldconfig with the minconfig (and addconfigs)
1440 run_command "$defconfig $make oldnoconfig" or
1441 dodie "failed make config oldconfig";
1443 # check to see what we lost (or gained)
1444 open (IN, $output_config)
1445 or dodie "Failed to read $start_config";
1447 my %removed_configs;
1451 if (/^((CONFIG\S*)=.*)/) {
1452 # save off all options
1453 $config_set{$2} = $1;
1454 if (defined($config_check{$2})) {
1455 if (defined($config_ignore{$2})) {
1456 $removed_configs{$2} = $1;
1458 $config_list{$2} = $1;
1460 } elsif (!defined($config_ignore{$2})) {
1461 $added_configs{$2} = $1;
1462 $config_list{$2} = $1;
1468 my @confs = keys %removed_configs;
1470 doprint "Configs overridden by default configs and removed from check:\n";
1471 foreach my $config (@confs) {
1472 doprint " $config\n";
1475 @confs = keys %added_configs;
1477 doprint "Configs appearing in make oldconfig and added:\n";
1478 foreach my $config (@confs) {
1479 doprint " $config\n";
1486 # Sometimes kconfig does weird things. We must make sure
1487 # that the config we autocreate has everything we need
1488 # to test, otherwise we may miss testing configs, or
1489 # may not be able to create a new config.
1490 # Here we create a config with everything set.
1491 create_config (keys %config_list);
1492 read_current_config \%config_test;
1493 foreach my $config (keys %config_list) {
1494 if (!defined($config_test{$config})) {
1497 doprint "Configs not produced by kconfig (will not be checked):\n";
1499 doprint " $config\n";
1500 delete $config_list{$config};
1505 $ret = run_config_bisect;
1508 return $ret if ($ret < 0);
1516 die "PATCHCHECK_START[$i] not defined\n"
1517 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1518 die "PATCHCHECK_TYPE[$i] not defined\n"
1519 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1521 my $start = $opt{"PATCHCHECK_START[$i]"};
1524 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1525 $end = $opt{"PATCHCHECK_END[$i]"};
1528 # Get the true sha1's since we can use things like HEAD~3
1529 $start = get_sha1($start);
1530 $end = get_sha1($end);
1532 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1534 # Can't have a test without having a test to run
1535 if ($type eq "test" && !defined($run_test)) {
1539 open (IN, "git log --pretty=oneline $end|") or
1540 dodie "could not get git list";
1546 $list[$#list+1] = $_;
1547 last if (/^$start/);
1551 if ($list[$#list] !~ /^$start/) {
1552 fail "SHA1 $start not found";
1555 # go backwards in the list
1556 @list = reverse @list;
1558 my $save_clean = $noclean;
1561 foreach my $item (@list) {
1563 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1565 doprint "\nProcessing commit $item\n\n";
1567 run_command "git checkout $sha1" or
1568 die "Failed to checkout $sha1";
1570 # only clean on the first and last patch
1571 if ($item eq $list[0] ||
1572 $item eq $list[$#list]) {
1573 $noclean = $save_clean;
1578 if (defined($minconfig)) {
1579 build "useconfig:$minconfig" or return 0;
1581 # ?? no config to use?
1582 build "oldconfig" or return 0;
1585 check_buildlog $sha1 or return 0;
1587 next if ($type eq "build");
1596 monitor or $failed = 1;
1598 if (!$failed && $type ne "boot"){
1599 do_run_test or $failed = 1;
1602 return 0 if ($failed);
1611 read_config $ARGV[0];
1614 die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
1615 die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
1616 die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
1617 die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
1618 die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
1619 die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
1620 die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
1621 die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
1622 die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
1624 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
1625 unlink $opt{"LOG_FILE"};
1628 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
1630 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
1633 doprint "DEFAULT OPTIONS:\n";
1635 doprint "\nTEST $i OPTIONS";
1636 if (defined($repeat_tests{$i})) {
1637 $repeat = $repeat_tests{$i};
1638 doprint " ITERATE $repeat";
1643 foreach my $option (sort keys %opt) {
1645 if ($option =~ /\[(\d+)\]$/) {
1651 doprint "$option = $opt{$option}\n";
1655 sub set_test_option {
1656 my ($name, $i) = @_;
1658 my $option = "$name\[$i\]";
1660 if (defined($opt{$option})) {
1661 return $opt{$option};
1664 foreach my $test (keys %repeat_tests) {
1666 $i < $test + $repeat_tests{$test}) {
1667 $option = "$name\[$test\]";
1668 if (defined($opt{$option})) {
1669 return $opt{$option};
1674 if (defined($opt{$name})) {
1681 # First we need to do is the builds
1682 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1686 my $makecmd = set_test_option("MAKE_CMD", $i);
1688 $machine = set_test_option("MACHINE", $i);
1689 $ssh_user = set_test_option("SSH_USER", $i);
1690 $tmpdir = set_test_option("TMP_DIR", $i);
1691 $outputdir = set_test_option("OUTPUT_DIR", $i);
1692 $builddir = set_test_option("BUILD_DIR", $i);
1693 $test_type = set_test_option("TEST_TYPE", $i);
1694 $build_type = set_test_option("BUILD_TYPE", $i);
1695 $build_options = set_test_option("BUILD_OPTIONS", $i);
1696 $power_cycle = set_test_option("POWER_CYCLE", $i);
1697 $reboot = set_test_option("REBOOT", $i);
1698 $noclean = set_test_option("BUILD_NOCLEAN", $i);
1699 $minconfig = set_test_option("MIN_CONFIG", $i);
1700 $run_test = set_test_option("TEST", $i);
1701 $addconfig = set_test_option("ADD_CONFIG", $i);
1702 $reboot_type = set_test_option("REBOOT_TYPE", $i);
1703 $grub_menu = set_test_option("GRUB_MENU", $i);
1704 $post_install = set_test_option("POST_INSTALL", $i);
1705 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
1706 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
1707 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
1708 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
1709 $power_off = set_test_option("POWER_OFF", $i);
1710 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
1711 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
1712 $sleep_time = set_test_option("SLEEP_TIME", $i);
1713 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
1714 $store_failures = set_test_option("STORE_FAILURES", $i);
1715 $timeout = set_test_option("TIMEOUT", $i);
1716 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
1717 $console = set_test_option("CONSOLE", $i);
1718 $success_line = set_test_option("SUCCESS_LINE", $i);
1719 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
1720 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
1721 $build_target = set_test_option("BUILD_TARGET", $i);
1722 $ssh_exec = set_test_option("SSH_EXEC", $i);
1723 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
1724 $target_image = set_test_option("TARGET_IMAGE", $i);
1725 $localversion = set_test_option("LOCALVERSION", $i);
1727 chdir $builddir || die "can't change directory to $builddir";
1731 die "can't create $tmpdir";
1734 $ENV{"SSH_USER"} = $ssh_user;
1735 $ENV{"MACHINE"} = $machine;
1737 $target = "$ssh_user\@$machine";
1739 $buildlog = "$tmpdir/buildlog-$machine";
1740 $dmesg = "$tmpdir/dmesg-$machine";
1741 $make = "$makecmd O=$outputdir";
1742 $output_config = "$outputdir/.config";
1744 if ($reboot_type eq "grub") {
1745 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
1746 } elsif (!defined($reboot_script)) {
1747 dodie "REBOOT_SCRIPT not defined"
1750 my $run_type = $build_type;
1751 if ($test_type eq "patchcheck") {
1752 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
1753 } elsif ($test_type eq "bisect") {
1754 $run_type = $opt{"BISECT_TYPE[$i]"};
1755 } elsif ($test_type eq "config_bisect") {
1756 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
1759 # mistake in config file?
1760 if (!defined($run_type)) {
1761 $run_type = "ERROR";
1765 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
1770 if (!defined($minconfig)) {
1771 $minconfig = $addconfig;
1773 } elsif (defined($addconfig)) {
1774 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
1775 dodie "Failed to create temp config";
1776 $minconfig = "$tmpdir/add_config";
1779 my $checkout = $opt{"CHECKOUT[$i]"};
1780 if (defined($checkout)) {
1781 run_command "git checkout $checkout" or
1782 die "failed to checkout $checkout";
1785 if ($test_type eq "bisect") {
1788 } elsif ($test_type eq "config_bisect") {
1791 } elsif ($test_type eq "patchcheck") {
1796 if ($build_type ne "nobuild") {
1797 build $build_type or next;
1800 if ($test_type ne "build") {
1807 monitor or $failed = 1;;
1809 if (!$failed && $test_type ne "boot" && defined($run_test)) {
1810 do_run_test or $failed = 1;
1819 if ($opt{"POWEROFF_ON_SUCCESS"}) {
1821 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
1825 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";