ktest: Have all values be set by defaults
[linux-2.6-block.git] / tools / testing / ktest / ktest.pl
CommitLineData
2545eb61 1#!/usr/bin/perl -w
d6ce2a0b 2#
cce1dac8 3# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
d6ce2a0b
SR
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
2545eb61
SR
16$| = 1;
17
18my %opt;
a57419b3
SR
19my %repeat_tests;
20my %repeats;
2545eb61
SR
21
22#default opts
4f43e0dc
SR
23my %default = (
24 "NUM_TESTS" => 1,
25 "TEST_TYPE" => "build",
26 "BUILD_TYPE" => "randconfig",
27 "MAKE_CMD" => "make",
28 "TIMEOUT" => 120,
29 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
30 "SLEEP_TIME" => 60, # sleep time between tests
31 "BUILD_NOCLEAN" => 0,
32 "REBOOT_ON_ERROR" => 0,
33 "POWEROFF_ON_ERROR" => 0,
34 "REBOOT_ON_SUCCESS" => 1,
35 "POWEROFF_ON_SUCCESS" => 0,
36 "BUILD_OPTIONS" => "",
37 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
38 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
39 "CLEAR_LOG" => 0,
40 "BISECT_MANUAL" => 0,
41 "BISECT_SKIP" => 1,
42 "SUCCESS_LINE" => "login:",
43 "DETECT_TRIPLE_FAULT" => 1,
44 "NO_INSTALL" => 0,
45 "BOOTED_TIMEOUT" => 1,
46 "DIE_ON_FAILURE" => 1,
47 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
48 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
49 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
50 "STOP_AFTER_SUCCESS" => 10,
51 "STOP_AFTER_FAILURE" => 60,
52 "STOP_TEST_AFTER" => 600,
600bbf0a
SR
53
54# required, and we will ask users if they don't have them but we keep the default
55# value something that is common.
4f43e0dc
SR
56 "REBOOT_TYPE" => "grub",
57 "LOCALVERSION" => "-test",
58 "SSH_USER" => "root",
59 "BUILD_TARGET" => "arch/x86/boot/bzImage",
60 "TARGET_IMAGE" => "/boot/vmlinuz-test",
61);
2545eb61 62
8d1491ba 63my $ktest_config;
2545eb61 64my $version;
a75fecec 65my $machine;
e48c5293 66my $ssh_user;
a75fecec
SR
67my $tmpdir;
68my $builddir;
69my $outputdir;
51ad1dd1 70my $output_config;
a75fecec 71my $test_type;
7faafbd6 72my $build_type;
a75fecec 73my $build_options;
0bd6c1a3
SR
74my $pre_build;
75my $post_build;
76my $pre_build_die;
77my $post_build_die;
a75fecec
SR
78my $reboot_type;
79my $reboot_script;
80my $power_cycle;
e48c5293 81my $reboot;
a75fecec 82my $reboot_on_error;
bc7c5803
SR
83my $switch_to_good;
84my $switch_to_test;
a75fecec
SR
85my $poweroff_on_error;
86my $die_on_failure;
576f627c
SR
87my $powercycle_after_reboot;
88my $poweroff_after_halt;
e48c5293
SR
89my $ssh_exec;
90my $scp_to_target;
a75fecec
SR
91my $power_off;
92my $grub_menu;
2545eb61
SR
93my $grub_number;
94my $target;
95my $make;
8b37ca8c 96my $post_install;
e0a8742e 97my $no_install;
5c42fc5b 98my $noclean;
5f9b6ced 99my $minconfig;
4c4ab120 100my $start_minconfig;
35ce5952 101my $start_minconfig_defined;
4c4ab120
SR
102my $output_minconfig;
103my $ignore_config;
2b7d9b21 104my $addconfig;
5f9b6ced 105my $in_bisect = 0;
b5f4aea6 106my $bisect_bad_commit = "";
d6ce2a0b 107my $reverse_bisect;
c960bb9f 108my $bisect_manual;
c23dca7c 109my $bisect_skip;
30f75da5 110my $config_bisect_good;
c5dacb88
SR
111my $bisect_ret_good;
112my $bisect_ret_bad;
113my $bisect_ret_skip;
114my $bisect_ret_abort;
115my $bisect_ret_default;
6c5ee0be 116my $in_patchcheck = 0;
5a391fbf 117my $run_test;
6c5ee0be 118my $redirect;
7faafbd6 119my $buildlog;
a9dd5d63 120my $testlog;
7faafbd6
SR
121my $dmesg;
122my $monitor_fp;
123my $monitor_pid;
124my $monitor_cnt = 0;
a75fecec
SR
125my $sleep_time;
126my $bisect_sleep_time;
27d934b2 127my $patchcheck_sleep_time;
1990207d 128my $ignore_warnings;
a75fecec 129my $store_failures;
de5b6e3b 130my $store_successes;
9064af52 131my $test_name;
a75fecec
SR
132my $timeout;
133my $booted_timeout;
f1a5b962 134my $detect_triplefault;
a75fecec 135my $console;
2b803365 136my $reboot_success_line;
a75fecec 137my $success_line;
1c8a617a
SR
138my $stop_after_success;
139my $stop_after_failure;
2d01b26a 140my $stop_test_after;
a75fecec
SR
141my $build_target;
142my $target_image;
b5f4aea6 143my $checkout;
a75fecec 144my $localversion;
576f627c 145my $iteration = 0;
e48c5293 146my $successes = 0;
2545eb61 147
b5f4aea6
SR
148my $bisect_good;
149my $bisect_bad;
150my $bisect_type;
151my $bisect_start;
152my $bisect_replay;
153my $bisect_files;
154my $bisect_reverse;
155my $bisect_check;
156
157my $config_bisect;
158my $config_bisect_type;
159
160my $patchcheck_type;
161my $patchcheck_start;
162my $patchcheck_end;
163
165708b2 164# set when a test is something other that just building or install
bb8474b1
SR
165# which would require more options.
166my $buildonly = 1;
167
dbd3783b
SR
168# set when creating a new config
169my $newconfig = 0;
170
8d1491ba
SR
171my %entered_configs;
172my %config_help;
77d942ce 173my %variable;
fcb3f16a 174my %force_config;
8d1491ba 175
4ab1cce5
SR
176# do not force reboots on config problems
177my $no_reboot = 1;
178
7bf51073
SR
179# default variables that can be used
180chomp ($variable{"PWD"} = `pwd`);
181
8d1491ba
SR
182$config_help{"MACHINE"} = << "EOF"
183 The machine hostname that you will test.
bb8474b1 184 For build only tests, it is still needed to differentiate log files.
8d1491ba
SR
185EOF
186 ;
187$config_help{"SSH_USER"} = << "EOF"
188 The box is expected to have ssh on normal bootup, provide the user
189 (most likely root, since you need privileged operations)
190EOF
191 ;
192$config_help{"BUILD_DIR"} = << "EOF"
193 The directory that contains the Linux source code (full path).
0e7a22de
SR
194 You can use \${PWD} that will be the path where ktest.pl is run, or use
195 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
8d1491ba
SR
196EOF
197 ;
198$config_help{"OUTPUT_DIR"} = << "EOF"
199 The directory that the objects will be built (full path).
200 (can not be same as BUILD_DIR)
0e7a22de
SR
201 You can use \${PWD} that will be the path where ktest.pl is run, or use
202 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
8d1491ba
SR
203EOF
204 ;
205$config_help{"BUILD_TARGET"} = << "EOF"
206 The location of the compiled file to copy to the target.
207 (relative to OUTPUT_DIR)
208EOF
209 ;
dbd3783b
SR
210$config_help{"BUILD_OPTIONS"} = << "EOF"
211 Options to add to \"make\" when building.
212 i.e. -j20
213EOF
214 ;
8d1491ba
SR
215$config_help{"TARGET_IMAGE"} = << "EOF"
216 The place to put your image on the test machine.
217EOF
218 ;
219$config_help{"POWER_CYCLE"} = << "EOF"
220 A script or command to reboot the box.
221
222 Here is a digital loggers power switch example
223 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
224
225 Here is an example to reboot a virtual box on the current host
226 with the name "Guest".
227 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
228EOF
229 ;
230$config_help{"CONSOLE"} = << "EOF"
231 The script or command that reads the console
232
233 If you use ttywatch server, something like the following would work.
234CONSOLE = nc -d localhost 3001
235
236 For a virtual machine with guest name "Guest".
237CONSOLE = virsh console Guest
238EOF
239 ;
240$config_help{"LOCALVERSION"} = << "EOF"
241 Required version ending to differentiate the test
242 from other linux builds on the system.
243EOF
244 ;
245$config_help{"REBOOT_TYPE"} = << "EOF"
246 Way to reboot the box to the test kernel.
247 Only valid options so far are "grub" and "script".
248
249 If you specify grub, it will assume grub version 1
250 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
251 and select that target to reboot to the kernel. If this is not
252 your setup, then specify "script" and have a command or script
253 specified in REBOOT_SCRIPT to boot to the target.
254
255 The entry in /boot/grub/menu.lst must be entered in manually.
256 The test will not modify that file.
257EOF
258 ;
259$config_help{"GRUB_MENU"} = << "EOF"
260 The grub title name for the test kernel to boot
261 (Only mandatory if REBOOT_TYPE = grub)
262
263 Note, ktest.pl will not update the grub menu.lst, you need to
264 manually add an option for the test. ktest.pl will search
265 the grub menu.lst for this option to find what kernel to
266 reboot into.
267
268 For example, if in the /boot/grub/menu.lst the test kernel title has:
269 title Test Kernel
270 kernel vmlinuz-test
271 GRUB_MENU = Test Kernel
272EOF
273 ;
274$config_help{"REBOOT_SCRIPT"} = << "EOF"
275 A script to reboot the target into the test kernel
276 (Only mandatory if REBOOT_TYPE = script)
277EOF
278 ;
279
dad98754
SR
280sub read_prompt {
281 my ($cancel, $prompt) = @_;
35ce5952
SR
282
283 my $ans;
284
285 for (;;) {
dad98754
SR
286 if ($cancel) {
287 print "$prompt [y/n/C] ";
288 } else {
289 print "$prompt [Y/n] ";
290 }
35ce5952
SR
291 $ans = <STDIN>;
292 chomp $ans;
293 if ($ans =~ /^\s*$/) {
dad98754
SR
294 if ($cancel) {
295 $ans = "c";
296 } else {
297 $ans = "y";
298 }
35ce5952
SR
299 }
300 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
dad98754
SR
301 if ($cancel) {
302 last if ($ans =~ /^c$/i);
303 print "Please answer either 'y', 'n' or 'c'.\n";
304 } else {
305 print "Please answer either 'y' or 'n'.\n";
306 }
307 }
308 if ($ans =~ /^c/i) {
309 exit;
35ce5952
SR
310 }
311 if ($ans !~ /^y$/i) {
312 return 0;
313 }
314 return 1;
315}
8d1491ba 316
dad98754
SR
317sub read_yn {
318 my ($prompt) = @_;
319
320 return read_prompt 0, $prompt;
321}
322
323sub read_ync {
324 my ($prompt) = @_;
325
326 return read_prompt 1, $prompt;
327}
328
8d1491ba
SR
329sub get_ktest_config {
330 my ($config) = @_;
815e2bd7 331 my $ans;
8d1491ba
SR
332
333 return if (defined($opt{$config}));
334
335 if (defined($config_help{$config})) {
336 print "\n";
337 print $config_help{$config};
338 }
339
340 for (;;) {
341 print "$config = ";
dbd3783b 342 if (defined($default{$config}) && length($default{$config})) {
8d1491ba
SR
343 print "\[$default{$config}\] ";
344 }
815e2bd7
SR
345 $ans = <STDIN>;
346 $ans =~ s/^\s*(.*\S)\s*$/$1/;
347 if ($ans =~ /^\s*$/) {
8d1491ba 348 if ($default{$config}) {
815e2bd7 349 $ans = $default{$config};
8d1491ba
SR
350 } else {
351 print "Your answer can not be blank\n";
352 next;
353 }
354 }
0e7a22de 355 $entered_configs{$config} = ${ans};
8d1491ba
SR
356 last;
357 }
358}
359
360sub get_ktest_configs {
361 get_ktest_config("MACHINE");
8d1491ba
SR
362 get_ktest_config("BUILD_DIR");
363 get_ktest_config("OUTPUT_DIR");
bb8474b1 364
dbd3783b
SR
365 if ($newconfig) {
366 get_ktest_config("BUILD_OPTIONS");
367 }
368
bb8474b1
SR
369 # options required for other than just building a kernel
370 if (!$buildonly) {
165708b2
SR
371 get_ktest_config("POWER_CYCLE");
372 get_ktest_config("CONSOLE");
373 }
374
375 # options required for install and more
376 if ($buildonly != 1) {
bb8474b1
SR
377 get_ktest_config("SSH_USER");
378 get_ktest_config("BUILD_TARGET");
379 get_ktest_config("TARGET_IMAGE");
bb8474b1
SR
380 }
381
8d1491ba
SR
382 get_ktest_config("LOCALVERSION");
383
bb8474b1
SR
384 return if ($buildonly);
385
8d1491ba
SR
386 my $rtype = $opt{"REBOOT_TYPE"};
387
388 if (!defined($rtype)) {
389 if (!defined($opt{"GRUB_MENU"})) {
390 get_ktest_config("REBOOT_TYPE");
391 $rtype = $entered_configs{"REBOOT_TYPE"};
392 } else {
393 $rtype = "grub";
394 }
395 }
396
397 if ($rtype eq "grub") {
398 get_ktest_config("GRUB_MENU");
399 } else {
400 get_ktest_config("REBOOT_SCRIPT");
401 }
402}
403
77d942ce 404sub process_variables {
8d735212 405 my ($value, $remove_undef) = @_;
77d942ce
SR
406 my $retval = "";
407
408 # We want to check for '\', and it is just easier
409 # to check the previous characet of '$' and not need
410 # to worry if '$' is the first character. By adding
411 # a space to $value, we can just check [^\\]\$ and
412 # it will still work.
413 $value = " $value";
414
415 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
416 my $begin = $1;
417 my $var = $2;
418 my $end = $3;
419 # append beginning of value to retval
420 $retval = "$retval$begin";
421 if (defined($variable{$var})) {
422 $retval = "$retval$variable{$var}";
8d735212
SR
423 } elsif (defined($remove_undef) && $remove_undef) {
424 # for if statements, any variable that is not defined,
425 # we simple convert to 0
426 $retval = "${retval}0";
77d942ce
SR
427 } else {
428 # put back the origin piece.
429 $retval = "$retval\$\{$var\}";
430 }
431 $value = $end;
432 }
433 $retval = "$retval$value";
434
435 # remove the space added in the beginning
436 $retval =~ s/ //;
437
438 return "$retval"
439}
440
a57419b3 441sub set_value {
3d1cc414 442 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
a57419b3 443
cad96669
SR
444 my $prvalue = process_variables($rvalue);
445
446 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
bb8474b1
SR
447 # Note if a test is something other than build, then we
448 # will need other manditory options.
cad96669 449 if ($prvalue ne "install") {
165708b2
SR
450 $buildonly = 0;
451 } else {
452 # install still limits some manditory options.
453 $buildonly = 2;
454 }
bb8474b1
SR
455 }
456
a57419b3 457 if (defined($opt{$lvalue})) {
3d1cc414
SR
458 if (!$override || defined(${$overrides}{$lvalue})) {
459 my $extra = "";
460 if ($override) {
461 $extra = "In the same override section!\n";
462 }
463 die "$name: $.: Option $lvalue defined more than once!\n$extra";
464 }
cad96669 465 ${$overrides}{$lvalue} = $prvalue;
a57419b3 466 }
21a9679f
SR
467 if ($rvalue =~ /^\s*$/) {
468 delete $opt{$lvalue};
469 } else {
cad96669 470 $opt{$lvalue} = $prvalue;
21a9679f 471 }
a57419b3
SR
472}
473
77d942ce
SR
474sub set_variable {
475 my ($lvalue, $rvalue) = @_;
476
477 if ($rvalue =~ /^\s*$/) {
478 delete $variable{$lvalue};
479 } else {
480 $rvalue = process_variables($rvalue);
481 $variable{$lvalue} = $rvalue;
482 }
483}
484
ab7a3f52
SR
485sub process_compare {
486 my ($lval, $cmp, $rval) = @_;
487
488 # remove whitespace
489
490 $lval =~ s/^\s*//;
491 $lval =~ s/\s*$//;
492
493 $rval =~ s/^\s*//;
494 $rval =~ s/\s*$//;
495
496 if ($cmp eq "==") {
497 return $lval eq $rval;
498 } elsif ($cmp eq "!=") {
499 return $lval ne $rval;
500 }
501
502 my $statement = "$lval $cmp $rval";
503 my $ret = eval $statement;
504
505 # $@ stores error of eval
506 if ($@) {
507 return -1;
508 }
509
510 return $ret;
511}
512
9900b5dc
SR
513sub value_defined {
514 my ($val) = @_;
515
516 return defined($variable{$2}) ||
517 defined($opt{$2});
518}
519
8d735212
SR
520my $d = 0;
521sub process_expression {
522 my ($name, $val) = @_;
523
524 my $c = $d++;
525
526 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
527 my $express = $1;
528
529 if (process_expression($name, $express)) {
530 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
531 } else {
532 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
533 }
534 }
535
536 $d--;
537 my $OR = "\\|\\|";
538 my $AND = "\\&\\&";
45d73a5d 539
8d735212
SR
540 while ($val =~ s/^(.*?)($OR|$AND)//) {
541 my $express = $1;
542 my $op = $2;
543
544 if (process_expression($name, $express)) {
545 if ($op eq "||") {
546 return 1;
547 }
548 } else {
549 if ($op eq "&&") {
550 return 0;
551 }
552 }
553 }
45d73a5d 554
ab7a3f52
SR
555 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
556 my $ret = process_compare($1, $2, $3);
557 if ($ret < 0) {
558 die "$name: $.: Unable to process comparison\n";
559 }
560 return $ret;
561 }
562
9900b5dc
SR
563 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
564 if (defined $1) {
565 return !value_defined($2);
566 } else {
567 return value_defined($2);
568 }
569 }
570
45d73a5d
SR
571 if ($val =~ /^\s*0\s*$/) {
572 return 0;
573 } elsif ($val =~ /^\s*\d+\s*$/) {
574 return 1;
575 }
576
9900b5dc 577 die ("$name: $.: Undefined content $val in if statement\n");
8d735212
SR
578}
579
580sub process_if {
581 my ($name, $value) = @_;
582
583 # Convert variables and replace undefined ones with 0
584 my $val = process_variables($value, 1);
585 my $ret = process_expression $name, $val;
586
587 return $ret;
45d73a5d
SR
588}
589
2ed3b161
SR
590sub __read_config {
591 my ($config, $current_test_num) = @_;
2545eb61 592
2ed3b161
SR
593 my $in;
594 open($in, $config) || die "can't read file $config";
2545eb61 595
a57419b3
SR
596 my $name = $config;
597 $name =~ s,.*/(.*),$1,;
598
2ed3b161 599 my $test_num = $$current_test_num;
a57419b3
SR
600 my $default = 1;
601 my $repeat = 1;
602 my $num_tests_set = 0;
603 my $skip = 0;
604 my $rest;
a9f84424 605 my $line;
0df213ca 606 my $test_case = 0;
45d73a5d
SR
607 my $if = 0;
608 my $if_set = 0;
3d1cc414
SR
609 my $override = 0;
610
611 my %overrides;
a57419b3 612
2ed3b161 613 while (<$in>) {
2545eb61
SR
614
615 # ignore blank lines and comments
616 next if (/^\s*$/ || /\s*\#/);
617
0050b6bb 618 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
a57419b3 619
0050b6bb
SR
620 my $type = $1;
621 $rest = $2;
a9f84424 622 $line = $2;
a57419b3 623
0050b6bb
SR
624 my $old_test_num;
625 my $old_repeat;
3d1cc414 626 $override = 0;
0050b6bb
SR
627
628 if ($type eq "TEST_START") {
629
630 if ($num_tests_set) {
631 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
632 }
a57419b3 633
0050b6bb
SR
634 $old_test_num = $test_num;
635 $old_repeat = $repeat;
a57419b3 636
0050b6bb
SR
637 $test_num += $repeat;
638 $default = 0;
639 $repeat = 1;
640 } else {
641 $default = 1;
642 }
a57419b3 643
a9f84424
SR
644 # If SKIP is anywhere in the line, the command will be skipped
645 if ($rest =~ s/\s+SKIP\b//) {
a57419b3
SR
646 $skip = 1;
647 } else {
0df213ca 648 $test_case = 1;
a57419b3
SR
649 $skip = 0;
650 }
651
a9f84424
SR
652 if ($rest =~ s/\sELSE\b//) {
653 if (!$if) {
654 die "$name: $.: ELSE found with out matching IF section\n$_";
655 }
656 $if = 0;
657
658 if ($if_set) {
659 $skip = 1;
660 } else {
661 $skip = 0;
3d1cc414 662 }
a57419b3
SR
663 }
664
a9f84424 665 if ($rest =~ s/\sIF\s+(.*)//) {
45d73a5d
SR
666 if (process_if($name, $1)) {
667 $if_set = 1;
668 } else {
669 $skip = 1;
670 }
671 $if = 1;
672 } else {
673 $if = 0;
a9f84424
SR
674 $if_set = 0;
675 }
676
677 if (!$skip) {
678 if ($type eq "TEST_START") {
679 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
680 $repeat = $1;
681 $repeat_tests{"$test_num"} = $repeat;
682 }
683 } elsif ($rest =~ s/\sOVERRIDE\b//) {
684 # DEFAULT only
685 $override = 1;
686 # Clear previous overrides
687 %overrides = ();
688 }
a57419b3
SR
689 }
690
a9f84424 691 if (!$skip && $rest !~ /^\s*$/) {
0050b6bb 692 die "$name: $.: Gargbage found after $type\n$_";
a57419b3
SR
693 }
694
0050b6bb 695 if ($skip && $type eq "TEST_START") {
a57419b3 696 $test_num = $old_test_num;
e48c5293 697 $repeat = $old_repeat;
a57419b3
SR
698 }
699
ab7a3f52 700 } elsif (/^\s*ELSE\b(.*)$/) {
45d73a5d
SR
701 if (!$if) {
702 die "$name: $.: ELSE found with out matching IF section\n$_";
703 }
704 $rest = $1;
705 if ($if_set) {
706 $skip = 1;
ab7a3f52 707 $rest = "";
45d73a5d
SR
708 } else {
709 $skip = 0;
710
ab7a3f52 711 if ($rest =~ /\sIF\s+(.*)/) {
45d73a5d
SR
712 # May be a ELSE IF section.
713 if (!process_if($name, $1)) {
714 $skip = 1;
715 }
ab7a3f52 716 $rest = "";
45d73a5d
SR
717 } else {
718 $if = 0;
719 }
720 }
721
ab7a3f52
SR
722 if ($rest !~ /^\s*$/) {
723 die "$name: $.: Gargbage found after DEFAULTS\n$_";
724 }
725
2ed3b161
SR
726 } elsif (/^\s*INCLUDE\s+(\S+)/) {
727
728 next if ($skip);
729
730 if (!$default) {
731 die "$name: $.: INCLUDE can only be done in default sections\n$_";
732 }
733
734 my $file = process_variables($1);
735
736 if ($file !~ m,^/,) {
737 # check the path of the config file first
738 if ($config =~ m,(.*)/,) {
739 if (-f "$1/$file") {
740 $file = "$1/$file";
741 }
742 }
743 }
744
745 if ( ! -r $file ) {
746 die "$name: $.: Can't read file $file\n$_";
747 }
748
749 if (__read_config($file, \$test_num)) {
750 $test_case = 1;
751 }
752
a57419b3
SR
753 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
754
755 next if ($skip);
756
2545eb61
SR
757 my $lvalue = $1;
758 my $rvalue = $2;
759
a57419b3
SR
760 if (!$default &&
761 ($lvalue eq "NUM_TESTS" ||
762 $lvalue eq "LOG_FILE" ||
763 $lvalue eq "CLEAR_LOG")) {
764 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
765 }
766
767 if ($lvalue eq "NUM_TESTS") {
768 if ($test_num) {
769 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
770 }
771 if (!$default) {
772 die "$name: $.: NUM_TESTS must be set in default section\n";
773 }
774 $num_tests_set = 1;
775 }
776
777 if ($default || $lvalue =~ /\[\d+\]$/) {
3d1cc414 778 set_value($lvalue, $rvalue, $override, \%overrides, $name);
a57419b3
SR
779 } else {
780 my $val = "$lvalue\[$test_num\]";
3d1cc414 781 set_value($val, $rvalue, $override, \%overrides, $name);
a57419b3
SR
782
783 if ($repeat > 1) {
784 $repeats{$val} = $repeat;
785 }
a75fecec 786 }
77d942ce
SR
787 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
788 next if ($skip);
789
790 my $lvalue = $1;
791 my $rvalue = $2;
792
793 # process config variables.
794 # Config variables are only active while reading the
795 # config and can be defined anywhere. They also ignore
796 # TEST_START and DEFAULTS, but are skipped if they are in
797 # on of these sections that have SKIP defined.
798 # The save variable can be
799 # defined multiple times and the new one simply overrides
800 # the prevous one.
801 set_variable($lvalue, $rvalue);
802
a57419b3
SR
803 } else {
804 die "$name: $.: Garbage found in config\n$_";
2545eb61
SR
805 }
806 }
807
a57419b3
SR
808 if ($test_num) {
809 $test_num += $repeat - 1;
810 $opt{"NUM_TESTS"} = $test_num;
811 }
812
2ed3b161
SR
813 close($in);
814
815 $$current_test_num = $test_num;
816
817 return $test_case;
818}
819
c4261d0f
SR
820sub get_test_case {
821 print "What test case would you like to run?\n";
822 print " (build, install or boot)\n";
823 print " Other tests are available but require editing the config file\n";
824 my $ans = <STDIN>;
825 chomp $ans;
826 $default{"TEST_TYPE"} = $ans;
827}
828
2ed3b161
SR
829sub read_config {
830 my ($config) = @_;
831
832 my $test_case;
833 my $test_num = 0;
834
835 $test_case = __read_config $config, \$test_num;
836
8d1491ba
SR
837 # make sure we have all mandatory configs
838 get_ktest_configs;
839
0df213ca
SR
840 # was a test specified?
841 if (!$test_case) {
842 print "No test case specified.\n";
c4261d0f 843 get_test_case;
0df213ca
SR
844 }
845
a75fecec
SR
846 # set any defaults
847
848 foreach my $default (keys %default) {
849 if (!defined($opt{$default})) {
850 $opt{$default} = $default{$default};
851 }
852 }
2545eb61
SR
853}
854
23715c3c
SR
855sub __eval_option {
856 my ($option, $i) = @_;
857
858 # Add space to evaluate the character before $
859 $option = " $option";
860 my $retval = "";
f9dfb65b
RV
861 my $repeated = 0;
862 my $parent = 0;
863
864 foreach my $test (keys %repeat_tests) {
865 if ($i >= $test &&
866 $i < $test + $repeat_tests{$test}) {
867
868 $repeated = 1;
869 $parent = $test;
870 last;
871 }
872 }
23715c3c
SR
873
874 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
875 my $start = $1;
876 my $var = $2;
877 my $end = $3;
878
879 # Append beginning of line
880 $retval = "$retval$start";
881
882 # If the iteration option OPT[$i] exists, then use that.
883 # otherwise see if the default OPT (without [$i]) exists.
884
885 my $o = "$var\[$i\]";
f9dfb65b 886 my $parento = "$var\[$parent\]";
23715c3c
SR
887
888 if (defined($opt{$o})) {
889 $o = $opt{$o};
890 $retval = "$retval$o";
f9dfb65b
RV
891 } elsif ($repeated && defined($opt{$parento})) {
892 $o = $opt{$parento};
893 $retval = "$retval$o";
23715c3c
SR
894 } elsif (defined($opt{$var})) {
895 $o = $opt{$var};
896 $retval = "$retval$o";
897 } else {
898 $retval = "$retval\$\{$var\}";
899 }
900
901 $option = $end;
902 }
903
904 $retval = "$retval$option";
905
906 $retval =~ s/^ //;
907
908 return $retval;
909}
910
911sub eval_option {
912 my ($option, $i) = @_;
913
914 my $prev = "";
915
916 # Since an option can evaluate to another option,
917 # keep iterating until we do not evaluate any more
918 # options.
919 my $r = 0;
920 while ($prev ne $option) {
921 # Check for recursive evaluations.
922 # 100 deep should be more than enough.
923 if ($r++ > 100) {
924 die "Over 100 evaluations accurred with $option\n" .
925 "Check for recursive variables\n";
926 }
927 $prev = $option;
928 $option = __eval_option($option, $i);
929 }
930
931 return $option;
932}
933
d1e2f22a 934sub _logit {
2545eb61
SR
935 if (defined($opt{"LOG_FILE"})) {
936 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
937 print OUT @_;
938 close(OUT);
939 }
940}
941
d1e2f22a
SR
942sub logit {
943 if (defined($opt{"LOG_FILE"})) {
944 _logit @_;
945 } else {
946 print @_;
947 }
948}
949
5f9b6ced
SR
950sub doprint {
951 print @_;
d1e2f22a 952 _logit @_;
5f9b6ced
SR
953}
954
7faafbd6 955sub run_command;
2728be41
AJ
956sub start_monitor;
957sub end_monitor;
958sub wait_for_monitor;
7faafbd6
SR
959
960sub reboot {
2728be41
AJ
961 my ($time) = @_;
962
2b803365
SR
963 if (defined($time)) {
964 start_monitor;
965 # flush out current monitor
966 # May contain the reboot success line
967 wait_for_monitor 1;
968 }
969
7faafbd6 970 # try to reboot normally
e48c5293 971 if (run_command $reboot) {
576f627c
SR
972 if (defined($powercycle_after_reboot)) {
973 sleep $powercycle_after_reboot;
974 run_command "$power_cycle";
975 }
976 } else {
7faafbd6 977 # nope? power cycle it.
a75fecec 978 run_command "$power_cycle";
7faafbd6 979 }
2728be41
AJ
980
981 if (defined($time)) {
2b803365 982 wait_for_monitor($time, $reboot_success_line);
2728be41
AJ
983 end_monitor;
984 }
7faafbd6
SR
985}
986
bc7c5803
SR
987sub reboot_to_good {
988 my ($time) = @_;
989
990 if (defined($switch_to_good)) {
991 run_command $switch_to_good;
992 return;
993 }
994
995 reboot $time;
996}
997
576f627c
SR
998sub do_not_reboot {
999 my $i = $iteration;
1000
4ab1cce5 1001 return $test_type eq "build" || $no_reboot ||
576f627c
SR
1002 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1003 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1004}
1005
5c42fc5b 1006sub dodie {
5a391fbf 1007 doprint "CRITICAL FAILURE... ", @_, "\n";
5c42fc5b 1008
576f627c
SR
1009 my $i = $iteration;
1010
1011 if ($reboot_on_error && !do_not_reboot) {
1012
75c3fda7 1013 doprint "REBOOTING\n";
bc7c5803 1014 reboot_to_good;
75c3fda7 1015
a75fecec 1016 } elsif ($poweroff_on_error && defined($power_off)) {
5c42fc5b 1017 doprint "POWERING OFF\n";
a75fecec 1018 `$power_off`;
5c42fc5b 1019 }
75c3fda7 1020
f80802cb
SR
1021 if (defined($opt{"LOG_FILE"})) {
1022 print " See $opt{LOG_FILE} for more info.\n";
1023 }
1024
576f627c 1025 die @_, "\n";
5c42fc5b
SR
1026}
1027
7faafbd6
SR
1028sub open_console {
1029 my ($fp) = @_;
1030
1031 my $flags;
1032
a75fecec
SR
1033 my $pid = open($fp, "$console|") or
1034 dodie "Can't open console $console";
7faafbd6
SR
1035
1036 $flags = fcntl($fp, F_GETFL, 0) or
576f627c 1037 dodie "Can't get flags for the socket: $!";
7faafbd6 1038 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
576f627c 1039 dodie "Can't set flags for the socket: $!";
7faafbd6
SR
1040
1041 return $pid;
1042}
1043
1044sub close_console {
1045 my ($fp, $pid) = @_;
1046
1047 doprint "kill child process $pid\n";
1048 kill 2, $pid;
1049
1050 print "closing!\n";
1051 close($fp);
1052}
1053
1054sub start_monitor {
1055 if ($monitor_cnt++) {
1056 return;
1057 }
1058 $monitor_fp = \*MONFD;
1059 $monitor_pid = open_console $monitor_fp;
a75fecec
SR
1060
1061 return;
1062
1063 open(MONFD, "Stop perl from warning about single use of MONFD");
7faafbd6
SR
1064}
1065
1066sub end_monitor {
1067 if (--$monitor_cnt) {
1068 return;
1069 }
1070 close_console($monitor_fp, $monitor_pid);
1071}
1072
1073sub wait_for_monitor {
2b803365
SR
1074 my ($time, $stop) = @_;
1075 my $full_line = "";
7faafbd6 1076 my $line;
2b803365 1077 my $booted = 0;
7faafbd6 1078
a75fecec 1079 doprint "** Wait for monitor to settle down **\n";
7faafbd6
SR
1080
1081 # read the monitor and wait for the system to calm down
2b803365 1082 while (!$booted) {
7faafbd6 1083 $line = wait_for_input($monitor_fp, $time);
2b803365
SR
1084 last if (!defined($line));
1085 print "$line";
1086 $full_line .= $line;
1087
1088 if (defined($stop) && $full_line =~ /$stop/) {
1089 doprint "wait for monitor detected $stop\n";
1090 $booted = 1;
1091 }
1092
1093 if ($line =~ /\n/) {
1094 $full_line = "";
1095 }
1096 }
a75fecec 1097 print "** Monitor flushed **\n";
7faafbd6
SR
1098}
1099
de5b6e3b
RV
1100sub save_logs {
1101 my ($result, $basedir) = @_;
1102 my @t = localtime;
1103 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1104 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1105
1106 my $type = $build_type;
1107 if ($type =~ /useconfig/) {
1108 $type = "useconfig";
1109 }
1110
1111 my $dir = "$machine-$test_type-$type-$result-$date";
1112
1113 $dir = "$basedir/$dir";
1114
1115 if (!-d $dir) {
1116 mkpath($dir) or
1117 die "can't create $dir";
1118 }
1119
1120 my %files = (
1121 "config" => $output_config,
1122 "buildlog" => $buildlog,
1123 "dmesg" => $dmesg,
1124 "testlog" => $testlog,
1125 );
1126
1127 while (my ($name, $source) = each(%files)) {
1128 if (-f "$source") {
1129 cp "$source", "$dir/$name" or
1130 die "failed to copy $source";
1131 }
1132 }
1133
1134 doprint "*** Saved info to $dir ***\n";
1135}
1136
2b7d9b21
SR
1137sub fail {
1138
a75fecec 1139 if ($die_on_failure) {
2b7d9b21
SR
1140 dodie @_;
1141 }
1142
a75fecec 1143 doprint "FAILED\n";
7faafbd6 1144
576f627c
SR
1145 my $i = $iteration;
1146
a75fecec 1147 # no need to reboot for just building.
576f627c 1148 if (!do_not_reboot) {
a75fecec 1149 doprint "REBOOTING\n";
bc7c5803 1150 reboot_to_good $sleep_time;
a75fecec 1151 }
7faafbd6 1152
9064af52
SR
1153 my $name = "";
1154
1155 if (defined($test_name)) {
1156 $name = " ($test_name)";
1157 }
1158
576f627c
SR
1159 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1160 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
9064af52 1161 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
576f627c
SR
1162 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1163 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
a75fecec 1164
de5b6e3b
RV
1165 if (defined($store_failures)) {
1166 save_logs "fail", $store_failures;
1167 }
7faafbd6 1168
2b7d9b21
SR
1169 return 1;
1170}
1171
2545eb61
SR
1172sub run_command {
1173 my ($command) = @_;
d6ce2a0b
SR
1174 my $dolog = 0;
1175 my $dord = 0;
1176 my $pid;
1177
e48c5293
SR
1178 $command =~ s/\$SSH_USER/$ssh_user/g;
1179 $command =~ s/\$MACHINE/$machine/g;
1180
d6ce2a0b
SR
1181 doprint("$command ... ");
1182
1183 $pid = open(CMD, "$command 2>&1 |") or
2b7d9b21 1184 (fail "unable to exec $command" and return 0);
2545eb61
SR
1185
1186 if (defined($opt{"LOG_FILE"})) {
d6ce2a0b
SR
1187 open(LOG, ">>$opt{LOG_FILE}") or
1188 dodie "failed to write to log";
1189 $dolog = 1;
6c5ee0be
SR
1190 }
1191
1192 if (defined($redirect)) {
d6ce2a0b
SR
1193 open (RD, ">$redirect") or
1194 dodie "failed to write to redirect $redirect";
1195 $dord = 1;
2545eb61
SR
1196 }
1197
d6ce2a0b
SR
1198 while (<CMD>) {
1199 print LOG if ($dolog);
1200 print RD if ($dord);
1201 }
2545eb61 1202
d6ce2a0b 1203 waitpid($pid, 0);
2545eb61
SR
1204 my $failed = $?;
1205
d6ce2a0b
SR
1206 close(CMD);
1207 close(LOG) if ($dolog);
1208 close(RD) if ($dord);
1209
2545eb61
SR
1210 if ($failed) {
1211 doprint "FAILED!\n";
1212 } else {
1213 doprint "SUCCESS\n";
1214 }
1215
5f9b6ced
SR
1216 return !$failed;
1217}
1218
e48c5293
SR
1219sub run_ssh {
1220 my ($cmd) = @_;
1221 my $cp_exec = $ssh_exec;
1222
1223 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1224 return run_command "$cp_exec";
1225}
1226
1227sub run_scp {
1228 my ($src, $dst) = @_;
1229 my $cp_scp = $scp_to_target;
1230
1231 $cp_scp =~ s/\$SRC_FILE/$src/g;
1232 $cp_scp =~ s/\$DST_FILE/$dst/g;
1233
1234 return run_command "$cp_scp";
1235}
1236
5f9b6ced
SR
1237sub get_grub_index {
1238
a75fecec
SR
1239 if ($reboot_type ne "grub") {
1240 return;
1241 }
5a391fbf 1242 return if (defined($grub_number));
5f9b6ced
SR
1243
1244 doprint "Find grub menu ... ";
1245 $grub_number = -1;
e48c5293
SR
1246
1247 my $ssh_grub = $ssh_exec;
1248 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1249
1250 open(IN, "$ssh_grub |")
5f9b6ced 1251 or die "unable to get menu.lst";
e48c5293 1252
eaa1fe25
SR
1253 my $found = 0;
1254
5f9b6ced 1255 while (<IN>) {
a75fecec 1256 if (/^\s*title\s+$grub_menu\s*$/) {
5f9b6ced 1257 $grub_number++;
eaa1fe25 1258 $found = 1;
5f9b6ced
SR
1259 last;
1260 } elsif (/^\s*title\s/) {
1261 $grub_number++;
1262 }
1263 }
1264 close(IN);
1265
a75fecec 1266 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
eaa1fe25 1267 if (!$found);
5f9b6ced 1268 doprint "$grub_number\n";
2545eb61
SR
1269}
1270
2545eb61
SR
1271sub wait_for_input
1272{
1273 my ($fp, $time) = @_;
1274 my $rin;
1275 my $ready;
1276 my $line;
1277 my $ch;
1278
1279 if (!defined($time)) {
1280 $time = $timeout;
1281 }
1282
1283 $rin = '';
1284 vec($rin, fileno($fp), 1) = 1;
1285 $ready = select($rin, undef, undef, $time);
1286
1287 $line = "";
1288
1289 # try to read one char at a time
1290 while (sysread $fp, $ch, 1) {
1291 $line .= $ch;
1292 last if ($ch eq "\n");
1293 }
1294
1295 if (!length($line)) {
1296 return undef;
1297 }
1298
1299 return $line;
1300}
1301
75c3fda7 1302sub reboot_to {
bc7c5803
SR
1303 if (defined($switch_to_test)) {
1304 run_command $switch_to_test;
1305 }
1306
a75fecec 1307 if ($reboot_type eq "grub") {
c54367f9
SR
1308 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1309 reboot;
a75fecec
SR
1310 return;
1311 }
1312
1313 run_command "$reboot_script";
2545eb61
SR
1314}
1315
a57419b3
SR
1316sub get_sha1 {
1317 my ($commit) = @_;
1318
1319 doprint "git rev-list --max-count=1 $commit ... ";
1320 my $sha1 = `git rev-list --max-count=1 $commit`;
1321 my $ret = $?;
1322
1323 logit $sha1;
1324
1325 if ($ret) {
1326 doprint "FAILED\n";
1327 dodie "Failed to get git $commit";
1328 }
1329
1330 print "SUCCESS\n";
1331
1332 chomp $sha1;
1333
1334 return $sha1;
1335}
1336
5a391fbf 1337sub monitor {
2545eb61
SR
1338 my $booted = 0;
1339 my $bug = 0;
5c42fc5b 1340 my $skip_call_trace = 0;
2b7d9b21 1341 my $loops;
2545eb61 1342
7faafbd6 1343 wait_for_monitor 5;
2545eb61
SR
1344
1345 my $line;
1346 my $full_line = "";
1347
7faafbd6
SR
1348 open(DMESG, "> $dmesg") or
1349 die "unable to write to $dmesg";
2545eb61 1350
75c3fda7 1351 reboot_to;
2545eb61 1352
1c8a617a
SR
1353 my $success_start;
1354 my $failure_start;
2d01b26a
SR
1355 my $monitor_start = time;
1356 my $done = 0;
f1a5b962 1357 my $version_found = 0;
1c8a617a 1358
2d01b26a 1359 while (!$done) {
2545eb61 1360
ecaf8e52
SR
1361 if ($bug && defined($stop_after_failure) &&
1362 $stop_after_failure >= 0) {
1363 my $time = $stop_after_failure - (time - $failure_start);
1364 $line = wait_for_input($monitor_fp, $time);
1365 if (!defined($line)) {
1366 doprint "bug timed out after $booted_timeout seconds\n";
1367 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1368 last;
1369 }
1370 } elsif ($booted) {
a75fecec 1371 $line = wait_for_input($monitor_fp, $booted_timeout);
cd4f1d53
SR
1372 if (!defined($line)) {
1373 my $s = $booted_timeout == 1 ? "" : "s";
1374 doprint "Successful boot found: break after $booted_timeout second$s\n";
1375 last;
1376 }
2b7d9b21 1377 } else {
7faafbd6 1378 $line = wait_for_input($monitor_fp);
cd4f1d53
SR
1379 if (!defined($line)) {
1380 my $s = $timeout == 1 ? "" : "s";
1381 doprint "Timed out after $timeout second$s\n";
1382 last;
1383 }
2b7d9b21 1384 }
2545eb61 1385
2545eb61 1386 doprint $line;
7faafbd6 1387 print DMESG $line;
2545eb61
SR
1388
1389 # we are not guaranteed to get a full line
1390 $full_line .= $line;
1391
a75fecec 1392 if ($full_line =~ /$success_line/) {
2545eb61 1393 $booted = 1;
1c8a617a
SR
1394 $success_start = time;
1395 }
1396
1397 if ($booted && defined($stop_after_success) &&
1398 $stop_after_success >= 0) {
1399 my $now = time;
1400 if ($now - $success_start >= $stop_after_success) {
1401 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1402 last;
1403 }
2545eb61
SR
1404 }
1405
5c42fc5b
SR
1406 if ($full_line =~ /\[ backtrace testing \]/) {
1407 $skip_call_trace = 1;
1408 }
1409
2545eb61 1410 if ($full_line =~ /call trace:/i) {
4651920e 1411 if (!$bug && !$skip_call_trace) {
1c8a617a
SR
1412 $bug = 1;
1413 $failure_start = time;
1414 }
1415 }
1416
1417 if ($bug && defined($stop_after_failure) &&
1418 $stop_after_failure >= 0) {
1419 my $now = time;
1420 if ($now - $failure_start >= $stop_after_failure) {
1421 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1422 last;
1423 }
5c42fc5b
SR
1424 }
1425
1426 if ($full_line =~ /\[ end of backtrace testing \]/) {
1427 $skip_call_trace = 0;
1428 }
1429
1430 if ($full_line =~ /Kernel panic -/) {
10abf118 1431 $failure_start = time;
2545eb61
SR
1432 $bug = 1;
1433 }
1434
f1a5b962
SR
1435 # Detect triple faults by testing the banner
1436 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1437 if ($1 eq $version) {
1438 $version_found = 1;
1439 } elsif ($version_found && $detect_triplefault) {
1440 # We already booted into the kernel we are testing,
1441 # but now we booted into another kernel?
1442 # Consider this a triple fault.
1443 doprint "Aleady booted in Linux kernel $version, but now\n";
1444 doprint "we booted into Linux kernel $1.\n";
1445 doprint "Assuming that this is a triple fault.\n";
1446 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1447 last;
1448 }
1449 }
1450
2545eb61
SR
1451 if ($line =~ /\n/) {
1452 $full_line = "";
1453 }
2d01b26a
SR
1454
1455 if ($stop_test_after > 0 && !$booted && !$bug) {
1456 if (time - $monitor_start > $stop_test_after) {
4d62bf51 1457 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
2d01b26a
SR
1458 $done = 1;
1459 }
1460 }
2545eb61
SR
1461 }
1462
7faafbd6 1463 close(DMESG);
2545eb61 1464
a75fecec 1465 if ($bug) {
2b7d9b21 1466 return 0 if ($in_bisect);
576f627c 1467 fail "failed - got a bug report" and return 0;
2545eb61
SR
1468 }
1469
a75fecec 1470 if (!$booted) {
2b7d9b21 1471 return 0 if ($in_bisect);
576f627c 1472 fail "failed - never got a boot prompt." and return 0;
2545eb61 1473 }
5f9b6ced 1474
2b7d9b21 1475 return 1;
2545eb61
SR
1476}
1477
2b29b2f8
SR
1478sub eval_kernel_version {
1479 my ($option) = @_;
1480
1481 $option =~ s/\$KERNEL_VERSION/$version/g;
1482
1483 return $option;
1484}
1485
db05cfef
SR
1486sub do_post_install {
1487
1488 return if (!defined($post_install));
1489
2b29b2f8 1490 my $cp_post_install = eval_kernel_version $post_install;
db05cfef
SR
1491 run_command "$cp_post_install" or
1492 dodie "Failed to run post install";
1493}
1494
2545eb61
SR
1495sub install {
1496
e0a8742e
SR
1497 return if ($no_install);
1498
2b29b2f8
SR
1499 my $cp_target = eval_kernel_version $target_image;
1500
1501 run_scp "$outputdir/$build_target", "$cp_target" or
5c42fc5b 1502 dodie "failed to copy image";
2545eb61 1503
5f9b6ced 1504 my $install_mods = 0;
2545eb61 1505
5f9b6ced
SR
1506 # should we process modules?
1507 $install_mods = 0;
51ad1dd1 1508 open(IN, "$output_config") or dodie("Can't read config file");
5f9b6ced
SR
1509 while (<IN>) {
1510 if (/CONFIG_MODULES(=y)?/) {
1511 $install_mods = 1 if (defined($1));
1512 last;
5c42fc5b 1513 }
5f9b6ced
SR
1514 }
1515 close(IN);
5c42fc5b 1516
5f9b6ced 1517 if (!$install_mods) {
db05cfef 1518 do_post_install;
5f9b6ced
SR
1519 doprint "No modules needed\n";
1520 return;
1521 }
2545eb61 1522
a75fecec 1523 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
5f9b6ced 1524 dodie "Failed to install modules";
5c42fc5b 1525
5f9b6ced 1526 my $modlib = "/lib/modules/$version";
a57419b3 1527 my $modtar = "ktest-mods.tar.bz2";
5c42fc5b 1528
e48c5293 1529 run_ssh "rm -rf $modlib" or
5f9b6ced 1530 dodie "failed to remove old mods: $modlib";
5c42fc5b 1531
5f9b6ced 1532 # would be nice if scp -r did not follow symbolic links
a75fecec 1533 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
5f9b6ced
SR
1534 dodie "making tarball";
1535
e48c5293 1536 run_scp "$tmpdir/$modtar", "/tmp" or
5f9b6ced
SR
1537 dodie "failed to copy modules";
1538
a75fecec 1539 unlink "$tmpdir/$modtar";
5f9b6ced 1540
e7b13441 1541 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
5f9b6ced 1542 dodie "failed to tar modules";
2545eb61 1543
e48c5293 1544 run_ssh "rm -f /tmp/$modtar";
8b37ca8c 1545
db05cfef 1546 do_post_install;
2545eb61
SR
1547}
1548
ddf607e5
SR
1549sub get_version {
1550 # get the release name
1551 doprint "$make kernelrelease ... ";
1552 $version = `$make kernelrelease | tail -1`;
1553 chomp($version);
1554 doprint "$version\n";
1555}
1556
1557sub start_monitor_and_boot {
9f7424cc
SR
1558 # Make sure the stable kernel has finished booting
1559 start_monitor;
1560 wait_for_monitor 5;
1561 end_monitor;
1562
ddf607e5
SR
1563 get_grub_index;
1564 get_version;
1565 install;
1566
1567 start_monitor;
1568 return monitor;
1569}
1570
6c5ee0be
SR
1571sub check_buildlog {
1572 my ($patch) = @_;
1573
6c5ee0be
SR
1574 my @files = `git show $patch | diffstat -l`;
1575
1576 open(IN, "git show $patch |") or
1577 dodie "failed to show $patch";
1578 while (<IN>) {
1579 if (m,^--- a/(.*),) {
1580 chomp $1;
1581 $files[$#files] = $1;
1582 }
1583 }
1584 close(IN);
1585
1586 open(IN, $buildlog) or dodie "Can't open $buildlog";
1587 while (<IN>) {
1588 if (/^\s*(.*?):.*(warning|error)/) {
1589 my $err = $1;
1590 foreach my $file (@files) {
a75fecec 1591 my $fullpath = "$builddir/$file";
6c5ee0be 1592 if ($file eq $err || $fullpath eq $err) {
2b7d9b21 1593 fail "$file built with warnings" and return 0;
6c5ee0be
SR
1594 }
1595 }
1596 }
1597 }
1598 close(IN);
2b7d9b21
SR
1599
1600 return 1;
6c5ee0be
SR
1601}
1602
fcb3f16a
SR
1603sub apply_min_config {
1604 my $outconfig = "$output_config.new";
1605
1606 # Read the config file and remove anything that
1607 # is in the force_config hash (from minconfig and others)
1608 # then add the force config back.
1609
1610 doprint "Applying minimum configurations into $output_config.new\n";
1611
1612 open (OUT, ">$outconfig") or
1613 dodie "Can't create $outconfig";
1614
1615 if (-f $output_config) {
1616 open (IN, $output_config) or
1617 dodie "Failed to open $output_config";
1618 while (<IN>) {
1619 if (/^(# )?(CONFIG_[^\s=]*)/) {
1620 next if (defined($force_config{$2}));
1621 }
1622 print OUT;
1623 }
1624 close IN;
1625 }
1626 foreach my $config (keys %force_config) {
1627 print OUT "$force_config{$config}\n";
1628 }
1629 close OUT;
1630
1631 run_command "mv $outconfig $output_config";
1632}
1633
612b9e9b 1634sub make_oldconfig {
612b9e9b 1635
4c4ab120
SR
1636 my @force_list = keys %force_config;
1637
1638 if ($#force_list >= 0) {
1639 apply_min_config;
1640 }
fcb3f16a
SR
1641
1642 if (!run_command "$make oldnoconfig") {
612b9e9b
SR
1643 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1644 # try a yes '' | oldconfig
1645 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
fcb3f16a 1646 run_command "yes '' | $make oldconfig" or
612b9e9b
SR
1647 dodie "failed make config oldconfig";
1648 }
1649}
1650
fcb3f16a
SR
1651# read a config file and use this to force new configs.
1652sub load_force_config {
1653 my ($config) = @_;
1654
1655 open(IN, $config) or
1656 dodie "failed to read $config";
1657 while (<IN>) {
1658 chomp;
1659 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1660 $force_config{$1} = $_;
1661 } elsif (/^# (CONFIG_\S*) is not set/) {
1662 $force_config{$1} = $_;
1663 }
1664 }
1665 close IN;
1666}
1667
2545eb61
SR
1668sub build {
1669 my ($type) = @_;
5c42fc5b 1670
7faafbd6
SR
1671 unlink $buildlog;
1672
4ab1cce5
SR
1673 # Failed builds should not reboot the target
1674 my $save_no_reboot = $no_reboot;
1675 $no_reboot = 1;
1676
0bd6c1a3
SR
1677 if (defined($pre_build)) {
1678 my $ret = run_command $pre_build;
1679 if (!$ret && defined($pre_build_die) &&
1680 $pre_build_die) {
1681 dodie "failed to pre_build\n";
1682 }
1683 }
1684
75c3fda7 1685 if ($type =~ /^useconfig:(.*)/) {
51ad1dd1 1686 run_command "cp $1 $output_config" or
75c3fda7 1687 dodie "could not copy $1 to .config";
5f9b6ced 1688
75c3fda7
SR
1689 $type = "oldconfig";
1690 }
1691
5c42fc5b
SR
1692 # old config can ask questions
1693 if ($type eq "oldconfig") {
9386c6ab 1694 $type = "oldnoconfig";
75c3fda7
SR
1695
1696 # allow for empty configs
51ad1dd1 1697 run_command "touch $output_config";
75c3fda7 1698
13488231
AJ
1699 if (!$noclean) {
1700 run_command "mv $output_config $outputdir/config_temp" or
1701 dodie "moving .config";
2545eb61 1702
13488231 1703 run_command "$make mrproper" or dodie "make mrproper";
2545eb61 1704
13488231
AJ
1705 run_command "mv $outputdir/config_temp $output_config" or
1706 dodie "moving config_temp";
1707 }
5c42fc5b
SR
1708
1709 } elsif (!$noclean) {
51ad1dd1 1710 unlink "$output_config";
5f9b6ced 1711 run_command "$make mrproper" or
5c42fc5b 1712 dodie "make mrproper";
5c42fc5b 1713 }
2545eb61
SR
1714
1715 # add something to distinguish this build
a75fecec
SR
1716 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1717 print OUT "$localversion\n";
2545eb61
SR
1718 close(OUT);
1719
5f9b6ced 1720 if (defined($minconfig)) {
fcb3f16a 1721 load_force_config($minconfig);
2545eb61
SR
1722 }
1723
fcb3f16a
SR
1724 if ($type ne "oldnoconfig") {
1725 run_command "$make $type" or
612b9e9b
SR
1726 dodie "failed make config";
1727 }
fcb3f16a
SR
1728 # Run old config regardless, to enforce min configurations
1729 make_oldconfig;
2545eb61 1730
a75fecec 1731 $redirect = "$buildlog";
0bd6c1a3
SR
1732 my $build_ret = run_command "$make $build_options";
1733 undef $redirect;
1734
1735 if (defined($post_build)) {
1736 my $ret = run_command $post_build;
1737 if (!$ret && defined($post_build_die) &&
1738 $post_build_die) {
1739 dodie "failed to post_build\n";
1740 }
1741 }
1742
1743 if (!$build_ret) {
5f9b6ced 1744 # bisect may need this to pass
4ab1cce5
SR
1745 if ($in_bisect) {
1746 $no_reboot = $save_no_reboot;
1747 return 0;
1748 }
2b7d9b21 1749 fail "failed build" and return 0;
2545eb61 1750 }
5f9b6ced 1751
4ab1cce5
SR
1752 $no_reboot = $save_no_reboot;
1753
2b7d9b21 1754 return 1;
2545eb61
SR
1755}
1756
75c3fda7 1757sub halt {
e48c5293 1758 if (!run_ssh "halt" or defined($power_off)) {
576f627c
SR
1759 if (defined($poweroff_after_halt)) {
1760 sleep $poweroff_after_halt;
1761 run_command "$power_off";
1762 }
1763 } else {
75c3fda7 1764 # nope? the zap it!
a75fecec 1765 run_command "$power_off";
75c3fda7
SR
1766 }
1767}
1768
5f9b6ced
SR
1769sub success {
1770 my ($i) = @_;
1771
e48c5293
SR
1772 $successes++;
1773
9064af52
SR
1774 my $name = "";
1775
1776 if (defined($test_name)) {
1777 $name = " ($test_name)";
1778 }
1779
5f9b6ced
SR
1780 doprint "\n\n*******************************************\n";
1781 doprint "*******************************************\n";
9064af52 1782 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
5f9b6ced
SR
1783 doprint "*******************************************\n";
1784 doprint "*******************************************\n";
1785
de5b6e3b
RV
1786 if (defined($store_successes)) {
1787 save_logs "success", $store_successes;
1788 }
1789
576f627c 1790 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
a75fecec 1791 doprint "Reboot and wait $sleep_time seconds\n";
bc7c5803 1792 reboot_to_good $sleep_time;
5f9b6ced
SR
1793 }
1794}
1795
c960bb9f
SR
1796sub answer_bisect {
1797 for (;;) {
1798 doprint "Pass or fail? [p/f]";
1799 my $ans = <STDIN>;
1800 chomp $ans;
1801 if ($ans eq "p" || $ans eq "P") {
1802 return 1;
1803 } elsif ($ans eq "f" || $ans eq "F") {
1804 return 0;
1805 } else {
1806 print "Please answer 'P' or 'F'\n";
1807 }
1808 }
1809}
1810
5a391fbf 1811sub child_run_test {
7faafbd6 1812 my $failed = 0;
5a391fbf 1813
7faafbd6 1814 # child should have no power
a75fecec
SR
1815 $reboot_on_error = 0;
1816 $poweroff_on_error = 0;
1817 $die_on_failure = 1;
7faafbd6 1818
a9dd5d63 1819 $redirect = "$testlog";
7faafbd6 1820 run_command $run_test or $failed = 1;
a9dd5d63
RV
1821 undef $redirect;
1822
5a391fbf
SR
1823 exit $failed;
1824}
1825
1826my $child_done;
1827
1828sub child_finished {
1829 $child_done = 1;
1830}
1831
1832sub do_run_test {
1833 my $child_pid;
1834 my $child_exit;
5a391fbf
SR
1835 my $line;
1836 my $full_line;
1837 my $bug = 0;
5a391fbf 1838
7faafbd6 1839 wait_for_monitor 1;
5a391fbf 1840
7faafbd6 1841 doprint "run test $run_test\n";
5a391fbf
SR
1842
1843 $child_done = 0;
1844
1845 $SIG{CHLD} = qw(child_finished);
1846
1847 $child_pid = fork;
1848
1849 child_run_test if (!$child_pid);
1850
1851 $full_line = "";
1852
1853 do {
7faafbd6 1854 $line = wait_for_input($monitor_fp, 1);
5a391fbf
SR
1855 if (defined($line)) {
1856
1857 # we are not guaranteed to get a full line
1858 $full_line .= $line;
8ea0e063 1859 doprint $line;
5a391fbf
SR
1860
1861 if ($full_line =~ /call trace:/i) {
1862 $bug = 1;
1863 }
1864
1865 if ($full_line =~ /Kernel panic -/) {
1866 $bug = 1;
1867 }
1868
1869 if ($line =~ /\n/) {
1870 $full_line = "";
1871 }
1872 }
1873 } while (!$child_done && !$bug);
1874
1875 if ($bug) {
8ea0e063
SR
1876 my $failure_start = time;
1877 my $now;
1878 do {
1879 $line = wait_for_input($monitor_fp, 1);
1880 if (defined($line)) {
1881 doprint $line;
1882 }
1883 $now = time;
1884 if ($now - $failure_start >= $stop_after_failure) {
1885 last;
1886 }
1887 } while (defined($line));
1888
5a391fbf
SR
1889 doprint "Detected kernel crash!\n";
1890 # kill the child with extreme prejudice
1891 kill 9, $child_pid;
1892 }
1893
1894 waitpid $child_pid, 0;
1895 $child_exit = $?;
1896
c5dacb88
SR
1897 if (!$bug && $in_bisect) {
1898 if (defined($bisect_ret_good)) {
1899 if ($child_exit == $bisect_ret_good) {
1900 return 1;
1901 }
1902 }
1903 if (defined($bisect_ret_skip)) {
1904 if ($child_exit == $bisect_ret_skip) {
1905 return -1;
1906 }
1907 }
1908 if (defined($bisect_ret_abort)) {
1909 if ($child_exit == $bisect_ret_abort) {
1910 fail "test abort" and return -2;
1911 }
1912 }
1913 if (defined($bisect_ret_bad)) {
1914 if ($child_exit == $bisect_ret_skip) {
1915 return 0;
1916 }
1917 }
1918 if (defined($bisect_ret_default)) {
1919 if ($bisect_ret_default eq "good") {
1920 return 1;
1921 } elsif ($bisect_ret_default eq "bad") {
1922 return 0;
1923 } elsif ($bisect_ret_default eq "skip") {
1924 return -1;
1925 } elsif ($bisect_ret_default eq "abort") {
1926 return -2;
1927 } else {
1928 fail "unknown default action: $bisect_ret_default"
1929 and return -2;
1930 }
1931 }
1932 }
1933
5a391fbf 1934 if ($bug || $child_exit) {
2b7d9b21
SR
1935 return 0 if $in_bisect;
1936 fail "test failed" and return 0;
5a391fbf 1937 }
2b7d9b21 1938 return 1;
5a391fbf
SR
1939}
1940
a75fecec
SR
1941sub run_git_bisect {
1942 my ($command) = @_;
1943
1944 doprint "$command ... ";
1945
1946 my $output = `$command 2>&1`;
1947 my $ret = $?;
1948
1949 logit $output;
1950
1951 if ($ret) {
1952 doprint "FAILED\n";
1953 dodie "Failed to git bisect";
1954 }
1955
1956 doprint "SUCCESS\n";
1957 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1958 doprint "$1 [$2]\n";
1959 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
b5f4aea6 1960 $bisect_bad_commit = $1;
a75fecec
SR
1961 doprint "Found bad commit... $1\n";
1962 return 0;
1963 } else {
1964 # we already logged it, just print it now.
1965 print $output;
1966 }
1967
1968 return 1;
1969}
1970
c23dca7c
SR
1971sub bisect_reboot {
1972 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
bc7c5803 1973 reboot_to_good $bisect_sleep_time;
c23dca7c
SR
1974}
1975
1976# returns 1 on success, 0 on failure, -1 on skip
0a05c769
SR
1977sub run_bisect_test {
1978 my ($type, $buildtype) = @_;
5f9b6ced 1979
2b7d9b21 1980 my $failed = 0;
5f9b6ced
SR
1981 my $result;
1982 my $output;
1983 my $ret;
1984
0a05c769
SR
1985 $in_bisect = 1;
1986
1987 build $buildtype or $failed = 1;
5f9b6ced
SR
1988
1989 if ($type ne "build") {
c23dca7c
SR
1990 if ($failed && $bisect_skip) {
1991 $in_bisect = 0;
1992 return -1;
1993 }
7faafbd6 1994 dodie "Failed on build" if $failed;
5f9b6ced
SR
1995
1996 # Now boot the box
ddf607e5 1997 start_monitor_and_boot or $failed = 1;
5f9b6ced
SR
1998
1999 if ($type ne "boot") {
c23dca7c
SR
2000 if ($failed && $bisect_skip) {
2001 end_monitor;
2002 bisect_reboot;
2003 $in_bisect = 0;
2004 return -1;
2005 }
7faafbd6 2006 dodie "Failed on boot" if $failed;
5a391fbf 2007
2b7d9b21 2008 do_run_test or $failed = 1;
5f9b6ced 2009 }
7faafbd6 2010 end_monitor;
5f9b6ced
SR
2011 }
2012
2013 if ($failed) {
0a05c769 2014 $result = 0;
5f9b6ced 2015 } else {
0a05c769
SR
2016 $result = 1;
2017 }
4025bc62
SR
2018
2019 # reboot the box to a kernel we can ssh to
2020 if ($type ne "build") {
2021 bisect_reboot;
2022 }
0a05c769
SR
2023 $in_bisect = 0;
2024
2025 return $result;
2026}
2027
2028sub run_bisect {
2029 my ($type) = @_;
2030 my $buildtype = "oldconfig";
2031
2032 # We should have a minconfig to use?
2033 if (defined($minconfig)) {
2034 $buildtype = "useconfig:$minconfig";
5f9b6ced
SR
2035 }
2036
0a05c769
SR
2037 my $ret = run_bisect_test $type, $buildtype;
2038
c960bb9f
SR
2039 if ($bisect_manual) {
2040 $ret = answer_bisect;
2041 }
0a05c769 2042
d6ce2a0b
SR
2043 # Are we looking for where it worked, not failed?
2044 if ($reverse_bisect) {
0a05c769 2045 $ret = !$ret;
d6ce2a0b
SR
2046 }
2047
c23dca7c 2048 if ($ret > 0) {
0a05c769 2049 return "good";
c23dca7c 2050 } elsif ($ret == 0) {
0a05c769 2051 return "bad";
c23dca7c
SR
2052 } elsif ($bisect_skip) {
2053 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2054 return "skip";
0a05c769 2055 }
5f9b6ced
SR
2056}
2057
dad98754
SR
2058sub update_bisect_replay {
2059 my $tmp_log = "$tmpdir/ktest_bisect_log";
2060 run_command "git bisect log > $tmp_log" or
2061 die "can't create bisect log";
2062 return $tmp_log;
2063}
2064
5f9b6ced
SR
2065sub bisect {
2066 my ($i) = @_;
2067
2068 my $result;
2069
b5f4aea6
SR
2070 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2071 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2072 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
5f9b6ced 2073
b5f4aea6
SR
2074 my $good = $bisect_good;
2075 my $bad = $bisect_bad;
2076 my $type = $bisect_type;
2077 my $start = $bisect_start;
2078 my $replay = $bisect_replay;
2079 my $start_files = $bisect_files;
3410f6fd
SR
2080
2081 if (defined($start_files)) {
2082 $start_files = " -- " . $start_files;
2083 } else {
2084 $start_files = "";
2085 }
5f9b6ced 2086
a57419b3
SR
2087 # convert to true sha1's
2088 $good = get_sha1($good);
2089 $bad = get_sha1($bad);
2090
b5f4aea6 2091 if (defined($bisect_reverse) && $bisect_reverse == 1) {
d6ce2a0b
SR
2092 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2093 $reverse_bisect = 1;
2094 } else {
2095 $reverse_bisect = 0;
2096 }
2097
a75fecec
SR
2098 # Can't have a test without having a test to run
2099 if ($type eq "test" && !defined($run_test)) {
2100 $type = "boot";
2101 }
2102
dad98754
SR
2103 # Check if a bisect was running
2104 my $bisect_start_file = "$builddir/.git/BISECT_START";
2105
b5f4aea6 2106 my $check = $bisect_check;
dad98754
SR
2107 my $do_check = defined($check) && $check ne "0";
2108
2109 if ( -f $bisect_start_file ) {
2110 print "Bisect in progress found\n";
2111 if ($do_check) {
2112 print " If you say yes, then no checks of good or bad will be done\n";
2113 }
2114 if (defined($replay)) {
2115 print "** BISECT_REPLAY is defined in config file **";
2116 print " Ignore config option and perform new git bisect log?\n";
2117 if (read_ync " (yes, no, or cancel) ") {
2118 $replay = update_bisect_replay;
2119 $do_check = 0;
2120 }
2121 } elsif (read_yn "read git log and continue?") {
2122 $replay = update_bisect_replay;
2123 $do_check = 0;
2124 }
2125 }
2126
2127 if ($do_check) {
a75fecec
SR
2128
2129 # get current HEAD
a57419b3 2130 my $head = get_sha1("HEAD");
a75fecec
SR
2131
2132 if ($check ne "good") {
2133 doprint "TESTING BISECT BAD [$bad]\n";
2134 run_command "git checkout $bad" or
2135 die "Failed to checkout $bad";
2136
2137 $result = run_bisect $type;
2138
2139 if ($result ne "bad") {
2140 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2141 }
2142 }
2143
2144 if ($check ne "bad") {
2145 doprint "TESTING BISECT GOOD [$good]\n";
2146 run_command "git checkout $good" or
2147 die "Failed to checkout $good";
2148
2149 $result = run_bisect $type;
2150
2151 if ($result ne "good") {
2152 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2153 }
2154 }
2155
2156 # checkout where we started
2157 run_command "git checkout $head" or
2158 die "Failed to checkout $head";
2159 }
2160
3410f6fd 2161 run_command "git bisect start$start_files" or
a75fecec 2162 dodie "could not start bisect";
5f9b6ced
SR
2163
2164 run_command "git bisect good $good" or
a75fecec 2165 dodie "could not set bisect good to $good";
5f9b6ced 2166
a75fecec
SR
2167 run_git_bisect "git bisect bad $bad" or
2168 dodie "could not set bisect bad to $bad";
5f9b6ced 2169
a75fecec
SR
2170 if (defined($replay)) {
2171 run_command "git bisect replay $replay" or
2172 dodie "failed to run replay";
5a391fbf
SR
2173 }
2174
a75fecec
SR
2175 if (defined($start)) {
2176 run_command "git checkout $start" or
2177 dodie "failed to checkout $start";
2178 }
2179
2180 my $test;
5f9b6ced
SR
2181 do {
2182 $result = run_bisect $type;
a75fecec
SR
2183 $test = run_git_bisect "git bisect $result";
2184 } while ($test);
5f9b6ced
SR
2185
2186 run_command "git bisect log" or
2187 dodie "could not capture git bisect log";
2188
2189 run_command "git bisect reset" or
2190 dodie "could not reset git bisect";
2191
b5f4aea6 2192 doprint "Bad commit was [$bisect_bad_commit]\n";
5f9b6ced 2193
0a05c769
SR
2194 success $i;
2195}
2196
2197my %config_ignore;
2198my %config_set;
2199
2200my %config_list;
2201my %null_config;
2202
2203my %dependency;
2204
4c4ab120
SR
2205sub assign_configs {
2206 my ($hash, $config) = @_;
0a05c769
SR
2207
2208 open (IN, $config)
2209 or dodie "Failed to read $config";
2210
2211 while (<IN>) {
9bf71749 2212 if (/^((CONFIG\S*)=.*)/) {
4c4ab120 2213 ${$hash}{$2} = $1;
0a05c769
SR
2214 }
2215 }
2216
2217 close(IN);
2218}
2219
4c4ab120
SR
2220sub process_config_ignore {
2221 my ($config) = @_;
2222
2223 assign_configs \%config_ignore, $config;
2224}
2225
0a05c769
SR
2226sub read_current_config {
2227 my ($config_ref) = @_;
2228
2229 %{$config_ref} = ();
2230 undef %{$config_ref};
2231
2232 my @key = keys %{$config_ref};
2233 if ($#key >= 0) {
2234 print "did not delete!\n";
2235 exit;
2236 }
2237 open (IN, "$output_config");
2238
2239 while (<IN>) {
2240 if (/^(CONFIG\S+)=(.*)/) {
2241 ${$config_ref}{$1} = $2;
2242 }
2243 }
2244 close(IN);
2245}
2246
2247sub get_dependencies {
2248 my ($config) = @_;
2249
2250 my $arr = $dependency{$config};
2251 if (!defined($arr)) {
2252 return ();
2253 }
2254
2255 my @deps = @{$arr};
2256
2257 foreach my $dep (@{$arr}) {
2258 print "ADD DEP $dep\n";
2259 @deps = (@deps, get_dependencies $dep);
2260 }
2261
2262 return @deps;
2263}
2264
2265sub create_config {
2266 my @configs = @_;
2267
2268 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2269
2270 foreach my $config (@configs) {
2271 print OUT "$config_set{$config}\n";
2272 my @deps = get_dependencies $config;
2273 foreach my $dep (@deps) {
2274 print OUT "$config_set{$dep}\n";
2275 }
2276 }
2277
2278 foreach my $config (keys %config_ignore) {
2279 print OUT "$config_ignore{$config}\n";
2280 }
2281 close(OUT);
2282
2283# exit;
fcb3f16a 2284 make_oldconfig;
0a05c769
SR
2285}
2286
2287sub compare_configs {
2288 my (%a, %b) = @_;
2289
2290 foreach my $item (keys %a) {
2291 if (!defined($b{$item})) {
2292 print "diff $item\n";
2293 return 1;
2294 }
2295 delete $b{$item};
2296 }
2297
2298 my @keys = keys %b;
2299 if ($#keys) {
2300 print "diff2 $keys[0]\n";
2301 }
2302 return -1 if ($#keys >= 0);
2303
2304 return 0;
2305}
2306
2307sub run_config_bisect_test {
2308 my ($type) = @_;
2309
2310 return run_bisect_test $type, "oldconfig";
2311}
2312
2313sub process_passed {
2314 my (%configs) = @_;
2315
2316 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2317 # Passed! All these configs are part of a good compile.
2318 # Add them to the min options.
2319 foreach my $config (keys %configs) {
2320 if (defined($config_list{$config})) {
2321 doprint " removing $config\n";
2322 $config_ignore{$config} = $config_list{$config};
2323 delete $config_list{$config};
2324 }
2325 }
f1a27850
SR
2326 doprint "config copied to $outputdir/config_good\n";
2327 run_command "cp -f $output_config $outputdir/config_good";
0a05c769
SR
2328}
2329
2330sub process_failed {
2331 my ($config) = @_;
2332
2333 doprint "\n\n***************************************\n";
2334 doprint "Found bad config: $config\n";
2335 doprint "***************************************\n\n";
2336}
2337
2338sub run_config_bisect {
2339
2340 my @start_list = keys %config_list;
2341
2342 if ($#start_list < 0) {
2343 doprint "No more configs to test!!!\n";
2344 return -1;
2345 }
2346
2347 doprint "***** RUN TEST ***\n";
b5f4aea6 2348 my $type = $config_bisect_type;
0a05c769
SR
2349 my $ret;
2350 my %current_config;
2351
2352 my $count = $#start_list + 1;
2353 doprint " $count configs to test\n";
2354
2355 my $half = int($#start_list / 2);
2356
2357 do {
2358 my @tophalf = @start_list[0 .. $half];
2359
2360 create_config @tophalf;
2361 read_current_config \%current_config;
2362
2363 $count = $#tophalf + 1;
2364 doprint "Testing $count configs\n";
2365 my $found = 0;
2366 # make sure we test something
2367 foreach my $config (@tophalf) {
2368 if (defined($current_config{$config})) {
2369 logit " $config\n";
2370 $found = 1;
2371 }
2372 }
2373 if (!$found) {
2374 # try the other half
2375 doprint "Top half produced no set configs, trying bottom half\n";
4c8cc55b 2376 @tophalf = @start_list[$half + 1 .. $#start_list];
0a05c769
SR
2377 create_config @tophalf;
2378 read_current_config \%current_config;
2379 foreach my $config (@tophalf) {
2380 if (defined($current_config{$config})) {
2381 logit " $config\n";
2382 $found = 1;
2383 }
2384 }
2385 if (!$found) {
2386 doprint "Failed: Can't make new config with current configs\n";
2387 foreach my $config (@start_list) {
2388 doprint " CONFIG: $config\n";
2389 }
2390 return -1;
2391 }
2392 $count = $#tophalf + 1;
2393 doprint "Testing $count configs\n";
2394 }
2395
2396 $ret = run_config_bisect_test $type;
c960bb9f
SR
2397 if ($bisect_manual) {
2398 $ret = answer_bisect;
2399 }
0a05c769
SR
2400 if ($ret) {
2401 process_passed %current_config;
2402 return 0;
2403 }
2404
2405 doprint "This config had a failure.\n";
2406 doprint "Removing these configs that were not set in this config:\n";
f1a27850
SR
2407 doprint "config copied to $outputdir/config_bad\n";
2408 run_command "cp -f $output_config $outputdir/config_bad";
0a05c769
SR
2409
2410 # A config exists in this group that was bad.
2411 foreach my $config (keys %config_list) {
2412 if (!defined($current_config{$config})) {
2413 doprint " removing $config\n";
2414 delete $config_list{$config};
2415 }
2416 }
2417
2418 @start_list = @tophalf;
2419
2420 if ($#start_list == 0) {
2421 process_failed $start_list[0];
2422 return 1;
2423 }
2424
2425 # remove half the configs we are looking at and see if
2426 # they are good.
2427 $half = int($#start_list / 2);
4c8cc55b 2428 } while ($#start_list > 0);
0a05c769 2429
c960bb9f
SR
2430 # we found a single config, try it again unless we are running manually
2431
2432 if ($bisect_manual) {
2433 process_failed $start_list[0];
2434 return 1;
2435 }
2436
0a05c769
SR
2437 my @tophalf = @start_list[0 .. 0];
2438
2439 $ret = run_config_bisect_test $type;
2440 if ($ret) {
2441 process_passed %current_config;
2442 return 0;
2443 }
2444
2445 process_failed $start_list[0];
2446 return 1;
2447}
2448
2449sub config_bisect {
2450 my ($i) = @_;
2451
b5f4aea6 2452 my $start_config = $config_bisect;
0a05c769
SR
2453
2454 my $tmpconfig = "$tmpdir/use_config";
2455
30f75da5
SR
2456 if (defined($config_bisect_good)) {
2457 process_config_ignore $config_bisect_good;
2458 }
2459
0a05c769
SR
2460 # Make the file with the bad config and the min config
2461 if (defined($minconfig)) {
2462 # read the min config for things to ignore
2463 run_command "cp $minconfig $tmpconfig" or
2464 dodie "failed to copy $minconfig to $tmpconfig";
2465 } else {
2466 unlink $tmpconfig;
2467 }
2468
0a05c769 2469 if (-f $tmpconfig) {
fcb3f16a 2470 load_force_config($tmpconfig);
0a05c769
SR
2471 process_config_ignore $tmpconfig;
2472 }
2473
2474 # now process the start config
2475 run_command "cp $start_config $output_config" or
2476 dodie "failed to copy $start_config to $output_config";
2477
2478 # read directly what we want to check
2479 my %config_check;
2480 open (IN, $output_config)
2481 or dodie "faied to open $output_config";
2482
2483 while (<IN>) {
2484 if (/^((CONFIG\S*)=.*)/) {
2485 $config_check{$2} = $1;
2486 }
2487 }
2488 close(IN);
2489
250bae8b 2490 # Now run oldconfig with the minconfig
fcb3f16a 2491 make_oldconfig;
0a05c769
SR
2492
2493 # check to see what we lost (or gained)
2494 open (IN, $output_config)
2495 or dodie "Failed to read $start_config";
2496
2497 my %removed_configs;
2498 my %added_configs;
2499
2500 while (<IN>) {
2501 if (/^((CONFIG\S*)=.*)/) {
2502 # save off all options
2503 $config_set{$2} = $1;
2504 if (defined($config_check{$2})) {
2505 if (defined($config_ignore{$2})) {
2506 $removed_configs{$2} = $1;
2507 } else {
2508 $config_list{$2} = $1;
2509 }
2510 } elsif (!defined($config_ignore{$2})) {
2511 $added_configs{$2} = $1;
2512 $config_list{$2} = $1;
2513 }
2514 }
2515 }
2516 close(IN);
2517
2518 my @confs = keys %removed_configs;
2519 if ($#confs >= 0) {
2520 doprint "Configs overridden by default configs and removed from check:\n";
2521 foreach my $config (@confs) {
2522 doprint " $config\n";
2523 }
2524 }
2525 @confs = keys %added_configs;
2526 if ($#confs >= 0) {
2527 doprint "Configs appearing in make oldconfig and added:\n";
2528 foreach my $config (@confs) {
2529 doprint " $config\n";
2530 }
2531 }
2532
2533 my %config_test;
2534 my $once = 0;
2535
2536 # Sometimes kconfig does weird things. We must make sure
2537 # that the config we autocreate has everything we need
2538 # to test, otherwise we may miss testing configs, or
2539 # may not be able to create a new config.
2540 # Here we create a config with everything set.
2541 create_config (keys %config_list);
2542 read_current_config \%config_test;
2543 foreach my $config (keys %config_list) {
2544 if (!defined($config_test{$config})) {
2545 if (!$once) {
2546 $once = 1;
2547 doprint "Configs not produced by kconfig (will not be checked):\n";
2548 }
2549 doprint " $config\n";
2550 delete $config_list{$config};
2551 }
2552 }
2553 my $ret;
2554 do {
2555 $ret = run_config_bisect;
2556 } while (!$ret);
2557
2558 return $ret if ($ret < 0);
5f9b6ced
SR
2559
2560 success $i;
2561}
2562
27d934b2
SR
2563sub patchcheck_reboot {
2564 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
bc7c5803 2565 reboot_to_good $patchcheck_sleep_time;
27d934b2
SR
2566}
2567
6c5ee0be
SR
2568sub patchcheck {
2569 my ($i) = @_;
2570
2571 die "PATCHCHECK_START[$i] not defined\n"
b5f4aea6 2572 if (!defined($patchcheck_start));
6c5ee0be 2573 die "PATCHCHECK_TYPE[$i] not defined\n"
b5f4aea6 2574 if (!defined($patchcheck_type));
6c5ee0be 2575
b5f4aea6 2576 my $start = $patchcheck_start;
6c5ee0be
SR
2577
2578 my $end = "HEAD";
b5f4aea6
SR
2579 if (defined($patchcheck_end)) {
2580 $end = $patchcheck_end;
6c5ee0be
SR
2581 }
2582
a57419b3
SR
2583 # Get the true sha1's since we can use things like HEAD~3
2584 $start = get_sha1($start);
2585 $end = get_sha1($end);
2586
b5f4aea6 2587 my $type = $patchcheck_type;
6c5ee0be
SR
2588
2589 # Can't have a test without having a test to run
2590 if ($type eq "test" && !defined($run_test)) {
2591 $type = "boot";
2592 }
2593
2594 open (IN, "git log --pretty=oneline $end|") or
2595 dodie "could not get git list";
2596
2597 my @list;
2598
2599 while (<IN>) {
2600 chomp;
2601 $list[$#list+1] = $_;
2602 last if (/^$start/);
2603 }
2604 close(IN);
2605
2606 if ($list[$#list] !~ /^$start/) {
2b7d9b21 2607 fail "SHA1 $start not found";
6c5ee0be
SR
2608 }
2609
2610 # go backwards in the list
2611 @list = reverse @list;
2612
2613 my $save_clean = $noclean;
1990207d
SR
2614 my %ignored_warnings;
2615
2616 if (defined($ignore_warnings)) {
2617 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2618 $ignored_warnings{$sha1} = 1;
2619 }
2620 }
6c5ee0be
SR
2621
2622 $in_patchcheck = 1;
2623 foreach my $item (@list) {
2624 my $sha1 = $item;
2625 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2626
2627 doprint "\nProcessing commit $item\n\n";
2628
2629 run_command "git checkout $sha1" or
2630 die "Failed to checkout $sha1";
2631
2632 # only clean on the first and last patch
2633 if ($item eq $list[0] ||
2634 $item eq $list[$#list]) {
2635 $noclean = $save_clean;
2636 } else {
2637 $noclean = 1;
2638 }
2639
2640 if (defined($minconfig)) {
2b7d9b21 2641 build "useconfig:$minconfig" or return 0;
6c5ee0be
SR
2642 } else {
2643 # ?? no config to use?
2b7d9b21 2644 build "oldconfig" or return 0;
6c5ee0be
SR
2645 }
2646
1990207d
SR
2647
2648 if (!defined($ignored_warnings{$sha1})) {
2649 check_buildlog $sha1 or return 0;
2650 }
6c5ee0be
SR
2651
2652 next if ($type eq "build");
2653
7faafbd6
SR
2654 my $failed = 0;
2655
ddf607e5 2656 start_monitor_and_boot or $failed = 1;
7faafbd6
SR
2657
2658 if (!$failed && $type ne "boot"){
2659 do_run_test or $failed = 1;
2660 }
2661 end_monitor;
2662 return 0 if ($failed);
2663
27d934b2
SR
2664 patchcheck_reboot;
2665
6c5ee0be
SR
2666 }
2667 $in_patchcheck = 0;
2668 success $i;
2b7d9b21
SR
2669
2670 return 1;
6c5ee0be
SR
2671}
2672
b9066f6c 2673my %depends;
ac6974c7 2674my %depcount;
b9066f6c
SR
2675my $iflevel = 0;
2676my @ifdeps;
2677
2678# prevent recursion
2679my %read_kconfigs;
2680
ac6974c7
SR
2681sub add_dep {
2682 # $config depends on $dep
2683 my ($config, $dep) = @_;
2684
2685 if (defined($depends{$config})) {
2686 $depends{$config} .= " " . $dep;
2687 } else {
2688 $depends{$config} = $dep;
2689 }
2690
2691 # record the number of configs depending on $dep
2692 if (defined $depcount{$dep}) {
2693 $depcount{$dep}++;
2694 } else {
2695 $depcount{$dep} = 1;
2696 }
2697}
2698
b9066f6c
SR
2699# taken from streamline_config.pl
2700sub read_kconfig {
2701 my ($kconfig) = @_;
2702
2703 my $state = "NONE";
2704 my $config;
2705 my @kconfigs;
2706
2707 my $cont = 0;
2708 my $line;
2709
2710
2711 if (! -f $kconfig) {
2712 doprint "file $kconfig does not exist, skipping\n";
2713 return;
2714 }
2715
2716 open(KIN, "$kconfig")
2717 or die "Can't open $kconfig";
2718 while (<KIN>) {
2719 chomp;
2720
2721 # Make sure that lines ending with \ continue
2722 if ($cont) {
2723 $_ = $line . " " . $_;
2724 }
2725
2726 if (s/\\$//) {
2727 $cont = 1;
2728 $line = $_;
2729 next;
2730 }
2731
2732 $cont = 0;
2733
2734 # collect any Kconfig sources
2735 if (/^source\s*"(.*)"/) {
2736 $kconfigs[$#kconfigs+1] = $1;
2737 }
2738
2739 # configs found
2740 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2741 $state = "NEW";
2742 $config = $2;
2743
2744 for (my $i = 0; $i < $iflevel; $i++) {
ac6974c7 2745 add_dep $config, $ifdeps[$i];
b9066f6c
SR
2746 }
2747
2748 # collect the depends for the config
2749 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2750
ac6974c7 2751 add_dep $config, $1;
b9066f6c
SR
2752
2753 # Get the configs that select this config
ac6974c7
SR
2754 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2755
2756 # selected by depends on config
2757 add_dep $1, $config;
b9066f6c
SR
2758
2759 # Check for if statements
2760 } elsif (/^if\s+(.*\S)\s*$/) {
2761 my $deps = $1;
2762 # remove beginning and ending non text
2763 $deps =~ s/^[^a-zA-Z0-9_]*//;
2764 $deps =~ s/[^a-zA-Z0-9_]*$//;
2765
2766 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2767
2768 $ifdeps[$iflevel++] = join ':', @deps;
2769
2770 } elsif (/^endif/) {
2771
2772 $iflevel-- if ($iflevel);
2773
2774 # stop on "help"
2775 } elsif (/^\s*help\s*$/) {
2776 $state = "NONE";
2777 }
2778 }
2779 close(KIN);
2780
2781 # read in any configs that were found.
2782 foreach $kconfig (@kconfigs) {
2783 if (!defined($read_kconfigs{$kconfig})) {
2784 $read_kconfigs{$kconfig} = 1;
2785 read_kconfig("$builddir/$kconfig");
2786 }
2787 }
2788}
2789
2790sub read_depends {
2791 # find out which arch this is by the kconfig file
2792 open (IN, $output_config)
2793 or dodie "Failed to read $output_config";
2794 my $arch;
2795 while (<IN>) {
2796 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2797 $arch = $1;
2798 last;
2799 }
2800 }
2801 close IN;
2802
2803 if (!defined($arch)) {
2804 doprint "Could not find arch from config file\n";
2805 doprint "no dependencies used\n";
2806 return;
2807 }
2808
2809 # arch is really the subarch, we need to know
2810 # what directory to look at.
2811 if ($arch eq "i386" || $arch eq "x86_64") {
2812 $arch = "x86";
2813 } elsif ($arch =~ /^tile/) {
2814 $arch = "tile";
2815 }
2816
2817 my $kconfig = "$builddir/arch/$arch/Kconfig";
2818
2819 if (! -f $kconfig && $arch =~ /\d$/) {
2820 my $orig = $arch;
2821 # some subarchs have numbers, truncate them
2822 $arch =~ s/\d*$//;
2823 $kconfig = "$builddir/arch/$arch/Kconfig";
2824 if (! -f $kconfig) {
2825 doprint "No idea what arch dir $orig is for\n";
2826 doprint "no dependencies used\n";
2827 return;
2828 }
2829 }
2830
2831 read_kconfig($kconfig);
2832}
2833
4c4ab120
SR
2834sub read_config_list {
2835 my ($config) = @_;
2836
2837 open (IN, $config)
2838 or dodie "Failed to read $config";
2839
2840 while (<IN>) {
2841 if (/^((CONFIG\S*)=.*)/) {
2842 if (!defined($config_ignore{$2})) {
2843 $config_list{$2} = $1;
2844 }
2845 }
2846 }
2847
2848 close(IN);
2849}
2850
2851sub read_output_config {
2852 my ($config) = @_;
2853
2854 assign_configs \%config_ignore, $config;
2855}
2856
2857sub make_new_config {
2858 my @configs = @_;
2859
2860 open (OUT, ">$output_config")
2861 or dodie "Failed to write $output_config";
2862
2863 foreach my $config (@configs) {
2864 print OUT "$config\n";
2865 }
2866 close OUT;
2867}
2868
ac6974c7
SR
2869sub chomp_config {
2870 my ($config) = @_;
2871
2872 $config =~ s/CONFIG_//;
2873
2874 return $config;
2875}
2876
b9066f6c
SR
2877sub get_depends {
2878 my ($dep) = @_;
2879
ac6974c7 2880 my $kconfig = chomp_config $dep;
b9066f6c
SR
2881
2882 $dep = $depends{"$kconfig"};
2883
2884 # the dep string we have saves the dependencies as they
2885 # were found, including expressions like ! && ||. We
2886 # want to split this out into just an array of configs.
2887
2888 my $valid = "A-Za-z_0-9";
2889
2890 my @configs;
2891
2892 while ($dep =~ /[$valid]/) {
2893
2894 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2895 my $conf = "CONFIG_" . $1;
2896
2897 $configs[$#configs + 1] = $conf;
2898
2899 $dep =~ s/^[^$valid]*[$valid]+//;
2900 } else {
2901 die "this should never happen";
2902 }
2903 }
2904
2905 return @configs;
2906}
2907
2908my %min_configs;
2909my %keep_configs;
43d1b651 2910my %save_configs;
b9066f6c
SR
2911my %processed_configs;
2912my %nochange_config;
2913
2914sub test_this_config {
2915 my ($config) = @_;
2916
2917 my $found;
2918
2919 # if we already processed this config, skip it
2920 if (defined($processed_configs{$config})) {
2921 return undef;
2922 }
2923 $processed_configs{$config} = 1;
2924
2925 # if this config failed during this round, skip it
2926 if (defined($nochange_config{$config})) {
2927 return undef;
2928 }
2929
ac6974c7 2930 my $kconfig = chomp_config $config;
b9066f6c
SR
2931
2932 # Test dependencies first
2933 if (defined($depends{"$kconfig"})) {
2934 my @parents = get_depends $config;
2935 foreach my $parent (@parents) {
2936 # if the parent is in the min config, check it first
2937 next if (!defined($min_configs{$parent}));
2938 $found = test_this_config($parent);
2939 if (defined($found)) {
2940 return $found;
2941 }
2942 }
2943 }
2944
2945 # Remove this config from the list of configs
2946 # do a make oldnoconfig and then read the resulting
2947 # .config to make sure it is missing the config that
2948 # we had before
2949 my %configs = %min_configs;
2950 delete $configs{$config};
2951 make_new_config ((values %configs), (values %keep_configs));
2952 make_oldconfig;
2953 undef %configs;
2954 assign_configs \%configs, $output_config;
2955
2956 return $config if (!defined($configs{$config}));
2957
2958 doprint "disabling config $config did not change .config\n";
2959
2960 $nochange_config{$config} = 1;
2961
2962 return undef;
2963}
2964
4c4ab120
SR
2965sub make_min_config {
2966 my ($i) = @_;
2967
2968 if (!defined($output_minconfig)) {
2969 fail "OUTPUT_MIN_CONFIG not defined" and return;
2970 }
35ce5952
SR
2971
2972 # If output_minconfig exists, and the start_minconfig
2973 # came from min_config, than ask if we should use
2974 # that instead.
2975 if (-f $output_minconfig && !$start_minconfig_defined) {
2976 print "$output_minconfig exists\n";
2977 if (read_yn " Use it as minconfig?") {
2978 $start_minconfig = $output_minconfig;
2979 }
2980 }
2981
4c4ab120
SR
2982 if (!defined($start_minconfig)) {
2983 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2984 }
2985
35ce5952
SR
2986 my $temp_config = "$tmpdir/temp_config";
2987
4c4ab120
SR
2988 # First things first. We build an allnoconfig to find
2989 # out what the defaults are that we can't touch.
2990 # Some are selections, but we really can't handle selections.
2991
2992 my $save_minconfig = $minconfig;
2993 undef $minconfig;
2994
2995 run_command "$make allnoconfig" or return 0;
2996
b9066f6c
SR
2997 read_depends;
2998
4c4ab120 2999 process_config_ignore $output_config;
b9066f6c 3000
43d1b651 3001 undef %save_configs;
b9066f6c 3002 undef %min_configs;
4c4ab120
SR
3003
3004 if (defined($ignore_config)) {
3005 # make sure the file exists
3006 `touch $ignore_config`;
43d1b651 3007 assign_configs \%save_configs, $ignore_config;
4c4ab120
SR
3008 }
3009
43d1b651
SR
3010 %keep_configs = %save_configs;
3011
4c4ab120
SR
3012 doprint "Load initial configs from $start_minconfig\n";
3013
3014 # Look at the current min configs, and save off all the
3015 # ones that were set via the allnoconfig
4c4ab120
SR
3016 assign_configs \%min_configs, $start_minconfig;
3017
3018 my @config_keys = keys %min_configs;
3019
ac6974c7
SR
3020 # All configs need a depcount
3021 foreach my $config (@config_keys) {
3022 my $kconfig = chomp_config $config;
3023 if (!defined $depcount{$kconfig}) {
3024 $depcount{$kconfig} = 0;
3025 }
3026 }
3027
4c4ab120
SR
3028 # Remove anything that was set by the make allnoconfig
3029 # we shouldn't need them as they get set for us anyway.
3030 foreach my $config (@config_keys) {
3031 # Remove anything in the ignore_config
3032 if (defined($keep_configs{$config})) {
3033 my $file = $ignore_config;
3034 $file =~ s,.*/(.*?)$,$1,;
3035 doprint "$config set by $file ... ignored\n";
3036 delete $min_configs{$config};
3037 next;
3038 }
3039 # But make sure the settings are the same. If a min config
3040 # sets a selection, we do not want to get rid of it if
3041 # it is not the same as what we have. Just move it into
3042 # the keep configs.
3043 if (defined($config_ignore{$config})) {
3044 if ($config_ignore{$config} ne $min_configs{$config}) {
3045 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3046 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3047 $keep_configs{$config} = $min_configs{$config};
3048 } else {
3049 doprint "$config set by allnoconfig ... ignored\n";
3050 }
3051 delete $min_configs{$config};
3052 }
3053 }
3054
4c4ab120 3055 my $done = 0;
b9066f6c 3056 my $take_two = 0;
4c4ab120
SR
3057
3058 while (!$done) {
3059
3060 my $config;
3061 my $found;
3062
3063 # Now disable each config one by one and do a make oldconfig
3064 # till we find a config that changes our list.
3065
4c4ab120 3066 my @test_configs = keys %min_configs;
ac6974c7
SR
3067
3068 # Sort keys by who is most dependent on
3069 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3070 @test_configs ;
3071
3072 # Put configs that did not modify the config at the end.
4c4ab120
SR
3073 my $reset = 1;
3074 for (my $i = 0; $i < $#test_configs; $i++) {
3075 if (!defined($nochange_config{$test_configs[0]})) {
3076 $reset = 0;
3077 last;
3078 }
3079 # This config didn't change the .config last time.
3080 # Place it at the end
3081 my $config = shift @test_configs;
3082 push @test_configs, $config;
3083 }
3084
3085 # if every test config has failed to modify the .config file
3086 # in the past, then reset and start over.
3087 if ($reset) {
3088 undef %nochange_config;
3089 }
3090
b9066f6c
SR
3091 undef %processed_configs;
3092
4c4ab120
SR
3093 foreach my $config (@test_configs) {
3094
b9066f6c 3095 $found = test_this_config $config;
4c4ab120 3096
b9066f6c 3097 last if (defined($found));
4c4ab120
SR
3098
3099 # oh well, try another config
4c4ab120
SR
3100 }
3101
3102 if (!defined($found)) {
b9066f6c
SR
3103 # we could have failed due to the nochange_config hash
3104 # reset and try again
3105 if (!$take_two) {
3106 undef %nochange_config;
3107 $take_two = 1;
3108 next;
3109 }
4c4ab120
SR
3110 doprint "No more configs found that we can disable\n";
3111 $done = 1;
3112 last;
3113 }
b9066f6c 3114 $take_two = 0;
4c4ab120
SR
3115
3116 $config = $found;
3117
3118 doprint "Test with $config disabled\n";
3119
3120 # set in_bisect to keep build and monitor from dieing
3121 $in_bisect = 1;
3122
3123 my $failed = 0;
3124 build "oldconfig";
3125 start_monitor_and_boot or $failed = 1;
3126 end_monitor;
3127
3128 $in_bisect = 0;
3129
3130 if ($failed) {
b9066f6c 3131 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
4c4ab120
SR
3132 # this config is needed, add it to the ignore list.
3133 $keep_configs{$config} = $min_configs{$config};
43d1b651 3134 $save_configs{$config} = $min_configs{$config};
4c4ab120 3135 delete $min_configs{$config};
35ce5952
SR
3136
3137 # update new ignore configs
3138 if (defined($ignore_config)) {
3139 open (OUT, ">$temp_config")
3140 or die "Can't write to $temp_config";
43d1b651
SR
3141 foreach my $config (keys %save_configs) {
3142 print OUT "$save_configs{$config}\n";
35ce5952
SR
3143 }
3144 close OUT;
3145 run_command "mv $temp_config $ignore_config" or
3146 dodie "failed to copy update to $ignore_config";
3147 }
3148
4c4ab120
SR
3149 } else {
3150 # We booted without this config, remove it from the minconfigs.
3151 doprint "$config is not needed, disabling\n";
3152
3153 delete $min_configs{$config};
3154
3155 # Also disable anything that is not enabled in this config
3156 my %configs;
3157 assign_configs \%configs, $output_config;
3158 my @config_keys = keys %min_configs;
3159 foreach my $config (@config_keys) {
3160 if (!defined($configs{$config})) {
3161 doprint "$config is not set, disabling\n";
3162 delete $min_configs{$config};
3163 }
3164 }
3165
3166 # Save off all the current mandidory configs
35ce5952
SR
3167 open (OUT, ">$temp_config")
3168 or die "Can't write to $temp_config";
4c4ab120
SR
3169 foreach my $config (keys %keep_configs) {
3170 print OUT "$keep_configs{$config}\n";
3171 }
3172 foreach my $config (keys %min_configs) {
3173 print OUT "$min_configs{$config}\n";
3174 }
3175 close OUT;
35ce5952
SR
3176
3177 run_command "mv $temp_config $output_minconfig" or
3178 dodie "failed to copy update to $output_minconfig";
4c4ab120
SR
3179 }
3180
3181 doprint "Reboot and wait $sleep_time seconds\n";
bc7c5803 3182 reboot_to_good $sleep_time;
4c4ab120
SR
3183 }
3184
3185 success $i;
3186 return 1;
3187}
3188
8d1491ba
SR
3189$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3190
3191if ($#ARGV == 0) {
3192 $ktest_config = $ARGV[0];
3193 if (! -f $ktest_config) {
3194 print "$ktest_config does not exist.\n";
35ce5952 3195 if (!read_yn "Create it?") {
8d1491ba
SR
3196 exit 0;
3197 }
3198 }
3199} else {
3200 $ktest_config = "ktest.conf";
3201}
3202
3203if (! -f $ktest_config) {
dbd3783b 3204 $newconfig = 1;
c4261d0f 3205 get_test_case;
8d1491ba
SR
3206 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3207 print OUT << "EOF"
3208# Generated by ktest.pl
3209#
0e7a22de
SR
3210
3211# PWD is a ktest.pl variable that will result in the process working
3212# directory that ktest.pl is executed in.
3213
3214# THIS_DIR is automatically assigned the PWD of the path that generated
3215# the config file. It is best to use this variable when assigning other
3216# directory paths within this directory. This allows you to easily
3217# move the test cases to other locations or to other machines.
3218#
3219THIS_DIR := $variable{"PWD"}
3220
8d1491ba
SR
3221# Define each test with TEST_START
3222# The config options below it will override the defaults
3223TEST_START
c4261d0f 3224TEST_TYPE = $default{"TEST_TYPE"}
8d1491ba
SR
3225
3226DEFAULTS
3227EOF
3228;
3229 close(OUT);
3230}
3231read_config $ktest_config;
3232
23715c3c
SR
3233if (defined($opt{"LOG_FILE"})) {
3234 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3235}
3236
8d1491ba
SR
3237# Append any configs entered in manually to the config file.
3238my @new_configs = keys %entered_configs;
3239if ($#new_configs >= 0) {
3240 print "\nAppending entered in configs to $ktest_config\n";
3241 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3242 foreach my $config (@new_configs) {
3243 print OUT "$config = $entered_configs{$config}\n";
0e7a22de 3244 $opt{$config} = process_variables($entered_configs{$config});
8d1491ba
SR
3245 }
3246}
2545eb61 3247
2b7d9b21
SR
3248if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3249 unlink $opt{"LOG_FILE"};
3250}
2545eb61 3251
2b7d9b21
SR
3252doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3253
a57419b3
SR
3254for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3255
3256 if (!$i) {
3257 doprint "DEFAULT OPTIONS:\n";
3258 } else {
3259 doprint "\nTEST $i OPTIONS";
3260 if (defined($repeat_tests{$i})) {
3261 $repeat = $repeat_tests{$i};
3262 doprint " ITERATE $repeat";
3263 }
3264 doprint "\n";
3265 }
3266
3267 foreach my $option (sort keys %opt) {
3268
3269 if ($option =~ /\[(\d+)\]$/) {
3270 next if ($i != $1);
3271 } else {
3272 next if ($i);
3273 }
3274
3275 doprint "$option = $opt{$option}\n";
3276 }
2b7d9b21 3277}
2545eb61 3278
2a62512b 3279sub __set_test_option {
5a391fbf 3280 my ($name, $i) = @_;
2545eb61 3281
5a391fbf 3282 my $option = "$name\[$i\]";
5c42fc5b 3283
5a391fbf
SR
3284 if (defined($opt{$option})) {
3285 return $opt{$option};
5f9b6ced
SR
3286 }
3287
a57419b3
SR
3288 foreach my $test (keys %repeat_tests) {
3289 if ($i >= $test &&
3290 $i < $test + $repeat_tests{$test}) {
3291 $option = "$name\[$test\]";
3292 if (defined($opt{$option})) {
3293 return $opt{$option};
3294 }
3295 }
3296 }
3297
5a391fbf
SR
3298 if (defined($opt{$name})) {
3299 return $opt{$name};
2545eb61
SR
3300 }
3301
5a391fbf
SR
3302 return undef;
3303}
3304
2a62512b
SR
3305sub set_test_option {
3306 my ($name, $i) = @_;
3307
3308 my $option = __set_test_option($name, $i);
3309 return $option if (!defined($option));
3310
23715c3c 3311 return eval_option($option, $i);
2a62512b
SR
3312}
3313
5a391fbf 3314# First we need to do is the builds
a75fecec
SR
3315for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3316
4ab1cce5
SR
3317 # Do not reboot on failing test options
3318 $no_reboot = 1;
3319
576f627c
SR
3320 $iteration = $i;
3321
a75fecec
SR
3322 my $makecmd = set_test_option("MAKE_CMD", $i);
3323
3324 $machine = set_test_option("MACHINE", $i);
e48c5293 3325 $ssh_user = set_test_option("SSH_USER", $i);
a75fecec
SR
3326 $tmpdir = set_test_option("TMP_DIR", $i);
3327 $outputdir = set_test_option("OUTPUT_DIR", $i);
3328 $builddir = set_test_option("BUILD_DIR", $i);
3329 $test_type = set_test_option("TEST_TYPE", $i);
3330 $build_type = set_test_option("BUILD_TYPE", $i);
3331 $build_options = set_test_option("BUILD_OPTIONS", $i);
0bd6c1a3
SR
3332 $pre_build = set_test_option("PRE_BUILD", $i);
3333 $post_build = set_test_option("POST_BUILD", $i);
3334 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3335 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
a75fecec 3336 $power_cycle = set_test_option("POWER_CYCLE", $i);
e48c5293 3337 $reboot = set_test_option("REBOOT", $i);
a75fecec
SR
3338 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3339 $minconfig = set_test_option("MIN_CONFIG", $i);
4c4ab120
SR
3340 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3341 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3342 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
a75fecec
SR
3343 $run_test = set_test_option("TEST", $i);
3344 $addconfig = set_test_option("ADD_CONFIG", $i);
3345 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3346 $grub_menu = set_test_option("GRUB_MENU", $i);
8b37ca8c 3347 $post_install = set_test_option("POST_INSTALL", $i);
e0a8742e 3348 $no_install = set_test_option("NO_INSTALL", $i);
a75fecec
SR
3349 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3350 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
bc7c5803
SR
3351 $switch_to_good = set_test_option("SWITCH_TO_GOOD", $i);
3352 $switch_to_test = set_test_option("SWITCH_TO_TEST", $i);
a75fecec
SR
3353 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3354 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3355 $power_off = set_test_option("POWER_OFF", $i);
576f627c
SR
3356 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3357 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
a75fecec
SR
3358 $sleep_time = set_test_option("SLEEP_TIME", $i);
3359 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
27d934b2 3360 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
1990207d 3361 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
c960bb9f 3362 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
c23dca7c 3363 $bisect_skip = set_test_option("BISECT_SKIP", $i);
30f75da5 3364 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
c5dacb88
SR
3365 $bisect_ret_good = set_test_option("BISECT_RET_GOOD", $i);
3366 $bisect_ret_bad = set_test_option("BISECT_RET_BAD", $i);
3367 $bisect_ret_skip = set_test_option("BISECT_RET_SKIP", $i);
3368 $bisect_ret_abort = set_test_option("BISECT_RET_ABORT", $i);
3369 $bisect_ret_default = set_test_option("BISECT_RET_DEFAULT", $i);
a75fecec 3370 $store_failures = set_test_option("STORE_FAILURES", $i);
de5b6e3b 3371 $store_successes = set_test_option("STORE_SUCCESSES", $i);
9064af52 3372 $test_name = set_test_option("TEST_NAME", $i);
a75fecec
SR
3373 $timeout = set_test_option("TIMEOUT", $i);
3374 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3375 $console = set_test_option("CONSOLE", $i);
f1a5b962 3376 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
a75fecec 3377 $success_line = set_test_option("SUCCESS_LINE", $i);
2b803365 3378 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
1c8a617a
SR
3379 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3380 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
2d01b26a 3381 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
a75fecec 3382 $build_target = set_test_option("BUILD_TARGET", $i);
e48c5293
SR
3383 $ssh_exec = set_test_option("SSH_EXEC", $i);
3384 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
b5f4aea6 3385 $checkout = set_test_option("CHECKOUT", $i);
a75fecec
SR
3386 $target_image = set_test_option("TARGET_IMAGE", $i);
3387 $localversion = set_test_option("LOCALVERSION", $i);
3388
b5f4aea6
SR
3389 $bisect_good = set_test_option("BISECT_GOOD", $i);
3390 $bisect_bad = set_test_option("BISECT_BAD", $i);
3391 $bisect_type = set_test_option("BISECT_TYPE", $i);
3392 $bisect_start = set_test_option("BISECT_START", $i);
3393 $bisect_replay = set_test_option("BISECT_REPLAY", $i);
3394 $bisect_files = set_test_option("BISECT_FILES", $i);
3395 $bisect_reverse = set_test_option("BISECT_REVERSE", $i);
3396 $bisect_check = set_test_option("BISECT_CHECK", $i);
3397
3398 $config_bisect = set_test_option("CONFIG_BISECT", $i);
3399 $config_bisect_type = set_test_option("CONFIG_BISECT_TYPE", $i);
3400
3401 $patchcheck_type = set_test_option("PATCHCHECK_TYPE", $i);
3402 $patchcheck_start = set_test_option("PATCHCHECK_START", $i);
3403 $patchcheck_end = set_test_option("PATCHCHECK_END", $i);
3404
35ce5952
SR
3405 $start_minconfig_defined = 1;
3406
4c4ab120 3407 if (!defined($start_minconfig)) {
35ce5952 3408 $start_minconfig_defined = 0;
4c4ab120
SR
3409 $start_minconfig = $minconfig;
3410 }
3411
a75fecec
SR
3412 chdir $builddir || die "can't change directory to $builddir";
3413
a908a665
AJ
3414 foreach my $dir ($tmpdir, $outputdir) {
3415 if (!-d $dir) {
3416 mkpath($dir) or
3417 die "can't create $dir";
3418 }
a75fecec 3419 }
1a5cfce3 3420
e48c5293
SR
3421 $ENV{"SSH_USER"} = $ssh_user;
3422 $ENV{"MACHINE"} = $machine;
3423
a75fecec 3424 $buildlog = "$tmpdir/buildlog-$machine";
a9dd5d63 3425 $testlog = "$tmpdir/testlog-$machine";
a75fecec
SR
3426 $dmesg = "$tmpdir/dmesg-$machine";
3427 $make = "$makecmd O=$outputdir";
51ad1dd1 3428 $output_config = "$outputdir/.config";
a75fecec 3429
bb8474b1
SR
3430 if (!$buildonly) {
3431 $target = "$ssh_user\@$machine";
3432 if ($reboot_type eq "grub") {
3433 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3434 } elsif (!defined($reboot_script)) {
3435 dodie "REBOOT_SCRIPT not defined"
3436 }
a75fecec
SR
3437 }
3438
3439 my $run_type = $build_type;
3440 if ($test_type eq "patchcheck") {
b5f4aea6 3441 $run_type = $patchcheck_type;
a75fecec 3442 } elsif ($test_type eq "bisect") {
b5f4aea6 3443 $run_type = $bisect_type;
0a05c769 3444 } elsif ($test_type eq "config_bisect") {
b5f4aea6 3445 $run_type = $config_bisect_type;
a75fecec
SR
3446 }
3447
4c4ab120
SR
3448 if ($test_type eq "make_min_config") {
3449 $run_type = "";
3450 }
3451
a75fecec
SR
3452 # mistake in config file?
3453 if (!defined($run_type)) {
3454 $run_type = "ERROR";
3455 }
5a391fbf 3456
e0a8742e
SR
3457 my $installme = "";
3458 $installme = " no_install" if ($no_install);
3459
2545eb61 3460 doprint "\n\n";
e0a8742e 3461 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
7faafbd6
SR
3462
3463 unlink $dmesg;
3464 unlink $buildlog;
a9dd5d63 3465 unlink $testlog;
2545eb61 3466
250bae8b
SR
3467 if (defined($addconfig)) {
3468 my $min = $minconfig;
3469 if (!defined($minconfig)) {
3470 $min = "";
3471 }
3472 run_command "cat $addconfig $min > $tmpdir/add_config" or
2b7d9b21 3473 dodie "Failed to create temp config";
9be2e6b5 3474 $minconfig = "$tmpdir/add_config";
2b7d9b21
SR
3475 }
3476
6c5ee0be
SR
3477 if (defined($checkout)) {
3478 run_command "git checkout $checkout" or
3479 die "failed to checkout $checkout";
3480 }
3481
4ab1cce5
SR
3482 $no_reboot = 0;
3483
3484
a75fecec 3485 if ($test_type eq "bisect") {
5f9b6ced
SR
3486 bisect $i;
3487 next;
0a05c769
SR
3488 } elsif ($test_type eq "config_bisect") {
3489 config_bisect $i;
3490 next;
a75fecec 3491 } elsif ($test_type eq "patchcheck") {
6c5ee0be
SR
3492 patchcheck $i;
3493 next;
4c4ab120
SR
3494 } elsif ($test_type eq "make_min_config") {
3495 make_min_config $i;
3496 next;
2545eb61 3497 }
2545eb61 3498
7faafbd6
SR
3499 if ($build_type ne "nobuild") {
3500 build $build_type or next;
2545eb61
SR
3501 }
3502
cd8e368f
SR
3503 if ($test_type eq "install") {
3504 get_version;
3505 install;
3506 success $i;
3507 next;
3508 }
3509
a75fecec 3510 if ($test_type ne "build") {
a75fecec 3511 my $failed = 0;
ddf607e5 3512 start_monitor_and_boot or $failed = 1;
a75fecec
SR
3513
3514 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3515 do_run_test or $failed = 1;
3516 }
3517 end_monitor;
3518 next if ($failed);
5a391fbf
SR
3519 }
3520
5f9b6ced 3521 success $i;
2545eb61
SR
3522}
3523
5c42fc5b 3524if ($opt{"POWEROFF_ON_SUCCESS"}) {
75c3fda7 3525 halt;
576f627c 3526} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
bc7c5803 3527 reboot_to_good;
5c42fc5b 3528}
75c3fda7 3529
e48c5293
SR
3530doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3531
2545eb61 3532exit 0;