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