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";
64 my $poweroff_on_error;
66 my $powercycle_after_reboot;
67 my $poweroff_after_halt;
82 my $in_patchcheck = 0;
91 my $bisect_sleep_time;
104 my ($lvalue, $rvalue) = @_;
106 if (defined($opt{$lvalue})) {
107 die "Error: Option $lvalue defined more than once!\n";
109 if ($rvalue =~ /^\s*$/) {
110 delete $opt{$lvalue};
112 $opt{$lvalue} = $rvalue;
119 open(IN, $config) || die "can't read file $config";
122 $name =~ s,.*/(.*),$1,;
127 my $num_tests_set = 0;
133 # ignore blank lines and comments
134 next if (/^\s*$/ || /\s*\#/);
136 if (/^\s*TEST_START(.*)/) {
140 if ($num_tests_set) {
141 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
144 my $old_test_num = $test_num;
145 my $old_repeat = $repeat;
147 $test_num += $repeat;
151 if ($rest =~ /\s+SKIP(.*)/) {
158 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
161 $repeat_tests{"$test_num"} = $repeat;
164 if ($rest =~ /\s+SKIP(.*)/) {
169 if ($rest !~ /^\s*$/) {
170 die "$name: $.: Gargbage found after TEST_START\n$_";
174 $test_num = $old_test_num;
175 $repeat = $old_repeat;
178 } elsif (/^\s*DEFAULTS(.*)$/) {
183 if ($rest =~ /\s+SKIP(.*)/) {
190 if ($rest !~ /^\s*$/) {
191 die "$name: $.: Gargbage found after DEFAULTS\n$_";
194 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
202 ($lvalue eq "NUM_TESTS" ||
203 $lvalue eq "LOG_FILE" ||
204 $lvalue eq "CLEAR_LOG")) {
205 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
208 if ($lvalue eq "NUM_TESTS") {
210 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
213 die "$name: $.: NUM_TESTS must be set in default section\n";
218 if ($default || $lvalue =~ /\[\d+\]$/) {
219 set_value($lvalue, $rvalue);
221 my $val = "$lvalue\[$test_num\]";
222 set_value($val, $rvalue);
225 $repeats{$val} = $repeat;
229 die "$name: $.: Garbage found in config\n$_";
236 $test_num += $repeat - 1;
237 $opt{"NUM_TESTS"} = $test_num;
242 foreach my $default (keys %default) {
243 if (!defined($opt{$default})) {
244 $opt{$default} = $default{$default};
250 if (defined($opt{"LOG_FILE"})) {
251 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
258 if (defined($opt{"LOG_FILE"})) {
273 # try to reboot normally
274 if (run_command $reboot) {
275 if (defined($powercycle_after_reboot)) {
276 sleep $powercycle_after_reboot;
277 run_command "$power_cycle";
280 # nope? power cycle it.
281 run_command "$power_cycle";
288 return $test_type eq "build" ||
289 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
290 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
294 doprint "CRITICAL FAILURE... ", @_, "\n";
298 if ($reboot_on_error && !do_not_reboot) {
300 doprint "REBOOTING\n";
303 } elsif ($poweroff_on_error && defined($power_off)) {
304 doprint "POWERING OFF\n";
316 my $pid = open($fp, "$console|") or
317 dodie "Can't open console $console";
319 $flags = fcntl($fp, F_GETFL, 0) or
320 dodie "Can't get flags for the socket: $!";
321 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
322 dodie "Can't set flags for the socket: $!";
330 doprint "kill child process $pid\n";
338 if ($monitor_cnt++) {
341 $monitor_fp = \*MONFD;
342 $monitor_pid = open_console $monitor_fp;
346 open(MONFD, "Stop perl from warning about single use of MONFD");
350 if (--$monitor_cnt) {
353 close_console($monitor_fp, $monitor_pid);
356 sub wait_for_monitor {
360 doprint "** Wait for monitor to settle down **\n";
362 # read the monitor and wait for the system to calm down
364 $line = wait_for_input($monitor_fp, $time);
365 print "$line" if (defined($line));
366 } while (defined($line));
367 print "** Monitor flushed **\n";
372 if ($die_on_failure) {
380 # no need to reboot for just building.
381 if (!do_not_reboot) {
382 doprint "REBOOTING\n";
385 wait_for_monitor $sleep_time;
389 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
390 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
391 doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n";
392 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
393 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
395 return 1 if (!defined($store_failures));
398 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
399 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
401 my $dir = "$machine-$test_type-$build_type-fail-$date";
402 my $faildir = "$store_failures/$dir";
406 die "can't create $faildir";
408 if (-f "$output_config") {
409 cp "$output_config", "$faildir/config" or
410 die "failed to copy .config";
413 cp $buildlog, "$faildir/buildlog" or
414 die "failed to move $buildlog";
417 cp $dmesg, "$faildir/dmesg" or
418 die "failed to move $dmesg";
421 doprint "*** Saved info to $faildir ***\n";
432 $command =~ s/\$SSH_USER/$ssh_user/g;
433 $command =~ s/\$MACHINE/$machine/g;
435 doprint("$command ... ");
437 $pid = open(CMD, "$command 2>&1 |") or
438 (fail "unable to exec $command" and return 0);
440 if (defined($opt{"LOG_FILE"})) {
441 open(LOG, ">>$opt{LOG_FILE}") or
442 dodie "failed to write to log";
446 if (defined($redirect)) {
447 open (RD, ">$redirect") or
448 dodie "failed to write to redirect $redirect";
453 print LOG if ($dolog);
461 close(LOG) if ($dolog);
462 close(RD) if ($dord);
475 my $cp_exec = $ssh_exec;
477 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
478 return run_command "$cp_exec";
482 my ($src, $dst) = @_;
483 my $cp_scp = $scp_to_target;
485 $cp_scp =~ s/\$SRC_FILE/$src/g;
486 $cp_scp =~ s/\$DST_FILE/$dst/g;
488 return run_command "$cp_scp";
493 if ($reboot_type ne "grub") {
496 return if (defined($grub_number));
498 doprint "Find grub menu ... ";
501 my $ssh_grub = $ssh_exec;
502 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
504 open(IN, "$ssh_grub |")
505 or die "unable to get menu.lst";
508 if (/^\s*title\s+$grub_menu\s*$/) {
511 } elsif (/^\s*title\s/) {
517 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
518 if ($grub_number < 0);
519 doprint "$grub_number\n";
524 my ($fp, $time) = @_;
530 if (!defined($time)) {
535 vec($rin, fileno($fp), 1) = 1;
536 $ready = select($rin, undef, undef, $time);
540 # try to read one char at a time
541 while (sysread $fp, $ch, 1) {
543 last if ($ch eq "\n");
546 if (!length($line)) {
554 if ($reboot_type eq "grub") {
555 run_command "$ssh_exec '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
559 run_command "$reboot_script";
565 doprint "git rev-list --max-count=1 $commit ... ";
566 my $sha1 = `git rev-list --max-count=1 $commit`;
573 dodie "Failed to get git $commit";
586 my $skip_call_trace = 0;
594 open(DMESG, "> $dmesg") or
595 die "unable to write to $dmesg";
602 $line = wait_for_input($monitor_fp, $booted_timeout);
604 $line = wait_for_input($monitor_fp);
607 last if (!defined($line));
612 # we are not guaranteed to get a full line
615 if ($full_line =~ /$success_line/) {
619 if ($full_line =~ /\[ backtrace testing \]/) {
620 $skip_call_trace = 1;
623 if ($full_line =~ /call trace:/i) {
624 $bug = 1 if (!$skip_call_trace);
627 if ($full_line =~ /\[ end of backtrace testing \]/) {
628 $skip_call_trace = 0;
631 if ($full_line =~ /Kernel panic -/) {
643 return 0 if ($in_bisect);
644 fail "failed - got a bug report" and return 0;
648 return 0 if ($in_bisect);
649 fail "failed - never got a boot prompt." and return 0;
657 run_scp "$outputdir/$build_target", "$target_image" or
658 dodie "failed to copy image";
660 my $install_mods = 0;
662 # should we process modules?
664 open(IN, "$output_config") or dodie("Can't read config file");
666 if (/CONFIG_MODULES(=y)?/) {
667 $install_mods = 1 if (defined($1));
673 if (!$install_mods) {
674 doprint "No modules needed\n";
678 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
679 dodie "Failed to install modules";
681 my $modlib = "/lib/modules/$version";
682 my $modtar = "ktest-mods.tar.bz2";
684 run_ssh "rm -rf $modlib" or
685 dodie "failed to remove old mods: $modlib";
687 # would be nice if scp -r did not follow symbolic links
688 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
689 dodie "making tarball";
691 run_scp "$tmpdir/$modtar", "/tmp" or
692 dodie "failed to copy modules";
694 unlink "$tmpdir/$modtar";
696 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
697 dodie "failed to tar modules";
699 run_ssh "rm -f /tmp/$modtar";
701 return if (!defined($post_install));
703 my $cp_post_install = $post_install;
704 $cp_post_install = s/\$KERNEL_VERSION/$version/g;
705 run_command "$cp_post_install" or
706 dodie "Failed to run post install";
712 my @files = `git show $patch | diffstat -l`;
714 open(IN, "git show $patch |") or
715 dodie "failed to show $patch";
717 if (m,^--- a/(.*),) {
719 $files[$#files] = $1;
724 open(IN, $buildlog) or dodie "Can't open $buildlog";
726 if (/^\s*(.*?):.*(warning|error)/) {
728 foreach my $file (@files) {
729 my $fullpath = "$builddir/$file";
730 if ($file eq $err || $fullpath eq $err) {
731 fail "$file built with warnings" and return 0;
747 if ($type =~ /^useconfig:(.*)/) {
748 run_command "cp $1 $output_config" or
749 dodie "could not copy $1 to .config";
754 # old config can ask questions
755 if ($type eq "oldconfig") {
756 $type = "oldnoconfig";
758 # allow for empty configs
759 run_command "touch $output_config";
761 run_command "mv $output_config $outputdir/config_temp" or
762 dodie "moving .config";
764 if (!$noclean && !run_command "$make mrproper") {
765 dodie "make mrproper";
768 run_command "mv $outputdir/config_temp $output_config" or
769 dodie "moving config_temp";
771 } elsif (!$noclean) {
772 unlink "$output_config";
773 run_command "$make mrproper" or
774 dodie "make mrproper";
777 # add something to distinguish this build
778 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
779 print OUT "$localversion\n";
782 if (defined($minconfig)) {
783 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
786 run_command "$defconfig $make $type" or
787 dodie "failed make config";
789 $redirect = "$buildlog";
790 if (!run_command "$make $build_options") {
792 # bisect may need this to pass
793 return 0 if ($in_bisect);
794 fail "failed build" and return 0;
802 if (!run_ssh "halt" or defined($power_off)) {
803 if (defined($poweroff_after_halt)) {
804 sleep $poweroff_after_halt;
805 run_command "$power_off";
809 run_command "$power_off";
818 doprint "\n\n*******************************************\n";
819 doprint "*******************************************\n";
820 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
821 doprint "*******************************************\n";
822 doprint "*******************************************\n";
824 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
825 doprint "Reboot and wait $sleep_time seconds\n";
828 wait_for_monitor $sleep_time;
834 # get the release name
835 doprint "$make kernelrelease ... ";
836 $version = `$make kernelrelease | tail -1`;
838 doprint "$version\n";
844 # child should have no power
845 $reboot_on_error = 0;
846 $poweroff_on_error = 0;
849 run_command $run_test or $failed = 1;
868 doprint "run test $run_test\n";
872 $SIG{CHLD} = qw(child_finished);
876 child_run_test if (!$child_pid);
881 $line = wait_for_input($monitor_fp, 1);
882 if (defined($line)) {
884 # we are not guaranteed to get a full line
887 if ($full_line =~ /call trace:/i) {
891 if ($full_line =~ /Kernel panic -/) {
899 } while (!$child_done && !$bug);
902 doprint "Detected kernel crash!\n";
903 # kill the child with extreme prejudice
907 waitpid $child_pid, 0;
910 if ($bug || $child_exit) {
911 return 0 if $in_bisect;
912 fail "test failed" and return 0;
920 doprint "$command ... ";
922 my $output = `$command 2>&1`;
929 dodie "Failed to git bisect";
933 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
935 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
937 doprint "Found bad commit... $1\n";
940 # we already logged it, just print it now.
947 # returns 1 on success, 0 on failure
948 sub run_bisect_test {
949 my ($type, $buildtype) = @_;
958 build $buildtype or $failed = 1;
960 if ($type ne "build") {
961 dodie "Failed on build" if $failed;
969 monitor or $failed = 1;
971 if ($type ne "boot") {
972 dodie "Failed on boot" if $failed;
974 do_run_test or $failed = 1;
982 # reboot the box to a good kernel
983 if ($type ne "build") {
984 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
987 wait_for_monitor $bisect_sleep_time;
1000 my $buildtype = "oldconfig";
1002 # We should have a minconfig to use?
1003 if (defined($minconfig)) {
1004 $buildtype = "useconfig:$minconfig";
1007 my $ret = run_bisect_test $type, $buildtype;
1010 # Are we looking for where it worked, not failed?
1011 if ($reverse_bisect) {
1027 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1028 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1029 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1031 my $good = $opt{"BISECT_GOOD[$i]"};
1032 my $bad = $opt{"BISECT_BAD[$i]"};
1033 my $type = $opt{"BISECT_TYPE[$i]"};
1034 my $start = $opt{"BISECT_START[$i]"};
1035 my $replay = $opt{"BISECT_REPLAY[$i]"};
1037 # convert to true sha1's
1038 $good = get_sha1($good);
1039 $bad = get_sha1($bad);
1041 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1042 $opt{"BISECT_REVERSE[$i]"} == 1) {
1043 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1044 $reverse_bisect = 1;
1046 $reverse_bisect = 0;
1049 # Can't have a test without having a test to run
1050 if ($type eq "test" && !defined($run_test)) {
1054 my $check = $opt{"BISECT_CHECK[$i]"};
1055 if (defined($check) && $check ne "0") {
1058 my $head = get_sha1("HEAD");
1060 if ($check ne "good") {
1061 doprint "TESTING BISECT BAD [$bad]\n";
1062 run_command "git checkout $bad" or
1063 die "Failed to checkout $bad";
1065 $result = run_bisect $type;
1067 if ($result ne "bad") {
1068 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1072 if ($check ne "bad") {
1073 doprint "TESTING BISECT GOOD [$good]\n";
1074 run_command "git checkout $good" or
1075 die "Failed to checkout $good";
1077 $result = run_bisect $type;
1079 if ($result ne "good") {
1080 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1084 # checkout where we started
1085 run_command "git checkout $head" or
1086 die "Failed to checkout $head";
1089 run_command "git bisect start" or
1090 dodie "could not start bisect";
1092 run_command "git bisect good $good" or
1093 dodie "could not set bisect good to $good";
1095 run_git_bisect "git bisect bad $bad" or
1096 dodie "could not set bisect bad to $bad";
1098 if (defined($replay)) {
1099 run_command "git bisect replay $replay" or
1100 dodie "failed to run replay";
1103 if (defined($start)) {
1104 run_command "git checkout $start" or
1105 dodie "failed to checkout $start";
1110 $result = run_bisect $type;
1111 $test = run_git_bisect "git bisect $result";
1114 run_command "git bisect log" or
1115 dodie "could not capture git bisect log";
1117 run_command "git bisect reset" or
1118 dodie "could not reset git bisect";
1120 doprint "Bad commit was [$bisect_bad]\n";
1133 sub process_config_ignore {
1137 or dodie "Failed to read $config";
1140 if (/^(.*?(CONFIG\S*)(=.*| is not set))/) {
1141 $config_ignore{$2} = $1;
1148 sub read_current_config {
1149 my ($config_ref) = @_;
1151 %{$config_ref} = ();
1152 undef %{$config_ref};
1154 my @key = keys %{$config_ref};
1156 print "did not delete!\n";
1159 open (IN, "$output_config");
1162 if (/^(CONFIG\S+)=(.*)/) {
1163 ${$config_ref}{$1} = $2;
1169 sub get_dependencies {
1172 my $arr = $dependency{$config};
1173 if (!defined($arr)) {
1179 foreach my $dep (@{$arr}) {
1180 print "ADD DEP $dep\n";
1181 @deps = (@deps, get_dependencies $dep);
1190 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1192 foreach my $config (@configs) {
1193 print OUT "$config_set{$config}\n";
1194 my @deps = get_dependencies $config;
1195 foreach my $dep (@deps) {
1196 print OUT "$config_set{$dep}\n";
1200 foreach my $config (keys %config_ignore) {
1201 print OUT "$config_ignore{$config}\n";
1206 run_command "$make oldnoconfig" or
1207 dodie "failed make config oldconfig";
1211 sub compare_configs {
1214 foreach my $item (keys %a) {
1215 if (!defined($b{$item})) {
1216 print "diff $item\n";
1224 print "diff2 $keys[0]\n";
1226 return -1 if ($#keys >= 0);
1231 sub run_config_bisect_test {
1234 return run_bisect_test $type, "oldconfig";
1237 sub process_passed {
1240 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1241 # Passed! All these configs are part of a good compile.
1242 # Add them to the min options.
1243 foreach my $config (keys %configs) {
1244 if (defined($config_list{$config})) {
1245 doprint " removing $config\n";
1246 $config_ignore{$config} = $config_list{$config};
1247 delete $config_list{$config};
1252 sub process_failed {
1255 doprint "\n\n***************************************\n";
1256 doprint "Found bad config: $config\n";
1257 doprint "***************************************\n\n";
1260 sub run_config_bisect {
1262 my @start_list = keys %config_list;
1264 if ($#start_list < 0) {
1265 doprint "No more configs to test!!!\n";
1269 doprint "***** RUN TEST ***\n";
1270 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1274 my $count = $#start_list + 1;
1275 doprint " $count configs to test\n";
1277 my $half = int($#start_list / 2);
1280 my @tophalf = @start_list[0 .. $half];
1282 create_config @tophalf;
1283 read_current_config \%current_config;
1285 $count = $#tophalf + 1;
1286 doprint "Testing $count configs\n";
1288 # make sure we test something
1289 foreach my $config (@tophalf) {
1290 if (defined($current_config{$config})) {
1296 # try the other half
1297 doprint "Top half produced no set configs, trying bottom half\n";
1298 @tophalf = @start_list[$half .. $#start_list];
1299 create_config @tophalf;
1300 read_current_config \%current_config;
1301 foreach my $config (@tophalf) {
1302 if (defined($current_config{$config})) {
1308 doprint "Failed: Can't make new config with current configs\n";
1309 foreach my $config (@start_list) {
1310 doprint " CONFIG: $config\n";
1314 $count = $#tophalf + 1;
1315 doprint "Testing $count configs\n";
1318 $ret = run_config_bisect_test $type;
1321 process_passed %current_config;
1325 doprint "This config had a failure.\n";
1326 doprint "Removing these configs that were not set in this config:\n";
1328 # A config exists in this group that was bad.
1329 foreach my $config (keys %config_list) {
1330 if (!defined($current_config{$config})) {
1331 doprint " removing $config\n";
1332 delete $config_list{$config};
1336 @start_list = @tophalf;
1338 if ($#start_list == 0) {
1339 process_failed $start_list[0];
1343 # remove half the configs we are looking at and see if
1345 $half = int($#start_list / 2);
1346 } while ($half > 0);
1348 # we found a single config, try it again
1349 my @tophalf = @start_list[0 .. 0];
1351 $ret = run_config_bisect_test $type;
1353 process_passed %current_config;
1357 process_failed $start_list[0];
1364 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1366 my $tmpconfig = "$tmpdir/use_config";
1368 # Make the file with the bad config and the min config
1369 if (defined($minconfig)) {
1370 # read the min config for things to ignore
1371 run_command "cp $minconfig $tmpconfig" or
1372 dodie "failed to copy $minconfig to $tmpconfig";
1378 if (defined($addconfig)) {
1379 run_command "cat $addconfig >> $tmpconfig" or
1380 dodie "failed to append $addconfig";
1384 if (-f $tmpconfig) {
1385 $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
1386 process_config_ignore $tmpconfig;
1389 # now process the start config
1390 run_command "cp $start_config $output_config" or
1391 dodie "failed to copy $start_config to $output_config";
1393 # read directly what we want to check
1395 open (IN, $output_config)
1396 or dodie "faied to open $output_config";
1399 if (/^((CONFIG\S*)=.*)/) {
1400 $config_check{$2} = $1;
1405 # Now run oldconfig with the minconfig (and addconfigs)
1406 run_command "$defconfig $make oldnoconfig" or
1407 dodie "failed make config oldconfig";
1409 # check to see what we lost (or gained)
1410 open (IN, $output_config)
1411 or dodie "Failed to read $start_config";
1413 my %removed_configs;
1417 if (/^((CONFIG\S*)=.*)/) {
1418 # save off all options
1419 $config_set{$2} = $1;
1420 if (defined($config_check{$2})) {
1421 if (defined($config_ignore{$2})) {
1422 $removed_configs{$2} = $1;
1424 $config_list{$2} = $1;
1426 } elsif (!defined($config_ignore{$2})) {
1427 $added_configs{$2} = $1;
1428 $config_list{$2} = $1;
1434 my @confs = keys %removed_configs;
1436 doprint "Configs overridden by default configs and removed from check:\n";
1437 foreach my $config (@confs) {
1438 doprint " $config\n";
1441 @confs = keys %added_configs;
1443 doprint "Configs appearing in make oldconfig and added:\n";
1444 foreach my $config (@confs) {
1445 doprint " $config\n";
1452 # Sometimes kconfig does weird things. We must make sure
1453 # that the config we autocreate has everything we need
1454 # to test, otherwise we may miss testing configs, or
1455 # may not be able to create a new config.
1456 # Here we create a config with everything set.
1457 create_config (keys %config_list);
1458 read_current_config \%config_test;
1459 foreach my $config (keys %config_list) {
1460 if (!defined($config_test{$config})) {
1463 doprint "Configs not produced by kconfig (will not be checked):\n";
1465 doprint " $config\n";
1466 delete $config_list{$config};
1471 $ret = run_config_bisect;
1474 return $ret if ($ret < 0);
1482 die "PATCHCHECK_START[$i] not defined\n"
1483 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1484 die "PATCHCHECK_TYPE[$i] not defined\n"
1485 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1487 my $start = $opt{"PATCHCHECK_START[$i]"};
1490 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1491 $end = $opt{"PATCHCHECK_END[$i]"};
1494 # Get the true sha1's since we can use things like HEAD~3
1495 $start = get_sha1($start);
1496 $end = get_sha1($end);
1498 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1500 # Can't have a test without having a test to run
1501 if ($type eq "test" && !defined($run_test)) {
1505 open (IN, "git log --pretty=oneline $end|") or
1506 dodie "could not get git list";
1512 $list[$#list+1] = $_;
1513 last if (/^$start/);
1517 if ($list[$#list] !~ /^$start/) {
1518 fail "SHA1 $start not found";
1521 # go backwards in the list
1522 @list = reverse @list;
1524 my $save_clean = $noclean;
1527 foreach my $item (@list) {
1529 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1531 doprint "\nProcessing commit $item\n\n";
1533 run_command "git checkout $sha1" or
1534 die "Failed to checkout $sha1";
1536 # only clean on the first and last patch
1537 if ($item eq $list[0] ||
1538 $item eq $list[$#list]) {
1539 $noclean = $save_clean;
1544 if (defined($minconfig)) {
1545 build "useconfig:$minconfig" or return 0;
1547 # ?? no config to use?
1548 build "oldconfig" or return 0;
1551 check_buildlog $sha1 or return 0;
1553 next if ($type eq "build");
1562 monitor or $failed = 1;
1564 if (!$failed && $type ne "boot"){
1565 do_run_test or $failed = 1;
1568 return 0 if ($failed);
1577 read_config $ARGV[0];
1580 die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
1581 die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
1582 die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
1583 die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
1584 die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
1585 die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
1586 die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
1587 die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
1588 die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
1590 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
1591 unlink $opt{"LOG_FILE"};
1594 doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
1596 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
1599 doprint "DEFAULT OPTIONS:\n";
1601 doprint "\nTEST $i OPTIONS";
1602 if (defined($repeat_tests{$i})) {
1603 $repeat = $repeat_tests{$i};
1604 doprint " ITERATE $repeat";
1609 foreach my $option (sort keys %opt) {
1611 if ($option =~ /\[(\d+)\]$/) {
1617 doprint "$option = $opt{$option}\n";
1621 sub set_test_option {
1622 my ($name, $i) = @_;
1624 my $option = "$name\[$i\]";
1626 if (defined($opt{$option})) {
1627 return $opt{$option};
1630 foreach my $test (keys %repeat_tests) {
1632 $i < $test + $repeat_tests{$test}) {
1633 $option = "$name\[$test\]";
1634 if (defined($opt{$option})) {
1635 return $opt{$option};
1640 if (defined($opt{$name})) {
1647 # First we need to do is the builds
1648 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1652 my $makecmd = set_test_option("MAKE_CMD", $i);
1654 $machine = set_test_option("MACHINE", $i);
1655 $ssh_user = set_test_option("SSH_USER", $i);
1656 $tmpdir = set_test_option("TMP_DIR", $i);
1657 $outputdir = set_test_option("OUTPUT_DIR", $i);
1658 $builddir = set_test_option("BUILD_DIR", $i);
1659 $test_type = set_test_option("TEST_TYPE", $i);
1660 $build_type = set_test_option("BUILD_TYPE", $i);
1661 $build_options = set_test_option("BUILD_OPTIONS", $i);
1662 $power_cycle = set_test_option("POWER_CYCLE", $i);
1663 $reboot = set_test_option("REBOOT", $i);
1664 $noclean = set_test_option("BUILD_NOCLEAN", $i);
1665 $minconfig = set_test_option("MIN_CONFIG", $i);
1666 $run_test = set_test_option("TEST", $i);
1667 $addconfig = set_test_option("ADD_CONFIG", $i);
1668 $reboot_type = set_test_option("REBOOT_TYPE", $i);
1669 $grub_menu = set_test_option("GRUB_MENU", $i);
1670 $post_install = set_test_option("POST_INSTALL", $i);
1671 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
1672 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
1673 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
1674 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
1675 $power_off = set_test_option("POWER_OFF", $i);
1676 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
1677 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
1678 $sleep_time = set_test_option("SLEEP_TIME", $i);
1679 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
1680 $store_failures = set_test_option("STORE_FAILURES", $i);
1681 $timeout = set_test_option("TIMEOUT", $i);
1682 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
1683 $console = set_test_option("CONSOLE", $i);
1684 $success_line = set_test_option("SUCCESS_LINE", $i);
1685 $build_target = set_test_option("BUILD_TARGET", $i);
1686 $ssh_exec = set_test_option("SSH_EXEC", $i);
1687 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
1688 $target_image = set_test_option("TARGET_IMAGE", $i);
1689 $localversion = set_test_option("LOCALVERSION", $i);
1691 chdir $builddir || die "can't change directory to $builddir";
1695 die "can't create $tmpdir";
1698 $ENV{"SSH_USER"} = $ssh_user;
1699 $ENV{"MACHINE"} = $machine;
1701 $target = "$ssh_user\@$machine";
1703 $buildlog = "$tmpdir/buildlog-$machine";
1704 $dmesg = "$tmpdir/dmesg-$machine";
1705 $make = "$makecmd O=$outputdir";
1706 $output_config = "$outputdir/.config";
1708 if ($reboot_type eq "grub") {
1709 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
1710 } elsif (!defined($reboot_script)) {
1711 dodie "REBOOT_SCRIPT not defined"
1714 my $run_type = $build_type;
1715 if ($test_type eq "patchcheck") {
1716 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
1717 } elsif ($test_type eq "bisect") {
1718 $run_type = $opt{"BISECT_TYPE[$i]"};
1719 } elsif ($test_type eq "config_bisect") {
1720 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
1723 # mistake in config file?
1724 if (!defined($run_type)) {
1725 $run_type = "ERROR";
1729 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
1734 if (!defined($minconfig)) {
1735 $minconfig = $addconfig;
1737 } elsif (defined($addconfig)) {
1738 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
1739 dodie "Failed to create temp config";
1740 $minconfig = "$tmpdir/add_config";
1743 my $checkout = $opt{"CHECKOUT[$i]"};
1744 if (defined($checkout)) {
1745 run_command "git checkout $checkout" or
1746 die "failed to checkout $checkout";
1749 if ($test_type eq "bisect") {
1752 } elsif ($test_type eq "config_bisect") {
1755 } elsif ($test_type eq "patchcheck") {
1760 if ($build_type ne "nobuild") {
1761 build $build_type or next;
1764 if ($test_type ne "build") {
1771 monitor or $failed = 1;;
1773 if (!$failed && $test_type ne "boot" && defined($run_test)) {
1774 do_run_test or $failed = 1;
1783 if ($opt{"POWEROFF_ON_SUCCESS"}) {
1785 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
1789 doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";