blob: 77b464980de1da6c1e7cb75c5c44cb695c9561fb [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002#
Uwe Kleine-Königcce1dac2011-01-24 21:12:01 +01003# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04004# Licensed under the terms of the GNU GPL License version 2
5#
Steven Rostedt2545eb62010-11-02 15:01:32 -04006
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Steven Rostedt7faafbd2010-11-02 14:58:22 -040010use File::Path qw(mkpath);
11use File::Copy qw(cp);
Steven Rostedt2545eb62010-11-02 15:01:32 -040012use FileHandle;
13
Steven Rostedte48c5292010-11-02 14:35:37 -040014my $VERSION = "0.2";
15
Steven Rostedt2545eb62010-11-02 15:01:32 -040016$| = 1;
17
18my %opt;
Steven Rostedta57419b2010-11-02 15:13:54 -040019my %repeat_tests;
20my %repeats;
Steven Rostedta75fece2010-11-02 14:58:27 -040021my %default;
Steven Rostedt2545eb62010-11-02 15:01:32 -040022
23#default opts
Steven Rostedta57419b2010-11-02 15:13:54 -040024$default{"NUM_TESTS"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040025$default{"TEST_TYPE"} = "test";
26$default{"BUILD_TYPE"} = "randconfig";
27$default{"MAKE_CMD"} = "make";
28$default{"TIMEOUT"} = 120;
Steven Rostedt48920632011-06-14 20:42:19 -040029$default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
Steven Rostedta75fece2010-11-02 14:58:27 -040030$default{"SLEEP_TIME"} = 60; # sleep time between tests
31$default{"BUILD_NOCLEAN"} = 0;
32$default{"REBOOT_ON_ERROR"} = 0;
33$default{"POWEROFF_ON_ERROR"} = 0;
34$default{"REBOOT_ON_SUCCESS"} = 1;
35$default{"POWEROFF_ON_SUCCESS"} = 0;
36$default{"BUILD_OPTIONS"} = "";
37$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
Steven Rostedt27d934b2011-05-20 09:18:18 -040038$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
Steven Rostedta75fece2010-11-02 14:58:27 -040039$default{"CLEAR_LOG"} = 0;
Steven Rostedtc960bb92011-03-08 09:22:39 -050040$default{"BISECT_MANUAL"} = 0;
Steven Rostedtc23dca72011-03-08 09:26:31 -050041$default{"BISECT_SKIP"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040042$default{"SUCCESS_LINE"} = "login:";
Steven Rostedtf1a5b962011-06-13 10:30:00 -040043$default{"DETECT_TRIPLE_FAULT"} = 1;
Steven Rostedte0a87422011-09-30 17:50:48 -040044$default{"NO_INSTALL"} = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040045$default{"BOOTED_TIMEOUT"} = 1;
46$default{"DIE_ON_FAILURE"} = 1;
Steven Rostedte48c5292010-11-02 14:35:37 -040047$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
48$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
49$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
Steven Rostedt1c8a6172010-11-09 12:55:40 -050050$default{"STOP_AFTER_SUCCESS"} = 10;
51$default{"STOP_AFTER_FAILURE"} = 60;
Steven Rostedt2d01b262011-03-08 09:47:54 -050052$default{"STOP_TEST_AFTER"} = 600;
Steven Rostedt600bbf02011-11-21 20:12:04 -050053
54# required, and we will ask users if they don't have them but we keep the default
55# value something that is common.
56$default{"REBOOT_TYPE"} = "grub";
Steven Rostedt8d1491b2010-11-18 15:39:48 -050057$default{"LOCALVERSION"} = "-test";
Steven Rostedt600bbf02011-11-21 20:12:04 -050058$default{"SSH_USER"} = "root";
59$default{"BUILD_TARGET"} = "arch/x86/boot/bzImage";
60$default{"TARGET_IMAGE"} = "/boot/vmlinuz-test";
Steven Rostedt2545eb62010-11-02 15:01:32 -040061
Steven Rostedt8d1491b2010-11-18 15:39:48 -050062my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040063my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040064my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040065my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040066my $tmpdir;
67my $builddir;
68my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050069my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040070my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040071my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040072my $build_options;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040073my $pre_build;
74my $post_build;
75my $pre_build_die;
76my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $reboot_type;
78my $reboot_script;
79my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040080my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040081my $reboot_on_error;
82my $poweroff_on_error;
83my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040084my $powercycle_after_reboot;
85my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040086my $ssh_exec;
87my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040088my $power_off;
89my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040090my $grub_number;
91my $target;
92my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040093my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -040094my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040095my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040096my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040097my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -040098my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040099my $output_minconfig;
100my $ignore_config;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400101my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400102my $in_bisect = 0;
103my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400104my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500105my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500106my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400107my $config_bisect_good;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400108my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400109my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400110my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400111my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530112my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400113my $dmesg;
114my $monitor_fp;
115my $monitor_pid;
116my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400117my $sleep_time;
118my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400119my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400120my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400121my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530122my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400123my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400124my $timeout;
125my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400126my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400127my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400128my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400129my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500130my $stop_after_success;
131my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500132my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400133my $build_target;
134my $target_image;
135my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400136my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400137my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400138
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500139my %entered_configs;
140my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400141my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400142my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500143
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400144# do not force reboots on config problems
145my $no_reboot = 1;
146
Steven Rostedt7bf51072011-10-22 09:07:03 -0400147# default variables that can be used
148chomp ($variable{"PWD"} = `pwd`);
149
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500150$config_help{"MACHINE"} = << "EOF"
151 The machine hostname that you will test.
152EOF
153 ;
154$config_help{"SSH_USER"} = << "EOF"
155 The box is expected to have ssh on normal bootup, provide the user
156 (most likely root, since you need privileged operations)
157EOF
158 ;
159$config_help{"BUILD_DIR"} = << "EOF"
160 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500161 You can use \${PWD} that will be the path where ktest.pl is run, or use
162 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500163EOF
164 ;
165$config_help{"OUTPUT_DIR"} = << "EOF"
166 The directory that the objects will be built (full path).
167 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500168 You can use \${PWD} that will be the path where ktest.pl is run, or use
169 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500170EOF
171 ;
172$config_help{"BUILD_TARGET"} = << "EOF"
173 The location of the compiled file to copy to the target.
174 (relative to OUTPUT_DIR)
175EOF
176 ;
177$config_help{"TARGET_IMAGE"} = << "EOF"
178 The place to put your image on the test machine.
179EOF
180 ;
181$config_help{"POWER_CYCLE"} = << "EOF"
182 A script or command to reboot the box.
183
184 Here is a digital loggers power switch example
185 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
186
187 Here is an example to reboot a virtual box on the current host
188 with the name "Guest".
189 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
190EOF
191 ;
192$config_help{"CONSOLE"} = << "EOF"
193 The script or command that reads the console
194
195 If you use ttywatch server, something like the following would work.
196CONSOLE = nc -d localhost 3001
197
198 For a virtual machine with guest name "Guest".
199CONSOLE = virsh console Guest
200EOF
201 ;
202$config_help{"LOCALVERSION"} = << "EOF"
203 Required version ending to differentiate the test
204 from other linux builds on the system.
205EOF
206 ;
207$config_help{"REBOOT_TYPE"} = << "EOF"
208 Way to reboot the box to the test kernel.
209 Only valid options so far are "grub" and "script".
210
211 If you specify grub, it will assume grub version 1
212 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
213 and select that target to reboot to the kernel. If this is not
214 your setup, then specify "script" and have a command or script
215 specified in REBOOT_SCRIPT to boot to the target.
216
217 The entry in /boot/grub/menu.lst must be entered in manually.
218 The test will not modify that file.
219EOF
220 ;
221$config_help{"GRUB_MENU"} = << "EOF"
222 The grub title name for the test kernel to boot
223 (Only mandatory if REBOOT_TYPE = grub)
224
225 Note, ktest.pl will not update the grub menu.lst, you need to
226 manually add an option for the test. ktest.pl will search
227 the grub menu.lst for this option to find what kernel to
228 reboot into.
229
230 For example, if in the /boot/grub/menu.lst the test kernel title has:
231 title Test Kernel
232 kernel vmlinuz-test
233 GRUB_MENU = Test Kernel
234EOF
235 ;
236$config_help{"REBOOT_SCRIPT"} = << "EOF"
237 A script to reboot the target into the test kernel
238 (Only mandatory if REBOOT_TYPE = script)
239EOF
240 ;
241
Steven Rostedt35ce5952011-07-15 21:57:25 -0400242sub read_yn {
243 my ($prompt) = @_;
244
245 my $ans;
246
247 for (;;) {
248 print "$prompt [Y/n] ";
249 $ans = <STDIN>;
250 chomp $ans;
251 if ($ans =~ /^\s*$/) {
252 $ans = "y";
253 }
254 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
255 print "Please answer either 'y' or 'n'.\n";
256 }
257 if ($ans !~ /^y$/i) {
258 return 0;
259 }
260 return 1;
261}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500262
263sub get_ktest_config {
264 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400265 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500266
267 return if (defined($opt{$config}));
268
269 if (defined($config_help{$config})) {
270 print "\n";
271 print $config_help{$config};
272 }
273
274 for (;;) {
275 print "$config = ";
276 if (defined($default{$config})) {
277 print "\[$default{$config}\] ";
278 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400279 $ans = <STDIN>;
280 $ans =~ s/^\s*(.*\S)\s*$/$1/;
281 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500282 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400283 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500284 } else {
285 print "Your answer can not be blank\n";
286 next;
287 }
288 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500289 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500290 last;
291 }
292}
293
294sub get_ktest_configs {
295 get_ktest_config("MACHINE");
296 get_ktest_config("SSH_USER");
297 get_ktest_config("BUILD_DIR");
298 get_ktest_config("OUTPUT_DIR");
299 get_ktest_config("BUILD_TARGET");
300 get_ktest_config("TARGET_IMAGE");
301 get_ktest_config("POWER_CYCLE");
302 get_ktest_config("CONSOLE");
303 get_ktest_config("LOCALVERSION");
304
305 my $rtype = $opt{"REBOOT_TYPE"};
306
307 if (!defined($rtype)) {
308 if (!defined($opt{"GRUB_MENU"})) {
309 get_ktest_config("REBOOT_TYPE");
310 $rtype = $entered_configs{"REBOOT_TYPE"};
311 } else {
312 $rtype = "grub";
313 }
314 }
315
316 if ($rtype eq "grub") {
317 get_ktest_config("GRUB_MENU");
318 } else {
319 get_ktest_config("REBOOT_SCRIPT");
320 }
321}
322
Steven Rostedt77d942c2011-05-20 13:36:58 -0400323sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400324 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400325 my $retval = "";
326
327 # We want to check for '\', and it is just easier
328 # to check the previous characet of '$' and not need
329 # to worry if '$' is the first character. By adding
330 # a space to $value, we can just check [^\\]\$ and
331 # it will still work.
332 $value = " $value";
333
334 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
335 my $begin = $1;
336 my $var = $2;
337 my $end = $3;
338 # append beginning of value to retval
339 $retval = "$retval$begin";
340 if (defined($variable{$var})) {
341 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400342 } elsif (defined($remove_undef) && $remove_undef) {
343 # for if statements, any variable that is not defined,
344 # we simple convert to 0
345 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400346 } else {
347 # put back the origin piece.
348 $retval = "$retval\$\{$var\}";
349 }
350 $value = $end;
351 }
352 $retval = "$retval$value";
353
354 # remove the space added in the beginning
355 $retval =~ s/ //;
356
357 return "$retval"
358}
359
Steven Rostedta57419b2010-11-02 15:13:54 -0400360sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400361 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400362
363 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400364 if (!$override || defined(${$overrides}{$lvalue})) {
365 my $extra = "";
366 if ($override) {
367 $extra = "In the same override section!\n";
368 }
369 die "$name: $.: Option $lvalue defined more than once!\n$extra";
370 }
371 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400372 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500373 if ($rvalue =~ /^\s*$/) {
374 delete $opt{$lvalue};
375 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400376 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500377 $opt{$lvalue} = $rvalue;
378 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400379}
380
Steven Rostedt77d942c2011-05-20 13:36:58 -0400381sub set_variable {
382 my ($lvalue, $rvalue) = @_;
383
384 if ($rvalue =~ /^\s*$/) {
385 delete $variable{$lvalue};
386 } else {
387 $rvalue = process_variables($rvalue);
388 $variable{$lvalue} = $rvalue;
389 }
390}
391
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400392sub process_compare {
393 my ($lval, $cmp, $rval) = @_;
394
395 # remove whitespace
396
397 $lval =~ s/^\s*//;
398 $lval =~ s/\s*$//;
399
400 $rval =~ s/^\s*//;
401 $rval =~ s/\s*$//;
402
403 if ($cmp eq "==") {
404 return $lval eq $rval;
405 } elsif ($cmp eq "!=") {
406 return $lval ne $rval;
407 }
408
409 my $statement = "$lval $cmp $rval";
410 my $ret = eval $statement;
411
412 # $@ stores error of eval
413 if ($@) {
414 return -1;
415 }
416
417 return $ret;
418}
419
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400420sub value_defined {
421 my ($val) = @_;
422
423 return defined($variable{$2}) ||
424 defined($opt{$2});
425}
426
Steven Rostedt8d735212011-10-17 11:36:44 -0400427my $d = 0;
428sub process_expression {
429 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400430
Steven Rostedt8d735212011-10-17 11:36:44 -0400431 my $c = $d++;
432
433 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
434 my $express = $1;
435
436 if (process_expression($name, $express)) {
437 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
438 } else {
439 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
440 }
441 }
442
443 $d--;
444 my $OR = "\\|\\|";
445 my $AND = "\\&\\&";
446
447 while ($val =~ s/^(.*?)($OR|$AND)//) {
448 my $express = $1;
449 my $op = $2;
450
451 if (process_expression($name, $express)) {
452 if ($op eq "||") {
453 return 1;
454 }
455 } else {
456 if ($op eq "&&") {
457 return 0;
458 }
459 }
460 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400461
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400462 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
463 my $ret = process_compare($1, $2, $3);
464 if ($ret < 0) {
465 die "$name: $.: Unable to process comparison\n";
466 }
467 return $ret;
468 }
469
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400470 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
471 if (defined $1) {
472 return !value_defined($2);
473 } else {
474 return value_defined($2);
475 }
476 }
477
Steven Rostedt45d73a52011-09-30 19:44:53 -0400478 if ($val =~ /^\s*0\s*$/) {
479 return 0;
480 } elsif ($val =~ /^\s*\d+\s*$/) {
481 return 1;
482 }
483
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400484 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400485}
486
487sub process_if {
488 my ($name, $value) = @_;
489
490 # Convert variables and replace undefined ones with 0
491 my $val = process_variables($value, 1);
492 my $ret = process_expression $name, $val;
493
494 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400495}
496
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400497sub __read_config {
498 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400499
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400500 my $in;
501 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400502
Steven Rostedta57419b2010-11-02 15:13:54 -0400503 my $name = $config;
504 $name =~ s,.*/(.*),$1,;
505
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400506 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400507 my $default = 1;
508 my $repeat = 1;
509 my $num_tests_set = 0;
510 my $skip = 0;
511 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400512 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400513 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400514 my $if = 0;
515 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400516 my $override = 0;
517
518 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400519
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400520 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400521
522 # ignore blank lines and comments
523 next if (/^\s*$/ || /\s*\#/);
524
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400525 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400526
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400527 my $type = $1;
528 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400529 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400530
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400531 my $old_test_num;
532 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400533 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400534
535 if ($type eq "TEST_START") {
536
537 if ($num_tests_set) {
538 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
539 }
540
541 $old_test_num = $test_num;
542 $old_repeat = $repeat;
543
544 $test_num += $repeat;
545 $default = 0;
546 $repeat = 1;
547 } else {
548 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400549 }
550
Steven Rostedta9f84422011-10-17 11:06:29 -0400551 # If SKIP is anywhere in the line, the command will be skipped
552 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400553 $skip = 1;
554 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400555 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400556 $skip = 0;
557 }
558
Steven Rostedta9f84422011-10-17 11:06:29 -0400559 if ($rest =~ s/\sELSE\b//) {
560 if (!$if) {
561 die "$name: $.: ELSE found with out matching IF section\n$_";
562 }
563 $if = 0;
564
565 if ($if_set) {
566 $skip = 1;
567 } else {
568 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400569 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400570 }
571
Steven Rostedta9f84422011-10-17 11:06:29 -0400572 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400573 if (process_if($name, $1)) {
574 $if_set = 1;
575 } else {
576 $skip = 1;
577 }
578 $if = 1;
579 } else {
580 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400581 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400582 }
583
Steven Rostedta9f84422011-10-17 11:06:29 -0400584 if (!$skip) {
585 if ($type eq "TEST_START") {
586 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
587 $repeat = $1;
588 $repeat_tests{"$test_num"} = $repeat;
589 }
590 } elsif ($rest =~ s/\sOVERRIDE\b//) {
591 # DEFAULT only
592 $override = 1;
593 # Clear previous overrides
594 %overrides = ();
595 }
596 }
597
598 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400599 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400600 }
601
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400602 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400603 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400604 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400605 }
606
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400607 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400608 if (!$if) {
609 die "$name: $.: ELSE found with out matching IF section\n$_";
610 }
611 $rest = $1;
612 if ($if_set) {
613 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400614 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400615 } else {
616 $skip = 0;
617
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400618 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400619 # May be a ELSE IF section.
620 if (!process_if($name, $1)) {
621 $skip = 1;
622 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400623 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400624 } else {
625 $if = 0;
626 }
627 }
628
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400629 if ($rest !~ /^\s*$/) {
630 die "$name: $.: Gargbage found after DEFAULTS\n$_";
631 }
632
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400633 } elsif (/^\s*INCLUDE\s+(\S+)/) {
634
635 next if ($skip);
636
637 if (!$default) {
638 die "$name: $.: INCLUDE can only be done in default sections\n$_";
639 }
640
641 my $file = process_variables($1);
642
643 if ($file !~ m,^/,) {
644 # check the path of the config file first
645 if ($config =~ m,(.*)/,) {
646 if (-f "$1/$file") {
647 $file = "$1/$file";
648 }
649 }
650 }
651
652 if ( ! -r $file ) {
653 die "$name: $.: Can't read file $file\n$_";
654 }
655
656 if (__read_config($file, \$test_num)) {
657 $test_case = 1;
658 }
659
Steven Rostedta57419b2010-11-02 15:13:54 -0400660 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
661
662 next if ($skip);
663
Steven Rostedt2545eb62010-11-02 15:01:32 -0400664 my $lvalue = $1;
665 my $rvalue = $2;
666
Steven Rostedta57419b2010-11-02 15:13:54 -0400667 if (!$default &&
668 ($lvalue eq "NUM_TESTS" ||
669 $lvalue eq "LOG_FILE" ||
670 $lvalue eq "CLEAR_LOG")) {
671 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400672 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400673
674 if ($lvalue eq "NUM_TESTS") {
675 if ($test_num) {
676 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
677 }
678 if (!$default) {
679 die "$name: $.: NUM_TESTS must be set in default section\n";
680 }
681 $num_tests_set = 1;
682 }
683
684 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400685 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400686 } else {
687 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400688 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400689
690 if ($repeat > 1) {
691 $repeats{$val} = $repeat;
692 }
693 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400694 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
695 next if ($skip);
696
697 my $lvalue = $1;
698 my $rvalue = $2;
699
700 # process config variables.
701 # Config variables are only active while reading the
702 # config and can be defined anywhere. They also ignore
703 # TEST_START and DEFAULTS, but are skipped if they are in
704 # on of these sections that have SKIP defined.
705 # The save variable can be
706 # defined multiple times and the new one simply overrides
707 # the prevous one.
708 set_variable($lvalue, $rvalue);
709
Steven Rostedta57419b2010-11-02 15:13:54 -0400710 } else {
711 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400712 }
713 }
714
Steven Rostedta57419b2010-11-02 15:13:54 -0400715 if ($test_num) {
716 $test_num += $repeat - 1;
717 $opt{"NUM_TESTS"} = $test_num;
718 }
719
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400720 close($in);
721
722 $$current_test_num = $test_num;
723
724 return $test_case;
725}
726
727sub read_config {
728 my ($config) = @_;
729
730 my $test_case;
731 my $test_num = 0;
732
733 $test_case = __read_config $config, \$test_num;
734
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500735 # make sure we have all mandatory configs
736 get_ktest_configs;
737
Steven Rostedt0df213c2011-06-14 20:51:37 -0400738 # was a test specified?
739 if (!$test_case) {
740 print "No test case specified.\n";
741 print "What test case would you like to run?\n";
742 my $ans = <STDIN>;
743 chomp $ans;
744 $default{"TEST_TYPE"} = $ans;
745 }
746
Steven Rostedta75fece2010-11-02 14:58:27 -0400747 # set any defaults
748
749 foreach my $default (keys %default) {
750 if (!defined($opt{$default})) {
751 $opt{$default} = $default{$default};
752 }
753 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400754}
755
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400756sub __eval_option {
757 my ($option, $i) = @_;
758
759 # Add space to evaluate the character before $
760 $option = " $option";
761 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530762 my $repeated = 0;
763 my $parent = 0;
764
765 foreach my $test (keys %repeat_tests) {
766 if ($i >= $test &&
767 $i < $test + $repeat_tests{$test}) {
768
769 $repeated = 1;
770 $parent = $test;
771 last;
772 }
773 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400774
775 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
776 my $start = $1;
777 my $var = $2;
778 my $end = $3;
779
780 # Append beginning of line
781 $retval = "$retval$start";
782
783 # If the iteration option OPT[$i] exists, then use that.
784 # otherwise see if the default OPT (without [$i]) exists.
785
786 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530787 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400788
789 if (defined($opt{$o})) {
790 $o = $opt{$o};
791 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530792 } elsif ($repeated && defined($opt{$parento})) {
793 $o = $opt{$parento};
794 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400795 } elsif (defined($opt{$var})) {
796 $o = $opt{$var};
797 $retval = "$retval$o";
798 } else {
799 $retval = "$retval\$\{$var\}";
800 }
801
802 $option = $end;
803 }
804
805 $retval = "$retval$option";
806
807 $retval =~ s/^ //;
808
809 return $retval;
810}
811
812sub eval_option {
813 my ($option, $i) = @_;
814
815 my $prev = "";
816
817 # Since an option can evaluate to another option,
818 # keep iterating until we do not evaluate any more
819 # options.
820 my $r = 0;
821 while ($prev ne $option) {
822 # Check for recursive evaluations.
823 # 100 deep should be more than enough.
824 if ($r++ > 100) {
825 die "Over 100 evaluations accurred with $option\n" .
826 "Check for recursive variables\n";
827 }
828 $prev = $option;
829 $option = __eval_option($option, $i);
830 }
831
832 return $option;
833}
834
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500835sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400836 if (defined($opt{"LOG_FILE"})) {
837 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
838 print OUT @_;
839 close(OUT);
840 }
841}
842
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500843sub logit {
844 if (defined($opt{"LOG_FILE"})) {
845 _logit @_;
846 } else {
847 print @_;
848 }
849}
850
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400851sub doprint {
852 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500853 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400854}
855
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400856sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200857sub start_monitor;
858sub end_monitor;
859sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400860
861sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200862 my ($time) = @_;
863
Steven Rostedt2b803362011-09-30 18:00:23 -0400864 if (defined($time)) {
865 start_monitor;
866 # flush out current monitor
867 # May contain the reboot success line
868 wait_for_monitor 1;
869 }
870
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400871 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400872 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400873 if (defined($powercycle_after_reboot)) {
874 sleep $powercycle_after_reboot;
875 run_command "$power_cycle";
876 }
877 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400878 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400879 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400880 }
Andrew Jones2728be42011-08-12 15:32:05 +0200881
882 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400883 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200884 end_monitor;
885 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400886}
887
Steven Rostedt576f6272010-11-02 14:58:38 -0400888sub do_not_reboot {
889 my $i = $iteration;
890
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400891 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400892 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
893 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
894}
895
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400896sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400897 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400898
Steven Rostedt576f6272010-11-02 14:58:38 -0400899 my $i = $iteration;
900
901 if ($reboot_on_error && !do_not_reboot) {
902
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400903 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400904 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400905
Steven Rostedta75fece2010-11-02 14:58:27 -0400906 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400907 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400908 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400909 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400910
Steven Rostedtf80802c2011-03-07 13:18:47 -0500911 if (defined($opt{"LOG_FILE"})) {
912 print " See $opt{LOG_FILE} for more info.\n";
913 }
914
Steven Rostedt576f6272010-11-02 14:58:38 -0400915 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400916}
917
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400918sub open_console {
919 my ($fp) = @_;
920
921 my $flags;
922
Steven Rostedta75fece2010-11-02 14:58:27 -0400923 my $pid = open($fp, "$console|") or
924 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400925
926 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400927 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400928 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400929 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400930
931 return $pid;
932}
933
934sub close_console {
935 my ($fp, $pid) = @_;
936
937 doprint "kill child process $pid\n";
938 kill 2, $pid;
939
940 print "closing!\n";
941 close($fp);
942}
943
944sub start_monitor {
945 if ($monitor_cnt++) {
946 return;
947 }
948 $monitor_fp = \*MONFD;
949 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400950
951 return;
952
953 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400954}
955
956sub end_monitor {
957 if (--$monitor_cnt) {
958 return;
959 }
960 close_console($monitor_fp, $monitor_pid);
961}
962
963sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -0400964 my ($time, $stop) = @_;
965 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400966 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -0400967 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400968
Steven Rostedta75fece2010-11-02 14:58:27 -0400969 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400970
971 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -0400972 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400973 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -0400974 last if (!defined($line));
975 print "$line";
976 $full_line .= $line;
977
978 if (defined($stop) && $full_line =~ /$stop/) {
979 doprint "wait for monitor detected $stop\n";
980 $booted = 1;
981 }
982
983 if ($line =~ /\n/) {
984 $full_line = "";
985 }
986 }
Steven Rostedta75fece2010-11-02 14:58:27 -0400987 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400988}
989
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530990sub save_logs {
991 my ($result, $basedir) = @_;
992 my @t = localtime;
993 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
994 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
995
996 my $type = $build_type;
997 if ($type =~ /useconfig/) {
998 $type = "useconfig";
999 }
1000
1001 my $dir = "$machine-$test_type-$type-$result-$date";
1002
1003 $dir = "$basedir/$dir";
1004
1005 if (!-d $dir) {
1006 mkpath($dir) or
1007 die "can't create $dir";
1008 }
1009
1010 my %files = (
1011 "config" => $output_config,
1012 "buildlog" => $buildlog,
1013 "dmesg" => $dmesg,
1014 "testlog" => $testlog,
1015 );
1016
1017 while (my ($name, $source) = each(%files)) {
1018 if (-f "$source") {
1019 cp "$source", "$dir/$name" or
1020 die "failed to copy $source";
1021 }
1022 }
1023
1024 doprint "*** Saved info to $dir ***\n";
1025}
1026
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001027sub fail {
1028
Steven Rostedta75fece2010-11-02 14:58:27 -04001029 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001030 dodie @_;
1031 }
1032
Steven Rostedta75fece2010-11-02 14:58:27 -04001033 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001034
Steven Rostedt576f6272010-11-02 14:58:38 -04001035 my $i = $iteration;
1036
Steven Rostedta75fece2010-11-02 14:58:27 -04001037 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001038 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001039 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001040 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001041 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001042
Steven Rostedt9064af52011-06-13 10:38:48 -04001043 my $name = "";
1044
1045 if (defined($test_name)) {
1046 $name = " ($test_name)";
1047 }
1048
Steven Rostedt576f6272010-11-02 14:58:38 -04001049 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1050 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001051 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001052 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1053 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001054
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301055 if (defined($store_failures)) {
1056 save_logs "fail", $store_failures;
1057 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001058
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001059 return 1;
1060}
1061
Steven Rostedt2545eb62010-11-02 15:01:32 -04001062sub run_command {
1063 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001064 my $dolog = 0;
1065 my $dord = 0;
1066 my $pid;
1067
Steven Rostedte48c5292010-11-02 14:35:37 -04001068 $command =~ s/\$SSH_USER/$ssh_user/g;
1069 $command =~ s/\$MACHINE/$machine/g;
1070
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001071 doprint("$command ... ");
1072
1073 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001074 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001075
1076 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001077 open(LOG, ">>$opt{LOG_FILE}") or
1078 dodie "failed to write to log";
1079 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001080 }
1081
1082 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001083 open (RD, ">$redirect") or
1084 dodie "failed to write to redirect $redirect";
1085 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001086 }
1087
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001088 while (<CMD>) {
1089 print LOG if ($dolog);
1090 print RD if ($dord);
1091 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001092
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001093 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001094 my $failed = $?;
1095
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001096 close(CMD);
1097 close(LOG) if ($dolog);
1098 close(RD) if ($dord);
1099
Steven Rostedt2545eb62010-11-02 15:01:32 -04001100 if ($failed) {
1101 doprint "FAILED!\n";
1102 } else {
1103 doprint "SUCCESS\n";
1104 }
1105
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001106 return !$failed;
1107}
1108
Steven Rostedte48c5292010-11-02 14:35:37 -04001109sub run_ssh {
1110 my ($cmd) = @_;
1111 my $cp_exec = $ssh_exec;
1112
1113 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1114 return run_command "$cp_exec";
1115}
1116
1117sub run_scp {
1118 my ($src, $dst) = @_;
1119 my $cp_scp = $scp_to_target;
1120
1121 $cp_scp =~ s/\$SRC_FILE/$src/g;
1122 $cp_scp =~ s/\$DST_FILE/$dst/g;
1123
1124 return run_command "$cp_scp";
1125}
1126
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001127sub get_grub_index {
1128
Steven Rostedta75fece2010-11-02 14:58:27 -04001129 if ($reboot_type ne "grub") {
1130 return;
1131 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001132 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001133
1134 doprint "Find grub menu ... ";
1135 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001136
1137 my $ssh_grub = $ssh_exec;
1138 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1139
1140 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001141 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001142
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001143 my $found = 0;
1144
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001145 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001146 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001147 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001148 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001149 last;
1150 } elsif (/^\s*title\s/) {
1151 $grub_number++;
1152 }
1153 }
1154 close(IN);
1155
Steven Rostedta75fece2010-11-02 14:58:27 -04001156 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001157 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001158 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001159}
1160
Steven Rostedt2545eb62010-11-02 15:01:32 -04001161sub wait_for_input
1162{
1163 my ($fp, $time) = @_;
1164 my $rin;
1165 my $ready;
1166 my $line;
1167 my $ch;
1168
1169 if (!defined($time)) {
1170 $time = $timeout;
1171 }
1172
1173 $rin = '';
1174 vec($rin, fileno($fp), 1) = 1;
1175 $ready = select($rin, undef, undef, $time);
1176
1177 $line = "";
1178
1179 # try to read one char at a time
1180 while (sysread $fp, $ch, 1) {
1181 $line .= $ch;
1182 last if ($ch eq "\n");
1183 }
1184
1185 if (!length($line)) {
1186 return undef;
1187 }
1188
1189 return $line;
1190}
1191
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001192sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001193 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001194 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1195 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001196 return;
1197 }
1198
1199 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001200}
1201
Steven Rostedta57419b2010-11-02 15:13:54 -04001202sub get_sha1 {
1203 my ($commit) = @_;
1204
1205 doprint "git rev-list --max-count=1 $commit ... ";
1206 my $sha1 = `git rev-list --max-count=1 $commit`;
1207 my $ret = $?;
1208
1209 logit $sha1;
1210
1211 if ($ret) {
1212 doprint "FAILED\n";
1213 dodie "Failed to get git $commit";
1214 }
1215
1216 print "SUCCESS\n";
1217
1218 chomp $sha1;
1219
1220 return $sha1;
1221}
1222
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001223sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001224 my $booted = 0;
1225 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001226 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001227 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001228
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001229 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001230
1231 my $line;
1232 my $full_line = "";
1233
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001234 open(DMESG, "> $dmesg") or
1235 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001236
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001237 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001238
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001239 my $success_start;
1240 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001241 my $monitor_start = time;
1242 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001243 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001244
Steven Rostedt2d01b262011-03-08 09:47:54 -05001245 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001246
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001247 if ($bug && defined($stop_after_failure) &&
1248 $stop_after_failure >= 0) {
1249 my $time = $stop_after_failure - (time - $failure_start);
1250 $line = wait_for_input($monitor_fp, $time);
1251 if (!defined($line)) {
1252 doprint "bug timed out after $booted_timeout seconds\n";
1253 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1254 last;
1255 }
1256 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001257 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001258 if (!defined($line)) {
1259 my $s = $booted_timeout == 1 ? "" : "s";
1260 doprint "Successful boot found: break after $booted_timeout second$s\n";
1261 last;
1262 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001263 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001264 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001265 if (!defined($line)) {
1266 my $s = $timeout == 1 ? "" : "s";
1267 doprint "Timed out after $timeout second$s\n";
1268 last;
1269 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001270 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001271
Steven Rostedt2545eb62010-11-02 15:01:32 -04001272 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001273 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001274
1275 # we are not guaranteed to get a full line
1276 $full_line .= $line;
1277
Steven Rostedta75fece2010-11-02 14:58:27 -04001278 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001279 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001280 $success_start = time;
1281 }
1282
1283 if ($booted && defined($stop_after_success) &&
1284 $stop_after_success >= 0) {
1285 my $now = time;
1286 if ($now - $success_start >= $stop_after_success) {
1287 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1288 last;
1289 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001290 }
1291
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001292 if ($full_line =~ /\[ backtrace testing \]/) {
1293 $skip_call_trace = 1;
1294 }
1295
Steven Rostedt2545eb62010-11-02 15:01:32 -04001296 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001297 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001298 $bug = 1;
1299 $failure_start = time;
1300 }
1301 }
1302
1303 if ($bug && defined($stop_after_failure) &&
1304 $stop_after_failure >= 0) {
1305 my $now = time;
1306 if ($now - $failure_start >= $stop_after_failure) {
1307 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1308 last;
1309 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001310 }
1311
1312 if ($full_line =~ /\[ end of backtrace testing \]/) {
1313 $skip_call_trace = 0;
1314 }
1315
1316 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001317 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001318 $bug = 1;
1319 }
1320
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001321 # Detect triple faults by testing the banner
1322 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1323 if ($1 eq $version) {
1324 $version_found = 1;
1325 } elsif ($version_found && $detect_triplefault) {
1326 # We already booted into the kernel we are testing,
1327 # but now we booted into another kernel?
1328 # Consider this a triple fault.
1329 doprint "Aleady booted in Linux kernel $version, but now\n";
1330 doprint "we booted into Linux kernel $1.\n";
1331 doprint "Assuming that this is a triple fault.\n";
1332 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1333 last;
1334 }
1335 }
1336
Steven Rostedt2545eb62010-11-02 15:01:32 -04001337 if ($line =~ /\n/) {
1338 $full_line = "";
1339 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001340
1341 if ($stop_test_after > 0 && !$booted && !$bug) {
1342 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001343 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001344 $done = 1;
1345 }
1346 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001347 }
1348
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001349 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001350
Steven Rostedt2545eb62010-11-02 15:01:32 -04001351 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001352 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001353 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001354 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001355
Steven Rostedta75fece2010-11-02 14:58:27 -04001356 if (!$booted) {
1357 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001358 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001359 }
1360
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001361 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001362}
1363
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001364sub do_post_install {
1365
1366 return if (!defined($post_install));
1367
1368 my $cp_post_install = $post_install;
1369 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1370 run_command "$cp_post_install" or
1371 dodie "Failed to run post install";
1372}
1373
Steven Rostedt2545eb62010-11-02 15:01:32 -04001374sub install {
1375
Steven Rostedte0a87422011-09-30 17:50:48 -04001376 return if ($no_install);
1377
Steven Rostedte48c5292010-11-02 14:35:37 -04001378 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001379 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001380
1381 my $install_mods = 0;
1382
1383 # should we process modules?
1384 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001385 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001386 while (<IN>) {
1387 if (/CONFIG_MODULES(=y)?/) {
1388 $install_mods = 1 if (defined($1));
1389 last;
1390 }
1391 }
1392 close(IN);
1393
1394 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001395 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001396 doprint "No modules needed\n";
1397 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001398 }
1399
Steven Rostedta75fece2010-11-02 14:58:27 -04001400 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001401 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001402
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001403 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001404 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001405
Steven Rostedte48c5292010-11-02 14:35:37 -04001406 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001407 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001408
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001409 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001410 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001411 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001412
Steven Rostedte48c5292010-11-02 14:35:37 -04001413 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001414 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001415
Steven Rostedta75fece2010-11-02 14:58:27 -04001416 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001417
Steven Rostedte7b13442011-06-14 20:44:36 -04001418 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001419 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001420
Steven Rostedte48c5292010-11-02 14:35:37 -04001421 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001422
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001423 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001424}
1425
Steven Rostedtddf607e2011-06-14 20:49:13 -04001426sub get_version {
1427 # get the release name
1428 doprint "$make kernelrelease ... ";
1429 $version = `$make kernelrelease | tail -1`;
1430 chomp($version);
1431 doprint "$version\n";
1432}
1433
1434sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001435 # Make sure the stable kernel has finished booting
1436 start_monitor;
1437 wait_for_monitor 5;
1438 end_monitor;
1439
Steven Rostedtddf607e2011-06-14 20:49:13 -04001440 get_grub_index;
1441 get_version;
1442 install;
1443
1444 start_monitor;
1445 return monitor;
1446}
1447
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001448sub check_buildlog {
1449 my ($patch) = @_;
1450
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001451 my @files = `git show $patch | diffstat -l`;
1452
1453 open(IN, "git show $patch |") or
1454 dodie "failed to show $patch";
1455 while (<IN>) {
1456 if (m,^--- a/(.*),) {
1457 chomp $1;
1458 $files[$#files] = $1;
1459 }
1460 }
1461 close(IN);
1462
1463 open(IN, $buildlog) or dodie "Can't open $buildlog";
1464 while (<IN>) {
1465 if (/^\s*(.*?):.*(warning|error)/) {
1466 my $err = $1;
1467 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001468 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001469 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001470 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001471 }
1472 }
1473 }
1474 }
1475 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001476
1477 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001478}
1479
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001480sub apply_min_config {
1481 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001482
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001483 # Read the config file and remove anything that
1484 # is in the force_config hash (from minconfig and others)
1485 # then add the force config back.
1486
1487 doprint "Applying minimum configurations into $output_config.new\n";
1488
1489 open (OUT, ">$outconfig") or
1490 dodie "Can't create $outconfig";
1491
1492 if (-f $output_config) {
1493 open (IN, $output_config) or
1494 dodie "Failed to open $output_config";
1495 while (<IN>) {
1496 if (/^(# )?(CONFIG_[^\s=]*)/) {
1497 next if (defined($force_config{$2}));
1498 }
1499 print OUT;
1500 }
1501 close IN;
1502 }
1503 foreach my $config (keys %force_config) {
1504 print OUT "$force_config{$config}\n";
1505 }
1506 close OUT;
1507
1508 run_command "mv $outconfig $output_config";
1509}
1510
1511sub make_oldconfig {
1512
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001513 my @force_list = keys %force_config;
1514
1515 if ($#force_list >= 0) {
1516 apply_min_config;
1517 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001518
1519 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001520 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1521 # try a yes '' | oldconfig
1522 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001523 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001524 dodie "failed make config oldconfig";
1525 }
1526}
1527
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001528# read a config file and use this to force new configs.
1529sub load_force_config {
1530 my ($config) = @_;
1531
1532 open(IN, $config) or
1533 dodie "failed to read $config";
1534 while (<IN>) {
1535 chomp;
1536 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1537 $force_config{$1} = $_;
1538 } elsif (/^# (CONFIG_\S*) is not set/) {
1539 $force_config{$1} = $_;
1540 }
1541 }
1542 close IN;
1543}
1544
Steven Rostedt2545eb62010-11-02 15:01:32 -04001545sub build {
1546 my ($type) = @_;
1547
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001548 unlink $buildlog;
1549
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001550 # Failed builds should not reboot the target
1551 my $save_no_reboot = $no_reboot;
1552 $no_reboot = 1;
1553
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001554 if (defined($pre_build)) {
1555 my $ret = run_command $pre_build;
1556 if (!$ret && defined($pre_build_die) &&
1557 $pre_build_die) {
1558 dodie "failed to pre_build\n";
1559 }
1560 }
1561
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001562 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001563 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001564 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001565
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001566 $type = "oldconfig";
1567 }
1568
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001569 # old config can ask questions
1570 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001571 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001572
1573 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001574 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001575
Andrew Jones13488232011-08-12 15:32:04 +02001576 if (!$noclean) {
1577 run_command "mv $output_config $outputdir/config_temp" or
1578 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001579
Andrew Jones13488232011-08-12 15:32:04 +02001580 run_command "$make mrproper" or dodie "make mrproper";
1581
1582 run_command "mv $outputdir/config_temp $output_config" or
1583 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001584 }
1585
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001586 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001587 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001588 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001589 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001590 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001591
1592 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001593 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1594 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001595 close(OUT);
1596
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001597 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001598 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001599 }
1600
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001601 if ($type ne "oldnoconfig") {
1602 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001603 dodie "failed make config";
1604 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001605 # Run old config regardless, to enforce min configurations
1606 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001607
Steven Rostedta75fece2010-11-02 14:58:27 -04001608 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001609 my $build_ret = run_command "$make $build_options";
1610 undef $redirect;
1611
1612 if (defined($post_build)) {
1613 my $ret = run_command $post_build;
1614 if (!$ret && defined($post_build_die) &&
1615 $post_build_die) {
1616 dodie "failed to post_build\n";
1617 }
1618 }
1619
1620 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001621 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001622 if ($in_bisect) {
1623 $no_reboot = $save_no_reboot;
1624 return 0;
1625 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001626 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001627 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001628
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001629 $no_reboot = $save_no_reboot;
1630
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001631 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001632}
1633
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001634sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001635 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001636 if (defined($poweroff_after_halt)) {
1637 sleep $poweroff_after_halt;
1638 run_command "$power_off";
1639 }
1640 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001641 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001642 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001643 }
1644}
1645
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001646sub success {
1647 my ($i) = @_;
1648
Steven Rostedte48c5292010-11-02 14:35:37 -04001649 $successes++;
1650
Steven Rostedt9064af52011-06-13 10:38:48 -04001651 my $name = "";
1652
1653 if (defined($test_name)) {
1654 $name = " ($test_name)";
1655 }
1656
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001657 doprint "\n\n*******************************************\n";
1658 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001659 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001660 doprint "*******************************************\n";
1661 doprint "*******************************************\n";
1662
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301663 if (defined($store_successes)) {
1664 save_logs "success", $store_successes;
1665 }
1666
Steven Rostedt576f6272010-11-02 14:58:38 -04001667 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001668 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001669 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001670 }
1671}
1672
Steven Rostedtc960bb92011-03-08 09:22:39 -05001673sub answer_bisect {
1674 for (;;) {
1675 doprint "Pass or fail? [p/f]";
1676 my $ans = <STDIN>;
1677 chomp $ans;
1678 if ($ans eq "p" || $ans eq "P") {
1679 return 1;
1680 } elsif ($ans eq "f" || $ans eq "F") {
1681 return 0;
1682 } else {
1683 print "Please answer 'P' or 'F'\n";
1684 }
1685 }
1686}
1687
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001688sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001689 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001690
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001691 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001692 $reboot_on_error = 0;
1693 $poweroff_on_error = 0;
1694 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001695
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301696 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001697 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301698 undef $redirect;
1699
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001700 exit $failed;
1701}
1702
1703my $child_done;
1704
1705sub child_finished {
1706 $child_done = 1;
1707}
1708
1709sub do_run_test {
1710 my $child_pid;
1711 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001712 my $line;
1713 my $full_line;
1714 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001715
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001716 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001717
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001718 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001719
1720 $child_done = 0;
1721
1722 $SIG{CHLD} = qw(child_finished);
1723
1724 $child_pid = fork;
1725
1726 child_run_test if (!$child_pid);
1727
1728 $full_line = "";
1729
1730 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001731 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001732 if (defined($line)) {
1733
1734 # we are not guaranteed to get a full line
1735 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001736 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001737
1738 if ($full_line =~ /call trace:/i) {
1739 $bug = 1;
1740 }
1741
1742 if ($full_line =~ /Kernel panic -/) {
1743 $bug = 1;
1744 }
1745
1746 if ($line =~ /\n/) {
1747 $full_line = "";
1748 }
1749 }
1750 } while (!$child_done && !$bug);
1751
1752 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001753 my $failure_start = time;
1754 my $now;
1755 do {
1756 $line = wait_for_input($monitor_fp, 1);
1757 if (defined($line)) {
1758 doprint $line;
1759 }
1760 $now = time;
1761 if ($now - $failure_start >= $stop_after_failure) {
1762 last;
1763 }
1764 } while (defined($line));
1765
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001766 doprint "Detected kernel crash!\n";
1767 # kill the child with extreme prejudice
1768 kill 9, $child_pid;
1769 }
1770
1771 waitpid $child_pid, 0;
1772 $child_exit = $?;
1773
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001774 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001775 return 0 if $in_bisect;
1776 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001777 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001778 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001779}
1780
Steven Rostedta75fece2010-11-02 14:58:27 -04001781sub run_git_bisect {
1782 my ($command) = @_;
1783
1784 doprint "$command ... ";
1785
1786 my $output = `$command 2>&1`;
1787 my $ret = $?;
1788
1789 logit $output;
1790
1791 if ($ret) {
1792 doprint "FAILED\n";
1793 dodie "Failed to git bisect";
1794 }
1795
1796 doprint "SUCCESS\n";
1797 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1798 doprint "$1 [$2]\n";
1799 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1800 $bisect_bad = $1;
1801 doprint "Found bad commit... $1\n";
1802 return 0;
1803 } else {
1804 # we already logged it, just print it now.
1805 print $output;
1806 }
1807
1808 return 1;
1809}
1810
Steven Rostedtc23dca72011-03-08 09:26:31 -05001811sub bisect_reboot {
1812 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001813 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001814}
1815
1816# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001817sub run_bisect_test {
1818 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001819
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001820 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001821 my $result;
1822 my $output;
1823 my $ret;
1824
Steven Rostedt0a05c762010-11-08 11:14:10 -05001825 $in_bisect = 1;
1826
1827 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001828
1829 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001830 if ($failed && $bisect_skip) {
1831 $in_bisect = 0;
1832 return -1;
1833 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001834 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001835
1836 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001837 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001838
1839 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001840 if ($failed && $bisect_skip) {
1841 end_monitor;
1842 bisect_reboot;
1843 $in_bisect = 0;
1844 return -1;
1845 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001846 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001847
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001848 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001849 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001850 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001851 }
1852
1853 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001854 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001855 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001856 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001857 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001858
1859 # reboot the box to a kernel we can ssh to
1860 if ($type ne "build") {
1861 bisect_reboot;
1862 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001863 $in_bisect = 0;
1864
1865 return $result;
1866}
1867
1868sub run_bisect {
1869 my ($type) = @_;
1870 my $buildtype = "oldconfig";
1871
1872 # We should have a minconfig to use?
1873 if (defined($minconfig)) {
1874 $buildtype = "useconfig:$minconfig";
1875 }
1876
1877 my $ret = run_bisect_test $type, $buildtype;
1878
Steven Rostedtc960bb92011-03-08 09:22:39 -05001879 if ($bisect_manual) {
1880 $ret = answer_bisect;
1881 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001882
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001883 # Are we looking for where it worked, not failed?
1884 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001885 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001886 }
1887
Steven Rostedtc23dca72011-03-08 09:26:31 -05001888 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001889 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001890 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001891 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001892 } elsif ($bisect_skip) {
1893 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1894 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001895 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001896}
1897
1898sub bisect {
1899 my ($i) = @_;
1900
1901 my $result;
1902
1903 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1904 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1905 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1906
1907 my $good = $opt{"BISECT_GOOD[$i]"};
1908 my $bad = $opt{"BISECT_BAD[$i]"};
1909 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001910 my $start = $opt{"BISECT_START[$i]"};
1911 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001912 my $start_files = $opt{"BISECT_FILES[$i]"};
1913
1914 if (defined($start_files)) {
1915 $start_files = " -- " . $start_files;
1916 } else {
1917 $start_files = "";
1918 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001919
Steven Rostedta57419b2010-11-02 15:13:54 -04001920 # convert to true sha1's
1921 $good = get_sha1($good);
1922 $bad = get_sha1($bad);
1923
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001924 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1925 $opt{"BISECT_REVERSE[$i]"} == 1) {
1926 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1927 $reverse_bisect = 1;
1928 } else {
1929 $reverse_bisect = 0;
1930 }
1931
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001932 # Can't have a test without having a test to run
1933 if ($type eq "test" && !defined($run_test)) {
1934 $type = "boot";
1935 }
1936
Steven Rostedta75fece2010-11-02 14:58:27 -04001937 my $check = $opt{"BISECT_CHECK[$i]"};
1938 if (defined($check) && $check ne "0") {
1939
1940 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001941 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001942
1943 if ($check ne "good") {
1944 doprint "TESTING BISECT BAD [$bad]\n";
1945 run_command "git checkout $bad" or
1946 die "Failed to checkout $bad";
1947
1948 $result = run_bisect $type;
1949
1950 if ($result ne "bad") {
1951 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1952 }
1953 }
1954
1955 if ($check ne "bad") {
1956 doprint "TESTING BISECT GOOD [$good]\n";
1957 run_command "git checkout $good" or
1958 die "Failed to checkout $good";
1959
1960 $result = run_bisect $type;
1961
1962 if ($result ne "good") {
1963 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1964 }
1965 }
1966
1967 # checkout where we started
1968 run_command "git checkout $head" or
1969 die "Failed to checkout $head";
1970 }
1971
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001972 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001973 dodie "could not start bisect";
1974
1975 run_command "git bisect good $good" or
1976 dodie "could not set bisect good to $good";
1977
1978 run_git_bisect "git bisect bad $bad" or
1979 dodie "could not set bisect bad to $bad";
1980
1981 if (defined($replay)) {
1982 run_command "git bisect replay $replay" or
1983 dodie "failed to run replay";
1984 }
1985
1986 if (defined($start)) {
1987 run_command "git checkout $start" or
1988 dodie "failed to checkout $start";
1989 }
1990
1991 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001992 do {
1993 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001994 $test = run_git_bisect "git bisect $result";
1995 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001996
1997 run_command "git bisect log" or
1998 dodie "could not capture git bisect log";
1999
2000 run_command "git bisect reset" or
2001 dodie "could not reset git bisect";
2002
2003 doprint "Bad commit was [$bisect_bad]\n";
2004
Steven Rostedt0a05c762010-11-08 11:14:10 -05002005 success $i;
2006}
2007
2008my %config_ignore;
2009my %config_set;
2010
2011my %config_list;
2012my %null_config;
2013
2014my %dependency;
2015
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002016sub assign_configs {
2017 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002018
2019 open (IN, $config)
2020 or dodie "Failed to read $config";
2021
2022 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002023 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002024 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002025 }
2026 }
2027
2028 close(IN);
2029}
2030
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002031sub process_config_ignore {
2032 my ($config) = @_;
2033
2034 assign_configs \%config_ignore, $config;
2035}
2036
Steven Rostedt0a05c762010-11-08 11:14:10 -05002037sub read_current_config {
2038 my ($config_ref) = @_;
2039
2040 %{$config_ref} = ();
2041 undef %{$config_ref};
2042
2043 my @key = keys %{$config_ref};
2044 if ($#key >= 0) {
2045 print "did not delete!\n";
2046 exit;
2047 }
2048 open (IN, "$output_config");
2049
2050 while (<IN>) {
2051 if (/^(CONFIG\S+)=(.*)/) {
2052 ${$config_ref}{$1} = $2;
2053 }
2054 }
2055 close(IN);
2056}
2057
2058sub get_dependencies {
2059 my ($config) = @_;
2060
2061 my $arr = $dependency{$config};
2062 if (!defined($arr)) {
2063 return ();
2064 }
2065
2066 my @deps = @{$arr};
2067
2068 foreach my $dep (@{$arr}) {
2069 print "ADD DEP $dep\n";
2070 @deps = (@deps, get_dependencies $dep);
2071 }
2072
2073 return @deps;
2074}
2075
2076sub create_config {
2077 my @configs = @_;
2078
2079 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2080
2081 foreach my $config (@configs) {
2082 print OUT "$config_set{$config}\n";
2083 my @deps = get_dependencies $config;
2084 foreach my $dep (@deps) {
2085 print OUT "$config_set{$dep}\n";
2086 }
2087 }
2088
2089 foreach my $config (keys %config_ignore) {
2090 print OUT "$config_ignore{$config}\n";
2091 }
2092 close(OUT);
2093
2094# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002095 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002096}
2097
2098sub compare_configs {
2099 my (%a, %b) = @_;
2100
2101 foreach my $item (keys %a) {
2102 if (!defined($b{$item})) {
2103 print "diff $item\n";
2104 return 1;
2105 }
2106 delete $b{$item};
2107 }
2108
2109 my @keys = keys %b;
2110 if ($#keys) {
2111 print "diff2 $keys[0]\n";
2112 }
2113 return -1 if ($#keys >= 0);
2114
2115 return 0;
2116}
2117
2118sub run_config_bisect_test {
2119 my ($type) = @_;
2120
2121 return run_bisect_test $type, "oldconfig";
2122}
2123
2124sub process_passed {
2125 my (%configs) = @_;
2126
2127 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2128 # Passed! All these configs are part of a good compile.
2129 # Add them to the min options.
2130 foreach my $config (keys %configs) {
2131 if (defined($config_list{$config})) {
2132 doprint " removing $config\n";
2133 $config_ignore{$config} = $config_list{$config};
2134 delete $config_list{$config};
2135 }
2136 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002137 doprint "config copied to $outputdir/config_good\n";
2138 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002139}
2140
2141sub process_failed {
2142 my ($config) = @_;
2143
2144 doprint "\n\n***************************************\n";
2145 doprint "Found bad config: $config\n";
2146 doprint "***************************************\n\n";
2147}
2148
2149sub run_config_bisect {
2150
2151 my @start_list = keys %config_list;
2152
2153 if ($#start_list < 0) {
2154 doprint "No more configs to test!!!\n";
2155 return -1;
2156 }
2157
2158 doprint "***** RUN TEST ***\n";
2159 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2160 my $ret;
2161 my %current_config;
2162
2163 my $count = $#start_list + 1;
2164 doprint " $count configs to test\n";
2165
2166 my $half = int($#start_list / 2);
2167
2168 do {
2169 my @tophalf = @start_list[0 .. $half];
2170
2171 create_config @tophalf;
2172 read_current_config \%current_config;
2173
2174 $count = $#tophalf + 1;
2175 doprint "Testing $count configs\n";
2176 my $found = 0;
2177 # make sure we test something
2178 foreach my $config (@tophalf) {
2179 if (defined($current_config{$config})) {
2180 logit " $config\n";
2181 $found = 1;
2182 }
2183 }
2184 if (!$found) {
2185 # try the other half
2186 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002187 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002188 create_config @tophalf;
2189 read_current_config \%current_config;
2190 foreach my $config (@tophalf) {
2191 if (defined($current_config{$config})) {
2192 logit " $config\n";
2193 $found = 1;
2194 }
2195 }
2196 if (!$found) {
2197 doprint "Failed: Can't make new config with current configs\n";
2198 foreach my $config (@start_list) {
2199 doprint " CONFIG: $config\n";
2200 }
2201 return -1;
2202 }
2203 $count = $#tophalf + 1;
2204 doprint "Testing $count configs\n";
2205 }
2206
2207 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002208 if ($bisect_manual) {
2209 $ret = answer_bisect;
2210 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002211 if ($ret) {
2212 process_passed %current_config;
2213 return 0;
2214 }
2215
2216 doprint "This config had a failure.\n";
2217 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002218 doprint "config copied to $outputdir/config_bad\n";
2219 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002220
2221 # A config exists in this group that was bad.
2222 foreach my $config (keys %config_list) {
2223 if (!defined($current_config{$config})) {
2224 doprint " removing $config\n";
2225 delete $config_list{$config};
2226 }
2227 }
2228
2229 @start_list = @tophalf;
2230
2231 if ($#start_list == 0) {
2232 process_failed $start_list[0];
2233 return 1;
2234 }
2235
2236 # remove half the configs we are looking at and see if
2237 # they are good.
2238 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002239 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002240
Steven Rostedtc960bb92011-03-08 09:22:39 -05002241 # we found a single config, try it again unless we are running manually
2242
2243 if ($bisect_manual) {
2244 process_failed $start_list[0];
2245 return 1;
2246 }
2247
Steven Rostedt0a05c762010-11-08 11:14:10 -05002248 my @tophalf = @start_list[0 .. 0];
2249
2250 $ret = run_config_bisect_test $type;
2251 if ($ret) {
2252 process_passed %current_config;
2253 return 0;
2254 }
2255
2256 process_failed $start_list[0];
2257 return 1;
2258}
2259
2260sub config_bisect {
2261 my ($i) = @_;
2262
2263 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2264
2265 my $tmpconfig = "$tmpdir/use_config";
2266
Steven Rostedt30f75da2011-06-13 10:35:35 -04002267 if (defined($config_bisect_good)) {
2268 process_config_ignore $config_bisect_good;
2269 }
2270
Steven Rostedt0a05c762010-11-08 11:14:10 -05002271 # Make the file with the bad config and the min config
2272 if (defined($minconfig)) {
2273 # read the min config for things to ignore
2274 run_command "cp $minconfig $tmpconfig" or
2275 dodie "failed to copy $minconfig to $tmpconfig";
2276 } else {
2277 unlink $tmpconfig;
2278 }
2279
Steven Rostedt0a05c762010-11-08 11:14:10 -05002280 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002281 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002282 process_config_ignore $tmpconfig;
2283 }
2284
2285 # now process the start config
2286 run_command "cp $start_config $output_config" or
2287 dodie "failed to copy $start_config to $output_config";
2288
2289 # read directly what we want to check
2290 my %config_check;
2291 open (IN, $output_config)
2292 or dodie "faied to open $output_config";
2293
2294 while (<IN>) {
2295 if (/^((CONFIG\S*)=.*)/) {
2296 $config_check{$2} = $1;
2297 }
2298 }
2299 close(IN);
2300
Steven Rostedt250bae82011-07-15 22:05:59 -04002301 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002302 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002303
2304 # check to see what we lost (or gained)
2305 open (IN, $output_config)
2306 or dodie "Failed to read $start_config";
2307
2308 my %removed_configs;
2309 my %added_configs;
2310
2311 while (<IN>) {
2312 if (/^((CONFIG\S*)=.*)/) {
2313 # save off all options
2314 $config_set{$2} = $1;
2315 if (defined($config_check{$2})) {
2316 if (defined($config_ignore{$2})) {
2317 $removed_configs{$2} = $1;
2318 } else {
2319 $config_list{$2} = $1;
2320 }
2321 } elsif (!defined($config_ignore{$2})) {
2322 $added_configs{$2} = $1;
2323 $config_list{$2} = $1;
2324 }
2325 }
2326 }
2327 close(IN);
2328
2329 my @confs = keys %removed_configs;
2330 if ($#confs >= 0) {
2331 doprint "Configs overridden by default configs and removed from check:\n";
2332 foreach my $config (@confs) {
2333 doprint " $config\n";
2334 }
2335 }
2336 @confs = keys %added_configs;
2337 if ($#confs >= 0) {
2338 doprint "Configs appearing in make oldconfig and added:\n";
2339 foreach my $config (@confs) {
2340 doprint " $config\n";
2341 }
2342 }
2343
2344 my %config_test;
2345 my $once = 0;
2346
2347 # Sometimes kconfig does weird things. We must make sure
2348 # that the config we autocreate has everything we need
2349 # to test, otherwise we may miss testing configs, or
2350 # may not be able to create a new config.
2351 # Here we create a config with everything set.
2352 create_config (keys %config_list);
2353 read_current_config \%config_test;
2354 foreach my $config (keys %config_list) {
2355 if (!defined($config_test{$config})) {
2356 if (!$once) {
2357 $once = 1;
2358 doprint "Configs not produced by kconfig (will not be checked):\n";
2359 }
2360 doprint " $config\n";
2361 delete $config_list{$config};
2362 }
2363 }
2364 my $ret;
2365 do {
2366 $ret = run_config_bisect;
2367 } while (!$ret);
2368
2369 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002370
2371 success $i;
2372}
2373
Steven Rostedt27d934b2011-05-20 09:18:18 -04002374sub patchcheck_reboot {
2375 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002376 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002377}
2378
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002379sub patchcheck {
2380 my ($i) = @_;
2381
2382 die "PATCHCHECK_START[$i] not defined\n"
2383 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2384 die "PATCHCHECK_TYPE[$i] not defined\n"
2385 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2386
2387 my $start = $opt{"PATCHCHECK_START[$i]"};
2388
2389 my $end = "HEAD";
2390 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2391 $end = $opt{"PATCHCHECK_END[$i]"};
2392 }
2393
Steven Rostedta57419b2010-11-02 15:13:54 -04002394 # Get the true sha1's since we can use things like HEAD~3
2395 $start = get_sha1($start);
2396 $end = get_sha1($end);
2397
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002398 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2399
2400 # Can't have a test without having a test to run
2401 if ($type eq "test" && !defined($run_test)) {
2402 $type = "boot";
2403 }
2404
2405 open (IN, "git log --pretty=oneline $end|") or
2406 dodie "could not get git list";
2407
2408 my @list;
2409
2410 while (<IN>) {
2411 chomp;
2412 $list[$#list+1] = $_;
2413 last if (/^$start/);
2414 }
2415 close(IN);
2416
2417 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002418 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002419 }
2420
2421 # go backwards in the list
2422 @list = reverse @list;
2423
2424 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002425 my %ignored_warnings;
2426
2427 if (defined($ignore_warnings)) {
2428 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2429 $ignored_warnings{$sha1} = 1;
2430 }
2431 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002432
2433 $in_patchcheck = 1;
2434 foreach my $item (@list) {
2435 my $sha1 = $item;
2436 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2437
2438 doprint "\nProcessing commit $item\n\n";
2439
2440 run_command "git checkout $sha1" or
2441 die "Failed to checkout $sha1";
2442
2443 # only clean on the first and last patch
2444 if ($item eq $list[0] ||
2445 $item eq $list[$#list]) {
2446 $noclean = $save_clean;
2447 } else {
2448 $noclean = 1;
2449 }
2450
2451 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002452 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002453 } else {
2454 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002455 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002456 }
2457
Steven Rostedt19902072011-06-14 20:46:25 -04002458
2459 if (!defined($ignored_warnings{$sha1})) {
2460 check_buildlog $sha1 or return 0;
2461 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002462
2463 next if ($type eq "build");
2464
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002465 my $failed = 0;
2466
Steven Rostedtddf607e2011-06-14 20:49:13 -04002467 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002468
2469 if (!$failed && $type ne "boot"){
2470 do_run_test or $failed = 1;
2471 }
2472 end_monitor;
2473 return 0 if ($failed);
2474
Steven Rostedt27d934b2011-05-20 09:18:18 -04002475 patchcheck_reboot;
2476
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002477 }
2478 $in_patchcheck = 0;
2479 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002480
2481 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002482}
2483
Steven Rostedtb9066f62011-07-15 21:25:24 -04002484my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002485my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002486my $iflevel = 0;
2487my @ifdeps;
2488
2489# prevent recursion
2490my %read_kconfigs;
2491
Steven Rostedtac6974c2011-10-04 09:40:17 -04002492sub add_dep {
2493 # $config depends on $dep
2494 my ($config, $dep) = @_;
2495
2496 if (defined($depends{$config})) {
2497 $depends{$config} .= " " . $dep;
2498 } else {
2499 $depends{$config} = $dep;
2500 }
2501
2502 # record the number of configs depending on $dep
2503 if (defined $depcount{$dep}) {
2504 $depcount{$dep}++;
2505 } else {
2506 $depcount{$dep} = 1;
2507 }
2508}
2509
Steven Rostedtb9066f62011-07-15 21:25:24 -04002510# taken from streamline_config.pl
2511sub read_kconfig {
2512 my ($kconfig) = @_;
2513
2514 my $state = "NONE";
2515 my $config;
2516 my @kconfigs;
2517
2518 my $cont = 0;
2519 my $line;
2520
2521
2522 if (! -f $kconfig) {
2523 doprint "file $kconfig does not exist, skipping\n";
2524 return;
2525 }
2526
2527 open(KIN, "$kconfig")
2528 or die "Can't open $kconfig";
2529 while (<KIN>) {
2530 chomp;
2531
2532 # Make sure that lines ending with \ continue
2533 if ($cont) {
2534 $_ = $line . " " . $_;
2535 }
2536
2537 if (s/\\$//) {
2538 $cont = 1;
2539 $line = $_;
2540 next;
2541 }
2542
2543 $cont = 0;
2544
2545 # collect any Kconfig sources
2546 if (/^source\s*"(.*)"/) {
2547 $kconfigs[$#kconfigs+1] = $1;
2548 }
2549
2550 # configs found
2551 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2552 $state = "NEW";
2553 $config = $2;
2554
2555 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002556 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002557 }
2558
2559 # collect the depends for the config
2560 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2561
Steven Rostedtac6974c2011-10-04 09:40:17 -04002562 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002563
2564 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002565 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2566
2567 # selected by depends on config
2568 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002569
2570 # Check for if statements
2571 } elsif (/^if\s+(.*\S)\s*$/) {
2572 my $deps = $1;
2573 # remove beginning and ending non text
2574 $deps =~ s/^[^a-zA-Z0-9_]*//;
2575 $deps =~ s/[^a-zA-Z0-9_]*$//;
2576
2577 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2578
2579 $ifdeps[$iflevel++] = join ':', @deps;
2580
2581 } elsif (/^endif/) {
2582
2583 $iflevel-- if ($iflevel);
2584
2585 # stop on "help"
2586 } elsif (/^\s*help\s*$/) {
2587 $state = "NONE";
2588 }
2589 }
2590 close(KIN);
2591
2592 # read in any configs that were found.
2593 foreach $kconfig (@kconfigs) {
2594 if (!defined($read_kconfigs{$kconfig})) {
2595 $read_kconfigs{$kconfig} = 1;
2596 read_kconfig("$builddir/$kconfig");
2597 }
2598 }
2599}
2600
2601sub read_depends {
2602 # find out which arch this is by the kconfig file
2603 open (IN, $output_config)
2604 or dodie "Failed to read $output_config";
2605 my $arch;
2606 while (<IN>) {
2607 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2608 $arch = $1;
2609 last;
2610 }
2611 }
2612 close IN;
2613
2614 if (!defined($arch)) {
2615 doprint "Could not find arch from config file\n";
2616 doprint "no dependencies used\n";
2617 return;
2618 }
2619
2620 # arch is really the subarch, we need to know
2621 # what directory to look at.
2622 if ($arch eq "i386" || $arch eq "x86_64") {
2623 $arch = "x86";
2624 } elsif ($arch =~ /^tile/) {
2625 $arch = "tile";
2626 }
2627
2628 my $kconfig = "$builddir/arch/$arch/Kconfig";
2629
2630 if (! -f $kconfig && $arch =~ /\d$/) {
2631 my $orig = $arch;
2632 # some subarchs have numbers, truncate them
2633 $arch =~ s/\d*$//;
2634 $kconfig = "$builddir/arch/$arch/Kconfig";
2635 if (! -f $kconfig) {
2636 doprint "No idea what arch dir $orig is for\n";
2637 doprint "no dependencies used\n";
2638 return;
2639 }
2640 }
2641
2642 read_kconfig($kconfig);
2643}
2644
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002645sub read_config_list {
2646 my ($config) = @_;
2647
2648 open (IN, $config)
2649 or dodie "Failed to read $config";
2650
2651 while (<IN>) {
2652 if (/^((CONFIG\S*)=.*)/) {
2653 if (!defined($config_ignore{$2})) {
2654 $config_list{$2} = $1;
2655 }
2656 }
2657 }
2658
2659 close(IN);
2660}
2661
2662sub read_output_config {
2663 my ($config) = @_;
2664
2665 assign_configs \%config_ignore, $config;
2666}
2667
2668sub make_new_config {
2669 my @configs = @_;
2670
2671 open (OUT, ">$output_config")
2672 or dodie "Failed to write $output_config";
2673
2674 foreach my $config (@configs) {
2675 print OUT "$config\n";
2676 }
2677 close OUT;
2678}
2679
Steven Rostedtac6974c2011-10-04 09:40:17 -04002680sub chomp_config {
2681 my ($config) = @_;
2682
2683 $config =~ s/CONFIG_//;
2684
2685 return $config;
2686}
2687
Steven Rostedtb9066f62011-07-15 21:25:24 -04002688sub get_depends {
2689 my ($dep) = @_;
2690
Steven Rostedtac6974c2011-10-04 09:40:17 -04002691 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002692
2693 $dep = $depends{"$kconfig"};
2694
2695 # the dep string we have saves the dependencies as they
2696 # were found, including expressions like ! && ||. We
2697 # want to split this out into just an array of configs.
2698
2699 my $valid = "A-Za-z_0-9";
2700
2701 my @configs;
2702
2703 while ($dep =~ /[$valid]/) {
2704
2705 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2706 my $conf = "CONFIG_" . $1;
2707
2708 $configs[$#configs + 1] = $conf;
2709
2710 $dep =~ s/^[^$valid]*[$valid]+//;
2711 } else {
2712 die "this should never happen";
2713 }
2714 }
2715
2716 return @configs;
2717}
2718
2719my %min_configs;
2720my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002721my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002722my %processed_configs;
2723my %nochange_config;
2724
2725sub test_this_config {
2726 my ($config) = @_;
2727
2728 my $found;
2729
2730 # if we already processed this config, skip it
2731 if (defined($processed_configs{$config})) {
2732 return undef;
2733 }
2734 $processed_configs{$config} = 1;
2735
2736 # if this config failed during this round, skip it
2737 if (defined($nochange_config{$config})) {
2738 return undef;
2739 }
2740
Steven Rostedtac6974c2011-10-04 09:40:17 -04002741 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002742
2743 # Test dependencies first
2744 if (defined($depends{"$kconfig"})) {
2745 my @parents = get_depends $config;
2746 foreach my $parent (@parents) {
2747 # if the parent is in the min config, check it first
2748 next if (!defined($min_configs{$parent}));
2749 $found = test_this_config($parent);
2750 if (defined($found)) {
2751 return $found;
2752 }
2753 }
2754 }
2755
2756 # Remove this config from the list of configs
2757 # do a make oldnoconfig and then read the resulting
2758 # .config to make sure it is missing the config that
2759 # we had before
2760 my %configs = %min_configs;
2761 delete $configs{$config};
2762 make_new_config ((values %configs), (values %keep_configs));
2763 make_oldconfig;
2764 undef %configs;
2765 assign_configs \%configs, $output_config;
2766
2767 return $config if (!defined($configs{$config}));
2768
2769 doprint "disabling config $config did not change .config\n";
2770
2771 $nochange_config{$config} = 1;
2772
2773 return undef;
2774}
2775
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002776sub make_min_config {
2777 my ($i) = @_;
2778
2779 if (!defined($output_minconfig)) {
2780 fail "OUTPUT_MIN_CONFIG not defined" and return;
2781 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002782
2783 # If output_minconfig exists, and the start_minconfig
2784 # came from min_config, than ask if we should use
2785 # that instead.
2786 if (-f $output_minconfig && !$start_minconfig_defined) {
2787 print "$output_minconfig exists\n";
2788 if (read_yn " Use it as minconfig?") {
2789 $start_minconfig = $output_minconfig;
2790 }
2791 }
2792
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002793 if (!defined($start_minconfig)) {
2794 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2795 }
2796
Steven Rostedt35ce5952011-07-15 21:57:25 -04002797 my $temp_config = "$tmpdir/temp_config";
2798
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002799 # First things first. We build an allnoconfig to find
2800 # out what the defaults are that we can't touch.
2801 # Some are selections, but we really can't handle selections.
2802
2803 my $save_minconfig = $minconfig;
2804 undef $minconfig;
2805
2806 run_command "$make allnoconfig" or return 0;
2807
Steven Rostedtb9066f62011-07-15 21:25:24 -04002808 read_depends;
2809
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002810 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002811
Steven Rostedt43d1b652011-07-15 22:01:56 -04002812 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002813 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002814
2815 if (defined($ignore_config)) {
2816 # make sure the file exists
2817 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002818 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002819 }
2820
Steven Rostedt43d1b652011-07-15 22:01:56 -04002821 %keep_configs = %save_configs;
2822
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002823 doprint "Load initial configs from $start_minconfig\n";
2824
2825 # Look at the current min configs, and save off all the
2826 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002827 assign_configs \%min_configs, $start_minconfig;
2828
2829 my @config_keys = keys %min_configs;
2830
Steven Rostedtac6974c2011-10-04 09:40:17 -04002831 # All configs need a depcount
2832 foreach my $config (@config_keys) {
2833 my $kconfig = chomp_config $config;
2834 if (!defined $depcount{$kconfig}) {
2835 $depcount{$kconfig} = 0;
2836 }
2837 }
2838
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002839 # Remove anything that was set by the make allnoconfig
2840 # we shouldn't need them as they get set for us anyway.
2841 foreach my $config (@config_keys) {
2842 # Remove anything in the ignore_config
2843 if (defined($keep_configs{$config})) {
2844 my $file = $ignore_config;
2845 $file =~ s,.*/(.*?)$,$1,;
2846 doprint "$config set by $file ... ignored\n";
2847 delete $min_configs{$config};
2848 next;
2849 }
2850 # But make sure the settings are the same. If a min config
2851 # sets a selection, we do not want to get rid of it if
2852 # it is not the same as what we have. Just move it into
2853 # the keep configs.
2854 if (defined($config_ignore{$config})) {
2855 if ($config_ignore{$config} ne $min_configs{$config}) {
2856 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2857 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2858 $keep_configs{$config} = $min_configs{$config};
2859 } else {
2860 doprint "$config set by allnoconfig ... ignored\n";
2861 }
2862 delete $min_configs{$config};
2863 }
2864 }
2865
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002866 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002867 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002868
2869 while (!$done) {
2870
2871 my $config;
2872 my $found;
2873
2874 # Now disable each config one by one and do a make oldconfig
2875 # till we find a config that changes our list.
2876
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002877 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002878
2879 # Sort keys by who is most dependent on
2880 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2881 @test_configs ;
2882
2883 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002884 my $reset = 1;
2885 for (my $i = 0; $i < $#test_configs; $i++) {
2886 if (!defined($nochange_config{$test_configs[0]})) {
2887 $reset = 0;
2888 last;
2889 }
2890 # This config didn't change the .config last time.
2891 # Place it at the end
2892 my $config = shift @test_configs;
2893 push @test_configs, $config;
2894 }
2895
2896 # if every test config has failed to modify the .config file
2897 # in the past, then reset and start over.
2898 if ($reset) {
2899 undef %nochange_config;
2900 }
2901
Steven Rostedtb9066f62011-07-15 21:25:24 -04002902 undef %processed_configs;
2903
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002904 foreach my $config (@test_configs) {
2905
Steven Rostedtb9066f62011-07-15 21:25:24 -04002906 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002907
Steven Rostedtb9066f62011-07-15 21:25:24 -04002908 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002909
2910 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002911 }
2912
2913 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002914 # we could have failed due to the nochange_config hash
2915 # reset and try again
2916 if (!$take_two) {
2917 undef %nochange_config;
2918 $take_two = 1;
2919 next;
2920 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002921 doprint "No more configs found that we can disable\n";
2922 $done = 1;
2923 last;
2924 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04002925 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002926
2927 $config = $found;
2928
2929 doprint "Test with $config disabled\n";
2930
2931 # set in_bisect to keep build and monitor from dieing
2932 $in_bisect = 1;
2933
2934 my $failed = 0;
2935 build "oldconfig";
2936 start_monitor_and_boot or $failed = 1;
2937 end_monitor;
2938
2939 $in_bisect = 0;
2940
2941 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002942 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002943 # this config is needed, add it to the ignore list.
2944 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04002945 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002946 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04002947
2948 # update new ignore configs
2949 if (defined($ignore_config)) {
2950 open (OUT, ">$temp_config")
2951 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04002952 foreach my $config (keys %save_configs) {
2953 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04002954 }
2955 close OUT;
2956 run_command "mv $temp_config $ignore_config" or
2957 dodie "failed to copy update to $ignore_config";
2958 }
2959
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002960 } else {
2961 # We booted without this config, remove it from the minconfigs.
2962 doprint "$config is not needed, disabling\n";
2963
2964 delete $min_configs{$config};
2965
2966 # Also disable anything that is not enabled in this config
2967 my %configs;
2968 assign_configs \%configs, $output_config;
2969 my @config_keys = keys %min_configs;
2970 foreach my $config (@config_keys) {
2971 if (!defined($configs{$config})) {
2972 doprint "$config is not set, disabling\n";
2973 delete $min_configs{$config};
2974 }
2975 }
2976
2977 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04002978 open (OUT, ">$temp_config")
2979 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002980 foreach my $config (keys %keep_configs) {
2981 print OUT "$keep_configs{$config}\n";
2982 }
2983 foreach my $config (keys %min_configs) {
2984 print OUT "$min_configs{$config}\n";
2985 }
2986 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04002987
2988 run_command "mv $temp_config $output_minconfig" or
2989 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002990 }
2991
2992 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002993 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002994 }
2995
2996 success $i;
2997 return 1;
2998}
2999
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003000$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003001
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003002if ($#ARGV == 0) {
3003 $ktest_config = $ARGV[0];
3004 if (! -f $ktest_config) {
3005 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003006 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003007 exit 0;
3008 }
3009 }
3010} else {
3011 $ktest_config = "ktest.conf";
3012}
3013
3014if (! -f $ktest_config) {
3015 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3016 print OUT << "EOF"
3017# Generated by ktest.pl
3018#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003019
3020# PWD is a ktest.pl variable that will result in the process working
3021# directory that ktest.pl is executed in.
3022
3023# THIS_DIR is automatically assigned the PWD of the path that generated
3024# the config file. It is best to use this variable when assigning other
3025# directory paths within this directory. This allows you to easily
3026# move the test cases to other locations or to other machines.
3027#
3028THIS_DIR := $variable{"PWD"}
3029
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003030# Define each test with TEST_START
3031# The config options below it will override the defaults
3032TEST_START
3033
3034DEFAULTS
3035EOF
3036;
3037 close(OUT);
3038}
3039read_config $ktest_config;
3040
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003041if (defined($opt{"LOG_FILE"})) {
3042 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3043}
3044
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003045# Append any configs entered in manually to the config file.
3046my @new_configs = keys %entered_configs;
3047if ($#new_configs >= 0) {
3048 print "\nAppending entered in configs to $ktest_config\n";
3049 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3050 foreach my $config (@new_configs) {
3051 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003052 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003053 }
3054}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003055
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003056if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3057 unlink $opt{"LOG_FILE"};
3058}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003059
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003060doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3061
Steven Rostedta57419b2010-11-02 15:13:54 -04003062for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3063
3064 if (!$i) {
3065 doprint "DEFAULT OPTIONS:\n";
3066 } else {
3067 doprint "\nTEST $i OPTIONS";
3068 if (defined($repeat_tests{$i})) {
3069 $repeat = $repeat_tests{$i};
3070 doprint " ITERATE $repeat";
3071 }
3072 doprint "\n";
3073 }
3074
3075 foreach my $option (sort keys %opt) {
3076
3077 if ($option =~ /\[(\d+)\]$/) {
3078 next if ($i != $1);
3079 } else {
3080 next if ($i);
3081 }
3082
3083 doprint "$option = $opt{$option}\n";
3084 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003085}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003086
Steven Rostedt2a625122011-05-20 15:48:59 -04003087sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003088 my ($name, $i) = @_;
3089
3090 my $option = "$name\[$i\]";
3091
3092 if (defined($opt{$option})) {
3093 return $opt{$option};
3094 }
3095
Steven Rostedta57419b2010-11-02 15:13:54 -04003096 foreach my $test (keys %repeat_tests) {
3097 if ($i >= $test &&
3098 $i < $test + $repeat_tests{$test}) {
3099 $option = "$name\[$test\]";
3100 if (defined($opt{$option})) {
3101 return $opt{$option};
3102 }
3103 }
3104 }
3105
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003106 if (defined($opt{$name})) {
3107 return $opt{$name};
3108 }
3109
3110 return undef;
3111}
3112
Steven Rostedt2a625122011-05-20 15:48:59 -04003113sub set_test_option {
3114 my ($name, $i) = @_;
3115
3116 my $option = __set_test_option($name, $i);
3117 return $option if (!defined($option));
3118
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003119 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003120}
3121
Steven Rostedt2545eb62010-11-02 15:01:32 -04003122# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003123for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003124
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003125 # Do not reboot on failing test options
3126 $no_reboot = 1;
3127
Steven Rostedt576f6272010-11-02 14:58:38 -04003128 $iteration = $i;
3129
Steven Rostedta75fece2010-11-02 14:58:27 -04003130 my $makecmd = set_test_option("MAKE_CMD", $i);
3131
3132 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003133 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003134 $tmpdir = set_test_option("TMP_DIR", $i);
3135 $outputdir = set_test_option("OUTPUT_DIR", $i);
3136 $builddir = set_test_option("BUILD_DIR", $i);
3137 $test_type = set_test_option("TEST_TYPE", $i);
3138 $build_type = set_test_option("BUILD_TYPE", $i);
3139 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003140 $pre_build = set_test_option("PRE_BUILD", $i);
3141 $post_build = set_test_option("POST_BUILD", $i);
3142 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3143 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003144 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003145 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003146 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3147 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003148 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3149 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3150 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003151 $run_test = set_test_option("TEST", $i);
3152 $addconfig = set_test_option("ADD_CONFIG", $i);
3153 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3154 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003155 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003156 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003157 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3158 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3159 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3160 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3161 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003162 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3163 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003164 $sleep_time = set_test_option("SLEEP_TIME", $i);
3165 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003166 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003167 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003168 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003169 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003170 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003171 $store_failures = set_test_option("STORE_FAILURES", $i);
Rabin Vincentde5b6e32011-11-18 17:05:31 +05303172 $store_successes = set_test_option("STORE_SUCCESSES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003173 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003174 $timeout = set_test_option("TIMEOUT", $i);
3175 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3176 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003177 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003178 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003179 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003180 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3181 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003182 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003183 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003184 $ssh_exec = set_test_option("SSH_EXEC", $i);
3185 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003186 $target_image = set_test_option("TARGET_IMAGE", $i);
3187 $localversion = set_test_option("LOCALVERSION", $i);
3188
Steven Rostedt35ce5952011-07-15 21:57:25 -04003189 $start_minconfig_defined = 1;
3190
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003191 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003192 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003193 $start_minconfig = $minconfig;
3194 }
3195
Steven Rostedta75fece2010-11-02 14:58:27 -04003196 chdir $builddir || die "can't change directory to $builddir";
3197
Andrew Jonesa908a662011-08-12 15:32:03 +02003198 foreach my $dir ($tmpdir, $outputdir) {
3199 if (!-d $dir) {
3200 mkpath($dir) or
3201 die "can't create $dir";
3202 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003203 }
3204
Steven Rostedte48c5292010-11-02 14:35:37 -04003205 $ENV{"SSH_USER"} = $ssh_user;
3206 $ENV{"MACHINE"} = $machine;
3207
Steven Rostedta75fece2010-11-02 14:58:27 -04003208 $target = "$ssh_user\@$machine";
3209
3210 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303211 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003212 $dmesg = "$tmpdir/dmesg-$machine";
3213 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003214 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003215
3216 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04003217 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04003218 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04003219 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04003220 }
3221
3222 my $run_type = $build_type;
3223 if ($test_type eq "patchcheck") {
3224 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3225 } elsif ($test_type eq "bisect") {
3226 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003227 } elsif ($test_type eq "config_bisect") {
3228 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003229 }
3230
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003231 if ($test_type eq "make_min_config") {
3232 $run_type = "";
3233 }
3234
Steven Rostedta75fece2010-11-02 14:58:27 -04003235 # mistake in config file?
3236 if (!defined($run_type)) {
3237 $run_type = "ERROR";
3238 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003239
Steven Rostedte0a87422011-09-30 17:50:48 -04003240 my $installme = "";
3241 $installme = " no_install" if ($no_install);
3242
Steven Rostedt2545eb62010-11-02 15:01:32 -04003243 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003244 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003245
3246 unlink $dmesg;
3247 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303248 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003249
Steven Rostedt250bae82011-07-15 22:05:59 -04003250 if (defined($addconfig)) {
3251 my $min = $minconfig;
3252 if (!defined($minconfig)) {
3253 $min = "";
3254 }
3255 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003256 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003257 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003258 }
3259
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003260 my $checkout = $opt{"CHECKOUT[$i]"};
3261 if (defined($checkout)) {
3262 run_command "git checkout $checkout" or
3263 die "failed to checkout $checkout";
3264 }
3265
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003266 $no_reboot = 0;
3267
3268
Steven Rostedta75fece2010-11-02 14:58:27 -04003269 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003270 bisect $i;
3271 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003272 } elsif ($test_type eq "config_bisect") {
3273 config_bisect $i;
3274 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003275 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003276 patchcheck $i;
3277 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003278 } elsif ($test_type eq "make_min_config") {
3279 make_min_config $i;
3280 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003281 }
3282
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003283 if ($build_type ne "nobuild") {
3284 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003285 }
3286
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003287 if ($test_type eq "install") {
3288 get_version;
3289 install;
3290 success $i;
3291 next;
3292 }
3293
Steven Rostedta75fece2010-11-02 14:58:27 -04003294 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003295 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003296 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003297
3298 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3299 do_run_test or $failed = 1;
3300 }
3301 end_monitor;
3302 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003303 }
3304
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003305 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003306}
3307
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003308if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003309 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003310} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003311 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003312}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003313
Steven Rostedte48c5292010-11-02 14:35:37 -04003314doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3315
Steven Rostedt2545eb62010-11-02 15:01:32 -04003316exit 0;