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