blob: 05f429d68857d57468b1456784b8fba310153a2f [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002#
Uwe Kleine-Königcce1dac2011-01-24 21:12:01 +01003# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04004# Licensed under the terms of the GNU GPL License version 2
5#
Steven Rostedt2545eb62010-11-02 15:01:32 -04006
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Steven Rostedt7faafbd2010-11-02 14:58:22 -040010use File::Path qw(mkpath);
11use File::Copy qw(cp);
Steven Rostedt2545eb62010-11-02 15:01:32 -040012use FileHandle;
13
Steven Rostedte48c5292010-11-02 14:35:37 -040014my $VERSION = "0.2";
15
Steven Rostedt2545eb62010-11-02 15:01:32 -040016$| = 1;
17
18my %opt;
Steven Rostedta57419b2010-11-02 15:13:54 -040019my %repeat_tests;
20my %repeats;
Steven Rostedta75fece2010-11-02 14:58:27 -040021my %default;
Steven Rostedt2545eb62010-11-02 15:01:32 -040022
23#default opts
Steven Rostedta57419b2010-11-02 15:13:54 -040024$default{"NUM_TESTS"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040025$default{"TEST_TYPE"} = "test";
26$default{"BUILD_TYPE"} = "randconfig";
27$default{"MAKE_CMD"} = "make";
28$default{"TIMEOUT"} = 120;
Steven Rostedt48920632011-06-14 20:42:19 -040029$default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
Steven Rostedta75fece2010-11-02 14:58:27 -040030$default{"SLEEP_TIME"} = 60; # sleep time between tests
31$default{"BUILD_NOCLEAN"} = 0;
32$default{"REBOOT_ON_ERROR"} = 0;
33$default{"POWEROFF_ON_ERROR"} = 0;
34$default{"REBOOT_ON_SUCCESS"} = 1;
35$default{"POWEROFF_ON_SUCCESS"} = 0;
36$default{"BUILD_OPTIONS"} = "";
37$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
Steven Rostedt27d934b2011-05-20 09:18:18 -040038$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
Steven Rostedta75fece2010-11-02 14:58:27 -040039$default{"CLEAR_LOG"} = 0;
Steven Rostedtc960bb92011-03-08 09:22:39 -050040$default{"BISECT_MANUAL"} = 0;
Steven Rostedtc23dca72011-03-08 09:26:31 -050041$default{"BISECT_SKIP"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040042$default{"SUCCESS_LINE"} = "login:";
Steven Rostedtf1a5b962011-06-13 10:30:00 -040043$default{"DETECT_TRIPLE_FAULT"} = 1;
Steven Rostedte0a87422011-09-30 17:50:48 -040044$default{"NO_INSTALL"} = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040045$default{"BOOTED_TIMEOUT"} = 1;
46$default{"DIE_ON_FAILURE"} = 1;
Steven Rostedte48c5292010-11-02 14:35:37 -040047$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
48$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
49$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
Steven Rostedt1c8a6172010-11-09 12:55:40 -050050$default{"STOP_AFTER_SUCCESS"} = 10;
51$default{"STOP_AFTER_FAILURE"} = 60;
Steven Rostedt2d01b262011-03-08 09:47:54 -050052$default{"STOP_TEST_AFTER"} = 600;
Steven Rostedt600bbf02011-11-21 20:12:04 -050053
54# required, and we will ask users if they don't have them but we keep the default
55# value something that is common.
56$default{"REBOOT_TYPE"} = "grub";
Steven Rostedt8d1491b2010-11-18 15:39:48 -050057$default{"LOCALVERSION"} = "-test";
Steven Rostedt600bbf02011-11-21 20:12:04 -050058$default{"SSH_USER"} = "root";
59$default{"BUILD_TARGET"} = "arch/x86/boot/bzImage";
60$default{"TARGET_IMAGE"} = "/boot/vmlinuz-test";
Steven Rostedt2545eb62010-11-02 15:01:32 -040061
Steven Rostedt8d1491b2010-11-18 15:39:48 -050062my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040063my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040064my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040065my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040066my $tmpdir;
67my $builddir;
68my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050069my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040070my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040071my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040072my $build_options;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040073my $pre_build;
74my $post_build;
75my $pre_build_die;
76my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $reboot_type;
78my $reboot_script;
79my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040080my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040081my $reboot_on_error;
82my $poweroff_on_error;
83my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040084my $powercycle_after_reboot;
85my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040086my $ssh_exec;
87my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040088my $power_off;
89my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040090my $grub_number;
91my $target;
92my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040093my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -040094my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040095my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040096my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040097my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -040098my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040099my $output_minconfig;
100my $ignore_config;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400101my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400102my $in_bisect = 0;
103my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400104my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500105my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500106my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400107my $config_bisect_good;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400108my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400109my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400110my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400111my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530112my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400113my $dmesg;
114my $monitor_fp;
115my $monitor_pid;
116my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400117my $sleep_time;
118my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400119my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400120my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400121my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530122my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400123my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400124my $timeout;
125my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400126my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400127my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400128my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400129my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500130my $stop_after_success;
131my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500132my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400133my $build_target;
134my $target_image;
135my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400136my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400137my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400138
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500139my %entered_configs;
140my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400141my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400142my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500143
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400144# do not force reboots on config problems
145my $no_reboot = 1;
146
Steven Rostedt7bf51072011-10-22 09:07:03 -0400147# default variables that can be used
148chomp ($variable{"PWD"} = `pwd`);
149
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500150$config_help{"MACHINE"} = << "EOF"
151 The machine hostname that you will test.
152EOF
153 ;
154$config_help{"SSH_USER"} = << "EOF"
155 The box is expected to have ssh on normal bootup, provide the user
156 (most likely root, since you need privileged operations)
157EOF
158 ;
159$config_help{"BUILD_DIR"} = << "EOF"
160 The directory that contains the Linux source code (full path).
161EOF
162 ;
163$config_help{"OUTPUT_DIR"} = << "EOF"
164 The directory that the objects will be built (full path).
165 (can not be same as BUILD_DIR)
166EOF
167 ;
168$config_help{"BUILD_TARGET"} = << "EOF"
169 The location of the compiled file to copy to the target.
170 (relative to OUTPUT_DIR)
171EOF
172 ;
173$config_help{"TARGET_IMAGE"} = << "EOF"
174 The place to put your image on the test machine.
175EOF
176 ;
177$config_help{"POWER_CYCLE"} = << "EOF"
178 A script or command to reboot the box.
179
180 Here is a digital loggers power switch example
181 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
182
183 Here is an example to reboot a virtual box on the current host
184 with the name "Guest".
185 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
186EOF
187 ;
188$config_help{"CONSOLE"} = << "EOF"
189 The script or command that reads the console
190
191 If you use ttywatch server, something like the following would work.
192CONSOLE = nc -d localhost 3001
193
194 For a virtual machine with guest name "Guest".
195CONSOLE = virsh console Guest
196EOF
197 ;
198$config_help{"LOCALVERSION"} = << "EOF"
199 Required version ending to differentiate the test
200 from other linux builds on the system.
201EOF
202 ;
203$config_help{"REBOOT_TYPE"} = << "EOF"
204 Way to reboot the box to the test kernel.
205 Only valid options so far are "grub" and "script".
206
207 If you specify grub, it will assume grub version 1
208 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
209 and select that target to reboot to the kernel. If this is not
210 your setup, then specify "script" and have a command or script
211 specified in REBOOT_SCRIPT to boot to the target.
212
213 The entry in /boot/grub/menu.lst must be entered in manually.
214 The test will not modify that file.
215EOF
216 ;
217$config_help{"GRUB_MENU"} = << "EOF"
218 The grub title name for the test kernel to boot
219 (Only mandatory if REBOOT_TYPE = grub)
220
221 Note, ktest.pl will not update the grub menu.lst, you need to
222 manually add an option for the test. ktest.pl will search
223 the grub menu.lst for this option to find what kernel to
224 reboot into.
225
226 For example, if in the /boot/grub/menu.lst the test kernel title has:
227 title Test Kernel
228 kernel vmlinuz-test
229 GRUB_MENU = Test Kernel
230EOF
231 ;
232$config_help{"REBOOT_SCRIPT"} = << "EOF"
233 A script to reboot the target into the test kernel
234 (Only mandatory if REBOOT_TYPE = script)
235EOF
236 ;
237
Steven Rostedt35ce5952011-07-15 21:57:25 -0400238sub read_yn {
239 my ($prompt) = @_;
240
241 my $ans;
242
243 for (;;) {
244 print "$prompt [Y/n] ";
245 $ans = <STDIN>;
246 chomp $ans;
247 if ($ans =~ /^\s*$/) {
248 $ans = "y";
249 }
250 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
251 print "Please answer either 'y' or 'n'.\n";
252 }
253 if ($ans !~ /^y$/i) {
254 return 0;
255 }
256 return 1;
257}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500258
259sub get_ktest_config {
260 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400261 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500262
263 return if (defined($opt{$config}));
264
265 if (defined($config_help{$config})) {
266 print "\n";
267 print $config_help{$config};
268 }
269
270 for (;;) {
271 print "$config = ";
272 if (defined($default{$config})) {
273 print "\[$default{$config}\] ";
274 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400275 $ans = <STDIN>;
276 $ans =~ s/^\s*(.*\S)\s*$/$1/;
277 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500278 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400279 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500280 } else {
281 print "Your answer can not be blank\n";
282 next;
283 }
284 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400285 $entered_configs{$config} = process_variables($ans);
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500286 last;
287 }
288}
289
290sub get_ktest_configs {
291 get_ktest_config("MACHINE");
292 get_ktest_config("SSH_USER");
293 get_ktest_config("BUILD_DIR");
294 get_ktest_config("OUTPUT_DIR");
295 get_ktest_config("BUILD_TARGET");
296 get_ktest_config("TARGET_IMAGE");
297 get_ktest_config("POWER_CYCLE");
298 get_ktest_config("CONSOLE");
299 get_ktest_config("LOCALVERSION");
300
301 my $rtype = $opt{"REBOOT_TYPE"};
302
303 if (!defined($rtype)) {
304 if (!defined($opt{"GRUB_MENU"})) {
305 get_ktest_config("REBOOT_TYPE");
306 $rtype = $entered_configs{"REBOOT_TYPE"};
307 } else {
308 $rtype = "grub";
309 }
310 }
311
312 if ($rtype eq "grub") {
313 get_ktest_config("GRUB_MENU");
314 } else {
315 get_ktest_config("REBOOT_SCRIPT");
316 }
317}
318
Steven Rostedt77d942c2011-05-20 13:36:58 -0400319sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400320 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400321 my $retval = "";
322
323 # We want to check for '\', and it is just easier
324 # to check the previous characet of '$' and not need
325 # to worry if '$' is the first character. By adding
326 # a space to $value, we can just check [^\\]\$ and
327 # it will still work.
328 $value = " $value";
329
330 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
331 my $begin = $1;
332 my $var = $2;
333 my $end = $3;
334 # append beginning of value to retval
335 $retval = "$retval$begin";
336 if (defined($variable{$var})) {
337 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400338 } elsif (defined($remove_undef) && $remove_undef) {
339 # for if statements, any variable that is not defined,
340 # we simple convert to 0
341 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400342 } else {
343 # put back the origin piece.
344 $retval = "$retval\$\{$var\}";
345 }
346 $value = $end;
347 }
348 $retval = "$retval$value";
349
350 # remove the space added in the beginning
351 $retval =~ s/ //;
352
353 return "$retval"
354}
355
Steven Rostedta57419b2010-11-02 15:13:54 -0400356sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400357 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400358
359 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400360 if (!$override || defined(${$overrides}{$lvalue})) {
361 my $extra = "";
362 if ($override) {
363 $extra = "In the same override section!\n";
364 }
365 die "$name: $.: Option $lvalue defined more than once!\n$extra";
366 }
367 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400368 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500369 if ($rvalue =~ /^\s*$/) {
370 delete $opt{$lvalue};
371 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400372 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500373 $opt{$lvalue} = $rvalue;
374 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400375}
376
Steven Rostedt77d942c2011-05-20 13:36:58 -0400377sub set_variable {
378 my ($lvalue, $rvalue) = @_;
379
380 if ($rvalue =~ /^\s*$/) {
381 delete $variable{$lvalue};
382 } else {
383 $rvalue = process_variables($rvalue);
384 $variable{$lvalue} = $rvalue;
385 }
386}
387
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400388sub process_compare {
389 my ($lval, $cmp, $rval) = @_;
390
391 # remove whitespace
392
393 $lval =~ s/^\s*//;
394 $lval =~ s/\s*$//;
395
396 $rval =~ s/^\s*//;
397 $rval =~ s/\s*$//;
398
399 if ($cmp eq "==") {
400 return $lval eq $rval;
401 } elsif ($cmp eq "!=") {
402 return $lval ne $rval;
403 }
404
405 my $statement = "$lval $cmp $rval";
406 my $ret = eval $statement;
407
408 # $@ stores error of eval
409 if ($@) {
410 return -1;
411 }
412
413 return $ret;
414}
415
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400416sub value_defined {
417 my ($val) = @_;
418
419 return defined($variable{$2}) ||
420 defined($opt{$2});
421}
422
Steven Rostedt8d735212011-10-17 11:36:44 -0400423my $d = 0;
424sub process_expression {
425 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400426
Steven Rostedt8d735212011-10-17 11:36:44 -0400427 my $c = $d++;
428
429 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
430 my $express = $1;
431
432 if (process_expression($name, $express)) {
433 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
434 } else {
435 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
436 }
437 }
438
439 $d--;
440 my $OR = "\\|\\|";
441 my $AND = "\\&\\&";
442
443 while ($val =~ s/^(.*?)($OR|$AND)//) {
444 my $express = $1;
445 my $op = $2;
446
447 if (process_expression($name, $express)) {
448 if ($op eq "||") {
449 return 1;
450 }
451 } else {
452 if ($op eq "&&") {
453 return 0;
454 }
455 }
456 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400457
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400458 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
459 my $ret = process_compare($1, $2, $3);
460 if ($ret < 0) {
461 die "$name: $.: Unable to process comparison\n";
462 }
463 return $ret;
464 }
465
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400466 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
467 if (defined $1) {
468 return !value_defined($2);
469 } else {
470 return value_defined($2);
471 }
472 }
473
Steven Rostedt45d73a52011-09-30 19:44:53 -0400474 if ($val =~ /^\s*0\s*$/) {
475 return 0;
476 } elsif ($val =~ /^\s*\d+\s*$/) {
477 return 1;
478 }
479
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400480 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400481}
482
483sub process_if {
484 my ($name, $value) = @_;
485
486 # Convert variables and replace undefined ones with 0
487 my $val = process_variables($value, 1);
488 my $ret = process_expression $name, $val;
489
490 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400491}
492
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400493sub __read_config {
494 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400495
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400496 my $in;
497 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400498
Steven Rostedta57419b2010-11-02 15:13:54 -0400499 my $name = $config;
500 $name =~ s,.*/(.*),$1,;
501
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400502 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400503 my $default = 1;
504 my $repeat = 1;
505 my $num_tests_set = 0;
506 my $skip = 0;
507 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400508 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400509 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400510 my $if = 0;
511 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400512 my $override = 0;
513
514 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400515
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400516 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400517
518 # ignore blank lines and comments
519 next if (/^\s*$/ || /\s*\#/);
520
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400521 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400522
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400523 my $type = $1;
524 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400525 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400526
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400527 my $old_test_num;
528 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400529 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400530
531 if ($type eq "TEST_START") {
532
533 if ($num_tests_set) {
534 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
535 }
536
537 $old_test_num = $test_num;
538 $old_repeat = $repeat;
539
540 $test_num += $repeat;
541 $default = 0;
542 $repeat = 1;
543 } else {
544 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400545 }
546
Steven Rostedta9f84422011-10-17 11:06:29 -0400547 # If SKIP is anywhere in the line, the command will be skipped
548 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400549 $skip = 1;
550 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400551 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400552 $skip = 0;
553 }
554
Steven Rostedta9f84422011-10-17 11:06:29 -0400555 if ($rest =~ s/\sELSE\b//) {
556 if (!$if) {
557 die "$name: $.: ELSE found with out matching IF section\n$_";
558 }
559 $if = 0;
560
561 if ($if_set) {
562 $skip = 1;
563 } else {
564 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400565 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400566 }
567
Steven Rostedta9f84422011-10-17 11:06:29 -0400568 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400569 if (process_if($name, $1)) {
570 $if_set = 1;
571 } else {
572 $skip = 1;
573 }
574 $if = 1;
575 } else {
576 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400577 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400578 }
579
Steven Rostedta9f84422011-10-17 11:06:29 -0400580 if (!$skip) {
581 if ($type eq "TEST_START") {
582 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
583 $repeat = $1;
584 $repeat_tests{"$test_num"} = $repeat;
585 }
586 } elsif ($rest =~ s/\sOVERRIDE\b//) {
587 # DEFAULT only
588 $override = 1;
589 # Clear previous overrides
590 %overrides = ();
591 }
592 }
593
594 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400595 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400596 }
597
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400598 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400599 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400600 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400601 }
602
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400603 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400604 if (!$if) {
605 die "$name: $.: ELSE found with out matching IF section\n$_";
606 }
607 $rest = $1;
608 if ($if_set) {
609 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400610 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400611 } else {
612 $skip = 0;
613
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400614 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400615 # May be a ELSE IF section.
616 if (!process_if($name, $1)) {
617 $skip = 1;
618 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400619 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400620 } else {
621 $if = 0;
622 }
623 }
624
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400625 if ($rest !~ /^\s*$/) {
626 die "$name: $.: Gargbage found after DEFAULTS\n$_";
627 }
628
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400629 } elsif (/^\s*INCLUDE\s+(\S+)/) {
630
631 next if ($skip);
632
633 if (!$default) {
634 die "$name: $.: INCLUDE can only be done in default sections\n$_";
635 }
636
637 my $file = process_variables($1);
638
639 if ($file !~ m,^/,) {
640 # check the path of the config file first
641 if ($config =~ m,(.*)/,) {
642 if (-f "$1/$file") {
643 $file = "$1/$file";
644 }
645 }
646 }
647
648 if ( ! -r $file ) {
649 die "$name: $.: Can't read file $file\n$_";
650 }
651
652 if (__read_config($file, \$test_num)) {
653 $test_case = 1;
654 }
655
Steven Rostedta57419b2010-11-02 15:13:54 -0400656 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
657
658 next if ($skip);
659
Steven Rostedt2545eb62010-11-02 15:01:32 -0400660 my $lvalue = $1;
661 my $rvalue = $2;
662
Steven Rostedta57419b2010-11-02 15:13:54 -0400663 if (!$default &&
664 ($lvalue eq "NUM_TESTS" ||
665 $lvalue eq "LOG_FILE" ||
666 $lvalue eq "CLEAR_LOG")) {
667 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400668 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400669
670 if ($lvalue eq "NUM_TESTS") {
671 if ($test_num) {
672 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
673 }
674 if (!$default) {
675 die "$name: $.: NUM_TESTS must be set in default section\n";
676 }
677 $num_tests_set = 1;
678 }
679
680 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400681 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400682 } else {
683 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400684 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400685
686 if ($repeat > 1) {
687 $repeats{$val} = $repeat;
688 }
689 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400690 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
691 next if ($skip);
692
693 my $lvalue = $1;
694 my $rvalue = $2;
695
696 # process config variables.
697 # Config variables are only active while reading the
698 # config and can be defined anywhere. They also ignore
699 # TEST_START and DEFAULTS, but are skipped if they are in
700 # on of these sections that have SKIP defined.
701 # The save variable can be
702 # defined multiple times and the new one simply overrides
703 # the prevous one.
704 set_variable($lvalue, $rvalue);
705
Steven Rostedta57419b2010-11-02 15:13:54 -0400706 } else {
707 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400708 }
709 }
710
Steven Rostedta57419b2010-11-02 15:13:54 -0400711 if ($test_num) {
712 $test_num += $repeat - 1;
713 $opt{"NUM_TESTS"} = $test_num;
714 }
715
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400716 close($in);
717
718 $$current_test_num = $test_num;
719
720 return $test_case;
721}
722
723sub read_config {
724 my ($config) = @_;
725
726 my $test_case;
727 my $test_num = 0;
728
729 $test_case = __read_config $config, \$test_num;
730
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500731 # make sure we have all mandatory configs
732 get_ktest_configs;
733
Steven Rostedt0df213c2011-06-14 20:51:37 -0400734 # was a test specified?
735 if (!$test_case) {
736 print "No test case specified.\n";
737 print "What test case would you like to run?\n";
738 my $ans = <STDIN>;
739 chomp $ans;
740 $default{"TEST_TYPE"} = $ans;
741 }
742
Steven Rostedta75fece2010-11-02 14:58:27 -0400743 # set any defaults
744
745 foreach my $default (keys %default) {
746 if (!defined($opt{$default})) {
747 $opt{$default} = $default{$default};
748 }
749 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400750}
751
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400752sub __eval_option {
753 my ($option, $i) = @_;
754
755 # Add space to evaluate the character before $
756 $option = " $option";
757 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530758 my $repeated = 0;
759 my $parent = 0;
760
761 foreach my $test (keys %repeat_tests) {
762 if ($i >= $test &&
763 $i < $test + $repeat_tests{$test}) {
764
765 $repeated = 1;
766 $parent = $test;
767 last;
768 }
769 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400770
771 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
772 my $start = $1;
773 my $var = $2;
774 my $end = $3;
775
776 # Append beginning of line
777 $retval = "$retval$start";
778
779 # If the iteration option OPT[$i] exists, then use that.
780 # otherwise see if the default OPT (without [$i]) exists.
781
782 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530783 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400784
785 if (defined($opt{$o})) {
786 $o = $opt{$o};
787 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530788 } elsif ($repeated && defined($opt{$parento})) {
789 $o = $opt{$parento};
790 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400791 } elsif (defined($opt{$var})) {
792 $o = $opt{$var};
793 $retval = "$retval$o";
794 } else {
795 $retval = "$retval\$\{$var\}";
796 }
797
798 $option = $end;
799 }
800
801 $retval = "$retval$option";
802
803 $retval =~ s/^ //;
804
805 return $retval;
806}
807
808sub eval_option {
809 my ($option, $i) = @_;
810
811 my $prev = "";
812
813 # Since an option can evaluate to another option,
814 # keep iterating until we do not evaluate any more
815 # options.
816 my $r = 0;
817 while ($prev ne $option) {
818 # Check for recursive evaluations.
819 # 100 deep should be more than enough.
820 if ($r++ > 100) {
821 die "Over 100 evaluations accurred with $option\n" .
822 "Check for recursive variables\n";
823 }
824 $prev = $option;
825 $option = __eval_option($option, $i);
826 }
827
828 return $option;
829}
830
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500831sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400832 if (defined($opt{"LOG_FILE"})) {
833 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
834 print OUT @_;
835 close(OUT);
836 }
837}
838
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500839sub logit {
840 if (defined($opt{"LOG_FILE"})) {
841 _logit @_;
842 } else {
843 print @_;
844 }
845}
846
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400847sub doprint {
848 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500849 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400850}
851
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400852sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200853sub start_monitor;
854sub end_monitor;
855sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400856
857sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200858 my ($time) = @_;
859
Steven Rostedt2b803362011-09-30 18:00:23 -0400860 if (defined($time)) {
861 start_monitor;
862 # flush out current monitor
863 # May contain the reboot success line
864 wait_for_monitor 1;
865 }
866
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400867 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400868 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400869 if (defined($powercycle_after_reboot)) {
870 sleep $powercycle_after_reboot;
871 run_command "$power_cycle";
872 }
873 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400874 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400875 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400876 }
Andrew Jones2728be42011-08-12 15:32:05 +0200877
878 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400879 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200880 end_monitor;
881 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400882}
883
Steven Rostedt576f6272010-11-02 14:58:38 -0400884sub do_not_reboot {
885 my $i = $iteration;
886
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400887 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400888 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
889 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
890}
891
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400892sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400893 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400894
Steven Rostedt576f6272010-11-02 14:58:38 -0400895 my $i = $iteration;
896
897 if ($reboot_on_error && !do_not_reboot) {
898
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400899 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400900 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400901
Steven Rostedta75fece2010-11-02 14:58:27 -0400902 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400903 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400904 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400905 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400906
Steven Rostedtf80802c2011-03-07 13:18:47 -0500907 if (defined($opt{"LOG_FILE"})) {
908 print " See $opt{LOG_FILE} for more info.\n";
909 }
910
Steven Rostedt576f6272010-11-02 14:58:38 -0400911 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400912}
913
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400914sub open_console {
915 my ($fp) = @_;
916
917 my $flags;
918
Steven Rostedta75fece2010-11-02 14:58:27 -0400919 my $pid = open($fp, "$console|") or
920 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400921
922 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400923 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400924 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400925 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400926
927 return $pid;
928}
929
930sub close_console {
931 my ($fp, $pid) = @_;
932
933 doprint "kill child process $pid\n";
934 kill 2, $pid;
935
936 print "closing!\n";
937 close($fp);
938}
939
940sub start_monitor {
941 if ($monitor_cnt++) {
942 return;
943 }
944 $monitor_fp = \*MONFD;
945 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400946
947 return;
948
949 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400950}
951
952sub end_monitor {
953 if (--$monitor_cnt) {
954 return;
955 }
956 close_console($monitor_fp, $monitor_pid);
957}
958
959sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -0400960 my ($time, $stop) = @_;
961 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400962 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -0400963 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400964
Steven Rostedta75fece2010-11-02 14:58:27 -0400965 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400966
967 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -0400968 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400969 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -0400970 last if (!defined($line));
971 print "$line";
972 $full_line .= $line;
973
974 if (defined($stop) && $full_line =~ /$stop/) {
975 doprint "wait for monitor detected $stop\n";
976 $booted = 1;
977 }
978
979 if ($line =~ /\n/) {
980 $full_line = "";
981 }
982 }
Steven Rostedta75fece2010-11-02 14:58:27 -0400983 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400984}
985
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530986sub save_logs {
987 my ($result, $basedir) = @_;
988 my @t = localtime;
989 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
990 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
991
992 my $type = $build_type;
993 if ($type =~ /useconfig/) {
994 $type = "useconfig";
995 }
996
997 my $dir = "$machine-$test_type-$type-$result-$date";
998
999 $dir = "$basedir/$dir";
1000
1001 if (!-d $dir) {
1002 mkpath($dir) or
1003 die "can't create $dir";
1004 }
1005
1006 my %files = (
1007 "config" => $output_config,
1008 "buildlog" => $buildlog,
1009 "dmesg" => $dmesg,
1010 "testlog" => $testlog,
1011 );
1012
1013 while (my ($name, $source) = each(%files)) {
1014 if (-f "$source") {
1015 cp "$source", "$dir/$name" or
1016 die "failed to copy $source";
1017 }
1018 }
1019
1020 doprint "*** Saved info to $dir ***\n";
1021}
1022
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001023sub fail {
1024
Steven Rostedta75fece2010-11-02 14:58:27 -04001025 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001026 dodie @_;
1027 }
1028
Steven Rostedta75fece2010-11-02 14:58:27 -04001029 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001030
Steven Rostedt576f6272010-11-02 14:58:38 -04001031 my $i = $iteration;
1032
Steven Rostedta75fece2010-11-02 14:58:27 -04001033 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001034 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001035 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001036 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001037 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001038
Steven Rostedt9064af52011-06-13 10:38:48 -04001039 my $name = "";
1040
1041 if (defined($test_name)) {
1042 $name = " ($test_name)";
1043 }
1044
Steven Rostedt576f6272010-11-02 14:58:38 -04001045 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1046 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001047 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001048 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1049 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001050
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301051 if (defined($store_failures)) {
1052 save_logs "fail", $store_failures;
1053 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001054
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001055 return 1;
1056}
1057
Steven Rostedt2545eb62010-11-02 15:01:32 -04001058sub run_command {
1059 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001060 my $dolog = 0;
1061 my $dord = 0;
1062 my $pid;
1063
Steven Rostedte48c5292010-11-02 14:35:37 -04001064 $command =~ s/\$SSH_USER/$ssh_user/g;
1065 $command =~ s/\$MACHINE/$machine/g;
1066
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001067 doprint("$command ... ");
1068
1069 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001070 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001071
1072 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001073 open(LOG, ">>$opt{LOG_FILE}") or
1074 dodie "failed to write to log";
1075 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001076 }
1077
1078 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001079 open (RD, ">$redirect") or
1080 dodie "failed to write to redirect $redirect";
1081 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001082 }
1083
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001084 while (<CMD>) {
1085 print LOG if ($dolog);
1086 print RD if ($dord);
1087 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001088
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001089 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001090 my $failed = $?;
1091
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001092 close(CMD);
1093 close(LOG) if ($dolog);
1094 close(RD) if ($dord);
1095
Steven Rostedt2545eb62010-11-02 15:01:32 -04001096 if ($failed) {
1097 doprint "FAILED!\n";
1098 } else {
1099 doprint "SUCCESS\n";
1100 }
1101
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001102 return !$failed;
1103}
1104
Steven Rostedte48c5292010-11-02 14:35:37 -04001105sub run_ssh {
1106 my ($cmd) = @_;
1107 my $cp_exec = $ssh_exec;
1108
1109 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1110 return run_command "$cp_exec";
1111}
1112
1113sub run_scp {
1114 my ($src, $dst) = @_;
1115 my $cp_scp = $scp_to_target;
1116
1117 $cp_scp =~ s/\$SRC_FILE/$src/g;
1118 $cp_scp =~ s/\$DST_FILE/$dst/g;
1119
1120 return run_command "$cp_scp";
1121}
1122
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001123sub get_grub_index {
1124
Steven Rostedta75fece2010-11-02 14:58:27 -04001125 if ($reboot_type ne "grub") {
1126 return;
1127 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001128 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001129
1130 doprint "Find grub menu ... ";
1131 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001132
1133 my $ssh_grub = $ssh_exec;
1134 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1135
1136 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001137 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001138
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001139 my $found = 0;
1140
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001141 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001142 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001143 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001144 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001145 last;
1146 } elsif (/^\s*title\s/) {
1147 $grub_number++;
1148 }
1149 }
1150 close(IN);
1151
Steven Rostedta75fece2010-11-02 14:58:27 -04001152 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001153 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001154 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001155}
1156
Steven Rostedt2545eb62010-11-02 15:01:32 -04001157sub wait_for_input
1158{
1159 my ($fp, $time) = @_;
1160 my $rin;
1161 my $ready;
1162 my $line;
1163 my $ch;
1164
1165 if (!defined($time)) {
1166 $time = $timeout;
1167 }
1168
1169 $rin = '';
1170 vec($rin, fileno($fp), 1) = 1;
1171 $ready = select($rin, undef, undef, $time);
1172
1173 $line = "";
1174
1175 # try to read one char at a time
1176 while (sysread $fp, $ch, 1) {
1177 $line .= $ch;
1178 last if ($ch eq "\n");
1179 }
1180
1181 if (!length($line)) {
1182 return undef;
1183 }
1184
1185 return $line;
1186}
1187
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001188sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001189 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001190 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1191 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001192 return;
1193 }
1194
1195 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001196}
1197
Steven Rostedta57419b2010-11-02 15:13:54 -04001198sub get_sha1 {
1199 my ($commit) = @_;
1200
1201 doprint "git rev-list --max-count=1 $commit ... ";
1202 my $sha1 = `git rev-list --max-count=1 $commit`;
1203 my $ret = $?;
1204
1205 logit $sha1;
1206
1207 if ($ret) {
1208 doprint "FAILED\n";
1209 dodie "Failed to get git $commit";
1210 }
1211
1212 print "SUCCESS\n";
1213
1214 chomp $sha1;
1215
1216 return $sha1;
1217}
1218
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001219sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001220 my $booted = 0;
1221 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001222 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001223 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001224
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001225 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001226
1227 my $line;
1228 my $full_line = "";
1229
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001230 open(DMESG, "> $dmesg") or
1231 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001232
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001233 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001234
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001235 my $success_start;
1236 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001237 my $monitor_start = time;
1238 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001239 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001240
Steven Rostedt2d01b262011-03-08 09:47:54 -05001241 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001242
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001243 if ($bug && defined($stop_after_failure) &&
1244 $stop_after_failure >= 0) {
1245 my $time = $stop_after_failure - (time - $failure_start);
1246 $line = wait_for_input($monitor_fp, $time);
1247 if (!defined($line)) {
1248 doprint "bug timed out after $booted_timeout seconds\n";
1249 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1250 last;
1251 }
1252 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001253 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001254 if (!defined($line)) {
1255 my $s = $booted_timeout == 1 ? "" : "s";
1256 doprint "Successful boot found: break after $booted_timeout second$s\n";
1257 last;
1258 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001259 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001260 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001261 if (!defined($line)) {
1262 my $s = $timeout == 1 ? "" : "s";
1263 doprint "Timed out after $timeout second$s\n";
1264 last;
1265 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001266 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001267
Steven Rostedt2545eb62010-11-02 15:01:32 -04001268 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001269 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001270
1271 # we are not guaranteed to get a full line
1272 $full_line .= $line;
1273
Steven Rostedta75fece2010-11-02 14:58:27 -04001274 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001275 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001276 $success_start = time;
1277 }
1278
1279 if ($booted && defined($stop_after_success) &&
1280 $stop_after_success >= 0) {
1281 my $now = time;
1282 if ($now - $success_start >= $stop_after_success) {
1283 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1284 last;
1285 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001286 }
1287
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001288 if ($full_line =~ /\[ backtrace testing \]/) {
1289 $skip_call_trace = 1;
1290 }
1291
Steven Rostedt2545eb62010-11-02 15:01:32 -04001292 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001293 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001294 $bug = 1;
1295 $failure_start = time;
1296 }
1297 }
1298
1299 if ($bug && defined($stop_after_failure) &&
1300 $stop_after_failure >= 0) {
1301 my $now = time;
1302 if ($now - $failure_start >= $stop_after_failure) {
1303 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1304 last;
1305 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001306 }
1307
1308 if ($full_line =~ /\[ end of backtrace testing \]/) {
1309 $skip_call_trace = 0;
1310 }
1311
1312 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001313 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001314 $bug = 1;
1315 }
1316
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001317 # Detect triple faults by testing the banner
1318 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1319 if ($1 eq $version) {
1320 $version_found = 1;
1321 } elsif ($version_found && $detect_triplefault) {
1322 # We already booted into the kernel we are testing,
1323 # but now we booted into another kernel?
1324 # Consider this a triple fault.
1325 doprint "Aleady booted in Linux kernel $version, but now\n";
1326 doprint "we booted into Linux kernel $1.\n";
1327 doprint "Assuming that this is a triple fault.\n";
1328 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1329 last;
1330 }
1331 }
1332
Steven Rostedt2545eb62010-11-02 15:01:32 -04001333 if ($line =~ /\n/) {
1334 $full_line = "";
1335 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001336
1337 if ($stop_test_after > 0 && !$booted && !$bug) {
1338 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001339 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001340 $done = 1;
1341 }
1342 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001343 }
1344
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001345 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001346
Steven Rostedt2545eb62010-11-02 15:01:32 -04001347 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001348 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001349 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001350 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001351
Steven Rostedta75fece2010-11-02 14:58:27 -04001352 if (!$booted) {
1353 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001354 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001355 }
1356
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001357 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001358}
1359
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001360sub do_post_install {
1361
1362 return if (!defined($post_install));
1363
1364 my $cp_post_install = $post_install;
1365 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1366 run_command "$cp_post_install" or
1367 dodie "Failed to run post install";
1368}
1369
Steven Rostedt2545eb62010-11-02 15:01:32 -04001370sub install {
1371
Steven Rostedte0a87422011-09-30 17:50:48 -04001372 return if ($no_install);
1373
Steven Rostedte48c5292010-11-02 14:35:37 -04001374 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001375 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001376
1377 my $install_mods = 0;
1378
1379 # should we process modules?
1380 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001381 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001382 while (<IN>) {
1383 if (/CONFIG_MODULES(=y)?/) {
1384 $install_mods = 1 if (defined($1));
1385 last;
1386 }
1387 }
1388 close(IN);
1389
1390 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001391 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001392 doprint "No modules needed\n";
1393 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001394 }
1395
Steven Rostedta75fece2010-11-02 14:58:27 -04001396 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001397 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001398
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001399 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001400 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001401
Steven Rostedte48c5292010-11-02 14:35:37 -04001402 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001403 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001404
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001405 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001406 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001407 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001408
Steven Rostedte48c5292010-11-02 14:35:37 -04001409 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001410 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001411
Steven Rostedta75fece2010-11-02 14:58:27 -04001412 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001413
Steven Rostedte7b13442011-06-14 20:44:36 -04001414 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001415 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001416
Steven Rostedte48c5292010-11-02 14:35:37 -04001417 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001418
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001419 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001420}
1421
Steven Rostedtddf607e2011-06-14 20:49:13 -04001422sub get_version {
1423 # get the release name
1424 doprint "$make kernelrelease ... ";
1425 $version = `$make kernelrelease | tail -1`;
1426 chomp($version);
1427 doprint "$version\n";
1428}
1429
1430sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001431 # Make sure the stable kernel has finished booting
1432 start_monitor;
1433 wait_for_monitor 5;
1434 end_monitor;
1435
Steven Rostedtddf607e2011-06-14 20:49:13 -04001436 get_grub_index;
1437 get_version;
1438 install;
1439
1440 start_monitor;
1441 return monitor;
1442}
1443
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001444sub check_buildlog {
1445 my ($patch) = @_;
1446
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001447 my @files = `git show $patch | diffstat -l`;
1448
1449 open(IN, "git show $patch |") or
1450 dodie "failed to show $patch";
1451 while (<IN>) {
1452 if (m,^--- a/(.*),) {
1453 chomp $1;
1454 $files[$#files] = $1;
1455 }
1456 }
1457 close(IN);
1458
1459 open(IN, $buildlog) or dodie "Can't open $buildlog";
1460 while (<IN>) {
1461 if (/^\s*(.*?):.*(warning|error)/) {
1462 my $err = $1;
1463 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001464 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001465 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001466 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001467 }
1468 }
1469 }
1470 }
1471 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001472
1473 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001474}
1475
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001476sub apply_min_config {
1477 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001478
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001479 # Read the config file and remove anything that
1480 # is in the force_config hash (from minconfig and others)
1481 # then add the force config back.
1482
1483 doprint "Applying minimum configurations into $output_config.new\n";
1484
1485 open (OUT, ">$outconfig") or
1486 dodie "Can't create $outconfig";
1487
1488 if (-f $output_config) {
1489 open (IN, $output_config) or
1490 dodie "Failed to open $output_config";
1491 while (<IN>) {
1492 if (/^(# )?(CONFIG_[^\s=]*)/) {
1493 next if (defined($force_config{$2}));
1494 }
1495 print OUT;
1496 }
1497 close IN;
1498 }
1499 foreach my $config (keys %force_config) {
1500 print OUT "$force_config{$config}\n";
1501 }
1502 close OUT;
1503
1504 run_command "mv $outconfig $output_config";
1505}
1506
1507sub make_oldconfig {
1508
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001509 my @force_list = keys %force_config;
1510
1511 if ($#force_list >= 0) {
1512 apply_min_config;
1513 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001514
1515 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001516 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1517 # try a yes '' | oldconfig
1518 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001519 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001520 dodie "failed make config oldconfig";
1521 }
1522}
1523
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001524# read a config file and use this to force new configs.
1525sub load_force_config {
1526 my ($config) = @_;
1527
1528 open(IN, $config) or
1529 dodie "failed to read $config";
1530 while (<IN>) {
1531 chomp;
1532 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1533 $force_config{$1} = $_;
1534 } elsif (/^# (CONFIG_\S*) is not set/) {
1535 $force_config{$1} = $_;
1536 }
1537 }
1538 close IN;
1539}
1540
Steven Rostedt2545eb62010-11-02 15:01:32 -04001541sub build {
1542 my ($type) = @_;
1543
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001544 unlink $buildlog;
1545
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001546 # Failed builds should not reboot the target
1547 my $save_no_reboot = $no_reboot;
1548 $no_reboot = 1;
1549
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001550 if (defined($pre_build)) {
1551 my $ret = run_command $pre_build;
1552 if (!$ret && defined($pre_build_die) &&
1553 $pre_build_die) {
1554 dodie "failed to pre_build\n";
1555 }
1556 }
1557
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001558 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001559 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001560 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001561
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001562 $type = "oldconfig";
1563 }
1564
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001565 # old config can ask questions
1566 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001567 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001568
1569 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001570 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001571
Andrew Jones13488232011-08-12 15:32:04 +02001572 if (!$noclean) {
1573 run_command "mv $output_config $outputdir/config_temp" or
1574 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001575
Andrew Jones13488232011-08-12 15:32:04 +02001576 run_command "$make mrproper" or dodie "make mrproper";
1577
1578 run_command "mv $outputdir/config_temp $output_config" or
1579 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001580 }
1581
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001582 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001583 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001584 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001585 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001586 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001587
1588 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001589 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1590 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001591 close(OUT);
1592
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001593 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001594 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001595 }
1596
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001597 if ($type ne "oldnoconfig") {
1598 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001599 dodie "failed make config";
1600 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001601 # Run old config regardless, to enforce min configurations
1602 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001603
Steven Rostedta75fece2010-11-02 14:58:27 -04001604 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001605 my $build_ret = run_command "$make $build_options";
1606 undef $redirect;
1607
1608 if (defined($post_build)) {
1609 my $ret = run_command $post_build;
1610 if (!$ret && defined($post_build_die) &&
1611 $post_build_die) {
1612 dodie "failed to post_build\n";
1613 }
1614 }
1615
1616 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001617 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001618 if ($in_bisect) {
1619 $no_reboot = $save_no_reboot;
1620 return 0;
1621 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001622 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001623 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001624
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001625 $no_reboot = $save_no_reboot;
1626
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001627 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001628}
1629
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001630sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001631 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001632 if (defined($poweroff_after_halt)) {
1633 sleep $poweroff_after_halt;
1634 run_command "$power_off";
1635 }
1636 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001637 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001638 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001639 }
1640}
1641
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001642sub success {
1643 my ($i) = @_;
1644
Steven Rostedte48c5292010-11-02 14:35:37 -04001645 $successes++;
1646
Steven Rostedt9064af52011-06-13 10:38:48 -04001647 my $name = "";
1648
1649 if (defined($test_name)) {
1650 $name = " ($test_name)";
1651 }
1652
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001653 doprint "\n\n*******************************************\n";
1654 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001655 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001656 doprint "*******************************************\n";
1657 doprint "*******************************************\n";
1658
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301659 if (defined($store_successes)) {
1660 save_logs "success", $store_successes;
1661 }
1662
Steven Rostedt576f6272010-11-02 14:58:38 -04001663 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001664 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001665 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001666 }
1667}
1668
Steven Rostedtc960bb92011-03-08 09:22:39 -05001669sub answer_bisect {
1670 for (;;) {
1671 doprint "Pass or fail? [p/f]";
1672 my $ans = <STDIN>;
1673 chomp $ans;
1674 if ($ans eq "p" || $ans eq "P") {
1675 return 1;
1676 } elsif ($ans eq "f" || $ans eq "F") {
1677 return 0;
1678 } else {
1679 print "Please answer 'P' or 'F'\n";
1680 }
1681 }
1682}
1683
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001684sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001685 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001686
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001687 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001688 $reboot_on_error = 0;
1689 $poweroff_on_error = 0;
1690 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001691
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301692 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001693 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301694 undef $redirect;
1695
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001696 exit $failed;
1697}
1698
1699my $child_done;
1700
1701sub child_finished {
1702 $child_done = 1;
1703}
1704
1705sub do_run_test {
1706 my $child_pid;
1707 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001708 my $line;
1709 my $full_line;
1710 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001711
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001712 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001713
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001714 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001715
1716 $child_done = 0;
1717
1718 $SIG{CHLD} = qw(child_finished);
1719
1720 $child_pid = fork;
1721
1722 child_run_test if (!$child_pid);
1723
1724 $full_line = "";
1725
1726 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001727 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001728 if (defined($line)) {
1729
1730 # we are not guaranteed to get a full line
1731 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001732 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001733
1734 if ($full_line =~ /call trace:/i) {
1735 $bug = 1;
1736 }
1737
1738 if ($full_line =~ /Kernel panic -/) {
1739 $bug = 1;
1740 }
1741
1742 if ($line =~ /\n/) {
1743 $full_line = "";
1744 }
1745 }
1746 } while (!$child_done && !$bug);
1747
1748 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001749 my $failure_start = time;
1750 my $now;
1751 do {
1752 $line = wait_for_input($monitor_fp, 1);
1753 if (defined($line)) {
1754 doprint $line;
1755 }
1756 $now = time;
1757 if ($now - $failure_start >= $stop_after_failure) {
1758 last;
1759 }
1760 } while (defined($line));
1761
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001762 doprint "Detected kernel crash!\n";
1763 # kill the child with extreme prejudice
1764 kill 9, $child_pid;
1765 }
1766
1767 waitpid $child_pid, 0;
1768 $child_exit = $?;
1769
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001770 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001771 return 0 if $in_bisect;
1772 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001773 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001774 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001775}
1776
Steven Rostedta75fece2010-11-02 14:58:27 -04001777sub run_git_bisect {
1778 my ($command) = @_;
1779
1780 doprint "$command ... ";
1781
1782 my $output = `$command 2>&1`;
1783 my $ret = $?;
1784
1785 logit $output;
1786
1787 if ($ret) {
1788 doprint "FAILED\n";
1789 dodie "Failed to git bisect";
1790 }
1791
1792 doprint "SUCCESS\n";
1793 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1794 doprint "$1 [$2]\n";
1795 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1796 $bisect_bad = $1;
1797 doprint "Found bad commit... $1\n";
1798 return 0;
1799 } else {
1800 # we already logged it, just print it now.
1801 print $output;
1802 }
1803
1804 return 1;
1805}
1806
Steven Rostedtc23dca72011-03-08 09:26:31 -05001807sub bisect_reboot {
1808 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001809 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001810}
1811
1812# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001813sub run_bisect_test {
1814 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001815
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001816 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001817 my $result;
1818 my $output;
1819 my $ret;
1820
Steven Rostedt0a05c762010-11-08 11:14:10 -05001821 $in_bisect = 1;
1822
1823 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001824
1825 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001826 if ($failed && $bisect_skip) {
1827 $in_bisect = 0;
1828 return -1;
1829 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001830 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001831
1832 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001833 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001834
1835 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001836 if ($failed && $bisect_skip) {
1837 end_monitor;
1838 bisect_reboot;
1839 $in_bisect = 0;
1840 return -1;
1841 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001842 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001843
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001844 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001845 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001846 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001847 }
1848
1849 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001850 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001851 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001852 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001853 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001854
1855 # reboot the box to a kernel we can ssh to
1856 if ($type ne "build") {
1857 bisect_reboot;
1858 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001859 $in_bisect = 0;
1860
1861 return $result;
1862}
1863
1864sub run_bisect {
1865 my ($type) = @_;
1866 my $buildtype = "oldconfig";
1867
1868 # We should have a minconfig to use?
1869 if (defined($minconfig)) {
1870 $buildtype = "useconfig:$minconfig";
1871 }
1872
1873 my $ret = run_bisect_test $type, $buildtype;
1874
Steven Rostedtc960bb92011-03-08 09:22:39 -05001875 if ($bisect_manual) {
1876 $ret = answer_bisect;
1877 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001878
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001879 # Are we looking for where it worked, not failed?
1880 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001881 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001882 }
1883
Steven Rostedtc23dca72011-03-08 09:26:31 -05001884 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001885 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001886 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001887 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001888 } elsif ($bisect_skip) {
1889 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1890 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001891 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001892}
1893
1894sub bisect {
1895 my ($i) = @_;
1896
1897 my $result;
1898
1899 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1900 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1901 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1902
1903 my $good = $opt{"BISECT_GOOD[$i]"};
1904 my $bad = $opt{"BISECT_BAD[$i]"};
1905 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001906 my $start = $opt{"BISECT_START[$i]"};
1907 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001908 my $start_files = $opt{"BISECT_FILES[$i]"};
1909
1910 if (defined($start_files)) {
1911 $start_files = " -- " . $start_files;
1912 } else {
1913 $start_files = "";
1914 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001915
Steven Rostedta57419b2010-11-02 15:13:54 -04001916 # convert to true sha1's
1917 $good = get_sha1($good);
1918 $bad = get_sha1($bad);
1919
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001920 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1921 $opt{"BISECT_REVERSE[$i]"} == 1) {
1922 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1923 $reverse_bisect = 1;
1924 } else {
1925 $reverse_bisect = 0;
1926 }
1927
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001928 # Can't have a test without having a test to run
1929 if ($type eq "test" && !defined($run_test)) {
1930 $type = "boot";
1931 }
1932
Steven Rostedta75fece2010-11-02 14:58:27 -04001933 my $check = $opt{"BISECT_CHECK[$i]"};
1934 if (defined($check) && $check ne "0") {
1935
1936 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001937 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001938
1939 if ($check ne "good") {
1940 doprint "TESTING BISECT BAD [$bad]\n";
1941 run_command "git checkout $bad" or
1942 die "Failed to checkout $bad";
1943
1944 $result = run_bisect $type;
1945
1946 if ($result ne "bad") {
1947 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1948 }
1949 }
1950
1951 if ($check ne "bad") {
1952 doprint "TESTING BISECT GOOD [$good]\n";
1953 run_command "git checkout $good" or
1954 die "Failed to checkout $good";
1955
1956 $result = run_bisect $type;
1957
1958 if ($result ne "good") {
1959 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1960 }
1961 }
1962
1963 # checkout where we started
1964 run_command "git checkout $head" or
1965 die "Failed to checkout $head";
1966 }
1967
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001968 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001969 dodie "could not start bisect";
1970
1971 run_command "git bisect good $good" or
1972 dodie "could not set bisect good to $good";
1973
1974 run_git_bisect "git bisect bad $bad" or
1975 dodie "could not set bisect bad to $bad";
1976
1977 if (defined($replay)) {
1978 run_command "git bisect replay $replay" or
1979 dodie "failed to run replay";
1980 }
1981
1982 if (defined($start)) {
1983 run_command "git checkout $start" or
1984 dodie "failed to checkout $start";
1985 }
1986
1987 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001988 do {
1989 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001990 $test = run_git_bisect "git bisect $result";
1991 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001992
1993 run_command "git bisect log" or
1994 dodie "could not capture git bisect log";
1995
1996 run_command "git bisect reset" or
1997 dodie "could not reset git bisect";
1998
1999 doprint "Bad commit was [$bisect_bad]\n";
2000
Steven Rostedt0a05c762010-11-08 11:14:10 -05002001 success $i;
2002}
2003
2004my %config_ignore;
2005my %config_set;
2006
2007my %config_list;
2008my %null_config;
2009
2010my %dependency;
2011
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002012sub assign_configs {
2013 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002014
2015 open (IN, $config)
2016 or dodie "Failed to read $config";
2017
2018 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002019 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002020 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002021 }
2022 }
2023
2024 close(IN);
2025}
2026
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002027sub process_config_ignore {
2028 my ($config) = @_;
2029
2030 assign_configs \%config_ignore, $config;
2031}
2032
Steven Rostedt0a05c762010-11-08 11:14:10 -05002033sub read_current_config {
2034 my ($config_ref) = @_;
2035
2036 %{$config_ref} = ();
2037 undef %{$config_ref};
2038
2039 my @key = keys %{$config_ref};
2040 if ($#key >= 0) {
2041 print "did not delete!\n";
2042 exit;
2043 }
2044 open (IN, "$output_config");
2045
2046 while (<IN>) {
2047 if (/^(CONFIG\S+)=(.*)/) {
2048 ${$config_ref}{$1} = $2;
2049 }
2050 }
2051 close(IN);
2052}
2053
2054sub get_dependencies {
2055 my ($config) = @_;
2056
2057 my $arr = $dependency{$config};
2058 if (!defined($arr)) {
2059 return ();
2060 }
2061
2062 my @deps = @{$arr};
2063
2064 foreach my $dep (@{$arr}) {
2065 print "ADD DEP $dep\n";
2066 @deps = (@deps, get_dependencies $dep);
2067 }
2068
2069 return @deps;
2070}
2071
2072sub create_config {
2073 my @configs = @_;
2074
2075 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2076
2077 foreach my $config (@configs) {
2078 print OUT "$config_set{$config}\n";
2079 my @deps = get_dependencies $config;
2080 foreach my $dep (@deps) {
2081 print OUT "$config_set{$dep}\n";
2082 }
2083 }
2084
2085 foreach my $config (keys %config_ignore) {
2086 print OUT "$config_ignore{$config}\n";
2087 }
2088 close(OUT);
2089
2090# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002091 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002092}
2093
2094sub compare_configs {
2095 my (%a, %b) = @_;
2096
2097 foreach my $item (keys %a) {
2098 if (!defined($b{$item})) {
2099 print "diff $item\n";
2100 return 1;
2101 }
2102 delete $b{$item};
2103 }
2104
2105 my @keys = keys %b;
2106 if ($#keys) {
2107 print "diff2 $keys[0]\n";
2108 }
2109 return -1 if ($#keys >= 0);
2110
2111 return 0;
2112}
2113
2114sub run_config_bisect_test {
2115 my ($type) = @_;
2116
2117 return run_bisect_test $type, "oldconfig";
2118}
2119
2120sub process_passed {
2121 my (%configs) = @_;
2122
2123 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2124 # Passed! All these configs are part of a good compile.
2125 # Add them to the min options.
2126 foreach my $config (keys %configs) {
2127 if (defined($config_list{$config})) {
2128 doprint " removing $config\n";
2129 $config_ignore{$config} = $config_list{$config};
2130 delete $config_list{$config};
2131 }
2132 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002133 doprint "config copied to $outputdir/config_good\n";
2134 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002135}
2136
2137sub process_failed {
2138 my ($config) = @_;
2139
2140 doprint "\n\n***************************************\n";
2141 doprint "Found bad config: $config\n";
2142 doprint "***************************************\n\n";
2143}
2144
2145sub run_config_bisect {
2146
2147 my @start_list = keys %config_list;
2148
2149 if ($#start_list < 0) {
2150 doprint "No more configs to test!!!\n";
2151 return -1;
2152 }
2153
2154 doprint "***** RUN TEST ***\n";
2155 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2156 my $ret;
2157 my %current_config;
2158
2159 my $count = $#start_list + 1;
2160 doprint " $count configs to test\n";
2161
2162 my $half = int($#start_list / 2);
2163
2164 do {
2165 my @tophalf = @start_list[0 .. $half];
2166
2167 create_config @tophalf;
2168 read_current_config \%current_config;
2169
2170 $count = $#tophalf + 1;
2171 doprint "Testing $count configs\n";
2172 my $found = 0;
2173 # make sure we test something
2174 foreach my $config (@tophalf) {
2175 if (defined($current_config{$config})) {
2176 logit " $config\n";
2177 $found = 1;
2178 }
2179 }
2180 if (!$found) {
2181 # try the other half
2182 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002183 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002184 create_config @tophalf;
2185 read_current_config \%current_config;
2186 foreach my $config (@tophalf) {
2187 if (defined($current_config{$config})) {
2188 logit " $config\n";
2189 $found = 1;
2190 }
2191 }
2192 if (!$found) {
2193 doprint "Failed: Can't make new config with current configs\n";
2194 foreach my $config (@start_list) {
2195 doprint " CONFIG: $config\n";
2196 }
2197 return -1;
2198 }
2199 $count = $#tophalf + 1;
2200 doprint "Testing $count configs\n";
2201 }
2202
2203 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002204 if ($bisect_manual) {
2205 $ret = answer_bisect;
2206 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002207 if ($ret) {
2208 process_passed %current_config;
2209 return 0;
2210 }
2211
2212 doprint "This config had a failure.\n";
2213 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002214 doprint "config copied to $outputdir/config_bad\n";
2215 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002216
2217 # A config exists in this group that was bad.
2218 foreach my $config (keys %config_list) {
2219 if (!defined($current_config{$config})) {
2220 doprint " removing $config\n";
2221 delete $config_list{$config};
2222 }
2223 }
2224
2225 @start_list = @tophalf;
2226
2227 if ($#start_list == 0) {
2228 process_failed $start_list[0];
2229 return 1;
2230 }
2231
2232 # remove half the configs we are looking at and see if
2233 # they are good.
2234 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002235 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002236
Steven Rostedtc960bb92011-03-08 09:22:39 -05002237 # we found a single config, try it again unless we are running manually
2238
2239 if ($bisect_manual) {
2240 process_failed $start_list[0];
2241 return 1;
2242 }
2243
Steven Rostedt0a05c762010-11-08 11:14:10 -05002244 my @tophalf = @start_list[0 .. 0];
2245
2246 $ret = run_config_bisect_test $type;
2247 if ($ret) {
2248 process_passed %current_config;
2249 return 0;
2250 }
2251
2252 process_failed $start_list[0];
2253 return 1;
2254}
2255
2256sub config_bisect {
2257 my ($i) = @_;
2258
2259 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2260
2261 my $tmpconfig = "$tmpdir/use_config";
2262
Steven Rostedt30f75da2011-06-13 10:35:35 -04002263 if (defined($config_bisect_good)) {
2264 process_config_ignore $config_bisect_good;
2265 }
2266
Steven Rostedt0a05c762010-11-08 11:14:10 -05002267 # Make the file with the bad config and the min config
2268 if (defined($minconfig)) {
2269 # read the min config for things to ignore
2270 run_command "cp $minconfig $tmpconfig" or
2271 dodie "failed to copy $minconfig to $tmpconfig";
2272 } else {
2273 unlink $tmpconfig;
2274 }
2275
Steven Rostedt0a05c762010-11-08 11:14:10 -05002276 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002277 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002278 process_config_ignore $tmpconfig;
2279 }
2280
2281 # now process the start config
2282 run_command "cp $start_config $output_config" or
2283 dodie "failed to copy $start_config to $output_config";
2284
2285 # read directly what we want to check
2286 my %config_check;
2287 open (IN, $output_config)
2288 or dodie "faied to open $output_config";
2289
2290 while (<IN>) {
2291 if (/^((CONFIG\S*)=.*)/) {
2292 $config_check{$2} = $1;
2293 }
2294 }
2295 close(IN);
2296
Steven Rostedt250bae82011-07-15 22:05:59 -04002297 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002298 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002299
2300 # check to see what we lost (or gained)
2301 open (IN, $output_config)
2302 or dodie "Failed to read $start_config";
2303
2304 my %removed_configs;
2305 my %added_configs;
2306
2307 while (<IN>) {
2308 if (/^((CONFIG\S*)=.*)/) {
2309 # save off all options
2310 $config_set{$2} = $1;
2311 if (defined($config_check{$2})) {
2312 if (defined($config_ignore{$2})) {
2313 $removed_configs{$2} = $1;
2314 } else {
2315 $config_list{$2} = $1;
2316 }
2317 } elsif (!defined($config_ignore{$2})) {
2318 $added_configs{$2} = $1;
2319 $config_list{$2} = $1;
2320 }
2321 }
2322 }
2323 close(IN);
2324
2325 my @confs = keys %removed_configs;
2326 if ($#confs >= 0) {
2327 doprint "Configs overridden by default configs and removed from check:\n";
2328 foreach my $config (@confs) {
2329 doprint " $config\n";
2330 }
2331 }
2332 @confs = keys %added_configs;
2333 if ($#confs >= 0) {
2334 doprint "Configs appearing in make oldconfig and added:\n";
2335 foreach my $config (@confs) {
2336 doprint " $config\n";
2337 }
2338 }
2339
2340 my %config_test;
2341 my $once = 0;
2342
2343 # Sometimes kconfig does weird things. We must make sure
2344 # that the config we autocreate has everything we need
2345 # to test, otherwise we may miss testing configs, or
2346 # may not be able to create a new config.
2347 # Here we create a config with everything set.
2348 create_config (keys %config_list);
2349 read_current_config \%config_test;
2350 foreach my $config (keys %config_list) {
2351 if (!defined($config_test{$config})) {
2352 if (!$once) {
2353 $once = 1;
2354 doprint "Configs not produced by kconfig (will not be checked):\n";
2355 }
2356 doprint " $config\n";
2357 delete $config_list{$config};
2358 }
2359 }
2360 my $ret;
2361 do {
2362 $ret = run_config_bisect;
2363 } while (!$ret);
2364
2365 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002366
2367 success $i;
2368}
2369
Steven Rostedt27d934b2011-05-20 09:18:18 -04002370sub patchcheck_reboot {
2371 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002372 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002373}
2374
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002375sub patchcheck {
2376 my ($i) = @_;
2377
2378 die "PATCHCHECK_START[$i] not defined\n"
2379 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2380 die "PATCHCHECK_TYPE[$i] not defined\n"
2381 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2382
2383 my $start = $opt{"PATCHCHECK_START[$i]"};
2384
2385 my $end = "HEAD";
2386 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2387 $end = $opt{"PATCHCHECK_END[$i]"};
2388 }
2389
Steven Rostedta57419b2010-11-02 15:13:54 -04002390 # Get the true sha1's since we can use things like HEAD~3
2391 $start = get_sha1($start);
2392 $end = get_sha1($end);
2393
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002394 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2395
2396 # Can't have a test without having a test to run
2397 if ($type eq "test" && !defined($run_test)) {
2398 $type = "boot";
2399 }
2400
2401 open (IN, "git log --pretty=oneline $end|") or
2402 dodie "could not get git list";
2403
2404 my @list;
2405
2406 while (<IN>) {
2407 chomp;
2408 $list[$#list+1] = $_;
2409 last if (/^$start/);
2410 }
2411 close(IN);
2412
2413 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002414 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002415 }
2416
2417 # go backwards in the list
2418 @list = reverse @list;
2419
2420 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002421 my %ignored_warnings;
2422
2423 if (defined($ignore_warnings)) {
2424 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2425 $ignored_warnings{$sha1} = 1;
2426 }
2427 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002428
2429 $in_patchcheck = 1;
2430 foreach my $item (@list) {
2431 my $sha1 = $item;
2432 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2433
2434 doprint "\nProcessing commit $item\n\n";
2435
2436 run_command "git checkout $sha1" or
2437 die "Failed to checkout $sha1";
2438
2439 # only clean on the first and last patch
2440 if ($item eq $list[0] ||
2441 $item eq $list[$#list]) {
2442 $noclean = $save_clean;
2443 } else {
2444 $noclean = 1;
2445 }
2446
2447 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002448 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002449 } else {
2450 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002451 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002452 }
2453
Steven Rostedt19902072011-06-14 20:46:25 -04002454
2455 if (!defined($ignored_warnings{$sha1})) {
2456 check_buildlog $sha1 or return 0;
2457 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002458
2459 next if ($type eq "build");
2460
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002461 my $failed = 0;
2462
Steven Rostedtddf607e2011-06-14 20:49:13 -04002463 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002464
2465 if (!$failed && $type ne "boot"){
2466 do_run_test or $failed = 1;
2467 }
2468 end_monitor;
2469 return 0 if ($failed);
2470
Steven Rostedt27d934b2011-05-20 09:18:18 -04002471 patchcheck_reboot;
2472
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002473 }
2474 $in_patchcheck = 0;
2475 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002476
2477 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002478}
2479
Steven Rostedtb9066f62011-07-15 21:25:24 -04002480my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002481my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002482my $iflevel = 0;
2483my @ifdeps;
2484
2485# prevent recursion
2486my %read_kconfigs;
2487
Steven Rostedtac6974c2011-10-04 09:40:17 -04002488sub add_dep {
2489 # $config depends on $dep
2490 my ($config, $dep) = @_;
2491
2492 if (defined($depends{$config})) {
2493 $depends{$config} .= " " . $dep;
2494 } else {
2495 $depends{$config} = $dep;
2496 }
2497
2498 # record the number of configs depending on $dep
2499 if (defined $depcount{$dep}) {
2500 $depcount{$dep}++;
2501 } else {
2502 $depcount{$dep} = 1;
2503 }
2504}
2505
Steven Rostedtb9066f62011-07-15 21:25:24 -04002506# taken from streamline_config.pl
2507sub read_kconfig {
2508 my ($kconfig) = @_;
2509
2510 my $state = "NONE";
2511 my $config;
2512 my @kconfigs;
2513
2514 my $cont = 0;
2515 my $line;
2516
2517
2518 if (! -f $kconfig) {
2519 doprint "file $kconfig does not exist, skipping\n";
2520 return;
2521 }
2522
2523 open(KIN, "$kconfig")
2524 or die "Can't open $kconfig";
2525 while (<KIN>) {
2526 chomp;
2527
2528 # Make sure that lines ending with \ continue
2529 if ($cont) {
2530 $_ = $line . " " . $_;
2531 }
2532
2533 if (s/\\$//) {
2534 $cont = 1;
2535 $line = $_;
2536 next;
2537 }
2538
2539 $cont = 0;
2540
2541 # collect any Kconfig sources
2542 if (/^source\s*"(.*)"/) {
2543 $kconfigs[$#kconfigs+1] = $1;
2544 }
2545
2546 # configs found
2547 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2548 $state = "NEW";
2549 $config = $2;
2550
2551 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002552 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002553 }
2554
2555 # collect the depends for the config
2556 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2557
Steven Rostedtac6974c2011-10-04 09:40:17 -04002558 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002559
2560 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002561 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2562
2563 # selected by depends on config
2564 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002565
2566 # Check for if statements
2567 } elsif (/^if\s+(.*\S)\s*$/) {
2568 my $deps = $1;
2569 # remove beginning and ending non text
2570 $deps =~ s/^[^a-zA-Z0-9_]*//;
2571 $deps =~ s/[^a-zA-Z0-9_]*$//;
2572
2573 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2574
2575 $ifdeps[$iflevel++] = join ':', @deps;
2576
2577 } elsif (/^endif/) {
2578
2579 $iflevel-- if ($iflevel);
2580
2581 # stop on "help"
2582 } elsif (/^\s*help\s*$/) {
2583 $state = "NONE";
2584 }
2585 }
2586 close(KIN);
2587
2588 # read in any configs that were found.
2589 foreach $kconfig (@kconfigs) {
2590 if (!defined($read_kconfigs{$kconfig})) {
2591 $read_kconfigs{$kconfig} = 1;
2592 read_kconfig("$builddir/$kconfig");
2593 }
2594 }
2595}
2596
2597sub read_depends {
2598 # find out which arch this is by the kconfig file
2599 open (IN, $output_config)
2600 or dodie "Failed to read $output_config";
2601 my $arch;
2602 while (<IN>) {
2603 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2604 $arch = $1;
2605 last;
2606 }
2607 }
2608 close IN;
2609
2610 if (!defined($arch)) {
2611 doprint "Could not find arch from config file\n";
2612 doprint "no dependencies used\n";
2613 return;
2614 }
2615
2616 # arch is really the subarch, we need to know
2617 # what directory to look at.
2618 if ($arch eq "i386" || $arch eq "x86_64") {
2619 $arch = "x86";
2620 } elsif ($arch =~ /^tile/) {
2621 $arch = "tile";
2622 }
2623
2624 my $kconfig = "$builddir/arch/$arch/Kconfig";
2625
2626 if (! -f $kconfig && $arch =~ /\d$/) {
2627 my $orig = $arch;
2628 # some subarchs have numbers, truncate them
2629 $arch =~ s/\d*$//;
2630 $kconfig = "$builddir/arch/$arch/Kconfig";
2631 if (! -f $kconfig) {
2632 doprint "No idea what arch dir $orig is for\n";
2633 doprint "no dependencies used\n";
2634 return;
2635 }
2636 }
2637
2638 read_kconfig($kconfig);
2639}
2640
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002641sub read_config_list {
2642 my ($config) = @_;
2643
2644 open (IN, $config)
2645 or dodie "Failed to read $config";
2646
2647 while (<IN>) {
2648 if (/^((CONFIG\S*)=.*)/) {
2649 if (!defined($config_ignore{$2})) {
2650 $config_list{$2} = $1;
2651 }
2652 }
2653 }
2654
2655 close(IN);
2656}
2657
2658sub read_output_config {
2659 my ($config) = @_;
2660
2661 assign_configs \%config_ignore, $config;
2662}
2663
2664sub make_new_config {
2665 my @configs = @_;
2666
2667 open (OUT, ">$output_config")
2668 or dodie "Failed to write $output_config";
2669
2670 foreach my $config (@configs) {
2671 print OUT "$config\n";
2672 }
2673 close OUT;
2674}
2675
Steven Rostedtac6974c2011-10-04 09:40:17 -04002676sub chomp_config {
2677 my ($config) = @_;
2678
2679 $config =~ s/CONFIG_//;
2680
2681 return $config;
2682}
2683
Steven Rostedtb9066f62011-07-15 21:25:24 -04002684sub get_depends {
2685 my ($dep) = @_;
2686
Steven Rostedtac6974c2011-10-04 09:40:17 -04002687 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002688
2689 $dep = $depends{"$kconfig"};
2690
2691 # the dep string we have saves the dependencies as they
2692 # were found, including expressions like ! && ||. We
2693 # want to split this out into just an array of configs.
2694
2695 my $valid = "A-Za-z_0-9";
2696
2697 my @configs;
2698
2699 while ($dep =~ /[$valid]/) {
2700
2701 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2702 my $conf = "CONFIG_" . $1;
2703
2704 $configs[$#configs + 1] = $conf;
2705
2706 $dep =~ s/^[^$valid]*[$valid]+//;
2707 } else {
2708 die "this should never happen";
2709 }
2710 }
2711
2712 return @configs;
2713}
2714
2715my %min_configs;
2716my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002717my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002718my %processed_configs;
2719my %nochange_config;
2720
2721sub test_this_config {
2722 my ($config) = @_;
2723
2724 my $found;
2725
2726 # if we already processed this config, skip it
2727 if (defined($processed_configs{$config})) {
2728 return undef;
2729 }
2730 $processed_configs{$config} = 1;
2731
2732 # if this config failed during this round, skip it
2733 if (defined($nochange_config{$config})) {
2734 return undef;
2735 }
2736
Steven Rostedtac6974c2011-10-04 09:40:17 -04002737 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002738
2739 # Test dependencies first
2740 if (defined($depends{"$kconfig"})) {
2741 my @parents = get_depends $config;
2742 foreach my $parent (@parents) {
2743 # if the parent is in the min config, check it first
2744 next if (!defined($min_configs{$parent}));
2745 $found = test_this_config($parent);
2746 if (defined($found)) {
2747 return $found;
2748 }
2749 }
2750 }
2751
2752 # Remove this config from the list of configs
2753 # do a make oldnoconfig and then read the resulting
2754 # .config to make sure it is missing the config that
2755 # we had before
2756 my %configs = %min_configs;
2757 delete $configs{$config};
2758 make_new_config ((values %configs), (values %keep_configs));
2759 make_oldconfig;
2760 undef %configs;
2761 assign_configs \%configs, $output_config;
2762
2763 return $config if (!defined($configs{$config}));
2764
2765 doprint "disabling config $config did not change .config\n";
2766
2767 $nochange_config{$config} = 1;
2768
2769 return undef;
2770}
2771
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002772sub make_min_config {
2773 my ($i) = @_;
2774
2775 if (!defined($output_minconfig)) {
2776 fail "OUTPUT_MIN_CONFIG not defined" and return;
2777 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002778
2779 # If output_minconfig exists, and the start_minconfig
2780 # came from min_config, than ask if we should use
2781 # that instead.
2782 if (-f $output_minconfig && !$start_minconfig_defined) {
2783 print "$output_minconfig exists\n";
2784 if (read_yn " Use it as minconfig?") {
2785 $start_minconfig = $output_minconfig;
2786 }
2787 }
2788
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002789 if (!defined($start_minconfig)) {
2790 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2791 }
2792
Steven Rostedt35ce5952011-07-15 21:57:25 -04002793 my $temp_config = "$tmpdir/temp_config";
2794
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002795 # First things first. We build an allnoconfig to find
2796 # out what the defaults are that we can't touch.
2797 # Some are selections, but we really can't handle selections.
2798
2799 my $save_minconfig = $minconfig;
2800 undef $minconfig;
2801
2802 run_command "$make allnoconfig" or return 0;
2803
Steven Rostedtb9066f62011-07-15 21:25:24 -04002804 read_depends;
2805
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002806 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002807
Steven Rostedt43d1b652011-07-15 22:01:56 -04002808 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002809 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002810
2811 if (defined($ignore_config)) {
2812 # make sure the file exists
2813 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002814 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002815 }
2816
Steven Rostedt43d1b652011-07-15 22:01:56 -04002817 %keep_configs = %save_configs;
2818
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002819 doprint "Load initial configs from $start_minconfig\n";
2820
2821 # Look at the current min configs, and save off all the
2822 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002823 assign_configs \%min_configs, $start_minconfig;
2824
2825 my @config_keys = keys %min_configs;
2826
Steven Rostedtac6974c2011-10-04 09:40:17 -04002827 # All configs need a depcount
2828 foreach my $config (@config_keys) {
2829 my $kconfig = chomp_config $config;
2830 if (!defined $depcount{$kconfig}) {
2831 $depcount{$kconfig} = 0;
2832 }
2833 }
2834
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002835 # Remove anything that was set by the make allnoconfig
2836 # we shouldn't need them as they get set for us anyway.
2837 foreach my $config (@config_keys) {
2838 # Remove anything in the ignore_config
2839 if (defined($keep_configs{$config})) {
2840 my $file = $ignore_config;
2841 $file =~ s,.*/(.*?)$,$1,;
2842 doprint "$config set by $file ... ignored\n";
2843 delete $min_configs{$config};
2844 next;
2845 }
2846 # But make sure the settings are the same. If a min config
2847 # sets a selection, we do not want to get rid of it if
2848 # it is not the same as what we have. Just move it into
2849 # the keep configs.
2850 if (defined($config_ignore{$config})) {
2851 if ($config_ignore{$config} ne $min_configs{$config}) {
2852 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2853 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2854 $keep_configs{$config} = $min_configs{$config};
2855 } else {
2856 doprint "$config set by allnoconfig ... ignored\n";
2857 }
2858 delete $min_configs{$config};
2859 }
2860 }
2861
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002862 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002863 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002864
2865 while (!$done) {
2866
2867 my $config;
2868 my $found;
2869
2870 # Now disable each config one by one and do a make oldconfig
2871 # till we find a config that changes our list.
2872
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002873 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002874
2875 # Sort keys by who is most dependent on
2876 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2877 @test_configs ;
2878
2879 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002880 my $reset = 1;
2881 for (my $i = 0; $i < $#test_configs; $i++) {
2882 if (!defined($nochange_config{$test_configs[0]})) {
2883 $reset = 0;
2884 last;
2885 }
2886 # This config didn't change the .config last time.
2887 # Place it at the end
2888 my $config = shift @test_configs;
2889 push @test_configs, $config;
2890 }
2891
2892 # if every test config has failed to modify the .config file
2893 # in the past, then reset and start over.
2894 if ($reset) {
2895 undef %nochange_config;
2896 }
2897
Steven Rostedtb9066f62011-07-15 21:25:24 -04002898 undef %processed_configs;
2899
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002900 foreach my $config (@test_configs) {
2901
Steven Rostedtb9066f62011-07-15 21:25:24 -04002902 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002903
Steven Rostedtb9066f62011-07-15 21:25:24 -04002904 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002905
2906 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002907 }
2908
2909 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002910 # we could have failed due to the nochange_config hash
2911 # reset and try again
2912 if (!$take_two) {
2913 undef %nochange_config;
2914 $take_two = 1;
2915 next;
2916 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002917 doprint "No more configs found that we can disable\n";
2918 $done = 1;
2919 last;
2920 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04002921 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002922
2923 $config = $found;
2924
2925 doprint "Test with $config disabled\n";
2926
2927 # set in_bisect to keep build and monitor from dieing
2928 $in_bisect = 1;
2929
2930 my $failed = 0;
2931 build "oldconfig";
2932 start_monitor_and_boot or $failed = 1;
2933 end_monitor;
2934
2935 $in_bisect = 0;
2936
2937 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002938 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002939 # this config is needed, add it to the ignore list.
2940 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04002941 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002942 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04002943
2944 # update new ignore configs
2945 if (defined($ignore_config)) {
2946 open (OUT, ">$temp_config")
2947 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04002948 foreach my $config (keys %save_configs) {
2949 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002950 }
2951 close OUT;
2952 run_command "mv $temp_config $ignore_config" or
2953 dodie "failed to copy update to $ignore_config";
2954 }
2955
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002956 } else {
2957 # We booted without this config, remove it from the minconfigs.
2958 doprint "$config is not needed, disabling\n";
2959
2960 delete $min_configs{$config};
2961
2962 # Also disable anything that is not enabled in this config
2963 my %configs;
2964 assign_configs \%configs, $output_config;
2965 my @config_keys = keys %min_configs;
2966 foreach my $config (@config_keys) {
2967 if (!defined($configs{$config})) {
2968 doprint "$config is not set, disabling\n";
2969 delete $min_configs{$config};
2970 }
2971 }
2972
2973 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04002974 open (OUT, ">$temp_config")
2975 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002976 foreach my $config (keys %keep_configs) {
2977 print OUT "$keep_configs{$config}\n";
2978 }
2979 foreach my $config (keys %min_configs) {
2980 print OUT "$min_configs{$config}\n";
2981 }
2982 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04002983
2984 run_command "mv $temp_config $output_minconfig" or
2985 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002986 }
2987
2988 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002989 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002990 }
2991
2992 success $i;
2993 return 1;
2994}
2995
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002996$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002997
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002998if ($#ARGV == 0) {
2999 $ktest_config = $ARGV[0];
3000 if (! -f $ktest_config) {
3001 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003002 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003003 exit 0;
3004 }
3005 }
3006} else {
3007 $ktest_config = "ktest.conf";
3008}
3009
3010if (! -f $ktest_config) {
3011 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3012 print OUT << "EOF"
3013# Generated by ktest.pl
3014#
3015# Define each test with TEST_START
3016# The config options below it will override the defaults
3017TEST_START
3018
3019DEFAULTS
3020EOF
3021;
3022 close(OUT);
3023}
3024read_config $ktest_config;
3025
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003026if (defined($opt{"LOG_FILE"})) {
3027 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3028}
3029
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003030# Append any configs entered in manually to the config file.
3031my @new_configs = keys %entered_configs;
3032if ($#new_configs >= 0) {
3033 print "\nAppending entered in configs to $ktest_config\n";
3034 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3035 foreach my $config (@new_configs) {
3036 print OUT "$config = $entered_configs{$config}\n";
3037 $opt{$config} = $entered_configs{$config};
3038 }
3039}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003040
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003041if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3042 unlink $opt{"LOG_FILE"};
3043}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003044
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003045doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3046
Steven Rostedta57419b2010-11-02 15:13:54 -04003047for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3048
3049 if (!$i) {
3050 doprint "DEFAULT OPTIONS:\n";
3051 } else {
3052 doprint "\nTEST $i OPTIONS";
3053 if (defined($repeat_tests{$i})) {
3054 $repeat = $repeat_tests{$i};
3055 doprint " ITERATE $repeat";
3056 }
3057 doprint "\n";
3058 }
3059
3060 foreach my $option (sort keys %opt) {
3061
3062 if ($option =~ /\[(\d+)\]$/) {
3063 next if ($i != $1);
3064 } else {
3065 next if ($i);
3066 }
3067
3068 doprint "$option = $opt{$option}\n";
3069 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003070}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003071
Steven Rostedt2a625122011-05-20 15:48:59 -04003072sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003073 my ($name, $i) = @_;
3074
3075 my $option = "$name\[$i\]";
3076
3077 if (defined($opt{$option})) {
3078 return $opt{$option};
3079 }
3080
Steven Rostedta57419b2010-11-02 15:13:54 -04003081 foreach my $test (keys %repeat_tests) {
3082 if ($i >= $test &&
3083 $i < $test + $repeat_tests{$test}) {
3084 $option = "$name\[$test\]";
3085 if (defined($opt{$option})) {
3086 return $opt{$option};
3087 }
3088 }
3089 }
3090
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003091 if (defined($opt{$name})) {
3092 return $opt{$name};
3093 }
3094
3095 return undef;
3096}
3097
Steven Rostedt2a625122011-05-20 15:48:59 -04003098sub set_test_option {
3099 my ($name, $i) = @_;
3100
3101 my $option = __set_test_option($name, $i);
3102 return $option if (!defined($option));
3103
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003104 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003105}
3106
Steven Rostedt2545eb62010-11-02 15:01:32 -04003107# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003108for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003109
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003110 # Do not reboot on failing test options
3111 $no_reboot = 1;
3112
Steven Rostedt576f6272010-11-02 14:58:38 -04003113 $iteration = $i;
3114
Steven Rostedta75fece2010-11-02 14:58:27 -04003115 my $makecmd = set_test_option("MAKE_CMD", $i);
3116
3117 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003118 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003119 $tmpdir = set_test_option("TMP_DIR", $i);
3120 $outputdir = set_test_option("OUTPUT_DIR", $i);
3121 $builddir = set_test_option("BUILD_DIR", $i);
3122 $test_type = set_test_option("TEST_TYPE", $i);
3123 $build_type = set_test_option("BUILD_TYPE", $i);
3124 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003125 $pre_build = set_test_option("PRE_BUILD", $i);
3126 $post_build = set_test_option("POST_BUILD", $i);
3127 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3128 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003129 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003130 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003131 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3132 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003133 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3134 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3135 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003136 $run_test = set_test_option("TEST", $i);
3137 $addconfig = set_test_option("ADD_CONFIG", $i);
3138 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3139 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003140 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003141 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003142 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3143 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3144 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3145 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3146 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003147 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3148 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003149 $sleep_time = set_test_option("SLEEP_TIME", $i);
3150 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003151 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003152 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003153 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003154 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003155 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003156 $store_failures = set_test_option("STORE_FAILURES", $i);
Rabin Vincentde5b6e32011-11-18 17:05:31 +05303157 $store_successes = set_test_option("STORE_SUCCESSES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003158 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003159 $timeout = set_test_option("TIMEOUT", $i);
3160 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3161 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003162 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003163 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003164 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003165 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3166 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003167 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003168 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003169 $ssh_exec = set_test_option("SSH_EXEC", $i);
3170 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003171 $target_image = set_test_option("TARGET_IMAGE", $i);
3172 $localversion = set_test_option("LOCALVERSION", $i);
3173
Steven Rostedt35ce5952011-07-15 21:57:25 -04003174 $start_minconfig_defined = 1;
3175
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003176 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003177 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003178 $start_minconfig = $minconfig;
3179 }
3180
Steven Rostedta75fece2010-11-02 14:58:27 -04003181 chdir $builddir || die "can't change directory to $builddir";
3182
Andrew Jonesa908a662011-08-12 15:32:03 +02003183 foreach my $dir ($tmpdir, $outputdir) {
3184 if (!-d $dir) {
3185 mkpath($dir) or
3186 die "can't create $dir";
3187 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003188 }
3189
Steven Rostedte48c5292010-11-02 14:35:37 -04003190 $ENV{"SSH_USER"} = $ssh_user;
3191 $ENV{"MACHINE"} = $machine;
3192
Steven Rostedta75fece2010-11-02 14:58:27 -04003193 $target = "$ssh_user\@$machine";
3194
3195 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303196 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003197 $dmesg = "$tmpdir/dmesg-$machine";
3198 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003199 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003200
3201 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04003202 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04003203 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04003204 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04003205 }
3206
3207 my $run_type = $build_type;
3208 if ($test_type eq "patchcheck") {
3209 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3210 } elsif ($test_type eq "bisect") {
3211 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003212 } elsif ($test_type eq "config_bisect") {
3213 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003214 }
3215
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003216 if ($test_type eq "make_min_config") {
3217 $run_type = "";
3218 }
3219
Steven Rostedta75fece2010-11-02 14:58:27 -04003220 # mistake in config file?
3221 if (!defined($run_type)) {
3222 $run_type = "ERROR";
3223 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003224
Steven Rostedte0a87422011-09-30 17:50:48 -04003225 my $installme = "";
3226 $installme = " no_install" if ($no_install);
3227
Steven Rostedt2545eb62010-11-02 15:01:32 -04003228 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003229 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003230
3231 unlink $dmesg;
3232 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303233 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003234
Steven Rostedt250bae82011-07-15 22:05:59 -04003235 if (defined($addconfig)) {
3236 my $min = $minconfig;
3237 if (!defined($minconfig)) {
3238 $min = "";
3239 }
3240 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003241 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003242 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003243 }
3244
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003245 my $checkout = $opt{"CHECKOUT[$i]"};
3246 if (defined($checkout)) {
3247 run_command "git checkout $checkout" or
3248 die "failed to checkout $checkout";
3249 }
3250
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003251 $no_reboot = 0;
3252
3253
Steven Rostedta75fece2010-11-02 14:58:27 -04003254 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003255 bisect $i;
3256 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003257 } elsif ($test_type eq "config_bisect") {
3258 config_bisect $i;
3259 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003260 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003261 patchcheck $i;
3262 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003263 } elsif ($test_type eq "make_min_config") {
3264 make_min_config $i;
3265 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003266 }
3267
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003268 if ($build_type ne "nobuild") {
3269 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003270 }
3271
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003272 if ($test_type eq "install") {
3273 get_version;
3274 install;
3275 success $i;
3276 next;
3277 }
3278
Steven Rostedta75fece2010-11-02 14:58:27 -04003279 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003280 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003281 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003282
3283 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3284 do_run_test or $failed = 1;
3285 }
3286 end_monitor;
3287 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003288 }
3289
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003290 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003291}
3292
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003293if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003294 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003295} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003296 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003297}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003298
Steven Rostedte48c5292010-11-02 14:35:37 -04003299doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3300
Steven Rostedt2545eb62010-11-02 15:01:32 -04003301exit 0;