blob: 652446dd9e795764faf36944f8017b7bf125215b [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 Rostedt8d1491b2010-11-18 15:39:48 -0500139$config_help{"MACHINE"} = << "EOF"
140 The machine hostname that you will test.
141EOF
142 ;
143$config_help{"SSH_USER"} = << "EOF"
144 The box is expected to have ssh on normal bootup, provide the user
145 (most likely root, since you need privileged operations)
146EOF
147 ;
148$config_help{"BUILD_DIR"} = << "EOF"
149 The directory that contains the Linux source code (full path).
150EOF
151 ;
152$config_help{"OUTPUT_DIR"} = << "EOF"
153 The directory that the objects will be built (full path).
154 (can not be same as BUILD_DIR)
155EOF
156 ;
157$config_help{"BUILD_TARGET"} = << "EOF"
158 The location of the compiled file to copy to the target.
159 (relative to OUTPUT_DIR)
160EOF
161 ;
162$config_help{"TARGET_IMAGE"} = << "EOF"
163 The place to put your image on the test machine.
164EOF
165 ;
166$config_help{"POWER_CYCLE"} = << "EOF"
167 A script or command to reboot the box.
168
169 Here is a digital loggers power switch example
170 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
171
172 Here is an example to reboot a virtual box on the current host
173 with the name "Guest".
174 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
175EOF
176 ;
177$config_help{"CONSOLE"} = << "EOF"
178 The script or command that reads the console
179
180 If you use ttywatch server, something like the following would work.
181CONSOLE = nc -d localhost 3001
182
183 For a virtual machine with guest name "Guest".
184CONSOLE = virsh console Guest
185EOF
186 ;
187$config_help{"LOCALVERSION"} = << "EOF"
188 Required version ending to differentiate the test
189 from other linux builds on the system.
190EOF
191 ;
192$config_help{"REBOOT_TYPE"} = << "EOF"
193 Way to reboot the box to the test kernel.
194 Only valid options so far are "grub" and "script".
195
196 If you specify grub, it will assume grub version 1
197 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
198 and select that target to reboot to the kernel. If this is not
199 your setup, then specify "script" and have a command or script
200 specified in REBOOT_SCRIPT to boot to the target.
201
202 The entry in /boot/grub/menu.lst must be entered in manually.
203 The test will not modify that file.
204EOF
205 ;
206$config_help{"GRUB_MENU"} = << "EOF"
207 The grub title name for the test kernel to boot
208 (Only mandatory if REBOOT_TYPE = grub)
209
210 Note, ktest.pl will not update the grub menu.lst, you need to
211 manually add an option for the test. ktest.pl will search
212 the grub menu.lst for this option to find what kernel to
213 reboot into.
214
215 For example, if in the /boot/grub/menu.lst the test kernel title has:
216 title Test Kernel
217 kernel vmlinuz-test
218 GRUB_MENU = Test Kernel
219EOF
220 ;
221$config_help{"REBOOT_SCRIPT"} = << "EOF"
222 A script to reboot the target into the test kernel
223 (Only mandatory if REBOOT_TYPE = script)
224EOF
225 ;
226
Steven Rostedt35ce5952011-07-15 21:57:25 -0400227sub read_yn {
228 my ($prompt) = @_;
229
230 my $ans;
231
232 for (;;) {
233 print "$prompt [Y/n] ";
234 $ans = <STDIN>;
235 chomp $ans;
236 if ($ans =~ /^\s*$/) {
237 $ans = "y";
238 }
239 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
240 print "Please answer either 'y' or 'n'.\n";
241 }
242 if ($ans !~ /^y$/i) {
243 return 0;
244 }
245 return 1;
246}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500247
248sub get_ktest_config {
249 my ($config) = @_;
250
251 return if (defined($opt{$config}));
252
253 if (defined($config_help{$config})) {
254 print "\n";
255 print $config_help{$config};
256 }
257
258 for (;;) {
259 print "$config = ";
260 if (defined($default{$config})) {
261 print "\[$default{$config}\] ";
262 }
263 $entered_configs{$config} = <STDIN>;
264 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
265 if ($entered_configs{$config} =~ /^\s*$/) {
266 if ($default{$config}) {
267 $entered_configs{$config} = $default{$config};
268 } else {
269 print "Your answer can not be blank\n";
270 next;
271 }
272 }
273 last;
274 }
275}
276
277sub get_ktest_configs {
278 get_ktest_config("MACHINE");
279 get_ktest_config("SSH_USER");
280 get_ktest_config("BUILD_DIR");
281 get_ktest_config("OUTPUT_DIR");
282 get_ktest_config("BUILD_TARGET");
283 get_ktest_config("TARGET_IMAGE");
284 get_ktest_config("POWER_CYCLE");
285 get_ktest_config("CONSOLE");
286 get_ktest_config("LOCALVERSION");
287
288 my $rtype = $opt{"REBOOT_TYPE"};
289
290 if (!defined($rtype)) {
291 if (!defined($opt{"GRUB_MENU"})) {
292 get_ktest_config("REBOOT_TYPE");
293 $rtype = $entered_configs{"REBOOT_TYPE"};
294 } else {
295 $rtype = "grub";
296 }
297 }
298
299 if ($rtype eq "grub") {
300 get_ktest_config("GRUB_MENU");
301 } else {
302 get_ktest_config("REBOOT_SCRIPT");
303 }
304}
305
Steven Rostedt77d942c2011-05-20 13:36:58 -0400306sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400307 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400308 my $retval = "";
309
310 # We want to check for '\', and it is just easier
311 # to check the previous characet of '$' and not need
312 # to worry if '$' is the first character. By adding
313 # a space to $value, we can just check [^\\]\$ and
314 # it will still work.
315 $value = " $value";
316
317 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
318 my $begin = $1;
319 my $var = $2;
320 my $end = $3;
321 # append beginning of value to retval
322 $retval = "$retval$begin";
323 if (defined($variable{$var})) {
324 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400325 } elsif (defined($remove_undef) && $remove_undef) {
326 # for if statements, any variable that is not defined,
327 # we simple convert to 0
328 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400329 } else {
330 # put back the origin piece.
331 $retval = "$retval\$\{$var\}";
332 }
333 $value = $end;
334 }
335 $retval = "$retval$value";
336
337 # remove the space added in the beginning
338 $retval =~ s/ //;
339
340 return "$retval"
341}
342
Steven Rostedta57419b2010-11-02 15:13:54 -0400343sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400344 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400345
346 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400347 if (!$override || defined(${$overrides}{$lvalue})) {
348 my $extra = "";
349 if ($override) {
350 $extra = "In the same override section!\n";
351 }
352 die "$name: $.: Option $lvalue defined more than once!\n$extra";
353 }
354 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400355 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500356 if ($rvalue =~ /^\s*$/) {
357 delete $opt{$lvalue};
358 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400359 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500360 $opt{$lvalue} = $rvalue;
361 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400362}
363
Steven Rostedt77d942c2011-05-20 13:36:58 -0400364sub set_variable {
365 my ($lvalue, $rvalue) = @_;
366
367 if ($rvalue =~ /^\s*$/) {
368 delete $variable{$lvalue};
369 } else {
370 $rvalue = process_variables($rvalue);
371 $variable{$lvalue} = $rvalue;
372 }
373}
374
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400375sub process_compare {
376 my ($lval, $cmp, $rval) = @_;
377
378 # remove whitespace
379
380 $lval =~ s/^\s*//;
381 $lval =~ s/\s*$//;
382
383 $rval =~ s/^\s*//;
384 $rval =~ s/\s*$//;
385
386 if ($cmp eq "==") {
387 return $lval eq $rval;
388 } elsif ($cmp eq "!=") {
389 return $lval ne $rval;
390 }
391
392 my $statement = "$lval $cmp $rval";
393 my $ret = eval $statement;
394
395 # $@ stores error of eval
396 if ($@) {
397 return -1;
398 }
399
400 return $ret;
401}
402
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400403sub value_defined {
404 my ($val) = @_;
405
406 return defined($variable{$2}) ||
407 defined($opt{$2});
408}
409
Steven Rostedt8d735212011-10-17 11:36:44 -0400410my $d = 0;
411sub process_expression {
412 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400413
Steven Rostedt8d735212011-10-17 11:36:44 -0400414 my $c = $d++;
415
416 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
417 my $express = $1;
418
419 if (process_expression($name, $express)) {
420 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
421 } else {
422 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
423 }
424 }
425
426 $d--;
427 my $OR = "\\|\\|";
428 my $AND = "\\&\\&";
429
430 while ($val =~ s/^(.*?)($OR|$AND)//) {
431 my $express = $1;
432 my $op = $2;
433
434 if (process_expression($name, $express)) {
435 if ($op eq "||") {
436 return 1;
437 }
438 } else {
439 if ($op eq "&&") {
440 return 0;
441 }
442 }
443 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400444
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400445 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
446 my $ret = process_compare($1, $2, $3);
447 if ($ret < 0) {
448 die "$name: $.: Unable to process comparison\n";
449 }
450 return $ret;
451 }
452
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400453 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
454 if (defined $1) {
455 return !value_defined($2);
456 } else {
457 return value_defined($2);
458 }
459 }
460
Steven Rostedt45d73a52011-09-30 19:44:53 -0400461 if ($val =~ /^\s*0\s*$/) {
462 return 0;
463 } elsif ($val =~ /^\s*\d+\s*$/) {
464 return 1;
465 }
466
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400467 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400468}
469
470sub process_if {
471 my ($name, $value) = @_;
472
473 # Convert variables and replace undefined ones with 0
474 my $val = process_variables($value, 1);
475 my $ret = process_expression $name, $val;
476
477 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400478}
479
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400480sub __read_config {
481 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400482
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400483 my $in;
484 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400485
Steven Rostedta57419b2010-11-02 15:13:54 -0400486 my $name = $config;
487 $name =~ s,.*/(.*),$1,;
488
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400489 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400490 my $default = 1;
491 my $repeat = 1;
492 my $num_tests_set = 0;
493 my $skip = 0;
494 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400495 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400496 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400497 my $if = 0;
498 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400499 my $override = 0;
500
501 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400502
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400503 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400504
505 # ignore blank lines and comments
506 next if (/^\s*$/ || /\s*\#/);
507
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400508 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400509
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400510 my $type = $1;
511 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400512 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400513
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400514 my $old_test_num;
515 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400516 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400517
518 if ($type eq "TEST_START") {
519
520 if ($num_tests_set) {
521 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
522 }
523
524 $old_test_num = $test_num;
525 $old_repeat = $repeat;
526
527 $test_num += $repeat;
528 $default = 0;
529 $repeat = 1;
530 } else {
531 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400532 }
533
Steven Rostedta9f84422011-10-17 11:06:29 -0400534 # If SKIP is anywhere in the line, the command will be skipped
535 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400536 $skip = 1;
537 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400538 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400539 $skip = 0;
540 }
541
Steven Rostedta9f84422011-10-17 11:06:29 -0400542 if ($rest =~ s/\sELSE\b//) {
543 if (!$if) {
544 die "$name: $.: ELSE found with out matching IF section\n$_";
545 }
546 $if = 0;
547
548 if ($if_set) {
549 $skip = 1;
550 } else {
551 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400552 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400553 }
554
Steven Rostedta9f84422011-10-17 11:06:29 -0400555 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400556 if (process_if($name, $1)) {
557 $if_set = 1;
558 } else {
559 $skip = 1;
560 }
561 $if = 1;
562 } else {
563 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400564 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400565 }
566
Steven Rostedta9f84422011-10-17 11:06:29 -0400567 if (!$skip) {
568 if ($type eq "TEST_START") {
569 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
570 $repeat = $1;
571 $repeat_tests{"$test_num"} = $repeat;
572 }
573 } elsif ($rest =~ s/\sOVERRIDE\b//) {
574 # DEFAULT only
575 $override = 1;
576 # Clear previous overrides
577 %overrides = ();
578 }
579 }
580
581 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400582 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400583 }
584
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400585 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400586 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400587 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400588 }
589
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400590 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400591 if (!$if) {
592 die "$name: $.: ELSE found with out matching IF section\n$_";
593 }
594 $rest = $1;
595 if ($if_set) {
596 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400597 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400598 } else {
599 $skip = 0;
600
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400601 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400602 # May be a ELSE IF section.
603 if (!process_if($name, $1)) {
604 $skip = 1;
605 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400606 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400607 } else {
608 $if = 0;
609 }
610 }
611
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400612 if ($rest !~ /^\s*$/) {
613 die "$name: $.: Gargbage found after DEFAULTS\n$_";
614 }
615
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400616 } elsif (/^\s*INCLUDE\s+(\S+)/) {
617
618 next if ($skip);
619
620 if (!$default) {
621 die "$name: $.: INCLUDE can only be done in default sections\n$_";
622 }
623
624 my $file = process_variables($1);
625
626 if ($file !~ m,^/,) {
627 # check the path of the config file first
628 if ($config =~ m,(.*)/,) {
629 if (-f "$1/$file") {
630 $file = "$1/$file";
631 }
632 }
633 }
634
635 if ( ! -r $file ) {
636 die "$name: $.: Can't read file $file\n$_";
637 }
638
639 if (__read_config($file, \$test_num)) {
640 $test_case = 1;
641 }
642
Steven Rostedta57419b2010-11-02 15:13:54 -0400643 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
644
645 next if ($skip);
646
Steven Rostedt2545eb62010-11-02 15:01:32 -0400647 my $lvalue = $1;
648 my $rvalue = $2;
649
Steven Rostedta57419b2010-11-02 15:13:54 -0400650 if (!$default &&
651 ($lvalue eq "NUM_TESTS" ||
652 $lvalue eq "LOG_FILE" ||
653 $lvalue eq "CLEAR_LOG")) {
654 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400655 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400656
657 if ($lvalue eq "NUM_TESTS") {
658 if ($test_num) {
659 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
660 }
661 if (!$default) {
662 die "$name: $.: NUM_TESTS must be set in default section\n";
663 }
664 $num_tests_set = 1;
665 }
666
667 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400668 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400669 } else {
670 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400671 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400672
673 if ($repeat > 1) {
674 $repeats{$val} = $repeat;
675 }
676 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400677 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
678 next if ($skip);
679
680 my $lvalue = $1;
681 my $rvalue = $2;
682
683 # process config variables.
684 # Config variables are only active while reading the
685 # config and can be defined anywhere. They also ignore
686 # TEST_START and DEFAULTS, but are skipped if they are in
687 # on of these sections that have SKIP defined.
688 # The save variable can be
689 # defined multiple times and the new one simply overrides
690 # the prevous one.
691 set_variable($lvalue, $rvalue);
692
Steven Rostedta57419b2010-11-02 15:13:54 -0400693 } else {
694 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400695 }
696 }
697
Steven Rostedta57419b2010-11-02 15:13:54 -0400698 if ($test_num) {
699 $test_num += $repeat - 1;
700 $opt{"NUM_TESTS"} = $test_num;
701 }
702
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400703 close($in);
704
705 $$current_test_num = $test_num;
706
707 return $test_case;
708}
709
710sub read_config {
711 my ($config) = @_;
712
713 my $test_case;
714 my $test_num = 0;
715
716 $test_case = __read_config $config, \$test_num;
717
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500718 # make sure we have all mandatory configs
719 get_ktest_configs;
720
Steven Rostedt0df213c2011-06-14 20:51:37 -0400721 # was a test specified?
722 if (!$test_case) {
723 print "No test case specified.\n";
724 print "What test case would you like to run?\n";
725 my $ans = <STDIN>;
726 chomp $ans;
727 $default{"TEST_TYPE"} = $ans;
728 }
729
Steven Rostedta75fece2010-11-02 14:58:27 -0400730 # set any defaults
731
732 foreach my $default (keys %default) {
733 if (!defined($opt{$default})) {
734 $opt{$default} = $default{$default};
735 }
736 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400737}
738
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400739sub __eval_option {
740 my ($option, $i) = @_;
741
742 # Add space to evaluate the character before $
743 $option = " $option";
744 my $retval = "";
745
746 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
747 my $start = $1;
748 my $var = $2;
749 my $end = $3;
750
751 # Append beginning of line
752 $retval = "$retval$start";
753
754 # If the iteration option OPT[$i] exists, then use that.
755 # otherwise see if the default OPT (without [$i]) exists.
756
757 my $o = "$var\[$i\]";
758
759 if (defined($opt{$o})) {
760 $o = $opt{$o};
761 $retval = "$retval$o";
762 } elsif (defined($opt{$var})) {
763 $o = $opt{$var};
764 $retval = "$retval$o";
765 } else {
766 $retval = "$retval\$\{$var\}";
767 }
768
769 $option = $end;
770 }
771
772 $retval = "$retval$option";
773
774 $retval =~ s/^ //;
775
776 return $retval;
777}
778
779sub eval_option {
780 my ($option, $i) = @_;
781
782 my $prev = "";
783
784 # Since an option can evaluate to another option,
785 # keep iterating until we do not evaluate any more
786 # options.
787 my $r = 0;
788 while ($prev ne $option) {
789 # Check for recursive evaluations.
790 # 100 deep should be more than enough.
791 if ($r++ > 100) {
792 die "Over 100 evaluations accurred with $option\n" .
793 "Check for recursive variables\n";
794 }
795 $prev = $option;
796 $option = __eval_option($option, $i);
797 }
798
799 return $option;
800}
801
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500802sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400803 if (defined($opt{"LOG_FILE"})) {
804 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
805 print OUT @_;
806 close(OUT);
807 }
808}
809
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500810sub logit {
811 if (defined($opt{"LOG_FILE"})) {
812 _logit @_;
813 } else {
814 print @_;
815 }
816}
817
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400818sub doprint {
819 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500820 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400821}
822
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400823sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200824sub start_monitor;
825sub end_monitor;
826sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400827
828sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200829 my ($time) = @_;
830
Steven Rostedt2b803362011-09-30 18:00:23 -0400831 if (defined($time)) {
832 start_monitor;
833 # flush out current monitor
834 # May contain the reboot success line
835 wait_for_monitor 1;
836 }
837
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400838 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400839 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400840 if (defined($powercycle_after_reboot)) {
841 sleep $powercycle_after_reboot;
842 run_command "$power_cycle";
843 }
844 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400845 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400846 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400847 }
Andrew Jones2728be42011-08-12 15:32:05 +0200848
849 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400850 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200851 end_monitor;
852 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400853}
854
Steven Rostedt576f6272010-11-02 14:58:38 -0400855sub do_not_reboot {
856 my $i = $iteration;
857
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400858 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400859 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
860 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
861}
862
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400863sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400864 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400865
Steven Rostedt576f6272010-11-02 14:58:38 -0400866 my $i = $iteration;
867
868 if ($reboot_on_error && !do_not_reboot) {
869
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400870 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400871 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400872
Steven Rostedta75fece2010-11-02 14:58:27 -0400873 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400874 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400875 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400876 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400877
Steven Rostedtf80802c2011-03-07 13:18:47 -0500878 if (defined($opt{"LOG_FILE"})) {
879 print " See $opt{LOG_FILE} for more info.\n";
880 }
881
Steven Rostedt576f6272010-11-02 14:58:38 -0400882 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400883}
884
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400885sub open_console {
886 my ($fp) = @_;
887
888 my $flags;
889
Steven Rostedta75fece2010-11-02 14:58:27 -0400890 my $pid = open($fp, "$console|") or
891 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400892
893 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400894 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400895 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400896 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400897
898 return $pid;
899}
900
901sub close_console {
902 my ($fp, $pid) = @_;
903
904 doprint "kill child process $pid\n";
905 kill 2, $pid;
906
907 print "closing!\n";
908 close($fp);
909}
910
911sub start_monitor {
912 if ($monitor_cnt++) {
913 return;
914 }
915 $monitor_fp = \*MONFD;
916 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400917
918 return;
919
920 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400921}
922
923sub end_monitor {
924 if (--$monitor_cnt) {
925 return;
926 }
927 close_console($monitor_fp, $monitor_pid);
928}
929
930sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -0400931 my ($time, $stop) = @_;
932 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400933 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -0400934 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400935
Steven Rostedta75fece2010-11-02 14:58:27 -0400936 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400937
938 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -0400939 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400940 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -0400941 last if (!defined($line));
942 print "$line";
943 $full_line .= $line;
944
945 if (defined($stop) && $full_line =~ /$stop/) {
946 doprint "wait for monitor detected $stop\n";
947 $booted = 1;
948 }
949
950 if ($line =~ /\n/) {
951 $full_line = "";
952 }
953 }
Steven Rostedta75fece2010-11-02 14:58:27 -0400954 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400955}
956
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400957sub fail {
958
Steven Rostedta75fece2010-11-02 14:58:27 -0400959 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400960 dodie @_;
961 }
962
Steven Rostedta75fece2010-11-02 14:58:27 -0400963 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400964
Steven Rostedt576f6272010-11-02 14:58:38 -0400965 my $i = $iteration;
966
Steven Rostedta75fece2010-11-02 14:58:27 -0400967 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -0400968 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400969 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +0200970 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -0400971 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400972
Steven Rostedt9064af52011-06-13 10:38:48 -0400973 my $name = "";
974
975 if (defined($test_name)) {
976 $name = " ($test_name)";
977 }
978
Steven Rostedt576f6272010-11-02 14:58:38 -0400979 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
980 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -0400981 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -0400982 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
983 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400984
985 return 1 if (!defined($store_failures));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400986
987 my @t = localtime;
988 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
989 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
990
Steven Rostedtcccae1a2010-11-09 12:21:32 -0500991 my $type = $build_type;
992 if ($type =~ /useconfig/) {
993 $type = "useconfig";
994 }
995
996 my $dir = "$machine-$test_type-$type-fail-$date";
Steven Rostedta75fece2010-11-02 14:58:27 -0400997 my $faildir = "$store_failures/$dir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400998
999 if (!-d $faildir) {
1000 mkpath($faildir) or
Steven Rostedta75fece2010-11-02 14:58:27 -04001001 die "can't create $faildir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001002 }
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001003 if (-f "$output_config") {
1004 cp "$output_config", "$faildir/config" or
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001005 die "failed to copy .config";
1006 }
1007 if (-f $buildlog) {
1008 cp $buildlog, "$faildir/buildlog" or
1009 die "failed to move $buildlog";
1010 }
1011 if (-f $dmesg) {
1012 cp $dmesg, "$faildir/dmesg" or
1013 die "failed to move $dmesg";
1014 }
1015
1016 doprint "*** Saved info to $faildir ***\n";
1017
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001018 return 1;
1019}
1020
Steven Rostedt2545eb62010-11-02 15:01:32 -04001021sub run_command {
1022 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001023 my $dolog = 0;
1024 my $dord = 0;
1025 my $pid;
1026
Steven Rostedte48c5292010-11-02 14:35:37 -04001027 $command =~ s/\$SSH_USER/$ssh_user/g;
1028 $command =~ s/\$MACHINE/$machine/g;
1029
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001030 doprint("$command ... ");
1031
1032 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001033 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001034
1035 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001036 open(LOG, ">>$opt{LOG_FILE}") or
1037 dodie "failed to write to log";
1038 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001039 }
1040
1041 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001042 open (RD, ">$redirect") or
1043 dodie "failed to write to redirect $redirect";
1044 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001045 }
1046
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001047 while (<CMD>) {
1048 print LOG if ($dolog);
1049 print RD if ($dord);
1050 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001051
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001052 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001053 my $failed = $?;
1054
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001055 close(CMD);
1056 close(LOG) if ($dolog);
1057 close(RD) if ($dord);
1058
Steven Rostedt2545eb62010-11-02 15:01:32 -04001059 if ($failed) {
1060 doprint "FAILED!\n";
1061 } else {
1062 doprint "SUCCESS\n";
1063 }
1064
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001065 return !$failed;
1066}
1067
Steven Rostedte48c5292010-11-02 14:35:37 -04001068sub run_ssh {
1069 my ($cmd) = @_;
1070 my $cp_exec = $ssh_exec;
1071
1072 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1073 return run_command "$cp_exec";
1074}
1075
1076sub run_scp {
1077 my ($src, $dst) = @_;
1078 my $cp_scp = $scp_to_target;
1079
1080 $cp_scp =~ s/\$SRC_FILE/$src/g;
1081 $cp_scp =~ s/\$DST_FILE/$dst/g;
1082
1083 return run_command "$cp_scp";
1084}
1085
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001086sub get_grub_index {
1087
Steven Rostedta75fece2010-11-02 14:58:27 -04001088 if ($reboot_type ne "grub") {
1089 return;
1090 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001091 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001092
1093 doprint "Find grub menu ... ";
1094 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001095
1096 my $ssh_grub = $ssh_exec;
1097 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1098
1099 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001100 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001101
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001102 my $found = 0;
1103
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001104 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001105 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001106 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001107 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001108 last;
1109 } elsif (/^\s*title\s/) {
1110 $grub_number++;
1111 }
1112 }
1113 close(IN);
1114
Steven Rostedta75fece2010-11-02 14:58:27 -04001115 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001116 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001117 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001118}
1119
Steven Rostedt2545eb62010-11-02 15:01:32 -04001120sub wait_for_input
1121{
1122 my ($fp, $time) = @_;
1123 my $rin;
1124 my $ready;
1125 my $line;
1126 my $ch;
1127
1128 if (!defined($time)) {
1129 $time = $timeout;
1130 }
1131
1132 $rin = '';
1133 vec($rin, fileno($fp), 1) = 1;
1134 $ready = select($rin, undef, undef, $time);
1135
1136 $line = "";
1137
1138 # try to read one char at a time
1139 while (sysread $fp, $ch, 1) {
1140 $line .= $ch;
1141 last if ($ch eq "\n");
1142 }
1143
1144 if (!length($line)) {
1145 return undef;
1146 }
1147
1148 return $line;
1149}
1150
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001151sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001152 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001153 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1154 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001155 return;
1156 }
1157
1158 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001159}
1160
Steven Rostedta57419b2010-11-02 15:13:54 -04001161sub get_sha1 {
1162 my ($commit) = @_;
1163
1164 doprint "git rev-list --max-count=1 $commit ... ";
1165 my $sha1 = `git rev-list --max-count=1 $commit`;
1166 my $ret = $?;
1167
1168 logit $sha1;
1169
1170 if ($ret) {
1171 doprint "FAILED\n";
1172 dodie "Failed to get git $commit";
1173 }
1174
1175 print "SUCCESS\n";
1176
1177 chomp $sha1;
1178
1179 return $sha1;
1180}
1181
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001182sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001183 my $booted = 0;
1184 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001185 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001186 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001187
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001188 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001189
1190 my $line;
1191 my $full_line = "";
1192
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001193 open(DMESG, "> $dmesg") or
1194 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001195
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001196 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001197
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001198 my $success_start;
1199 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001200 my $monitor_start = time;
1201 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001202 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001203
Steven Rostedt2d01b262011-03-08 09:47:54 -05001204 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001205
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001206 if ($bug && defined($stop_after_failure) &&
1207 $stop_after_failure >= 0) {
1208 my $time = $stop_after_failure - (time - $failure_start);
1209 $line = wait_for_input($monitor_fp, $time);
1210 if (!defined($line)) {
1211 doprint "bug timed out after $booted_timeout seconds\n";
1212 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1213 last;
1214 }
1215 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001216 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001217 if (!defined($line)) {
1218 my $s = $booted_timeout == 1 ? "" : "s";
1219 doprint "Successful boot found: break after $booted_timeout second$s\n";
1220 last;
1221 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001222 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001223 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001224 if (!defined($line)) {
1225 my $s = $timeout == 1 ? "" : "s";
1226 doprint "Timed out after $timeout second$s\n";
1227 last;
1228 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001229 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001230
Steven Rostedt2545eb62010-11-02 15:01:32 -04001231 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001232 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001233
1234 # we are not guaranteed to get a full line
1235 $full_line .= $line;
1236
Steven Rostedta75fece2010-11-02 14:58:27 -04001237 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001238 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001239 $success_start = time;
1240 }
1241
1242 if ($booted && defined($stop_after_success) &&
1243 $stop_after_success >= 0) {
1244 my $now = time;
1245 if ($now - $success_start >= $stop_after_success) {
1246 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1247 last;
1248 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001249 }
1250
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001251 if ($full_line =~ /\[ backtrace testing \]/) {
1252 $skip_call_trace = 1;
1253 }
1254
Steven Rostedt2545eb62010-11-02 15:01:32 -04001255 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001256 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001257 $bug = 1;
1258 $failure_start = time;
1259 }
1260 }
1261
1262 if ($bug && defined($stop_after_failure) &&
1263 $stop_after_failure >= 0) {
1264 my $now = time;
1265 if ($now - $failure_start >= $stop_after_failure) {
1266 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1267 last;
1268 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001269 }
1270
1271 if ($full_line =~ /\[ end of backtrace testing \]/) {
1272 $skip_call_trace = 0;
1273 }
1274
1275 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001276 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001277 $bug = 1;
1278 }
1279
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001280 # Detect triple faults by testing the banner
1281 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1282 if ($1 eq $version) {
1283 $version_found = 1;
1284 } elsif ($version_found && $detect_triplefault) {
1285 # We already booted into the kernel we are testing,
1286 # but now we booted into another kernel?
1287 # Consider this a triple fault.
1288 doprint "Aleady booted in Linux kernel $version, but now\n";
1289 doprint "we booted into Linux kernel $1.\n";
1290 doprint "Assuming that this is a triple fault.\n";
1291 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1292 last;
1293 }
1294 }
1295
Steven Rostedt2545eb62010-11-02 15:01:32 -04001296 if ($line =~ /\n/) {
1297 $full_line = "";
1298 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001299
1300 if ($stop_test_after > 0 && !$booted && !$bug) {
1301 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001302 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001303 $done = 1;
1304 }
1305 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001306 }
1307
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001308 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001309
Steven Rostedt2545eb62010-11-02 15:01:32 -04001310 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001311 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001312 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001313 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001314
Steven Rostedta75fece2010-11-02 14:58:27 -04001315 if (!$booted) {
1316 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001317 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001318 }
1319
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001320 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001321}
1322
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001323sub do_post_install {
1324
1325 return if (!defined($post_install));
1326
1327 my $cp_post_install = $post_install;
1328 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1329 run_command "$cp_post_install" or
1330 dodie "Failed to run post install";
1331}
1332
Steven Rostedt2545eb62010-11-02 15:01:32 -04001333sub install {
1334
Steven Rostedte0a87422011-09-30 17:50:48 -04001335 return if ($no_install);
1336
Steven Rostedte48c5292010-11-02 14:35:37 -04001337 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001338 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001339
1340 my $install_mods = 0;
1341
1342 # should we process modules?
1343 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001344 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001345 while (<IN>) {
1346 if (/CONFIG_MODULES(=y)?/) {
1347 $install_mods = 1 if (defined($1));
1348 last;
1349 }
1350 }
1351 close(IN);
1352
1353 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001354 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001355 doprint "No modules needed\n";
1356 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001357 }
1358
Steven Rostedta75fece2010-11-02 14:58:27 -04001359 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001360 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001361
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001362 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001363 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001364
Steven Rostedte48c5292010-11-02 14:35:37 -04001365 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001366 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001367
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001368 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001369 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001370 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001371
Steven Rostedte48c5292010-11-02 14:35:37 -04001372 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001373 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001374
Steven Rostedta75fece2010-11-02 14:58:27 -04001375 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001376
Steven Rostedte7b13442011-06-14 20:44:36 -04001377 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001378 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001379
Steven Rostedte48c5292010-11-02 14:35:37 -04001380 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001381
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001382 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001383}
1384
Steven Rostedtddf607e2011-06-14 20:49:13 -04001385sub get_version {
1386 # get the release name
1387 doprint "$make kernelrelease ... ";
1388 $version = `$make kernelrelease | tail -1`;
1389 chomp($version);
1390 doprint "$version\n";
1391}
1392
1393sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001394 # Make sure the stable kernel has finished booting
1395 start_monitor;
1396 wait_for_monitor 5;
1397 end_monitor;
1398
Steven Rostedtddf607e2011-06-14 20:49:13 -04001399 get_grub_index;
1400 get_version;
1401 install;
1402
1403 start_monitor;
1404 return monitor;
1405}
1406
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001407sub check_buildlog {
1408 my ($patch) = @_;
1409
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001410 my @files = `git show $patch | diffstat -l`;
1411
1412 open(IN, "git show $patch |") or
1413 dodie "failed to show $patch";
1414 while (<IN>) {
1415 if (m,^--- a/(.*),) {
1416 chomp $1;
1417 $files[$#files] = $1;
1418 }
1419 }
1420 close(IN);
1421
1422 open(IN, $buildlog) or dodie "Can't open $buildlog";
1423 while (<IN>) {
1424 if (/^\s*(.*?):.*(warning|error)/) {
1425 my $err = $1;
1426 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001427 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001428 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001429 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001430 }
1431 }
1432 }
1433 }
1434 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001435
1436 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001437}
1438
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001439sub apply_min_config {
1440 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001441
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001442 # Read the config file and remove anything that
1443 # is in the force_config hash (from minconfig and others)
1444 # then add the force config back.
1445
1446 doprint "Applying minimum configurations into $output_config.new\n";
1447
1448 open (OUT, ">$outconfig") or
1449 dodie "Can't create $outconfig";
1450
1451 if (-f $output_config) {
1452 open (IN, $output_config) or
1453 dodie "Failed to open $output_config";
1454 while (<IN>) {
1455 if (/^(# )?(CONFIG_[^\s=]*)/) {
1456 next if (defined($force_config{$2}));
1457 }
1458 print OUT;
1459 }
1460 close IN;
1461 }
1462 foreach my $config (keys %force_config) {
1463 print OUT "$force_config{$config}\n";
1464 }
1465 close OUT;
1466
1467 run_command "mv $outconfig $output_config";
1468}
1469
1470sub make_oldconfig {
1471
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001472 my @force_list = keys %force_config;
1473
1474 if ($#force_list >= 0) {
1475 apply_min_config;
1476 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001477
1478 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001479 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1480 # try a yes '' | oldconfig
1481 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001482 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001483 dodie "failed make config oldconfig";
1484 }
1485}
1486
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001487# read a config file and use this to force new configs.
1488sub load_force_config {
1489 my ($config) = @_;
1490
1491 open(IN, $config) or
1492 dodie "failed to read $config";
1493 while (<IN>) {
1494 chomp;
1495 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1496 $force_config{$1} = $_;
1497 } elsif (/^# (CONFIG_\S*) is not set/) {
1498 $force_config{$1} = $_;
1499 }
1500 }
1501 close IN;
1502}
1503
Steven Rostedt2545eb62010-11-02 15:01:32 -04001504sub build {
1505 my ($type) = @_;
1506
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001507 unlink $buildlog;
1508
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001509 # Failed builds should not reboot the target
1510 my $save_no_reboot = $no_reboot;
1511 $no_reboot = 1;
1512
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001513 if (defined($pre_build)) {
1514 my $ret = run_command $pre_build;
1515 if (!$ret && defined($pre_build_die) &&
1516 $pre_build_die) {
1517 dodie "failed to pre_build\n";
1518 }
1519 }
1520
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001521 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001522 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001523 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001524
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001525 $type = "oldconfig";
1526 }
1527
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001528 # old config can ask questions
1529 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001530 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001531
1532 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001533 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001534
Andrew Jones13488232011-08-12 15:32:04 +02001535 if (!$noclean) {
1536 run_command "mv $output_config $outputdir/config_temp" or
1537 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001538
Andrew Jones13488232011-08-12 15:32:04 +02001539 run_command "$make mrproper" or dodie "make mrproper";
1540
1541 run_command "mv $outputdir/config_temp $output_config" or
1542 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001543 }
1544
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001545 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001546 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001547 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001548 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001549 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001550
1551 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001552 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1553 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001554 close(OUT);
1555
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001556 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001557 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001558 }
1559
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001560 if ($type ne "oldnoconfig") {
1561 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001562 dodie "failed make config";
1563 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001564 # Run old config regardless, to enforce min configurations
1565 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001566
Steven Rostedta75fece2010-11-02 14:58:27 -04001567 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001568 my $build_ret = run_command "$make $build_options";
1569 undef $redirect;
1570
1571 if (defined($post_build)) {
1572 my $ret = run_command $post_build;
1573 if (!$ret && defined($post_build_die) &&
1574 $post_build_die) {
1575 dodie "failed to post_build\n";
1576 }
1577 }
1578
1579 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001580 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001581 if ($in_bisect) {
1582 $no_reboot = $save_no_reboot;
1583 return 0;
1584 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001585 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001586 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001587
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001588 $no_reboot = $save_no_reboot;
1589
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001590 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001591}
1592
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001593sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001594 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001595 if (defined($poweroff_after_halt)) {
1596 sleep $poweroff_after_halt;
1597 run_command "$power_off";
1598 }
1599 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001600 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001601 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001602 }
1603}
1604
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001605sub success {
1606 my ($i) = @_;
1607
Steven Rostedte48c5292010-11-02 14:35:37 -04001608 $successes++;
1609
Steven Rostedt9064af52011-06-13 10:38:48 -04001610 my $name = "";
1611
1612 if (defined($test_name)) {
1613 $name = " ($test_name)";
1614 }
1615
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001616 doprint "\n\n*******************************************\n";
1617 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001618 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001619 doprint "*******************************************\n";
1620 doprint "*******************************************\n";
1621
Steven Rostedt576f6272010-11-02 14:58:38 -04001622 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001623 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001624 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001625 }
1626}
1627
Steven Rostedtc960bb92011-03-08 09:22:39 -05001628sub answer_bisect {
1629 for (;;) {
1630 doprint "Pass or fail? [p/f]";
1631 my $ans = <STDIN>;
1632 chomp $ans;
1633 if ($ans eq "p" || $ans eq "P") {
1634 return 1;
1635 } elsif ($ans eq "f" || $ans eq "F") {
1636 return 0;
1637 } else {
1638 print "Please answer 'P' or 'F'\n";
1639 }
1640 }
1641}
1642
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001643sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001644 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001645
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001646 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001647 $reboot_on_error = 0;
1648 $poweroff_on_error = 0;
1649 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001650
1651 run_command $run_test or $failed = 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001652 exit $failed;
1653}
1654
1655my $child_done;
1656
1657sub child_finished {
1658 $child_done = 1;
1659}
1660
1661sub do_run_test {
1662 my $child_pid;
1663 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001664 my $line;
1665 my $full_line;
1666 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001667
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001668 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001669
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001670 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001671
1672 $child_done = 0;
1673
1674 $SIG{CHLD} = qw(child_finished);
1675
1676 $child_pid = fork;
1677
1678 child_run_test if (!$child_pid);
1679
1680 $full_line = "";
1681
1682 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001683 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001684 if (defined($line)) {
1685
1686 # we are not guaranteed to get a full line
1687 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001688 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001689
1690 if ($full_line =~ /call trace:/i) {
1691 $bug = 1;
1692 }
1693
1694 if ($full_line =~ /Kernel panic -/) {
1695 $bug = 1;
1696 }
1697
1698 if ($line =~ /\n/) {
1699 $full_line = "";
1700 }
1701 }
1702 } while (!$child_done && !$bug);
1703
1704 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001705 my $failure_start = time;
1706 my $now;
1707 do {
1708 $line = wait_for_input($monitor_fp, 1);
1709 if (defined($line)) {
1710 doprint $line;
1711 }
1712 $now = time;
1713 if ($now - $failure_start >= $stop_after_failure) {
1714 last;
1715 }
1716 } while (defined($line));
1717
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001718 doprint "Detected kernel crash!\n";
1719 # kill the child with extreme prejudice
1720 kill 9, $child_pid;
1721 }
1722
1723 waitpid $child_pid, 0;
1724 $child_exit = $?;
1725
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001726 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001727 return 0 if $in_bisect;
1728 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001729 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001730 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001731}
1732
Steven Rostedta75fece2010-11-02 14:58:27 -04001733sub run_git_bisect {
1734 my ($command) = @_;
1735
1736 doprint "$command ... ";
1737
1738 my $output = `$command 2>&1`;
1739 my $ret = $?;
1740
1741 logit $output;
1742
1743 if ($ret) {
1744 doprint "FAILED\n";
1745 dodie "Failed to git bisect";
1746 }
1747
1748 doprint "SUCCESS\n";
1749 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1750 doprint "$1 [$2]\n";
1751 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1752 $bisect_bad = $1;
1753 doprint "Found bad commit... $1\n";
1754 return 0;
1755 } else {
1756 # we already logged it, just print it now.
1757 print $output;
1758 }
1759
1760 return 1;
1761}
1762
Steven Rostedtc23dca72011-03-08 09:26:31 -05001763sub bisect_reboot {
1764 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001765 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001766}
1767
1768# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001769sub run_bisect_test {
1770 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001771
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001772 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001773 my $result;
1774 my $output;
1775 my $ret;
1776
Steven Rostedt0a05c762010-11-08 11:14:10 -05001777 $in_bisect = 1;
1778
1779 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001780
1781 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001782 if ($failed && $bisect_skip) {
1783 $in_bisect = 0;
1784 return -1;
1785 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001786 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001787
1788 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001789 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001790
1791 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001792 if ($failed && $bisect_skip) {
1793 end_monitor;
1794 bisect_reboot;
1795 $in_bisect = 0;
1796 return -1;
1797 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001798 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001799
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001800 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001801 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001802 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001803 }
1804
1805 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001806 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001807 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001808 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001809 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001810
1811 # reboot the box to a kernel we can ssh to
1812 if ($type ne "build") {
1813 bisect_reboot;
1814 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001815 $in_bisect = 0;
1816
1817 return $result;
1818}
1819
1820sub run_bisect {
1821 my ($type) = @_;
1822 my $buildtype = "oldconfig";
1823
1824 # We should have a minconfig to use?
1825 if (defined($minconfig)) {
1826 $buildtype = "useconfig:$minconfig";
1827 }
1828
1829 my $ret = run_bisect_test $type, $buildtype;
1830
Steven Rostedtc960bb92011-03-08 09:22:39 -05001831 if ($bisect_manual) {
1832 $ret = answer_bisect;
1833 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001834
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001835 # Are we looking for where it worked, not failed?
1836 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001837 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001838 }
1839
Steven Rostedtc23dca72011-03-08 09:26:31 -05001840 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001841 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001842 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001843 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001844 } elsif ($bisect_skip) {
1845 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1846 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001847 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001848}
1849
1850sub bisect {
1851 my ($i) = @_;
1852
1853 my $result;
1854
1855 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1856 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1857 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1858
1859 my $good = $opt{"BISECT_GOOD[$i]"};
1860 my $bad = $opt{"BISECT_BAD[$i]"};
1861 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001862 my $start = $opt{"BISECT_START[$i]"};
1863 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001864 my $start_files = $opt{"BISECT_FILES[$i]"};
1865
1866 if (defined($start_files)) {
1867 $start_files = " -- " . $start_files;
1868 } else {
1869 $start_files = "";
1870 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001871
Steven Rostedta57419b2010-11-02 15:13:54 -04001872 # convert to true sha1's
1873 $good = get_sha1($good);
1874 $bad = get_sha1($bad);
1875
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001876 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1877 $opt{"BISECT_REVERSE[$i]"} == 1) {
1878 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1879 $reverse_bisect = 1;
1880 } else {
1881 $reverse_bisect = 0;
1882 }
1883
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001884 # Can't have a test without having a test to run
1885 if ($type eq "test" && !defined($run_test)) {
1886 $type = "boot";
1887 }
1888
Steven Rostedta75fece2010-11-02 14:58:27 -04001889 my $check = $opt{"BISECT_CHECK[$i]"};
1890 if (defined($check) && $check ne "0") {
1891
1892 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001893 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001894
1895 if ($check ne "good") {
1896 doprint "TESTING BISECT BAD [$bad]\n";
1897 run_command "git checkout $bad" or
1898 die "Failed to checkout $bad";
1899
1900 $result = run_bisect $type;
1901
1902 if ($result ne "bad") {
1903 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1904 }
1905 }
1906
1907 if ($check ne "bad") {
1908 doprint "TESTING BISECT GOOD [$good]\n";
1909 run_command "git checkout $good" or
1910 die "Failed to checkout $good";
1911
1912 $result = run_bisect $type;
1913
1914 if ($result ne "good") {
1915 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1916 }
1917 }
1918
1919 # checkout where we started
1920 run_command "git checkout $head" or
1921 die "Failed to checkout $head";
1922 }
1923
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001924 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001925 dodie "could not start bisect";
1926
1927 run_command "git bisect good $good" or
1928 dodie "could not set bisect good to $good";
1929
1930 run_git_bisect "git bisect bad $bad" or
1931 dodie "could not set bisect bad to $bad";
1932
1933 if (defined($replay)) {
1934 run_command "git bisect replay $replay" or
1935 dodie "failed to run replay";
1936 }
1937
1938 if (defined($start)) {
1939 run_command "git checkout $start" or
1940 dodie "failed to checkout $start";
1941 }
1942
1943 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001944 do {
1945 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001946 $test = run_git_bisect "git bisect $result";
1947 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001948
1949 run_command "git bisect log" or
1950 dodie "could not capture git bisect log";
1951
1952 run_command "git bisect reset" or
1953 dodie "could not reset git bisect";
1954
1955 doprint "Bad commit was [$bisect_bad]\n";
1956
Steven Rostedt0a05c762010-11-08 11:14:10 -05001957 success $i;
1958}
1959
1960my %config_ignore;
1961my %config_set;
1962
1963my %config_list;
1964my %null_config;
1965
1966my %dependency;
1967
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001968sub assign_configs {
1969 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001970
1971 open (IN, $config)
1972 or dodie "Failed to read $config";
1973
1974 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04001975 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001976 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001977 }
1978 }
1979
1980 close(IN);
1981}
1982
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001983sub process_config_ignore {
1984 my ($config) = @_;
1985
1986 assign_configs \%config_ignore, $config;
1987}
1988
Steven Rostedt0a05c762010-11-08 11:14:10 -05001989sub read_current_config {
1990 my ($config_ref) = @_;
1991
1992 %{$config_ref} = ();
1993 undef %{$config_ref};
1994
1995 my @key = keys %{$config_ref};
1996 if ($#key >= 0) {
1997 print "did not delete!\n";
1998 exit;
1999 }
2000 open (IN, "$output_config");
2001
2002 while (<IN>) {
2003 if (/^(CONFIG\S+)=(.*)/) {
2004 ${$config_ref}{$1} = $2;
2005 }
2006 }
2007 close(IN);
2008}
2009
2010sub get_dependencies {
2011 my ($config) = @_;
2012
2013 my $arr = $dependency{$config};
2014 if (!defined($arr)) {
2015 return ();
2016 }
2017
2018 my @deps = @{$arr};
2019
2020 foreach my $dep (@{$arr}) {
2021 print "ADD DEP $dep\n";
2022 @deps = (@deps, get_dependencies $dep);
2023 }
2024
2025 return @deps;
2026}
2027
2028sub create_config {
2029 my @configs = @_;
2030
2031 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2032
2033 foreach my $config (@configs) {
2034 print OUT "$config_set{$config}\n";
2035 my @deps = get_dependencies $config;
2036 foreach my $dep (@deps) {
2037 print OUT "$config_set{$dep}\n";
2038 }
2039 }
2040
2041 foreach my $config (keys %config_ignore) {
2042 print OUT "$config_ignore{$config}\n";
2043 }
2044 close(OUT);
2045
2046# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002047 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002048}
2049
2050sub compare_configs {
2051 my (%a, %b) = @_;
2052
2053 foreach my $item (keys %a) {
2054 if (!defined($b{$item})) {
2055 print "diff $item\n";
2056 return 1;
2057 }
2058 delete $b{$item};
2059 }
2060
2061 my @keys = keys %b;
2062 if ($#keys) {
2063 print "diff2 $keys[0]\n";
2064 }
2065 return -1 if ($#keys >= 0);
2066
2067 return 0;
2068}
2069
2070sub run_config_bisect_test {
2071 my ($type) = @_;
2072
2073 return run_bisect_test $type, "oldconfig";
2074}
2075
2076sub process_passed {
2077 my (%configs) = @_;
2078
2079 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2080 # Passed! All these configs are part of a good compile.
2081 # Add them to the min options.
2082 foreach my $config (keys %configs) {
2083 if (defined($config_list{$config})) {
2084 doprint " removing $config\n";
2085 $config_ignore{$config} = $config_list{$config};
2086 delete $config_list{$config};
2087 }
2088 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002089 doprint "config copied to $outputdir/config_good\n";
2090 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002091}
2092
2093sub process_failed {
2094 my ($config) = @_;
2095
2096 doprint "\n\n***************************************\n";
2097 doprint "Found bad config: $config\n";
2098 doprint "***************************************\n\n";
2099}
2100
2101sub run_config_bisect {
2102
2103 my @start_list = keys %config_list;
2104
2105 if ($#start_list < 0) {
2106 doprint "No more configs to test!!!\n";
2107 return -1;
2108 }
2109
2110 doprint "***** RUN TEST ***\n";
2111 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2112 my $ret;
2113 my %current_config;
2114
2115 my $count = $#start_list + 1;
2116 doprint " $count configs to test\n";
2117
2118 my $half = int($#start_list / 2);
2119
2120 do {
2121 my @tophalf = @start_list[0 .. $half];
2122
2123 create_config @tophalf;
2124 read_current_config \%current_config;
2125
2126 $count = $#tophalf + 1;
2127 doprint "Testing $count configs\n";
2128 my $found = 0;
2129 # make sure we test something
2130 foreach my $config (@tophalf) {
2131 if (defined($current_config{$config})) {
2132 logit " $config\n";
2133 $found = 1;
2134 }
2135 }
2136 if (!$found) {
2137 # try the other half
2138 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002139 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002140 create_config @tophalf;
2141 read_current_config \%current_config;
2142 foreach my $config (@tophalf) {
2143 if (defined($current_config{$config})) {
2144 logit " $config\n";
2145 $found = 1;
2146 }
2147 }
2148 if (!$found) {
2149 doprint "Failed: Can't make new config with current configs\n";
2150 foreach my $config (@start_list) {
2151 doprint " CONFIG: $config\n";
2152 }
2153 return -1;
2154 }
2155 $count = $#tophalf + 1;
2156 doprint "Testing $count configs\n";
2157 }
2158
2159 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002160 if ($bisect_manual) {
2161 $ret = answer_bisect;
2162 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002163 if ($ret) {
2164 process_passed %current_config;
2165 return 0;
2166 }
2167
2168 doprint "This config had a failure.\n";
2169 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002170 doprint "config copied to $outputdir/config_bad\n";
2171 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002172
2173 # A config exists in this group that was bad.
2174 foreach my $config (keys %config_list) {
2175 if (!defined($current_config{$config})) {
2176 doprint " removing $config\n";
2177 delete $config_list{$config};
2178 }
2179 }
2180
2181 @start_list = @tophalf;
2182
2183 if ($#start_list == 0) {
2184 process_failed $start_list[0];
2185 return 1;
2186 }
2187
2188 # remove half the configs we are looking at and see if
2189 # they are good.
2190 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002191 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002192
Steven Rostedtc960bb92011-03-08 09:22:39 -05002193 # we found a single config, try it again unless we are running manually
2194
2195 if ($bisect_manual) {
2196 process_failed $start_list[0];
2197 return 1;
2198 }
2199
Steven Rostedt0a05c762010-11-08 11:14:10 -05002200 my @tophalf = @start_list[0 .. 0];
2201
2202 $ret = run_config_bisect_test $type;
2203 if ($ret) {
2204 process_passed %current_config;
2205 return 0;
2206 }
2207
2208 process_failed $start_list[0];
2209 return 1;
2210}
2211
2212sub config_bisect {
2213 my ($i) = @_;
2214
2215 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2216
2217 my $tmpconfig = "$tmpdir/use_config";
2218
Steven Rostedt30f75da2011-06-13 10:35:35 -04002219 if (defined($config_bisect_good)) {
2220 process_config_ignore $config_bisect_good;
2221 }
2222
Steven Rostedt0a05c762010-11-08 11:14:10 -05002223 # Make the file with the bad config and the min config
2224 if (defined($minconfig)) {
2225 # read the min config for things to ignore
2226 run_command "cp $minconfig $tmpconfig" or
2227 dodie "failed to copy $minconfig to $tmpconfig";
2228 } else {
2229 unlink $tmpconfig;
2230 }
2231
Steven Rostedt0a05c762010-11-08 11:14:10 -05002232 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002233 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002234 process_config_ignore $tmpconfig;
2235 }
2236
2237 # now process the start config
2238 run_command "cp $start_config $output_config" or
2239 dodie "failed to copy $start_config to $output_config";
2240
2241 # read directly what we want to check
2242 my %config_check;
2243 open (IN, $output_config)
2244 or dodie "faied to open $output_config";
2245
2246 while (<IN>) {
2247 if (/^((CONFIG\S*)=.*)/) {
2248 $config_check{$2} = $1;
2249 }
2250 }
2251 close(IN);
2252
Steven Rostedt250bae82011-07-15 22:05:59 -04002253 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002254 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002255
2256 # check to see what we lost (or gained)
2257 open (IN, $output_config)
2258 or dodie "Failed to read $start_config";
2259
2260 my %removed_configs;
2261 my %added_configs;
2262
2263 while (<IN>) {
2264 if (/^((CONFIG\S*)=.*)/) {
2265 # save off all options
2266 $config_set{$2} = $1;
2267 if (defined($config_check{$2})) {
2268 if (defined($config_ignore{$2})) {
2269 $removed_configs{$2} = $1;
2270 } else {
2271 $config_list{$2} = $1;
2272 }
2273 } elsif (!defined($config_ignore{$2})) {
2274 $added_configs{$2} = $1;
2275 $config_list{$2} = $1;
2276 }
2277 }
2278 }
2279 close(IN);
2280
2281 my @confs = keys %removed_configs;
2282 if ($#confs >= 0) {
2283 doprint "Configs overridden by default configs and removed from check:\n";
2284 foreach my $config (@confs) {
2285 doprint " $config\n";
2286 }
2287 }
2288 @confs = keys %added_configs;
2289 if ($#confs >= 0) {
2290 doprint "Configs appearing in make oldconfig and added:\n";
2291 foreach my $config (@confs) {
2292 doprint " $config\n";
2293 }
2294 }
2295
2296 my %config_test;
2297 my $once = 0;
2298
2299 # Sometimes kconfig does weird things. We must make sure
2300 # that the config we autocreate has everything we need
2301 # to test, otherwise we may miss testing configs, or
2302 # may not be able to create a new config.
2303 # Here we create a config with everything set.
2304 create_config (keys %config_list);
2305 read_current_config \%config_test;
2306 foreach my $config (keys %config_list) {
2307 if (!defined($config_test{$config})) {
2308 if (!$once) {
2309 $once = 1;
2310 doprint "Configs not produced by kconfig (will not be checked):\n";
2311 }
2312 doprint " $config\n";
2313 delete $config_list{$config};
2314 }
2315 }
2316 my $ret;
2317 do {
2318 $ret = run_config_bisect;
2319 } while (!$ret);
2320
2321 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002322
2323 success $i;
2324}
2325
Steven Rostedt27d934b2011-05-20 09:18:18 -04002326sub patchcheck_reboot {
2327 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002328 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002329}
2330
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002331sub patchcheck {
2332 my ($i) = @_;
2333
2334 die "PATCHCHECK_START[$i] not defined\n"
2335 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2336 die "PATCHCHECK_TYPE[$i] not defined\n"
2337 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2338
2339 my $start = $opt{"PATCHCHECK_START[$i]"};
2340
2341 my $end = "HEAD";
2342 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2343 $end = $opt{"PATCHCHECK_END[$i]"};
2344 }
2345
Steven Rostedta57419b2010-11-02 15:13:54 -04002346 # Get the true sha1's since we can use things like HEAD~3
2347 $start = get_sha1($start);
2348 $end = get_sha1($end);
2349
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002350 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2351
2352 # Can't have a test without having a test to run
2353 if ($type eq "test" && !defined($run_test)) {
2354 $type = "boot";
2355 }
2356
2357 open (IN, "git log --pretty=oneline $end|") or
2358 dodie "could not get git list";
2359
2360 my @list;
2361
2362 while (<IN>) {
2363 chomp;
2364 $list[$#list+1] = $_;
2365 last if (/^$start/);
2366 }
2367 close(IN);
2368
2369 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002370 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002371 }
2372
2373 # go backwards in the list
2374 @list = reverse @list;
2375
2376 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002377 my %ignored_warnings;
2378
2379 if (defined($ignore_warnings)) {
2380 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2381 $ignored_warnings{$sha1} = 1;
2382 }
2383 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002384
2385 $in_patchcheck = 1;
2386 foreach my $item (@list) {
2387 my $sha1 = $item;
2388 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2389
2390 doprint "\nProcessing commit $item\n\n";
2391
2392 run_command "git checkout $sha1" or
2393 die "Failed to checkout $sha1";
2394
2395 # only clean on the first and last patch
2396 if ($item eq $list[0] ||
2397 $item eq $list[$#list]) {
2398 $noclean = $save_clean;
2399 } else {
2400 $noclean = 1;
2401 }
2402
2403 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002404 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002405 } else {
2406 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002407 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002408 }
2409
Steven Rostedt19902072011-06-14 20:46:25 -04002410
2411 if (!defined($ignored_warnings{$sha1})) {
2412 check_buildlog $sha1 or return 0;
2413 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002414
2415 next if ($type eq "build");
2416
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002417 my $failed = 0;
2418
Steven Rostedtddf607e2011-06-14 20:49:13 -04002419 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002420
2421 if (!$failed && $type ne "boot"){
2422 do_run_test or $failed = 1;
2423 }
2424 end_monitor;
2425 return 0 if ($failed);
2426
Steven Rostedt27d934b2011-05-20 09:18:18 -04002427 patchcheck_reboot;
2428
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002429 }
2430 $in_patchcheck = 0;
2431 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002432
2433 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002434}
2435
Steven Rostedtb9066f62011-07-15 21:25:24 -04002436my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002437my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002438my $iflevel = 0;
2439my @ifdeps;
2440
2441# prevent recursion
2442my %read_kconfigs;
2443
Steven Rostedtac6974c2011-10-04 09:40:17 -04002444sub add_dep {
2445 # $config depends on $dep
2446 my ($config, $dep) = @_;
2447
2448 if (defined($depends{$config})) {
2449 $depends{$config} .= " " . $dep;
2450 } else {
2451 $depends{$config} = $dep;
2452 }
2453
2454 # record the number of configs depending on $dep
2455 if (defined $depcount{$dep}) {
2456 $depcount{$dep}++;
2457 } else {
2458 $depcount{$dep} = 1;
2459 }
2460}
2461
Steven Rostedtb9066f62011-07-15 21:25:24 -04002462# taken from streamline_config.pl
2463sub read_kconfig {
2464 my ($kconfig) = @_;
2465
2466 my $state = "NONE";
2467 my $config;
2468 my @kconfigs;
2469
2470 my $cont = 0;
2471 my $line;
2472
2473
2474 if (! -f $kconfig) {
2475 doprint "file $kconfig does not exist, skipping\n";
2476 return;
2477 }
2478
2479 open(KIN, "$kconfig")
2480 or die "Can't open $kconfig";
2481 while (<KIN>) {
2482 chomp;
2483
2484 # Make sure that lines ending with \ continue
2485 if ($cont) {
2486 $_ = $line . " " . $_;
2487 }
2488
2489 if (s/\\$//) {
2490 $cont = 1;
2491 $line = $_;
2492 next;
2493 }
2494
2495 $cont = 0;
2496
2497 # collect any Kconfig sources
2498 if (/^source\s*"(.*)"/) {
2499 $kconfigs[$#kconfigs+1] = $1;
2500 }
2501
2502 # configs found
2503 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2504 $state = "NEW";
2505 $config = $2;
2506
2507 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002508 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002509 }
2510
2511 # collect the depends for the config
2512 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2513
Steven Rostedtac6974c2011-10-04 09:40:17 -04002514 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002515
2516 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002517 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2518
2519 # selected by depends on config
2520 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002521
2522 # Check for if statements
2523 } elsif (/^if\s+(.*\S)\s*$/) {
2524 my $deps = $1;
2525 # remove beginning and ending non text
2526 $deps =~ s/^[^a-zA-Z0-9_]*//;
2527 $deps =~ s/[^a-zA-Z0-9_]*$//;
2528
2529 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2530
2531 $ifdeps[$iflevel++] = join ':', @deps;
2532
2533 } elsif (/^endif/) {
2534
2535 $iflevel-- if ($iflevel);
2536
2537 # stop on "help"
2538 } elsif (/^\s*help\s*$/) {
2539 $state = "NONE";
2540 }
2541 }
2542 close(KIN);
2543
2544 # read in any configs that were found.
2545 foreach $kconfig (@kconfigs) {
2546 if (!defined($read_kconfigs{$kconfig})) {
2547 $read_kconfigs{$kconfig} = 1;
2548 read_kconfig("$builddir/$kconfig");
2549 }
2550 }
2551}
2552
2553sub read_depends {
2554 # find out which arch this is by the kconfig file
2555 open (IN, $output_config)
2556 or dodie "Failed to read $output_config";
2557 my $arch;
2558 while (<IN>) {
2559 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2560 $arch = $1;
2561 last;
2562 }
2563 }
2564 close IN;
2565
2566 if (!defined($arch)) {
2567 doprint "Could not find arch from config file\n";
2568 doprint "no dependencies used\n";
2569 return;
2570 }
2571
2572 # arch is really the subarch, we need to know
2573 # what directory to look at.
2574 if ($arch eq "i386" || $arch eq "x86_64") {
2575 $arch = "x86";
2576 } elsif ($arch =~ /^tile/) {
2577 $arch = "tile";
2578 }
2579
2580 my $kconfig = "$builddir/arch/$arch/Kconfig";
2581
2582 if (! -f $kconfig && $arch =~ /\d$/) {
2583 my $orig = $arch;
2584 # some subarchs have numbers, truncate them
2585 $arch =~ s/\d*$//;
2586 $kconfig = "$builddir/arch/$arch/Kconfig";
2587 if (! -f $kconfig) {
2588 doprint "No idea what arch dir $orig is for\n";
2589 doprint "no dependencies used\n";
2590 return;
2591 }
2592 }
2593
2594 read_kconfig($kconfig);
2595}
2596
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002597sub read_config_list {
2598 my ($config) = @_;
2599
2600 open (IN, $config)
2601 or dodie "Failed to read $config";
2602
2603 while (<IN>) {
2604 if (/^((CONFIG\S*)=.*)/) {
2605 if (!defined($config_ignore{$2})) {
2606 $config_list{$2} = $1;
2607 }
2608 }
2609 }
2610
2611 close(IN);
2612}
2613
2614sub read_output_config {
2615 my ($config) = @_;
2616
2617 assign_configs \%config_ignore, $config;
2618}
2619
2620sub make_new_config {
2621 my @configs = @_;
2622
2623 open (OUT, ">$output_config")
2624 or dodie "Failed to write $output_config";
2625
2626 foreach my $config (@configs) {
2627 print OUT "$config\n";
2628 }
2629 close OUT;
2630}
2631
Steven Rostedtac6974c2011-10-04 09:40:17 -04002632sub chomp_config {
2633 my ($config) = @_;
2634
2635 $config =~ s/CONFIG_//;
2636
2637 return $config;
2638}
2639
Steven Rostedtb9066f62011-07-15 21:25:24 -04002640sub get_depends {
2641 my ($dep) = @_;
2642
Steven Rostedtac6974c2011-10-04 09:40:17 -04002643 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002644
2645 $dep = $depends{"$kconfig"};
2646
2647 # the dep string we have saves the dependencies as they
2648 # were found, including expressions like ! && ||. We
2649 # want to split this out into just an array of configs.
2650
2651 my $valid = "A-Za-z_0-9";
2652
2653 my @configs;
2654
2655 while ($dep =~ /[$valid]/) {
2656
2657 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2658 my $conf = "CONFIG_" . $1;
2659
2660 $configs[$#configs + 1] = $conf;
2661
2662 $dep =~ s/^[^$valid]*[$valid]+//;
2663 } else {
2664 die "this should never happen";
2665 }
2666 }
2667
2668 return @configs;
2669}
2670
2671my %min_configs;
2672my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002673my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002674my %processed_configs;
2675my %nochange_config;
2676
2677sub test_this_config {
2678 my ($config) = @_;
2679
2680 my $found;
2681
2682 # if we already processed this config, skip it
2683 if (defined($processed_configs{$config})) {
2684 return undef;
2685 }
2686 $processed_configs{$config} = 1;
2687
2688 # if this config failed during this round, skip it
2689 if (defined($nochange_config{$config})) {
2690 return undef;
2691 }
2692
Steven Rostedtac6974c2011-10-04 09:40:17 -04002693 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002694
2695 # Test dependencies first
2696 if (defined($depends{"$kconfig"})) {
2697 my @parents = get_depends $config;
2698 foreach my $parent (@parents) {
2699 # if the parent is in the min config, check it first
2700 next if (!defined($min_configs{$parent}));
2701 $found = test_this_config($parent);
2702 if (defined($found)) {
2703 return $found;
2704 }
2705 }
2706 }
2707
2708 # Remove this config from the list of configs
2709 # do a make oldnoconfig and then read the resulting
2710 # .config to make sure it is missing the config that
2711 # we had before
2712 my %configs = %min_configs;
2713 delete $configs{$config};
2714 make_new_config ((values %configs), (values %keep_configs));
2715 make_oldconfig;
2716 undef %configs;
2717 assign_configs \%configs, $output_config;
2718
2719 return $config if (!defined($configs{$config}));
2720
2721 doprint "disabling config $config did not change .config\n";
2722
2723 $nochange_config{$config} = 1;
2724
2725 return undef;
2726}
2727
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002728sub make_min_config {
2729 my ($i) = @_;
2730
2731 if (!defined($output_minconfig)) {
2732 fail "OUTPUT_MIN_CONFIG not defined" and return;
2733 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002734
2735 # If output_minconfig exists, and the start_minconfig
2736 # came from min_config, than ask if we should use
2737 # that instead.
2738 if (-f $output_minconfig && !$start_minconfig_defined) {
2739 print "$output_minconfig exists\n";
2740 if (read_yn " Use it as minconfig?") {
2741 $start_minconfig = $output_minconfig;
2742 }
2743 }
2744
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002745 if (!defined($start_minconfig)) {
2746 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2747 }
2748
Steven Rostedt35ce5952011-07-15 21:57:25 -04002749 my $temp_config = "$tmpdir/temp_config";
2750
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002751 # First things first. We build an allnoconfig to find
2752 # out what the defaults are that we can't touch.
2753 # Some are selections, but we really can't handle selections.
2754
2755 my $save_minconfig = $minconfig;
2756 undef $minconfig;
2757
2758 run_command "$make allnoconfig" or return 0;
2759
Steven Rostedtb9066f62011-07-15 21:25:24 -04002760 read_depends;
2761
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002762 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002763
Steven Rostedt43d1b652011-07-15 22:01:56 -04002764 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002765 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002766
2767 if (defined($ignore_config)) {
2768 # make sure the file exists
2769 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002770 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002771 }
2772
Steven Rostedt43d1b652011-07-15 22:01:56 -04002773 %keep_configs = %save_configs;
2774
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002775 doprint "Load initial configs from $start_minconfig\n";
2776
2777 # Look at the current min configs, and save off all the
2778 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002779 assign_configs \%min_configs, $start_minconfig;
2780
2781 my @config_keys = keys %min_configs;
2782
Steven Rostedtac6974c2011-10-04 09:40:17 -04002783 # All configs need a depcount
2784 foreach my $config (@config_keys) {
2785 my $kconfig = chomp_config $config;
2786 if (!defined $depcount{$kconfig}) {
2787 $depcount{$kconfig} = 0;
2788 }
2789 }
2790
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002791 # Remove anything that was set by the make allnoconfig
2792 # we shouldn't need them as they get set for us anyway.
2793 foreach my $config (@config_keys) {
2794 # Remove anything in the ignore_config
2795 if (defined($keep_configs{$config})) {
2796 my $file = $ignore_config;
2797 $file =~ s,.*/(.*?)$,$1,;
2798 doprint "$config set by $file ... ignored\n";
2799 delete $min_configs{$config};
2800 next;
2801 }
2802 # But make sure the settings are the same. If a min config
2803 # sets a selection, we do not want to get rid of it if
2804 # it is not the same as what we have. Just move it into
2805 # the keep configs.
2806 if (defined($config_ignore{$config})) {
2807 if ($config_ignore{$config} ne $min_configs{$config}) {
2808 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2809 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2810 $keep_configs{$config} = $min_configs{$config};
2811 } else {
2812 doprint "$config set by allnoconfig ... ignored\n";
2813 }
2814 delete $min_configs{$config};
2815 }
2816 }
2817
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002818 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002819 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002820
2821 while (!$done) {
2822
2823 my $config;
2824 my $found;
2825
2826 # Now disable each config one by one and do a make oldconfig
2827 # till we find a config that changes our list.
2828
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002829 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002830
2831 # Sort keys by who is most dependent on
2832 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2833 @test_configs ;
2834
2835 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002836 my $reset = 1;
2837 for (my $i = 0; $i < $#test_configs; $i++) {
2838 if (!defined($nochange_config{$test_configs[0]})) {
2839 $reset = 0;
2840 last;
2841 }
2842 # This config didn't change the .config last time.
2843 # Place it at the end
2844 my $config = shift @test_configs;
2845 push @test_configs, $config;
2846 }
2847
2848 # if every test config has failed to modify the .config file
2849 # in the past, then reset and start over.
2850 if ($reset) {
2851 undef %nochange_config;
2852 }
2853
Steven Rostedtb9066f62011-07-15 21:25:24 -04002854 undef %processed_configs;
2855
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002856 foreach my $config (@test_configs) {
2857
Steven Rostedtb9066f62011-07-15 21:25:24 -04002858 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002859
Steven Rostedtb9066f62011-07-15 21:25:24 -04002860 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002861
2862 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002863 }
2864
2865 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002866 # we could have failed due to the nochange_config hash
2867 # reset and try again
2868 if (!$take_two) {
2869 undef %nochange_config;
2870 $take_two = 1;
2871 next;
2872 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002873 doprint "No more configs found that we can disable\n";
2874 $done = 1;
2875 last;
2876 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04002877 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002878
2879 $config = $found;
2880
2881 doprint "Test with $config disabled\n";
2882
2883 # set in_bisect to keep build and monitor from dieing
2884 $in_bisect = 1;
2885
2886 my $failed = 0;
2887 build "oldconfig";
2888 start_monitor_and_boot or $failed = 1;
2889 end_monitor;
2890
2891 $in_bisect = 0;
2892
2893 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002894 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002895 # this config is needed, add it to the ignore list.
2896 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04002897 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002898 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04002899
2900 # update new ignore configs
2901 if (defined($ignore_config)) {
2902 open (OUT, ">$temp_config")
2903 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04002904 foreach my $config (keys %save_configs) {
2905 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002906 }
2907 close OUT;
2908 run_command "mv $temp_config $ignore_config" or
2909 dodie "failed to copy update to $ignore_config";
2910 }
2911
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002912 } else {
2913 # We booted without this config, remove it from the minconfigs.
2914 doprint "$config is not needed, disabling\n";
2915
2916 delete $min_configs{$config};
2917
2918 # Also disable anything that is not enabled in this config
2919 my %configs;
2920 assign_configs \%configs, $output_config;
2921 my @config_keys = keys %min_configs;
2922 foreach my $config (@config_keys) {
2923 if (!defined($configs{$config})) {
2924 doprint "$config is not set, disabling\n";
2925 delete $min_configs{$config};
2926 }
2927 }
2928
2929 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04002930 open (OUT, ">$temp_config")
2931 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002932 foreach my $config (keys %keep_configs) {
2933 print OUT "$keep_configs{$config}\n";
2934 }
2935 foreach my $config (keys %min_configs) {
2936 print OUT "$min_configs{$config}\n";
2937 }
2938 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04002939
2940 run_command "mv $temp_config $output_minconfig" or
2941 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002942 }
2943
2944 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002945 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002946 }
2947
2948 success $i;
2949 return 1;
2950}
2951
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002952$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002953
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002954if ($#ARGV == 0) {
2955 $ktest_config = $ARGV[0];
2956 if (! -f $ktest_config) {
2957 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002958 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002959 exit 0;
2960 }
2961 }
2962} else {
2963 $ktest_config = "ktest.conf";
2964}
2965
2966if (! -f $ktest_config) {
2967 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2968 print OUT << "EOF"
2969# Generated by ktest.pl
2970#
2971# Define each test with TEST_START
2972# The config options below it will override the defaults
2973TEST_START
2974
2975DEFAULTS
2976EOF
2977;
2978 close(OUT);
2979}
2980read_config $ktest_config;
2981
Steven Rostedt23715c3c2011-06-13 11:03:34 -04002982if (defined($opt{"LOG_FILE"})) {
2983 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2984}
2985
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002986# Append any configs entered in manually to the config file.
2987my @new_configs = keys %entered_configs;
2988if ($#new_configs >= 0) {
2989 print "\nAppending entered in configs to $ktest_config\n";
2990 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2991 foreach my $config (@new_configs) {
2992 print OUT "$config = $entered_configs{$config}\n";
2993 $opt{$config} = $entered_configs{$config};
2994 }
2995}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002996
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002997if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2998 unlink $opt{"LOG_FILE"};
2999}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003000
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003001doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3002
Steven Rostedta57419b2010-11-02 15:13:54 -04003003for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3004
3005 if (!$i) {
3006 doprint "DEFAULT OPTIONS:\n";
3007 } else {
3008 doprint "\nTEST $i OPTIONS";
3009 if (defined($repeat_tests{$i})) {
3010 $repeat = $repeat_tests{$i};
3011 doprint " ITERATE $repeat";
3012 }
3013 doprint "\n";
3014 }
3015
3016 foreach my $option (sort keys %opt) {
3017
3018 if ($option =~ /\[(\d+)\]$/) {
3019 next if ($i != $1);
3020 } else {
3021 next if ($i);
3022 }
3023
3024 doprint "$option = $opt{$option}\n";
3025 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003026}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003027
Steven Rostedt2a625122011-05-20 15:48:59 -04003028sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003029 my ($name, $i) = @_;
3030
3031 my $option = "$name\[$i\]";
3032
3033 if (defined($opt{$option})) {
3034 return $opt{$option};
3035 }
3036
Steven Rostedta57419b2010-11-02 15:13:54 -04003037 foreach my $test (keys %repeat_tests) {
3038 if ($i >= $test &&
3039 $i < $test + $repeat_tests{$test}) {
3040 $option = "$name\[$test\]";
3041 if (defined($opt{$option})) {
3042 return $opt{$option};
3043 }
3044 }
3045 }
3046
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003047 if (defined($opt{$name})) {
3048 return $opt{$name};
3049 }
3050
3051 return undef;
3052}
3053
Steven Rostedt2a625122011-05-20 15:48:59 -04003054sub set_test_option {
3055 my ($name, $i) = @_;
3056
3057 my $option = __set_test_option($name, $i);
3058 return $option if (!defined($option));
3059
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003060 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003061}
3062
Steven Rostedt2545eb62010-11-02 15:01:32 -04003063# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003064for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003065
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003066 # Do not reboot on failing test options
3067 $no_reboot = 1;
3068
Steven Rostedt576f6272010-11-02 14:58:38 -04003069 $iteration = $i;
3070
Steven Rostedta75fece2010-11-02 14:58:27 -04003071 my $makecmd = set_test_option("MAKE_CMD", $i);
3072
3073 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003074 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003075 $tmpdir = set_test_option("TMP_DIR", $i);
3076 $outputdir = set_test_option("OUTPUT_DIR", $i);
3077 $builddir = set_test_option("BUILD_DIR", $i);
3078 $test_type = set_test_option("TEST_TYPE", $i);
3079 $build_type = set_test_option("BUILD_TYPE", $i);
3080 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003081 $pre_build = set_test_option("PRE_BUILD", $i);
3082 $post_build = set_test_option("POST_BUILD", $i);
3083 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3084 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003085 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003086 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003087 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3088 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003089 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3090 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3091 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003092 $run_test = set_test_option("TEST", $i);
3093 $addconfig = set_test_option("ADD_CONFIG", $i);
3094 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3095 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003096 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003097 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003098 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3099 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3100 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3101 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3102 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003103 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3104 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003105 $sleep_time = set_test_option("SLEEP_TIME", $i);
3106 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003107 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003108 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003109 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003110 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003111 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003112 $store_failures = set_test_option("STORE_FAILURES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003113 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003114 $timeout = set_test_option("TIMEOUT", $i);
3115 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3116 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003117 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003118 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003119 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003120 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3121 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003122 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003123 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003124 $ssh_exec = set_test_option("SSH_EXEC", $i);
3125 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003126 $target_image = set_test_option("TARGET_IMAGE", $i);
3127 $localversion = set_test_option("LOCALVERSION", $i);
3128
Steven Rostedt35ce5952011-07-15 21:57:25 -04003129 $start_minconfig_defined = 1;
3130
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003131 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003132 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003133 $start_minconfig = $minconfig;
3134 }
3135
Steven Rostedta75fece2010-11-02 14:58:27 -04003136 chdir $builddir || die "can't change directory to $builddir";
3137
Andrew Jonesa908a662011-08-12 15:32:03 +02003138 foreach my $dir ($tmpdir, $outputdir) {
3139 if (!-d $dir) {
3140 mkpath($dir) or
3141 die "can't create $dir";
3142 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003143 }
3144
Steven Rostedte48c5292010-11-02 14:35:37 -04003145 $ENV{"SSH_USER"} = $ssh_user;
3146 $ENV{"MACHINE"} = $machine;
3147
Steven Rostedta75fece2010-11-02 14:58:27 -04003148 $target = "$ssh_user\@$machine";
3149
3150 $buildlog = "$tmpdir/buildlog-$machine";
3151 $dmesg = "$tmpdir/dmesg-$machine";
3152 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003153 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003154
3155 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04003156 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04003157 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04003158 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04003159 }
3160
3161 my $run_type = $build_type;
3162 if ($test_type eq "patchcheck") {
3163 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3164 } elsif ($test_type eq "bisect") {
3165 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003166 } elsif ($test_type eq "config_bisect") {
3167 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003168 }
3169
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003170 if ($test_type eq "make_min_config") {
3171 $run_type = "";
3172 }
3173
Steven Rostedta75fece2010-11-02 14:58:27 -04003174 # mistake in config file?
3175 if (!defined($run_type)) {
3176 $run_type = "ERROR";
3177 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003178
Steven Rostedte0a87422011-09-30 17:50:48 -04003179 my $installme = "";
3180 $installme = " no_install" if ($no_install);
3181
Steven Rostedt2545eb62010-11-02 15:01:32 -04003182 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003183 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003184
3185 unlink $dmesg;
3186 unlink $buildlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003187
Steven Rostedt250bae82011-07-15 22:05:59 -04003188 if (defined($addconfig)) {
3189 my $min = $minconfig;
3190 if (!defined($minconfig)) {
3191 $min = "";
3192 }
3193 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003194 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003195 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003196 }
3197
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003198 my $checkout = $opt{"CHECKOUT[$i]"};
3199 if (defined($checkout)) {
3200 run_command "git checkout $checkout" or
3201 die "failed to checkout $checkout";
3202 }
3203
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003204 $no_reboot = 0;
3205
3206
Steven Rostedta75fece2010-11-02 14:58:27 -04003207 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003208 bisect $i;
3209 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003210 } elsif ($test_type eq "config_bisect") {
3211 config_bisect $i;
3212 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003213 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003214 patchcheck $i;
3215 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003216 } elsif ($test_type eq "make_min_config") {
3217 make_min_config $i;
3218 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003219 }
3220
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003221 if ($build_type ne "nobuild") {
3222 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003223 }
3224
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003225 if ($test_type eq "install") {
3226 get_version;
3227 install;
3228 success $i;
3229 next;
3230 }
3231
Steven Rostedta75fece2010-11-02 14:58:27 -04003232 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003233 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003234 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003235
3236 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3237 do_run_test or $failed = 1;
3238 }
3239 end_monitor;
3240 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003241 }
3242
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003243 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003244}
3245
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003246if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003247 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003248} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003249 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003250}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003251
Steven Rostedte48c5292010-11-02 14:35:37 -04003252doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3253
Steven Rostedt2545eb62010-11-02 15:01:32 -04003254exit 0;