blob: 7159e10ab8a44e7d246f60bbb157e7fbad423e5a [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 Rostedtbb8474b2011-11-23 15:58:00 -050025$default{"TEST_TYPE"} = "build";
Steven Rostedta75fece2010-11-02 14:58:27 -040026$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 Rostedtbb8474b2011-11-23 15:58:00 -0500139# set when a test is something other that just building
140# which would require more options.
141my $buildonly = 1;
142
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500143my %entered_configs;
144my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400145my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400146my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500147
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400148# do not force reboots on config problems
149my $no_reboot = 1;
150
Steven Rostedt7bf51072011-10-22 09:07:03 -0400151# default variables that can be used
152chomp ($variable{"PWD"} = `pwd`);
153
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500154$config_help{"MACHINE"} = << "EOF"
155 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500156 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500157EOF
158 ;
159$config_help{"SSH_USER"} = << "EOF"
160 The box is expected to have ssh on normal bootup, provide the user
161 (most likely root, since you need privileged operations)
162EOF
163 ;
164$config_help{"BUILD_DIR"} = << "EOF"
165 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500166 You can use \${PWD} that will be the path where ktest.pl is run, or use
167 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500168EOF
169 ;
170$config_help{"OUTPUT_DIR"} = << "EOF"
171 The directory that the objects will be built (full path).
172 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500173 You can use \${PWD} that will be the path where ktest.pl is run, or use
174 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500175EOF
176 ;
177$config_help{"BUILD_TARGET"} = << "EOF"
178 The location of the compiled file to copy to the target.
179 (relative to OUTPUT_DIR)
180EOF
181 ;
182$config_help{"TARGET_IMAGE"} = << "EOF"
183 The place to put your image on the test machine.
184EOF
185 ;
186$config_help{"POWER_CYCLE"} = << "EOF"
187 A script or command to reboot the box.
188
189 Here is a digital loggers power switch example
190 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
191
192 Here is an example to reboot a virtual box on the current host
193 with the name "Guest".
194 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
195EOF
196 ;
197$config_help{"CONSOLE"} = << "EOF"
198 The script or command that reads the console
199
200 If you use ttywatch server, something like the following would work.
201CONSOLE = nc -d localhost 3001
202
203 For a virtual machine with guest name "Guest".
204CONSOLE = virsh console Guest
205EOF
206 ;
207$config_help{"LOCALVERSION"} = << "EOF"
208 Required version ending to differentiate the test
209 from other linux builds on the system.
210EOF
211 ;
212$config_help{"REBOOT_TYPE"} = << "EOF"
213 Way to reboot the box to the test kernel.
214 Only valid options so far are "grub" and "script".
215
216 If you specify grub, it will assume grub version 1
217 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
218 and select that target to reboot to the kernel. If this is not
219 your setup, then specify "script" and have a command or script
220 specified in REBOOT_SCRIPT to boot to the target.
221
222 The entry in /boot/grub/menu.lst must be entered in manually.
223 The test will not modify that file.
224EOF
225 ;
226$config_help{"GRUB_MENU"} = << "EOF"
227 The grub title name for the test kernel to boot
228 (Only mandatory if REBOOT_TYPE = grub)
229
230 Note, ktest.pl will not update the grub menu.lst, you need to
231 manually add an option for the test. ktest.pl will search
232 the grub menu.lst for this option to find what kernel to
233 reboot into.
234
235 For example, if in the /boot/grub/menu.lst the test kernel title has:
236 title Test Kernel
237 kernel vmlinuz-test
238 GRUB_MENU = Test Kernel
239EOF
240 ;
241$config_help{"REBOOT_SCRIPT"} = << "EOF"
242 A script to reboot the target into the test kernel
243 (Only mandatory if REBOOT_TYPE = script)
244EOF
245 ;
246
Steven Rostedtdad98752011-11-22 20:48:57 -0500247sub read_prompt {
248 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400249
250 my $ans;
251
252 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500253 if ($cancel) {
254 print "$prompt [y/n/C] ";
255 } else {
256 print "$prompt [Y/n] ";
257 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400258 $ans = <STDIN>;
259 chomp $ans;
260 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500261 if ($cancel) {
262 $ans = "c";
263 } else {
264 $ans = "y";
265 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400266 }
267 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500268 if ($cancel) {
269 last if ($ans =~ /^c$/i);
270 print "Please answer either 'y', 'n' or 'c'.\n";
271 } else {
272 print "Please answer either 'y' or 'n'.\n";
273 }
274 }
275 if ($ans =~ /^c/i) {
276 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400277 }
278 if ($ans !~ /^y$/i) {
279 return 0;
280 }
281 return 1;
282}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500283
Steven Rostedtdad98752011-11-22 20:48:57 -0500284sub read_yn {
285 my ($prompt) = @_;
286
287 return read_prompt 0, $prompt;
288}
289
290sub read_ync {
291 my ($prompt) = @_;
292
293 return read_prompt 1, $prompt;
294}
295
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500296sub get_ktest_config {
297 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400298 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500299
300 return if (defined($opt{$config}));
301
302 if (defined($config_help{$config})) {
303 print "\n";
304 print $config_help{$config};
305 }
306
307 for (;;) {
308 print "$config = ";
309 if (defined($default{$config})) {
310 print "\[$default{$config}\] ";
311 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400312 $ans = <STDIN>;
313 $ans =~ s/^\s*(.*\S)\s*$/$1/;
314 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500315 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400316 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500317 } else {
318 print "Your answer can not be blank\n";
319 next;
320 }
321 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500322 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500323 last;
324 }
325}
326
327sub get_ktest_configs {
328 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500329 get_ktest_config("BUILD_DIR");
330 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500331
332 # options required for other than just building a kernel
333 if (!$buildonly) {
334 get_ktest_config("SSH_USER");
335 get_ktest_config("BUILD_TARGET");
336 get_ktest_config("TARGET_IMAGE");
337 get_ktest_config("POWER_CYCLE");
338 get_ktest_config("CONSOLE");
339 }
340
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500341 get_ktest_config("LOCALVERSION");
342
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500343 return if ($buildonly);
344
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500345 my $rtype = $opt{"REBOOT_TYPE"};
346
347 if (!defined($rtype)) {
348 if (!defined($opt{"GRUB_MENU"})) {
349 get_ktest_config("REBOOT_TYPE");
350 $rtype = $entered_configs{"REBOOT_TYPE"};
351 } else {
352 $rtype = "grub";
353 }
354 }
355
356 if ($rtype eq "grub") {
357 get_ktest_config("GRUB_MENU");
358 } else {
359 get_ktest_config("REBOOT_SCRIPT");
360 }
361}
362
Steven Rostedt77d942c2011-05-20 13:36:58 -0400363sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400364 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400365 my $retval = "";
366
367 # We want to check for '\', and it is just easier
368 # to check the previous characet of '$' and not need
369 # to worry if '$' is the first character. By adding
370 # a space to $value, we can just check [^\\]\$ and
371 # it will still work.
372 $value = " $value";
373
374 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
375 my $begin = $1;
376 my $var = $2;
377 my $end = $3;
378 # append beginning of value to retval
379 $retval = "$retval$begin";
380 if (defined($variable{$var})) {
381 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400382 } elsif (defined($remove_undef) && $remove_undef) {
383 # for if statements, any variable that is not defined,
384 # we simple convert to 0
385 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400386 } else {
387 # put back the origin piece.
388 $retval = "$retval\$\{$var\}";
389 }
390 $value = $end;
391 }
392 $retval = "$retval$value";
393
394 # remove the space added in the beginning
395 $retval =~ s/ //;
396
397 return "$retval"
398}
399
Steven Rostedta57419b2010-11-02 15:13:54 -0400400sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400401 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400402
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500403 if ($lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $rvalue ne "build") {
404 # Note if a test is something other than build, then we
405 # will need other manditory options.
406 $buildonly = 0;
407 }
408
Steven Rostedta57419b2010-11-02 15:13:54 -0400409 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400410 if (!$override || defined(${$overrides}{$lvalue})) {
411 my $extra = "";
412 if ($override) {
413 $extra = "In the same override section!\n";
414 }
415 die "$name: $.: Option $lvalue defined more than once!\n$extra";
416 }
417 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400418 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500419 if ($rvalue =~ /^\s*$/) {
420 delete $opt{$lvalue};
421 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400422 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500423 $opt{$lvalue} = $rvalue;
424 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400425}
426
Steven Rostedt77d942c2011-05-20 13:36:58 -0400427sub set_variable {
428 my ($lvalue, $rvalue) = @_;
429
430 if ($rvalue =~ /^\s*$/) {
431 delete $variable{$lvalue};
432 } else {
433 $rvalue = process_variables($rvalue);
434 $variable{$lvalue} = $rvalue;
435 }
436}
437
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400438sub process_compare {
439 my ($lval, $cmp, $rval) = @_;
440
441 # remove whitespace
442
443 $lval =~ s/^\s*//;
444 $lval =~ s/\s*$//;
445
446 $rval =~ s/^\s*//;
447 $rval =~ s/\s*$//;
448
449 if ($cmp eq "==") {
450 return $lval eq $rval;
451 } elsif ($cmp eq "!=") {
452 return $lval ne $rval;
453 }
454
455 my $statement = "$lval $cmp $rval";
456 my $ret = eval $statement;
457
458 # $@ stores error of eval
459 if ($@) {
460 return -1;
461 }
462
463 return $ret;
464}
465
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400466sub value_defined {
467 my ($val) = @_;
468
469 return defined($variable{$2}) ||
470 defined($opt{$2});
471}
472
Steven Rostedt8d735212011-10-17 11:36:44 -0400473my $d = 0;
474sub process_expression {
475 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400476
Steven Rostedt8d735212011-10-17 11:36:44 -0400477 my $c = $d++;
478
479 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
480 my $express = $1;
481
482 if (process_expression($name, $express)) {
483 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
484 } else {
485 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
486 }
487 }
488
489 $d--;
490 my $OR = "\\|\\|";
491 my $AND = "\\&\\&";
492
493 while ($val =~ s/^(.*?)($OR|$AND)//) {
494 my $express = $1;
495 my $op = $2;
496
497 if (process_expression($name, $express)) {
498 if ($op eq "||") {
499 return 1;
500 }
501 } else {
502 if ($op eq "&&") {
503 return 0;
504 }
505 }
506 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400507
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400508 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
509 my $ret = process_compare($1, $2, $3);
510 if ($ret < 0) {
511 die "$name: $.: Unable to process comparison\n";
512 }
513 return $ret;
514 }
515
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400516 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
517 if (defined $1) {
518 return !value_defined($2);
519 } else {
520 return value_defined($2);
521 }
522 }
523
Steven Rostedt45d73a52011-09-30 19:44:53 -0400524 if ($val =~ /^\s*0\s*$/) {
525 return 0;
526 } elsif ($val =~ /^\s*\d+\s*$/) {
527 return 1;
528 }
529
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400530 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400531}
532
533sub process_if {
534 my ($name, $value) = @_;
535
536 # Convert variables and replace undefined ones with 0
537 my $val = process_variables($value, 1);
538 my $ret = process_expression $name, $val;
539
540 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400541}
542
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400543sub __read_config {
544 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400545
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400546 my $in;
547 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400548
Steven Rostedta57419b2010-11-02 15:13:54 -0400549 my $name = $config;
550 $name =~ s,.*/(.*),$1,;
551
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400552 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400553 my $default = 1;
554 my $repeat = 1;
555 my $num_tests_set = 0;
556 my $skip = 0;
557 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400558 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400559 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400560 my $if = 0;
561 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400562 my $override = 0;
563
564 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400565
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400566 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400567
568 # ignore blank lines and comments
569 next if (/^\s*$/ || /\s*\#/);
570
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400571 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400572
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400573 my $type = $1;
574 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400575 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400576
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400577 my $old_test_num;
578 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400579 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400580
581 if ($type eq "TEST_START") {
582
583 if ($num_tests_set) {
584 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
585 }
586
587 $old_test_num = $test_num;
588 $old_repeat = $repeat;
589
590 $test_num += $repeat;
591 $default = 0;
592 $repeat = 1;
593 } else {
594 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400595 }
596
Steven Rostedta9f84422011-10-17 11:06:29 -0400597 # If SKIP is anywhere in the line, the command will be skipped
598 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400599 $skip = 1;
600 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400601 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400602 $skip = 0;
603 }
604
Steven Rostedta9f84422011-10-17 11:06:29 -0400605 if ($rest =~ s/\sELSE\b//) {
606 if (!$if) {
607 die "$name: $.: ELSE found with out matching IF section\n$_";
608 }
609 $if = 0;
610
611 if ($if_set) {
612 $skip = 1;
613 } else {
614 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400615 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400616 }
617
Steven Rostedta9f84422011-10-17 11:06:29 -0400618 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400619 if (process_if($name, $1)) {
620 $if_set = 1;
621 } else {
622 $skip = 1;
623 }
624 $if = 1;
625 } else {
626 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400627 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400628 }
629
Steven Rostedta9f84422011-10-17 11:06:29 -0400630 if (!$skip) {
631 if ($type eq "TEST_START") {
632 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
633 $repeat = $1;
634 $repeat_tests{"$test_num"} = $repeat;
635 }
636 } elsif ($rest =~ s/\sOVERRIDE\b//) {
637 # DEFAULT only
638 $override = 1;
639 # Clear previous overrides
640 %overrides = ();
641 }
642 }
643
644 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400645 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400646 }
647
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400648 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400649 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400650 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400651 }
652
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400653 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400654 if (!$if) {
655 die "$name: $.: ELSE found with out matching IF section\n$_";
656 }
657 $rest = $1;
658 if ($if_set) {
659 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400660 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400661 } else {
662 $skip = 0;
663
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400664 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400665 # May be a ELSE IF section.
666 if (!process_if($name, $1)) {
667 $skip = 1;
668 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400669 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400670 } else {
671 $if = 0;
672 }
673 }
674
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400675 if ($rest !~ /^\s*$/) {
676 die "$name: $.: Gargbage found after DEFAULTS\n$_";
677 }
678
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400679 } elsif (/^\s*INCLUDE\s+(\S+)/) {
680
681 next if ($skip);
682
683 if (!$default) {
684 die "$name: $.: INCLUDE can only be done in default sections\n$_";
685 }
686
687 my $file = process_variables($1);
688
689 if ($file !~ m,^/,) {
690 # check the path of the config file first
691 if ($config =~ m,(.*)/,) {
692 if (-f "$1/$file") {
693 $file = "$1/$file";
694 }
695 }
696 }
697
698 if ( ! -r $file ) {
699 die "$name: $.: Can't read file $file\n$_";
700 }
701
702 if (__read_config($file, \$test_num)) {
703 $test_case = 1;
704 }
705
Steven Rostedta57419b2010-11-02 15:13:54 -0400706 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
707
708 next if ($skip);
709
Steven Rostedt2545eb62010-11-02 15:01:32 -0400710 my $lvalue = $1;
711 my $rvalue = $2;
712
Steven Rostedta57419b2010-11-02 15:13:54 -0400713 if (!$default &&
714 ($lvalue eq "NUM_TESTS" ||
715 $lvalue eq "LOG_FILE" ||
716 $lvalue eq "CLEAR_LOG")) {
717 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400718 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400719
720 if ($lvalue eq "NUM_TESTS") {
721 if ($test_num) {
722 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
723 }
724 if (!$default) {
725 die "$name: $.: NUM_TESTS must be set in default section\n";
726 }
727 $num_tests_set = 1;
728 }
729
730 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400731 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400732 } else {
733 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400734 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400735
736 if ($repeat > 1) {
737 $repeats{$val} = $repeat;
738 }
739 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400740 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
741 next if ($skip);
742
743 my $lvalue = $1;
744 my $rvalue = $2;
745
746 # process config variables.
747 # Config variables are only active while reading the
748 # config and can be defined anywhere. They also ignore
749 # TEST_START and DEFAULTS, but are skipped if they are in
750 # on of these sections that have SKIP defined.
751 # The save variable can be
752 # defined multiple times and the new one simply overrides
753 # the prevous one.
754 set_variable($lvalue, $rvalue);
755
Steven Rostedta57419b2010-11-02 15:13:54 -0400756 } else {
757 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400758 }
759 }
760
Steven Rostedta57419b2010-11-02 15:13:54 -0400761 if ($test_num) {
762 $test_num += $repeat - 1;
763 $opt{"NUM_TESTS"} = $test_num;
764 }
765
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400766 close($in);
767
768 $$current_test_num = $test_num;
769
770 return $test_case;
771}
772
Steven Rostedtc4261d02011-11-23 13:41:18 -0500773sub get_test_case {
774 print "What test case would you like to run?\n";
775 print " (build, install or boot)\n";
776 print " Other tests are available but require editing the config file\n";
777 my $ans = <STDIN>;
778 chomp $ans;
779 $default{"TEST_TYPE"} = $ans;
780}
781
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400782sub read_config {
783 my ($config) = @_;
784
785 my $test_case;
786 my $test_num = 0;
787
788 $test_case = __read_config $config, \$test_num;
789
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500790 # make sure we have all mandatory configs
791 get_ktest_configs;
792
Steven Rostedt0df213c2011-06-14 20:51:37 -0400793 # was a test specified?
794 if (!$test_case) {
795 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500796 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400797 }
798
Steven Rostedta75fece2010-11-02 14:58:27 -0400799 # set any defaults
800
801 foreach my $default (keys %default) {
802 if (!defined($opt{$default})) {
803 $opt{$default} = $default{$default};
804 }
805 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400806}
807
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400808sub __eval_option {
809 my ($option, $i) = @_;
810
811 # Add space to evaluate the character before $
812 $option = " $option";
813 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530814 my $repeated = 0;
815 my $parent = 0;
816
817 foreach my $test (keys %repeat_tests) {
818 if ($i >= $test &&
819 $i < $test + $repeat_tests{$test}) {
820
821 $repeated = 1;
822 $parent = $test;
823 last;
824 }
825 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400826
827 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
828 my $start = $1;
829 my $var = $2;
830 my $end = $3;
831
832 # Append beginning of line
833 $retval = "$retval$start";
834
835 # If the iteration option OPT[$i] exists, then use that.
836 # otherwise see if the default OPT (without [$i]) exists.
837
838 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530839 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400840
841 if (defined($opt{$o})) {
842 $o = $opt{$o};
843 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530844 } elsif ($repeated && defined($opt{$parento})) {
845 $o = $opt{$parento};
846 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400847 } elsif (defined($opt{$var})) {
848 $o = $opt{$var};
849 $retval = "$retval$o";
850 } else {
851 $retval = "$retval\$\{$var\}";
852 }
853
854 $option = $end;
855 }
856
857 $retval = "$retval$option";
858
859 $retval =~ s/^ //;
860
861 return $retval;
862}
863
864sub eval_option {
865 my ($option, $i) = @_;
866
867 my $prev = "";
868
869 # Since an option can evaluate to another option,
870 # keep iterating until we do not evaluate any more
871 # options.
872 my $r = 0;
873 while ($prev ne $option) {
874 # Check for recursive evaluations.
875 # 100 deep should be more than enough.
876 if ($r++ > 100) {
877 die "Over 100 evaluations accurred with $option\n" .
878 "Check for recursive variables\n";
879 }
880 $prev = $option;
881 $option = __eval_option($option, $i);
882 }
883
884 return $option;
885}
886
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500887sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400888 if (defined($opt{"LOG_FILE"})) {
889 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
890 print OUT @_;
891 close(OUT);
892 }
893}
894
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500895sub logit {
896 if (defined($opt{"LOG_FILE"})) {
897 _logit @_;
898 } else {
899 print @_;
900 }
901}
902
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400903sub doprint {
904 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500905 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400906}
907
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400908sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200909sub start_monitor;
910sub end_monitor;
911sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400912
913sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200914 my ($time) = @_;
915
Steven Rostedt2b803362011-09-30 18:00:23 -0400916 if (defined($time)) {
917 start_monitor;
918 # flush out current monitor
919 # May contain the reboot success line
920 wait_for_monitor 1;
921 }
922
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400923 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400924 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400925 if (defined($powercycle_after_reboot)) {
926 sleep $powercycle_after_reboot;
927 run_command "$power_cycle";
928 }
929 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400930 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400931 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400932 }
Andrew Jones2728be42011-08-12 15:32:05 +0200933
934 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400935 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200936 end_monitor;
937 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400938}
939
Steven Rostedt576f6272010-11-02 14:58:38 -0400940sub do_not_reboot {
941 my $i = $iteration;
942
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400943 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400944 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
945 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
946}
947
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400948sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400949 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400950
Steven Rostedt576f6272010-11-02 14:58:38 -0400951 my $i = $iteration;
952
953 if ($reboot_on_error && !do_not_reboot) {
954
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400955 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400956 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400957
Steven Rostedta75fece2010-11-02 14:58:27 -0400958 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400959 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400960 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400961 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400962
Steven Rostedtf80802c2011-03-07 13:18:47 -0500963 if (defined($opt{"LOG_FILE"})) {
964 print " See $opt{LOG_FILE} for more info.\n";
965 }
966
Steven Rostedt576f6272010-11-02 14:58:38 -0400967 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400968}
969
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400970sub open_console {
971 my ($fp) = @_;
972
973 my $flags;
974
Steven Rostedta75fece2010-11-02 14:58:27 -0400975 my $pid = open($fp, "$console|") or
976 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400977
978 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400979 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400980 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400981 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400982
983 return $pid;
984}
985
986sub close_console {
987 my ($fp, $pid) = @_;
988
989 doprint "kill child process $pid\n";
990 kill 2, $pid;
991
992 print "closing!\n";
993 close($fp);
994}
995
996sub start_monitor {
997 if ($monitor_cnt++) {
998 return;
999 }
1000 $monitor_fp = \*MONFD;
1001 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001002
1003 return;
1004
1005 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001006}
1007
1008sub end_monitor {
1009 if (--$monitor_cnt) {
1010 return;
1011 }
1012 close_console($monitor_fp, $monitor_pid);
1013}
1014
1015sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001016 my ($time, $stop) = @_;
1017 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001018 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001019 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001020
Steven Rostedta75fece2010-11-02 14:58:27 -04001021 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001022
1023 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001024 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001025 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001026 last if (!defined($line));
1027 print "$line";
1028 $full_line .= $line;
1029
1030 if (defined($stop) && $full_line =~ /$stop/) {
1031 doprint "wait for monitor detected $stop\n";
1032 $booted = 1;
1033 }
1034
1035 if ($line =~ /\n/) {
1036 $full_line = "";
1037 }
1038 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001039 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001040}
1041
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301042sub save_logs {
1043 my ($result, $basedir) = @_;
1044 my @t = localtime;
1045 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1046 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1047
1048 my $type = $build_type;
1049 if ($type =~ /useconfig/) {
1050 $type = "useconfig";
1051 }
1052
1053 my $dir = "$machine-$test_type-$type-$result-$date";
1054
1055 $dir = "$basedir/$dir";
1056
1057 if (!-d $dir) {
1058 mkpath($dir) or
1059 die "can't create $dir";
1060 }
1061
1062 my %files = (
1063 "config" => $output_config,
1064 "buildlog" => $buildlog,
1065 "dmesg" => $dmesg,
1066 "testlog" => $testlog,
1067 );
1068
1069 while (my ($name, $source) = each(%files)) {
1070 if (-f "$source") {
1071 cp "$source", "$dir/$name" or
1072 die "failed to copy $source";
1073 }
1074 }
1075
1076 doprint "*** Saved info to $dir ***\n";
1077}
1078
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001079sub fail {
1080
Steven Rostedta75fece2010-11-02 14:58:27 -04001081 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001082 dodie @_;
1083 }
1084
Steven Rostedta75fece2010-11-02 14:58:27 -04001085 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001086
Steven Rostedt576f6272010-11-02 14:58:38 -04001087 my $i = $iteration;
1088
Steven Rostedta75fece2010-11-02 14:58:27 -04001089 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001090 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001091 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001092 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001093 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001094
Steven Rostedt9064af52011-06-13 10:38:48 -04001095 my $name = "";
1096
1097 if (defined($test_name)) {
1098 $name = " ($test_name)";
1099 }
1100
Steven Rostedt576f6272010-11-02 14:58:38 -04001101 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1102 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001103 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001104 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1105 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001106
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301107 if (defined($store_failures)) {
1108 save_logs "fail", $store_failures;
1109 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001110
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001111 return 1;
1112}
1113
Steven Rostedt2545eb62010-11-02 15:01:32 -04001114sub run_command {
1115 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001116 my $dolog = 0;
1117 my $dord = 0;
1118 my $pid;
1119
Steven Rostedte48c5292010-11-02 14:35:37 -04001120 $command =~ s/\$SSH_USER/$ssh_user/g;
1121 $command =~ s/\$MACHINE/$machine/g;
1122
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001123 doprint("$command ... ");
1124
1125 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001126 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001127
1128 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001129 open(LOG, ">>$opt{LOG_FILE}") or
1130 dodie "failed to write to log";
1131 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001132 }
1133
1134 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001135 open (RD, ">$redirect") or
1136 dodie "failed to write to redirect $redirect";
1137 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001138 }
1139
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001140 while (<CMD>) {
1141 print LOG if ($dolog);
1142 print RD if ($dord);
1143 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001144
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001145 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001146 my $failed = $?;
1147
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001148 close(CMD);
1149 close(LOG) if ($dolog);
1150 close(RD) if ($dord);
1151
Steven Rostedt2545eb62010-11-02 15:01:32 -04001152 if ($failed) {
1153 doprint "FAILED!\n";
1154 } else {
1155 doprint "SUCCESS\n";
1156 }
1157
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001158 return !$failed;
1159}
1160
Steven Rostedte48c5292010-11-02 14:35:37 -04001161sub run_ssh {
1162 my ($cmd) = @_;
1163 my $cp_exec = $ssh_exec;
1164
1165 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1166 return run_command "$cp_exec";
1167}
1168
1169sub run_scp {
1170 my ($src, $dst) = @_;
1171 my $cp_scp = $scp_to_target;
1172
1173 $cp_scp =~ s/\$SRC_FILE/$src/g;
1174 $cp_scp =~ s/\$DST_FILE/$dst/g;
1175
1176 return run_command "$cp_scp";
1177}
1178
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001179sub get_grub_index {
1180
Steven Rostedta75fece2010-11-02 14:58:27 -04001181 if ($reboot_type ne "grub") {
1182 return;
1183 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001184 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001185
1186 doprint "Find grub menu ... ";
1187 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001188
1189 my $ssh_grub = $ssh_exec;
1190 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1191
1192 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001193 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001194
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001195 my $found = 0;
1196
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001197 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001198 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001199 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001200 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001201 last;
1202 } elsif (/^\s*title\s/) {
1203 $grub_number++;
1204 }
1205 }
1206 close(IN);
1207
Steven Rostedta75fece2010-11-02 14:58:27 -04001208 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001209 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001210 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001211}
1212
Steven Rostedt2545eb62010-11-02 15:01:32 -04001213sub wait_for_input
1214{
1215 my ($fp, $time) = @_;
1216 my $rin;
1217 my $ready;
1218 my $line;
1219 my $ch;
1220
1221 if (!defined($time)) {
1222 $time = $timeout;
1223 }
1224
1225 $rin = '';
1226 vec($rin, fileno($fp), 1) = 1;
1227 $ready = select($rin, undef, undef, $time);
1228
1229 $line = "";
1230
1231 # try to read one char at a time
1232 while (sysread $fp, $ch, 1) {
1233 $line .= $ch;
1234 last if ($ch eq "\n");
1235 }
1236
1237 if (!length($line)) {
1238 return undef;
1239 }
1240
1241 return $line;
1242}
1243
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001244sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001245 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001246 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1247 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001248 return;
1249 }
1250
1251 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001252}
1253
Steven Rostedta57419b2010-11-02 15:13:54 -04001254sub get_sha1 {
1255 my ($commit) = @_;
1256
1257 doprint "git rev-list --max-count=1 $commit ... ";
1258 my $sha1 = `git rev-list --max-count=1 $commit`;
1259 my $ret = $?;
1260
1261 logit $sha1;
1262
1263 if ($ret) {
1264 doprint "FAILED\n";
1265 dodie "Failed to get git $commit";
1266 }
1267
1268 print "SUCCESS\n";
1269
1270 chomp $sha1;
1271
1272 return $sha1;
1273}
1274
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001275sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001276 my $booted = 0;
1277 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001278 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001279 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001280
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001281 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001282
1283 my $line;
1284 my $full_line = "";
1285
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001286 open(DMESG, "> $dmesg") or
1287 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001288
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001289 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001290
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001291 my $success_start;
1292 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001293 my $monitor_start = time;
1294 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001295 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001296
Steven Rostedt2d01b262011-03-08 09:47:54 -05001297 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001298
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001299 if ($bug && defined($stop_after_failure) &&
1300 $stop_after_failure >= 0) {
1301 my $time = $stop_after_failure - (time - $failure_start);
1302 $line = wait_for_input($monitor_fp, $time);
1303 if (!defined($line)) {
1304 doprint "bug timed out after $booted_timeout seconds\n";
1305 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1306 last;
1307 }
1308 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001309 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001310 if (!defined($line)) {
1311 my $s = $booted_timeout == 1 ? "" : "s";
1312 doprint "Successful boot found: break after $booted_timeout second$s\n";
1313 last;
1314 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001315 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001316 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001317 if (!defined($line)) {
1318 my $s = $timeout == 1 ? "" : "s";
1319 doprint "Timed out after $timeout second$s\n";
1320 last;
1321 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001322 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001323
Steven Rostedt2545eb62010-11-02 15:01:32 -04001324 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001325 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001326
1327 # we are not guaranteed to get a full line
1328 $full_line .= $line;
1329
Steven Rostedta75fece2010-11-02 14:58:27 -04001330 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001331 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001332 $success_start = time;
1333 }
1334
1335 if ($booted && defined($stop_after_success) &&
1336 $stop_after_success >= 0) {
1337 my $now = time;
1338 if ($now - $success_start >= $stop_after_success) {
1339 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1340 last;
1341 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001342 }
1343
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001344 if ($full_line =~ /\[ backtrace testing \]/) {
1345 $skip_call_trace = 1;
1346 }
1347
Steven Rostedt2545eb62010-11-02 15:01:32 -04001348 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001349 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001350 $bug = 1;
1351 $failure_start = time;
1352 }
1353 }
1354
1355 if ($bug && defined($stop_after_failure) &&
1356 $stop_after_failure >= 0) {
1357 my $now = time;
1358 if ($now - $failure_start >= $stop_after_failure) {
1359 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1360 last;
1361 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001362 }
1363
1364 if ($full_line =~ /\[ end of backtrace testing \]/) {
1365 $skip_call_trace = 0;
1366 }
1367
1368 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001369 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001370 $bug = 1;
1371 }
1372
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001373 # Detect triple faults by testing the banner
1374 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1375 if ($1 eq $version) {
1376 $version_found = 1;
1377 } elsif ($version_found && $detect_triplefault) {
1378 # We already booted into the kernel we are testing,
1379 # but now we booted into another kernel?
1380 # Consider this a triple fault.
1381 doprint "Aleady booted in Linux kernel $version, but now\n";
1382 doprint "we booted into Linux kernel $1.\n";
1383 doprint "Assuming that this is a triple fault.\n";
1384 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1385 last;
1386 }
1387 }
1388
Steven Rostedt2545eb62010-11-02 15:01:32 -04001389 if ($line =~ /\n/) {
1390 $full_line = "";
1391 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001392
1393 if ($stop_test_after > 0 && !$booted && !$bug) {
1394 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001395 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001396 $done = 1;
1397 }
1398 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001399 }
1400
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001401 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001402
Steven Rostedt2545eb62010-11-02 15:01:32 -04001403 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001404 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001405 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001406 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001407
Steven Rostedta75fece2010-11-02 14:58:27 -04001408 if (!$booted) {
1409 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001410 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001411 }
1412
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001413 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001414}
1415
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001416sub do_post_install {
1417
1418 return if (!defined($post_install));
1419
1420 my $cp_post_install = $post_install;
1421 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1422 run_command "$cp_post_install" or
1423 dodie "Failed to run post install";
1424}
1425
Steven Rostedt2545eb62010-11-02 15:01:32 -04001426sub install {
1427
Steven Rostedte0a87422011-09-30 17:50:48 -04001428 return if ($no_install);
1429
Steven Rostedte48c5292010-11-02 14:35:37 -04001430 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001431 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001432
1433 my $install_mods = 0;
1434
1435 # should we process modules?
1436 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001437 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001438 while (<IN>) {
1439 if (/CONFIG_MODULES(=y)?/) {
1440 $install_mods = 1 if (defined($1));
1441 last;
1442 }
1443 }
1444 close(IN);
1445
1446 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001447 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001448 doprint "No modules needed\n";
1449 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001450 }
1451
Steven Rostedta75fece2010-11-02 14:58:27 -04001452 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001453 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001454
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001455 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001456 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001457
Steven Rostedte48c5292010-11-02 14:35:37 -04001458 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001459 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001460
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001461 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001462 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001463 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001464
Steven Rostedte48c5292010-11-02 14:35:37 -04001465 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001466 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001467
Steven Rostedta75fece2010-11-02 14:58:27 -04001468 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001469
Steven Rostedte7b13442011-06-14 20:44:36 -04001470 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001471 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001472
Steven Rostedte48c5292010-11-02 14:35:37 -04001473 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001474
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001475 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001476}
1477
Steven Rostedtddf607e2011-06-14 20:49:13 -04001478sub get_version {
1479 # get the release name
1480 doprint "$make kernelrelease ... ";
1481 $version = `$make kernelrelease | tail -1`;
1482 chomp($version);
1483 doprint "$version\n";
1484}
1485
1486sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001487 # Make sure the stable kernel has finished booting
1488 start_monitor;
1489 wait_for_monitor 5;
1490 end_monitor;
1491
Steven Rostedtddf607e2011-06-14 20:49:13 -04001492 get_grub_index;
1493 get_version;
1494 install;
1495
1496 start_monitor;
1497 return monitor;
1498}
1499
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001500sub check_buildlog {
1501 my ($patch) = @_;
1502
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001503 my @files = `git show $patch | diffstat -l`;
1504
1505 open(IN, "git show $patch |") or
1506 dodie "failed to show $patch";
1507 while (<IN>) {
1508 if (m,^--- a/(.*),) {
1509 chomp $1;
1510 $files[$#files] = $1;
1511 }
1512 }
1513 close(IN);
1514
1515 open(IN, $buildlog) or dodie "Can't open $buildlog";
1516 while (<IN>) {
1517 if (/^\s*(.*?):.*(warning|error)/) {
1518 my $err = $1;
1519 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001520 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001521 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001522 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001523 }
1524 }
1525 }
1526 }
1527 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001528
1529 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001530}
1531
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001532sub apply_min_config {
1533 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001534
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001535 # Read the config file and remove anything that
1536 # is in the force_config hash (from minconfig and others)
1537 # then add the force config back.
1538
1539 doprint "Applying minimum configurations into $output_config.new\n";
1540
1541 open (OUT, ">$outconfig") or
1542 dodie "Can't create $outconfig";
1543
1544 if (-f $output_config) {
1545 open (IN, $output_config) or
1546 dodie "Failed to open $output_config";
1547 while (<IN>) {
1548 if (/^(# )?(CONFIG_[^\s=]*)/) {
1549 next if (defined($force_config{$2}));
1550 }
1551 print OUT;
1552 }
1553 close IN;
1554 }
1555 foreach my $config (keys %force_config) {
1556 print OUT "$force_config{$config}\n";
1557 }
1558 close OUT;
1559
1560 run_command "mv $outconfig $output_config";
1561}
1562
1563sub make_oldconfig {
1564
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001565 my @force_list = keys %force_config;
1566
1567 if ($#force_list >= 0) {
1568 apply_min_config;
1569 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001570
1571 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001572 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1573 # try a yes '' | oldconfig
1574 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001575 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001576 dodie "failed make config oldconfig";
1577 }
1578}
1579
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001580# read a config file and use this to force new configs.
1581sub load_force_config {
1582 my ($config) = @_;
1583
1584 open(IN, $config) or
1585 dodie "failed to read $config";
1586 while (<IN>) {
1587 chomp;
1588 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1589 $force_config{$1} = $_;
1590 } elsif (/^# (CONFIG_\S*) is not set/) {
1591 $force_config{$1} = $_;
1592 }
1593 }
1594 close IN;
1595}
1596
Steven Rostedt2545eb62010-11-02 15:01:32 -04001597sub build {
1598 my ($type) = @_;
1599
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001600 unlink $buildlog;
1601
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001602 # Failed builds should not reboot the target
1603 my $save_no_reboot = $no_reboot;
1604 $no_reboot = 1;
1605
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001606 if (defined($pre_build)) {
1607 my $ret = run_command $pre_build;
1608 if (!$ret && defined($pre_build_die) &&
1609 $pre_build_die) {
1610 dodie "failed to pre_build\n";
1611 }
1612 }
1613
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001614 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001615 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001616 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001617
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001618 $type = "oldconfig";
1619 }
1620
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001621 # old config can ask questions
1622 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001623 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001624
1625 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001626 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001627
Andrew Jones13488232011-08-12 15:32:04 +02001628 if (!$noclean) {
1629 run_command "mv $output_config $outputdir/config_temp" or
1630 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001631
Andrew Jones13488232011-08-12 15:32:04 +02001632 run_command "$make mrproper" or dodie "make mrproper";
1633
1634 run_command "mv $outputdir/config_temp $output_config" or
1635 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001636 }
1637
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001638 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001639 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001640 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001641 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001642 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001643
1644 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001645 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1646 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001647 close(OUT);
1648
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001649 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001650 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001651 }
1652
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001653 if ($type ne "oldnoconfig") {
1654 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001655 dodie "failed make config";
1656 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001657 # Run old config regardless, to enforce min configurations
1658 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001659
Steven Rostedta75fece2010-11-02 14:58:27 -04001660 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001661 my $build_ret = run_command "$make $build_options";
1662 undef $redirect;
1663
1664 if (defined($post_build)) {
1665 my $ret = run_command $post_build;
1666 if (!$ret && defined($post_build_die) &&
1667 $post_build_die) {
1668 dodie "failed to post_build\n";
1669 }
1670 }
1671
1672 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001673 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001674 if ($in_bisect) {
1675 $no_reboot = $save_no_reboot;
1676 return 0;
1677 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001678 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001679 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001680
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001681 $no_reboot = $save_no_reboot;
1682
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001683 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001684}
1685
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001686sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001687 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001688 if (defined($poweroff_after_halt)) {
1689 sleep $poweroff_after_halt;
1690 run_command "$power_off";
1691 }
1692 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001693 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001694 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001695 }
1696}
1697
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001698sub success {
1699 my ($i) = @_;
1700
Steven Rostedte48c5292010-11-02 14:35:37 -04001701 $successes++;
1702
Steven Rostedt9064af52011-06-13 10:38:48 -04001703 my $name = "";
1704
1705 if (defined($test_name)) {
1706 $name = " ($test_name)";
1707 }
1708
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001709 doprint "\n\n*******************************************\n";
1710 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001711 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001712 doprint "*******************************************\n";
1713 doprint "*******************************************\n";
1714
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301715 if (defined($store_successes)) {
1716 save_logs "success", $store_successes;
1717 }
1718
Steven Rostedt576f6272010-11-02 14:58:38 -04001719 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001720 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001721 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001722 }
1723}
1724
Steven Rostedtc960bb92011-03-08 09:22:39 -05001725sub answer_bisect {
1726 for (;;) {
1727 doprint "Pass or fail? [p/f]";
1728 my $ans = <STDIN>;
1729 chomp $ans;
1730 if ($ans eq "p" || $ans eq "P") {
1731 return 1;
1732 } elsif ($ans eq "f" || $ans eq "F") {
1733 return 0;
1734 } else {
1735 print "Please answer 'P' or 'F'\n";
1736 }
1737 }
1738}
1739
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001740sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001741 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001742
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001743 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001744 $reboot_on_error = 0;
1745 $poweroff_on_error = 0;
1746 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001747
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301748 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001749 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301750 undef $redirect;
1751
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001752 exit $failed;
1753}
1754
1755my $child_done;
1756
1757sub child_finished {
1758 $child_done = 1;
1759}
1760
1761sub do_run_test {
1762 my $child_pid;
1763 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001764 my $line;
1765 my $full_line;
1766 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001767
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001768 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001769
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001770 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001771
1772 $child_done = 0;
1773
1774 $SIG{CHLD} = qw(child_finished);
1775
1776 $child_pid = fork;
1777
1778 child_run_test if (!$child_pid);
1779
1780 $full_line = "";
1781
1782 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001783 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001784 if (defined($line)) {
1785
1786 # we are not guaranteed to get a full line
1787 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001788 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001789
1790 if ($full_line =~ /call trace:/i) {
1791 $bug = 1;
1792 }
1793
1794 if ($full_line =~ /Kernel panic -/) {
1795 $bug = 1;
1796 }
1797
1798 if ($line =~ /\n/) {
1799 $full_line = "";
1800 }
1801 }
1802 } while (!$child_done && !$bug);
1803
1804 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001805 my $failure_start = time;
1806 my $now;
1807 do {
1808 $line = wait_for_input($monitor_fp, 1);
1809 if (defined($line)) {
1810 doprint $line;
1811 }
1812 $now = time;
1813 if ($now - $failure_start >= $stop_after_failure) {
1814 last;
1815 }
1816 } while (defined($line));
1817
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001818 doprint "Detected kernel crash!\n";
1819 # kill the child with extreme prejudice
1820 kill 9, $child_pid;
1821 }
1822
1823 waitpid $child_pid, 0;
1824 $child_exit = $?;
1825
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001826 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001827 return 0 if $in_bisect;
1828 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001829 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001830 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001831}
1832
Steven Rostedta75fece2010-11-02 14:58:27 -04001833sub run_git_bisect {
1834 my ($command) = @_;
1835
1836 doprint "$command ... ";
1837
1838 my $output = `$command 2>&1`;
1839 my $ret = $?;
1840
1841 logit $output;
1842
1843 if ($ret) {
1844 doprint "FAILED\n";
1845 dodie "Failed to git bisect";
1846 }
1847
1848 doprint "SUCCESS\n";
1849 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1850 doprint "$1 [$2]\n";
1851 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1852 $bisect_bad = $1;
1853 doprint "Found bad commit... $1\n";
1854 return 0;
1855 } else {
1856 # we already logged it, just print it now.
1857 print $output;
1858 }
1859
1860 return 1;
1861}
1862
Steven Rostedtc23dca72011-03-08 09:26:31 -05001863sub bisect_reboot {
1864 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001865 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001866}
1867
1868# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001869sub run_bisect_test {
1870 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001871
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001872 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001873 my $result;
1874 my $output;
1875 my $ret;
1876
Steven Rostedt0a05c762010-11-08 11:14:10 -05001877 $in_bisect = 1;
1878
1879 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001880
1881 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001882 if ($failed && $bisect_skip) {
1883 $in_bisect = 0;
1884 return -1;
1885 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001886 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001887
1888 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001889 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001890
1891 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001892 if ($failed && $bisect_skip) {
1893 end_monitor;
1894 bisect_reboot;
1895 $in_bisect = 0;
1896 return -1;
1897 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001898 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001899
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001900 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001901 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001902 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001903 }
1904
1905 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001906 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001907 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001908 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001909 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001910
1911 # reboot the box to a kernel we can ssh to
1912 if ($type ne "build") {
1913 bisect_reboot;
1914 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001915 $in_bisect = 0;
1916
1917 return $result;
1918}
1919
1920sub run_bisect {
1921 my ($type) = @_;
1922 my $buildtype = "oldconfig";
1923
1924 # We should have a minconfig to use?
1925 if (defined($minconfig)) {
1926 $buildtype = "useconfig:$minconfig";
1927 }
1928
1929 my $ret = run_bisect_test $type, $buildtype;
1930
Steven Rostedtc960bb92011-03-08 09:22:39 -05001931 if ($bisect_manual) {
1932 $ret = answer_bisect;
1933 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001934
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001935 # Are we looking for where it worked, not failed?
1936 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001937 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001938 }
1939
Steven Rostedtc23dca72011-03-08 09:26:31 -05001940 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001941 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001942 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001943 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001944 } elsif ($bisect_skip) {
1945 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1946 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001947 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001948}
1949
Steven Rostedtdad98752011-11-22 20:48:57 -05001950sub update_bisect_replay {
1951 my $tmp_log = "$tmpdir/ktest_bisect_log";
1952 run_command "git bisect log > $tmp_log" or
1953 die "can't create bisect log";
1954 return $tmp_log;
1955}
1956
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001957sub bisect {
1958 my ($i) = @_;
1959
1960 my $result;
1961
1962 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1963 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1964 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1965
1966 my $good = $opt{"BISECT_GOOD[$i]"};
1967 my $bad = $opt{"BISECT_BAD[$i]"};
1968 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001969 my $start = $opt{"BISECT_START[$i]"};
1970 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001971 my $start_files = $opt{"BISECT_FILES[$i]"};
1972
1973 if (defined($start_files)) {
1974 $start_files = " -- " . $start_files;
1975 } else {
1976 $start_files = "";
1977 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001978
Steven Rostedta57419b2010-11-02 15:13:54 -04001979 # convert to true sha1's
1980 $good = get_sha1($good);
1981 $bad = get_sha1($bad);
1982
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001983 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1984 $opt{"BISECT_REVERSE[$i]"} == 1) {
1985 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1986 $reverse_bisect = 1;
1987 } else {
1988 $reverse_bisect = 0;
1989 }
1990
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001991 # Can't have a test without having a test to run
1992 if ($type eq "test" && !defined($run_test)) {
1993 $type = "boot";
1994 }
1995
Steven Rostedtdad98752011-11-22 20:48:57 -05001996 # Check if a bisect was running
1997 my $bisect_start_file = "$builddir/.git/BISECT_START";
1998
Steven Rostedta75fece2010-11-02 14:58:27 -04001999 my $check = $opt{"BISECT_CHECK[$i]"};
Steven Rostedtdad98752011-11-22 20:48:57 -05002000 my $do_check = defined($check) && $check ne "0";
2001
2002 if ( -f $bisect_start_file ) {
2003 print "Bisect in progress found\n";
2004 if ($do_check) {
2005 print " If you say yes, then no checks of good or bad will be done\n";
2006 }
2007 if (defined($replay)) {
2008 print "** BISECT_REPLAY is defined in config file **";
2009 print " Ignore config option and perform new git bisect log?\n";
2010 if (read_ync " (yes, no, or cancel) ") {
2011 $replay = update_bisect_replay;
2012 $do_check = 0;
2013 }
2014 } elsif (read_yn "read git log and continue?") {
2015 $replay = update_bisect_replay;
2016 $do_check = 0;
2017 }
2018 }
2019
2020 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002021
2022 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002023 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002024
2025 if ($check ne "good") {
2026 doprint "TESTING BISECT BAD [$bad]\n";
2027 run_command "git checkout $bad" or
2028 die "Failed to checkout $bad";
2029
2030 $result = run_bisect $type;
2031
2032 if ($result ne "bad") {
2033 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2034 }
2035 }
2036
2037 if ($check ne "bad") {
2038 doprint "TESTING BISECT GOOD [$good]\n";
2039 run_command "git checkout $good" or
2040 die "Failed to checkout $good";
2041
2042 $result = run_bisect $type;
2043
2044 if ($result ne "good") {
2045 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2046 }
2047 }
2048
2049 # checkout where we started
2050 run_command "git checkout $head" or
2051 die "Failed to checkout $head";
2052 }
2053
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002054 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002055 dodie "could not start bisect";
2056
2057 run_command "git bisect good $good" or
2058 dodie "could not set bisect good to $good";
2059
2060 run_git_bisect "git bisect bad $bad" or
2061 dodie "could not set bisect bad to $bad";
2062
2063 if (defined($replay)) {
2064 run_command "git bisect replay $replay" or
2065 dodie "failed to run replay";
2066 }
2067
2068 if (defined($start)) {
2069 run_command "git checkout $start" or
2070 dodie "failed to checkout $start";
2071 }
2072
2073 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002074 do {
2075 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002076 $test = run_git_bisect "git bisect $result";
2077 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002078
2079 run_command "git bisect log" or
2080 dodie "could not capture git bisect log";
2081
2082 run_command "git bisect reset" or
2083 dodie "could not reset git bisect";
2084
2085 doprint "Bad commit was [$bisect_bad]\n";
2086
Steven Rostedt0a05c762010-11-08 11:14:10 -05002087 success $i;
2088}
2089
2090my %config_ignore;
2091my %config_set;
2092
2093my %config_list;
2094my %null_config;
2095
2096my %dependency;
2097
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002098sub assign_configs {
2099 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002100
2101 open (IN, $config)
2102 or dodie "Failed to read $config";
2103
2104 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002105 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002106 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002107 }
2108 }
2109
2110 close(IN);
2111}
2112
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002113sub process_config_ignore {
2114 my ($config) = @_;
2115
2116 assign_configs \%config_ignore, $config;
2117}
2118
Steven Rostedt0a05c762010-11-08 11:14:10 -05002119sub read_current_config {
2120 my ($config_ref) = @_;
2121
2122 %{$config_ref} = ();
2123 undef %{$config_ref};
2124
2125 my @key = keys %{$config_ref};
2126 if ($#key >= 0) {
2127 print "did not delete!\n";
2128 exit;
2129 }
2130 open (IN, "$output_config");
2131
2132 while (<IN>) {
2133 if (/^(CONFIG\S+)=(.*)/) {
2134 ${$config_ref}{$1} = $2;
2135 }
2136 }
2137 close(IN);
2138}
2139
2140sub get_dependencies {
2141 my ($config) = @_;
2142
2143 my $arr = $dependency{$config};
2144 if (!defined($arr)) {
2145 return ();
2146 }
2147
2148 my @deps = @{$arr};
2149
2150 foreach my $dep (@{$arr}) {
2151 print "ADD DEP $dep\n";
2152 @deps = (@deps, get_dependencies $dep);
2153 }
2154
2155 return @deps;
2156}
2157
2158sub create_config {
2159 my @configs = @_;
2160
2161 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2162
2163 foreach my $config (@configs) {
2164 print OUT "$config_set{$config}\n";
2165 my @deps = get_dependencies $config;
2166 foreach my $dep (@deps) {
2167 print OUT "$config_set{$dep}\n";
2168 }
2169 }
2170
2171 foreach my $config (keys %config_ignore) {
2172 print OUT "$config_ignore{$config}\n";
2173 }
2174 close(OUT);
2175
2176# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002177 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002178}
2179
2180sub compare_configs {
2181 my (%a, %b) = @_;
2182
2183 foreach my $item (keys %a) {
2184 if (!defined($b{$item})) {
2185 print "diff $item\n";
2186 return 1;
2187 }
2188 delete $b{$item};
2189 }
2190
2191 my @keys = keys %b;
2192 if ($#keys) {
2193 print "diff2 $keys[0]\n";
2194 }
2195 return -1 if ($#keys >= 0);
2196
2197 return 0;
2198}
2199
2200sub run_config_bisect_test {
2201 my ($type) = @_;
2202
2203 return run_bisect_test $type, "oldconfig";
2204}
2205
2206sub process_passed {
2207 my (%configs) = @_;
2208
2209 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2210 # Passed! All these configs are part of a good compile.
2211 # Add them to the min options.
2212 foreach my $config (keys %configs) {
2213 if (defined($config_list{$config})) {
2214 doprint " removing $config\n";
2215 $config_ignore{$config} = $config_list{$config};
2216 delete $config_list{$config};
2217 }
2218 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002219 doprint "config copied to $outputdir/config_good\n";
2220 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002221}
2222
2223sub process_failed {
2224 my ($config) = @_;
2225
2226 doprint "\n\n***************************************\n";
2227 doprint "Found bad config: $config\n";
2228 doprint "***************************************\n\n";
2229}
2230
2231sub run_config_bisect {
2232
2233 my @start_list = keys %config_list;
2234
2235 if ($#start_list < 0) {
2236 doprint "No more configs to test!!!\n";
2237 return -1;
2238 }
2239
2240 doprint "***** RUN TEST ***\n";
2241 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2242 my $ret;
2243 my %current_config;
2244
2245 my $count = $#start_list + 1;
2246 doprint " $count configs to test\n";
2247
2248 my $half = int($#start_list / 2);
2249
2250 do {
2251 my @tophalf = @start_list[0 .. $half];
2252
2253 create_config @tophalf;
2254 read_current_config \%current_config;
2255
2256 $count = $#tophalf + 1;
2257 doprint "Testing $count configs\n";
2258 my $found = 0;
2259 # make sure we test something
2260 foreach my $config (@tophalf) {
2261 if (defined($current_config{$config})) {
2262 logit " $config\n";
2263 $found = 1;
2264 }
2265 }
2266 if (!$found) {
2267 # try the other half
2268 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002269 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002270 create_config @tophalf;
2271 read_current_config \%current_config;
2272 foreach my $config (@tophalf) {
2273 if (defined($current_config{$config})) {
2274 logit " $config\n";
2275 $found = 1;
2276 }
2277 }
2278 if (!$found) {
2279 doprint "Failed: Can't make new config with current configs\n";
2280 foreach my $config (@start_list) {
2281 doprint " CONFIG: $config\n";
2282 }
2283 return -1;
2284 }
2285 $count = $#tophalf + 1;
2286 doprint "Testing $count configs\n";
2287 }
2288
2289 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002290 if ($bisect_manual) {
2291 $ret = answer_bisect;
2292 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002293 if ($ret) {
2294 process_passed %current_config;
2295 return 0;
2296 }
2297
2298 doprint "This config had a failure.\n";
2299 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002300 doprint "config copied to $outputdir/config_bad\n";
2301 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002302
2303 # A config exists in this group that was bad.
2304 foreach my $config (keys %config_list) {
2305 if (!defined($current_config{$config})) {
2306 doprint " removing $config\n";
2307 delete $config_list{$config};
2308 }
2309 }
2310
2311 @start_list = @tophalf;
2312
2313 if ($#start_list == 0) {
2314 process_failed $start_list[0];
2315 return 1;
2316 }
2317
2318 # remove half the configs we are looking at and see if
2319 # they are good.
2320 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002321 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002322
Steven Rostedtc960bb92011-03-08 09:22:39 -05002323 # we found a single config, try it again unless we are running manually
2324
2325 if ($bisect_manual) {
2326 process_failed $start_list[0];
2327 return 1;
2328 }
2329
Steven Rostedt0a05c762010-11-08 11:14:10 -05002330 my @tophalf = @start_list[0 .. 0];
2331
2332 $ret = run_config_bisect_test $type;
2333 if ($ret) {
2334 process_passed %current_config;
2335 return 0;
2336 }
2337
2338 process_failed $start_list[0];
2339 return 1;
2340}
2341
2342sub config_bisect {
2343 my ($i) = @_;
2344
2345 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2346
2347 my $tmpconfig = "$tmpdir/use_config";
2348
Steven Rostedt30f75da2011-06-13 10:35:35 -04002349 if (defined($config_bisect_good)) {
2350 process_config_ignore $config_bisect_good;
2351 }
2352
Steven Rostedt0a05c762010-11-08 11:14:10 -05002353 # Make the file with the bad config and the min config
2354 if (defined($minconfig)) {
2355 # read the min config for things to ignore
2356 run_command "cp $minconfig $tmpconfig" or
2357 dodie "failed to copy $minconfig to $tmpconfig";
2358 } else {
2359 unlink $tmpconfig;
2360 }
2361
Steven Rostedt0a05c762010-11-08 11:14:10 -05002362 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002363 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002364 process_config_ignore $tmpconfig;
2365 }
2366
2367 # now process the start config
2368 run_command "cp $start_config $output_config" or
2369 dodie "failed to copy $start_config to $output_config";
2370
2371 # read directly what we want to check
2372 my %config_check;
2373 open (IN, $output_config)
2374 or dodie "faied to open $output_config";
2375
2376 while (<IN>) {
2377 if (/^((CONFIG\S*)=.*)/) {
2378 $config_check{$2} = $1;
2379 }
2380 }
2381 close(IN);
2382
Steven Rostedt250bae82011-07-15 22:05:59 -04002383 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002384 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002385
2386 # check to see what we lost (or gained)
2387 open (IN, $output_config)
2388 or dodie "Failed to read $start_config";
2389
2390 my %removed_configs;
2391 my %added_configs;
2392
2393 while (<IN>) {
2394 if (/^((CONFIG\S*)=.*)/) {
2395 # save off all options
2396 $config_set{$2} = $1;
2397 if (defined($config_check{$2})) {
2398 if (defined($config_ignore{$2})) {
2399 $removed_configs{$2} = $1;
2400 } else {
2401 $config_list{$2} = $1;
2402 }
2403 } elsif (!defined($config_ignore{$2})) {
2404 $added_configs{$2} = $1;
2405 $config_list{$2} = $1;
2406 }
2407 }
2408 }
2409 close(IN);
2410
2411 my @confs = keys %removed_configs;
2412 if ($#confs >= 0) {
2413 doprint "Configs overridden by default configs and removed from check:\n";
2414 foreach my $config (@confs) {
2415 doprint " $config\n";
2416 }
2417 }
2418 @confs = keys %added_configs;
2419 if ($#confs >= 0) {
2420 doprint "Configs appearing in make oldconfig and added:\n";
2421 foreach my $config (@confs) {
2422 doprint " $config\n";
2423 }
2424 }
2425
2426 my %config_test;
2427 my $once = 0;
2428
2429 # Sometimes kconfig does weird things. We must make sure
2430 # that the config we autocreate has everything we need
2431 # to test, otherwise we may miss testing configs, or
2432 # may not be able to create a new config.
2433 # Here we create a config with everything set.
2434 create_config (keys %config_list);
2435 read_current_config \%config_test;
2436 foreach my $config (keys %config_list) {
2437 if (!defined($config_test{$config})) {
2438 if (!$once) {
2439 $once = 1;
2440 doprint "Configs not produced by kconfig (will not be checked):\n";
2441 }
2442 doprint " $config\n";
2443 delete $config_list{$config};
2444 }
2445 }
2446 my $ret;
2447 do {
2448 $ret = run_config_bisect;
2449 } while (!$ret);
2450
2451 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002452
2453 success $i;
2454}
2455
Steven Rostedt27d934b2011-05-20 09:18:18 -04002456sub patchcheck_reboot {
2457 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002458 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002459}
2460
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002461sub patchcheck {
2462 my ($i) = @_;
2463
2464 die "PATCHCHECK_START[$i] not defined\n"
2465 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2466 die "PATCHCHECK_TYPE[$i] not defined\n"
2467 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2468
2469 my $start = $opt{"PATCHCHECK_START[$i]"};
2470
2471 my $end = "HEAD";
2472 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2473 $end = $opt{"PATCHCHECK_END[$i]"};
2474 }
2475
Steven Rostedta57419b2010-11-02 15:13:54 -04002476 # Get the true sha1's since we can use things like HEAD~3
2477 $start = get_sha1($start);
2478 $end = get_sha1($end);
2479
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002480 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2481
2482 # Can't have a test without having a test to run
2483 if ($type eq "test" && !defined($run_test)) {
2484 $type = "boot";
2485 }
2486
2487 open (IN, "git log --pretty=oneline $end|") or
2488 dodie "could not get git list";
2489
2490 my @list;
2491
2492 while (<IN>) {
2493 chomp;
2494 $list[$#list+1] = $_;
2495 last if (/^$start/);
2496 }
2497 close(IN);
2498
2499 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002500 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002501 }
2502
2503 # go backwards in the list
2504 @list = reverse @list;
2505
2506 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002507 my %ignored_warnings;
2508
2509 if (defined($ignore_warnings)) {
2510 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2511 $ignored_warnings{$sha1} = 1;
2512 }
2513 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002514
2515 $in_patchcheck = 1;
2516 foreach my $item (@list) {
2517 my $sha1 = $item;
2518 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2519
2520 doprint "\nProcessing commit $item\n\n";
2521
2522 run_command "git checkout $sha1" or
2523 die "Failed to checkout $sha1";
2524
2525 # only clean on the first and last patch
2526 if ($item eq $list[0] ||
2527 $item eq $list[$#list]) {
2528 $noclean = $save_clean;
2529 } else {
2530 $noclean = 1;
2531 }
2532
2533 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002534 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002535 } else {
2536 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002537 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002538 }
2539
Steven Rostedt19902072011-06-14 20:46:25 -04002540
2541 if (!defined($ignored_warnings{$sha1})) {
2542 check_buildlog $sha1 or return 0;
2543 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002544
2545 next if ($type eq "build");
2546
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002547 my $failed = 0;
2548
Steven Rostedtddf607e2011-06-14 20:49:13 -04002549 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002550
2551 if (!$failed && $type ne "boot"){
2552 do_run_test or $failed = 1;
2553 }
2554 end_monitor;
2555 return 0 if ($failed);
2556
Steven Rostedt27d934b2011-05-20 09:18:18 -04002557 patchcheck_reboot;
2558
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002559 }
2560 $in_patchcheck = 0;
2561 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002562
2563 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002564}
2565
Steven Rostedtb9066f62011-07-15 21:25:24 -04002566my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002567my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002568my $iflevel = 0;
2569my @ifdeps;
2570
2571# prevent recursion
2572my %read_kconfigs;
2573
Steven Rostedtac6974c2011-10-04 09:40:17 -04002574sub add_dep {
2575 # $config depends on $dep
2576 my ($config, $dep) = @_;
2577
2578 if (defined($depends{$config})) {
2579 $depends{$config} .= " " . $dep;
2580 } else {
2581 $depends{$config} = $dep;
2582 }
2583
2584 # record the number of configs depending on $dep
2585 if (defined $depcount{$dep}) {
2586 $depcount{$dep}++;
2587 } else {
2588 $depcount{$dep} = 1;
2589 }
2590}
2591
Steven Rostedtb9066f62011-07-15 21:25:24 -04002592# taken from streamline_config.pl
2593sub read_kconfig {
2594 my ($kconfig) = @_;
2595
2596 my $state = "NONE";
2597 my $config;
2598 my @kconfigs;
2599
2600 my $cont = 0;
2601 my $line;
2602
2603
2604 if (! -f $kconfig) {
2605 doprint "file $kconfig does not exist, skipping\n";
2606 return;
2607 }
2608
2609 open(KIN, "$kconfig")
2610 or die "Can't open $kconfig";
2611 while (<KIN>) {
2612 chomp;
2613
2614 # Make sure that lines ending with \ continue
2615 if ($cont) {
2616 $_ = $line . " " . $_;
2617 }
2618
2619 if (s/\\$//) {
2620 $cont = 1;
2621 $line = $_;
2622 next;
2623 }
2624
2625 $cont = 0;
2626
2627 # collect any Kconfig sources
2628 if (/^source\s*"(.*)"/) {
2629 $kconfigs[$#kconfigs+1] = $1;
2630 }
2631
2632 # configs found
2633 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2634 $state = "NEW";
2635 $config = $2;
2636
2637 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002638 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002639 }
2640
2641 # collect the depends for the config
2642 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2643
Steven Rostedtac6974c2011-10-04 09:40:17 -04002644 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002645
2646 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002647 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2648
2649 # selected by depends on config
2650 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002651
2652 # Check for if statements
2653 } elsif (/^if\s+(.*\S)\s*$/) {
2654 my $deps = $1;
2655 # remove beginning and ending non text
2656 $deps =~ s/^[^a-zA-Z0-9_]*//;
2657 $deps =~ s/[^a-zA-Z0-9_]*$//;
2658
2659 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2660
2661 $ifdeps[$iflevel++] = join ':', @deps;
2662
2663 } elsif (/^endif/) {
2664
2665 $iflevel-- if ($iflevel);
2666
2667 # stop on "help"
2668 } elsif (/^\s*help\s*$/) {
2669 $state = "NONE";
2670 }
2671 }
2672 close(KIN);
2673
2674 # read in any configs that were found.
2675 foreach $kconfig (@kconfigs) {
2676 if (!defined($read_kconfigs{$kconfig})) {
2677 $read_kconfigs{$kconfig} = 1;
2678 read_kconfig("$builddir/$kconfig");
2679 }
2680 }
2681}
2682
2683sub read_depends {
2684 # find out which arch this is by the kconfig file
2685 open (IN, $output_config)
2686 or dodie "Failed to read $output_config";
2687 my $arch;
2688 while (<IN>) {
2689 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2690 $arch = $1;
2691 last;
2692 }
2693 }
2694 close IN;
2695
2696 if (!defined($arch)) {
2697 doprint "Could not find arch from config file\n";
2698 doprint "no dependencies used\n";
2699 return;
2700 }
2701
2702 # arch is really the subarch, we need to know
2703 # what directory to look at.
2704 if ($arch eq "i386" || $arch eq "x86_64") {
2705 $arch = "x86";
2706 } elsif ($arch =~ /^tile/) {
2707 $arch = "tile";
2708 }
2709
2710 my $kconfig = "$builddir/arch/$arch/Kconfig";
2711
2712 if (! -f $kconfig && $arch =~ /\d$/) {
2713 my $orig = $arch;
2714 # some subarchs have numbers, truncate them
2715 $arch =~ s/\d*$//;
2716 $kconfig = "$builddir/arch/$arch/Kconfig";
2717 if (! -f $kconfig) {
2718 doprint "No idea what arch dir $orig is for\n";
2719 doprint "no dependencies used\n";
2720 return;
2721 }
2722 }
2723
2724 read_kconfig($kconfig);
2725}
2726
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002727sub read_config_list {
2728 my ($config) = @_;
2729
2730 open (IN, $config)
2731 or dodie "Failed to read $config";
2732
2733 while (<IN>) {
2734 if (/^((CONFIG\S*)=.*)/) {
2735 if (!defined($config_ignore{$2})) {
2736 $config_list{$2} = $1;
2737 }
2738 }
2739 }
2740
2741 close(IN);
2742}
2743
2744sub read_output_config {
2745 my ($config) = @_;
2746
2747 assign_configs \%config_ignore, $config;
2748}
2749
2750sub make_new_config {
2751 my @configs = @_;
2752
2753 open (OUT, ">$output_config")
2754 or dodie "Failed to write $output_config";
2755
2756 foreach my $config (@configs) {
2757 print OUT "$config\n";
2758 }
2759 close OUT;
2760}
2761
Steven Rostedtac6974c2011-10-04 09:40:17 -04002762sub chomp_config {
2763 my ($config) = @_;
2764
2765 $config =~ s/CONFIG_//;
2766
2767 return $config;
2768}
2769
Steven Rostedtb9066f62011-07-15 21:25:24 -04002770sub get_depends {
2771 my ($dep) = @_;
2772
Steven Rostedtac6974c2011-10-04 09:40:17 -04002773 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002774
2775 $dep = $depends{"$kconfig"};
2776
2777 # the dep string we have saves the dependencies as they
2778 # were found, including expressions like ! && ||. We
2779 # want to split this out into just an array of configs.
2780
2781 my $valid = "A-Za-z_0-9";
2782
2783 my @configs;
2784
2785 while ($dep =~ /[$valid]/) {
2786
2787 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2788 my $conf = "CONFIG_" . $1;
2789
2790 $configs[$#configs + 1] = $conf;
2791
2792 $dep =~ s/^[^$valid]*[$valid]+//;
2793 } else {
2794 die "this should never happen";
2795 }
2796 }
2797
2798 return @configs;
2799}
2800
2801my %min_configs;
2802my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002803my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002804my %processed_configs;
2805my %nochange_config;
2806
2807sub test_this_config {
2808 my ($config) = @_;
2809
2810 my $found;
2811
2812 # if we already processed this config, skip it
2813 if (defined($processed_configs{$config})) {
2814 return undef;
2815 }
2816 $processed_configs{$config} = 1;
2817
2818 # if this config failed during this round, skip it
2819 if (defined($nochange_config{$config})) {
2820 return undef;
2821 }
2822
Steven Rostedtac6974c2011-10-04 09:40:17 -04002823 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002824
2825 # Test dependencies first
2826 if (defined($depends{"$kconfig"})) {
2827 my @parents = get_depends $config;
2828 foreach my $parent (@parents) {
2829 # if the parent is in the min config, check it first
2830 next if (!defined($min_configs{$parent}));
2831 $found = test_this_config($parent);
2832 if (defined($found)) {
2833 return $found;
2834 }
2835 }
2836 }
2837
2838 # Remove this config from the list of configs
2839 # do a make oldnoconfig and then read the resulting
2840 # .config to make sure it is missing the config that
2841 # we had before
2842 my %configs = %min_configs;
2843 delete $configs{$config};
2844 make_new_config ((values %configs), (values %keep_configs));
2845 make_oldconfig;
2846 undef %configs;
2847 assign_configs \%configs, $output_config;
2848
2849 return $config if (!defined($configs{$config}));
2850
2851 doprint "disabling config $config did not change .config\n";
2852
2853 $nochange_config{$config} = 1;
2854
2855 return undef;
2856}
2857
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002858sub make_min_config {
2859 my ($i) = @_;
2860
2861 if (!defined($output_minconfig)) {
2862 fail "OUTPUT_MIN_CONFIG not defined" and return;
2863 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002864
2865 # If output_minconfig exists, and the start_minconfig
2866 # came from min_config, than ask if we should use
2867 # that instead.
2868 if (-f $output_minconfig && !$start_minconfig_defined) {
2869 print "$output_minconfig exists\n";
2870 if (read_yn " Use it as minconfig?") {
2871 $start_minconfig = $output_minconfig;
2872 }
2873 }
2874
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002875 if (!defined($start_minconfig)) {
2876 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2877 }
2878
Steven Rostedt35ce5952011-07-15 21:57:25 -04002879 my $temp_config = "$tmpdir/temp_config";
2880
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002881 # First things first. We build an allnoconfig to find
2882 # out what the defaults are that we can't touch.
2883 # Some are selections, but we really can't handle selections.
2884
2885 my $save_minconfig = $minconfig;
2886 undef $minconfig;
2887
2888 run_command "$make allnoconfig" or return 0;
2889
Steven Rostedtb9066f62011-07-15 21:25:24 -04002890 read_depends;
2891
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002892 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002893
Steven Rostedt43d1b652011-07-15 22:01:56 -04002894 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002895 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002896
2897 if (defined($ignore_config)) {
2898 # make sure the file exists
2899 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002900 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002901 }
2902
Steven Rostedt43d1b652011-07-15 22:01:56 -04002903 %keep_configs = %save_configs;
2904
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002905 doprint "Load initial configs from $start_minconfig\n";
2906
2907 # Look at the current min configs, and save off all the
2908 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002909 assign_configs \%min_configs, $start_minconfig;
2910
2911 my @config_keys = keys %min_configs;
2912
Steven Rostedtac6974c2011-10-04 09:40:17 -04002913 # All configs need a depcount
2914 foreach my $config (@config_keys) {
2915 my $kconfig = chomp_config $config;
2916 if (!defined $depcount{$kconfig}) {
2917 $depcount{$kconfig} = 0;
2918 }
2919 }
2920
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002921 # Remove anything that was set by the make allnoconfig
2922 # we shouldn't need them as they get set for us anyway.
2923 foreach my $config (@config_keys) {
2924 # Remove anything in the ignore_config
2925 if (defined($keep_configs{$config})) {
2926 my $file = $ignore_config;
2927 $file =~ s,.*/(.*?)$,$1,;
2928 doprint "$config set by $file ... ignored\n";
2929 delete $min_configs{$config};
2930 next;
2931 }
2932 # But make sure the settings are the same. If a min config
2933 # sets a selection, we do not want to get rid of it if
2934 # it is not the same as what we have. Just move it into
2935 # the keep configs.
2936 if (defined($config_ignore{$config})) {
2937 if ($config_ignore{$config} ne $min_configs{$config}) {
2938 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2939 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2940 $keep_configs{$config} = $min_configs{$config};
2941 } else {
2942 doprint "$config set by allnoconfig ... ignored\n";
2943 }
2944 delete $min_configs{$config};
2945 }
2946 }
2947
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002948 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002949 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002950
2951 while (!$done) {
2952
2953 my $config;
2954 my $found;
2955
2956 # Now disable each config one by one and do a make oldconfig
2957 # till we find a config that changes our list.
2958
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002959 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002960
2961 # Sort keys by who is most dependent on
2962 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2963 @test_configs ;
2964
2965 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002966 my $reset = 1;
2967 for (my $i = 0; $i < $#test_configs; $i++) {
2968 if (!defined($nochange_config{$test_configs[0]})) {
2969 $reset = 0;
2970 last;
2971 }
2972 # This config didn't change the .config last time.
2973 # Place it at the end
2974 my $config = shift @test_configs;
2975 push @test_configs, $config;
2976 }
2977
2978 # if every test config has failed to modify the .config file
2979 # in the past, then reset and start over.
2980 if ($reset) {
2981 undef %nochange_config;
2982 }
2983
Steven Rostedtb9066f62011-07-15 21:25:24 -04002984 undef %processed_configs;
2985
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002986 foreach my $config (@test_configs) {
2987
Steven Rostedtb9066f62011-07-15 21:25:24 -04002988 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002989
Steven Rostedtb9066f62011-07-15 21:25:24 -04002990 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002991
2992 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002993 }
2994
2995 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04002996 # we could have failed due to the nochange_config hash
2997 # reset and try again
2998 if (!$take_two) {
2999 undef %nochange_config;
3000 $take_two = 1;
3001 next;
3002 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003003 doprint "No more configs found that we can disable\n";
3004 $done = 1;
3005 last;
3006 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003007 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003008
3009 $config = $found;
3010
3011 doprint "Test with $config disabled\n";
3012
3013 # set in_bisect to keep build and monitor from dieing
3014 $in_bisect = 1;
3015
3016 my $failed = 0;
3017 build "oldconfig";
3018 start_monitor_and_boot or $failed = 1;
3019 end_monitor;
3020
3021 $in_bisect = 0;
3022
3023 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003024 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003025 # this config is needed, add it to the ignore list.
3026 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003027 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003028 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003029
3030 # update new ignore configs
3031 if (defined($ignore_config)) {
3032 open (OUT, ">$temp_config")
3033 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003034 foreach my $config (keys %save_configs) {
3035 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003036 }
3037 close OUT;
3038 run_command "mv $temp_config $ignore_config" or
3039 dodie "failed to copy update to $ignore_config";
3040 }
3041
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003042 } else {
3043 # We booted without this config, remove it from the minconfigs.
3044 doprint "$config is not needed, disabling\n";
3045
3046 delete $min_configs{$config};
3047
3048 # Also disable anything that is not enabled in this config
3049 my %configs;
3050 assign_configs \%configs, $output_config;
3051 my @config_keys = keys %min_configs;
3052 foreach my $config (@config_keys) {
3053 if (!defined($configs{$config})) {
3054 doprint "$config is not set, disabling\n";
3055 delete $min_configs{$config};
3056 }
3057 }
3058
3059 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003060 open (OUT, ">$temp_config")
3061 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003062 foreach my $config (keys %keep_configs) {
3063 print OUT "$keep_configs{$config}\n";
3064 }
3065 foreach my $config (keys %min_configs) {
3066 print OUT "$min_configs{$config}\n";
3067 }
3068 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003069
3070 run_command "mv $temp_config $output_minconfig" or
3071 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003072 }
3073
3074 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02003075 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003076 }
3077
3078 success $i;
3079 return 1;
3080}
3081
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003082$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003083
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003084if ($#ARGV == 0) {
3085 $ktest_config = $ARGV[0];
3086 if (! -f $ktest_config) {
3087 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003088 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003089 exit 0;
3090 }
3091 }
3092} else {
3093 $ktest_config = "ktest.conf";
3094}
3095
3096if (! -f $ktest_config) {
Steven Rostedtc4261d02011-11-23 13:41:18 -05003097 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003098 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3099 print OUT << "EOF"
3100# Generated by ktest.pl
3101#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003102
3103# PWD is a ktest.pl variable that will result in the process working
3104# directory that ktest.pl is executed in.
3105
3106# THIS_DIR is automatically assigned the PWD of the path that generated
3107# the config file. It is best to use this variable when assigning other
3108# directory paths within this directory. This allows you to easily
3109# move the test cases to other locations or to other machines.
3110#
3111THIS_DIR := $variable{"PWD"}
3112
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003113# Define each test with TEST_START
3114# The config options below it will override the defaults
3115TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003116TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003117
3118DEFAULTS
3119EOF
3120;
3121 close(OUT);
3122}
3123read_config $ktest_config;
3124
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003125if (defined($opt{"LOG_FILE"})) {
3126 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3127}
3128
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003129# Append any configs entered in manually to the config file.
3130my @new_configs = keys %entered_configs;
3131if ($#new_configs >= 0) {
3132 print "\nAppending entered in configs to $ktest_config\n";
3133 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3134 foreach my $config (@new_configs) {
3135 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003136 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003137 }
3138}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003139
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003140if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3141 unlink $opt{"LOG_FILE"};
3142}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003143
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003144doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3145
Steven Rostedta57419b2010-11-02 15:13:54 -04003146for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3147
3148 if (!$i) {
3149 doprint "DEFAULT OPTIONS:\n";
3150 } else {
3151 doprint "\nTEST $i OPTIONS";
3152 if (defined($repeat_tests{$i})) {
3153 $repeat = $repeat_tests{$i};
3154 doprint " ITERATE $repeat";
3155 }
3156 doprint "\n";
3157 }
3158
3159 foreach my $option (sort keys %opt) {
3160
3161 if ($option =~ /\[(\d+)\]$/) {
3162 next if ($i != $1);
3163 } else {
3164 next if ($i);
3165 }
3166
3167 doprint "$option = $opt{$option}\n";
3168 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003169}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003170
Steven Rostedt2a625122011-05-20 15:48:59 -04003171sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003172 my ($name, $i) = @_;
3173
3174 my $option = "$name\[$i\]";
3175
3176 if (defined($opt{$option})) {
3177 return $opt{$option};
3178 }
3179
Steven Rostedta57419b2010-11-02 15:13:54 -04003180 foreach my $test (keys %repeat_tests) {
3181 if ($i >= $test &&
3182 $i < $test + $repeat_tests{$test}) {
3183 $option = "$name\[$test\]";
3184 if (defined($opt{$option})) {
3185 return $opt{$option};
3186 }
3187 }
3188 }
3189
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003190 if (defined($opt{$name})) {
3191 return $opt{$name};
3192 }
3193
3194 return undef;
3195}
3196
Steven Rostedt2a625122011-05-20 15:48:59 -04003197sub set_test_option {
3198 my ($name, $i) = @_;
3199
3200 my $option = __set_test_option($name, $i);
3201 return $option if (!defined($option));
3202
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003203 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003204}
3205
Steven Rostedt2545eb62010-11-02 15:01:32 -04003206# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003207for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003208
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003209 # Do not reboot on failing test options
3210 $no_reboot = 1;
3211
Steven Rostedt576f6272010-11-02 14:58:38 -04003212 $iteration = $i;
3213
Steven Rostedta75fece2010-11-02 14:58:27 -04003214 my $makecmd = set_test_option("MAKE_CMD", $i);
3215
3216 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003217 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003218 $tmpdir = set_test_option("TMP_DIR", $i);
3219 $outputdir = set_test_option("OUTPUT_DIR", $i);
3220 $builddir = set_test_option("BUILD_DIR", $i);
3221 $test_type = set_test_option("TEST_TYPE", $i);
3222 $build_type = set_test_option("BUILD_TYPE", $i);
3223 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003224 $pre_build = set_test_option("PRE_BUILD", $i);
3225 $post_build = set_test_option("POST_BUILD", $i);
3226 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3227 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003228 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003229 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003230 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3231 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003232 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3233 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3234 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003235 $run_test = set_test_option("TEST", $i);
3236 $addconfig = set_test_option("ADD_CONFIG", $i);
3237 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3238 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003239 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003240 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003241 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3242 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3243 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3244 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3245 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003246 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3247 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003248 $sleep_time = set_test_option("SLEEP_TIME", $i);
3249 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003250 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003251 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003252 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003253 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003254 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003255 $store_failures = set_test_option("STORE_FAILURES", $i);
Rabin Vincentde5b6e32011-11-18 17:05:31 +05303256 $store_successes = set_test_option("STORE_SUCCESSES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003257 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003258 $timeout = set_test_option("TIMEOUT", $i);
3259 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3260 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003261 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003262 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003263 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003264 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3265 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003266 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003267 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003268 $ssh_exec = set_test_option("SSH_EXEC", $i);
3269 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003270 $target_image = set_test_option("TARGET_IMAGE", $i);
3271 $localversion = set_test_option("LOCALVERSION", $i);
3272
Steven Rostedt35ce5952011-07-15 21:57:25 -04003273 $start_minconfig_defined = 1;
3274
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003275 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003276 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003277 $start_minconfig = $minconfig;
3278 }
3279
Steven Rostedta75fece2010-11-02 14:58:27 -04003280 chdir $builddir || die "can't change directory to $builddir";
3281
Andrew Jonesa908a662011-08-12 15:32:03 +02003282 foreach my $dir ($tmpdir, $outputdir) {
3283 if (!-d $dir) {
3284 mkpath($dir) or
3285 die "can't create $dir";
3286 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003287 }
3288
Steven Rostedte48c5292010-11-02 14:35:37 -04003289 $ENV{"SSH_USER"} = $ssh_user;
3290 $ENV{"MACHINE"} = $machine;
3291
Steven Rostedta75fece2010-11-02 14:58:27 -04003292 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303293 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003294 $dmesg = "$tmpdir/dmesg-$machine";
3295 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003296 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003297
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003298 if (!$buildonly) {
3299 $target = "$ssh_user\@$machine";
3300 if ($reboot_type eq "grub") {
3301 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3302 } elsif (!defined($reboot_script)) {
3303 dodie "REBOOT_SCRIPT not defined"
3304 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003305 }
3306
3307 my $run_type = $build_type;
3308 if ($test_type eq "patchcheck") {
3309 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3310 } elsif ($test_type eq "bisect") {
3311 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003312 } elsif ($test_type eq "config_bisect") {
3313 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003314 }
3315
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003316 if ($test_type eq "make_min_config") {
3317 $run_type = "";
3318 }
3319
Steven Rostedta75fece2010-11-02 14:58:27 -04003320 # mistake in config file?
3321 if (!defined($run_type)) {
3322 $run_type = "ERROR";
3323 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003324
Steven Rostedte0a87422011-09-30 17:50:48 -04003325 my $installme = "";
3326 $installme = " no_install" if ($no_install);
3327
Steven Rostedt2545eb62010-11-02 15:01:32 -04003328 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003329 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003330
3331 unlink $dmesg;
3332 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303333 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003334
Steven Rostedt250bae82011-07-15 22:05:59 -04003335 if (defined($addconfig)) {
3336 my $min = $minconfig;
3337 if (!defined($minconfig)) {
3338 $min = "";
3339 }
3340 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003341 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003342 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003343 }
3344
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003345 my $checkout = $opt{"CHECKOUT[$i]"};
3346 if (defined($checkout)) {
3347 run_command "git checkout $checkout" or
3348 die "failed to checkout $checkout";
3349 }
3350
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003351 $no_reboot = 0;
3352
3353
Steven Rostedta75fece2010-11-02 14:58:27 -04003354 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003355 bisect $i;
3356 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003357 } elsif ($test_type eq "config_bisect") {
3358 config_bisect $i;
3359 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003360 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003361 patchcheck $i;
3362 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003363 } elsif ($test_type eq "make_min_config") {
3364 make_min_config $i;
3365 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003366 }
3367
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003368 if ($build_type ne "nobuild") {
3369 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003370 }
3371
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003372 if ($test_type eq "install") {
3373 get_version;
3374 install;
3375 success $i;
3376 next;
3377 }
3378
Steven Rostedta75fece2010-11-02 14:58:27 -04003379 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003380 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003381 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003382
3383 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3384 do_run_test or $failed = 1;
3385 }
3386 end_monitor;
3387 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003388 }
3389
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003390 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003391}
3392
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003393if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003394 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003395} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003396 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003397}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003398
Steven Rostedte48c5292010-11-02 14:35:37 -04003399doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3400
Steven Rostedt2545eb62010-11-02 15:01:32 -04003401exit 0;