blob: 2ffb67c3c49de5a53447ab2390e2e9748d82897a [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 Rostedtdad98752011-11-22 20:48:57 -0500242sub read_prompt {
243 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400244
245 my $ans;
246
247 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500248 if ($cancel) {
249 print "$prompt [y/n/C] ";
250 } else {
251 print "$prompt [Y/n] ";
252 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400253 $ans = <STDIN>;
254 chomp $ans;
255 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500256 if ($cancel) {
257 $ans = "c";
258 } else {
259 $ans = "y";
260 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400261 }
262 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500263 if ($cancel) {
264 last if ($ans =~ /^c$/i);
265 print "Please answer either 'y', 'n' or 'c'.\n";
266 } else {
267 print "Please answer either 'y' or 'n'.\n";
268 }
269 }
270 if ($ans =~ /^c/i) {
271 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400272 }
273 if ($ans !~ /^y$/i) {
274 return 0;
275 }
276 return 1;
277}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500278
Steven Rostedtdad98752011-11-22 20:48:57 -0500279sub read_yn {
280 my ($prompt) = @_;
281
282 return read_prompt 0, $prompt;
283}
284
285sub read_ync {
286 my ($prompt) = @_;
287
288 return read_prompt 1, $prompt;
289}
290
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500291sub get_ktest_config {
292 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400293 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500294
295 return if (defined($opt{$config}));
296
297 if (defined($config_help{$config})) {
298 print "\n";
299 print $config_help{$config};
300 }
301
302 for (;;) {
303 print "$config = ";
304 if (defined($default{$config})) {
305 print "\[$default{$config}\] ";
306 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400307 $ans = <STDIN>;
308 $ans =~ s/^\s*(.*\S)\s*$/$1/;
309 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500310 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400311 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500312 } else {
313 print "Your answer can not be blank\n";
314 next;
315 }
316 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500317 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500318 last;
319 }
320}
321
322sub get_ktest_configs {
323 get_ktest_config("MACHINE");
324 get_ktest_config("SSH_USER");
325 get_ktest_config("BUILD_DIR");
326 get_ktest_config("OUTPUT_DIR");
327 get_ktest_config("BUILD_TARGET");
328 get_ktest_config("TARGET_IMAGE");
329 get_ktest_config("POWER_CYCLE");
330 get_ktest_config("CONSOLE");
331 get_ktest_config("LOCALVERSION");
332
333 my $rtype = $opt{"REBOOT_TYPE"};
334
335 if (!defined($rtype)) {
336 if (!defined($opt{"GRUB_MENU"})) {
337 get_ktest_config("REBOOT_TYPE");
338 $rtype = $entered_configs{"REBOOT_TYPE"};
339 } else {
340 $rtype = "grub";
341 }
342 }
343
344 if ($rtype eq "grub") {
345 get_ktest_config("GRUB_MENU");
346 } else {
347 get_ktest_config("REBOOT_SCRIPT");
348 }
349}
350
Steven Rostedt77d942c2011-05-20 13:36:58 -0400351sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400352 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400353 my $retval = "";
354
355 # We want to check for '\', and it is just easier
356 # to check the previous characet of '$' and not need
357 # to worry if '$' is the first character. By adding
358 # a space to $value, we can just check [^\\]\$ and
359 # it will still work.
360 $value = " $value";
361
362 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
363 my $begin = $1;
364 my $var = $2;
365 my $end = $3;
366 # append beginning of value to retval
367 $retval = "$retval$begin";
368 if (defined($variable{$var})) {
369 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400370 } elsif (defined($remove_undef) && $remove_undef) {
371 # for if statements, any variable that is not defined,
372 # we simple convert to 0
373 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400374 } else {
375 # put back the origin piece.
376 $retval = "$retval\$\{$var\}";
377 }
378 $value = $end;
379 }
380 $retval = "$retval$value";
381
382 # remove the space added in the beginning
383 $retval =~ s/ //;
384
385 return "$retval"
386}
387
Steven Rostedta57419b2010-11-02 15:13:54 -0400388sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400389 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400390
391 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400392 if (!$override || defined(${$overrides}{$lvalue})) {
393 my $extra = "";
394 if ($override) {
395 $extra = "In the same override section!\n";
396 }
397 die "$name: $.: Option $lvalue defined more than once!\n$extra";
398 }
399 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400400 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500401 if ($rvalue =~ /^\s*$/) {
402 delete $opt{$lvalue};
403 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400404 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500405 $opt{$lvalue} = $rvalue;
406 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400407}
408
Steven Rostedt77d942c2011-05-20 13:36:58 -0400409sub set_variable {
410 my ($lvalue, $rvalue) = @_;
411
412 if ($rvalue =~ /^\s*$/) {
413 delete $variable{$lvalue};
414 } else {
415 $rvalue = process_variables($rvalue);
416 $variable{$lvalue} = $rvalue;
417 }
418}
419
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400420sub process_compare {
421 my ($lval, $cmp, $rval) = @_;
422
423 # remove whitespace
424
425 $lval =~ s/^\s*//;
426 $lval =~ s/\s*$//;
427
428 $rval =~ s/^\s*//;
429 $rval =~ s/\s*$//;
430
431 if ($cmp eq "==") {
432 return $lval eq $rval;
433 } elsif ($cmp eq "!=") {
434 return $lval ne $rval;
435 }
436
437 my $statement = "$lval $cmp $rval";
438 my $ret = eval $statement;
439
440 # $@ stores error of eval
441 if ($@) {
442 return -1;
443 }
444
445 return $ret;
446}
447
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400448sub value_defined {
449 my ($val) = @_;
450
451 return defined($variable{$2}) ||
452 defined($opt{$2});
453}
454
Steven Rostedt8d735212011-10-17 11:36:44 -0400455my $d = 0;
456sub process_expression {
457 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400458
Steven Rostedt8d735212011-10-17 11:36:44 -0400459 my $c = $d++;
460
461 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
462 my $express = $1;
463
464 if (process_expression($name, $express)) {
465 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
466 } else {
467 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
468 }
469 }
470
471 $d--;
472 my $OR = "\\|\\|";
473 my $AND = "\\&\\&";
474
475 while ($val =~ s/^(.*?)($OR|$AND)//) {
476 my $express = $1;
477 my $op = $2;
478
479 if (process_expression($name, $express)) {
480 if ($op eq "||") {
481 return 1;
482 }
483 } else {
484 if ($op eq "&&") {
485 return 0;
486 }
487 }
488 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400489
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400490 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
491 my $ret = process_compare($1, $2, $3);
492 if ($ret < 0) {
493 die "$name: $.: Unable to process comparison\n";
494 }
495 return $ret;
496 }
497
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400498 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
499 if (defined $1) {
500 return !value_defined($2);
501 } else {
502 return value_defined($2);
503 }
504 }
505
Steven Rostedt45d73a52011-09-30 19:44:53 -0400506 if ($val =~ /^\s*0\s*$/) {
507 return 0;
508 } elsif ($val =~ /^\s*\d+\s*$/) {
509 return 1;
510 }
511
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400512 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400513}
514
515sub process_if {
516 my ($name, $value) = @_;
517
518 # Convert variables and replace undefined ones with 0
519 my $val = process_variables($value, 1);
520 my $ret = process_expression $name, $val;
521
522 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400523}
524
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400525sub __read_config {
526 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400527
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400528 my $in;
529 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400530
Steven Rostedta57419b2010-11-02 15:13:54 -0400531 my $name = $config;
532 $name =~ s,.*/(.*),$1,;
533
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400534 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400535 my $default = 1;
536 my $repeat = 1;
537 my $num_tests_set = 0;
538 my $skip = 0;
539 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400540 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400541 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400542 my $if = 0;
543 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400544 my $override = 0;
545
546 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400547
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400548 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400549
550 # ignore blank lines and comments
551 next if (/^\s*$/ || /\s*\#/);
552
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400553 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400554
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400555 my $type = $1;
556 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400557 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400558
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400559 my $old_test_num;
560 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400561 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400562
563 if ($type eq "TEST_START") {
564
565 if ($num_tests_set) {
566 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
567 }
568
569 $old_test_num = $test_num;
570 $old_repeat = $repeat;
571
572 $test_num += $repeat;
573 $default = 0;
574 $repeat = 1;
575 } else {
576 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400577 }
578
Steven Rostedta9f84422011-10-17 11:06:29 -0400579 # If SKIP is anywhere in the line, the command will be skipped
580 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400581 $skip = 1;
582 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400583 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400584 $skip = 0;
585 }
586
Steven Rostedta9f84422011-10-17 11:06:29 -0400587 if ($rest =~ s/\sELSE\b//) {
588 if (!$if) {
589 die "$name: $.: ELSE found with out matching IF section\n$_";
590 }
591 $if = 0;
592
593 if ($if_set) {
594 $skip = 1;
595 } else {
596 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400597 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400598 }
599
Steven Rostedta9f84422011-10-17 11:06:29 -0400600 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400601 if (process_if($name, $1)) {
602 $if_set = 1;
603 } else {
604 $skip = 1;
605 }
606 $if = 1;
607 } else {
608 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400609 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400610 }
611
Steven Rostedta9f84422011-10-17 11:06:29 -0400612 if (!$skip) {
613 if ($type eq "TEST_START") {
614 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
615 $repeat = $1;
616 $repeat_tests{"$test_num"} = $repeat;
617 }
618 } elsif ($rest =~ s/\sOVERRIDE\b//) {
619 # DEFAULT only
620 $override = 1;
621 # Clear previous overrides
622 %overrides = ();
623 }
624 }
625
626 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400627 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400628 }
629
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400630 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400631 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400632 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400633 }
634
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400635 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400636 if (!$if) {
637 die "$name: $.: ELSE found with out matching IF section\n$_";
638 }
639 $rest = $1;
640 if ($if_set) {
641 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400642 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400643 } else {
644 $skip = 0;
645
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400646 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400647 # May be a ELSE IF section.
648 if (!process_if($name, $1)) {
649 $skip = 1;
650 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400651 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400652 } else {
653 $if = 0;
654 }
655 }
656
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400657 if ($rest !~ /^\s*$/) {
658 die "$name: $.: Gargbage found after DEFAULTS\n$_";
659 }
660
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400661 } elsif (/^\s*INCLUDE\s+(\S+)/) {
662
663 next if ($skip);
664
665 if (!$default) {
666 die "$name: $.: INCLUDE can only be done in default sections\n$_";
667 }
668
669 my $file = process_variables($1);
670
671 if ($file !~ m,^/,) {
672 # check the path of the config file first
673 if ($config =~ m,(.*)/,) {
674 if (-f "$1/$file") {
675 $file = "$1/$file";
676 }
677 }
678 }
679
680 if ( ! -r $file ) {
681 die "$name: $.: Can't read file $file\n$_";
682 }
683
684 if (__read_config($file, \$test_num)) {
685 $test_case = 1;
686 }
687
Steven Rostedta57419b2010-11-02 15:13:54 -0400688 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
689
690 next if ($skip);
691
Steven Rostedt2545eb62010-11-02 15:01:32 -0400692 my $lvalue = $1;
693 my $rvalue = $2;
694
Steven Rostedta57419b2010-11-02 15:13:54 -0400695 if (!$default &&
696 ($lvalue eq "NUM_TESTS" ||
697 $lvalue eq "LOG_FILE" ||
698 $lvalue eq "CLEAR_LOG")) {
699 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400700 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400701
702 if ($lvalue eq "NUM_TESTS") {
703 if ($test_num) {
704 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
705 }
706 if (!$default) {
707 die "$name: $.: NUM_TESTS must be set in default section\n";
708 }
709 $num_tests_set = 1;
710 }
711
712 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400713 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400714 } else {
715 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400716 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400717
718 if ($repeat > 1) {
719 $repeats{$val} = $repeat;
720 }
721 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400722 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
723 next if ($skip);
724
725 my $lvalue = $1;
726 my $rvalue = $2;
727
728 # process config variables.
729 # Config variables are only active while reading the
730 # config and can be defined anywhere. They also ignore
731 # TEST_START and DEFAULTS, but are skipped if they are in
732 # on of these sections that have SKIP defined.
733 # The save variable can be
734 # defined multiple times and the new one simply overrides
735 # the prevous one.
736 set_variable($lvalue, $rvalue);
737
Steven Rostedta57419b2010-11-02 15:13:54 -0400738 } else {
739 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400740 }
741 }
742
Steven Rostedta57419b2010-11-02 15:13:54 -0400743 if ($test_num) {
744 $test_num += $repeat - 1;
745 $opt{"NUM_TESTS"} = $test_num;
746 }
747
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400748 close($in);
749
750 $$current_test_num = $test_num;
751
752 return $test_case;
753}
754
755sub read_config {
756 my ($config) = @_;
757
758 my $test_case;
759 my $test_num = 0;
760
761 $test_case = __read_config $config, \$test_num;
762
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500763 # make sure we have all mandatory configs
764 get_ktest_configs;
765
Steven Rostedt0df213c2011-06-14 20:51:37 -0400766 # was a test specified?
767 if (!$test_case) {
768 print "No test case specified.\n";
769 print "What test case would you like to run?\n";
770 my $ans = <STDIN>;
771 chomp $ans;
772 $default{"TEST_TYPE"} = $ans;
773 }
774
Steven Rostedta75fece2010-11-02 14:58:27 -0400775 # set any defaults
776
777 foreach my $default (keys %default) {
778 if (!defined($opt{$default})) {
779 $opt{$default} = $default{$default};
780 }
781 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400782}
783
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400784sub __eval_option {
785 my ($option, $i) = @_;
786
787 # Add space to evaluate the character before $
788 $option = " $option";
789 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530790 my $repeated = 0;
791 my $parent = 0;
792
793 foreach my $test (keys %repeat_tests) {
794 if ($i >= $test &&
795 $i < $test + $repeat_tests{$test}) {
796
797 $repeated = 1;
798 $parent = $test;
799 last;
800 }
801 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400802
803 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
804 my $start = $1;
805 my $var = $2;
806 my $end = $3;
807
808 # Append beginning of line
809 $retval = "$retval$start";
810
811 # If the iteration option OPT[$i] exists, then use that.
812 # otherwise see if the default OPT (without [$i]) exists.
813
814 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530815 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400816
817 if (defined($opt{$o})) {
818 $o = $opt{$o};
819 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530820 } elsif ($repeated && defined($opt{$parento})) {
821 $o = $opt{$parento};
822 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400823 } elsif (defined($opt{$var})) {
824 $o = $opt{$var};
825 $retval = "$retval$o";
826 } else {
827 $retval = "$retval\$\{$var\}";
828 }
829
830 $option = $end;
831 }
832
833 $retval = "$retval$option";
834
835 $retval =~ s/^ //;
836
837 return $retval;
838}
839
840sub eval_option {
841 my ($option, $i) = @_;
842
843 my $prev = "";
844
845 # Since an option can evaluate to another option,
846 # keep iterating until we do not evaluate any more
847 # options.
848 my $r = 0;
849 while ($prev ne $option) {
850 # Check for recursive evaluations.
851 # 100 deep should be more than enough.
852 if ($r++ > 100) {
853 die "Over 100 evaluations accurred with $option\n" .
854 "Check for recursive variables\n";
855 }
856 $prev = $option;
857 $option = __eval_option($option, $i);
858 }
859
860 return $option;
861}
862
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500863sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400864 if (defined($opt{"LOG_FILE"})) {
865 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
866 print OUT @_;
867 close(OUT);
868 }
869}
870
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500871sub logit {
872 if (defined($opt{"LOG_FILE"})) {
873 _logit @_;
874 } else {
875 print @_;
876 }
877}
878
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400879sub doprint {
880 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500881 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400882}
883
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400884sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200885sub start_monitor;
886sub end_monitor;
887sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400888
889sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200890 my ($time) = @_;
891
Steven Rostedt2b803362011-09-30 18:00:23 -0400892 if (defined($time)) {
893 start_monitor;
894 # flush out current monitor
895 # May contain the reboot success line
896 wait_for_monitor 1;
897 }
898
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400899 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400900 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400901 if (defined($powercycle_after_reboot)) {
902 sleep $powercycle_after_reboot;
903 run_command "$power_cycle";
904 }
905 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400906 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400907 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400908 }
Andrew Jones2728be42011-08-12 15:32:05 +0200909
910 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400911 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200912 end_monitor;
913 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400914}
915
Steven Rostedt576f6272010-11-02 14:58:38 -0400916sub do_not_reboot {
917 my $i = $iteration;
918
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400919 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400920 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
921 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
922}
923
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400924sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400925 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400926
Steven Rostedt576f6272010-11-02 14:58:38 -0400927 my $i = $iteration;
928
929 if ($reboot_on_error && !do_not_reboot) {
930
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400931 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400932 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400933
Steven Rostedta75fece2010-11-02 14:58:27 -0400934 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400935 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400936 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400937 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400938
Steven Rostedtf80802c2011-03-07 13:18:47 -0500939 if (defined($opt{"LOG_FILE"})) {
940 print " See $opt{LOG_FILE} for more info.\n";
941 }
942
Steven Rostedt576f6272010-11-02 14:58:38 -0400943 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400944}
945
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400946sub open_console {
947 my ($fp) = @_;
948
949 my $flags;
950
Steven Rostedta75fece2010-11-02 14:58:27 -0400951 my $pid = open($fp, "$console|") or
952 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400953
954 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400955 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400956 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400957 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400958
959 return $pid;
960}
961
962sub close_console {
963 my ($fp, $pid) = @_;
964
965 doprint "kill child process $pid\n";
966 kill 2, $pid;
967
968 print "closing!\n";
969 close($fp);
970}
971
972sub start_monitor {
973 if ($monitor_cnt++) {
974 return;
975 }
976 $monitor_fp = \*MONFD;
977 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400978
979 return;
980
981 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400982}
983
984sub end_monitor {
985 if (--$monitor_cnt) {
986 return;
987 }
988 close_console($monitor_fp, $monitor_pid);
989}
990
991sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -0400992 my ($time, $stop) = @_;
993 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400994 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -0400995 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400996
Steven Rostedta75fece2010-11-02 14:58:27 -0400997 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400998
999 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001000 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001001 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001002 last if (!defined($line));
1003 print "$line";
1004 $full_line .= $line;
1005
1006 if (defined($stop) && $full_line =~ /$stop/) {
1007 doprint "wait for monitor detected $stop\n";
1008 $booted = 1;
1009 }
1010
1011 if ($line =~ /\n/) {
1012 $full_line = "";
1013 }
1014 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001015 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001016}
1017
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301018sub save_logs {
1019 my ($result, $basedir) = @_;
1020 my @t = localtime;
1021 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1022 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1023
1024 my $type = $build_type;
1025 if ($type =~ /useconfig/) {
1026 $type = "useconfig";
1027 }
1028
1029 my $dir = "$machine-$test_type-$type-$result-$date";
1030
1031 $dir = "$basedir/$dir";
1032
1033 if (!-d $dir) {
1034 mkpath($dir) or
1035 die "can't create $dir";
1036 }
1037
1038 my %files = (
1039 "config" => $output_config,
1040 "buildlog" => $buildlog,
1041 "dmesg" => $dmesg,
1042 "testlog" => $testlog,
1043 );
1044
1045 while (my ($name, $source) = each(%files)) {
1046 if (-f "$source") {
1047 cp "$source", "$dir/$name" or
1048 die "failed to copy $source";
1049 }
1050 }
1051
1052 doprint "*** Saved info to $dir ***\n";
1053}
1054
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001055sub fail {
1056
Steven Rostedta75fece2010-11-02 14:58:27 -04001057 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001058 dodie @_;
1059 }
1060
Steven Rostedta75fece2010-11-02 14:58:27 -04001061 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001062
Steven Rostedt576f6272010-11-02 14:58:38 -04001063 my $i = $iteration;
1064
Steven Rostedta75fece2010-11-02 14:58:27 -04001065 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001066 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001067 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001068 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001069 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001070
Steven Rostedt9064af52011-06-13 10:38:48 -04001071 my $name = "";
1072
1073 if (defined($test_name)) {
1074 $name = " ($test_name)";
1075 }
1076
Steven Rostedt576f6272010-11-02 14:58:38 -04001077 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1078 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001079 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001080 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1081 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001082
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301083 if (defined($store_failures)) {
1084 save_logs "fail", $store_failures;
1085 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001086
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001087 return 1;
1088}
1089
Steven Rostedt2545eb62010-11-02 15:01:32 -04001090sub run_command {
1091 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001092 my $dolog = 0;
1093 my $dord = 0;
1094 my $pid;
1095
Steven Rostedte48c5292010-11-02 14:35:37 -04001096 $command =~ s/\$SSH_USER/$ssh_user/g;
1097 $command =~ s/\$MACHINE/$machine/g;
1098
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001099 doprint("$command ... ");
1100
1101 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001102 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001103
1104 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001105 open(LOG, ">>$opt{LOG_FILE}") or
1106 dodie "failed to write to log";
1107 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001108 }
1109
1110 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001111 open (RD, ">$redirect") or
1112 dodie "failed to write to redirect $redirect";
1113 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001114 }
1115
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001116 while (<CMD>) {
1117 print LOG if ($dolog);
1118 print RD if ($dord);
1119 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001120
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001121 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001122 my $failed = $?;
1123
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001124 close(CMD);
1125 close(LOG) if ($dolog);
1126 close(RD) if ($dord);
1127
Steven Rostedt2545eb62010-11-02 15:01:32 -04001128 if ($failed) {
1129 doprint "FAILED!\n";
1130 } else {
1131 doprint "SUCCESS\n";
1132 }
1133
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001134 return !$failed;
1135}
1136
Steven Rostedte48c5292010-11-02 14:35:37 -04001137sub run_ssh {
1138 my ($cmd) = @_;
1139 my $cp_exec = $ssh_exec;
1140
1141 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1142 return run_command "$cp_exec";
1143}
1144
1145sub run_scp {
1146 my ($src, $dst) = @_;
1147 my $cp_scp = $scp_to_target;
1148
1149 $cp_scp =~ s/\$SRC_FILE/$src/g;
1150 $cp_scp =~ s/\$DST_FILE/$dst/g;
1151
1152 return run_command "$cp_scp";
1153}
1154
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001155sub get_grub_index {
1156
Steven Rostedta75fece2010-11-02 14:58:27 -04001157 if ($reboot_type ne "grub") {
1158 return;
1159 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001160 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001161
1162 doprint "Find grub menu ... ";
1163 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001164
1165 my $ssh_grub = $ssh_exec;
1166 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1167
1168 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001169 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001170
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001171 my $found = 0;
1172
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001173 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001174 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001175 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001176 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001177 last;
1178 } elsif (/^\s*title\s/) {
1179 $grub_number++;
1180 }
1181 }
1182 close(IN);
1183
Steven Rostedta75fece2010-11-02 14:58:27 -04001184 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001185 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001186 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001187}
1188
Steven Rostedt2545eb62010-11-02 15:01:32 -04001189sub wait_for_input
1190{
1191 my ($fp, $time) = @_;
1192 my $rin;
1193 my $ready;
1194 my $line;
1195 my $ch;
1196
1197 if (!defined($time)) {
1198 $time = $timeout;
1199 }
1200
1201 $rin = '';
1202 vec($rin, fileno($fp), 1) = 1;
1203 $ready = select($rin, undef, undef, $time);
1204
1205 $line = "";
1206
1207 # try to read one char at a time
1208 while (sysread $fp, $ch, 1) {
1209 $line .= $ch;
1210 last if ($ch eq "\n");
1211 }
1212
1213 if (!length($line)) {
1214 return undef;
1215 }
1216
1217 return $line;
1218}
1219
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001220sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001221 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001222 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1223 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001224 return;
1225 }
1226
1227 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001228}
1229
Steven Rostedta57419b2010-11-02 15:13:54 -04001230sub get_sha1 {
1231 my ($commit) = @_;
1232
1233 doprint "git rev-list --max-count=1 $commit ... ";
1234 my $sha1 = `git rev-list --max-count=1 $commit`;
1235 my $ret = $?;
1236
1237 logit $sha1;
1238
1239 if ($ret) {
1240 doprint "FAILED\n";
1241 dodie "Failed to get git $commit";
1242 }
1243
1244 print "SUCCESS\n";
1245
1246 chomp $sha1;
1247
1248 return $sha1;
1249}
1250
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001251sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001252 my $booted = 0;
1253 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001254 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001255 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001256
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001257 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001258
1259 my $line;
1260 my $full_line = "";
1261
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001262 open(DMESG, "> $dmesg") or
1263 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001264
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001265 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001266
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001267 my $success_start;
1268 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001269 my $monitor_start = time;
1270 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001271 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001272
Steven Rostedt2d01b262011-03-08 09:47:54 -05001273 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001274
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001275 if ($bug && defined($stop_after_failure) &&
1276 $stop_after_failure >= 0) {
1277 my $time = $stop_after_failure - (time - $failure_start);
1278 $line = wait_for_input($monitor_fp, $time);
1279 if (!defined($line)) {
1280 doprint "bug timed out after $booted_timeout seconds\n";
1281 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1282 last;
1283 }
1284 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001285 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001286 if (!defined($line)) {
1287 my $s = $booted_timeout == 1 ? "" : "s";
1288 doprint "Successful boot found: break after $booted_timeout second$s\n";
1289 last;
1290 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001291 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001292 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001293 if (!defined($line)) {
1294 my $s = $timeout == 1 ? "" : "s";
1295 doprint "Timed out after $timeout second$s\n";
1296 last;
1297 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001298 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001299
Steven Rostedt2545eb62010-11-02 15:01:32 -04001300 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001301 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001302
1303 # we are not guaranteed to get a full line
1304 $full_line .= $line;
1305
Steven Rostedta75fece2010-11-02 14:58:27 -04001306 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001307 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001308 $success_start = time;
1309 }
1310
1311 if ($booted && defined($stop_after_success) &&
1312 $stop_after_success >= 0) {
1313 my $now = time;
1314 if ($now - $success_start >= $stop_after_success) {
1315 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1316 last;
1317 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001318 }
1319
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001320 if ($full_line =~ /\[ backtrace testing \]/) {
1321 $skip_call_trace = 1;
1322 }
1323
Steven Rostedt2545eb62010-11-02 15:01:32 -04001324 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001325 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001326 $bug = 1;
1327 $failure_start = time;
1328 }
1329 }
1330
1331 if ($bug && defined($stop_after_failure) &&
1332 $stop_after_failure >= 0) {
1333 my $now = time;
1334 if ($now - $failure_start >= $stop_after_failure) {
1335 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1336 last;
1337 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001338 }
1339
1340 if ($full_line =~ /\[ end of backtrace testing \]/) {
1341 $skip_call_trace = 0;
1342 }
1343
1344 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001345 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001346 $bug = 1;
1347 }
1348
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001349 # Detect triple faults by testing the banner
1350 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1351 if ($1 eq $version) {
1352 $version_found = 1;
1353 } elsif ($version_found && $detect_triplefault) {
1354 # We already booted into the kernel we are testing,
1355 # but now we booted into another kernel?
1356 # Consider this a triple fault.
1357 doprint "Aleady booted in Linux kernel $version, but now\n";
1358 doprint "we booted into Linux kernel $1.\n";
1359 doprint "Assuming that this is a triple fault.\n";
1360 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1361 last;
1362 }
1363 }
1364
Steven Rostedt2545eb62010-11-02 15:01:32 -04001365 if ($line =~ /\n/) {
1366 $full_line = "";
1367 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001368
1369 if ($stop_test_after > 0 && !$booted && !$bug) {
1370 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001371 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001372 $done = 1;
1373 }
1374 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001375 }
1376
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001377 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001378
Steven Rostedt2545eb62010-11-02 15:01:32 -04001379 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001380 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001381 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001382 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001383
Steven Rostedta75fece2010-11-02 14:58:27 -04001384 if (!$booted) {
1385 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001386 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001387 }
1388
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001389 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001390}
1391
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001392sub do_post_install {
1393
1394 return if (!defined($post_install));
1395
1396 my $cp_post_install = $post_install;
1397 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1398 run_command "$cp_post_install" or
1399 dodie "Failed to run post install";
1400}
1401
Steven Rostedt2545eb62010-11-02 15:01:32 -04001402sub install {
1403
Steven Rostedte0a87422011-09-30 17:50:48 -04001404 return if ($no_install);
1405
Steven Rostedte48c5292010-11-02 14:35:37 -04001406 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001407 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001408
1409 my $install_mods = 0;
1410
1411 # should we process modules?
1412 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001413 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001414 while (<IN>) {
1415 if (/CONFIG_MODULES(=y)?/) {
1416 $install_mods = 1 if (defined($1));
1417 last;
1418 }
1419 }
1420 close(IN);
1421
1422 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001423 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001424 doprint "No modules needed\n";
1425 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001426 }
1427
Steven Rostedta75fece2010-11-02 14:58:27 -04001428 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001429 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001430
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001431 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001432 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001433
Steven Rostedte48c5292010-11-02 14:35:37 -04001434 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001435 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001436
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001437 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001438 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001439 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001440
Steven Rostedte48c5292010-11-02 14:35:37 -04001441 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001442 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001443
Steven Rostedta75fece2010-11-02 14:58:27 -04001444 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001445
Steven Rostedte7b13442011-06-14 20:44:36 -04001446 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001447 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001448
Steven Rostedte48c5292010-11-02 14:35:37 -04001449 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001450
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001451 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001452}
1453
Steven Rostedtddf607e2011-06-14 20:49:13 -04001454sub get_version {
1455 # get the release name
1456 doprint "$make kernelrelease ... ";
1457 $version = `$make kernelrelease | tail -1`;
1458 chomp($version);
1459 doprint "$version\n";
1460}
1461
1462sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001463 # Make sure the stable kernel has finished booting
1464 start_monitor;
1465 wait_for_monitor 5;
1466 end_monitor;
1467
Steven Rostedtddf607e2011-06-14 20:49:13 -04001468 get_grub_index;
1469 get_version;
1470 install;
1471
1472 start_monitor;
1473 return monitor;
1474}
1475
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001476sub check_buildlog {
1477 my ($patch) = @_;
1478
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001479 my @files = `git show $patch | diffstat -l`;
1480
1481 open(IN, "git show $patch |") or
1482 dodie "failed to show $patch";
1483 while (<IN>) {
1484 if (m,^--- a/(.*),) {
1485 chomp $1;
1486 $files[$#files] = $1;
1487 }
1488 }
1489 close(IN);
1490
1491 open(IN, $buildlog) or dodie "Can't open $buildlog";
1492 while (<IN>) {
1493 if (/^\s*(.*?):.*(warning|error)/) {
1494 my $err = $1;
1495 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001496 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001497 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001498 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001499 }
1500 }
1501 }
1502 }
1503 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001504
1505 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001506}
1507
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001508sub apply_min_config {
1509 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001510
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001511 # Read the config file and remove anything that
1512 # is in the force_config hash (from minconfig and others)
1513 # then add the force config back.
1514
1515 doprint "Applying minimum configurations into $output_config.new\n";
1516
1517 open (OUT, ">$outconfig") or
1518 dodie "Can't create $outconfig";
1519
1520 if (-f $output_config) {
1521 open (IN, $output_config) or
1522 dodie "Failed to open $output_config";
1523 while (<IN>) {
1524 if (/^(# )?(CONFIG_[^\s=]*)/) {
1525 next if (defined($force_config{$2}));
1526 }
1527 print OUT;
1528 }
1529 close IN;
1530 }
1531 foreach my $config (keys %force_config) {
1532 print OUT "$force_config{$config}\n";
1533 }
1534 close OUT;
1535
1536 run_command "mv $outconfig $output_config";
1537}
1538
1539sub make_oldconfig {
1540
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001541 my @force_list = keys %force_config;
1542
1543 if ($#force_list >= 0) {
1544 apply_min_config;
1545 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001546
1547 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001548 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1549 # try a yes '' | oldconfig
1550 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001551 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001552 dodie "failed make config oldconfig";
1553 }
1554}
1555
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001556# read a config file and use this to force new configs.
1557sub load_force_config {
1558 my ($config) = @_;
1559
1560 open(IN, $config) or
1561 dodie "failed to read $config";
1562 while (<IN>) {
1563 chomp;
1564 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1565 $force_config{$1} = $_;
1566 } elsif (/^# (CONFIG_\S*) is not set/) {
1567 $force_config{$1} = $_;
1568 }
1569 }
1570 close IN;
1571}
1572
Steven Rostedt2545eb62010-11-02 15:01:32 -04001573sub build {
1574 my ($type) = @_;
1575
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001576 unlink $buildlog;
1577
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001578 # Failed builds should not reboot the target
1579 my $save_no_reboot = $no_reboot;
1580 $no_reboot = 1;
1581
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001582 if (defined($pre_build)) {
1583 my $ret = run_command $pre_build;
1584 if (!$ret && defined($pre_build_die) &&
1585 $pre_build_die) {
1586 dodie "failed to pre_build\n";
1587 }
1588 }
1589
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001590 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001591 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001592 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001593
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001594 $type = "oldconfig";
1595 }
1596
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001597 # old config can ask questions
1598 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001599 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001600
1601 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001602 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001603
Andrew Jones13488232011-08-12 15:32:04 +02001604 if (!$noclean) {
1605 run_command "mv $output_config $outputdir/config_temp" or
1606 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001607
Andrew Jones13488232011-08-12 15:32:04 +02001608 run_command "$make mrproper" or dodie "make mrproper";
1609
1610 run_command "mv $outputdir/config_temp $output_config" or
1611 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001612 }
1613
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001614 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001615 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001616 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001617 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001618 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001619
1620 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001621 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1622 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001623 close(OUT);
1624
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001625 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001626 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001627 }
1628
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001629 if ($type ne "oldnoconfig") {
1630 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001631 dodie "failed make config";
1632 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001633 # Run old config regardless, to enforce min configurations
1634 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001635
Steven Rostedta75fece2010-11-02 14:58:27 -04001636 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001637 my $build_ret = run_command "$make $build_options";
1638 undef $redirect;
1639
1640 if (defined($post_build)) {
1641 my $ret = run_command $post_build;
1642 if (!$ret && defined($post_build_die) &&
1643 $post_build_die) {
1644 dodie "failed to post_build\n";
1645 }
1646 }
1647
1648 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001649 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001650 if ($in_bisect) {
1651 $no_reboot = $save_no_reboot;
1652 return 0;
1653 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001654 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001655 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001656
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001657 $no_reboot = $save_no_reboot;
1658
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001659 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001660}
1661
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001662sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001663 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001664 if (defined($poweroff_after_halt)) {
1665 sleep $poweroff_after_halt;
1666 run_command "$power_off";
1667 }
1668 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001669 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001670 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001671 }
1672}
1673
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001674sub success {
1675 my ($i) = @_;
1676
Steven Rostedte48c5292010-11-02 14:35:37 -04001677 $successes++;
1678
Steven Rostedt9064af52011-06-13 10:38:48 -04001679 my $name = "";
1680
1681 if (defined($test_name)) {
1682 $name = " ($test_name)";
1683 }
1684
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001685 doprint "\n\n*******************************************\n";
1686 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001687 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001688 doprint "*******************************************\n";
1689 doprint "*******************************************\n";
1690
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301691 if (defined($store_successes)) {
1692 save_logs "success", $store_successes;
1693 }
1694
Steven Rostedt576f6272010-11-02 14:58:38 -04001695 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001696 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001697 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001698 }
1699}
1700
Steven Rostedtc960bb92011-03-08 09:22:39 -05001701sub answer_bisect {
1702 for (;;) {
1703 doprint "Pass or fail? [p/f]";
1704 my $ans = <STDIN>;
1705 chomp $ans;
1706 if ($ans eq "p" || $ans eq "P") {
1707 return 1;
1708 } elsif ($ans eq "f" || $ans eq "F") {
1709 return 0;
1710 } else {
1711 print "Please answer 'P' or 'F'\n";
1712 }
1713 }
1714}
1715
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001716sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001717 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001718
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001719 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001720 $reboot_on_error = 0;
1721 $poweroff_on_error = 0;
1722 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001723
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301724 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001725 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301726 undef $redirect;
1727
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001728 exit $failed;
1729}
1730
1731my $child_done;
1732
1733sub child_finished {
1734 $child_done = 1;
1735}
1736
1737sub do_run_test {
1738 my $child_pid;
1739 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001740 my $line;
1741 my $full_line;
1742 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001743
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001744 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001745
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001746 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001747
1748 $child_done = 0;
1749
1750 $SIG{CHLD} = qw(child_finished);
1751
1752 $child_pid = fork;
1753
1754 child_run_test if (!$child_pid);
1755
1756 $full_line = "";
1757
1758 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001759 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001760 if (defined($line)) {
1761
1762 # we are not guaranteed to get a full line
1763 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001764 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001765
1766 if ($full_line =~ /call trace:/i) {
1767 $bug = 1;
1768 }
1769
1770 if ($full_line =~ /Kernel panic -/) {
1771 $bug = 1;
1772 }
1773
1774 if ($line =~ /\n/) {
1775 $full_line = "";
1776 }
1777 }
1778 } while (!$child_done && !$bug);
1779
1780 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001781 my $failure_start = time;
1782 my $now;
1783 do {
1784 $line = wait_for_input($monitor_fp, 1);
1785 if (defined($line)) {
1786 doprint $line;
1787 }
1788 $now = time;
1789 if ($now - $failure_start >= $stop_after_failure) {
1790 last;
1791 }
1792 } while (defined($line));
1793
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001794 doprint "Detected kernel crash!\n";
1795 # kill the child with extreme prejudice
1796 kill 9, $child_pid;
1797 }
1798
1799 waitpid $child_pid, 0;
1800 $child_exit = $?;
1801
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001802 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001803 return 0 if $in_bisect;
1804 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001805 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001806 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001807}
1808
Steven Rostedta75fece2010-11-02 14:58:27 -04001809sub run_git_bisect {
1810 my ($command) = @_;
1811
1812 doprint "$command ... ";
1813
1814 my $output = `$command 2>&1`;
1815 my $ret = $?;
1816
1817 logit $output;
1818
1819 if ($ret) {
1820 doprint "FAILED\n";
1821 dodie "Failed to git bisect";
1822 }
1823
1824 doprint "SUCCESS\n";
1825 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1826 doprint "$1 [$2]\n";
1827 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1828 $bisect_bad = $1;
1829 doprint "Found bad commit... $1\n";
1830 return 0;
1831 } else {
1832 # we already logged it, just print it now.
1833 print $output;
1834 }
1835
1836 return 1;
1837}
1838
Steven Rostedtc23dca72011-03-08 09:26:31 -05001839sub bisect_reboot {
1840 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001841 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001842}
1843
1844# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001845sub run_bisect_test {
1846 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001847
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001848 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001849 my $result;
1850 my $output;
1851 my $ret;
1852
Steven Rostedt0a05c762010-11-08 11:14:10 -05001853 $in_bisect = 1;
1854
1855 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001856
1857 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001858 if ($failed && $bisect_skip) {
1859 $in_bisect = 0;
1860 return -1;
1861 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001862 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001863
1864 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001865 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001866
1867 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001868 if ($failed && $bisect_skip) {
1869 end_monitor;
1870 bisect_reboot;
1871 $in_bisect = 0;
1872 return -1;
1873 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001874 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001875
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001876 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001877 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001878 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001879 }
1880
1881 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001882 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001883 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001884 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001885 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001886
1887 # reboot the box to a kernel we can ssh to
1888 if ($type ne "build") {
1889 bisect_reboot;
1890 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001891 $in_bisect = 0;
1892
1893 return $result;
1894}
1895
1896sub run_bisect {
1897 my ($type) = @_;
1898 my $buildtype = "oldconfig";
1899
1900 # We should have a minconfig to use?
1901 if (defined($minconfig)) {
1902 $buildtype = "useconfig:$minconfig";
1903 }
1904
1905 my $ret = run_bisect_test $type, $buildtype;
1906
Steven Rostedtc960bb92011-03-08 09:22:39 -05001907 if ($bisect_manual) {
1908 $ret = answer_bisect;
1909 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001910
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001911 # Are we looking for where it worked, not failed?
1912 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001913 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001914 }
1915
Steven Rostedtc23dca72011-03-08 09:26:31 -05001916 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001917 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001918 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001919 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001920 } elsif ($bisect_skip) {
1921 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1922 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001923 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001924}
1925
Steven Rostedtdad98752011-11-22 20:48:57 -05001926sub update_bisect_replay {
1927 my $tmp_log = "$tmpdir/ktest_bisect_log";
1928 run_command "git bisect log > $tmp_log" or
1929 die "can't create bisect log";
1930 return $tmp_log;
1931}
1932
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001933sub bisect {
1934 my ($i) = @_;
1935
1936 my $result;
1937
1938 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1939 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1940 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1941
1942 my $good = $opt{"BISECT_GOOD[$i]"};
1943 my $bad = $opt{"BISECT_BAD[$i]"};
1944 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001945 my $start = $opt{"BISECT_START[$i]"};
1946 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001947 my $start_files = $opt{"BISECT_FILES[$i]"};
1948
1949 if (defined($start_files)) {
1950 $start_files = " -- " . $start_files;
1951 } else {
1952 $start_files = "";
1953 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001954
Steven Rostedta57419b2010-11-02 15:13:54 -04001955 # convert to true sha1's
1956 $good = get_sha1($good);
1957 $bad = get_sha1($bad);
1958
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001959 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1960 $opt{"BISECT_REVERSE[$i]"} == 1) {
1961 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1962 $reverse_bisect = 1;
1963 } else {
1964 $reverse_bisect = 0;
1965 }
1966
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001967 # Can't have a test without having a test to run
1968 if ($type eq "test" && !defined($run_test)) {
1969 $type = "boot";
1970 }
1971
Steven Rostedtdad98752011-11-22 20:48:57 -05001972 # Check if a bisect was running
1973 my $bisect_start_file = "$builddir/.git/BISECT_START";
1974
Steven Rostedta75fece2010-11-02 14:58:27 -04001975 my $check = $opt{"BISECT_CHECK[$i]"};
Steven Rostedtdad98752011-11-22 20:48:57 -05001976 my $do_check = defined($check) && $check ne "0";
1977
1978 if ( -f $bisect_start_file ) {
1979 print "Bisect in progress found\n";
1980 if ($do_check) {
1981 print " If you say yes, then no checks of good or bad will be done\n";
1982 }
1983 if (defined($replay)) {
1984 print "** BISECT_REPLAY is defined in config file **";
1985 print " Ignore config option and perform new git bisect log?\n";
1986 if (read_ync " (yes, no, or cancel) ") {
1987 $replay = update_bisect_replay;
1988 $do_check = 0;
1989 }
1990 } elsif (read_yn "read git log and continue?") {
1991 $replay = update_bisect_replay;
1992 $do_check = 0;
1993 }
1994 }
1995
1996 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001997
1998 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001999 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002000
2001 if ($check ne "good") {
2002 doprint "TESTING BISECT BAD [$bad]\n";
2003 run_command "git checkout $bad" or
2004 die "Failed to checkout $bad";
2005
2006 $result = run_bisect $type;
2007
2008 if ($result ne "bad") {
2009 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2010 }
2011 }
2012
2013 if ($check ne "bad") {
2014 doprint "TESTING BISECT GOOD [$good]\n";
2015 run_command "git checkout $good" or
2016 die "Failed to checkout $good";
2017
2018 $result = run_bisect $type;
2019
2020 if ($result ne "good") {
2021 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2022 }
2023 }
2024
2025 # checkout where we started
2026 run_command "git checkout $head" or
2027 die "Failed to checkout $head";
2028 }
2029
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002030 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002031 dodie "could not start bisect";
2032
2033 run_command "git bisect good $good" or
2034 dodie "could not set bisect good to $good";
2035
2036 run_git_bisect "git bisect bad $bad" or
2037 dodie "could not set bisect bad to $bad";
2038
2039 if (defined($replay)) {
2040 run_command "git bisect replay $replay" or
2041 dodie "failed to run replay";
2042 }
2043
2044 if (defined($start)) {
2045 run_command "git checkout $start" or
2046 dodie "failed to checkout $start";
2047 }
2048
2049 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002050 do {
2051 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002052 $test = run_git_bisect "git bisect $result";
2053 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002054
2055 run_command "git bisect log" or
2056 dodie "could not capture git bisect log";
2057
2058 run_command "git bisect reset" or
2059 dodie "could not reset git bisect";
2060
2061 doprint "Bad commit was [$bisect_bad]\n";
2062
Steven Rostedt0a05c762010-11-08 11:14:10 -05002063 success $i;
2064}
2065
2066my %config_ignore;
2067my %config_set;
2068
2069my %config_list;
2070my %null_config;
2071
2072my %dependency;
2073
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002074sub assign_configs {
2075 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002076
2077 open (IN, $config)
2078 or dodie "Failed to read $config";
2079
2080 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002081 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002082 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002083 }
2084 }
2085
2086 close(IN);
2087}
2088
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002089sub process_config_ignore {
2090 my ($config) = @_;
2091
2092 assign_configs \%config_ignore, $config;
2093}
2094
Steven Rostedt0a05c762010-11-08 11:14:10 -05002095sub read_current_config {
2096 my ($config_ref) = @_;
2097
2098 %{$config_ref} = ();
2099 undef %{$config_ref};
2100
2101 my @key = keys %{$config_ref};
2102 if ($#key >= 0) {
2103 print "did not delete!\n";
2104 exit;
2105 }
2106 open (IN, "$output_config");
2107
2108 while (<IN>) {
2109 if (/^(CONFIG\S+)=(.*)/) {
2110 ${$config_ref}{$1} = $2;
2111 }
2112 }
2113 close(IN);
2114}
2115
2116sub get_dependencies {
2117 my ($config) = @_;
2118
2119 my $arr = $dependency{$config};
2120 if (!defined($arr)) {
2121 return ();
2122 }
2123
2124 my @deps = @{$arr};
2125
2126 foreach my $dep (@{$arr}) {
2127 print "ADD DEP $dep\n";
2128 @deps = (@deps, get_dependencies $dep);
2129 }
2130
2131 return @deps;
2132}
2133
2134sub create_config {
2135 my @configs = @_;
2136
2137 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2138
2139 foreach my $config (@configs) {
2140 print OUT "$config_set{$config}\n";
2141 my @deps = get_dependencies $config;
2142 foreach my $dep (@deps) {
2143 print OUT "$config_set{$dep}\n";
2144 }
2145 }
2146
2147 foreach my $config (keys %config_ignore) {
2148 print OUT "$config_ignore{$config}\n";
2149 }
2150 close(OUT);
2151
2152# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002153 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002154}
2155
2156sub compare_configs {
2157 my (%a, %b) = @_;
2158
2159 foreach my $item (keys %a) {
2160 if (!defined($b{$item})) {
2161 print "diff $item\n";
2162 return 1;
2163 }
2164 delete $b{$item};
2165 }
2166
2167 my @keys = keys %b;
2168 if ($#keys) {
2169 print "diff2 $keys[0]\n";
2170 }
2171 return -1 if ($#keys >= 0);
2172
2173 return 0;
2174}
2175
2176sub run_config_bisect_test {
2177 my ($type) = @_;
2178
2179 return run_bisect_test $type, "oldconfig";
2180}
2181
2182sub process_passed {
2183 my (%configs) = @_;
2184
2185 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2186 # Passed! All these configs are part of a good compile.
2187 # Add them to the min options.
2188 foreach my $config (keys %configs) {
2189 if (defined($config_list{$config})) {
2190 doprint " removing $config\n";
2191 $config_ignore{$config} = $config_list{$config};
2192 delete $config_list{$config};
2193 }
2194 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002195 doprint "config copied to $outputdir/config_good\n";
2196 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002197}
2198
2199sub process_failed {
2200 my ($config) = @_;
2201
2202 doprint "\n\n***************************************\n";
2203 doprint "Found bad config: $config\n";
2204 doprint "***************************************\n\n";
2205}
2206
2207sub run_config_bisect {
2208
2209 my @start_list = keys %config_list;
2210
2211 if ($#start_list < 0) {
2212 doprint "No more configs to test!!!\n";
2213 return -1;
2214 }
2215
2216 doprint "***** RUN TEST ***\n";
2217 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2218 my $ret;
2219 my %current_config;
2220
2221 my $count = $#start_list + 1;
2222 doprint " $count configs to test\n";
2223
2224 my $half = int($#start_list / 2);
2225
2226 do {
2227 my @tophalf = @start_list[0 .. $half];
2228
2229 create_config @tophalf;
2230 read_current_config \%current_config;
2231
2232 $count = $#tophalf + 1;
2233 doprint "Testing $count configs\n";
2234 my $found = 0;
2235 # make sure we test something
2236 foreach my $config (@tophalf) {
2237 if (defined($current_config{$config})) {
2238 logit " $config\n";
2239 $found = 1;
2240 }
2241 }
2242 if (!$found) {
2243 # try the other half
2244 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002245 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002246 create_config @tophalf;
2247 read_current_config \%current_config;
2248 foreach my $config (@tophalf) {
2249 if (defined($current_config{$config})) {
2250 logit " $config\n";
2251 $found = 1;
2252 }
2253 }
2254 if (!$found) {
2255 doprint "Failed: Can't make new config with current configs\n";
2256 foreach my $config (@start_list) {
2257 doprint " CONFIG: $config\n";
2258 }
2259 return -1;
2260 }
2261 $count = $#tophalf + 1;
2262 doprint "Testing $count configs\n";
2263 }
2264
2265 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002266 if ($bisect_manual) {
2267 $ret = answer_bisect;
2268 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002269 if ($ret) {
2270 process_passed %current_config;
2271 return 0;
2272 }
2273
2274 doprint "This config had a failure.\n";
2275 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002276 doprint "config copied to $outputdir/config_bad\n";
2277 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002278
2279 # A config exists in this group that was bad.
2280 foreach my $config (keys %config_list) {
2281 if (!defined($current_config{$config})) {
2282 doprint " removing $config\n";
2283 delete $config_list{$config};
2284 }
2285 }
2286
2287 @start_list = @tophalf;
2288
2289 if ($#start_list == 0) {
2290 process_failed $start_list[0];
2291 return 1;
2292 }
2293
2294 # remove half the configs we are looking at and see if
2295 # they are good.
2296 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002297 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002298
Steven Rostedtc960bb92011-03-08 09:22:39 -05002299 # we found a single config, try it again unless we are running manually
2300
2301 if ($bisect_manual) {
2302 process_failed $start_list[0];
2303 return 1;
2304 }
2305
Steven Rostedt0a05c762010-11-08 11:14:10 -05002306 my @tophalf = @start_list[0 .. 0];
2307
2308 $ret = run_config_bisect_test $type;
2309 if ($ret) {
2310 process_passed %current_config;
2311 return 0;
2312 }
2313
2314 process_failed $start_list[0];
2315 return 1;
2316}
2317
2318sub config_bisect {
2319 my ($i) = @_;
2320
2321 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2322
2323 my $tmpconfig = "$tmpdir/use_config";
2324
Steven Rostedt30f75da2011-06-13 10:35:35 -04002325 if (defined($config_bisect_good)) {
2326 process_config_ignore $config_bisect_good;
2327 }
2328
Steven Rostedt0a05c762010-11-08 11:14:10 -05002329 # Make the file with the bad config and the min config
2330 if (defined($minconfig)) {
2331 # read the min config for things to ignore
2332 run_command "cp $minconfig $tmpconfig" or
2333 dodie "failed to copy $minconfig to $tmpconfig";
2334 } else {
2335 unlink $tmpconfig;
2336 }
2337
Steven Rostedt0a05c762010-11-08 11:14:10 -05002338 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002339 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002340 process_config_ignore $tmpconfig;
2341 }
2342
2343 # now process the start config
2344 run_command "cp $start_config $output_config" or
2345 dodie "failed to copy $start_config to $output_config";
2346
2347 # read directly what we want to check
2348 my %config_check;
2349 open (IN, $output_config)
2350 or dodie "faied to open $output_config";
2351
2352 while (<IN>) {
2353 if (/^((CONFIG\S*)=.*)/) {
2354 $config_check{$2} = $1;
2355 }
2356 }
2357 close(IN);
2358
Steven Rostedt250bae82011-07-15 22:05:59 -04002359 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002360 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002361
2362 # check to see what we lost (or gained)
2363 open (IN, $output_config)
2364 or dodie "Failed to read $start_config";
2365
2366 my %removed_configs;
2367 my %added_configs;
2368
2369 while (<IN>) {
2370 if (/^((CONFIG\S*)=.*)/) {
2371 # save off all options
2372 $config_set{$2} = $1;
2373 if (defined($config_check{$2})) {
2374 if (defined($config_ignore{$2})) {
2375 $removed_configs{$2} = $1;
2376 } else {
2377 $config_list{$2} = $1;
2378 }
2379 } elsif (!defined($config_ignore{$2})) {
2380 $added_configs{$2} = $1;
2381 $config_list{$2} = $1;
2382 }
2383 }
2384 }
2385 close(IN);
2386
2387 my @confs = keys %removed_configs;
2388 if ($#confs >= 0) {
2389 doprint "Configs overridden by default configs and removed from check:\n";
2390 foreach my $config (@confs) {
2391 doprint " $config\n";
2392 }
2393 }
2394 @confs = keys %added_configs;
2395 if ($#confs >= 0) {
2396 doprint "Configs appearing in make oldconfig and added:\n";
2397 foreach my $config (@confs) {
2398 doprint " $config\n";
2399 }
2400 }
2401
2402 my %config_test;
2403 my $once = 0;
2404
2405 # Sometimes kconfig does weird things. We must make sure
2406 # that the config we autocreate has everything we need
2407 # to test, otherwise we may miss testing configs, or
2408 # may not be able to create a new config.
2409 # Here we create a config with everything set.
2410 create_config (keys %config_list);
2411 read_current_config \%config_test;
2412 foreach my $config (keys %config_list) {
2413 if (!defined($config_test{$config})) {
2414 if (!$once) {
2415 $once = 1;
2416 doprint "Configs not produced by kconfig (will not be checked):\n";
2417 }
2418 doprint " $config\n";
2419 delete $config_list{$config};
2420 }
2421 }
2422 my $ret;
2423 do {
2424 $ret = run_config_bisect;
2425 } while (!$ret);
2426
2427 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002428
2429 success $i;
2430}
2431
Steven Rostedt27d934b2011-05-20 09:18:18 -04002432sub patchcheck_reboot {
2433 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002434 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002435}
2436
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002437sub patchcheck {
2438 my ($i) = @_;
2439
2440 die "PATCHCHECK_START[$i] not defined\n"
2441 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2442 die "PATCHCHECK_TYPE[$i] not defined\n"
2443 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2444
2445 my $start = $opt{"PATCHCHECK_START[$i]"};
2446
2447 my $end = "HEAD";
2448 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2449 $end = $opt{"PATCHCHECK_END[$i]"};
2450 }
2451
Steven Rostedta57419b2010-11-02 15:13:54 -04002452 # Get the true sha1's since we can use things like HEAD~3
2453 $start = get_sha1($start);
2454 $end = get_sha1($end);
2455
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002456 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2457
2458 # Can't have a test without having a test to run
2459 if ($type eq "test" && !defined($run_test)) {
2460 $type = "boot";
2461 }
2462
2463 open (IN, "git log --pretty=oneline $end|") or
2464 dodie "could not get git list";
2465
2466 my @list;
2467
2468 while (<IN>) {
2469 chomp;
2470 $list[$#list+1] = $_;
2471 last if (/^$start/);
2472 }
2473 close(IN);
2474
2475 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002476 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002477 }
2478
2479 # go backwards in the list
2480 @list = reverse @list;
2481
2482 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002483 my %ignored_warnings;
2484
2485 if (defined($ignore_warnings)) {
2486 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2487 $ignored_warnings{$sha1} = 1;
2488 }
2489 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002490
2491 $in_patchcheck = 1;
2492 foreach my $item (@list) {
2493 my $sha1 = $item;
2494 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2495
2496 doprint "\nProcessing commit $item\n\n";
2497
2498 run_command "git checkout $sha1" or
2499 die "Failed to checkout $sha1";
2500
2501 # only clean on the first and last patch
2502 if ($item eq $list[0] ||
2503 $item eq $list[$#list]) {
2504 $noclean = $save_clean;
2505 } else {
2506 $noclean = 1;
2507 }
2508
2509 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002510 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002511 } else {
2512 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002513 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002514 }
2515
Steven Rostedt19902072011-06-14 20:46:25 -04002516
2517 if (!defined($ignored_warnings{$sha1})) {
2518 check_buildlog $sha1 or return 0;
2519 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002520
2521 next if ($type eq "build");
2522
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002523 my $failed = 0;
2524
Steven Rostedtddf607e2011-06-14 20:49:13 -04002525 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002526
2527 if (!$failed && $type ne "boot"){
2528 do_run_test or $failed = 1;
2529 }
2530 end_monitor;
2531 return 0 if ($failed);
2532
Steven Rostedt27d934b2011-05-20 09:18:18 -04002533 patchcheck_reboot;
2534
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002535 }
2536 $in_patchcheck = 0;
2537 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002538
2539 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002540}
2541
Steven Rostedtb9066f62011-07-15 21:25:24 -04002542my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002543my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002544my $iflevel = 0;
2545my @ifdeps;
2546
2547# prevent recursion
2548my %read_kconfigs;
2549
Steven Rostedtac6974c2011-10-04 09:40:17 -04002550sub add_dep {
2551 # $config depends on $dep
2552 my ($config, $dep) = @_;
2553
2554 if (defined($depends{$config})) {
2555 $depends{$config} .= " " . $dep;
2556 } else {
2557 $depends{$config} = $dep;
2558 }
2559
2560 # record the number of configs depending on $dep
2561 if (defined $depcount{$dep}) {
2562 $depcount{$dep}++;
2563 } else {
2564 $depcount{$dep} = 1;
2565 }
2566}
2567
Steven Rostedtb9066f62011-07-15 21:25:24 -04002568# taken from streamline_config.pl
2569sub read_kconfig {
2570 my ($kconfig) = @_;
2571
2572 my $state = "NONE";
2573 my $config;
2574 my @kconfigs;
2575
2576 my $cont = 0;
2577 my $line;
2578
2579
2580 if (! -f $kconfig) {
2581 doprint "file $kconfig does not exist, skipping\n";
2582 return;
2583 }
2584
2585 open(KIN, "$kconfig")
2586 or die "Can't open $kconfig";
2587 while (<KIN>) {
2588 chomp;
2589
2590 # Make sure that lines ending with \ continue
2591 if ($cont) {
2592 $_ = $line . " " . $_;
2593 }
2594
2595 if (s/\\$//) {
2596 $cont = 1;
2597 $line = $_;
2598 next;
2599 }
2600
2601 $cont = 0;
2602
2603 # collect any Kconfig sources
2604 if (/^source\s*"(.*)"/) {
2605 $kconfigs[$#kconfigs+1] = $1;
2606 }
2607
2608 # configs found
2609 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2610 $state = "NEW";
2611 $config = $2;
2612
2613 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002614 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002615 }
2616
2617 # collect the depends for the config
2618 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2619
Steven Rostedtac6974c2011-10-04 09:40:17 -04002620 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002621
2622 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002623 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2624
2625 # selected by depends on config
2626 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002627
2628 # Check for if statements
2629 } elsif (/^if\s+(.*\S)\s*$/) {
2630 my $deps = $1;
2631 # remove beginning and ending non text
2632 $deps =~ s/^[^a-zA-Z0-9_]*//;
2633 $deps =~ s/[^a-zA-Z0-9_]*$//;
2634
2635 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2636
2637 $ifdeps[$iflevel++] = join ':', @deps;
2638
2639 } elsif (/^endif/) {
2640
2641 $iflevel-- if ($iflevel);
2642
2643 # stop on "help"
2644 } elsif (/^\s*help\s*$/) {
2645 $state = "NONE";
2646 }
2647 }
2648 close(KIN);
2649
2650 # read in any configs that were found.
2651 foreach $kconfig (@kconfigs) {
2652 if (!defined($read_kconfigs{$kconfig})) {
2653 $read_kconfigs{$kconfig} = 1;
2654 read_kconfig("$builddir/$kconfig");
2655 }
2656 }
2657}
2658
2659sub read_depends {
2660 # find out which arch this is by the kconfig file
2661 open (IN, $output_config)
2662 or dodie "Failed to read $output_config";
2663 my $arch;
2664 while (<IN>) {
2665 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2666 $arch = $1;
2667 last;
2668 }
2669 }
2670 close IN;
2671
2672 if (!defined($arch)) {
2673 doprint "Could not find arch from config file\n";
2674 doprint "no dependencies used\n";
2675 return;
2676 }
2677
2678 # arch is really the subarch, we need to know
2679 # what directory to look at.
2680 if ($arch eq "i386" || $arch eq "x86_64") {
2681 $arch = "x86";
2682 } elsif ($arch =~ /^tile/) {
2683 $arch = "tile";
2684 }
2685
2686 my $kconfig = "$builddir/arch/$arch/Kconfig";
2687
2688 if (! -f $kconfig && $arch =~ /\d$/) {
2689 my $orig = $arch;
2690 # some subarchs have numbers, truncate them
2691 $arch =~ s/\d*$//;
2692 $kconfig = "$builddir/arch/$arch/Kconfig";
2693 if (! -f $kconfig) {
2694 doprint "No idea what arch dir $orig is for\n";
2695 doprint "no dependencies used\n";
2696 return;
2697 }
2698 }
2699
2700 read_kconfig($kconfig);
2701}
2702
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002703sub read_config_list {
2704 my ($config) = @_;
2705
2706 open (IN, $config)
2707 or dodie "Failed to read $config";
2708
2709 while (<IN>) {
2710 if (/^((CONFIG\S*)=.*)/) {
2711 if (!defined($config_ignore{$2})) {
2712 $config_list{$2} = $1;
2713 }
2714 }
2715 }
2716
2717 close(IN);
2718}
2719
2720sub read_output_config {
2721 my ($config) = @_;
2722
2723 assign_configs \%config_ignore, $config;
2724}
2725
2726sub make_new_config {
2727 my @configs = @_;
2728
2729 open (OUT, ">$output_config")
2730 or dodie "Failed to write $output_config";
2731
2732 foreach my $config (@configs) {
2733 print OUT "$config\n";
2734 }
2735 close OUT;
2736}
2737
Steven Rostedtac6974c2011-10-04 09:40:17 -04002738sub chomp_config {
2739 my ($config) = @_;
2740
2741 $config =~ s/CONFIG_//;
2742
2743 return $config;
2744}
2745
Steven Rostedtb9066f62011-07-15 21:25:24 -04002746sub get_depends {
2747 my ($dep) = @_;
2748
Steven Rostedtac6974c2011-10-04 09:40:17 -04002749 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002750
2751 $dep = $depends{"$kconfig"};
2752
2753 # the dep string we have saves the dependencies as they
2754 # were found, including expressions like ! && ||. We
2755 # want to split this out into just an array of configs.
2756
2757 my $valid = "A-Za-z_0-9";
2758
2759 my @configs;
2760
2761 while ($dep =~ /[$valid]/) {
2762
2763 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2764 my $conf = "CONFIG_" . $1;
2765
2766 $configs[$#configs + 1] = $conf;
2767
2768 $dep =~ s/^[^$valid]*[$valid]+//;
2769 } else {
2770 die "this should never happen";
2771 }
2772 }
2773
2774 return @configs;
2775}
2776
2777my %min_configs;
2778my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002779my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002780my %processed_configs;
2781my %nochange_config;
2782
2783sub test_this_config {
2784 my ($config) = @_;
2785
2786 my $found;
2787
2788 # if we already processed this config, skip it
2789 if (defined($processed_configs{$config})) {
2790 return undef;
2791 }
2792 $processed_configs{$config} = 1;
2793
2794 # if this config failed during this round, skip it
2795 if (defined($nochange_config{$config})) {
2796 return undef;
2797 }
2798
Steven Rostedtac6974c2011-10-04 09:40:17 -04002799 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002800
2801 # Test dependencies first
2802 if (defined($depends{"$kconfig"})) {
2803 my @parents = get_depends $config;
2804 foreach my $parent (@parents) {
2805 # if the parent is in the min config, check it first
2806 next if (!defined($min_configs{$parent}));
2807 $found = test_this_config($parent);
2808 if (defined($found)) {
2809 return $found;
2810 }
2811 }
2812 }
2813
2814 # Remove this config from the list of configs
2815 # do a make oldnoconfig and then read the resulting
2816 # .config to make sure it is missing the config that
2817 # we had before
2818 my %configs = %min_configs;
2819 delete $configs{$config};
2820 make_new_config ((values %configs), (values %keep_configs));
2821 make_oldconfig;
2822 undef %configs;
2823 assign_configs \%configs, $output_config;
2824
2825 return $config if (!defined($configs{$config}));
2826
2827 doprint "disabling config $config did not change .config\n";
2828
2829 $nochange_config{$config} = 1;
2830
2831 return undef;
2832}
2833
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002834sub make_min_config {
2835 my ($i) = @_;
2836
2837 if (!defined($output_minconfig)) {
2838 fail "OUTPUT_MIN_CONFIG not defined" and return;
2839 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002840
2841 # If output_minconfig exists, and the start_minconfig
2842 # came from min_config, than ask if we should use
2843 # that instead.
2844 if (-f $output_minconfig && !$start_minconfig_defined) {
2845 print "$output_minconfig exists\n";
2846 if (read_yn " Use it as minconfig?") {
2847 $start_minconfig = $output_minconfig;
2848 }
2849 }
2850
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002851 if (!defined($start_minconfig)) {
2852 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2853 }
2854
Steven Rostedt35ce5952011-07-15 21:57:25 -04002855 my $temp_config = "$tmpdir/temp_config";
2856
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002857 # First things first. We build an allnoconfig to find
2858 # out what the defaults are that we can't touch.
2859 # Some are selections, but we really can't handle selections.
2860
2861 my $save_minconfig = $minconfig;
2862 undef $minconfig;
2863
2864 run_command "$make allnoconfig" or return 0;
2865
Steven Rostedtb9066f62011-07-15 21:25:24 -04002866 read_depends;
2867
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002868 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002869
Steven Rostedt43d1b652011-07-15 22:01:56 -04002870 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002871 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002872
2873 if (defined($ignore_config)) {
2874 # make sure the file exists
2875 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002876 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002877 }
2878
Steven Rostedt43d1b652011-07-15 22:01:56 -04002879 %keep_configs = %save_configs;
2880
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002881 doprint "Load initial configs from $start_minconfig\n";
2882
2883 # Look at the current min configs, and save off all the
2884 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002885 assign_configs \%min_configs, $start_minconfig;
2886
2887 my @config_keys = keys %min_configs;
2888
Steven Rostedtac6974c2011-10-04 09:40:17 -04002889 # All configs need a depcount
2890 foreach my $config (@config_keys) {
2891 my $kconfig = chomp_config $config;
2892 if (!defined $depcount{$kconfig}) {
2893 $depcount{$kconfig} = 0;
2894 }
2895 }
2896
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002897 # Remove anything that was set by the make allnoconfig
2898 # we shouldn't need them as they get set for us anyway.
2899 foreach my $config (@config_keys) {
2900 # Remove anything in the ignore_config
2901 if (defined($keep_configs{$config})) {
2902 my $file = $ignore_config;
2903 $file =~ s,.*/(.*?)$,$1,;
2904 doprint "$config set by $file ... ignored\n";
2905 delete $min_configs{$config};
2906 next;
2907 }
2908 # But make sure the settings are the same. If a min config
2909 # sets a selection, we do not want to get rid of it if
2910 # it is not the same as what we have. Just move it into
2911 # the keep configs.
2912 if (defined($config_ignore{$config})) {
2913 if ($config_ignore{$config} ne $min_configs{$config}) {
2914 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2915 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2916 $keep_configs{$config} = $min_configs{$config};
2917 } else {
2918 doprint "$config set by allnoconfig ... ignored\n";
2919 }
2920 delete $min_configs{$config};
2921 }
2922 }
2923
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002924 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002925 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002926
2927 while (!$done) {
2928
2929 my $config;
2930 my $found;
2931
2932 # Now disable each config one by one and do a make oldconfig
2933 # till we find a config that changes our list.
2934
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002935 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002936
2937 # Sort keys by who is most dependent on
2938 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2939 @test_configs ;
2940
2941 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002942 my $reset = 1;
2943 for (my $i = 0; $i < $#test_configs; $i++) {
2944 if (!defined($nochange_config{$test_configs[0]})) {
2945 $reset = 0;
2946 last;
2947 }
2948 # This config didn't change the .config last time.
2949 # Place it at the end
2950 my $config = shift @test_configs;
2951 push @test_configs, $config;
2952 }
2953
2954 # if every test config has failed to modify the .config file
2955 # in the past, then reset and start over.
2956 if ($reset) {
2957 undef %nochange_config;
2958 }
2959
Steven Rostedtb9066f62011-07-15 21:25:24 -04002960 undef %processed_configs;
2961
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002962 foreach my $config (@test_configs) {
2963
Steven Rostedtb9066f62011-07-15 21:25:24 -04002964 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002965
Steven Rostedtb9066f62011-07-15 21:25:24 -04002966 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002967
2968 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002969 }
2970
2971 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002972 # we could have failed due to the nochange_config hash
2973 # reset and try again
2974 if (!$take_two) {
2975 undef %nochange_config;
2976 $take_two = 1;
2977 next;
2978 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002979 doprint "No more configs found that we can disable\n";
2980 $done = 1;
2981 last;
2982 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04002983 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002984
2985 $config = $found;
2986
2987 doprint "Test with $config disabled\n";
2988
2989 # set in_bisect to keep build and monitor from dieing
2990 $in_bisect = 1;
2991
2992 my $failed = 0;
2993 build "oldconfig";
2994 start_monitor_and_boot or $failed = 1;
2995 end_monitor;
2996
2997 $in_bisect = 0;
2998
2999 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003000 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003001 # this config is needed, add it to the ignore list.
3002 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003003 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003004 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003005
3006 # update new ignore configs
3007 if (defined($ignore_config)) {
3008 open (OUT, ">$temp_config")
3009 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003010 foreach my $config (keys %save_configs) {
3011 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003012 }
3013 close OUT;
3014 run_command "mv $temp_config $ignore_config" or
3015 dodie "failed to copy update to $ignore_config";
3016 }
3017
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003018 } else {
3019 # We booted without this config, remove it from the minconfigs.
3020 doprint "$config is not needed, disabling\n";
3021
3022 delete $min_configs{$config};
3023
3024 # Also disable anything that is not enabled in this config
3025 my %configs;
3026 assign_configs \%configs, $output_config;
3027 my @config_keys = keys %min_configs;
3028 foreach my $config (@config_keys) {
3029 if (!defined($configs{$config})) {
3030 doprint "$config is not set, disabling\n";
3031 delete $min_configs{$config};
3032 }
3033 }
3034
3035 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003036 open (OUT, ">$temp_config")
3037 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003038 foreach my $config (keys %keep_configs) {
3039 print OUT "$keep_configs{$config}\n";
3040 }
3041 foreach my $config (keys %min_configs) {
3042 print OUT "$min_configs{$config}\n";
3043 }
3044 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003045
3046 run_command "mv $temp_config $output_minconfig" or
3047 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003048 }
3049
3050 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02003051 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003052 }
3053
3054 success $i;
3055 return 1;
3056}
3057
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003058$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003059
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003060if ($#ARGV == 0) {
3061 $ktest_config = $ARGV[0];
3062 if (! -f $ktest_config) {
3063 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003064 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003065 exit 0;
3066 }
3067 }
3068} else {
3069 $ktest_config = "ktest.conf";
3070}
3071
3072if (! -f $ktest_config) {
3073 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3074 print OUT << "EOF"
3075# Generated by ktest.pl
3076#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003077
3078# PWD is a ktest.pl variable that will result in the process working
3079# directory that ktest.pl is executed in.
3080
3081# THIS_DIR is automatically assigned the PWD of the path that generated
3082# the config file. It is best to use this variable when assigning other
3083# directory paths within this directory. This allows you to easily
3084# move the test cases to other locations or to other machines.
3085#
3086THIS_DIR := $variable{"PWD"}
3087
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003088# Define each test with TEST_START
3089# The config options below it will override the defaults
3090TEST_START
3091
3092DEFAULTS
3093EOF
3094;
3095 close(OUT);
3096}
3097read_config $ktest_config;
3098
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003099if (defined($opt{"LOG_FILE"})) {
3100 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3101}
3102
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003103# Append any configs entered in manually to the config file.
3104my @new_configs = keys %entered_configs;
3105if ($#new_configs >= 0) {
3106 print "\nAppending entered in configs to $ktest_config\n";
3107 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3108 foreach my $config (@new_configs) {
3109 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003110 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003111 }
3112}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003113
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003114if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3115 unlink $opt{"LOG_FILE"};
3116}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003117
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003118doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3119
Steven Rostedta57419b2010-11-02 15:13:54 -04003120for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3121
3122 if (!$i) {
3123 doprint "DEFAULT OPTIONS:\n";
3124 } else {
3125 doprint "\nTEST $i OPTIONS";
3126 if (defined($repeat_tests{$i})) {
3127 $repeat = $repeat_tests{$i};
3128 doprint " ITERATE $repeat";
3129 }
3130 doprint "\n";
3131 }
3132
3133 foreach my $option (sort keys %opt) {
3134
3135 if ($option =~ /\[(\d+)\]$/) {
3136 next if ($i != $1);
3137 } else {
3138 next if ($i);
3139 }
3140
3141 doprint "$option = $opt{$option}\n";
3142 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003143}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003144
Steven Rostedt2a625122011-05-20 15:48:59 -04003145sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003146 my ($name, $i) = @_;
3147
3148 my $option = "$name\[$i\]";
3149
3150 if (defined($opt{$option})) {
3151 return $opt{$option};
3152 }
3153
Steven Rostedta57419b2010-11-02 15:13:54 -04003154 foreach my $test (keys %repeat_tests) {
3155 if ($i >= $test &&
3156 $i < $test + $repeat_tests{$test}) {
3157 $option = "$name\[$test\]";
3158 if (defined($opt{$option})) {
3159 return $opt{$option};
3160 }
3161 }
3162 }
3163
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003164 if (defined($opt{$name})) {
3165 return $opt{$name};
3166 }
3167
3168 return undef;
3169}
3170
Steven Rostedt2a625122011-05-20 15:48:59 -04003171sub set_test_option {
3172 my ($name, $i) = @_;
3173
3174 my $option = __set_test_option($name, $i);
3175 return $option if (!defined($option));
3176
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003177 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003178}
3179
Steven Rostedt2545eb62010-11-02 15:01:32 -04003180# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003181for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003182
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003183 # Do not reboot on failing test options
3184 $no_reboot = 1;
3185
Steven Rostedt576f6272010-11-02 14:58:38 -04003186 $iteration = $i;
3187
Steven Rostedta75fece2010-11-02 14:58:27 -04003188 my $makecmd = set_test_option("MAKE_CMD", $i);
3189
3190 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003191 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003192 $tmpdir = set_test_option("TMP_DIR", $i);
3193 $outputdir = set_test_option("OUTPUT_DIR", $i);
3194 $builddir = set_test_option("BUILD_DIR", $i);
3195 $test_type = set_test_option("TEST_TYPE", $i);
3196 $build_type = set_test_option("BUILD_TYPE", $i);
3197 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003198 $pre_build = set_test_option("PRE_BUILD", $i);
3199 $post_build = set_test_option("POST_BUILD", $i);
3200 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3201 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003202 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003203 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003204 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3205 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003206 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3207 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3208 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003209 $run_test = set_test_option("TEST", $i);
3210 $addconfig = set_test_option("ADD_CONFIG", $i);
3211 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3212 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003213 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003214 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003215 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3216 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3217 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3218 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3219 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003220 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3221 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003222 $sleep_time = set_test_option("SLEEP_TIME", $i);
3223 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003224 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003225 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003226 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003227 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003228 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003229 $store_failures = set_test_option("STORE_FAILURES", $i);
Rabin Vincentde5b6e32011-11-18 17:05:31 +05303230 $store_successes = set_test_option("STORE_SUCCESSES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003231 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003232 $timeout = set_test_option("TIMEOUT", $i);
3233 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3234 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003235 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003236 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003237 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003238 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3239 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003240 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003241 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003242 $ssh_exec = set_test_option("SSH_EXEC", $i);
3243 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003244 $target_image = set_test_option("TARGET_IMAGE", $i);
3245 $localversion = set_test_option("LOCALVERSION", $i);
3246
Steven Rostedt35ce5952011-07-15 21:57:25 -04003247 $start_minconfig_defined = 1;
3248
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003249 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003250 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003251 $start_minconfig = $minconfig;
3252 }
3253
Steven Rostedta75fece2010-11-02 14:58:27 -04003254 chdir $builddir || die "can't change directory to $builddir";
3255
Andrew Jonesa908a662011-08-12 15:32:03 +02003256 foreach my $dir ($tmpdir, $outputdir) {
3257 if (!-d $dir) {
3258 mkpath($dir) or
3259 die "can't create $dir";
3260 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003261 }
3262
Steven Rostedte48c5292010-11-02 14:35:37 -04003263 $ENV{"SSH_USER"} = $ssh_user;
3264 $ENV{"MACHINE"} = $machine;
3265
Steven Rostedta75fece2010-11-02 14:58:27 -04003266 $target = "$ssh_user\@$machine";
3267
3268 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303269 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003270 $dmesg = "$tmpdir/dmesg-$machine";
3271 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003272 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003273
3274 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04003275 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04003276 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04003277 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04003278 }
3279
3280 my $run_type = $build_type;
3281 if ($test_type eq "patchcheck") {
3282 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3283 } elsif ($test_type eq "bisect") {
3284 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003285 } elsif ($test_type eq "config_bisect") {
3286 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003287 }
3288
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003289 if ($test_type eq "make_min_config") {
3290 $run_type = "";
3291 }
3292
Steven Rostedta75fece2010-11-02 14:58:27 -04003293 # mistake in config file?
3294 if (!defined($run_type)) {
3295 $run_type = "ERROR";
3296 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003297
Steven Rostedte0a87422011-09-30 17:50:48 -04003298 my $installme = "";
3299 $installme = " no_install" if ($no_install);
3300
Steven Rostedt2545eb62010-11-02 15:01:32 -04003301 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003302 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003303
3304 unlink $dmesg;
3305 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303306 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003307
Steven Rostedt250bae82011-07-15 22:05:59 -04003308 if (defined($addconfig)) {
3309 my $min = $minconfig;
3310 if (!defined($minconfig)) {
3311 $min = "";
3312 }
3313 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003314 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003315 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003316 }
3317
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003318 my $checkout = $opt{"CHECKOUT[$i]"};
3319 if (defined($checkout)) {
3320 run_command "git checkout $checkout" or
3321 die "failed to checkout $checkout";
3322 }
3323
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003324 $no_reboot = 0;
3325
3326
Steven Rostedta75fece2010-11-02 14:58:27 -04003327 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003328 bisect $i;
3329 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003330 } elsif ($test_type eq "config_bisect") {
3331 config_bisect $i;
3332 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003333 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003334 patchcheck $i;
3335 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003336 } elsif ($test_type eq "make_min_config") {
3337 make_min_config $i;
3338 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003339 }
3340
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003341 if ($build_type ne "nobuild") {
3342 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003343 }
3344
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003345 if ($test_type eq "install") {
3346 get_version;
3347 install;
3348 success $i;
3349 next;
3350 }
3351
Steven Rostedta75fece2010-11-02 14:58:27 -04003352 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003353 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003354 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003355
3356 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3357 do_run_test or $failed = 1;
3358 }
3359 end_monitor;
3360 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003361 }
3362
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003363 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003364}
3365
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003366if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003367 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003368} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003369 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003370}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003371
Steven Rostedte48c5292010-11-02 14:35:37 -04003372doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3373
Steven Rostedt2545eb62010-11-02 15:01:32 -04003374exit 0;