blob: 1bda07f6d673176ecfdcaaea49cd923f7ea3a480 [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 Rostedt4da46da2011-06-01 23:25:13 -04001153 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
Steven Rostedta75fece2010-11-02 14:58:27 -04001154 return;
1155 }
1156
1157 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001158}
1159
Steven Rostedta57419b2010-11-02 15:13:54 -04001160sub get_sha1 {
1161 my ($commit) = @_;
1162
1163 doprint "git rev-list --max-count=1 $commit ... ";
1164 my $sha1 = `git rev-list --max-count=1 $commit`;
1165 my $ret = $?;
1166
1167 logit $sha1;
1168
1169 if ($ret) {
1170 doprint "FAILED\n";
1171 dodie "Failed to get git $commit";
1172 }
1173
1174 print "SUCCESS\n";
1175
1176 chomp $sha1;
1177
1178 return $sha1;
1179}
1180
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001181sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001182 my $booted = 0;
1183 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001184 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001185 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001186
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001187 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001188
1189 my $line;
1190 my $full_line = "";
1191
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001192 open(DMESG, "> $dmesg") or
1193 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001194
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001195 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001196
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001197 my $success_start;
1198 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001199 my $monitor_start = time;
1200 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001201 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001202
Steven Rostedt2d01b262011-03-08 09:47:54 -05001203 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001204
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001205 if ($bug && defined($stop_after_failure) &&
1206 $stop_after_failure >= 0) {
1207 my $time = $stop_after_failure - (time - $failure_start);
1208 $line = wait_for_input($monitor_fp, $time);
1209 if (!defined($line)) {
1210 doprint "bug timed out after $booted_timeout seconds\n";
1211 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1212 last;
1213 }
1214 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001215 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001216 if (!defined($line)) {
1217 my $s = $booted_timeout == 1 ? "" : "s";
1218 doprint "Successful boot found: break after $booted_timeout second$s\n";
1219 last;
1220 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001221 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001222 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001223 if (!defined($line)) {
1224 my $s = $timeout == 1 ? "" : "s";
1225 doprint "Timed out after $timeout second$s\n";
1226 last;
1227 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001228 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001229
Steven Rostedt2545eb62010-11-02 15:01:32 -04001230 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001231 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001232
1233 # we are not guaranteed to get a full line
1234 $full_line .= $line;
1235
Steven Rostedta75fece2010-11-02 14:58:27 -04001236 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001237 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001238 $success_start = time;
1239 }
1240
1241 if ($booted && defined($stop_after_success) &&
1242 $stop_after_success >= 0) {
1243 my $now = time;
1244 if ($now - $success_start >= $stop_after_success) {
1245 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1246 last;
1247 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001248 }
1249
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001250 if ($full_line =~ /\[ backtrace testing \]/) {
1251 $skip_call_trace = 1;
1252 }
1253
Steven Rostedt2545eb62010-11-02 15:01:32 -04001254 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001255 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001256 $bug = 1;
1257 $failure_start = time;
1258 }
1259 }
1260
1261 if ($bug && defined($stop_after_failure) &&
1262 $stop_after_failure >= 0) {
1263 my $now = time;
1264 if ($now - $failure_start >= $stop_after_failure) {
1265 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1266 last;
1267 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001268 }
1269
1270 if ($full_line =~ /\[ end of backtrace testing \]/) {
1271 $skip_call_trace = 0;
1272 }
1273
1274 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001275 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001276 $bug = 1;
1277 }
1278
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001279 # Detect triple faults by testing the banner
1280 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1281 if ($1 eq $version) {
1282 $version_found = 1;
1283 } elsif ($version_found && $detect_triplefault) {
1284 # We already booted into the kernel we are testing,
1285 # but now we booted into another kernel?
1286 # Consider this a triple fault.
1287 doprint "Aleady booted in Linux kernel $version, but now\n";
1288 doprint "we booted into Linux kernel $1.\n";
1289 doprint "Assuming that this is a triple fault.\n";
1290 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1291 last;
1292 }
1293 }
1294
Steven Rostedt2545eb62010-11-02 15:01:32 -04001295 if ($line =~ /\n/) {
1296 $full_line = "";
1297 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001298
1299 if ($stop_test_after > 0 && !$booted && !$bug) {
1300 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001301 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001302 $done = 1;
1303 }
1304 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001305 }
1306
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001307 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001308
Steven Rostedt2545eb62010-11-02 15:01:32 -04001309 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001310 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001311 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001312 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001313
Steven Rostedta75fece2010-11-02 14:58:27 -04001314 if (!$booted) {
1315 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001316 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001317 }
1318
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001319 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001320}
1321
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001322sub do_post_install {
1323
1324 return if (!defined($post_install));
1325
1326 my $cp_post_install = $post_install;
1327 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1328 run_command "$cp_post_install" or
1329 dodie "Failed to run post install";
1330}
1331
Steven Rostedt2545eb62010-11-02 15:01:32 -04001332sub install {
1333
Steven Rostedte0a87422011-09-30 17:50:48 -04001334 return if ($no_install);
1335
Steven Rostedte48c5292010-11-02 14:35:37 -04001336 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001337 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001338
1339 my $install_mods = 0;
1340
1341 # should we process modules?
1342 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001343 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001344 while (<IN>) {
1345 if (/CONFIG_MODULES(=y)?/) {
1346 $install_mods = 1 if (defined($1));
1347 last;
1348 }
1349 }
1350 close(IN);
1351
1352 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001353 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001354 doprint "No modules needed\n";
1355 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001356 }
1357
Steven Rostedta75fece2010-11-02 14:58:27 -04001358 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001359 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001360
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001361 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001362 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001363
Steven Rostedte48c5292010-11-02 14:35:37 -04001364 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001365 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001366
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001367 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001368 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001369 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001370
Steven Rostedte48c5292010-11-02 14:35:37 -04001371 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001372 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001373
Steven Rostedta75fece2010-11-02 14:58:27 -04001374 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001375
Steven Rostedte7b13442011-06-14 20:44:36 -04001376 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001377 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001378
Steven Rostedte48c5292010-11-02 14:35:37 -04001379 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001380
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001381 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001382}
1383
Steven Rostedtddf607e2011-06-14 20:49:13 -04001384sub get_version {
1385 # get the release name
1386 doprint "$make kernelrelease ... ";
1387 $version = `$make kernelrelease | tail -1`;
1388 chomp($version);
1389 doprint "$version\n";
1390}
1391
1392sub start_monitor_and_boot {
1393 get_grub_index;
1394 get_version;
1395 install;
1396
1397 start_monitor;
1398 return monitor;
1399}
1400
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001401sub check_buildlog {
1402 my ($patch) = @_;
1403
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001404 my @files = `git show $patch | diffstat -l`;
1405
1406 open(IN, "git show $patch |") or
1407 dodie "failed to show $patch";
1408 while (<IN>) {
1409 if (m,^--- a/(.*),) {
1410 chomp $1;
1411 $files[$#files] = $1;
1412 }
1413 }
1414 close(IN);
1415
1416 open(IN, $buildlog) or dodie "Can't open $buildlog";
1417 while (<IN>) {
1418 if (/^\s*(.*?):.*(warning|error)/) {
1419 my $err = $1;
1420 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001421 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001422 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001423 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001424 }
1425 }
1426 }
1427 }
1428 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001429
1430 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001431}
1432
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001433sub apply_min_config {
1434 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001435
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001436 # Read the config file and remove anything that
1437 # is in the force_config hash (from minconfig and others)
1438 # then add the force config back.
1439
1440 doprint "Applying minimum configurations into $output_config.new\n";
1441
1442 open (OUT, ">$outconfig") or
1443 dodie "Can't create $outconfig";
1444
1445 if (-f $output_config) {
1446 open (IN, $output_config) or
1447 dodie "Failed to open $output_config";
1448 while (<IN>) {
1449 if (/^(# )?(CONFIG_[^\s=]*)/) {
1450 next if (defined($force_config{$2}));
1451 }
1452 print OUT;
1453 }
1454 close IN;
1455 }
1456 foreach my $config (keys %force_config) {
1457 print OUT "$force_config{$config}\n";
1458 }
1459 close OUT;
1460
1461 run_command "mv $outconfig $output_config";
1462}
1463
1464sub make_oldconfig {
1465
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001466 my @force_list = keys %force_config;
1467
1468 if ($#force_list >= 0) {
1469 apply_min_config;
1470 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001471
1472 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001473 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1474 # try a yes '' | oldconfig
1475 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001476 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001477 dodie "failed make config oldconfig";
1478 }
1479}
1480
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001481# read a config file and use this to force new configs.
1482sub load_force_config {
1483 my ($config) = @_;
1484
1485 open(IN, $config) or
1486 dodie "failed to read $config";
1487 while (<IN>) {
1488 chomp;
1489 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1490 $force_config{$1} = $_;
1491 } elsif (/^# (CONFIG_\S*) is not set/) {
1492 $force_config{$1} = $_;
1493 }
1494 }
1495 close IN;
1496}
1497
Steven Rostedt2545eb62010-11-02 15:01:32 -04001498sub build {
1499 my ($type) = @_;
1500
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001501 unlink $buildlog;
1502
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001503 # Failed builds should not reboot the target
1504 my $save_no_reboot = $no_reboot;
1505 $no_reboot = 1;
1506
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001507 if (defined($pre_build)) {
1508 my $ret = run_command $pre_build;
1509 if (!$ret && defined($pre_build_die) &&
1510 $pre_build_die) {
1511 dodie "failed to pre_build\n";
1512 }
1513 }
1514
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001515 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001516 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001517 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001518
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001519 $type = "oldconfig";
1520 }
1521
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001522 # old config can ask questions
1523 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001524 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001525
1526 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001527 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001528
Andrew Jones13488232011-08-12 15:32:04 +02001529 if (!$noclean) {
1530 run_command "mv $output_config $outputdir/config_temp" or
1531 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001532
Andrew Jones13488232011-08-12 15:32:04 +02001533 run_command "$make mrproper" or dodie "make mrproper";
1534
1535 run_command "mv $outputdir/config_temp $output_config" or
1536 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001537 }
1538
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001539 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001540 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001541 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001542 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001543 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001544
1545 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001546 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1547 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001548 close(OUT);
1549
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001550 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001551 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001552 }
1553
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001554 if ($type ne "oldnoconfig") {
1555 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001556 dodie "failed make config";
1557 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001558 # Run old config regardless, to enforce min configurations
1559 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001560
Steven Rostedta75fece2010-11-02 14:58:27 -04001561 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001562 my $build_ret = run_command "$make $build_options";
1563 undef $redirect;
1564
1565 if (defined($post_build)) {
1566 my $ret = run_command $post_build;
1567 if (!$ret && defined($post_build_die) &&
1568 $post_build_die) {
1569 dodie "failed to post_build\n";
1570 }
1571 }
1572
1573 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001574 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001575 if ($in_bisect) {
1576 $no_reboot = $save_no_reboot;
1577 return 0;
1578 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001579 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001580 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001581
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001582 $no_reboot = $save_no_reboot;
1583
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001584 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001585}
1586
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001587sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001588 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001589 if (defined($poweroff_after_halt)) {
1590 sleep $poweroff_after_halt;
1591 run_command "$power_off";
1592 }
1593 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001594 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001595 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001596 }
1597}
1598
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001599sub success {
1600 my ($i) = @_;
1601
Steven Rostedte48c5292010-11-02 14:35:37 -04001602 $successes++;
1603
Steven Rostedt9064af52011-06-13 10:38:48 -04001604 my $name = "";
1605
1606 if (defined($test_name)) {
1607 $name = " ($test_name)";
1608 }
1609
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001610 doprint "\n\n*******************************************\n";
1611 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001612 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001613 doprint "*******************************************\n";
1614 doprint "*******************************************\n";
1615
Steven Rostedt576f6272010-11-02 14:58:38 -04001616 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001617 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001618 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001619 }
1620}
1621
Steven Rostedtc960bb92011-03-08 09:22:39 -05001622sub answer_bisect {
1623 for (;;) {
1624 doprint "Pass or fail? [p/f]";
1625 my $ans = <STDIN>;
1626 chomp $ans;
1627 if ($ans eq "p" || $ans eq "P") {
1628 return 1;
1629 } elsif ($ans eq "f" || $ans eq "F") {
1630 return 0;
1631 } else {
1632 print "Please answer 'P' or 'F'\n";
1633 }
1634 }
1635}
1636
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001637sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001638 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001639
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001640 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001641 $reboot_on_error = 0;
1642 $poweroff_on_error = 0;
1643 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001644
1645 run_command $run_test or $failed = 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001646 exit $failed;
1647}
1648
1649my $child_done;
1650
1651sub child_finished {
1652 $child_done = 1;
1653}
1654
1655sub do_run_test {
1656 my $child_pid;
1657 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001658 my $line;
1659 my $full_line;
1660 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001661
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001662 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001663
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001664 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001665
1666 $child_done = 0;
1667
1668 $SIG{CHLD} = qw(child_finished);
1669
1670 $child_pid = fork;
1671
1672 child_run_test if (!$child_pid);
1673
1674 $full_line = "";
1675
1676 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001677 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001678 if (defined($line)) {
1679
1680 # we are not guaranteed to get a full line
1681 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001682 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001683
1684 if ($full_line =~ /call trace:/i) {
1685 $bug = 1;
1686 }
1687
1688 if ($full_line =~ /Kernel panic -/) {
1689 $bug = 1;
1690 }
1691
1692 if ($line =~ /\n/) {
1693 $full_line = "";
1694 }
1695 }
1696 } while (!$child_done && !$bug);
1697
1698 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001699 my $failure_start = time;
1700 my $now;
1701 do {
1702 $line = wait_for_input($monitor_fp, 1);
1703 if (defined($line)) {
1704 doprint $line;
1705 }
1706 $now = time;
1707 if ($now - $failure_start >= $stop_after_failure) {
1708 last;
1709 }
1710 } while (defined($line));
1711
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001712 doprint "Detected kernel crash!\n";
1713 # kill the child with extreme prejudice
1714 kill 9, $child_pid;
1715 }
1716
1717 waitpid $child_pid, 0;
1718 $child_exit = $?;
1719
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001720 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001721 return 0 if $in_bisect;
1722 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001723 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001724 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001725}
1726
Steven Rostedta75fece2010-11-02 14:58:27 -04001727sub run_git_bisect {
1728 my ($command) = @_;
1729
1730 doprint "$command ... ";
1731
1732 my $output = `$command 2>&1`;
1733 my $ret = $?;
1734
1735 logit $output;
1736
1737 if ($ret) {
1738 doprint "FAILED\n";
1739 dodie "Failed to git bisect";
1740 }
1741
1742 doprint "SUCCESS\n";
1743 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1744 doprint "$1 [$2]\n";
1745 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1746 $bisect_bad = $1;
1747 doprint "Found bad commit... $1\n";
1748 return 0;
1749 } else {
1750 # we already logged it, just print it now.
1751 print $output;
1752 }
1753
1754 return 1;
1755}
1756
Steven Rostedtc23dca72011-03-08 09:26:31 -05001757sub bisect_reboot {
1758 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001759 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001760}
1761
1762# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001763sub run_bisect_test {
1764 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001765
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001766 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001767 my $result;
1768 my $output;
1769 my $ret;
1770
Steven Rostedt0a05c762010-11-08 11:14:10 -05001771 $in_bisect = 1;
1772
1773 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001774
1775 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001776 if ($failed && $bisect_skip) {
1777 $in_bisect = 0;
1778 return -1;
1779 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001780 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001781
1782 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001783 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001784
1785 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001786 if ($failed && $bisect_skip) {
1787 end_monitor;
1788 bisect_reboot;
1789 $in_bisect = 0;
1790 return -1;
1791 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001792 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001793
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001794 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001795 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001796 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001797 }
1798
1799 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001800 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001801 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001802 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001803 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001804
1805 # reboot the box to a kernel we can ssh to
1806 if ($type ne "build") {
1807 bisect_reboot;
1808 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001809 $in_bisect = 0;
1810
1811 return $result;
1812}
1813
1814sub run_bisect {
1815 my ($type) = @_;
1816 my $buildtype = "oldconfig";
1817
1818 # We should have a minconfig to use?
1819 if (defined($minconfig)) {
1820 $buildtype = "useconfig:$minconfig";
1821 }
1822
1823 my $ret = run_bisect_test $type, $buildtype;
1824
Steven Rostedtc960bb92011-03-08 09:22:39 -05001825 if ($bisect_manual) {
1826 $ret = answer_bisect;
1827 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001828
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001829 # Are we looking for where it worked, not failed?
1830 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001831 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001832 }
1833
Steven Rostedtc23dca72011-03-08 09:26:31 -05001834 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001835 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001836 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001837 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001838 } elsif ($bisect_skip) {
1839 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1840 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001841 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001842}
1843
1844sub bisect {
1845 my ($i) = @_;
1846
1847 my $result;
1848
1849 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1850 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1851 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1852
1853 my $good = $opt{"BISECT_GOOD[$i]"};
1854 my $bad = $opt{"BISECT_BAD[$i]"};
1855 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001856 my $start = $opt{"BISECT_START[$i]"};
1857 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001858 my $start_files = $opt{"BISECT_FILES[$i]"};
1859
1860 if (defined($start_files)) {
1861 $start_files = " -- " . $start_files;
1862 } else {
1863 $start_files = "";
1864 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001865
Steven Rostedta57419b2010-11-02 15:13:54 -04001866 # convert to true sha1's
1867 $good = get_sha1($good);
1868 $bad = get_sha1($bad);
1869
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001870 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1871 $opt{"BISECT_REVERSE[$i]"} == 1) {
1872 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1873 $reverse_bisect = 1;
1874 } else {
1875 $reverse_bisect = 0;
1876 }
1877
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001878 # Can't have a test without having a test to run
1879 if ($type eq "test" && !defined($run_test)) {
1880 $type = "boot";
1881 }
1882
Steven Rostedta75fece2010-11-02 14:58:27 -04001883 my $check = $opt{"BISECT_CHECK[$i]"};
1884 if (defined($check) && $check ne "0") {
1885
1886 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001887 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001888
1889 if ($check ne "good") {
1890 doprint "TESTING BISECT BAD [$bad]\n";
1891 run_command "git checkout $bad" or
1892 die "Failed to checkout $bad";
1893
1894 $result = run_bisect $type;
1895
1896 if ($result ne "bad") {
1897 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1898 }
1899 }
1900
1901 if ($check ne "bad") {
1902 doprint "TESTING BISECT GOOD [$good]\n";
1903 run_command "git checkout $good" or
1904 die "Failed to checkout $good";
1905
1906 $result = run_bisect $type;
1907
1908 if ($result ne "good") {
1909 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1910 }
1911 }
1912
1913 # checkout where we started
1914 run_command "git checkout $head" or
1915 die "Failed to checkout $head";
1916 }
1917
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001918 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001919 dodie "could not start bisect";
1920
1921 run_command "git bisect good $good" or
1922 dodie "could not set bisect good to $good";
1923
1924 run_git_bisect "git bisect bad $bad" or
1925 dodie "could not set bisect bad to $bad";
1926
1927 if (defined($replay)) {
1928 run_command "git bisect replay $replay" or
1929 dodie "failed to run replay";
1930 }
1931
1932 if (defined($start)) {
1933 run_command "git checkout $start" or
1934 dodie "failed to checkout $start";
1935 }
1936
1937 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001938 do {
1939 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001940 $test = run_git_bisect "git bisect $result";
1941 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001942
1943 run_command "git bisect log" or
1944 dodie "could not capture git bisect log";
1945
1946 run_command "git bisect reset" or
1947 dodie "could not reset git bisect";
1948
1949 doprint "Bad commit was [$bisect_bad]\n";
1950
Steven Rostedt0a05c762010-11-08 11:14:10 -05001951 success $i;
1952}
1953
1954my %config_ignore;
1955my %config_set;
1956
1957my %config_list;
1958my %null_config;
1959
1960my %dependency;
1961
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001962sub assign_configs {
1963 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001964
1965 open (IN, $config)
1966 or dodie "Failed to read $config";
1967
1968 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04001969 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001970 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001971 }
1972 }
1973
1974 close(IN);
1975}
1976
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001977sub process_config_ignore {
1978 my ($config) = @_;
1979
1980 assign_configs \%config_ignore, $config;
1981}
1982
Steven Rostedt0a05c762010-11-08 11:14:10 -05001983sub read_current_config {
1984 my ($config_ref) = @_;
1985
1986 %{$config_ref} = ();
1987 undef %{$config_ref};
1988
1989 my @key = keys %{$config_ref};
1990 if ($#key >= 0) {
1991 print "did not delete!\n";
1992 exit;
1993 }
1994 open (IN, "$output_config");
1995
1996 while (<IN>) {
1997 if (/^(CONFIG\S+)=(.*)/) {
1998 ${$config_ref}{$1} = $2;
1999 }
2000 }
2001 close(IN);
2002}
2003
2004sub get_dependencies {
2005 my ($config) = @_;
2006
2007 my $arr = $dependency{$config};
2008 if (!defined($arr)) {
2009 return ();
2010 }
2011
2012 my @deps = @{$arr};
2013
2014 foreach my $dep (@{$arr}) {
2015 print "ADD DEP $dep\n";
2016 @deps = (@deps, get_dependencies $dep);
2017 }
2018
2019 return @deps;
2020}
2021
2022sub create_config {
2023 my @configs = @_;
2024
2025 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2026
2027 foreach my $config (@configs) {
2028 print OUT "$config_set{$config}\n";
2029 my @deps = get_dependencies $config;
2030 foreach my $dep (@deps) {
2031 print OUT "$config_set{$dep}\n";
2032 }
2033 }
2034
2035 foreach my $config (keys %config_ignore) {
2036 print OUT "$config_ignore{$config}\n";
2037 }
2038 close(OUT);
2039
2040# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002041 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002042}
2043
2044sub compare_configs {
2045 my (%a, %b) = @_;
2046
2047 foreach my $item (keys %a) {
2048 if (!defined($b{$item})) {
2049 print "diff $item\n";
2050 return 1;
2051 }
2052 delete $b{$item};
2053 }
2054
2055 my @keys = keys %b;
2056 if ($#keys) {
2057 print "diff2 $keys[0]\n";
2058 }
2059 return -1 if ($#keys >= 0);
2060
2061 return 0;
2062}
2063
2064sub run_config_bisect_test {
2065 my ($type) = @_;
2066
2067 return run_bisect_test $type, "oldconfig";
2068}
2069
2070sub process_passed {
2071 my (%configs) = @_;
2072
2073 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2074 # Passed! All these configs are part of a good compile.
2075 # Add them to the min options.
2076 foreach my $config (keys %configs) {
2077 if (defined($config_list{$config})) {
2078 doprint " removing $config\n";
2079 $config_ignore{$config} = $config_list{$config};
2080 delete $config_list{$config};
2081 }
2082 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002083 doprint "config copied to $outputdir/config_good\n";
2084 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002085}
2086
2087sub process_failed {
2088 my ($config) = @_;
2089
2090 doprint "\n\n***************************************\n";
2091 doprint "Found bad config: $config\n";
2092 doprint "***************************************\n\n";
2093}
2094
2095sub run_config_bisect {
2096
2097 my @start_list = keys %config_list;
2098
2099 if ($#start_list < 0) {
2100 doprint "No more configs to test!!!\n";
2101 return -1;
2102 }
2103
2104 doprint "***** RUN TEST ***\n";
2105 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2106 my $ret;
2107 my %current_config;
2108
2109 my $count = $#start_list + 1;
2110 doprint " $count configs to test\n";
2111
2112 my $half = int($#start_list / 2);
2113
2114 do {
2115 my @tophalf = @start_list[0 .. $half];
2116
2117 create_config @tophalf;
2118 read_current_config \%current_config;
2119
2120 $count = $#tophalf + 1;
2121 doprint "Testing $count configs\n";
2122 my $found = 0;
2123 # make sure we test something
2124 foreach my $config (@tophalf) {
2125 if (defined($current_config{$config})) {
2126 logit " $config\n";
2127 $found = 1;
2128 }
2129 }
2130 if (!$found) {
2131 # try the other half
2132 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002133 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002134 create_config @tophalf;
2135 read_current_config \%current_config;
2136 foreach my $config (@tophalf) {
2137 if (defined($current_config{$config})) {
2138 logit " $config\n";
2139 $found = 1;
2140 }
2141 }
2142 if (!$found) {
2143 doprint "Failed: Can't make new config with current configs\n";
2144 foreach my $config (@start_list) {
2145 doprint " CONFIG: $config\n";
2146 }
2147 return -1;
2148 }
2149 $count = $#tophalf + 1;
2150 doprint "Testing $count configs\n";
2151 }
2152
2153 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002154 if ($bisect_manual) {
2155 $ret = answer_bisect;
2156 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002157 if ($ret) {
2158 process_passed %current_config;
2159 return 0;
2160 }
2161
2162 doprint "This config had a failure.\n";
2163 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002164 doprint "config copied to $outputdir/config_bad\n";
2165 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002166
2167 # A config exists in this group that was bad.
2168 foreach my $config (keys %config_list) {
2169 if (!defined($current_config{$config})) {
2170 doprint " removing $config\n";
2171 delete $config_list{$config};
2172 }
2173 }
2174
2175 @start_list = @tophalf;
2176
2177 if ($#start_list == 0) {
2178 process_failed $start_list[0];
2179 return 1;
2180 }
2181
2182 # remove half the configs we are looking at and see if
2183 # they are good.
2184 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002185 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002186
Steven Rostedtc960bb92011-03-08 09:22:39 -05002187 # we found a single config, try it again unless we are running manually
2188
2189 if ($bisect_manual) {
2190 process_failed $start_list[0];
2191 return 1;
2192 }
2193
Steven Rostedt0a05c762010-11-08 11:14:10 -05002194 my @tophalf = @start_list[0 .. 0];
2195
2196 $ret = run_config_bisect_test $type;
2197 if ($ret) {
2198 process_passed %current_config;
2199 return 0;
2200 }
2201
2202 process_failed $start_list[0];
2203 return 1;
2204}
2205
2206sub config_bisect {
2207 my ($i) = @_;
2208
2209 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2210
2211 my $tmpconfig = "$tmpdir/use_config";
2212
Steven Rostedt30f75da2011-06-13 10:35:35 -04002213 if (defined($config_bisect_good)) {
2214 process_config_ignore $config_bisect_good;
2215 }
2216
Steven Rostedt0a05c762010-11-08 11:14:10 -05002217 # Make the file with the bad config and the min config
2218 if (defined($minconfig)) {
2219 # read the min config for things to ignore
2220 run_command "cp $minconfig $tmpconfig" or
2221 dodie "failed to copy $minconfig to $tmpconfig";
2222 } else {
2223 unlink $tmpconfig;
2224 }
2225
Steven Rostedt0a05c762010-11-08 11:14:10 -05002226 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002227 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002228 process_config_ignore $tmpconfig;
2229 }
2230
2231 # now process the start config
2232 run_command "cp $start_config $output_config" or
2233 dodie "failed to copy $start_config to $output_config";
2234
2235 # read directly what we want to check
2236 my %config_check;
2237 open (IN, $output_config)
2238 or dodie "faied to open $output_config";
2239
2240 while (<IN>) {
2241 if (/^((CONFIG\S*)=.*)/) {
2242 $config_check{$2} = $1;
2243 }
2244 }
2245 close(IN);
2246
Steven Rostedt250bae82011-07-15 22:05:59 -04002247 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002248 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002249
2250 # check to see what we lost (or gained)
2251 open (IN, $output_config)
2252 or dodie "Failed to read $start_config";
2253
2254 my %removed_configs;
2255 my %added_configs;
2256
2257 while (<IN>) {
2258 if (/^((CONFIG\S*)=.*)/) {
2259 # save off all options
2260 $config_set{$2} = $1;
2261 if (defined($config_check{$2})) {
2262 if (defined($config_ignore{$2})) {
2263 $removed_configs{$2} = $1;
2264 } else {
2265 $config_list{$2} = $1;
2266 }
2267 } elsif (!defined($config_ignore{$2})) {
2268 $added_configs{$2} = $1;
2269 $config_list{$2} = $1;
2270 }
2271 }
2272 }
2273 close(IN);
2274
2275 my @confs = keys %removed_configs;
2276 if ($#confs >= 0) {
2277 doprint "Configs overridden by default configs and removed from check:\n";
2278 foreach my $config (@confs) {
2279 doprint " $config\n";
2280 }
2281 }
2282 @confs = keys %added_configs;
2283 if ($#confs >= 0) {
2284 doprint "Configs appearing in make oldconfig and added:\n";
2285 foreach my $config (@confs) {
2286 doprint " $config\n";
2287 }
2288 }
2289
2290 my %config_test;
2291 my $once = 0;
2292
2293 # Sometimes kconfig does weird things. We must make sure
2294 # that the config we autocreate has everything we need
2295 # to test, otherwise we may miss testing configs, or
2296 # may not be able to create a new config.
2297 # Here we create a config with everything set.
2298 create_config (keys %config_list);
2299 read_current_config \%config_test;
2300 foreach my $config (keys %config_list) {
2301 if (!defined($config_test{$config})) {
2302 if (!$once) {
2303 $once = 1;
2304 doprint "Configs not produced by kconfig (will not be checked):\n";
2305 }
2306 doprint " $config\n";
2307 delete $config_list{$config};
2308 }
2309 }
2310 my $ret;
2311 do {
2312 $ret = run_config_bisect;
2313 } while (!$ret);
2314
2315 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002316
2317 success $i;
2318}
2319
Steven Rostedt27d934b2011-05-20 09:18:18 -04002320sub patchcheck_reboot {
2321 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002322 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002323}
2324
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002325sub patchcheck {
2326 my ($i) = @_;
2327
2328 die "PATCHCHECK_START[$i] not defined\n"
2329 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2330 die "PATCHCHECK_TYPE[$i] not defined\n"
2331 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2332
2333 my $start = $opt{"PATCHCHECK_START[$i]"};
2334
2335 my $end = "HEAD";
2336 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2337 $end = $opt{"PATCHCHECK_END[$i]"};
2338 }
2339
Steven Rostedta57419b2010-11-02 15:13:54 -04002340 # Get the true sha1's since we can use things like HEAD~3
2341 $start = get_sha1($start);
2342 $end = get_sha1($end);
2343
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002344 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2345
2346 # Can't have a test without having a test to run
2347 if ($type eq "test" && !defined($run_test)) {
2348 $type = "boot";
2349 }
2350
2351 open (IN, "git log --pretty=oneline $end|") or
2352 dodie "could not get git list";
2353
2354 my @list;
2355
2356 while (<IN>) {
2357 chomp;
2358 $list[$#list+1] = $_;
2359 last if (/^$start/);
2360 }
2361 close(IN);
2362
2363 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002364 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002365 }
2366
2367 # go backwards in the list
2368 @list = reverse @list;
2369
2370 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002371 my %ignored_warnings;
2372
2373 if (defined($ignore_warnings)) {
2374 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2375 $ignored_warnings{$sha1} = 1;
2376 }
2377 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002378
2379 $in_patchcheck = 1;
2380 foreach my $item (@list) {
2381 my $sha1 = $item;
2382 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2383
2384 doprint "\nProcessing commit $item\n\n";
2385
2386 run_command "git checkout $sha1" or
2387 die "Failed to checkout $sha1";
2388
2389 # only clean on the first and last patch
2390 if ($item eq $list[0] ||
2391 $item eq $list[$#list]) {
2392 $noclean = $save_clean;
2393 } else {
2394 $noclean = 1;
2395 }
2396
2397 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002398 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002399 } else {
2400 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002401 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002402 }
2403
Steven Rostedt19902072011-06-14 20:46:25 -04002404
2405 if (!defined($ignored_warnings{$sha1})) {
2406 check_buildlog $sha1 or return 0;
2407 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002408
2409 next if ($type eq "build");
2410
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002411 my $failed = 0;
2412
Steven Rostedtddf607e2011-06-14 20:49:13 -04002413 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002414
2415 if (!$failed && $type ne "boot"){
2416 do_run_test or $failed = 1;
2417 }
2418 end_monitor;
2419 return 0 if ($failed);
2420
Steven Rostedt27d934b2011-05-20 09:18:18 -04002421 patchcheck_reboot;
2422
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002423 }
2424 $in_patchcheck = 0;
2425 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002426
2427 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002428}
2429
Steven Rostedtb9066f62011-07-15 21:25:24 -04002430my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002431my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002432my $iflevel = 0;
2433my @ifdeps;
2434
2435# prevent recursion
2436my %read_kconfigs;
2437
Steven Rostedtac6974c2011-10-04 09:40:17 -04002438sub add_dep {
2439 # $config depends on $dep
2440 my ($config, $dep) = @_;
2441
2442 if (defined($depends{$config})) {
2443 $depends{$config} .= " " . $dep;
2444 } else {
2445 $depends{$config} = $dep;
2446 }
2447
2448 # record the number of configs depending on $dep
2449 if (defined $depcount{$dep}) {
2450 $depcount{$dep}++;
2451 } else {
2452 $depcount{$dep} = 1;
2453 }
2454}
2455
Steven Rostedtb9066f62011-07-15 21:25:24 -04002456# taken from streamline_config.pl
2457sub read_kconfig {
2458 my ($kconfig) = @_;
2459
2460 my $state = "NONE";
2461 my $config;
2462 my @kconfigs;
2463
2464 my $cont = 0;
2465 my $line;
2466
2467
2468 if (! -f $kconfig) {
2469 doprint "file $kconfig does not exist, skipping\n";
2470 return;
2471 }
2472
2473 open(KIN, "$kconfig")
2474 or die "Can't open $kconfig";
2475 while (<KIN>) {
2476 chomp;
2477
2478 # Make sure that lines ending with \ continue
2479 if ($cont) {
2480 $_ = $line . " " . $_;
2481 }
2482
2483 if (s/\\$//) {
2484 $cont = 1;
2485 $line = $_;
2486 next;
2487 }
2488
2489 $cont = 0;
2490
2491 # collect any Kconfig sources
2492 if (/^source\s*"(.*)"/) {
2493 $kconfigs[$#kconfigs+1] = $1;
2494 }
2495
2496 # configs found
2497 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2498 $state = "NEW";
2499 $config = $2;
2500
2501 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002502 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002503 }
2504
2505 # collect the depends for the config
2506 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2507
Steven Rostedtac6974c2011-10-04 09:40:17 -04002508 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002509
2510 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002511 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2512
2513 # selected by depends on config
2514 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002515
2516 # Check for if statements
2517 } elsif (/^if\s+(.*\S)\s*$/) {
2518 my $deps = $1;
2519 # remove beginning and ending non text
2520 $deps =~ s/^[^a-zA-Z0-9_]*//;
2521 $deps =~ s/[^a-zA-Z0-9_]*$//;
2522
2523 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2524
2525 $ifdeps[$iflevel++] = join ':', @deps;
2526
2527 } elsif (/^endif/) {
2528
2529 $iflevel-- if ($iflevel);
2530
2531 # stop on "help"
2532 } elsif (/^\s*help\s*$/) {
2533 $state = "NONE";
2534 }
2535 }
2536 close(KIN);
2537
2538 # read in any configs that were found.
2539 foreach $kconfig (@kconfigs) {
2540 if (!defined($read_kconfigs{$kconfig})) {
2541 $read_kconfigs{$kconfig} = 1;
2542 read_kconfig("$builddir/$kconfig");
2543 }
2544 }
2545}
2546
2547sub read_depends {
2548 # find out which arch this is by the kconfig file
2549 open (IN, $output_config)
2550 or dodie "Failed to read $output_config";
2551 my $arch;
2552 while (<IN>) {
2553 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2554 $arch = $1;
2555 last;
2556 }
2557 }
2558 close IN;
2559
2560 if (!defined($arch)) {
2561 doprint "Could not find arch from config file\n";
2562 doprint "no dependencies used\n";
2563 return;
2564 }
2565
2566 # arch is really the subarch, we need to know
2567 # what directory to look at.
2568 if ($arch eq "i386" || $arch eq "x86_64") {
2569 $arch = "x86";
2570 } elsif ($arch =~ /^tile/) {
2571 $arch = "tile";
2572 }
2573
2574 my $kconfig = "$builddir/arch/$arch/Kconfig";
2575
2576 if (! -f $kconfig && $arch =~ /\d$/) {
2577 my $orig = $arch;
2578 # some subarchs have numbers, truncate them
2579 $arch =~ s/\d*$//;
2580 $kconfig = "$builddir/arch/$arch/Kconfig";
2581 if (! -f $kconfig) {
2582 doprint "No idea what arch dir $orig is for\n";
2583 doprint "no dependencies used\n";
2584 return;
2585 }
2586 }
2587
2588 read_kconfig($kconfig);
2589}
2590
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002591sub read_config_list {
2592 my ($config) = @_;
2593
2594 open (IN, $config)
2595 or dodie "Failed to read $config";
2596
2597 while (<IN>) {
2598 if (/^((CONFIG\S*)=.*)/) {
2599 if (!defined($config_ignore{$2})) {
2600 $config_list{$2} = $1;
2601 }
2602 }
2603 }
2604
2605 close(IN);
2606}
2607
2608sub read_output_config {
2609 my ($config) = @_;
2610
2611 assign_configs \%config_ignore, $config;
2612}
2613
2614sub make_new_config {
2615 my @configs = @_;
2616
2617 open (OUT, ">$output_config")
2618 or dodie "Failed to write $output_config";
2619
2620 foreach my $config (@configs) {
2621 print OUT "$config\n";
2622 }
2623 close OUT;
2624}
2625
Steven Rostedtac6974c2011-10-04 09:40:17 -04002626sub chomp_config {
2627 my ($config) = @_;
2628
2629 $config =~ s/CONFIG_//;
2630
2631 return $config;
2632}
2633
Steven Rostedtb9066f62011-07-15 21:25:24 -04002634sub get_depends {
2635 my ($dep) = @_;
2636
Steven Rostedtac6974c2011-10-04 09:40:17 -04002637 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002638
2639 $dep = $depends{"$kconfig"};
2640
2641 # the dep string we have saves the dependencies as they
2642 # were found, including expressions like ! && ||. We
2643 # want to split this out into just an array of configs.
2644
2645 my $valid = "A-Za-z_0-9";
2646
2647 my @configs;
2648
2649 while ($dep =~ /[$valid]/) {
2650
2651 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2652 my $conf = "CONFIG_" . $1;
2653
2654 $configs[$#configs + 1] = $conf;
2655
2656 $dep =~ s/^[^$valid]*[$valid]+//;
2657 } else {
2658 die "this should never happen";
2659 }
2660 }
2661
2662 return @configs;
2663}
2664
2665my %min_configs;
2666my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002667my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002668my %processed_configs;
2669my %nochange_config;
2670
2671sub test_this_config {
2672 my ($config) = @_;
2673
2674 my $found;
2675
2676 # if we already processed this config, skip it
2677 if (defined($processed_configs{$config})) {
2678 return undef;
2679 }
2680 $processed_configs{$config} = 1;
2681
2682 # if this config failed during this round, skip it
2683 if (defined($nochange_config{$config})) {
2684 return undef;
2685 }
2686
Steven Rostedtac6974c2011-10-04 09:40:17 -04002687 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002688
2689 # Test dependencies first
2690 if (defined($depends{"$kconfig"})) {
2691 my @parents = get_depends $config;
2692 foreach my $parent (@parents) {
2693 # if the parent is in the min config, check it first
2694 next if (!defined($min_configs{$parent}));
2695 $found = test_this_config($parent);
2696 if (defined($found)) {
2697 return $found;
2698 }
2699 }
2700 }
2701
2702 # Remove this config from the list of configs
2703 # do a make oldnoconfig and then read the resulting
2704 # .config to make sure it is missing the config that
2705 # we had before
2706 my %configs = %min_configs;
2707 delete $configs{$config};
2708 make_new_config ((values %configs), (values %keep_configs));
2709 make_oldconfig;
2710 undef %configs;
2711 assign_configs \%configs, $output_config;
2712
2713 return $config if (!defined($configs{$config}));
2714
2715 doprint "disabling config $config did not change .config\n";
2716
2717 $nochange_config{$config} = 1;
2718
2719 return undef;
2720}
2721
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002722sub make_min_config {
2723 my ($i) = @_;
2724
2725 if (!defined($output_minconfig)) {
2726 fail "OUTPUT_MIN_CONFIG not defined" and return;
2727 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002728
2729 # If output_minconfig exists, and the start_minconfig
2730 # came from min_config, than ask if we should use
2731 # that instead.
2732 if (-f $output_minconfig && !$start_minconfig_defined) {
2733 print "$output_minconfig exists\n";
2734 if (read_yn " Use it as minconfig?") {
2735 $start_minconfig = $output_minconfig;
2736 }
2737 }
2738
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002739 if (!defined($start_minconfig)) {
2740 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2741 }
2742
Steven Rostedt35ce5952011-07-15 21:57:25 -04002743 my $temp_config = "$tmpdir/temp_config";
2744
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002745 # First things first. We build an allnoconfig to find
2746 # out what the defaults are that we can't touch.
2747 # Some are selections, but we really can't handle selections.
2748
2749 my $save_minconfig = $minconfig;
2750 undef $minconfig;
2751
2752 run_command "$make allnoconfig" or return 0;
2753
Steven Rostedtb9066f62011-07-15 21:25:24 -04002754 read_depends;
2755
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002756 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002757
Steven Rostedt43d1b652011-07-15 22:01:56 -04002758 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002759 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002760
2761 if (defined($ignore_config)) {
2762 # make sure the file exists
2763 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002764 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002765 }
2766
Steven Rostedt43d1b652011-07-15 22:01:56 -04002767 %keep_configs = %save_configs;
2768
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002769 doprint "Load initial configs from $start_minconfig\n";
2770
2771 # Look at the current min configs, and save off all the
2772 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002773 assign_configs \%min_configs, $start_minconfig;
2774
2775 my @config_keys = keys %min_configs;
2776
Steven Rostedtac6974c2011-10-04 09:40:17 -04002777 # All configs need a depcount
2778 foreach my $config (@config_keys) {
2779 my $kconfig = chomp_config $config;
2780 if (!defined $depcount{$kconfig}) {
2781 $depcount{$kconfig} = 0;
2782 }
2783 }
2784
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002785 # Remove anything that was set by the make allnoconfig
2786 # we shouldn't need them as they get set for us anyway.
2787 foreach my $config (@config_keys) {
2788 # Remove anything in the ignore_config
2789 if (defined($keep_configs{$config})) {
2790 my $file = $ignore_config;
2791 $file =~ s,.*/(.*?)$,$1,;
2792 doprint "$config set by $file ... ignored\n";
2793 delete $min_configs{$config};
2794 next;
2795 }
2796 # But make sure the settings are the same. If a min config
2797 # sets a selection, we do not want to get rid of it if
2798 # it is not the same as what we have. Just move it into
2799 # the keep configs.
2800 if (defined($config_ignore{$config})) {
2801 if ($config_ignore{$config} ne $min_configs{$config}) {
2802 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2803 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2804 $keep_configs{$config} = $min_configs{$config};
2805 } else {
2806 doprint "$config set by allnoconfig ... ignored\n";
2807 }
2808 delete $min_configs{$config};
2809 }
2810 }
2811
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002812 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002813 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002814
2815 while (!$done) {
2816
2817 my $config;
2818 my $found;
2819
2820 # Now disable each config one by one and do a make oldconfig
2821 # till we find a config that changes our list.
2822
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002823 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002824
2825 # Sort keys by who is most dependent on
2826 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2827 @test_configs ;
2828
2829 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002830 my $reset = 1;
2831 for (my $i = 0; $i < $#test_configs; $i++) {
2832 if (!defined($nochange_config{$test_configs[0]})) {
2833 $reset = 0;
2834 last;
2835 }
2836 # This config didn't change the .config last time.
2837 # Place it at the end
2838 my $config = shift @test_configs;
2839 push @test_configs, $config;
2840 }
2841
2842 # if every test config has failed to modify the .config file
2843 # in the past, then reset and start over.
2844 if ($reset) {
2845 undef %nochange_config;
2846 }
2847
Steven Rostedtb9066f62011-07-15 21:25:24 -04002848 undef %processed_configs;
2849
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002850 foreach my $config (@test_configs) {
2851
Steven Rostedtb9066f62011-07-15 21:25:24 -04002852 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002853
Steven Rostedtb9066f62011-07-15 21:25:24 -04002854 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002855
2856 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002857 }
2858
2859 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002860 # we could have failed due to the nochange_config hash
2861 # reset and try again
2862 if (!$take_two) {
2863 undef %nochange_config;
2864 $take_two = 1;
2865 next;
2866 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002867 doprint "No more configs found that we can disable\n";
2868 $done = 1;
2869 last;
2870 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04002871 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002872
2873 $config = $found;
2874
2875 doprint "Test with $config disabled\n";
2876
2877 # set in_bisect to keep build and monitor from dieing
2878 $in_bisect = 1;
2879
2880 my $failed = 0;
2881 build "oldconfig";
2882 start_monitor_and_boot or $failed = 1;
2883 end_monitor;
2884
2885 $in_bisect = 0;
2886
2887 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002888 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002889 # this config is needed, add it to the ignore list.
2890 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04002891 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002892 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04002893
2894 # update new ignore configs
2895 if (defined($ignore_config)) {
2896 open (OUT, ">$temp_config")
2897 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04002898 foreach my $config (keys %save_configs) {
2899 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002900 }
2901 close OUT;
2902 run_command "mv $temp_config $ignore_config" or
2903 dodie "failed to copy update to $ignore_config";
2904 }
2905
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002906 } else {
2907 # We booted without this config, remove it from the minconfigs.
2908 doprint "$config is not needed, disabling\n";
2909
2910 delete $min_configs{$config};
2911
2912 # Also disable anything that is not enabled in this config
2913 my %configs;
2914 assign_configs \%configs, $output_config;
2915 my @config_keys = keys %min_configs;
2916 foreach my $config (@config_keys) {
2917 if (!defined($configs{$config})) {
2918 doprint "$config is not set, disabling\n";
2919 delete $min_configs{$config};
2920 }
2921 }
2922
2923 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04002924 open (OUT, ">$temp_config")
2925 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002926 foreach my $config (keys %keep_configs) {
2927 print OUT "$keep_configs{$config}\n";
2928 }
2929 foreach my $config (keys %min_configs) {
2930 print OUT "$min_configs{$config}\n";
2931 }
2932 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04002933
2934 run_command "mv $temp_config $output_minconfig" or
2935 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002936 }
2937
2938 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002939 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002940 }
2941
2942 success $i;
2943 return 1;
2944}
2945
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002946$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002947
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002948if ($#ARGV == 0) {
2949 $ktest_config = $ARGV[0];
2950 if (! -f $ktest_config) {
2951 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002952 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002953 exit 0;
2954 }
2955 }
2956} else {
2957 $ktest_config = "ktest.conf";
2958}
2959
2960if (! -f $ktest_config) {
2961 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2962 print OUT << "EOF"
2963# Generated by ktest.pl
2964#
2965# Define each test with TEST_START
2966# The config options below it will override the defaults
2967TEST_START
2968
2969DEFAULTS
2970EOF
2971;
2972 close(OUT);
2973}
2974read_config $ktest_config;
2975
Steven Rostedt23715c3c2011-06-13 11:03:34 -04002976if (defined($opt{"LOG_FILE"})) {
2977 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
2978}
2979
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002980# Append any configs entered in manually to the config file.
2981my @new_configs = keys %entered_configs;
2982if ($#new_configs >= 0) {
2983 print "\nAppending entered in configs to $ktest_config\n";
2984 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2985 foreach my $config (@new_configs) {
2986 print OUT "$config = $entered_configs{$config}\n";
2987 $opt{$config} = $entered_configs{$config};
2988 }
2989}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002990
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002991if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2992 unlink $opt{"LOG_FILE"};
2993}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002994
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002995doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2996
Steven Rostedta57419b2010-11-02 15:13:54 -04002997for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2998
2999 if (!$i) {
3000 doprint "DEFAULT OPTIONS:\n";
3001 } else {
3002 doprint "\nTEST $i OPTIONS";
3003 if (defined($repeat_tests{$i})) {
3004 $repeat = $repeat_tests{$i};
3005 doprint " ITERATE $repeat";
3006 }
3007 doprint "\n";
3008 }
3009
3010 foreach my $option (sort keys %opt) {
3011
3012 if ($option =~ /\[(\d+)\]$/) {
3013 next if ($i != $1);
3014 } else {
3015 next if ($i);
3016 }
3017
3018 doprint "$option = $opt{$option}\n";
3019 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003020}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003021
Steven Rostedt2a625122011-05-20 15:48:59 -04003022sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003023 my ($name, $i) = @_;
3024
3025 my $option = "$name\[$i\]";
3026
3027 if (defined($opt{$option})) {
3028 return $opt{$option};
3029 }
3030
Steven Rostedta57419b2010-11-02 15:13:54 -04003031 foreach my $test (keys %repeat_tests) {
3032 if ($i >= $test &&
3033 $i < $test + $repeat_tests{$test}) {
3034 $option = "$name\[$test\]";
3035 if (defined($opt{$option})) {
3036 return $opt{$option};
3037 }
3038 }
3039 }
3040
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003041 if (defined($opt{$name})) {
3042 return $opt{$name};
3043 }
3044
3045 return undef;
3046}
3047
Steven Rostedt2a625122011-05-20 15:48:59 -04003048sub set_test_option {
3049 my ($name, $i) = @_;
3050
3051 my $option = __set_test_option($name, $i);
3052 return $option if (!defined($option));
3053
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003054 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003055}
3056
Steven Rostedt2545eb62010-11-02 15:01:32 -04003057# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003058for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003059
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003060 # Do not reboot on failing test options
3061 $no_reboot = 1;
3062
Steven Rostedt576f6272010-11-02 14:58:38 -04003063 $iteration = $i;
3064
Steven Rostedta75fece2010-11-02 14:58:27 -04003065 my $makecmd = set_test_option("MAKE_CMD", $i);
3066
3067 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003068 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003069 $tmpdir = set_test_option("TMP_DIR", $i);
3070 $outputdir = set_test_option("OUTPUT_DIR", $i);
3071 $builddir = set_test_option("BUILD_DIR", $i);
3072 $test_type = set_test_option("TEST_TYPE", $i);
3073 $build_type = set_test_option("BUILD_TYPE", $i);
3074 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003075 $pre_build = set_test_option("PRE_BUILD", $i);
3076 $post_build = set_test_option("POST_BUILD", $i);
3077 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3078 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003079 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003080 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003081 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3082 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003083 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3084 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3085 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003086 $run_test = set_test_option("TEST", $i);
3087 $addconfig = set_test_option("ADD_CONFIG", $i);
3088 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3089 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003090 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003091 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003092 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3093 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3094 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3095 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3096 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003097 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3098 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003099 $sleep_time = set_test_option("SLEEP_TIME", $i);
3100 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003101 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003102 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003103 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003104 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003105 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003106 $store_failures = set_test_option("STORE_FAILURES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003107 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003108 $timeout = set_test_option("TIMEOUT", $i);
3109 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3110 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003111 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003112 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003113 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003114 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3115 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003116 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003117 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003118 $ssh_exec = set_test_option("SSH_EXEC", $i);
3119 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003120 $target_image = set_test_option("TARGET_IMAGE", $i);
3121 $localversion = set_test_option("LOCALVERSION", $i);
3122
Steven Rostedt35ce5952011-07-15 21:57:25 -04003123 $start_minconfig_defined = 1;
3124
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003125 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003126 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003127 $start_minconfig = $minconfig;
3128 }
3129
Steven Rostedta75fece2010-11-02 14:58:27 -04003130 chdir $builddir || die "can't change directory to $builddir";
3131
Andrew Jonesa908a662011-08-12 15:32:03 +02003132 foreach my $dir ($tmpdir, $outputdir) {
3133 if (!-d $dir) {
3134 mkpath($dir) or
3135 die "can't create $dir";
3136 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003137 }
3138
Steven Rostedte48c5292010-11-02 14:35:37 -04003139 $ENV{"SSH_USER"} = $ssh_user;
3140 $ENV{"MACHINE"} = $machine;
3141
Steven Rostedta75fece2010-11-02 14:58:27 -04003142 $target = "$ssh_user\@$machine";
3143
3144 $buildlog = "$tmpdir/buildlog-$machine";
3145 $dmesg = "$tmpdir/dmesg-$machine";
3146 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003147 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003148
3149 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04003150 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04003151 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04003152 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04003153 }
3154
3155 my $run_type = $build_type;
3156 if ($test_type eq "patchcheck") {
3157 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3158 } elsif ($test_type eq "bisect") {
3159 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003160 } elsif ($test_type eq "config_bisect") {
3161 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003162 }
3163
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003164 if ($test_type eq "make_min_config") {
3165 $run_type = "";
3166 }
3167
Steven Rostedta75fece2010-11-02 14:58:27 -04003168 # mistake in config file?
3169 if (!defined($run_type)) {
3170 $run_type = "ERROR";
3171 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003172
Steven Rostedte0a87422011-09-30 17:50:48 -04003173 my $installme = "";
3174 $installme = " no_install" if ($no_install);
3175
Steven Rostedt2545eb62010-11-02 15:01:32 -04003176 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003177 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003178
3179 unlink $dmesg;
3180 unlink $buildlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003181
Steven Rostedt250bae82011-07-15 22:05:59 -04003182 if (defined($addconfig)) {
3183 my $min = $minconfig;
3184 if (!defined($minconfig)) {
3185 $min = "";
3186 }
3187 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003188 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003189 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003190 }
3191
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003192 my $checkout = $opt{"CHECKOUT[$i]"};
3193 if (defined($checkout)) {
3194 run_command "git checkout $checkout" or
3195 die "failed to checkout $checkout";
3196 }
3197
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003198 $no_reboot = 0;
3199
3200
Steven Rostedta75fece2010-11-02 14:58:27 -04003201 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003202 bisect $i;
3203 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003204 } elsif ($test_type eq "config_bisect") {
3205 config_bisect $i;
3206 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003207 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003208 patchcheck $i;
3209 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003210 } elsif ($test_type eq "make_min_config") {
3211 make_min_config $i;
3212 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003213 }
3214
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003215 if ($build_type ne "nobuild") {
3216 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003217 }
3218
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003219 if ($test_type eq "install") {
3220 get_version;
3221 install;
3222 success $i;
3223 next;
3224 }
3225
Steven Rostedta75fece2010-11-02 14:58:27 -04003226 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003227 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003228 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003229
3230 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3231 do_run_test or $failed = 1;
3232 }
3233 end_monitor;
3234 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003235 }
3236
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003237 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003238}
3239
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003240if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003241 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003242} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003243 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003244}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003245
Steven Rostedte48c5292010-11-02 14:35:37 -04003246doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3247
Steven Rostedt2545eb62010-11-02 15:01:32 -04003248exit 0;