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};
1284 doprint
"config copied to $outputdir/config_good\n";
1285 run_command
"cp -f $output_config $outputdir/config_good";
1288 sub process_failed
{
1291 doprint
"\n\n***************************************\n";
1292 doprint
"Found bad config: $config\n";
1293 doprint
"***************************************\n\n";
1296 sub run_config_bisect
{
1298 my @start_list = keys %config_list;
1300 if ($#start_list < 0) {
1301 doprint
"No more configs to test!!!\n";
1305 doprint
"***** RUN TEST ***\n";
1306 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1310 my $count = $#start_list + 1;
1311 doprint
" $count configs to test\n";
1313 my $half = int($#start_list / 2);
1316 my @tophalf = @start_list[0 .. $half];
1318 create_config
@tophalf;
1319 read_current_config \
%current_config;
1321 $count = $#tophalf + 1;
1322 doprint
"Testing $count configs\n";
1324 # make sure we test something
1325 foreach my $config (@tophalf) {
1326 if (defined($current_config{$config})) {
1332 # try the other half
1333 doprint
"Top half produced no set configs, trying bottom half\n";
1334 @tophalf = @start_list[$half .. $#start_list];
1335 create_config
@tophalf;
1336 read_current_config \
%current_config;
1337 foreach my $config (@tophalf) {
1338 if (defined($current_config{$config})) {
1344 doprint
"Failed: Can't make new config with current configs\n";
1345 foreach my $config (@start_list) {
1346 doprint
" CONFIG: $config\n";
1350 $count = $#tophalf + 1;
1351 doprint
"Testing $count configs\n";
1354 $ret = run_config_bisect_test
$type;
1357 process_passed
%current_config;
1361 doprint
"This config had a failure.\n";
1362 doprint
"Removing these configs that were not set in this config:\n";
1363 doprint
"config copied to $outputdir/config_bad\n";
1364 run_command
"cp -f $output_config $outputdir/config_bad";
1366 # A config exists in this group that was bad.
1367 foreach my $config (keys %config_list) {
1368 if (!defined($current_config{$config})) {
1369 doprint
" removing $config\n";
1370 delete $config_list{$config};
1374 @start_list = @tophalf;
1376 if ($#start_list == 0) {
1377 process_failed
$start_list[0];
1381 # remove half the configs we are looking at and see if
1383 $half = int($#start_list / 2);
1384 } while ($half > 0);
1386 # we found a single config, try it again
1387 my @tophalf = @start_list[0 .. 0];
1389 $ret = run_config_bisect_test
$type;
1391 process_passed
%current_config;
1395 process_failed
$start_list[0];
1402 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1404 my $tmpconfig = "$tmpdir/use_config";
1406 # Make the file with the bad config and the min config
1407 if (defined($minconfig)) {
1408 # read the min config for things to ignore
1409 run_command
"cp $minconfig $tmpconfig" or
1410 dodie
"failed to copy $minconfig to $tmpconfig";
1416 if (defined($addconfig)) {
1417 run_command
"cat $addconfig >> $tmpconfig" or
1418 dodie
"failed to append $addconfig";
1422 if (-f
$tmpconfig) {
1423 $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
1424 process_config_ignore
$tmpconfig;
1427 # now process the start config
1428 run_command
"cp $start_config $output_config" or
1429 dodie
"failed to copy $start_config to $output_config";
1431 # read directly what we want to check
1433 open (IN
, $output_config)
1434 or dodie
"faied to open $output_config";
1437 if (/^((CONFIG\S*)=.*)/) {
1438 $config_check{$2} = $1;
1443 # Now run oldconfig with the minconfig (and addconfigs)
1444 run_command
"$defconfig $make oldnoconfig" or
1445 dodie
"failed make config oldconfig";
1447 # check to see what we lost (or gained)
1448 open (IN
, $output_config)
1449 or dodie
"Failed to read $start_config";
1451 my %removed_configs;
1455 if (/^((CONFIG\S*)=.*)/) {
1456 # save off all options
1457 $config_set{$2} = $1;
1458 if (defined($config_check{$2})) {
1459 if (defined($config_ignore{$2})) {
1460 $removed_configs{$2} = $1;
1462 $config_list{$2} = $1;
1464 } elsif (!defined($config_ignore{$2})) {
1465 $added_configs{$2} = $1;
1466 $config_list{$2} = $1;
1472 my @confs = keys %removed_configs;
1474 doprint
"Configs overridden by default configs and removed from check:\n";
1475 foreach my $config (@confs) {
1476 doprint
" $config\n";
1479 @confs = keys %added_configs;
1481 doprint
"Configs appearing in make oldconfig and added:\n";
1482 foreach my $config (@confs) {
1483 doprint
" $config\n";
1490 # Sometimes kconfig does weird things. We must make sure
1491 # that the config we autocreate has everything we need
1492 # to test, otherwise we may miss testing configs, or
1493 # may not be able to create a new config.
1494 # Here we create a config with everything set.
1495 create_config
(keys %config_list);
1496 read_current_config \
%config_test;
1497 foreach my $config (keys %config_list) {
1498 if (!defined($config_test{$config})) {
1501 doprint
"Configs not produced by kconfig (will not be checked):\n";
1503 doprint
" $config\n";
1504 delete $config_list{$config};
1509 $ret = run_config_bisect
;
1512 return $ret if ($ret < 0);
1520 die "PATCHCHECK_START[$i] not defined\n"
1521 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1522 die "PATCHCHECK_TYPE[$i] not defined\n"
1523 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1525 my $start = $opt{"PATCHCHECK_START[$i]"};
1528 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1529 $end = $opt{"PATCHCHECK_END[$i]"};
1532 # Get the true sha1's since we can use things like HEAD~3
1533 $start = get_sha1
($start);
1534 $end = get_sha1
($end);
1536 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1538 # Can't have a test without having a test to run
1539 if ($type eq "test" && !defined($run_test)) {
1543 open (IN
, "git log --pretty=oneline $end|") or
1544 dodie
"could not get git list";
1550 $list[$#list+1] = $_;
1551 last if (/^$start/);
1555 if ($list[$#list] !~ /^$start/) {
1556 fail
"SHA1 $start not found";
1559 # go backwards in the list
1560 @list = reverse @list;
1562 my $save_clean = $noclean;
1565 foreach my $item (@list) {
1567 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1569 doprint
"\nProcessing commit $item\n\n";
1571 run_command
"git checkout $sha1" or
1572 die "Failed to checkout $sha1";
1574 # only clean on the first and last patch
1575 if ($item eq $list[0] ||
1576 $item eq $list[$#list]) {
1577 $noclean = $save_clean;
1582 if (defined($minconfig)) {
1583 build
"useconfig:$minconfig" or return 0;
1585 # ?? no config to use?
1586 build
"oldconfig" or return 0;
1589 check_buildlog
$sha1 or return 0;
1591 next if ($type eq "build");
1600 monitor
or $failed = 1;
1602 if (!$failed && $type ne "boot"){
1603 do_run_test
or $failed = 1;
1606 return 0 if ($failed);
1615 read_config
$ARGV[0];
1618 die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
1619 die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
1620 die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
1621 die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
1622 die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
1623 die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
1624 die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
1625 die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
1626 die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
1628 if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
1629 unlink $opt{"LOG_FILE"};
1632 doprint
"\n\nSTARTING AUTOMATED TESTS\n\n";
1634 for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
1637 doprint
"DEFAULT OPTIONS:\n";
1639 doprint
"\nTEST $i OPTIONS";
1640 if (defined($repeat_tests{$i})) {
1641 $repeat = $repeat_tests{$i};
1642 doprint
" ITERATE $repeat";
1647 foreach my $option (sort keys %opt) {
1649 if ($option =~ /\[(\d+)\]$/) {
1655 doprint
"$option = $opt{$option}\n";
1659 sub set_test_option
{
1660 my ($name, $i) = @_;
1662 my $option = "$name\[$i\]";
1664 if (defined($opt{$option})) {
1665 return $opt{$option};
1668 foreach my $test (keys %repeat_tests) {
1670 $i < $test + $repeat_tests{$test}) {
1671 $option = "$name\[$test\]";
1672 if (defined($opt{$option})) {
1673 return $opt{$option};
1678 if (defined($opt{$name})) {
1685 # First we need to do is the builds
1686 for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1690 my $makecmd = set_test_option
("MAKE_CMD", $i);
1692 $machine = set_test_option
("MACHINE", $i);
1693 $ssh_user = set_test_option
("SSH_USER", $i);
1694 $tmpdir = set_test_option
("TMP_DIR", $i);
1695 $outputdir = set_test_option
("OUTPUT_DIR", $i);
1696 $builddir = set_test_option
("BUILD_DIR", $i);
1697 $test_type = set_test_option
("TEST_TYPE", $i);
1698 $build_type = set_test_option
("BUILD_TYPE", $i);
1699 $build_options = set_test_option
("BUILD_OPTIONS", $i);
1700 $power_cycle = set_test_option
("POWER_CYCLE", $i);
1701 $reboot = set_test_option
("REBOOT", $i);
1702 $noclean = set_test_option
("BUILD_NOCLEAN", $i);
1703 $minconfig = set_test_option
("MIN_CONFIG", $i);
1704 $run_test = set_test_option
("TEST", $i);
1705 $addconfig = set_test_option
("ADD_CONFIG", $i);
1706 $reboot_type = set_test_option
("REBOOT_TYPE", $i);
1707 $grub_menu = set_test_option
("GRUB_MENU", $i);
1708 $post_install = set_test_option
("POST_INSTALL", $i);
1709 $reboot_script = set_test_option
("REBOOT_SCRIPT", $i);
1710 $reboot_on_error = set_test_option
("REBOOT_ON_ERROR", $i);
1711 $poweroff_on_error = set_test_option
("POWEROFF_ON_ERROR", $i);
1712 $die_on_failure = set_test_option
("DIE_ON_FAILURE", $i);
1713 $power_off = set_test_option
("POWER_OFF", $i);
1714 $powercycle_after_reboot = set_test_option
("POWERCYCLE_AFTER_REBOOT", $i);
1715 $poweroff_after_halt = set_test_option
("POWEROFF_AFTER_HALT", $i);
1716 $sleep_time = set_test_option
("SLEEP_TIME", $i);
1717 $bisect_sleep_time = set_test_option
("BISECT_SLEEP_TIME", $i);
1718 $store_failures = set_test_option
("STORE_FAILURES", $i);
1719 $timeout = set_test_option
("TIMEOUT", $i);
1720 $booted_timeout = set_test_option
("BOOTED_TIMEOUT", $i);
1721 $console = set_test_option
("CONSOLE", $i);
1722 $success_line = set_test_option
("SUCCESS_LINE", $i);
1723 $stop_after_success = set_test_option
("STOP_AFTER_SUCCESS", $i);
1724 $stop_after_failure = set_test_option
("STOP_AFTER_FAILURE", $i);
1725 $build_target = set_test_option
("BUILD_TARGET", $i);
1726 $ssh_exec = set_test_option
("SSH_EXEC", $i);
1727 $scp_to_target = set_test_option
("SCP_TO_TARGET", $i);
1728 $target_image = set_test_option
("TARGET_IMAGE", $i);
1729 $localversion = set_test_option
("LOCALVERSION", $i);
1731 chdir $builddir || die "can't change directory to $builddir";
1735 die "can't create $tmpdir";
1738 $ENV{"SSH_USER"} = $ssh_user;
1739 $ENV{"MACHINE"} = $machine;
1741 $target = "$ssh_user\@$machine";
1743 $buildlog = "$tmpdir/buildlog-$machine";
1744 $dmesg = "$tmpdir/dmesg-$machine";
1745 $make = "$makecmd O=$outputdir";
1746 $output_config = "$outputdir/.config";
1748 if ($reboot_type eq "grub") {
1749 dodie
"GRUB_MENU not defined" if (!defined($grub_menu));
1750 } elsif (!defined($reboot_script)) {
1751 dodie
"REBOOT_SCRIPT not defined"
1754 my $run_type = $build_type;
1755 if ($test_type eq "patchcheck") {
1756 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
1757 } elsif ($test_type eq "bisect") {
1758 $run_type = $opt{"BISECT_TYPE[$i]"};
1759 } elsif ($test_type eq "config_bisect") {
1760 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
1763 # mistake in config file?
1764 if (!defined($run_type)) {
1765 $run_type = "ERROR";
1769 doprint
"RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
1774 if (!defined($minconfig)) {
1775 $minconfig = $addconfig;
1777 } elsif (defined($addconfig)) {
1778 run_command
"cat $addconfig $minconfig > $tmpdir/add_config" or
1779 dodie
"Failed to create temp config";
1780 $minconfig = "$tmpdir/add_config";
1783 my $checkout = $opt{"CHECKOUT[$i]"};
1784 if (defined($checkout)) {
1785 run_command
"git checkout $checkout" or
1786 die "failed to checkout $checkout";
1789 if ($test_type eq "bisect") {
1792 } elsif ($test_type eq "config_bisect") {
1795 } elsif ($test_type eq "patchcheck") {
1800 if ($build_type ne "nobuild") {
1801 build
$build_type or next;
1804 if ($test_type ne "build") {
1811 monitor
or $failed = 1;;
1813 if (!$failed && $test_type ne "boot" && defined($run_test)) {
1814 do_run_test
or $failed = 1;
1823 if ($opt{"POWEROFF_ON_SUCCESS"}) {
1825 } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot
) {
1829 doprint
"\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
This page took 0.134218 seconds and 6 git commands to generate.