blob: 30e2befd6f2a237b7a04bd1125386ffa26c7a3ac [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{"REBOOT_TYPE"} = "grub";
26$default{"TEST_TYPE"} = "test";
27$default{"BUILD_TYPE"} = "randconfig";
28$default{"MAKE_CMD"} = "make";
29$default{"TIMEOUT"} = 120;
Steven Rostedt48920632011-06-14 20:42:19 -040030$default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
Steven Rostedta75fece2010-11-02 14:58:27 -040031$default{"SLEEP_TIME"} = 60; # sleep time between tests
32$default{"BUILD_NOCLEAN"} = 0;
33$default{"REBOOT_ON_ERROR"} = 0;
34$default{"POWEROFF_ON_ERROR"} = 0;
35$default{"REBOOT_ON_SUCCESS"} = 1;
36$default{"POWEROFF_ON_SUCCESS"} = 0;
37$default{"BUILD_OPTIONS"} = "";
38$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
Steven Rostedt27d934b2011-05-20 09:18:18 -040039$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
Steven Rostedta75fece2010-11-02 14:58:27 -040040$default{"CLEAR_LOG"} = 0;
Steven Rostedtc960bb92011-03-08 09:22:39 -050041$default{"BISECT_MANUAL"} = 0;
Steven Rostedtc23dca72011-03-08 09:26:31 -050042$default{"BISECT_SKIP"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040043$default{"SUCCESS_LINE"} = "login:";
Steven Rostedtf1a5b962011-06-13 10:30:00 -040044$default{"DETECT_TRIPLE_FAULT"} = 1;
Steven Rostedte0a87422011-09-30 17:50:48 -040045$default{"NO_INSTALL"} = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040046$default{"BOOTED_TIMEOUT"} = 1;
47$default{"DIE_ON_FAILURE"} = 1;
Steven Rostedte48c5292010-11-02 14:35:37 -040048$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
49$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
50$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
Steven Rostedt1c8a6172010-11-09 12:55:40 -050051$default{"STOP_AFTER_SUCCESS"} = 10;
52$default{"STOP_AFTER_FAILURE"} = 60;
Steven Rostedt2d01b262011-03-08 09:47:54 -050053$default{"STOP_TEST_AFTER"} = 600;
Steven Rostedt8d1491b2010-11-18 15:39:48 -050054$default{"LOCALVERSION"} = "-test";
Steven Rostedt2545eb62010-11-02 15:01:32 -040055
Steven Rostedt8d1491b2010-11-18 15:39:48 -050056my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040057my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040058my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040059my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040060my $tmpdir;
61my $builddir;
62my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050063my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040064my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040065my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040066my $build_options;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040067my $pre_build;
68my $post_build;
69my $pre_build_die;
70my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040071my $reboot_type;
72my $reboot_script;
73my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040074my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040075my $reboot_on_error;
76my $poweroff_on_error;
77my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040078my $powercycle_after_reboot;
79my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040080my $ssh_exec;
81my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040082my $power_off;
83my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040084my $grub_number;
85my $target;
86my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040087my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -040088my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040089my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040090my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040091my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -040092my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040093my $output_minconfig;
94my $ignore_config;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -040095my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040096my $in_bisect = 0;
97my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -040098my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -050099my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500100my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400101my $config_bisect_good;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400102my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400103my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400104my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400105my $buildlog;
106my $dmesg;
107my $monitor_fp;
108my $monitor_pid;
109my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400110my $sleep_time;
111my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400112my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400113my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400114my $store_failures;
Steven Rostedt9064af52011-06-13 10:38:48 -0400115my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400116my $timeout;
117my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400118my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400119my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400120my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400121my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500122my $stop_after_success;
123my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500124my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400125my $build_target;
126my $target_image;
127my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400128my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400129my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400130
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500131my %entered_configs;
132my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400133my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400134my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500135
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400136# do not force reboots on config problems
137my $no_reboot = 1;
138
Steven Rostedt7bf51072011-10-22 09:07:03 -0400139# default variables that can be used
140chomp ($variable{"PWD"} = `pwd`);
141
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500142$config_help{"MACHINE"} = << "EOF"
143 The machine hostname that you will test.
144EOF
145 ;
146$config_help{"SSH_USER"} = << "EOF"
147 The box is expected to have ssh on normal bootup, provide the user
148 (most likely root, since you need privileged operations)
149EOF
150 ;
151$config_help{"BUILD_DIR"} = << "EOF"
152 The directory that contains the Linux source code (full path).
153EOF
154 ;
155$config_help{"OUTPUT_DIR"} = << "EOF"
156 The directory that the objects will be built (full path).
157 (can not be same as BUILD_DIR)
158EOF
159 ;
160$config_help{"BUILD_TARGET"} = << "EOF"
161 The location of the compiled file to copy to the target.
162 (relative to OUTPUT_DIR)
163EOF
164 ;
165$config_help{"TARGET_IMAGE"} = << "EOF"
166 The place to put your image on the test machine.
167EOF
168 ;
169$config_help{"POWER_CYCLE"} = << "EOF"
170 A script or command to reboot the box.
171
172 Here is a digital loggers power switch example
173 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
174
175 Here is an example to reboot a virtual box on the current host
176 with the name "Guest".
177 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
178EOF
179 ;
180$config_help{"CONSOLE"} = << "EOF"
181 The script or command that reads the console
182
183 If you use ttywatch server, something like the following would work.
184CONSOLE = nc -d localhost 3001
185
186 For a virtual machine with guest name "Guest".
187CONSOLE = virsh console Guest
188EOF
189 ;
190$config_help{"LOCALVERSION"} = << "EOF"
191 Required version ending to differentiate the test
192 from other linux builds on the system.
193EOF
194 ;
195$config_help{"REBOOT_TYPE"} = << "EOF"
196 Way to reboot the box to the test kernel.
197 Only valid options so far are "grub" and "script".
198
199 If you specify grub, it will assume grub version 1
200 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
201 and select that target to reboot to the kernel. If this is not
202 your setup, then specify "script" and have a command or script
203 specified in REBOOT_SCRIPT to boot to the target.
204
205 The entry in /boot/grub/menu.lst must be entered in manually.
206 The test will not modify that file.
207EOF
208 ;
209$config_help{"GRUB_MENU"} = << "EOF"
210 The grub title name for the test kernel to boot
211 (Only mandatory if REBOOT_TYPE = grub)
212
213 Note, ktest.pl will not update the grub menu.lst, you need to
214 manually add an option for the test. ktest.pl will search
215 the grub menu.lst for this option to find what kernel to
216 reboot into.
217
218 For example, if in the /boot/grub/menu.lst the test kernel title has:
219 title Test Kernel
220 kernel vmlinuz-test
221 GRUB_MENU = Test Kernel
222EOF
223 ;
224$config_help{"REBOOT_SCRIPT"} = << "EOF"
225 A script to reboot the target into the test kernel
226 (Only mandatory if REBOOT_TYPE = script)
227EOF
228 ;
229
Steven Rostedt35ce5952011-07-15 21:57:25 -0400230sub read_yn {
231 my ($prompt) = @_;
232
233 my $ans;
234
235 for (;;) {
236 print "$prompt [Y/n] ";
237 $ans = <STDIN>;
238 chomp $ans;
239 if ($ans =~ /^\s*$/) {
240 $ans = "y";
241 }
242 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
243 print "Please answer either 'y' or 'n'.\n";
244 }
245 if ($ans !~ /^y$/i) {
246 return 0;
247 }
248 return 1;
249}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500250
251sub get_ktest_config {
252 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400253 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500254
255 return if (defined($opt{$config}));
256
257 if (defined($config_help{$config})) {
258 print "\n";
259 print $config_help{$config};
260 }
261
262 for (;;) {
263 print "$config = ";
264 if (defined($default{$config})) {
265 print "\[$default{$config}\] ";
266 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400267 $ans = <STDIN>;
268 $ans =~ s/^\s*(.*\S)\s*$/$1/;
269 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500270 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400271 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500272 } else {
273 print "Your answer can not be blank\n";
274 next;
275 }
276 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400277 $entered_configs{$config} = process_variables($ans);
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500278 last;
279 }
280}
281
282sub get_ktest_configs {
283 get_ktest_config("MACHINE");
284 get_ktest_config("SSH_USER");
285 get_ktest_config("BUILD_DIR");
286 get_ktest_config("OUTPUT_DIR");
287 get_ktest_config("BUILD_TARGET");
288 get_ktest_config("TARGET_IMAGE");
289 get_ktest_config("POWER_CYCLE");
290 get_ktest_config("CONSOLE");
291 get_ktest_config("LOCALVERSION");
292
293 my $rtype = $opt{"REBOOT_TYPE"};
294
295 if (!defined($rtype)) {
296 if (!defined($opt{"GRUB_MENU"})) {
297 get_ktest_config("REBOOT_TYPE");
298 $rtype = $entered_configs{"REBOOT_TYPE"};
299 } else {
300 $rtype = "grub";
301 }
302 }
303
304 if ($rtype eq "grub") {
305 get_ktest_config("GRUB_MENU");
306 } else {
307 get_ktest_config("REBOOT_SCRIPT");
308 }
309}
310
Steven Rostedt77d942c2011-05-20 13:36:58 -0400311sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400312 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400313 my $retval = "";
314
315 # We want to check for '\', and it is just easier
316 # to check the previous characet of '$' and not need
317 # to worry if '$' is the first character. By adding
318 # a space to $value, we can just check [^\\]\$ and
319 # it will still work.
320 $value = " $value";
321
322 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
323 my $begin = $1;
324 my $var = $2;
325 my $end = $3;
326 # append beginning of value to retval
327 $retval = "$retval$begin";
328 if (defined($variable{$var})) {
329 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400330 } elsif (defined($remove_undef) && $remove_undef) {
331 # for if statements, any variable that is not defined,
332 # we simple convert to 0
333 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400334 } else {
335 # put back the origin piece.
336 $retval = "$retval\$\{$var\}";
337 }
338 $value = $end;
339 }
340 $retval = "$retval$value";
341
342 # remove the space added in the beginning
343 $retval =~ s/ //;
344
345 return "$retval"
346}
347
Steven Rostedta57419b2010-11-02 15:13:54 -0400348sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400349 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400350
351 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400352 if (!$override || defined(${$overrides}{$lvalue})) {
353 my $extra = "";
354 if ($override) {
355 $extra = "In the same override section!\n";
356 }
357 die "$name: $.: Option $lvalue defined more than once!\n$extra";
358 }
359 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400360 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500361 if ($rvalue =~ /^\s*$/) {
362 delete $opt{$lvalue};
363 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400364 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500365 $opt{$lvalue} = $rvalue;
366 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400367}
368
Steven Rostedt77d942c2011-05-20 13:36:58 -0400369sub set_variable {
370 my ($lvalue, $rvalue) = @_;
371
372 if ($rvalue =~ /^\s*$/) {
373 delete $variable{$lvalue};
374 } else {
375 $rvalue = process_variables($rvalue);
376 $variable{$lvalue} = $rvalue;
377 }
378}
379
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400380sub process_compare {
381 my ($lval, $cmp, $rval) = @_;
382
383 # remove whitespace
384
385 $lval =~ s/^\s*//;
386 $lval =~ s/\s*$//;
387
388 $rval =~ s/^\s*//;
389 $rval =~ s/\s*$//;
390
391 if ($cmp eq "==") {
392 return $lval eq $rval;
393 } elsif ($cmp eq "!=") {
394 return $lval ne $rval;
395 }
396
397 my $statement = "$lval $cmp $rval";
398 my $ret = eval $statement;
399
400 # $@ stores error of eval
401 if ($@) {
402 return -1;
403 }
404
405 return $ret;
406}
407
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400408sub value_defined {
409 my ($val) = @_;
410
411 return defined($variable{$2}) ||
412 defined($opt{$2});
413}
414
Steven Rostedt8d735212011-10-17 11:36:44 -0400415my $d = 0;
416sub process_expression {
417 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400418
Steven Rostedt8d735212011-10-17 11:36:44 -0400419 my $c = $d++;
420
421 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
422 my $express = $1;
423
424 if (process_expression($name, $express)) {
425 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
426 } else {
427 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
428 }
429 }
430
431 $d--;
432 my $OR = "\\|\\|";
433 my $AND = "\\&\\&";
434
435 while ($val =~ s/^(.*?)($OR|$AND)//) {
436 my $express = $1;
437 my $op = $2;
438
439 if (process_expression($name, $express)) {
440 if ($op eq "||") {
441 return 1;
442 }
443 } else {
444 if ($op eq "&&") {
445 return 0;
446 }
447 }
448 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400449
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400450 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
451 my $ret = process_compare($1, $2, $3);
452 if ($ret < 0) {
453 die "$name: $.: Unable to process comparison\n";
454 }
455 return $ret;
456 }
457
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400458 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
459 if (defined $1) {
460 return !value_defined($2);
461 } else {
462 return value_defined($2);
463 }
464 }
465
Steven Rostedt45d73a52011-09-30 19:44:53 -0400466 if ($val =~ /^\s*0\s*$/) {
467 return 0;
468 } elsif ($val =~ /^\s*\d+\s*$/) {
469 return 1;
470 }
471
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400472 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400473}
474
475sub process_if {
476 my ($name, $value) = @_;
477
478 # Convert variables and replace undefined ones with 0
479 my $val = process_variables($value, 1);
480 my $ret = process_expression $name, $val;
481
482 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400483}
484
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400485sub __read_config {
486 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400487
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400488 my $in;
489 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400490
Steven Rostedta57419b2010-11-02 15:13:54 -0400491 my $name = $config;
492 $name =~ s,.*/(.*),$1,;
493
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400494 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400495 my $default = 1;
496 my $repeat = 1;
497 my $num_tests_set = 0;
498 my $skip = 0;
499 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400500 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400501 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400502 my $if = 0;
503 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400504 my $override = 0;
505
506 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400507
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400508 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400509
510 # ignore blank lines and comments
511 next if (/^\s*$/ || /\s*\#/);
512
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400513 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400514
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400515 my $type = $1;
516 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400517 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400518
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400519 my $old_test_num;
520 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400521 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400522
523 if ($type eq "TEST_START") {
524
525 if ($num_tests_set) {
526 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
527 }
528
529 $old_test_num = $test_num;
530 $old_repeat = $repeat;
531
532 $test_num += $repeat;
533 $default = 0;
534 $repeat = 1;
535 } else {
536 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400537 }
538
Steven Rostedta9f84422011-10-17 11:06:29 -0400539 # If SKIP is anywhere in the line, the command will be skipped
540 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400541 $skip = 1;
542 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400543 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400544 $skip = 0;
545 }
546
Steven Rostedta9f84422011-10-17 11:06:29 -0400547 if ($rest =~ s/\sELSE\b//) {
548 if (!$if) {
549 die "$name: $.: ELSE found with out matching IF section\n$_";
550 }
551 $if = 0;
552
553 if ($if_set) {
554 $skip = 1;
555 } else {
556 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400557 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400558 }
559
Steven Rostedta9f84422011-10-17 11:06:29 -0400560 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400561 if (process_if($name, $1)) {
562 $if_set = 1;
563 } else {
564 $skip = 1;
565 }
566 $if = 1;
567 } else {
568 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400569 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400570 }
571
Steven Rostedta9f84422011-10-17 11:06:29 -0400572 if (!$skip) {
573 if ($type eq "TEST_START") {
574 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
575 $repeat = $1;
576 $repeat_tests{"$test_num"} = $repeat;
577 }
578 } elsif ($rest =~ s/\sOVERRIDE\b//) {
579 # DEFAULT only
580 $override = 1;
581 # Clear previous overrides
582 %overrides = ();
583 }
584 }
585
586 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400587 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400588 }
589
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400590 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400591 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400592 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400593 }
594
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400595 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400596 if (!$if) {
597 die "$name: $.: ELSE found with out matching IF section\n$_";
598 }
599 $rest = $1;
600 if ($if_set) {
601 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400602 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400603 } else {
604 $skip = 0;
605
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400606 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400607 # May be a ELSE IF section.
608 if (!process_if($name, $1)) {
609 $skip = 1;
610 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400611 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400612 } else {
613 $if = 0;
614 }
615 }
616
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400617 if ($rest !~ /^\s*$/) {
618 die "$name: $.: Gargbage found after DEFAULTS\n$_";
619 }
620
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400621 } elsif (/^\s*INCLUDE\s+(\S+)/) {
622
623 next if ($skip);
624
625 if (!$default) {
626 die "$name: $.: INCLUDE can only be done in default sections\n$_";
627 }
628
629 my $file = process_variables($1);
630
631 if ($file !~ m,^/,) {
632 # check the path of the config file first
633 if ($config =~ m,(.*)/,) {
634 if (-f "$1/$file") {
635 $file = "$1/$file";
636 }
637 }
638 }
639
640 if ( ! -r $file ) {
641 die "$name: $.: Can't read file $file\n$_";
642 }
643
644 if (__read_config($file, \$test_num)) {
645 $test_case = 1;
646 }
647
Steven Rostedta57419b2010-11-02 15:13:54 -0400648 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
649
650 next if ($skip);
651
Steven Rostedt2545eb62010-11-02 15:01:32 -0400652 my $lvalue = $1;
653 my $rvalue = $2;
654
Steven Rostedta57419b2010-11-02 15:13:54 -0400655 if (!$default &&
656 ($lvalue eq "NUM_TESTS" ||
657 $lvalue eq "LOG_FILE" ||
658 $lvalue eq "CLEAR_LOG")) {
659 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400660 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400661
662 if ($lvalue eq "NUM_TESTS") {
663 if ($test_num) {
664 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
665 }
666 if (!$default) {
667 die "$name: $.: NUM_TESTS must be set in default section\n";
668 }
669 $num_tests_set = 1;
670 }
671
672 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400673 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400674 } else {
675 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400676 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400677
678 if ($repeat > 1) {
679 $repeats{$val} = $repeat;
680 }
681 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400682 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
683 next if ($skip);
684
685 my $lvalue = $1;
686 my $rvalue = $2;
687
688 # process config variables.
689 # Config variables are only active while reading the
690 # config and can be defined anywhere. They also ignore
691 # TEST_START and DEFAULTS, but are skipped if they are in
692 # on of these sections that have SKIP defined.
693 # The save variable can be
694 # defined multiple times and the new one simply overrides
695 # the prevous one.
696 set_variable($lvalue, $rvalue);
697
Steven Rostedta57419b2010-11-02 15:13:54 -0400698 } else {
699 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400700 }
701 }
702
Steven Rostedta57419b2010-11-02 15:13:54 -0400703 if ($test_num) {
704 $test_num += $repeat - 1;
705 $opt{"NUM_TESTS"} = $test_num;
706 }
707
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400708 close($in);
709
710 $$current_test_num = $test_num;
711
712 return $test_case;
713}
714
715sub read_config {
716 my ($config) = @_;
717
718 my $test_case;
719 my $test_num = 0;
720
721 $test_case = __read_config $config, \$test_num;
722
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500723 # make sure we have all mandatory configs
724 get_ktest_configs;
725
Steven Rostedt0df213c2011-06-14 20:51:37 -0400726 # was a test specified?
727 if (!$test_case) {
728 print "No test case specified.\n";
729 print "What test case would you like to run?\n";
730 my $ans = <STDIN>;
731 chomp $ans;
732 $default{"TEST_TYPE"} = $ans;
733 }
734
Steven Rostedta75fece2010-11-02 14:58:27 -0400735 # set any defaults
736
737 foreach my $default (keys %default) {
738 if (!defined($opt{$default})) {
739 $opt{$default} = $default{$default};
740 }
741 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400742}
743
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400744sub __eval_option {
745 my ($option, $i) = @_;
746
747 # Add space to evaluate the character before $
748 $option = " $option";
749 my $retval = "";
750
751 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
752 my $start = $1;
753 my $var = $2;
754 my $end = $3;
755
756 # Append beginning of line
757 $retval = "$retval$start";
758
759 # If the iteration option OPT[$i] exists, then use that.
760 # otherwise see if the default OPT (without [$i]) exists.
761
762 my $o = "$var\[$i\]";
763
764 if (defined($opt{$o})) {
765 $o = $opt{$o};
766 $retval = "$retval$o";
767 } elsif (defined($opt{$var})) {
768 $o = $opt{$var};
769 $retval = "$retval$o";
770 } else {
771 $retval = "$retval\$\{$var\}";
772 }
773
774 $option = $end;
775 }
776
777 $retval = "$retval$option";
778
779 $retval =~ s/^ //;
780
781 return $retval;
782}
783
784sub eval_option {
785 my ($option, $i) = @_;
786
787 my $prev = "";
788
789 # Since an option can evaluate to another option,
790 # keep iterating until we do not evaluate any more
791 # options.
792 my $r = 0;
793 while ($prev ne $option) {
794 # Check for recursive evaluations.
795 # 100 deep should be more than enough.
796 if ($r++ > 100) {
797 die "Over 100 evaluations accurred with $option\n" .
798 "Check for recursive variables\n";
799 }
800 $prev = $option;
801 $option = __eval_option($option, $i);
802 }
803
804 return $option;
805}
806
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500807sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400808 if (defined($opt{"LOG_FILE"})) {
809 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
810 print OUT @_;
811 close(OUT);
812 }
813}
814
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500815sub logit {
816 if (defined($opt{"LOG_FILE"})) {
817 _logit @_;
818 } else {
819 print @_;
820 }
821}
822
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400823sub doprint {
824 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500825 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400826}
827
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400828sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200829sub start_monitor;
830sub end_monitor;
831sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400832
833sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200834 my ($time) = @_;
835
Steven Rostedt2b803362011-09-30 18:00:23 -0400836 if (defined($time)) {
837 start_monitor;
838 # flush out current monitor
839 # May contain the reboot success line
840 wait_for_monitor 1;
841 }
842
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400843 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400844 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400845 if (defined($powercycle_after_reboot)) {
846 sleep $powercycle_after_reboot;
847 run_command "$power_cycle";
848 }
849 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400850 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400851 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400852 }
Andrew Jones2728be42011-08-12 15:32:05 +0200853
854 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400855 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200856 end_monitor;
857 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400858}
859
Steven Rostedt576f6272010-11-02 14:58:38 -0400860sub do_not_reboot {
861 my $i = $iteration;
862
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400863 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400864 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
865 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
866}
867
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400868sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400869 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400870
Steven Rostedt576f6272010-11-02 14:58:38 -0400871 my $i = $iteration;
872
873 if ($reboot_on_error && !do_not_reboot) {
874
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400875 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400876 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400877
Steven Rostedta75fece2010-11-02 14:58:27 -0400878 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400879 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400880 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400881 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400882
Steven Rostedtf80802c2011-03-07 13:18:47 -0500883 if (defined($opt{"LOG_FILE"})) {
884 print " See $opt{LOG_FILE} for more info.\n";
885 }
886
Steven Rostedt576f6272010-11-02 14:58:38 -0400887 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400888}
889
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400890sub open_console {
891 my ($fp) = @_;
892
893 my $flags;
894
Steven Rostedta75fece2010-11-02 14:58:27 -0400895 my $pid = open($fp, "$console|") or
896 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400897
898 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400899 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400900 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400901 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400902
903 return $pid;
904}
905
906sub close_console {
907 my ($fp, $pid) = @_;
908
909 doprint "kill child process $pid\n";
910 kill 2, $pid;
911
912 print "closing!\n";
913 close($fp);
914}
915
916sub start_monitor {
917 if ($monitor_cnt++) {
918 return;
919 }
920 $monitor_fp = \*MONFD;
921 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400922
923 return;
924
925 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400926}
927
928sub end_monitor {
929 if (--$monitor_cnt) {
930 return;
931 }
932 close_console($monitor_fp, $monitor_pid);
933}
934
935sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -0400936 my ($time, $stop) = @_;
937 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400938 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -0400939 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400940
Steven Rostedta75fece2010-11-02 14:58:27 -0400941 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400942
943 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -0400944 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400945 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -0400946 last if (!defined($line));
947 print "$line";
948 $full_line .= $line;
949
950 if (defined($stop) && $full_line =~ /$stop/) {
951 doprint "wait for monitor detected $stop\n";
952 $booted = 1;
953 }
954
955 if ($line =~ /\n/) {
956 $full_line = "";
957 }
958 }
Steven Rostedta75fece2010-11-02 14:58:27 -0400959 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400960}
961
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400962sub fail {
963
Steven Rostedta75fece2010-11-02 14:58:27 -0400964 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400965 dodie @_;
966 }
967
Steven Rostedta75fece2010-11-02 14:58:27 -0400968 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400969
Steven Rostedt576f6272010-11-02 14:58:38 -0400970 my $i = $iteration;
971
Steven Rostedta75fece2010-11-02 14:58:27 -0400972 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -0400973 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400974 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +0200975 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -0400976 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400977
Steven Rostedt9064af52011-06-13 10:38:48 -0400978 my $name = "";
979
980 if (defined($test_name)) {
981 $name = " ($test_name)";
982 }
983
Steven Rostedt576f6272010-11-02 14:58:38 -0400984 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
985 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -0400986 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -0400987 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
988 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400989
990 return 1 if (!defined($store_failures));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400991
992 my @t = localtime;
993 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
994 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
995
Steven Rostedtcccae1a2010-11-09 12:21:32 -0500996 my $type = $build_type;
997 if ($type =~ /useconfig/) {
998 $type = "useconfig";
999 }
1000
1001 my $dir = "$machine-$test_type-$type-fail-$date";
Steven Rostedta75fece2010-11-02 14:58:27 -04001002 my $faildir = "$store_failures/$dir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001003
1004 if (!-d $faildir) {
1005 mkpath($faildir) or
Steven Rostedta75fece2010-11-02 14:58:27 -04001006 die "can't create $faildir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001007 }
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001008 if (-f "$output_config") {
1009 cp "$output_config", "$faildir/config" or
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001010 die "failed to copy .config";
1011 }
1012 if (-f $buildlog) {
1013 cp $buildlog, "$faildir/buildlog" or
1014 die "failed to move $buildlog";
1015 }
1016 if (-f $dmesg) {
1017 cp $dmesg, "$faildir/dmesg" or
1018 die "failed to move $dmesg";
1019 }
1020
1021 doprint "*** Saved info to $faildir ***\n";
1022
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001023 return 1;
1024}
1025
Steven Rostedt2545eb62010-11-02 15:01:32 -04001026sub run_command {
1027 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001028 my $dolog = 0;
1029 my $dord = 0;
1030 my $pid;
1031
Steven Rostedte48c5292010-11-02 14:35:37 -04001032 $command =~ s/\$SSH_USER/$ssh_user/g;
1033 $command =~ s/\$MACHINE/$machine/g;
1034
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001035 doprint("$command ... ");
1036
1037 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001038 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001039
1040 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001041 open(LOG, ">>$opt{LOG_FILE}") or
1042 dodie "failed to write to log";
1043 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001044 }
1045
1046 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001047 open (RD, ">$redirect") or
1048 dodie "failed to write to redirect $redirect";
1049 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001050 }
1051
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001052 while (<CMD>) {
1053 print LOG if ($dolog);
1054 print RD if ($dord);
1055 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001056
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001057 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001058 my $failed = $?;
1059
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001060 close(CMD);
1061 close(LOG) if ($dolog);
1062 close(RD) if ($dord);
1063
Steven Rostedt2545eb62010-11-02 15:01:32 -04001064 if ($failed) {
1065 doprint "FAILED!\n";
1066 } else {
1067 doprint "SUCCESS\n";
1068 }
1069
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001070 return !$failed;
1071}
1072
Steven Rostedte48c5292010-11-02 14:35:37 -04001073sub run_ssh {
1074 my ($cmd) = @_;
1075 my $cp_exec = $ssh_exec;
1076
1077 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1078 return run_command "$cp_exec";
1079}
1080
1081sub run_scp {
1082 my ($src, $dst) = @_;
1083 my $cp_scp = $scp_to_target;
1084
1085 $cp_scp =~ s/\$SRC_FILE/$src/g;
1086 $cp_scp =~ s/\$DST_FILE/$dst/g;
1087
1088 return run_command "$cp_scp";
1089}
1090
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001091sub get_grub_index {
1092
Steven Rostedta75fece2010-11-02 14:58:27 -04001093 if ($reboot_type ne "grub") {
1094 return;
1095 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001096 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001097
1098 doprint "Find grub menu ... ";
1099 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001100
1101 my $ssh_grub = $ssh_exec;
1102 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1103
1104 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001105 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001106
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001107 my $found = 0;
1108
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001109 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001110 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001111 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001112 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001113 last;
1114 } elsif (/^\s*title\s/) {
1115 $grub_number++;
1116 }
1117 }
1118 close(IN);
1119
Steven Rostedta75fece2010-11-02 14:58:27 -04001120 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001121 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001122 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001123}
1124
Steven Rostedt2545eb62010-11-02 15:01:32 -04001125sub wait_for_input
1126{
1127 my ($fp, $time) = @_;
1128 my $rin;
1129 my $ready;
1130 my $line;
1131 my $ch;
1132
1133 if (!defined($time)) {
1134 $time = $timeout;
1135 }
1136
1137 $rin = '';
1138 vec($rin, fileno($fp), 1) = 1;
1139 $ready = select($rin, undef, undef, $time);
1140
1141 $line = "";
1142
1143 # try to read one char at a time
1144 while (sysread $fp, $ch, 1) {
1145 $line .= $ch;
1146 last if ($ch eq "\n");
1147 }
1148
1149 if (!length($line)) {
1150 return undef;
1151 }
1152
1153 return $line;
1154}
1155
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001156sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001157 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001158 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1159 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001160 return;
1161 }
1162
1163 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001164}
1165
Steven Rostedta57419b2010-11-02 15:13:54 -04001166sub get_sha1 {
1167 my ($commit) = @_;
1168
1169 doprint "git rev-list --max-count=1 $commit ... ";
1170 my $sha1 = `git rev-list --max-count=1 $commit`;
1171 my $ret = $?;
1172
1173 logit $sha1;
1174
1175 if ($ret) {
1176 doprint "FAILED\n";
1177 dodie "Failed to get git $commit";
1178 }
1179
1180 print "SUCCESS\n";
1181
1182 chomp $sha1;
1183
1184 return $sha1;
1185}
1186
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001187sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001188 my $booted = 0;
1189 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001190 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001191 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001192
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001193 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001194
1195 my $line;
1196 my $full_line = "";
1197
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001198 open(DMESG, "> $dmesg") or
1199 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001200
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001201 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001202
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001203 my $success_start;
1204 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001205 my $monitor_start = time;
1206 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001207 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001208
Steven Rostedt2d01b262011-03-08 09:47:54 -05001209 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001210
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001211 if ($bug && defined($stop_after_failure) &&
1212 $stop_after_failure >= 0) {
1213 my $time = $stop_after_failure - (time - $failure_start);
1214 $line = wait_for_input($monitor_fp, $time);
1215 if (!defined($line)) {
1216 doprint "bug timed out after $booted_timeout seconds\n";
1217 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1218 last;
1219 }
1220 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001221 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001222 if (!defined($line)) {
1223 my $s = $booted_timeout == 1 ? "" : "s";
1224 doprint "Successful boot found: break after $booted_timeout second$s\n";
1225 last;
1226 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001227 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001228 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001229 if (!defined($line)) {
1230 my $s = $timeout == 1 ? "" : "s";
1231 doprint "Timed out after $timeout second$s\n";
1232 last;
1233 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001234 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001235
Steven Rostedt2545eb62010-11-02 15:01:32 -04001236 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001237 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001238
1239 # we are not guaranteed to get a full line
1240 $full_line .= $line;
1241
Steven Rostedta75fece2010-11-02 14:58:27 -04001242 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001243 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001244 $success_start = time;
1245 }
1246
1247 if ($booted && defined($stop_after_success) &&
1248 $stop_after_success >= 0) {
1249 my $now = time;
1250 if ($now - $success_start >= $stop_after_success) {
1251 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1252 last;
1253 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001254 }
1255
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001256 if ($full_line =~ /\[ backtrace testing \]/) {
1257 $skip_call_trace = 1;
1258 }
1259
Steven Rostedt2545eb62010-11-02 15:01:32 -04001260 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001261 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001262 $bug = 1;
1263 $failure_start = time;
1264 }
1265 }
1266
1267 if ($bug && defined($stop_after_failure) &&
1268 $stop_after_failure >= 0) {
1269 my $now = time;
1270 if ($now - $failure_start >= $stop_after_failure) {
1271 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1272 last;
1273 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001274 }
1275
1276 if ($full_line =~ /\[ end of backtrace testing \]/) {
1277 $skip_call_trace = 0;
1278 }
1279
1280 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001281 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001282 $bug = 1;
1283 }
1284
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001285 # Detect triple faults by testing the banner
1286 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1287 if ($1 eq $version) {
1288 $version_found = 1;
1289 } elsif ($version_found && $detect_triplefault) {
1290 # We already booted into the kernel we are testing,
1291 # but now we booted into another kernel?
1292 # Consider this a triple fault.
1293 doprint "Aleady booted in Linux kernel $version, but now\n";
1294 doprint "we booted into Linux kernel $1.\n";
1295 doprint "Assuming that this is a triple fault.\n";
1296 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1297 last;
1298 }
1299 }
1300
Steven Rostedt2545eb62010-11-02 15:01:32 -04001301 if ($line =~ /\n/) {
1302 $full_line = "";
1303 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001304
1305 if ($stop_test_after > 0 && !$booted && !$bug) {
1306 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001307 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001308 $done = 1;
1309 }
1310 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001311 }
1312
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001313 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001314
Steven Rostedt2545eb62010-11-02 15:01:32 -04001315 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001316 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001317 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001318 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001319
Steven Rostedta75fece2010-11-02 14:58:27 -04001320 if (!$booted) {
1321 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001322 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001323 }
1324
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001325 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001326}
1327
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001328sub do_post_install {
1329
1330 return if (!defined($post_install));
1331
1332 my $cp_post_install = $post_install;
1333 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1334 run_command "$cp_post_install" or
1335 dodie "Failed to run post install";
1336}
1337
Steven Rostedt2545eb62010-11-02 15:01:32 -04001338sub install {
1339
Steven Rostedte0a87422011-09-30 17:50:48 -04001340 return if ($no_install);
1341
Steven Rostedte48c5292010-11-02 14:35:37 -04001342 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001343 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001344
1345 my $install_mods = 0;
1346
1347 # should we process modules?
1348 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001349 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001350 while (<IN>) {
1351 if (/CONFIG_MODULES(=y)?/) {
1352 $install_mods = 1 if (defined($1));
1353 last;
1354 }
1355 }
1356 close(IN);
1357
1358 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001359 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001360 doprint "No modules needed\n";
1361 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001362 }
1363
Steven Rostedta75fece2010-11-02 14:58:27 -04001364 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001365 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001366
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001367 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001368 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001369
Steven Rostedte48c5292010-11-02 14:35:37 -04001370 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001371 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001372
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001373 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001374 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001375 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001376
Steven Rostedte48c5292010-11-02 14:35:37 -04001377 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001378 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001379
Steven Rostedta75fece2010-11-02 14:58:27 -04001380 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001381
Steven Rostedte7b13442011-06-14 20:44:36 -04001382 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001383 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001384
Steven Rostedte48c5292010-11-02 14:35:37 -04001385 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001386
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001387 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001388}
1389
Steven Rostedtddf607e2011-06-14 20:49:13 -04001390sub get_version {
1391 # get the release name
1392 doprint "$make kernelrelease ... ";
1393 $version = `$make kernelrelease | tail -1`;
1394 chomp($version);
1395 doprint "$version\n";
1396}
1397
1398sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001399 # Make sure the stable kernel has finished booting
1400 start_monitor;
1401 wait_for_monitor 5;
1402 end_monitor;
1403
Steven Rostedtddf607e2011-06-14 20:49:13 -04001404 get_grub_index;
1405 get_version;
1406 install;
1407
1408 start_monitor;
1409 return monitor;
1410}
1411
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001412sub check_buildlog {
1413 my ($patch) = @_;
1414
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001415 my @files = `git show $patch | diffstat -l`;
1416
1417 open(IN, "git show $patch |") or
1418 dodie "failed to show $patch";
1419 while (<IN>) {
1420 if (m,^--- a/(.*),) {
1421 chomp $1;
1422 $files[$#files] = $1;
1423 }
1424 }
1425 close(IN);
1426
1427 open(IN, $buildlog) or dodie "Can't open $buildlog";
1428 while (<IN>) {
1429 if (/^\s*(.*?):.*(warning|error)/) {
1430 my $err = $1;
1431 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001432 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001433 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001434 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001435 }
1436 }
1437 }
1438 }
1439 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001440
1441 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001442}
1443
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001444sub apply_min_config {
1445 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001446
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001447 # Read the config file and remove anything that
1448 # is in the force_config hash (from minconfig and others)
1449 # then add the force config back.
1450
1451 doprint "Applying minimum configurations into $output_config.new\n";
1452
1453 open (OUT, ">$outconfig") or
1454 dodie "Can't create $outconfig";
1455
1456 if (-f $output_config) {
1457 open (IN, $output_config) or
1458 dodie "Failed to open $output_config";
1459 while (<IN>) {
1460 if (/^(# )?(CONFIG_[^\s=]*)/) {
1461 next if (defined($force_config{$2}));
1462 }
1463 print OUT;
1464 }
1465 close IN;
1466 }
1467 foreach my $config (keys %force_config) {
1468 print OUT "$force_config{$config}\n";
1469 }
1470 close OUT;
1471
1472 run_command "mv $outconfig $output_config";
1473}
1474
1475sub make_oldconfig {
1476
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001477 my @force_list = keys %force_config;
1478
1479 if ($#force_list >= 0) {
1480 apply_min_config;
1481 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001482
1483 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001484 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1485 # try a yes '' | oldconfig
1486 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001487 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001488 dodie "failed make config oldconfig";
1489 }
1490}
1491
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001492# read a config file and use this to force new configs.
1493sub load_force_config {
1494 my ($config) = @_;
1495
1496 open(IN, $config) or
1497 dodie "failed to read $config";
1498 while (<IN>) {
1499 chomp;
1500 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1501 $force_config{$1} = $_;
1502 } elsif (/^# (CONFIG_\S*) is not set/) {
1503 $force_config{$1} = $_;
1504 }
1505 }
1506 close IN;
1507}
1508
Steven Rostedt2545eb62010-11-02 15:01:32 -04001509sub build {
1510 my ($type) = @_;
1511
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001512 unlink $buildlog;
1513
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001514 # Failed builds should not reboot the target
1515 my $save_no_reboot = $no_reboot;
1516 $no_reboot = 1;
1517
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001518 if (defined($pre_build)) {
1519 my $ret = run_command $pre_build;
1520 if (!$ret && defined($pre_build_die) &&
1521 $pre_build_die) {
1522 dodie "failed to pre_build\n";
1523 }
1524 }
1525
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001526 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001527 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001528 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001529
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001530 $type = "oldconfig";
1531 }
1532
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001533 # old config can ask questions
1534 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001535 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001536
1537 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001538 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001539
Andrew Jones13488232011-08-12 15:32:04 +02001540 if (!$noclean) {
1541 run_command "mv $output_config $outputdir/config_temp" or
1542 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001543
Andrew Jones13488232011-08-12 15:32:04 +02001544 run_command "$make mrproper" or dodie "make mrproper";
1545
1546 run_command "mv $outputdir/config_temp $output_config" or
1547 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001548 }
1549
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001550 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001551 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001552 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001553 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001554 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001555
1556 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001557 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1558 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001559 close(OUT);
1560
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001561 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001562 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001563 }
1564
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001565 if ($type ne "oldnoconfig") {
1566 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001567 dodie "failed make config";
1568 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001569 # Run old config regardless, to enforce min configurations
1570 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001571
Steven Rostedta75fece2010-11-02 14:58:27 -04001572 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001573 my $build_ret = run_command "$make $build_options";
1574 undef $redirect;
1575
1576 if (defined($post_build)) {
1577 my $ret = run_command $post_build;
1578 if (!$ret && defined($post_build_die) &&
1579 $post_build_die) {
1580 dodie "failed to post_build\n";
1581 }
1582 }
1583
1584 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001585 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001586 if ($in_bisect) {
1587 $no_reboot = $save_no_reboot;
1588 return 0;
1589 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001590 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001591 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001592
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001593 $no_reboot = $save_no_reboot;
1594
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001595 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001596}
1597
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001598sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001599 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001600 if (defined($poweroff_after_halt)) {
1601 sleep $poweroff_after_halt;
1602 run_command "$power_off";
1603 }
1604 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001605 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001606 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001607 }
1608}
1609
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001610sub success {
1611 my ($i) = @_;
1612
Steven Rostedte48c5292010-11-02 14:35:37 -04001613 $successes++;
1614
Steven Rostedt9064af52011-06-13 10:38:48 -04001615 my $name = "";
1616
1617 if (defined($test_name)) {
1618 $name = " ($test_name)";
1619 }
1620
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001621 doprint "\n\n*******************************************\n";
1622 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001623 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001624 doprint "*******************************************\n";
1625 doprint "*******************************************\n";
1626
Steven Rostedt576f6272010-11-02 14:58:38 -04001627 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001628 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001629 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001630 }
1631}
1632
Steven Rostedtc960bb92011-03-08 09:22:39 -05001633sub answer_bisect {
1634 for (;;) {
1635 doprint "Pass or fail? [p/f]";
1636 my $ans = <STDIN>;
1637 chomp $ans;
1638 if ($ans eq "p" || $ans eq "P") {
1639 return 1;
1640 } elsif ($ans eq "f" || $ans eq "F") {
1641 return 0;
1642 } else {
1643 print "Please answer 'P' or 'F'\n";
1644 }
1645 }
1646}
1647
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001648sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001649 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001650
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001651 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001652 $reboot_on_error = 0;
1653 $poweroff_on_error = 0;
1654 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001655
1656 run_command $run_test or $failed = 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001657 exit $failed;
1658}
1659
1660my $child_done;
1661
1662sub child_finished {
1663 $child_done = 1;
1664}
1665
1666sub do_run_test {
1667 my $child_pid;
1668 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001669 my $line;
1670 my $full_line;
1671 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001672
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001673 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001674
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001675 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001676
1677 $child_done = 0;
1678
1679 $SIG{CHLD} = qw(child_finished);
1680
1681 $child_pid = fork;
1682
1683 child_run_test if (!$child_pid);
1684
1685 $full_line = "";
1686
1687 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001688 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001689 if (defined($line)) {
1690
1691 # we are not guaranteed to get a full line
1692 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001693 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001694
1695 if ($full_line =~ /call trace:/i) {
1696 $bug = 1;
1697 }
1698
1699 if ($full_line =~ /Kernel panic -/) {
1700 $bug = 1;
1701 }
1702
1703 if ($line =~ /\n/) {
1704 $full_line = "";
1705 }
1706 }
1707 } while (!$child_done && !$bug);
1708
1709 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001710 my $failure_start = time;
1711 my $now;
1712 do {
1713 $line = wait_for_input($monitor_fp, 1);
1714 if (defined($line)) {
1715 doprint $line;
1716 }
1717 $now = time;
1718 if ($now - $failure_start >= $stop_after_failure) {
1719 last;
1720 }
1721 } while (defined($line));
1722
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001723 doprint "Detected kernel crash!\n";
1724 # kill the child with extreme prejudice
1725 kill 9, $child_pid;
1726 }
1727
1728 waitpid $child_pid, 0;
1729 $child_exit = $?;
1730
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001731 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001732 return 0 if $in_bisect;
1733 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001734 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001735 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001736}
1737
Steven Rostedta75fece2010-11-02 14:58:27 -04001738sub run_git_bisect {
1739 my ($command) = @_;
1740
1741 doprint "$command ... ";
1742
1743 my $output = `$command 2>&1`;
1744 my $ret = $?;
1745
1746 logit $output;
1747
1748 if ($ret) {
1749 doprint "FAILED\n";
1750 dodie "Failed to git bisect";
1751 }
1752
1753 doprint "SUCCESS\n";
1754 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1755 doprint "$1 [$2]\n";
1756 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1757 $bisect_bad = $1;
1758 doprint "Found bad commit... $1\n";
1759 return 0;
1760 } else {
1761 # we already logged it, just print it now.
1762 print $output;
1763 }
1764
1765 return 1;
1766}
1767
Steven Rostedtc23dca72011-03-08 09:26:31 -05001768sub bisect_reboot {
1769 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001770 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001771}
1772
1773# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001774sub run_bisect_test {
1775 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001776
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001777 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001778 my $result;
1779 my $output;
1780 my $ret;
1781
Steven Rostedt0a05c762010-11-08 11:14:10 -05001782 $in_bisect = 1;
1783
1784 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001785
1786 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001787 if ($failed && $bisect_skip) {
1788 $in_bisect = 0;
1789 return -1;
1790 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001791 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001792
1793 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001794 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001795
1796 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001797 if ($failed && $bisect_skip) {
1798 end_monitor;
1799 bisect_reboot;
1800 $in_bisect = 0;
1801 return -1;
1802 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001803 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001804
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001805 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001806 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001807 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001808 }
1809
1810 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001811 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001812 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001813 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001814 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001815
1816 # reboot the box to a kernel we can ssh to
1817 if ($type ne "build") {
1818 bisect_reboot;
1819 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001820 $in_bisect = 0;
1821
1822 return $result;
1823}
1824
1825sub run_bisect {
1826 my ($type) = @_;
1827 my $buildtype = "oldconfig";
1828
1829 # We should have a minconfig to use?
1830 if (defined($minconfig)) {
1831 $buildtype = "useconfig:$minconfig";
1832 }
1833
1834 my $ret = run_bisect_test $type, $buildtype;
1835
Steven Rostedtc960bb92011-03-08 09:22:39 -05001836 if ($bisect_manual) {
1837 $ret = answer_bisect;
1838 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001839
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001840 # Are we looking for where it worked, not failed?
1841 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001842 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001843 }
1844
Steven Rostedtc23dca72011-03-08 09:26:31 -05001845 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001846 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001847 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001848 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001849 } elsif ($bisect_skip) {
1850 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1851 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001852 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001853}
1854
1855sub bisect {
1856 my ($i) = @_;
1857
1858 my $result;
1859
1860 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1861 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1862 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1863
1864 my $good = $opt{"BISECT_GOOD[$i]"};
1865 my $bad = $opt{"BISECT_BAD[$i]"};
1866 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001867 my $start = $opt{"BISECT_START[$i]"};
1868 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001869 my $start_files = $opt{"BISECT_FILES[$i]"};
1870
1871 if (defined($start_files)) {
1872 $start_files = " -- " . $start_files;
1873 } else {
1874 $start_files = "";
1875 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001876
Steven Rostedta57419b2010-11-02 15:13:54 -04001877 # convert to true sha1's
1878 $good = get_sha1($good);
1879 $bad = get_sha1($bad);
1880
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001881 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1882 $opt{"BISECT_REVERSE[$i]"} == 1) {
1883 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1884 $reverse_bisect = 1;
1885 } else {
1886 $reverse_bisect = 0;
1887 }
1888
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001889 # Can't have a test without having a test to run
1890 if ($type eq "test" && !defined($run_test)) {
1891 $type = "boot";
1892 }
1893
Steven Rostedta75fece2010-11-02 14:58:27 -04001894 my $check = $opt{"BISECT_CHECK[$i]"};
1895 if (defined($check) && $check ne "0") {
1896
1897 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001898 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001899
1900 if ($check ne "good") {
1901 doprint "TESTING BISECT BAD [$bad]\n";
1902 run_command "git checkout $bad" or
1903 die "Failed to checkout $bad";
1904
1905 $result = run_bisect $type;
1906
1907 if ($result ne "bad") {
1908 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1909 }
1910 }
1911
1912 if ($check ne "bad") {
1913 doprint "TESTING BISECT GOOD [$good]\n";
1914 run_command "git checkout $good" or
1915 die "Failed to checkout $good";
1916
1917 $result = run_bisect $type;
1918
1919 if ($result ne "good") {
1920 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1921 }
1922 }
1923
1924 # checkout where we started
1925 run_command "git checkout $head" or
1926 die "Failed to checkout $head";
1927 }
1928
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001929 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001930 dodie "could not start bisect";
1931
1932 run_command "git bisect good $good" or
1933 dodie "could not set bisect good to $good";
1934
1935 run_git_bisect "git bisect bad $bad" or
1936 dodie "could not set bisect bad to $bad";
1937
1938 if (defined($replay)) {
1939 run_command "git bisect replay $replay" or
1940 dodie "failed to run replay";
1941 }
1942
1943 if (defined($start)) {
1944 run_command "git checkout $start" or
1945 dodie "failed to checkout $start";
1946 }
1947
1948 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001949 do {
1950 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001951 $test = run_git_bisect "git bisect $result";
1952 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001953
1954 run_command "git bisect log" or
1955 dodie "could not capture git bisect log";
1956
1957 run_command "git bisect reset" or
1958 dodie "could not reset git bisect";
1959
1960 doprint "Bad commit was [$bisect_bad]\n";
1961
Steven Rostedt0a05c762010-11-08 11:14:10 -05001962 success $i;
1963}
1964
1965my %config_ignore;
1966my %config_set;
1967
1968my %config_list;
1969my %null_config;
1970
1971my %dependency;
1972
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001973sub assign_configs {
1974 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001975
1976 open (IN, $config)
1977 or dodie "Failed to read $config";
1978
1979 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04001980 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001981 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001982 }
1983 }
1984
1985 close(IN);
1986}
1987
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001988sub process_config_ignore {
1989 my ($config) = @_;
1990
1991 assign_configs \%config_ignore, $config;
1992}
1993
Steven Rostedt0a05c762010-11-08 11:14:10 -05001994sub read_current_config {
1995 my ($config_ref) = @_;
1996
1997 %{$config_ref} = ();
1998 undef %{$config_ref};
1999
2000 my @key = keys %{$config_ref};
2001 if ($#key >= 0) {
2002 print "did not delete!\n";
2003 exit;
2004 }
2005 open (IN, "$output_config");
2006
2007 while (<IN>) {
2008 if (/^(CONFIG\S+)=(.*)/) {
2009 ${$config_ref}{$1} = $2;
2010 }
2011 }
2012 close(IN);
2013}
2014
2015sub get_dependencies {
2016 my ($config) = @_;
2017
2018 my $arr = $dependency{$config};
2019 if (!defined($arr)) {
2020 return ();
2021 }
2022
2023 my @deps = @{$arr};
2024
2025 foreach my $dep (@{$arr}) {
2026 print "ADD DEP $dep\n";
2027 @deps = (@deps, get_dependencies $dep);
2028 }
2029
2030 return @deps;
2031}
2032
2033sub create_config {
2034 my @configs = @_;
2035
2036 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2037
2038 foreach my $config (@configs) {
2039 print OUT "$config_set{$config}\n";
2040 my @deps = get_dependencies $config;
2041 foreach my $dep (@deps) {
2042 print OUT "$config_set{$dep}\n";
2043 }
2044 }
2045
2046 foreach my $config (keys %config_ignore) {
2047 print OUT "$config_ignore{$config}\n";
2048 }
2049 close(OUT);
2050
2051# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002052 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002053}
2054
2055sub compare_configs {
2056 my (%a, %b) = @_;
2057
2058 foreach my $item (keys %a) {
2059 if (!defined($b{$item})) {
2060 print "diff $item\n";
2061 return 1;
2062 }
2063 delete $b{$item};
2064 }
2065
2066 my @keys = keys %b;
2067 if ($#keys) {
2068 print "diff2 $keys[0]\n";
2069 }
2070 return -1 if ($#keys >= 0);
2071
2072 return 0;
2073}
2074
2075sub run_config_bisect_test {
2076 my ($type) = @_;
2077
2078 return run_bisect_test $type, "oldconfig";
2079}
2080
2081sub process_passed {
2082 my (%configs) = @_;
2083
2084 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2085 # Passed! All these configs are part of a good compile.
2086 # Add them to the min options.
2087 foreach my $config (keys %configs) {
2088 if (defined($config_list{$config})) {
2089 doprint " removing $config\n";
2090 $config_ignore{$config} = $config_list{$config};
2091 delete $config_list{$config};
2092 }
2093 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002094 doprint "config copied to $outputdir/config_good\n";
2095 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002096}
2097
2098sub process_failed {
2099 my ($config) = @_;
2100
2101 doprint "\n\n***************************************\n";
2102 doprint "Found bad config: $config\n";
2103 doprint "***************************************\n\n";
2104}
2105
2106sub run_config_bisect {
2107
2108 my @start_list = keys %config_list;
2109
2110 if ($#start_list < 0) {
2111 doprint "No more configs to test!!!\n";
2112 return -1;
2113 }
2114
2115 doprint "***** RUN TEST ***\n";
2116 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2117 my $ret;
2118 my %current_config;
2119
2120 my $count = $#start_list + 1;
2121 doprint " $count configs to test\n";
2122
2123 my $half = int($#start_list / 2);
2124
2125 do {
2126 my @tophalf = @start_list[0 .. $half];
2127
2128 create_config @tophalf;
2129 read_current_config \%current_config;
2130
2131 $count = $#tophalf + 1;
2132 doprint "Testing $count configs\n";
2133 my $found = 0;
2134 # make sure we test something
2135 foreach my $config (@tophalf) {
2136 if (defined($current_config{$config})) {
2137 logit " $config\n";
2138 $found = 1;
2139 }
2140 }
2141 if (!$found) {
2142 # try the other half
2143 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002144 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002145 create_config @tophalf;
2146 read_current_config \%current_config;
2147 foreach my $config (@tophalf) {
2148 if (defined($current_config{$config})) {
2149 logit " $config\n";
2150 $found = 1;
2151 }
2152 }
2153 if (!$found) {
2154 doprint "Failed: Can't make new config with current configs\n";
2155 foreach my $config (@start_list) {
2156 doprint " CONFIG: $config\n";
2157 }
2158 return -1;
2159 }
2160 $count = $#tophalf + 1;
2161 doprint "Testing $count configs\n";
2162 }
2163
2164 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002165 if ($bisect_manual) {
2166 $ret = answer_bisect;
2167 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002168 if ($ret) {
2169 process_passed %current_config;
2170 return 0;
2171 }
2172
2173 doprint "This config had a failure.\n";
2174 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002175 doprint "config copied to $outputdir/config_bad\n";
2176 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002177
2178 # A config exists in this group that was bad.
2179 foreach my $config (keys %config_list) {
2180 if (!defined($current_config{$config})) {
2181 doprint " removing $config\n";
2182 delete $config_list{$config};
2183 }
2184 }
2185
2186 @start_list = @tophalf;
2187
2188 if ($#start_list == 0) {
2189 process_failed $start_list[0];
2190 return 1;
2191 }
2192
2193 # remove half the configs we are looking at and see if
2194 # they are good.
2195 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002196 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002197
Steven Rostedtc960bb92011-03-08 09:22:39 -05002198 # we found a single config, try it again unless we are running manually
2199
2200 if ($bisect_manual) {
2201 process_failed $start_list[0];
2202 return 1;
2203 }
2204
Steven Rostedt0a05c762010-11-08 11:14:10 -05002205 my @tophalf = @start_list[0 .. 0];
2206
2207 $ret = run_config_bisect_test $type;
2208 if ($ret) {
2209 process_passed %current_config;
2210 return 0;
2211 }
2212
2213 process_failed $start_list[0];
2214 return 1;
2215}
2216
2217sub config_bisect {
2218 my ($i) = @_;
2219
2220 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2221
2222 my $tmpconfig = "$tmpdir/use_config";
2223
Steven Rostedt30f75da2011-06-13 10:35:35 -04002224 if (defined($config_bisect_good)) {
2225 process_config_ignore $config_bisect_good;
2226 }
2227
Steven Rostedt0a05c762010-11-08 11:14:10 -05002228 # Make the file with the bad config and the min config
2229 if (defined($minconfig)) {
2230 # read the min config for things to ignore
2231 run_command "cp $minconfig $tmpconfig" or
2232 dodie "failed to copy $minconfig to $tmpconfig";
2233 } else {
2234 unlink $tmpconfig;
2235 }
2236
Steven Rostedt0a05c762010-11-08 11:14:10 -05002237 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002238 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002239 process_config_ignore $tmpconfig;
2240 }
2241
2242 # now process the start config
2243 run_command "cp $start_config $output_config" or
2244 dodie "failed to copy $start_config to $output_config";
2245
2246 # read directly what we want to check
2247 my %config_check;
2248 open (IN, $output_config)
2249 or dodie "faied to open $output_config";
2250
2251 while (<IN>) {
2252 if (/^((CONFIG\S*)=.*)/) {
2253 $config_check{$2} = $1;
2254 }
2255 }
2256 close(IN);
2257
Steven Rostedt250bae82011-07-15 22:05:59 -04002258 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002259 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002260
2261 # check to see what we lost (or gained)
2262 open (IN, $output_config)
2263 or dodie "Failed to read $start_config";
2264
2265 my %removed_configs;
2266 my %added_configs;
2267
2268 while (<IN>) {
2269 if (/^((CONFIG\S*)=.*)/) {
2270 # save off all options
2271 $config_set{$2} = $1;
2272 if (defined($config_check{$2})) {
2273 if (defined($config_ignore{$2})) {
2274 $removed_configs{$2} = $1;
2275 } else {
2276 $config_list{$2} = $1;
2277 }
2278 } elsif (!defined($config_ignore{$2})) {
2279 $added_configs{$2} = $1;
2280 $config_list{$2} = $1;
2281 }
2282 }
2283 }
2284 close(IN);
2285
2286 my @confs = keys %removed_configs;
2287 if ($#confs >= 0) {
2288 doprint "Configs overridden by default configs and removed from check:\n";
2289 foreach my $config (@confs) {
2290 doprint " $config\n";
2291 }
2292 }
2293 @confs = keys %added_configs;
2294 if ($#confs >= 0) {
2295 doprint "Configs appearing in make oldconfig and added:\n";
2296 foreach my $config (@confs) {
2297 doprint " $config\n";
2298 }
2299 }
2300
2301 my %config_test;
2302 my $once = 0;
2303
2304 # Sometimes kconfig does weird things. We must make sure
2305 # that the config we autocreate has everything we need
2306 # to test, otherwise we may miss testing configs, or
2307 # may not be able to create a new config.
2308 # Here we create a config with everything set.
2309 create_config (keys %config_list);
2310 read_current_config \%config_test;
2311 foreach my $config (keys %config_list) {
2312 if (!defined($config_test{$config})) {
2313 if (!$once) {
2314 $once = 1;
2315 doprint "Configs not produced by kconfig (will not be checked):\n";
2316 }
2317 doprint " $config\n";
2318 delete $config_list{$config};
2319 }
2320 }
2321 my $ret;
2322 do {
2323 $ret = run_config_bisect;
2324 } while (!$ret);
2325
2326 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002327
2328 success $i;
2329}
2330
Steven Rostedt27d934b2011-05-20 09:18:18 -04002331sub patchcheck_reboot {
2332 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002333 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002334}
2335
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002336sub patchcheck {
2337 my ($i) = @_;
2338
2339 die "PATCHCHECK_START[$i] not defined\n"
2340 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2341 die "PATCHCHECK_TYPE[$i] not defined\n"
2342 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2343
2344 my $start = $opt{"PATCHCHECK_START[$i]"};
2345
2346 my $end = "HEAD";
2347 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2348 $end = $opt{"PATCHCHECK_END[$i]"};
2349 }
2350
Steven Rostedta57419b2010-11-02 15:13:54 -04002351 # Get the true sha1's since we can use things like HEAD~3
2352 $start = get_sha1($start);
2353 $end = get_sha1($end);
2354
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002355 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2356
2357 # Can't have a test without having a test to run
2358 if ($type eq "test" && !defined($run_test)) {
2359 $type = "boot";
2360 }
2361
2362 open (IN, "git log --pretty=oneline $end|") or
2363 dodie "could not get git list";
2364
2365 my @list;
2366
2367 while (<IN>) {
2368 chomp;
2369 $list[$#list+1] = $_;
2370 last if (/^$start/);
2371 }
2372 close(IN);
2373
2374 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002375 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002376 }
2377
2378 # go backwards in the list
2379 @list = reverse @list;
2380
2381 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002382 my %ignored_warnings;
2383
2384 if (defined($ignore_warnings)) {
2385 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2386 $ignored_warnings{$sha1} = 1;
2387 }
2388 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002389
2390 $in_patchcheck = 1;
2391 foreach my $item (@list) {
2392 my $sha1 = $item;
2393 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2394
2395 doprint "\nProcessing commit $item\n\n";
2396
2397 run_command "git checkout $sha1" or
2398 die "Failed to checkout $sha1";
2399
2400 # only clean on the first and last patch
2401 if ($item eq $list[0] ||
2402 $item eq $list[$#list]) {
2403 $noclean = $save_clean;
2404 } else {
2405 $noclean = 1;
2406 }
2407
2408 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002409 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002410 } else {
2411 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002412 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002413 }
2414
Steven Rostedt19902072011-06-14 20:46:25 -04002415
2416 if (!defined($ignored_warnings{$sha1})) {
2417 check_buildlog $sha1 or return 0;
2418 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002419
2420 next if ($type eq "build");
2421
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002422 my $failed = 0;
2423
Steven Rostedtddf607e2011-06-14 20:49:13 -04002424 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002425
2426 if (!$failed && $type ne "boot"){
2427 do_run_test or $failed = 1;
2428 }
2429 end_monitor;
2430 return 0 if ($failed);
2431
Steven Rostedt27d934b2011-05-20 09:18:18 -04002432 patchcheck_reboot;
2433
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002434 }
2435 $in_patchcheck = 0;
2436 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002437
2438 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002439}
2440
Steven Rostedtb9066f62011-07-15 21:25:24 -04002441my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002442my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002443my $iflevel = 0;
2444my @ifdeps;
2445
2446# prevent recursion
2447my %read_kconfigs;
2448
Steven Rostedtac6974c2011-10-04 09:40:17 -04002449sub add_dep {
2450 # $config depends on $dep
2451 my ($config, $dep) = @_;
2452
2453 if (defined($depends{$config})) {
2454 $depends{$config} .= " " . $dep;
2455 } else {
2456 $depends{$config} = $dep;
2457 }
2458
2459 # record the number of configs depending on $dep
2460 if (defined $depcount{$dep}) {
2461 $depcount{$dep}++;
2462 } else {
2463 $depcount{$dep} = 1;
2464 }
2465}
2466
Steven Rostedtb9066f62011-07-15 21:25:24 -04002467# taken from streamline_config.pl
2468sub read_kconfig {
2469 my ($kconfig) = @_;
2470
2471 my $state = "NONE";
2472 my $config;
2473 my @kconfigs;
2474
2475 my $cont = 0;
2476 my $line;
2477
2478
2479 if (! -f $kconfig) {
2480 doprint "file $kconfig does not exist, skipping\n";
2481 return;
2482 }
2483
2484 open(KIN, "$kconfig")
2485 or die "Can't open $kconfig";
2486 while (<KIN>) {
2487 chomp;
2488
2489 # Make sure that lines ending with \ continue
2490 if ($cont) {
2491 $_ = $line . " " . $_;
2492 }
2493
2494 if (s/\\$//) {
2495 $cont = 1;
2496 $line = $_;
2497 next;
2498 }
2499
2500 $cont = 0;
2501
2502 # collect any Kconfig sources
2503 if (/^source\s*"(.*)"/) {
2504 $kconfigs[$#kconfigs+1] = $1;
2505 }
2506
2507 # configs found
2508 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2509 $state = "NEW";
2510 $config = $2;
2511
2512 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002513 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002514 }
2515
2516 # collect the depends for the config
2517 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2518
Steven Rostedtac6974c2011-10-04 09:40:17 -04002519 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002520
2521 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002522 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2523
2524 # selected by depends on config
2525 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002526
2527 # Check for if statements
2528 } elsif (/^if\s+(.*\S)\s*$/) {
2529 my $deps = $1;
2530 # remove beginning and ending non text
2531 $deps =~ s/^[^a-zA-Z0-9_]*//;
2532 $deps =~ s/[^a-zA-Z0-9_]*$//;
2533
2534 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2535
2536 $ifdeps[$iflevel++] = join ':', @deps;
2537
2538 } elsif (/^endif/) {
2539
2540 $iflevel-- if ($iflevel);
2541
2542 # stop on "help"
2543 } elsif (/^\s*help\s*$/) {
2544 $state = "NONE";
2545 }
2546 }
2547 close(KIN);
2548
2549 # read in any configs that were found.
2550 foreach $kconfig (@kconfigs) {
2551 if (!defined($read_kconfigs{$kconfig})) {
2552 $read_kconfigs{$kconfig} = 1;
2553 read_kconfig("$builddir/$kconfig");
2554 }
2555 }
2556}
2557
2558sub read_depends {
2559 # find out which arch this is by the kconfig file
2560 open (IN, $output_config)
2561 or dodie "Failed to read $output_config";
2562 my $arch;
2563 while (<IN>) {
2564 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2565 $arch = $1;
2566 last;
2567 }
2568 }
2569 close IN;
2570
2571 if (!defined($arch)) {
2572 doprint "Could not find arch from config file\n";
2573 doprint "no dependencies used\n";
2574 return;
2575 }
2576
2577 # arch is really the subarch, we need to know
2578 # what directory to look at.
2579 if ($arch eq "i386" || $arch eq "x86_64") {
2580 $arch = "x86";
2581 } elsif ($arch =~ /^tile/) {
2582 $arch = "tile";
2583 }
2584
2585 my $kconfig = "$builddir/arch/$arch/Kconfig";
2586
2587 if (! -f $kconfig && $arch =~ /\d$/) {
2588 my $orig = $arch;
2589 # some subarchs have numbers, truncate them
2590 $arch =~ s/\d*$//;
2591 $kconfig = "$builddir/arch/$arch/Kconfig";
2592 if (! -f $kconfig) {
2593 doprint "No idea what arch dir $orig is for\n";
2594 doprint "no dependencies used\n";
2595 return;
2596 }
2597 }
2598
2599 read_kconfig($kconfig);
2600}
2601
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002602sub read_config_list {
2603 my ($config) = @_;
2604
2605 open (IN, $config)
2606 or dodie "Failed to read $config";
2607
2608 while (<IN>) {
2609 if (/^((CONFIG\S*)=.*)/) {
2610 if (!defined($config_ignore{$2})) {
2611 $config_list{$2} = $1;
2612 }
2613 }
2614 }
2615
2616 close(IN);
2617}
2618
2619sub read_output_config {
2620 my ($config) = @_;
2621
2622 assign_configs \%config_ignore, $config;
2623}
2624
2625sub make_new_config {
2626 my @configs = @_;
2627
2628 open (OUT, ">$output_config")
2629 or dodie "Failed to write $output_config";
2630
2631 foreach my $config (@configs) {
2632 print OUT "$config\n";
2633 }
2634 close OUT;
2635}
2636
Steven Rostedtac6974c2011-10-04 09:40:17 -04002637sub chomp_config {
2638 my ($config) = @_;
2639
2640 $config =~ s/CONFIG_//;
2641
2642 return $config;
2643}
2644
Steven Rostedtb9066f62011-07-15 21:25:24 -04002645sub get_depends {
2646 my ($dep) = @_;
2647
Steven Rostedtac6974c2011-10-04 09:40:17 -04002648 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002649
2650 $dep = $depends{"$kconfig"};
2651
2652 # the dep string we have saves the dependencies as they
2653 # were found, including expressions like ! && ||. We
2654 # want to split this out into just an array of configs.
2655
2656 my $valid = "A-Za-z_0-9";
2657
2658 my @configs;
2659
2660 while ($dep =~ /[$valid]/) {
2661
2662 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2663 my $conf = "CONFIG_" . $1;
2664
2665 $configs[$#configs + 1] = $conf;
2666
2667 $dep =~ s/^[^$valid]*[$valid]+//;
2668 } else {
2669 die "this should never happen";
2670 }
2671 }
2672
2673 return @configs;
2674}
2675
2676my %min_configs;
2677my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002678my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002679my %processed_configs;
2680my %nochange_config;
2681
2682sub test_this_config {
2683 my ($config) = @_;
2684
2685 my $found;
2686
2687 # if we already processed this config, skip it
2688 if (defined($processed_configs{$config})) {
2689 return undef;
2690 }
2691 $processed_configs{$config} = 1;
2692
2693 # if this config failed during this round, skip it
2694 if (defined($nochange_config{$config})) {
2695 return undef;
2696 }
2697
Steven Rostedtac6974c2011-10-04 09:40:17 -04002698 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002699
2700 # Test dependencies first
2701 if (defined($depends{"$kconfig"})) {
2702 my @parents = get_depends $config;
2703 foreach my $parent (@parents) {
2704 # if the parent is in the min config, check it first
2705 next if (!defined($min_configs{$parent}));
2706 $found = test_this_config($parent);
2707 if (defined($found)) {
2708 return $found;
2709 }
2710 }
2711 }
2712
2713 # Remove this config from the list of configs
2714 # do a make oldnoconfig and then read the resulting
2715 # .config to make sure it is missing the config that
2716 # we had before
2717 my %configs = %min_configs;
2718 delete $configs{$config};
2719 make_new_config ((values %configs), (values %keep_configs));
2720 make_oldconfig;
2721 undef %configs;
2722 assign_configs \%configs, $output_config;
2723
2724 return $config if (!defined($configs{$config}));
2725
2726 doprint "disabling config $config did not change .config\n";
2727
2728 $nochange_config{$config} = 1;
2729
2730 return undef;
2731}
2732
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002733sub make_min_config {
2734 my ($i) = @_;
2735
2736 if (!defined($output_minconfig)) {
2737 fail "OUTPUT_MIN_CONFIG not defined" and return;
2738 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002739
2740 # If output_minconfig exists, and the start_minconfig
2741 # came from min_config, than ask if we should use
2742 # that instead.
2743 if (-f $output_minconfig && !$start_minconfig_defined) {
2744 print "$output_minconfig exists\n";
2745 if (read_yn " Use it as minconfig?") {
2746 $start_minconfig = $output_minconfig;
2747 }
2748 }
2749
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002750 if (!defined($start_minconfig)) {
2751 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2752 }
2753
Steven Rostedt35ce5952011-07-15 21:57:25 -04002754 my $temp_config = "$tmpdir/temp_config";
2755
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002756 # First things first. We build an allnoconfig to find
2757 # out what the defaults are that we can't touch.
2758 # Some are selections, but we really can't handle selections.
2759
2760 my $save_minconfig = $minconfig;
2761 undef $minconfig;
2762
2763 run_command "$make allnoconfig" or return 0;
2764
Steven Rostedtb9066f62011-07-15 21:25:24 -04002765 read_depends;
2766
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002767 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002768
Steven Rostedt43d1b652011-07-15 22:01:56 -04002769 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002770 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002771
2772 if (defined($ignore_config)) {
2773 # make sure the file exists
2774 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002775 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002776 }
2777
Steven Rostedt43d1b652011-07-15 22:01:56 -04002778 %keep_configs = %save_configs;
2779
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002780 doprint "Load initial configs from $start_minconfig\n";
2781
2782 # Look at the current min configs, and save off all the
2783 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002784 assign_configs \%min_configs, $start_minconfig;
2785
2786 my @config_keys = keys %min_configs;
2787
Steven Rostedtac6974c2011-10-04 09:40:17 -04002788 # All configs need a depcount
2789 foreach my $config (@config_keys) {
2790 my $kconfig = chomp_config $config;
2791 if (!defined $depcount{$kconfig}) {
2792 $depcount{$kconfig} = 0;
2793 }
2794 }
2795
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002796 # Remove anything that was set by the make allnoconfig
2797 # we shouldn't need them as they get set for us anyway.
2798 foreach my $config (@config_keys) {
2799 # Remove anything in the ignore_config
2800 if (defined($keep_configs{$config})) {
2801 my $file = $ignore_config;
2802 $file =~ s,.*/(.*?)$,$1,;
2803 doprint "$config set by $file ... ignored\n";
2804 delete $min_configs{$config};
2805 next;
2806 }
2807 # But make sure the settings are the same. If a min config
2808 # sets a selection, we do not want to get rid of it if
2809 # it is not the same as what we have. Just move it into
2810 # the keep configs.
2811 if (defined($config_ignore{$config})) {
2812 if ($config_ignore{$config} ne $min_configs{$config}) {
2813 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2814 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2815 $keep_configs{$config} = $min_configs{$config};
2816 } else {
2817 doprint "$config set by allnoconfig ... ignored\n";
2818 }
2819 delete $min_configs{$config};
2820 }
2821 }
2822
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002823 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002824 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002825
2826 while (!$done) {
2827
2828 my $config;
2829 my $found;
2830
2831 # Now disable each config one by one and do a make oldconfig
2832 # till we find a config that changes our list.
2833
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002834 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002835
2836 # Sort keys by who is most dependent on
2837 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2838 @test_configs ;
2839
2840 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002841 my $reset = 1;
2842 for (my $i = 0; $i < $#test_configs; $i++) {
2843 if (!defined($nochange_config{$test_configs[0]})) {
2844 $reset = 0;
2845 last;
2846 }
2847 # This config didn't change the .config last time.
2848 # Place it at the end
2849 my $config = shift @test_configs;
2850 push @test_configs, $config;
2851 }
2852
2853 # if every test config has failed to modify the .config file
2854 # in the past, then reset and start over.
2855 if ($reset) {
2856 undef %nochange_config;
2857 }
2858
Steven Rostedtb9066f62011-07-15 21:25:24 -04002859 undef %processed_configs;
2860
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002861 foreach my $config (@test_configs) {
2862
Steven Rostedtb9066f62011-07-15 21:25:24 -04002863 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002864
Steven Rostedtb9066f62011-07-15 21:25:24 -04002865 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002866
2867 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002868 }
2869
2870 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002871 # we could have failed due to the nochange_config hash
2872 # reset and try again
2873 if (!$take_two) {
2874 undef %nochange_config;
2875 $take_two = 1;
2876 next;
2877 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002878 doprint "No more configs found that we can disable\n";
2879 $done = 1;
2880 last;
2881 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04002882 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002883
2884 $config = $found;
2885
2886 doprint "Test with $config disabled\n";
2887
2888 # set in_bisect to keep build and monitor from dieing
2889 $in_bisect = 1;
2890
2891 my $failed = 0;
2892 build "oldconfig";
2893 start_monitor_and_boot or $failed = 1;
2894 end_monitor;
2895
2896 $in_bisect = 0;
2897
2898 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002899 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002900 # this config is needed, add it to the ignore list.
2901 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04002902 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002903 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04002904
2905 # update new ignore configs
2906 if (defined($ignore_config)) {
2907 open (OUT, ">$temp_config")
2908 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04002909 foreach my $config (keys %save_configs) {
2910 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002911 }
2912 close OUT;
2913 run_command "mv $temp_config $ignore_config" or
2914 dodie "failed to copy update to $ignore_config";
2915 }
2916
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002917 } else {
2918 # We booted without this config, remove it from the minconfigs.
2919 doprint "$config is not needed, disabling\n";
2920
2921 delete $min_configs{$config};
2922
2923 # Also disable anything that is not enabled in this config
2924 my %configs;
2925 assign_configs \%configs, $output_config;
2926 my @config_keys = keys %min_configs;
2927 foreach my $config (@config_keys) {
2928 if (!defined($configs{$config})) {
2929 doprint "$config is not set, disabling\n";
2930 delete $min_configs{$config};
2931 }
2932 }
2933
2934 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04002935 open (OUT, ">$temp_config")
2936 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002937 foreach my $config (keys %keep_configs) {
2938 print OUT "$keep_configs{$config}\n";
2939 }
2940 foreach my $config (keys %min_configs) {
2941 print OUT "$min_configs{$config}\n";
2942 }
2943 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04002944
2945 run_command "mv $temp_config $output_minconfig" or
2946 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002947 }
2948
2949 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002950 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002951 }
2952
2953 success $i;
2954 return 1;
2955}
2956
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002957$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002958
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002959if ($#ARGV == 0) {
2960 $ktest_config = $ARGV[0];
2961 if (! -f $ktest_config) {
2962 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002963 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002964 exit 0;
2965 }
2966 }
2967} else {
2968 $ktest_config = "ktest.conf";
2969}
2970
2971if (! -f $ktest_config) {
2972 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2973 print OUT << "EOF"
2974# Generated by ktest.pl
2975#
2976# Define each test with TEST_START
2977# The config options below it will override the defaults
2978TEST_START
2979
2980DEFAULTS
2981EOF
2982;
2983 close(OUT);
2984}
2985read_config $ktest_config;
2986
Steven Rostedt23715c3c2011-06-13 11:03:34 -04002987if (defined($opt{"LOG_FILE"})) {
2988 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2989}
2990
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002991# Append any configs entered in manually to the config file.
2992my @new_configs = keys %entered_configs;
2993if ($#new_configs >= 0) {
2994 print "\nAppending entered in configs to $ktest_config\n";
2995 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2996 foreach my $config (@new_configs) {
2997 print OUT "$config = $entered_configs{$config}\n";
2998 $opt{$config} = $entered_configs{$config};
2999 }
3000}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003001
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003002if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3003 unlink $opt{"LOG_FILE"};
3004}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003005
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003006doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3007
Steven Rostedta57419b2010-11-02 15:13:54 -04003008for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3009
3010 if (!$i) {
3011 doprint "DEFAULT OPTIONS:\n";
3012 } else {
3013 doprint "\nTEST $i OPTIONS";
3014 if (defined($repeat_tests{$i})) {
3015 $repeat = $repeat_tests{$i};
3016 doprint " ITERATE $repeat";
3017 }
3018 doprint "\n";
3019 }
3020
3021 foreach my $option (sort keys %opt) {
3022
3023 if ($option =~ /\[(\d+)\]$/) {
3024 next if ($i != $1);
3025 } else {
3026 next if ($i);
3027 }
3028
3029 doprint "$option = $opt{$option}\n";
3030 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003031}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003032
Steven Rostedt2a625122011-05-20 15:48:59 -04003033sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003034 my ($name, $i) = @_;
3035
3036 my $option = "$name\[$i\]";
3037
3038 if (defined($opt{$option})) {
3039 return $opt{$option};
3040 }
3041
Steven Rostedta57419b2010-11-02 15:13:54 -04003042 foreach my $test (keys %repeat_tests) {
3043 if ($i >= $test &&
3044 $i < $test + $repeat_tests{$test}) {
3045 $option = "$name\[$test\]";
3046 if (defined($opt{$option})) {
3047 return $opt{$option};
3048 }
3049 }
3050 }
3051
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003052 if (defined($opt{$name})) {
3053 return $opt{$name};
3054 }
3055
3056 return undef;
3057}
3058
Steven Rostedt2a625122011-05-20 15:48:59 -04003059sub set_test_option {
3060 my ($name, $i) = @_;
3061
3062 my $option = __set_test_option($name, $i);
3063 return $option if (!defined($option));
3064
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003065 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003066}
3067
Steven Rostedt2545eb62010-11-02 15:01:32 -04003068# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003069for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003070
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003071 # Do not reboot on failing test options
3072 $no_reboot = 1;
3073
Steven Rostedt576f6272010-11-02 14:58:38 -04003074 $iteration = $i;
3075
Steven Rostedta75fece2010-11-02 14:58:27 -04003076 my $makecmd = set_test_option("MAKE_CMD", $i);
3077
3078 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003079 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003080 $tmpdir = set_test_option("TMP_DIR", $i);
3081 $outputdir = set_test_option("OUTPUT_DIR", $i);
3082 $builddir = set_test_option("BUILD_DIR", $i);
3083 $test_type = set_test_option("TEST_TYPE", $i);
3084 $build_type = set_test_option("BUILD_TYPE", $i);
3085 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003086 $pre_build = set_test_option("PRE_BUILD", $i);
3087 $post_build = set_test_option("POST_BUILD", $i);
3088 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3089 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003090 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003091 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003092 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3093 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003094 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3095 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3096 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003097 $run_test = set_test_option("TEST", $i);
3098 $addconfig = set_test_option("ADD_CONFIG", $i);
3099 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3100 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003101 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003102 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003103 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3104 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3105 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3106 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3107 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003108 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3109 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003110 $sleep_time = set_test_option("SLEEP_TIME", $i);
3111 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003112 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003113 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003114 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003115 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003116 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003117 $store_failures = set_test_option("STORE_FAILURES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003118 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003119 $timeout = set_test_option("TIMEOUT", $i);
3120 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3121 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003122 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003123 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003124 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003125 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3126 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003127 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003128 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003129 $ssh_exec = set_test_option("SSH_EXEC", $i);
3130 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003131 $target_image = set_test_option("TARGET_IMAGE", $i);
3132 $localversion = set_test_option("LOCALVERSION", $i);
3133
Steven Rostedt35ce5952011-07-15 21:57:25 -04003134 $start_minconfig_defined = 1;
3135
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003136 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003137 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003138 $start_minconfig = $minconfig;
3139 }
3140
Steven Rostedta75fece2010-11-02 14:58:27 -04003141 chdir $builddir || die "can't change directory to $builddir";
3142
Andrew Jonesa908a662011-08-12 15:32:03 +02003143 foreach my $dir ($tmpdir, $outputdir) {
3144 if (!-d $dir) {
3145 mkpath($dir) or
3146 die "can't create $dir";
3147 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003148 }
3149
Steven Rostedte48c5292010-11-02 14:35:37 -04003150 $ENV{"SSH_USER"} = $ssh_user;
3151 $ENV{"MACHINE"} = $machine;
3152
Steven Rostedta75fece2010-11-02 14:58:27 -04003153 $target = "$ssh_user\@$machine";
3154
3155 $buildlog = "$tmpdir/buildlog-$machine";
3156 $dmesg = "$tmpdir/dmesg-$machine";
3157 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003158 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003159
3160 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04003161 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04003162 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04003163 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04003164 }
3165
3166 my $run_type = $build_type;
3167 if ($test_type eq "patchcheck") {
3168 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3169 } elsif ($test_type eq "bisect") {
3170 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003171 } elsif ($test_type eq "config_bisect") {
3172 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003173 }
3174
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003175 if ($test_type eq "make_min_config") {
3176 $run_type = "";
3177 }
3178
Steven Rostedta75fece2010-11-02 14:58:27 -04003179 # mistake in config file?
3180 if (!defined($run_type)) {
3181 $run_type = "ERROR";
3182 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003183
Steven Rostedte0a87422011-09-30 17:50:48 -04003184 my $installme = "";
3185 $installme = " no_install" if ($no_install);
3186
Steven Rostedt2545eb62010-11-02 15:01:32 -04003187 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003188 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003189
3190 unlink $dmesg;
3191 unlink $buildlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003192
Steven Rostedt250bae82011-07-15 22:05:59 -04003193 if (defined($addconfig)) {
3194 my $min = $minconfig;
3195 if (!defined($minconfig)) {
3196 $min = "";
3197 }
3198 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003199 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003200 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003201 }
3202
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003203 my $checkout = $opt{"CHECKOUT[$i]"};
3204 if (defined($checkout)) {
3205 run_command "git checkout $checkout" or
3206 die "failed to checkout $checkout";
3207 }
3208
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003209 $no_reboot = 0;
3210
3211
Steven Rostedta75fece2010-11-02 14:58:27 -04003212 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003213 bisect $i;
3214 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003215 } elsif ($test_type eq "config_bisect") {
3216 config_bisect $i;
3217 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003218 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003219 patchcheck $i;
3220 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003221 } elsif ($test_type eq "make_min_config") {
3222 make_min_config $i;
3223 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003224 }
3225
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003226 if ($build_type ne "nobuild") {
3227 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003228 }
3229
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003230 if ($test_type eq "install") {
3231 get_version;
3232 install;
3233 success $i;
3234 next;
3235 }
3236
Steven Rostedta75fece2010-11-02 14:58:27 -04003237 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003238 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003239 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003240
3241 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3242 do_run_test or $failed = 1;
3243 }
3244 end_monitor;
3245 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003246 }
3247
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003248 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003249}
3250
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003251if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003252 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003253} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003254 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003255}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003256
Steven Rostedte48c5292010-11-02 14:35:37 -04003257doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3258
Steven Rostedt2545eb62010-11-02 15:01:32 -04003259exit 0;