ktest: Use different temp config name for minconfig
[deliverable/linux.git] / tools / testing / ktest / ktest.pl
CommitLineData
2545eb61 1#!/usr/bin/perl -w
d6ce2a0b
SR
2#
3# Copywrite 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
4# Licensed under the terms of the GNU GPL License version 2
5#
2545eb61
SR
6
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
7faafbd6
SR
10use File::Path qw(mkpath);
11use File::Copy qw(cp);
2545eb61
SR
12use FileHandle;
13
e48c5293
SR
14my $VERSION = "0.2";
15
16$#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
2545eb61
SR
17
18$| = 1;
19
20my %opt;
a57419b3
SR
21my %repeat_tests;
22my %repeats;
a75fecec 23my %default;
2545eb61
SR
24
25#default opts
a57419b3 26$default{"NUM_TESTS"} = 1;
a75fecec
SR
27$default{"REBOOT_TYPE"} = "grub";
28$default{"TEST_TYPE"} = "test";
29$default{"BUILD_TYPE"} = "randconfig";
30$default{"MAKE_CMD"} = "make";
31$default{"TIMEOUT"} = 120;
a57419b3 32$default{"TMP_DIR"} = "/tmp/ktest";
a75fecec
SR
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;
e48c5293
SR
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";
2545eb61
SR
48
49my $version;
a75fecec 50my $machine;
e48c5293 51my $ssh_user;
a75fecec
SR
52my $tmpdir;
53my $builddir;
54my $outputdir;
51ad1dd1 55my $output_config;
a75fecec 56my $test_type;
7faafbd6 57my $build_type;
a75fecec
SR
58my $build_options;
59my $reboot_type;
60my $reboot_script;
61my $power_cycle;
e48c5293 62my $reboot;
a75fecec
SR
63my $reboot_on_error;
64my $poweroff_on_error;
65my $die_on_failure;
576f627c
SR
66my $powercycle_after_reboot;
67my $poweroff_after_halt;
e48c5293
SR
68my $ssh_exec;
69my $scp_to_target;
a75fecec
SR
70my $power_off;
71my $grub_menu;
2545eb61
SR
72my $grub_number;
73my $target;
74my $make;
8b37ca8c 75my $post_install;
5c42fc5b 76my $noclean;
5f9b6ced 77my $minconfig;
2b7d9b21 78my $addconfig;
5f9b6ced
SR
79my $in_bisect = 0;
80my $bisect_bad = "";
d6ce2a0b 81my $reverse_bisect;
6c5ee0be 82my $in_patchcheck = 0;
5a391fbf 83my $run_test;
6c5ee0be 84my $redirect;
7faafbd6
SR
85my $buildlog;
86my $dmesg;
87my $monitor_fp;
88my $monitor_pid;
89my $monitor_cnt = 0;
a75fecec
SR
90my $sleep_time;
91my $bisect_sleep_time;
92my $store_failures;
93my $timeout;
94my $booted_timeout;
95my $console;
96my $success_line;
97my $build_target;
98my $target_image;
99my $localversion;
576f627c 100my $iteration = 0;
e48c5293 101my $successes = 0;
2545eb61 102
a57419b3
SR
103sub set_value {
104 my ($lvalue, $rvalue) = @_;
105
106 if (defined($opt{$lvalue})) {
107 die "Error: Option $lvalue defined more than once!\n";
108 }
21a9679f
SR
109 if ($rvalue =~ /^\s*$/) {
110 delete $opt{$lvalue};
111 } else {
112 $opt{$lvalue} = $rvalue;
113 }
a57419b3
SR
114}
115
2545eb61
SR
116sub read_config {
117 my ($config) = @_;
118
119 open(IN, $config) || die "can't read file $config";
120
a57419b3
SR
121 my $name = $config;
122 $name =~ s,.*/(.*),$1,;
123
124 my $test_num = 0;
125 my $default = 1;
126 my $repeat = 1;
127 my $num_tests_set = 0;
128 my $skip = 0;
129 my $rest;
130
2545eb61
SR
131 while (<IN>) {
132
133 # ignore blank lines and comments
134 next if (/^\s*$/ || /\s*\#/);
135
a57419b3
SR
136 if (/^\s*TEST_START(.*)/) {
137
138 $rest = $1;
139
140 if ($num_tests_set) {
141 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
142 }
143
144 my $old_test_num = $test_num;
e48c5293 145 my $old_repeat = $repeat;
a57419b3
SR
146
147 $test_num += $repeat;
148 $default = 0;
149 $repeat = 1;
150
151 if ($rest =~ /\s+SKIP(.*)/) {
152 $rest = $1;
153 $skip = 1;
154 } else {
155 $skip = 0;
156 }
157
158 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
159 $repeat = $1;
160 $rest = $2;
161 $repeat_tests{"$test_num"} = $repeat;
162 }
163
164 if ($rest =~ /\s+SKIP(.*)/) {
165 $rest = $1;
166 $skip = 1;
167 }
168
169 if ($rest !~ /^\s*$/) {
170 die "$name: $.: Gargbage found after TEST_START\n$_";
171 }
172
173 if ($skip) {
174 $test_num = $old_test_num;
e48c5293 175 $repeat = $old_repeat;
a57419b3
SR
176 }
177
178 } elsif (/^\s*DEFAULTS(.*)$/) {
179 $default = 1;
180
181 $rest = $1;
182
183 if ($rest =~ /\s+SKIP(.*)/) {
184 $rest = $1;
185 $skip = 1;
186 } else {
187 $skip = 0;
188 }
189
190 if ($rest !~ /^\s*$/) {
191 die "$name: $.: Gargbage found after DEFAULTS\n$_";
192 }
193
194 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
195
196 next if ($skip);
197
2545eb61
SR
198 my $lvalue = $1;
199 my $rvalue = $2;
200
a57419b3
SR
201 if (!$default &&
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";
206 }
207
208 if ($lvalue eq "NUM_TESTS") {
209 if ($test_num) {
210 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
211 }
212 if (!$default) {
213 die "$name: $.: NUM_TESTS must be set in default section\n";
214 }
215 $num_tests_set = 1;
216 }
217
218 if ($default || $lvalue =~ /\[\d+\]$/) {
219 set_value($lvalue, $rvalue);
220 } else {
221 my $val = "$lvalue\[$test_num\]";
222 set_value($val, $rvalue);
223
224 if ($repeat > 1) {
225 $repeats{$val} = $repeat;
226 }
a75fecec 227 }
a57419b3
SR
228 } else {
229 die "$name: $.: Garbage found in config\n$_";
2545eb61
SR
230 }
231 }
232
233 close(IN);
a75fecec 234
a57419b3
SR
235 if ($test_num) {
236 $test_num += $repeat - 1;
237 $opt{"NUM_TESTS"} = $test_num;
238 }
239
a75fecec
SR
240 # set any defaults
241
242 foreach my $default (keys %default) {
243 if (!defined($opt{$default})) {
244 $opt{$default} = $default{$default};
245 }
246 }
2545eb61
SR
247}
248
d1e2f22a 249sub _logit {
2545eb61
SR
250 if (defined($opt{"LOG_FILE"})) {
251 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
252 print OUT @_;
253 close(OUT);
254 }
255}
256
d1e2f22a
SR
257sub logit {
258 if (defined($opt{"LOG_FILE"})) {
259 _logit @_;
260 } else {
261 print @_;
262 }
263}
264
5f9b6ced
SR
265sub doprint {
266 print @_;
d1e2f22a 267 _logit @_;
5f9b6ced
SR
268}
269
7faafbd6
SR
270sub run_command;
271
272sub reboot {
273 # try to reboot normally
e48c5293 274 if (run_command $reboot) {
576f627c
SR
275 if (defined($powercycle_after_reboot)) {
276 sleep $powercycle_after_reboot;
277 run_command "$power_cycle";
278 }
279 } else {
7faafbd6 280 # nope? power cycle it.
a75fecec 281 run_command "$power_cycle";
7faafbd6
SR
282 }
283}
284
576f627c
SR
285sub do_not_reboot {
286 my $i = $iteration;
287
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");
291}
292
5c42fc5b 293sub dodie {
5a391fbf 294 doprint "CRITICAL FAILURE... ", @_, "\n";
5c42fc5b 295
576f627c
SR
296 my $i = $iteration;
297
298 if ($reboot_on_error && !do_not_reboot) {
299
75c3fda7 300 doprint "REBOOTING\n";
7faafbd6 301 reboot;
75c3fda7 302
a75fecec 303 } elsif ($poweroff_on_error && defined($power_off)) {
5c42fc5b 304 doprint "POWERING OFF\n";
a75fecec 305 `$power_off`;
5c42fc5b 306 }
75c3fda7 307
576f627c 308 die @_, "\n";
5c42fc5b
SR
309}
310
7faafbd6
SR
311sub open_console {
312 my ($fp) = @_;
313
314 my $flags;
315
a75fecec
SR
316 my $pid = open($fp, "$console|") or
317 dodie "Can't open console $console";
7faafbd6
SR
318
319 $flags = fcntl($fp, F_GETFL, 0) or
576f627c 320 dodie "Can't get flags for the socket: $!";
7faafbd6 321 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
576f627c 322 dodie "Can't set flags for the socket: $!";
7faafbd6
SR
323
324 return $pid;
325}
326
327sub close_console {
328 my ($fp, $pid) = @_;
329
330 doprint "kill child process $pid\n";
331 kill 2, $pid;
332
333 print "closing!\n";
334 close($fp);
335}
336
337sub start_monitor {
338 if ($monitor_cnt++) {
339 return;
340 }
341 $monitor_fp = \*MONFD;
342 $monitor_pid = open_console $monitor_fp;
a75fecec
SR
343
344 return;
345
346 open(MONFD, "Stop perl from warning about single use of MONFD");
7faafbd6
SR
347}
348
349sub end_monitor {
350 if (--$monitor_cnt) {
351 return;
352 }
353 close_console($monitor_fp, $monitor_pid);
354}
355
356sub wait_for_monitor {
357 my ($time) = @_;
358 my $line;
359
a75fecec 360 doprint "** Wait for monitor to settle down **\n";
7faafbd6
SR
361
362 # read the monitor and wait for the system to calm down
363 do {
364 $line = wait_for_input($monitor_fp, $time);
a75fecec 365 print "$line" if (defined($line));
7faafbd6 366 } while (defined($line));
a75fecec 367 print "** Monitor flushed **\n";
7faafbd6
SR
368}
369
2b7d9b21
SR
370sub fail {
371
a75fecec 372 if ($die_on_failure) {
2b7d9b21
SR
373 dodie @_;
374 }
375
a75fecec 376 doprint "FAILED\n";
7faafbd6 377
576f627c
SR
378 my $i = $iteration;
379
a75fecec 380 # no need to reboot for just building.
576f627c 381 if (!do_not_reboot) {
a75fecec
SR
382 doprint "REBOOTING\n";
383 reboot;
384 start_monitor;
385 wait_for_monitor $sleep_time;
386 end_monitor;
387 }
7faafbd6 388
576f627c
SR
389 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
390 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
7a849cd9 391 doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n";
576f627c
SR
392 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
393 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
a75fecec
SR
394
395 return 1 if (!defined($store_failures));
7faafbd6
SR
396
397 my @t = localtime;
398 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
399 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
400
a75fecec
SR
401 my $dir = "$machine-$test_type-$build_type-fail-$date";
402 my $faildir = "$store_failures/$dir";
7faafbd6
SR
403
404 if (!-d $faildir) {
405 mkpath($faildir) or
a75fecec 406 die "can't create $faildir";
7faafbd6 407 }
51ad1dd1
SR
408 if (-f "$output_config") {
409 cp "$output_config", "$faildir/config" or
7faafbd6
SR
410 die "failed to copy .config";
411 }
412 if (-f $buildlog) {
413 cp $buildlog, "$faildir/buildlog" or
414 die "failed to move $buildlog";
415 }
416 if (-f $dmesg) {
417 cp $dmesg, "$faildir/dmesg" or
418 die "failed to move $dmesg";
419 }
420
421 doprint "*** Saved info to $faildir ***\n";
422
2b7d9b21
SR
423 return 1;
424}
425
2545eb61
SR
426sub run_command {
427 my ($command) = @_;
d6ce2a0b
SR
428 my $dolog = 0;
429 my $dord = 0;
430 my $pid;
431
e48c5293
SR
432 $command =~ s/\$SSH_USER/$ssh_user/g;
433 $command =~ s/\$MACHINE/$machine/g;
434
d6ce2a0b
SR
435 doprint("$command ... ");
436
437 $pid = open(CMD, "$command 2>&1 |") or
2b7d9b21 438 (fail "unable to exec $command" and return 0);
2545eb61
SR
439
440 if (defined($opt{"LOG_FILE"})) {
d6ce2a0b
SR
441 open(LOG, ">>$opt{LOG_FILE}") or
442 dodie "failed to write to log";
443 $dolog = 1;
6c5ee0be
SR
444 }
445
446 if (defined($redirect)) {
d6ce2a0b
SR
447 open (RD, ">$redirect") or
448 dodie "failed to write to redirect $redirect";
449 $dord = 1;
2545eb61
SR
450 }
451
d6ce2a0b
SR
452 while (<CMD>) {
453 print LOG if ($dolog);
454 print RD if ($dord);
455 }
2545eb61 456
d6ce2a0b 457 waitpid($pid, 0);
2545eb61
SR
458 my $failed = $?;
459
d6ce2a0b
SR
460 close(CMD);
461 close(LOG) if ($dolog);
462 close(RD) if ($dord);
463
2545eb61
SR
464 if ($failed) {
465 doprint "FAILED!\n";
466 } else {
467 doprint "SUCCESS\n";
468 }
469
5f9b6ced
SR
470 return !$failed;
471}
472
e48c5293
SR
473sub run_ssh {
474 my ($cmd) = @_;
475 my $cp_exec = $ssh_exec;
476
477 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
478 return run_command "$cp_exec";
479}
480
481sub run_scp {
482 my ($src, $dst) = @_;
483 my $cp_scp = $scp_to_target;
484
485 $cp_scp =~ s/\$SRC_FILE/$src/g;
486 $cp_scp =~ s/\$DST_FILE/$dst/g;
487
488 return run_command "$cp_scp";
489}
490
5f9b6ced
SR
491sub get_grub_index {
492
a75fecec
SR
493 if ($reboot_type ne "grub") {
494 return;
495 }
5a391fbf 496 return if (defined($grub_number));
5f9b6ced
SR
497
498 doprint "Find grub menu ... ";
499 $grub_number = -1;
e48c5293
SR
500
501 my $ssh_grub = $ssh_exec;
502 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
503
504 open(IN, "$ssh_grub |")
5f9b6ced 505 or die "unable to get menu.lst";
e48c5293 506
5f9b6ced 507 while (<IN>) {
a75fecec 508 if (/^\s*title\s+$grub_menu\s*$/) {
5f9b6ced
SR
509 $grub_number++;
510 last;
511 } elsif (/^\s*title\s/) {
512 $grub_number++;
513 }
514 }
515 close(IN);
516
a75fecec 517 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
5f9b6ced
SR
518 if ($grub_number < 0);
519 doprint "$grub_number\n";
2545eb61
SR
520}
521
2545eb61
SR
522sub wait_for_input
523{
524 my ($fp, $time) = @_;
525 my $rin;
526 my $ready;
527 my $line;
528 my $ch;
529
530 if (!defined($time)) {
531 $time = $timeout;
532 }
533
534 $rin = '';
535 vec($rin, fileno($fp), 1) = 1;
536 $ready = select($rin, undef, undef, $time);
537
538 $line = "";
539
540 # try to read one char at a time
541 while (sysread $fp, $ch, 1) {
542 $line .= $ch;
543 last if ($ch eq "\n");
544 }
545
546 if (!length($line)) {
547 return undef;
548 }
549
550 return $line;
551}
552
75c3fda7 553sub reboot_to {
a75fecec 554 if ($reboot_type eq "grub") {
e48c5293 555 run_command "$ssh_exec '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
a75fecec
SR
556 return;
557 }
558
559 run_command "$reboot_script";
2545eb61
SR
560}
561
a57419b3
SR
562sub get_sha1 {
563 my ($commit) = @_;
564
565 doprint "git rev-list --max-count=1 $commit ... ";
566 my $sha1 = `git rev-list --max-count=1 $commit`;
567 my $ret = $?;
568
569 logit $sha1;
570
571 if ($ret) {
572 doprint "FAILED\n";
573 dodie "Failed to get git $commit";
574 }
575
576 print "SUCCESS\n";
577
578 chomp $sha1;
579
580 return $sha1;
581}
582
5a391fbf 583sub monitor {
2545eb61
SR
584 my $booted = 0;
585 my $bug = 0;
5c42fc5b 586 my $skip_call_trace = 0;
2b7d9b21 587 my $loops;
2545eb61 588
7faafbd6 589 wait_for_monitor 5;
2545eb61
SR
590
591 my $line;
592 my $full_line = "";
593
7faafbd6
SR
594 open(DMESG, "> $dmesg") or
595 die "unable to write to $dmesg";
2545eb61 596
75c3fda7 597 reboot_to;
2545eb61
SR
598
599 for (;;) {
600
2b7d9b21 601 if ($booted) {
a75fecec 602 $line = wait_for_input($monitor_fp, $booted_timeout);
2b7d9b21 603 } else {
7faafbd6 604 $line = wait_for_input($monitor_fp);
2b7d9b21 605 }
2545eb61
SR
606
607 last if (!defined($line));
608
609 doprint $line;
7faafbd6 610 print DMESG $line;
2545eb61
SR
611
612 # we are not guaranteed to get a full line
613 $full_line .= $line;
614
a75fecec 615 if ($full_line =~ /$success_line/) {
2545eb61
SR
616 $booted = 1;
617 }
618
5c42fc5b
SR
619 if ($full_line =~ /\[ backtrace testing \]/) {
620 $skip_call_trace = 1;
621 }
622
2545eb61 623 if ($full_line =~ /call trace:/i) {
5c42fc5b
SR
624 $bug = 1 if (!$skip_call_trace);
625 }
626
627 if ($full_line =~ /\[ end of backtrace testing \]/) {
628 $skip_call_trace = 0;
629 }
630
631 if ($full_line =~ /Kernel panic -/) {
2545eb61
SR
632 $bug = 1;
633 }
634
635 if ($line =~ /\n/) {
636 $full_line = "";
637 }
638 }
639
7faafbd6 640 close(DMESG);
2545eb61 641
a75fecec 642 if ($bug) {
2b7d9b21 643 return 0 if ($in_bisect);
576f627c 644 fail "failed - got a bug report" and return 0;
2545eb61
SR
645 }
646
a75fecec 647 if (!$booted) {
2b7d9b21 648 return 0 if ($in_bisect);
576f627c 649 fail "failed - never got a boot prompt." and return 0;
2545eb61 650 }
5f9b6ced 651
2b7d9b21 652 return 1;
2545eb61
SR
653}
654
655sub install {
656
e48c5293 657 run_scp "$outputdir/$build_target", "$target_image" or
5c42fc5b 658 dodie "failed to copy image";
2545eb61 659
5f9b6ced 660 my $install_mods = 0;
2545eb61 661
5f9b6ced
SR
662 # should we process modules?
663 $install_mods = 0;
51ad1dd1 664 open(IN, "$output_config") or dodie("Can't read config file");
5f9b6ced
SR
665 while (<IN>) {
666 if (/CONFIG_MODULES(=y)?/) {
667 $install_mods = 1 if (defined($1));
668 last;
5c42fc5b 669 }
5f9b6ced
SR
670 }
671 close(IN);
5c42fc5b 672
5f9b6ced
SR
673 if (!$install_mods) {
674 doprint "No modules needed\n";
675 return;
676 }
2545eb61 677
a75fecec 678 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
5f9b6ced 679 dodie "Failed to install modules";
5c42fc5b 680
5f9b6ced 681 my $modlib = "/lib/modules/$version";
a57419b3 682 my $modtar = "ktest-mods.tar.bz2";
5c42fc5b 683
e48c5293 684 run_ssh "rm -rf $modlib" or
5f9b6ced 685 dodie "failed to remove old mods: $modlib";
5c42fc5b 686
5f9b6ced 687 # would be nice if scp -r did not follow symbolic links
a75fecec 688 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
5f9b6ced
SR
689 dodie "making tarball";
690
e48c5293 691 run_scp "$tmpdir/$modtar", "/tmp" or
5f9b6ced
SR
692 dodie "failed to copy modules";
693
a75fecec 694 unlink "$tmpdir/$modtar";
5f9b6ced 695
e48c5293 696 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
5f9b6ced 697 dodie "failed to tar modules";
2545eb61 698
e48c5293 699 run_ssh "rm -f /tmp/$modtar";
8b37ca8c
SR
700
701 return if (!defined($post_install));
702
e48c5293
SR
703 my $cp_post_install = $post_install;
704 $cp_post_install = s/\$KERNEL_VERSION/$version/g;
705 run_command "$cp_post_install" or
576f627c 706 dodie "Failed to run post install";
2545eb61
SR
707}
708
6c5ee0be
SR
709sub check_buildlog {
710 my ($patch) = @_;
711
6c5ee0be
SR
712 my @files = `git show $patch | diffstat -l`;
713
714 open(IN, "git show $patch |") or
715 dodie "failed to show $patch";
716 while (<IN>) {
717 if (m,^--- a/(.*),) {
718 chomp $1;
719 $files[$#files] = $1;
720 }
721 }
722 close(IN);
723
724 open(IN, $buildlog) or dodie "Can't open $buildlog";
725 while (<IN>) {
726 if (/^\s*(.*?):.*(warning|error)/) {
727 my $err = $1;
728 foreach my $file (@files) {
a75fecec 729 my $fullpath = "$builddir/$file";
6c5ee0be 730 if ($file eq $err || $fullpath eq $err) {
2b7d9b21 731 fail "$file built with warnings" and return 0;
6c5ee0be
SR
732 }
733 }
734 }
735 }
736 close(IN);
2b7d9b21
SR
737
738 return 1;
6c5ee0be
SR
739}
740
2545eb61
SR
741sub build {
742 my ($type) = @_;
5c42fc5b 743 my $defconfig = "";
5c42fc5b 744
7faafbd6
SR
745 unlink $buildlog;
746
75c3fda7 747 if ($type =~ /^useconfig:(.*)/) {
51ad1dd1 748 run_command "cp $1 $output_config" or
75c3fda7 749 dodie "could not copy $1 to .config";
5f9b6ced 750
75c3fda7
SR
751 $type = "oldconfig";
752 }
753
5c42fc5b
SR
754 # old config can ask questions
755 if ($type eq "oldconfig") {
9386c6ab 756 $type = "oldnoconfig";
75c3fda7
SR
757
758 # allow for empty configs
51ad1dd1 759 run_command "touch $output_config";
75c3fda7 760
51ad1dd1 761 run_command "mv $output_config $outputdir/config_temp" or
5c42fc5b 762 dodie "moving .config";
2545eb61 763
5f9b6ced 764 if (!$noclean && !run_command "$make mrproper") {
5c42fc5b
SR
765 dodie "make mrproper";
766 }
2545eb61 767
51ad1dd1 768 run_command "mv $outputdir/config_temp $output_config" or
5c42fc5b 769 dodie "moving config_temp";
5c42fc5b
SR
770
771 } elsif (!$noclean) {
51ad1dd1 772 unlink "$output_config";
5f9b6ced 773 run_command "$make mrproper" or
5c42fc5b 774 dodie "make mrproper";
5c42fc5b 775 }
2545eb61
SR
776
777 # add something to distinguish this build
a75fecec
SR
778 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
779 print OUT "$localversion\n";
2545eb61
SR
780 close(OUT);
781
5f9b6ced
SR
782 if (defined($minconfig)) {
783 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
2545eb61
SR
784 }
785
9386c6ab 786 run_command "$defconfig $make $type" or
5c42fc5b 787 dodie "failed make config";
2545eb61 788
a75fecec
SR
789 $redirect = "$buildlog";
790 if (!run_command "$make $build_options") {
6c5ee0be 791 undef $redirect;
5f9b6ced 792 # bisect may need this to pass
2b7d9b21
SR
793 return 0 if ($in_bisect);
794 fail "failed build" and return 0;
2545eb61 795 }
6c5ee0be 796 undef $redirect;
5f9b6ced 797
2b7d9b21 798 return 1;
2545eb61
SR
799}
800
75c3fda7 801sub halt {
e48c5293 802 if (!run_ssh "halt" or defined($power_off)) {
576f627c
SR
803 if (defined($poweroff_after_halt)) {
804 sleep $poweroff_after_halt;
805 run_command "$power_off";
806 }
807 } else {
75c3fda7 808 # nope? the zap it!
a75fecec 809 run_command "$power_off";
75c3fda7
SR
810 }
811}
812
5f9b6ced
SR
813sub success {
814 my ($i) = @_;
815
e48c5293
SR
816 $successes++;
817
5f9b6ced
SR
818 doprint "\n\n*******************************************\n";
819 doprint "*******************************************\n";
7a849cd9 820 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
5f9b6ced
SR
821 doprint "*******************************************\n";
822 doprint "*******************************************\n";
823
576f627c 824 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
a75fecec 825 doprint "Reboot and wait $sleep_time seconds\n";
5f9b6ced 826 reboot;
7faafbd6 827 start_monitor;
a75fecec 828 wait_for_monitor $sleep_time;
7faafbd6 829 end_monitor;
5f9b6ced
SR
830 }
831}
832
833sub get_version {
834 # get the release name
835 doprint "$make kernelrelease ... ";
836 $version = `$make kernelrelease | tail -1`;
837 chomp($version);
838 doprint "$version\n";
839}
840
5a391fbf 841sub child_run_test {
7faafbd6 842 my $failed = 0;
5a391fbf 843
7faafbd6 844 # child should have no power
a75fecec
SR
845 $reboot_on_error = 0;
846 $poweroff_on_error = 0;
847 $die_on_failure = 1;
7faafbd6
SR
848
849 run_command $run_test or $failed = 1;
5a391fbf
SR
850 exit $failed;
851}
852
853my $child_done;
854
855sub child_finished {
856 $child_done = 1;
857}
858
859sub do_run_test {
860 my $child_pid;
861 my $child_exit;
5a391fbf
SR
862 my $line;
863 my $full_line;
864 my $bug = 0;
5a391fbf 865
7faafbd6 866 wait_for_monitor 1;
5a391fbf 867
7faafbd6 868 doprint "run test $run_test\n";
5a391fbf
SR
869
870 $child_done = 0;
871
872 $SIG{CHLD} = qw(child_finished);
873
874 $child_pid = fork;
875
876 child_run_test if (!$child_pid);
877
878 $full_line = "";
879
880 do {
7faafbd6 881 $line = wait_for_input($monitor_fp, 1);
5a391fbf
SR
882 if (defined($line)) {
883
884 # we are not guaranteed to get a full line
885 $full_line .= $line;
886
887 if ($full_line =~ /call trace:/i) {
888 $bug = 1;
889 }
890
891 if ($full_line =~ /Kernel panic -/) {
892 $bug = 1;
893 }
894
895 if ($line =~ /\n/) {
896 $full_line = "";
897 }
898 }
899 } while (!$child_done && !$bug);
900
901 if ($bug) {
902 doprint "Detected kernel crash!\n";
903 # kill the child with extreme prejudice
904 kill 9, $child_pid;
905 }
906
907 waitpid $child_pid, 0;
908 $child_exit = $?;
909
5a391fbf 910 if ($bug || $child_exit) {
2b7d9b21
SR
911 return 0 if $in_bisect;
912 fail "test failed" and return 0;
5a391fbf 913 }
2b7d9b21 914 return 1;
5a391fbf
SR
915}
916
a75fecec
SR
917sub run_git_bisect {
918 my ($command) = @_;
919
920 doprint "$command ... ";
921
922 my $output = `$command 2>&1`;
923 my $ret = $?;
924
925 logit $output;
926
927 if ($ret) {
928 doprint "FAILED\n";
929 dodie "Failed to git bisect";
930 }
931
932 doprint "SUCCESS\n";
933 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
934 doprint "$1 [$2]\n";
935 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
936 $bisect_bad = $1;
937 doprint "Found bad commit... $1\n";
938 return 0;
939 } else {
940 # we already logged it, just print it now.
941 print $output;
942 }
943
944 return 1;
945}
946
0a05c769
SR
947# returns 1 on success, 0 on failure
948sub run_bisect_test {
949 my ($type, $buildtype) = @_;
5f9b6ced 950
2b7d9b21 951 my $failed = 0;
5f9b6ced
SR
952 my $result;
953 my $output;
954 my $ret;
955
0a05c769
SR
956 $in_bisect = 1;
957
958 build $buildtype or $failed = 1;
5f9b6ced
SR
959
960 if ($type ne "build") {
7faafbd6 961 dodie "Failed on build" if $failed;
5f9b6ced
SR
962
963 # Now boot the box
964 get_grub_index;
965 get_version;
966 install;
7faafbd6
SR
967
968 start_monitor;
2b7d9b21 969 monitor or $failed = 1;
5f9b6ced
SR
970
971 if ($type ne "boot") {
7faafbd6 972 dodie "Failed on boot" if $failed;
5a391fbf 973
2b7d9b21 974 do_run_test or $failed = 1;
5f9b6ced 975 }
7faafbd6 976 end_monitor;
5f9b6ced
SR
977 }
978
979 if ($failed) {
0a05c769 980 $result = 0;
5a391fbf
SR
981
982 # reboot the box to a good kernel
a75fecec
SR
983 if ($type ne "build") {
984 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
5a391fbf 985 reboot;
7faafbd6 986 start_monitor;
a75fecec 987 wait_for_monitor $bisect_sleep_time;
7faafbd6 988 end_monitor;
5a391fbf 989 }
5f9b6ced 990 } else {
0a05c769
SR
991 $result = 1;
992 }
993 $in_bisect = 0;
994
995 return $result;
996}
997
998sub run_bisect {
999 my ($type) = @_;
1000 my $buildtype = "oldconfig";
1001
1002 # We should have a minconfig to use?
1003 if (defined($minconfig)) {
1004 $buildtype = "useconfig:$minconfig";
5f9b6ced
SR
1005 }
1006
0a05c769
SR
1007 my $ret = run_bisect_test $type, $buildtype;
1008
1009
d6ce2a0b
SR
1010 # Are we looking for where it worked, not failed?
1011 if ($reverse_bisect) {
0a05c769 1012 $ret = !$ret;
d6ce2a0b
SR
1013 }
1014
0a05c769
SR
1015 if ($ret) {
1016 return "good";
1017 } else {
1018 return "bad";
1019 }
5f9b6ced
SR
1020}
1021
1022sub bisect {
1023 my ($i) = @_;
1024
1025 my $result;
1026
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]"}));
1030
1031 my $good = $opt{"BISECT_GOOD[$i]"};
1032 my $bad = $opt{"BISECT_BAD[$i]"};
1033 my $type = $opt{"BISECT_TYPE[$i]"};
a75fecec
SR
1034 my $start = $opt{"BISECT_START[$i]"};
1035 my $replay = $opt{"BISECT_REPLAY[$i]"};
5f9b6ced 1036
a57419b3
SR
1037 # convert to true sha1's
1038 $good = get_sha1($good);
1039 $bad = get_sha1($bad);
1040
d6ce2a0b
SR
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;
1045 } else {
1046 $reverse_bisect = 0;
1047 }
1048
a75fecec
SR
1049 # Can't have a test without having a test to run
1050 if ($type eq "test" && !defined($run_test)) {
1051 $type = "boot";
1052 }
1053
1054 my $check = $opt{"BISECT_CHECK[$i]"};
1055 if (defined($check) && $check ne "0") {
1056
1057 # get current HEAD
a57419b3 1058 my $head = get_sha1("HEAD");
a75fecec
SR
1059
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";
1064
1065 $result = run_bisect $type;
1066
1067 if ($result ne "bad") {
1068 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1069 }
1070 }
1071
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";
1076
1077 $result = run_bisect $type;
1078
1079 if ($result ne "good") {
1080 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1081 }
1082 }
1083
1084 # checkout where we started
1085 run_command "git checkout $head" or
1086 die "Failed to checkout $head";
1087 }
1088
5f9b6ced 1089 run_command "git bisect start" or
a75fecec 1090 dodie "could not start bisect";
5f9b6ced
SR
1091
1092 run_command "git bisect good $good" or
a75fecec 1093 dodie "could not set bisect good to $good";
5f9b6ced 1094
a75fecec
SR
1095 run_git_bisect "git bisect bad $bad" or
1096 dodie "could not set bisect bad to $bad";
5f9b6ced 1097
a75fecec
SR
1098 if (defined($replay)) {
1099 run_command "git bisect replay $replay" or
1100 dodie "failed to run replay";
5a391fbf
SR
1101 }
1102
a75fecec
SR
1103 if (defined($start)) {
1104 run_command "git checkout $start" or
1105 dodie "failed to checkout $start";
1106 }
1107
1108 my $test;
5f9b6ced
SR
1109 do {
1110 $result = run_bisect $type;
a75fecec
SR
1111 $test = run_git_bisect "git bisect $result";
1112 } while ($test);
5f9b6ced
SR
1113
1114 run_command "git bisect log" or
1115 dodie "could not capture git bisect log";
1116
1117 run_command "git bisect reset" or
1118 dodie "could not reset git bisect";
1119
1120 doprint "Bad commit was [$bisect_bad]\n";
1121
0a05c769
SR
1122 success $i;
1123}
1124
1125my %config_ignore;
1126my %config_set;
1127
1128my %config_list;
1129my %null_config;
1130
1131my %dependency;
1132
1133sub process_config_ignore {
1134 my ($config) = @_;
1135
1136 open (IN, $config)
1137 or dodie "Failed to read $config";
1138
1139 while (<IN>) {
1140 if (/^(.*?(CONFIG\S*)(=.*| is not set))/) {
1141 $config_ignore{$2} = $1;
1142 }
1143 }
1144
1145 close(IN);
1146}
1147
1148sub read_current_config {
1149 my ($config_ref) = @_;
1150
1151 %{$config_ref} = ();
1152 undef %{$config_ref};
1153
1154 my @key = keys %{$config_ref};
1155 if ($#key >= 0) {
1156 print "did not delete!\n";
1157 exit;
1158 }
1159 open (IN, "$output_config");
1160
1161 while (<IN>) {
1162 if (/^(CONFIG\S+)=(.*)/) {
1163 ${$config_ref}{$1} = $2;
1164 }
1165 }
1166 close(IN);
1167}
1168
1169sub get_dependencies {
1170 my ($config) = @_;
1171
1172 my $arr = $dependency{$config};
1173 if (!defined($arr)) {
1174 return ();
1175 }
1176
1177 my @deps = @{$arr};
1178
1179 foreach my $dep (@{$arr}) {
1180 print "ADD DEP $dep\n";
1181 @deps = (@deps, get_dependencies $dep);
1182 }
1183
1184 return @deps;
1185}
1186
1187sub create_config {
1188 my @configs = @_;
1189
1190 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1191
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";
1197 }
1198 }
1199
1200 foreach my $config (keys %config_ignore) {
1201 print OUT "$config_ignore{$config}\n";
1202 }
1203 close(OUT);
1204
1205# exit;
1206 run_command "$make oldnoconfig" or
1207 dodie "failed make config oldconfig";
1208
1209}
1210
1211sub compare_configs {
1212 my (%a, %b) = @_;
1213
1214 foreach my $item (keys %a) {
1215 if (!defined($b{$item})) {
1216 print "diff $item\n";
1217 return 1;
1218 }
1219 delete $b{$item};
1220 }
1221
1222 my @keys = keys %b;
1223 if ($#keys) {
1224 print "diff2 $keys[0]\n";
1225 }
1226 return -1 if ($#keys >= 0);
1227
1228 return 0;
1229}
1230
1231sub run_config_bisect_test {
1232 my ($type) = @_;
1233
1234 return run_bisect_test $type, "oldconfig";
1235}
1236
1237sub process_passed {
1238 my (%configs) = @_;
1239
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};
1248 }
1249 }
1250}
1251
1252sub process_failed {
1253 my ($config) = @_;
1254
1255 doprint "\n\n***************************************\n";
1256 doprint "Found bad config: $config\n";
1257 doprint "***************************************\n\n";
1258}
1259
1260sub run_config_bisect {
1261
1262 my @start_list = keys %config_list;
1263
1264 if ($#start_list < 0) {
1265 doprint "No more configs to test!!!\n";
1266 return -1;
1267 }
1268
1269 doprint "***** RUN TEST ***\n";
1270 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1271 my $ret;
1272 my %current_config;
1273
1274 my $count = $#start_list + 1;
1275 doprint " $count configs to test\n";
1276
1277 my $half = int($#start_list / 2);
1278
1279 do {
1280 my @tophalf = @start_list[0 .. $half];
1281
1282 create_config @tophalf;
1283 read_current_config \%current_config;
1284
1285 $count = $#tophalf + 1;
1286 doprint "Testing $count configs\n";
1287 my $found = 0;
1288 # make sure we test something
1289 foreach my $config (@tophalf) {
1290 if (defined($current_config{$config})) {
1291 logit " $config\n";
1292 $found = 1;
1293 }
1294 }
1295 if (!$found) {
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})) {
1303 logit " $config\n";
1304 $found = 1;
1305 }
1306 }
1307 if (!$found) {
1308 doprint "Failed: Can't make new config with current configs\n";
1309 foreach my $config (@start_list) {
1310 doprint " CONFIG: $config\n";
1311 }
1312 return -1;
1313 }
1314 $count = $#tophalf + 1;
1315 doprint "Testing $count configs\n";
1316 }
1317
1318 $ret = run_config_bisect_test $type;
1319
1320 if ($ret) {
1321 process_passed %current_config;
1322 return 0;
1323 }
1324
1325 doprint "This config had a failure.\n";
1326 doprint "Removing these configs that were not set in this config:\n";
1327
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};
1333 }
1334 }
1335
1336 @start_list = @tophalf;
1337
1338 if ($#start_list == 0) {
1339 process_failed $start_list[0];
1340 return 1;
1341 }
1342
1343 # remove half the configs we are looking at and see if
1344 # they are good.
1345 $half = int($#start_list / 2);
1346 } while ($half > 0);
1347
1348 # we found a single config, try it again
1349 my @tophalf = @start_list[0 .. 0];
1350
1351 $ret = run_config_bisect_test $type;
1352 if ($ret) {
1353 process_passed %current_config;
1354 return 0;
1355 }
1356
1357 process_failed $start_list[0];
1358 return 1;
1359}
1360
1361sub config_bisect {
1362 my ($i) = @_;
1363
1364 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1365
1366 my $tmpconfig = "$tmpdir/use_config";
1367
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";
1373 } else {
1374 unlink $tmpconfig;
1375 }
1376
1377 # Add other configs
1378 if (defined($addconfig)) {
1379 run_command "cat $addconfig >> $tmpconfig" or
1380 dodie "failed to append $addconfig";
1381 }
1382
1383 my $defconfig = "";
1384 if (-f $tmpconfig) {
1385 $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
1386 process_config_ignore $tmpconfig;
1387 }
1388
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";
1392
1393 # read directly what we want to check
1394 my %config_check;
1395 open (IN, $output_config)
1396 or dodie "faied to open $output_config";
1397
1398 while (<IN>) {
1399 if (/^((CONFIG\S*)=.*)/) {
1400 $config_check{$2} = $1;
1401 }
1402 }
1403 close(IN);
1404
1405 # Now run oldconfig with the minconfig (and addconfigs)
1406 run_command "$defconfig $make oldnoconfig" or
1407 dodie "failed make config oldconfig";
1408
1409 # check to see what we lost (or gained)
1410 open (IN, $output_config)
1411 or dodie "Failed to read $start_config";
1412
1413 my %removed_configs;
1414 my %added_configs;
1415
1416 while (<IN>) {
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;
1423 } else {
1424 $config_list{$2} = $1;
1425 }
1426 } elsif (!defined($config_ignore{$2})) {
1427 $added_configs{$2} = $1;
1428 $config_list{$2} = $1;
1429 }
1430 }
1431 }
1432 close(IN);
1433
1434 my @confs = keys %removed_configs;
1435 if ($#confs >= 0) {
1436 doprint "Configs overridden by default configs and removed from check:\n";
1437 foreach my $config (@confs) {
1438 doprint " $config\n";
1439 }
1440 }
1441 @confs = keys %added_configs;
1442 if ($#confs >= 0) {
1443 doprint "Configs appearing in make oldconfig and added:\n";
1444 foreach my $config (@confs) {
1445 doprint " $config\n";
1446 }
1447 }
1448
1449 my %config_test;
1450 my $once = 0;
1451
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})) {
1461 if (!$once) {
1462 $once = 1;
1463 doprint "Configs not produced by kconfig (will not be checked):\n";
1464 }
1465 doprint " $config\n";
1466 delete $config_list{$config};
1467 }
1468 }
1469 my $ret;
1470 do {
1471 $ret = run_config_bisect;
1472 } while (!$ret);
1473
1474 return $ret if ($ret < 0);
5f9b6ced
SR
1475
1476 success $i;
1477}
1478
6c5ee0be
SR
1479sub patchcheck {
1480 my ($i) = @_;
1481
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]"}));
1486
1487 my $start = $opt{"PATCHCHECK_START[$i]"};
1488
1489 my $end = "HEAD";
1490 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1491 $end = $opt{"PATCHCHECK_END[$i]"};
1492 }
1493
a57419b3
SR
1494 # Get the true sha1's since we can use things like HEAD~3
1495 $start = get_sha1($start);
1496 $end = get_sha1($end);
1497
6c5ee0be
SR
1498 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1499
1500 # Can't have a test without having a test to run
1501 if ($type eq "test" && !defined($run_test)) {
1502 $type = "boot";
1503 }
1504
1505 open (IN, "git log --pretty=oneline $end|") or
1506 dodie "could not get git list";
1507
1508 my @list;
1509
1510 while (<IN>) {
1511 chomp;
1512 $list[$#list+1] = $_;
1513 last if (/^$start/);
1514 }
1515 close(IN);
1516
1517 if ($list[$#list] !~ /^$start/) {
2b7d9b21 1518 fail "SHA1 $start not found";
6c5ee0be
SR
1519 }
1520
1521 # go backwards in the list
1522 @list = reverse @list;
1523
1524 my $save_clean = $noclean;
1525
1526 $in_patchcheck = 1;
1527 foreach my $item (@list) {
1528 my $sha1 = $item;
1529 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1530
1531 doprint "\nProcessing commit $item\n\n";
1532
1533 run_command "git checkout $sha1" or
1534 die "Failed to checkout $sha1";
1535
1536 # only clean on the first and last patch
1537 if ($item eq $list[0] ||
1538 $item eq $list[$#list]) {
1539 $noclean = $save_clean;
1540 } else {
1541 $noclean = 1;
1542 }
1543
1544 if (defined($minconfig)) {
2b7d9b21 1545 build "useconfig:$minconfig" or return 0;
6c5ee0be
SR
1546 } else {
1547 # ?? no config to use?
2b7d9b21 1548 build "oldconfig" or return 0;
6c5ee0be
SR
1549 }
1550
2b7d9b21 1551 check_buildlog $sha1 or return 0;
6c5ee0be
SR
1552
1553 next if ($type eq "build");
1554
1555 get_grub_index;
1556 get_version;
1557 install;
6c5ee0be 1558
7faafbd6
SR
1559 my $failed = 0;
1560
1561 start_monitor;
1562 monitor or $failed = 1;
1563
1564 if (!$failed && $type ne "boot"){
1565 do_run_test or $failed = 1;
1566 }
1567 end_monitor;
1568 return 0 if ($failed);
1569
6c5ee0be
SR
1570 }
1571 $in_patchcheck = 0;
1572 success $i;
2b7d9b21
SR
1573
1574 return 1;
6c5ee0be
SR
1575}
1576
2545eb61
SR
1577read_config $ARGV[0];
1578
1579# mandatory configs
1580die "MACHINE not defined\n" if (!defined($opt{"MACHINE"}));
1581die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"}));
1582die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"}));
1583die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"}));
1584die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"}));
75c3fda7 1585die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"}));
2545eb61
SR
1586die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"}));
1587die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"}));
1588die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"}));
2545eb61 1589
2b7d9b21
SR
1590if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
1591 unlink $opt{"LOG_FILE"};
1592}
2545eb61 1593
2b7d9b21
SR
1594doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
1595
a57419b3
SR
1596for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
1597
1598 if (!$i) {
1599 doprint "DEFAULT OPTIONS:\n";
1600 } else {
1601 doprint "\nTEST $i OPTIONS";
1602 if (defined($repeat_tests{$i})) {
1603 $repeat = $repeat_tests{$i};
1604 doprint " ITERATE $repeat";
1605 }
1606 doprint "\n";
1607 }
1608
1609 foreach my $option (sort keys %opt) {
1610
1611 if ($option =~ /\[(\d+)\]$/) {
1612 next if ($i != $1);
1613 } else {
1614 next if ($i);
1615 }
1616
1617 doprint "$option = $opt{$option}\n";
1618 }
2b7d9b21 1619}
2545eb61 1620
a75fecec 1621sub set_test_option {
5a391fbf 1622 my ($name, $i) = @_;
2545eb61 1623
5a391fbf 1624 my $option = "$name\[$i\]";
5c42fc5b 1625
5a391fbf
SR
1626 if (defined($opt{$option})) {
1627 return $opt{$option};
5f9b6ced
SR
1628 }
1629
a57419b3
SR
1630 foreach my $test (keys %repeat_tests) {
1631 if ($i >= $test &&
1632 $i < $test + $repeat_tests{$test}) {
1633 $option = "$name\[$test\]";
1634 if (defined($opt{$option})) {
1635 return $opt{$option};
1636 }
1637 }
1638 }
1639
5a391fbf
SR
1640 if (defined($opt{$name})) {
1641 return $opt{$name};
2545eb61
SR
1642 }
1643
5a391fbf
SR
1644 return undef;
1645}
1646
1647# First we need to do is the builds
a75fecec
SR
1648for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
1649
576f627c
SR
1650 $iteration = $i;
1651
a75fecec
SR
1652 my $makecmd = set_test_option("MAKE_CMD", $i);
1653
1654 $machine = set_test_option("MACHINE", $i);
e48c5293 1655 $ssh_user = set_test_option("SSH_USER", $i);
a75fecec
SR
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);
e48c5293 1663 $reboot = set_test_option("REBOOT", $i);
a75fecec
SR
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);
8b37ca8c 1670 $post_install = set_test_option("POST_INSTALL", $i);
a75fecec
SR
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);
576f627c
SR
1676 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
1677 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
a75fecec
SR
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);
e48c5293
SR
1686 $ssh_exec = set_test_option("SSH_EXEC", $i);
1687 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
a75fecec
SR
1688 $target_image = set_test_option("TARGET_IMAGE", $i);
1689 $localversion = set_test_option("LOCALVERSION", $i);
1690
1691 chdir $builddir || die "can't change directory to $builddir";
1692
1693 if (!-d $tmpdir) {
1694 mkpath($tmpdir) or
1695 die "can't create $tmpdir";
1696 }
1a5cfce3 1697
e48c5293
SR
1698 $ENV{"SSH_USER"} = $ssh_user;
1699 $ENV{"MACHINE"} = $machine;
1700
a75fecec
SR
1701 $target = "$ssh_user\@$machine";
1702
1703 $buildlog = "$tmpdir/buildlog-$machine";
1704 $dmesg = "$tmpdir/dmesg-$machine";
1705 $make = "$makecmd O=$outputdir";
51ad1dd1 1706 $output_config = "$outputdir/.config";
a75fecec
SR
1707
1708 if ($reboot_type eq "grub") {
576f627c 1709 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
a75fecec 1710 } elsif (!defined($reboot_script)) {
576f627c 1711 dodie "REBOOT_SCRIPT not defined"
a75fecec
SR
1712 }
1713
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]"};
0a05c769
SR
1719 } elsif ($test_type eq "config_bisect") {
1720 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
a75fecec
SR
1721 }
1722
1723 # mistake in config file?
1724 if (!defined($run_type)) {
1725 $run_type = "ERROR";
1726 }
5a391fbf 1727
2545eb61 1728 doprint "\n\n";
a75fecec 1729 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
7faafbd6
SR
1730
1731 unlink $dmesg;
1732 unlink $buildlog;
2545eb61 1733
2b7d9b21
SR
1734 if (!defined($minconfig)) {
1735 $minconfig = $addconfig;
1736
1737 } elsif (defined($addconfig)) {
9be2e6b5 1738 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
2b7d9b21 1739 dodie "Failed to create temp config";
9be2e6b5 1740 $minconfig = "$tmpdir/add_config";
2b7d9b21
SR
1741 }
1742
6c5ee0be
SR
1743 my $checkout = $opt{"CHECKOUT[$i]"};
1744 if (defined($checkout)) {
1745 run_command "git checkout $checkout" or
1746 die "failed to checkout $checkout";
1747 }
1748
a75fecec 1749 if ($test_type eq "bisect") {
5f9b6ced
SR
1750 bisect $i;
1751 next;
0a05c769
SR
1752 } elsif ($test_type eq "config_bisect") {
1753 config_bisect $i;
1754 next;
a75fecec 1755 } elsif ($test_type eq "patchcheck") {
6c5ee0be
SR
1756 patchcheck $i;
1757 next;
2545eb61 1758 }
2545eb61 1759
7faafbd6
SR
1760 if ($build_type ne "nobuild") {
1761 build $build_type or next;
2545eb61
SR
1762 }
1763
a75fecec
SR
1764 if ($test_type ne "build") {
1765 get_grub_index;
1766 get_version;
1767 install;
5a391fbf 1768
a75fecec
SR
1769 my $failed = 0;
1770 start_monitor;
1771 monitor or $failed = 1;;
1772
1773 if (!$failed && $test_type ne "boot" && defined($run_test)) {
1774 do_run_test or $failed = 1;
1775 }
1776 end_monitor;
1777 next if ($failed);
5a391fbf
SR
1778 }
1779
5f9b6ced 1780 success $i;
2545eb61
SR
1781}
1782
5c42fc5b 1783if ($opt{"POWEROFF_ON_SUCCESS"}) {
75c3fda7 1784 halt;
576f627c 1785} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
75c3fda7 1786 reboot;
5c42fc5b 1787}
75c3fda7 1788
e48c5293
SR
1789doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
1790
2545eb61 1791exit 0;
This page took 0.109601 seconds and 5 git commands to generate.