blob: 85c5d943c6db76000ec85cebb627cafb5751e645 [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 Rostedt2545eb62010-11-02 15:01:32 -040021
22#default opts
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050023my %default = (
24 "NUM_TESTS" => 1,
25 "TEST_TYPE" => "build",
26 "BUILD_TYPE" => "randconfig",
27 "MAKE_CMD" => "make",
28 "TIMEOUT" => 120,
29 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
30 "SLEEP_TIME" => 60, # sleep time between tests
31 "BUILD_NOCLEAN" => 0,
32 "REBOOT_ON_ERROR" => 0,
33 "POWEROFF_ON_ERROR" => 0,
34 "REBOOT_ON_SUCCESS" => 1,
35 "POWEROFF_ON_SUCCESS" => 0,
36 "BUILD_OPTIONS" => "",
37 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
38 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
39 "CLEAR_LOG" => 0,
40 "BISECT_MANUAL" => 0,
41 "BISECT_SKIP" => 1,
42 "SUCCESS_LINE" => "login:",
43 "DETECT_TRIPLE_FAULT" => 1,
44 "NO_INSTALL" => 0,
45 "BOOTED_TIMEOUT" => 1,
46 "DIE_ON_FAILURE" => 1,
47 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
48 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
49 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
50 "STOP_AFTER_SUCCESS" => 10,
51 "STOP_AFTER_FAILURE" => 60,
52 "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.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050056 "REBOOT_TYPE" => "grub",
57 "LOCALVERSION" => "-test",
58 "SSH_USER" => "root",
59 "BUILD_TARGET" => "arch/x86/boot/bzImage",
60 "TARGET_IMAGE" => "/boot/vmlinuz-test",
61);
Steven Rostedt2545eb62010-11-02 15:01:32 -040062
Steven Rostedt8d1491b2010-11-18 15:39:48 -050063my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040064my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040065my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040066my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040067my $tmpdir;
68my $builddir;
69my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050070my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040071my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040072my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040073my $build_options;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040074my $pre_build;
75my $post_build;
76my $pre_build_die;
77my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040078my $reboot_type;
79my $reboot_script;
80my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040081my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040082my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -050083my $switch_to_good;
84my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -040085my $poweroff_on_error;
86my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040087my $powercycle_after_reboot;
88my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040089my $ssh_exec;
90my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040091my $power_off;
92my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040093my $grub_number;
94my $target;
95my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040096my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -040097my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040098my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040099my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400100my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400101my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400102my $output_minconfig;
103my $ignore_config;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400104my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400105my $in_bisect = 0;
106my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400107my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500108my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500109my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400110my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500111my $bisect_ret_good;
112my $bisect_ret_bad;
113my $bisect_ret_skip;
114my $bisect_ret_abort;
115my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400116my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400117my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400118my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400119my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530120my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400121my $dmesg;
122my $monitor_fp;
123my $monitor_pid;
124my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400125my $sleep_time;
126my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400127my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400128my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400129my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530130my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400131my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400132my $timeout;
133my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400134my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400135my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400136my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400137my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500138my $stop_after_success;
139my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500140my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400141my $build_target;
142my $target_image;
143my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400144my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400145my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400146
Steven Rostedt165708b2011-11-26 20:56:52 -0500147# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500148# which would require more options.
149my $buildonly = 1;
150
Steven Rostedtdbd37832011-11-23 16:00:48 -0500151# set when creating a new config
152my $newconfig = 0;
153
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500154my %entered_configs;
155my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400156my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400157my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500158
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400159# do not force reboots on config problems
160my $no_reboot = 1;
161
Steven Rostedt7bf51072011-10-22 09:07:03 -0400162# default variables that can be used
163chomp ($variable{"PWD"} = `pwd`);
164
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500165$config_help{"MACHINE"} = << "EOF"
166 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500167 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500168EOF
169 ;
170$config_help{"SSH_USER"} = << "EOF"
171 The box is expected to have ssh on normal bootup, provide the user
172 (most likely root, since you need privileged operations)
173EOF
174 ;
175$config_help{"BUILD_DIR"} = << "EOF"
176 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500177 You can use \${PWD} that will be the path where ktest.pl is run, or use
178 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500179EOF
180 ;
181$config_help{"OUTPUT_DIR"} = << "EOF"
182 The directory that the objects will be built (full path).
183 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500184 You can use \${PWD} that will be the path where ktest.pl is run, or use
185 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500186EOF
187 ;
188$config_help{"BUILD_TARGET"} = << "EOF"
189 The location of the compiled file to copy to the target.
190 (relative to OUTPUT_DIR)
191EOF
192 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500193$config_help{"BUILD_OPTIONS"} = << "EOF"
194 Options to add to \"make\" when building.
195 i.e. -j20
196EOF
197 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500198$config_help{"TARGET_IMAGE"} = << "EOF"
199 The place to put your image on the test machine.
200EOF
201 ;
202$config_help{"POWER_CYCLE"} = << "EOF"
203 A script or command to reboot the box.
204
205 Here is a digital loggers power switch example
206 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
207
208 Here is an example to reboot a virtual box on the current host
209 with the name "Guest".
210 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
211EOF
212 ;
213$config_help{"CONSOLE"} = << "EOF"
214 The script or command that reads the console
215
216 If you use ttywatch server, something like the following would work.
217CONSOLE = nc -d localhost 3001
218
219 For a virtual machine with guest name "Guest".
220CONSOLE = virsh console Guest
221EOF
222 ;
223$config_help{"LOCALVERSION"} = << "EOF"
224 Required version ending to differentiate the test
225 from other linux builds on the system.
226EOF
227 ;
228$config_help{"REBOOT_TYPE"} = << "EOF"
229 Way to reboot the box to the test kernel.
230 Only valid options so far are "grub" and "script".
231
232 If you specify grub, it will assume grub version 1
233 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
234 and select that target to reboot to the kernel. If this is not
235 your setup, then specify "script" and have a command or script
236 specified in REBOOT_SCRIPT to boot to the target.
237
238 The entry in /boot/grub/menu.lst must be entered in manually.
239 The test will not modify that file.
240EOF
241 ;
242$config_help{"GRUB_MENU"} = << "EOF"
243 The grub title name for the test kernel to boot
244 (Only mandatory if REBOOT_TYPE = grub)
245
246 Note, ktest.pl will not update the grub menu.lst, you need to
247 manually add an option for the test. ktest.pl will search
248 the grub menu.lst for this option to find what kernel to
249 reboot into.
250
251 For example, if in the /boot/grub/menu.lst the test kernel title has:
252 title Test Kernel
253 kernel vmlinuz-test
254 GRUB_MENU = Test Kernel
255EOF
256 ;
257$config_help{"REBOOT_SCRIPT"} = << "EOF"
258 A script to reboot the target into the test kernel
259 (Only mandatory if REBOOT_TYPE = script)
260EOF
261 ;
262
Steven Rostedtdad98752011-11-22 20:48:57 -0500263sub read_prompt {
264 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400265
266 my $ans;
267
268 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500269 if ($cancel) {
270 print "$prompt [y/n/C] ";
271 } else {
272 print "$prompt [Y/n] ";
273 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400274 $ans = <STDIN>;
275 chomp $ans;
276 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500277 if ($cancel) {
278 $ans = "c";
279 } else {
280 $ans = "y";
281 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400282 }
283 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500284 if ($cancel) {
285 last if ($ans =~ /^c$/i);
286 print "Please answer either 'y', 'n' or 'c'.\n";
287 } else {
288 print "Please answer either 'y' or 'n'.\n";
289 }
290 }
291 if ($ans =~ /^c/i) {
292 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400293 }
294 if ($ans !~ /^y$/i) {
295 return 0;
296 }
297 return 1;
298}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500299
Steven Rostedtdad98752011-11-22 20:48:57 -0500300sub read_yn {
301 my ($prompt) = @_;
302
303 return read_prompt 0, $prompt;
304}
305
306sub read_ync {
307 my ($prompt) = @_;
308
309 return read_prompt 1, $prompt;
310}
311
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500312sub get_ktest_config {
313 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400314 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500315
316 return if (defined($opt{$config}));
317
318 if (defined($config_help{$config})) {
319 print "\n";
320 print $config_help{$config};
321 }
322
323 for (;;) {
324 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500325 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500326 print "\[$default{$config}\] ";
327 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400328 $ans = <STDIN>;
329 $ans =~ s/^\s*(.*\S)\s*$/$1/;
330 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500331 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400332 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500333 } else {
334 print "Your answer can not be blank\n";
335 next;
336 }
337 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500338 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500339 last;
340 }
341}
342
343sub get_ktest_configs {
344 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500345 get_ktest_config("BUILD_DIR");
346 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500347
Steven Rostedtdbd37832011-11-23 16:00:48 -0500348 if ($newconfig) {
349 get_ktest_config("BUILD_OPTIONS");
350 }
351
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500352 # options required for other than just building a kernel
353 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500354 get_ktest_config("POWER_CYCLE");
355 get_ktest_config("CONSOLE");
356 }
357
358 # options required for install and more
359 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500360 get_ktest_config("SSH_USER");
361 get_ktest_config("BUILD_TARGET");
362 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500363 }
364
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500365 get_ktest_config("LOCALVERSION");
366
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500367 return if ($buildonly);
368
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500369 my $rtype = $opt{"REBOOT_TYPE"};
370
371 if (!defined($rtype)) {
372 if (!defined($opt{"GRUB_MENU"})) {
373 get_ktest_config("REBOOT_TYPE");
374 $rtype = $entered_configs{"REBOOT_TYPE"};
375 } else {
376 $rtype = "grub";
377 }
378 }
379
380 if ($rtype eq "grub") {
381 get_ktest_config("GRUB_MENU");
382 } else {
383 get_ktest_config("REBOOT_SCRIPT");
384 }
385}
386
Steven Rostedt77d942c2011-05-20 13:36:58 -0400387sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400388 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400389 my $retval = "";
390
391 # We want to check for '\', and it is just easier
392 # to check the previous characet of '$' and not need
393 # to worry if '$' is the first character. By adding
394 # a space to $value, we can just check [^\\]\$ and
395 # it will still work.
396 $value = " $value";
397
398 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
399 my $begin = $1;
400 my $var = $2;
401 my $end = $3;
402 # append beginning of value to retval
403 $retval = "$retval$begin";
404 if (defined($variable{$var})) {
405 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400406 } elsif (defined($remove_undef) && $remove_undef) {
407 # for if statements, any variable that is not defined,
408 # we simple convert to 0
409 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400410 } else {
411 # put back the origin piece.
412 $retval = "$retval\$\{$var\}";
413 }
414 $value = $end;
415 }
416 $retval = "$retval$value";
417
418 # remove the space added in the beginning
419 $retval =~ s/ //;
420
421 return "$retval"
422}
423
Steven Rostedta57419b2010-11-02 15:13:54 -0400424sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400425 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400426
Steven Rostedtcad96662011-12-22 11:32:52 -0500427 my $prvalue = process_variables($rvalue);
428
429 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500430 # Note if a test is something other than build, then we
431 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500432 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500433 $buildonly = 0;
434 } else {
435 # install still limits some manditory options.
436 $buildonly = 2;
437 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500438 }
439
Steven Rostedta57419b2010-11-02 15:13:54 -0400440 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400441 if (!$override || defined(${$overrides}{$lvalue})) {
442 my $extra = "";
443 if ($override) {
444 $extra = "In the same override section!\n";
445 }
446 die "$name: $.: Option $lvalue defined more than once!\n$extra";
447 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500448 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400449 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500450 if ($rvalue =~ /^\s*$/) {
451 delete $opt{$lvalue};
452 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500453 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500454 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400455}
456
Steven Rostedt77d942c2011-05-20 13:36:58 -0400457sub set_variable {
458 my ($lvalue, $rvalue) = @_;
459
460 if ($rvalue =~ /^\s*$/) {
461 delete $variable{$lvalue};
462 } else {
463 $rvalue = process_variables($rvalue);
464 $variable{$lvalue} = $rvalue;
465 }
466}
467
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400468sub process_compare {
469 my ($lval, $cmp, $rval) = @_;
470
471 # remove whitespace
472
473 $lval =~ s/^\s*//;
474 $lval =~ s/\s*$//;
475
476 $rval =~ s/^\s*//;
477 $rval =~ s/\s*$//;
478
479 if ($cmp eq "==") {
480 return $lval eq $rval;
481 } elsif ($cmp eq "!=") {
482 return $lval ne $rval;
483 }
484
485 my $statement = "$lval $cmp $rval";
486 my $ret = eval $statement;
487
488 # $@ stores error of eval
489 if ($@) {
490 return -1;
491 }
492
493 return $ret;
494}
495
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400496sub value_defined {
497 my ($val) = @_;
498
499 return defined($variable{$2}) ||
500 defined($opt{$2});
501}
502
Steven Rostedt8d735212011-10-17 11:36:44 -0400503my $d = 0;
504sub process_expression {
505 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400506
Steven Rostedt8d735212011-10-17 11:36:44 -0400507 my $c = $d++;
508
509 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
510 my $express = $1;
511
512 if (process_expression($name, $express)) {
513 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
514 } else {
515 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
516 }
517 }
518
519 $d--;
520 my $OR = "\\|\\|";
521 my $AND = "\\&\\&";
522
523 while ($val =~ s/^(.*?)($OR|$AND)//) {
524 my $express = $1;
525 my $op = $2;
526
527 if (process_expression($name, $express)) {
528 if ($op eq "||") {
529 return 1;
530 }
531 } else {
532 if ($op eq "&&") {
533 return 0;
534 }
535 }
536 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400537
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400538 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
539 my $ret = process_compare($1, $2, $3);
540 if ($ret < 0) {
541 die "$name: $.: Unable to process comparison\n";
542 }
543 return $ret;
544 }
545
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400546 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
547 if (defined $1) {
548 return !value_defined($2);
549 } else {
550 return value_defined($2);
551 }
552 }
553
Steven Rostedt45d73a52011-09-30 19:44:53 -0400554 if ($val =~ /^\s*0\s*$/) {
555 return 0;
556 } elsif ($val =~ /^\s*\d+\s*$/) {
557 return 1;
558 }
559
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400560 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400561}
562
563sub process_if {
564 my ($name, $value) = @_;
565
566 # Convert variables and replace undefined ones with 0
567 my $val = process_variables($value, 1);
568 my $ret = process_expression $name, $val;
569
570 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400571}
572
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400573sub __read_config {
574 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400575
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400576 my $in;
577 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400578
Steven Rostedta57419b2010-11-02 15:13:54 -0400579 my $name = $config;
580 $name =~ s,.*/(.*),$1,;
581
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400582 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400583 my $default = 1;
584 my $repeat = 1;
585 my $num_tests_set = 0;
586 my $skip = 0;
587 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400588 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400589 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400590 my $if = 0;
591 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400592 my $override = 0;
593
594 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400595
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400596 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400597
598 # ignore blank lines and comments
599 next if (/^\s*$/ || /\s*\#/);
600
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400601 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400602
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400603 my $type = $1;
604 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400605 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400606
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400607 my $old_test_num;
608 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400609 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400610
611 if ($type eq "TEST_START") {
612
613 if ($num_tests_set) {
614 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
615 }
616
617 $old_test_num = $test_num;
618 $old_repeat = $repeat;
619
620 $test_num += $repeat;
621 $default = 0;
622 $repeat = 1;
623 } else {
624 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400625 }
626
Steven Rostedta9f84422011-10-17 11:06:29 -0400627 # If SKIP is anywhere in the line, the command will be skipped
628 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400629 $skip = 1;
630 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400631 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400632 $skip = 0;
633 }
634
Steven Rostedta9f84422011-10-17 11:06:29 -0400635 if ($rest =~ s/\sELSE\b//) {
636 if (!$if) {
637 die "$name: $.: ELSE found with out matching IF section\n$_";
638 }
639 $if = 0;
640
641 if ($if_set) {
642 $skip = 1;
643 } else {
644 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400645 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400646 }
647
Steven Rostedta9f84422011-10-17 11:06:29 -0400648 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400649 if (process_if($name, $1)) {
650 $if_set = 1;
651 } else {
652 $skip = 1;
653 }
654 $if = 1;
655 } else {
656 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400657 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400658 }
659
Steven Rostedta9f84422011-10-17 11:06:29 -0400660 if (!$skip) {
661 if ($type eq "TEST_START") {
662 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
663 $repeat = $1;
664 $repeat_tests{"$test_num"} = $repeat;
665 }
666 } elsif ($rest =~ s/\sOVERRIDE\b//) {
667 # DEFAULT only
668 $override = 1;
669 # Clear previous overrides
670 %overrides = ();
671 }
672 }
673
674 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400675 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400676 }
677
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400678 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400679 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400680 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400681 }
682
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400683 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400684 if (!$if) {
685 die "$name: $.: ELSE found with out matching IF section\n$_";
686 }
687 $rest = $1;
688 if ($if_set) {
689 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400690 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400691 } else {
692 $skip = 0;
693
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400694 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400695 # May be a ELSE IF section.
696 if (!process_if($name, $1)) {
697 $skip = 1;
698 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400699 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400700 } else {
701 $if = 0;
702 }
703 }
704
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400705 if ($rest !~ /^\s*$/) {
706 die "$name: $.: Gargbage found after DEFAULTS\n$_";
707 }
708
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400709 } elsif (/^\s*INCLUDE\s+(\S+)/) {
710
711 next if ($skip);
712
713 if (!$default) {
714 die "$name: $.: INCLUDE can only be done in default sections\n$_";
715 }
716
717 my $file = process_variables($1);
718
719 if ($file !~ m,^/,) {
720 # check the path of the config file first
721 if ($config =~ m,(.*)/,) {
722 if (-f "$1/$file") {
723 $file = "$1/$file";
724 }
725 }
726 }
727
728 if ( ! -r $file ) {
729 die "$name: $.: Can't read file $file\n$_";
730 }
731
732 if (__read_config($file, \$test_num)) {
733 $test_case = 1;
734 }
735
Steven Rostedta57419b2010-11-02 15:13:54 -0400736 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
737
738 next if ($skip);
739
Steven Rostedt2545eb62010-11-02 15:01:32 -0400740 my $lvalue = $1;
741 my $rvalue = $2;
742
Steven Rostedta57419b2010-11-02 15:13:54 -0400743 if (!$default &&
744 ($lvalue eq "NUM_TESTS" ||
745 $lvalue eq "LOG_FILE" ||
746 $lvalue eq "CLEAR_LOG")) {
747 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400748 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400749
750 if ($lvalue eq "NUM_TESTS") {
751 if ($test_num) {
752 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
753 }
754 if (!$default) {
755 die "$name: $.: NUM_TESTS must be set in default section\n";
756 }
757 $num_tests_set = 1;
758 }
759
760 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400761 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400762 } else {
763 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400764 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400765
766 if ($repeat > 1) {
767 $repeats{$val} = $repeat;
768 }
769 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400770 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
771 next if ($skip);
772
773 my $lvalue = $1;
774 my $rvalue = $2;
775
776 # process config variables.
777 # Config variables are only active while reading the
778 # config and can be defined anywhere. They also ignore
779 # TEST_START and DEFAULTS, but are skipped if they are in
780 # on of these sections that have SKIP defined.
781 # The save variable can be
782 # defined multiple times and the new one simply overrides
783 # the prevous one.
784 set_variable($lvalue, $rvalue);
785
Steven Rostedta57419b2010-11-02 15:13:54 -0400786 } else {
787 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400788 }
789 }
790
Steven Rostedta57419b2010-11-02 15:13:54 -0400791 if ($test_num) {
792 $test_num += $repeat - 1;
793 $opt{"NUM_TESTS"} = $test_num;
794 }
795
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400796 close($in);
797
798 $$current_test_num = $test_num;
799
800 return $test_case;
801}
802
Steven Rostedtc4261d02011-11-23 13:41:18 -0500803sub get_test_case {
804 print "What test case would you like to run?\n";
805 print " (build, install or boot)\n";
806 print " Other tests are available but require editing the config file\n";
807 my $ans = <STDIN>;
808 chomp $ans;
809 $default{"TEST_TYPE"} = $ans;
810}
811
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400812sub read_config {
813 my ($config) = @_;
814
815 my $test_case;
816 my $test_num = 0;
817
818 $test_case = __read_config $config, \$test_num;
819
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500820 # make sure we have all mandatory configs
821 get_ktest_configs;
822
Steven Rostedt0df213c2011-06-14 20:51:37 -0400823 # was a test specified?
824 if (!$test_case) {
825 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500826 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400827 }
828
Steven Rostedta75fece2010-11-02 14:58:27 -0400829 # set any defaults
830
831 foreach my $default (keys %default) {
832 if (!defined($opt{$default})) {
833 $opt{$default} = $default{$default};
834 }
835 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400836}
837
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400838sub __eval_option {
839 my ($option, $i) = @_;
840
841 # Add space to evaluate the character before $
842 $option = " $option";
843 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530844 my $repeated = 0;
845 my $parent = 0;
846
847 foreach my $test (keys %repeat_tests) {
848 if ($i >= $test &&
849 $i < $test + $repeat_tests{$test}) {
850
851 $repeated = 1;
852 $parent = $test;
853 last;
854 }
855 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400856
857 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
858 my $start = $1;
859 my $var = $2;
860 my $end = $3;
861
862 # Append beginning of line
863 $retval = "$retval$start";
864
865 # If the iteration option OPT[$i] exists, then use that.
866 # otherwise see if the default OPT (without [$i]) exists.
867
868 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530869 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400870
871 if (defined($opt{$o})) {
872 $o = $opt{$o};
873 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530874 } elsif ($repeated && defined($opt{$parento})) {
875 $o = $opt{$parento};
876 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400877 } elsif (defined($opt{$var})) {
878 $o = $opt{$var};
879 $retval = "$retval$o";
880 } else {
881 $retval = "$retval\$\{$var\}";
882 }
883
884 $option = $end;
885 }
886
887 $retval = "$retval$option";
888
889 $retval =~ s/^ //;
890
891 return $retval;
892}
893
894sub eval_option {
895 my ($option, $i) = @_;
896
897 my $prev = "";
898
899 # Since an option can evaluate to another option,
900 # keep iterating until we do not evaluate any more
901 # options.
902 my $r = 0;
903 while ($prev ne $option) {
904 # Check for recursive evaluations.
905 # 100 deep should be more than enough.
906 if ($r++ > 100) {
907 die "Over 100 evaluations accurred with $option\n" .
908 "Check for recursive variables\n";
909 }
910 $prev = $option;
911 $option = __eval_option($option, $i);
912 }
913
914 return $option;
915}
916
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500917sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400918 if (defined($opt{"LOG_FILE"})) {
919 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
920 print OUT @_;
921 close(OUT);
922 }
923}
924
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500925sub logit {
926 if (defined($opt{"LOG_FILE"})) {
927 _logit @_;
928 } else {
929 print @_;
930 }
931}
932
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400933sub doprint {
934 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500935 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400936}
937
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400938sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200939sub start_monitor;
940sub end_monitor;
941sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400942
943sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200944 my ($time) = @_;
945
Steven Rostedt2b803362011-09-30 18:00:23 -0400946 if (defined($time)) {
947 start_monitor;
948 # flush out current monitor
949 # May contain the reboot success line
950 wait_for_monitor 1;
951 }
952
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400953 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400954 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400955 if (defined($powercycle_after_reboot)) {
956 sleep $powercycle_after_reboot;
957 run_command "$power_cycle";
958 }
959 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400960 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400961 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400962 }
Andrew Jones2728be42011-08-12 15:32:05 +0200963
964 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400965 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200966 end_monitor;
967 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400968}
969
Steven Rostedtbc7c5802011-12-22 16:29:10 -0500970sub reboot_to_good {
971 my ($time) = @_;
972
973 if (defined($switch_to_good)) {
974 run_command $switch_to_good;
975 return;
976 }
977
978 reboot $time;
979}
980
Steven Rostedt576f6272010-11-02 14:58:38 -0400981sub do_not_reboot {
982 my $i = $iteration;
983
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400984 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400985 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
986 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
987}
988
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400989sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400990 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400991
Steven Rostedt576f6272010-11-02 14:58:38 -0400992 my $i = $iteration;
993
994 if ($reboot_on_error && !do_not_reboot) {
995
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400996 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -0500997 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400998
Steven Rostedta75fece2010-11-02 14:58:27 -0400999 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001000 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001001 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001002 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001003
Steven Rostedtf80802c2011-03-07 13:18:47 -05001004 if (defined($opt{"LOG_FILE"})) {
1005 print " See $opt{LOG_FILE} for more info.\n";
1006 }
1007
Steven Rostedt576f6272010-11-02 14:58:38 -04001008 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001009}
1010
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001011sub open_console {
1012 my ($fp) = @_;
1013
1014 my $flags;
1015
Steven Rostedta75fece2010-11-02 14:58:27 -04001016 my $pid = open($fp, "$console|") or
1017 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001018
1019 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001020 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001021 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001022 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001023
1024 return $pid;
1025}
1026
1027sub close_console {
1028 my ($fp, $pid) = @_;
1029
1030 doprint "kill child process $pid\n";
1031 kill 2, $pid;
1032
1033 print "closing!\n";
1034 close($fp);
1035}
1036
1037sub start_monitor {
1038 if ($monitor_cnt++) {
1039 return;
1040 }
1041 $monitor_fp = \*MONFD;
1042 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001043
1044 return;
1045
1046 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001047}
1048
1049sub end_monitor {
1050 if (--$monitor_cnt) {
1051 return;
1052 }
1053 close_console($monitor_fp, $monitor_pid);
1054}
1055
1056sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001057 my ($time, $stop) = @_;
1058 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001059 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001060 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001061
Steven Rostedta75fece2010-11-02 14:58:27 -04001062 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001063
1064 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001065 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001066 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001067 last if (!defined($line));
1068 print "$line";
1069 $full_line .= $line;
1070
1071 if (defined($stop) && $full_line =~ /$stop/) {
1072 doprint "wait for monitor detected $stop\n";
1073 $booted = 1;
1074 }
1075
1076 if ($line =~ /\n/) {
1077 $full_line = "";
1078 }
1079 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001080 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001081}
1082
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301083sub save_logs {
1084 my ($result, $basedir) = @_;
1085 my @t = localtime;
1086 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1087 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1088
1089 my $type = $build_type;
1090 if ($type =~ /useconfig/) {
1091 $type = "useconfig";
1092 }
1093
1094 my $dir = "$machine-$test_type-$type-$result-$date";
1095
1096 $dir = "$basedir/$dir";
1097
1098 if (!-d $dir) {
1099 mkpath($dir) or
1100 die "can't create $dir";
1101 }
1102
1103 my %files = (
1104 "config" => $output_config,
1105 "buildlog" => $buildlog,
1106 "dmesg" => $dmesg,
1107 "testlog" => $testlog,
1108 );
1109
1110 while (my ($name, $source) = each(%files)) {
1111 if (-f "$source") {
1112 cp "$source", "$dir/$name" or
1113 die "failed to copy $source";
1114 }
1115 }
1116
1117 doprint "*** Saved info to $dir ***\n";
1118}
1119
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001120sub fail {
1121
Steven Rostedta75fece2010-11-02 14:58:27 -04001122 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001123 dodie @_;
1124 }
1125
Steven Rostedta75fece2010-11-02 14:58:27 -04001126 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001127
Steven Rostedt576f6272010-11-02 14:58:38 -04001128 my $i = $iteration;
1129
Steven Rostedta75fece2010-11-02 14:58:27 -04001130 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001131 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001132 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001133 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001134 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001135
Steven Rostedt9064af52011-06-13 10:38:48 -04001136 my $name = "";
1137
1138 if (defined($test_name)) {
1139 $name = " ($test_name)";
1140 }
1141
Steven Rostedt576f6272010-11-02 14:58:38 -04001142 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1143 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001144 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001145 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1146 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001147
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301148 if (defined($store_failures)) {
1149 save_logs "fail", $store_failures;
1150 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001151
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001152 return 1;
1153}
1154
Steven Rostedt2545eb62010-11-02 15:01:32 -04001155sub run_command {
1156 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001157 my $dolog = 0;
1158 my $dord = 0;
1159 my $pid;
1160
Steven Rostedte48c5292010-11-02 14:35:37 -04001161 $command =~ s/\$SSH_USER/$ssh_user/g;
1162 $command =~ s/\$MACHINE/$machine/g;
1163
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001164 doprint("$command ... ");
1165
1166 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001167 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001168
1169 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001170 open(LOG, ">>$opt{LOG_FILE}") or
1171 dodie "failed to write to log";
1172 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001173 }
1174
1175 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001176 open (RD, ">$redirect") or
1177 dodie "failed to write to redirect $redirect";
1178 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001179 }
1180
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001181 while (<CMD>) {
1182 print LOG if ($dolog);
1183 print RD if ($dord);
1184 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001185
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001186 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001187 my $failed = $?;
1188
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001189 close(CMD);
1190 close(LOG) if ($dolog);
1191 close(RD) if ($dord);
1192
Steven Rostedt2545eb62010-11-02 15:01:32 -04001193 if ($failed) {
1194 doprint "FAILED!\n";
1195 } else {
1196 doprint "SUCCESS\n";
1197 }
1198
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001199 return !$failed;
1200}
1201
Steven Rostedte48c5292010-11-02 14:35:37 -04001202sub run_ssh {
1203 my ($cmd) = @_;
1204 my $cp_exec = $ssh_exec;
1205
1206 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1207 return run_command "$cp_exec";
1208}
1209
1210sub run_scp {
1211 my ($src, $dst) = @_;
1212 my $cp_scp = $scp_to_target;
1213
1214 $cp_scp =~ s/\$SRC_FILE/$src/g;
1215 $cp_scp =~ s/\$DST_FILE/$dst/g;
1216
1217 return run_command "$cp_scp";
1218}
1219
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001220sub get_grub_index {
1221
Steven Rostedta75fece2010-11-02 14:58:27 -04001222 if ($reboot_type ne "grub") {
1223 return;
1224 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001225 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001226
1227 doprint "Find grub menu ... ";
1228 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001229
1230 my $ssh_grub = $ssh_exec;
1231 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1232
1233 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001234 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001235
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001236 my $found = 0;
1237
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001238 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001239 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001240 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001241 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001242 last;
1243 } elsif (/^\s*title\s/) {
1244 $grub_number++;
1245 }
1246 }
1247 close(IN);
1248
Steven Rostedta75fece2010-11-02 14:58:27 -04001249 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001250 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001251 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001252}
1253
Steven Rostedt2545eb62010-11-02 15:01:32 -04001254sub wait_for_input
1255{
1256 my ($fp, $time) = @_;
1257 my $rin;
1258 my $ready;
1259 my $line;
1260 my $ch;
1261
1262 if (!defined($time)) {
1263 $time = $timeout;
1264 }
1265
1266 $rin = '';
1267 vec($rin, fileno($fp), 1) = 1;
1268 $ready = select($rin, undef, undef, $time);
1269
1270 $line = "";
1271
1272 # try to read one char at a time
1273 while (sysread $fp, $ch, 1) {
1274 $line .= $ch;
1275 last if ($ch eq "\n");
1276 }
1277
1278 if (!length($line)) {
1279 return undef;
1280 }
1281
1282 return $line;
1283}
1284
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001285sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001286 if (defined($switch_to_test)) {
1287 run_command $switch_to_test;
1288 }
1289
Steven Rostedta75fece2010-11-02 14:58:27 -04001290 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001291 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1292 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001293 return;
1294 }
1295
1296 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001297}
1298
Steven Rostedta57419b2010-11-02 15:13:54 -04001299sub get_sha1 {
1300 my ($commit) = @_;
1301
1302 doprint "git rev-list --max-count=1 $commit ... ";
1303 my $sha1 = `git rev-list --max-count=1 $commit`;
1304 my $ret = $?;
1305
1306 logit $sha1;
1307
1308 if ($ret) {
1309 doprint "FAILED\n";
1310 dodie "Failed to get git $commit";
1311 }
1312
1313 print "SUCCESS\n";
1314
1315 chomp $sha1;
1316
1317 return $sha1;
1318}
1319
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001320sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001321 my $booted = 0;
1322 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001323 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001324 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001325
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001326 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001327
1328 my $line;
1329 my $full_line = "";
1330
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001331 open(DMESG, "> $dmesg") or
1332 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001333
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001334 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001335
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001336 my $success_start;
1337 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001338 my $monitor_start = time;
1339 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001340 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001341
Steven Rostedt2d01b262011-03-08 09:47:54 -05001342 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001343
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001344 if ($bug && defined($stop_after_failure) &&
1345 $stop_after_failure >= 0) {
1346 my $time = $stop_after_failure - (time - $failure_start);
1347 $line = wait_for_input($monitor_fp, $time);
1348 if (!defined($line)) {
1349 doprint "bug timed out after $booted_timeout seconds\n";
1350 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1351 last;
1352 }
1353 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001354 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001355 if (!defined($line)) {
1356 my $s = $booted_timeout == 1 ? "" : "s";
1357 doprint "Successful boot found: break after $booted_timeout second$s\n";
1358 last;
1359 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001360 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001361 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001362 if (!defined($line)) {
1363 my $s = $timeout == 1 ? "" : "s";
1364 doprint "Timed out after $timeout second$s\n";
1365 last;
1366 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001367 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001368
Steven Rostedt2545eb62010-11-02 15:01:32 -04001369 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001370 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001371
1372 # we are not guaranteed to get a full line
1373 $full_line .= $line;
1374
Steven Rostedta75fece2010-11-02 14:58:27 -04001375 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001376 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001377 $success_start = time;
1378 }
1379
1380 if ($booted && defined($stop_after_success) &&
1381 $stop_after_success >= 0) {
1382 my $now = time;
1383 if ($now - $success_start >= $stop_after_success) {
1384 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1385 last;
1386 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001387 }
1388
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001389 if ($full_line =~ /\[ backtrace testing \]/) {
1390 $skip_call_trace = 1;
1391 }
1392
Steven Rostedt2545eb62010-11-02 15:01:32 -04001393 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001394 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001395 $bug = 1;
1396 $failure_start = time;
1397 }
1398 }
1399
1400 if ($bug && defined($stop_after_failure) &&
1401 $stop_after_failure >= 0) {
1402 my $now = time;
1403 if ($now - $failure_start >= $stop_after_failure) {
1404 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1405 last;
1406 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001407 }
1408
1409 if ($full_line =~ /\[ end of backtrace testing \]/) {
1410 $skip_call_trace = 0;
1411 }
1412
1413 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001414 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001415 $bug = 1;
1416 }
1417
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001418 # Detect triple faults by testing the banner
1419 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1420 if ($1 eq $version) {
1421 $version_found = 1;
1422 } elsif ($version_found && $detect_triplefault) {
1423 # We already booted into the kernel we are testing,
1424 # but now we booted into another kernel?
1425 # Consider this a triple fault.
1426 doprint "Aleady booted in Linux kernel $version, but now\n";
1427 doprint "we booted into Linux kernel $1.\n";
1428 doprint "Assuming that this is a triple fault.\n";
1429 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1430 last;
1431 }
1432 }
1433
Steven Rostedt2545eb62010-11-02 15:01:32 -04001434 if ($line =~ /\n/) {
1435 $full_line = "";
1436 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001437
1438 if ($stop_test_after > 0 && !$booted && !$bug) {
1439 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001440 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001441 $done = 1;
1442 }
1443 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001444 }
1445
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001446 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001447
Steven Rostedt2545eb62010-11-02 15:01:32 -04001448 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001449 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001450 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001451 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001452
Steven Rostedta75fece2010-11-02 14:58:27 -04001453 if (!$booted) {
1454 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001455 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001456 }
1457
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001458 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001459}
1460
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001461sub eval_kernel_version {
1462 my ($option) = @_;
1463
1464 $option =~ s/\$KERNEL_VERSION/$version/g;
1465
1466 return $option;
1467}
1468
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001469sub do_post_install {
1470
1471 return if (!defined($post_install));
1472
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001473 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001474 run_command "$cp_post_install" or
1475 dodie "Failed to run post install";
1476}
1477
Steven Rostedt2545eb62010-11-02 15:01:32 -04001478sub install {
1479
Steven Rostedte0a87422011-09-30 17:50:48 -04001480 return if ($no_install);
1481
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001482 my $cp_target = eval_kernel_version $target_image;
1483
1484 run_scp "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001485 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001486
1487 my $install_mods = 0;
1488
1489 # should we process modules?
1490 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001491 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001492 while (<IN>) {
1493 if (/CONFIG_MODULES(=y)?/) {
1494 $install_mods = 1 if (defined($1));
1495 last;
1496 }
1497 }
1498 close(IN);
1499
1500 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001501 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001502 doprint "No modules needed\n";
1503 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001504 }
1505
Steven Rostedta75fece2010-11-02 14:58:27 -04001506 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001507 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001508
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001509 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001510 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001511
Steven Rostedte48c5292010-11-02 14:35:37 -04001512 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001513 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001514
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001515 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001516 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001517 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001518
Steven Rostedte48c5292010-11-02 14:35:37 -04001519 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001520 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001521
Steven Rostedta75fece2010-11-02 14:58:27 -04001522 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001523
Steven Rostedte7b13442011-06-14 20:44:36 -04001524 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001525 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001526
Steven Rostedte48c5292010-11-02 14:35:37 -04001527 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001528
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001529 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001530}
1531
Steven Rostedtddf607e2011-06-14 20:49:13 -04001532sub get_version {
1533 # get the release name
1534 doprint "$make kernelrelease ... ";
1535 $version = `$make kernelrelease | tail -1`;
1536 chomp($version);
1537 doprint "$version\n";
1538}
1539
1540sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001541 # Make sure the stable kernel has finished booting
1542 start_monitor;
1543 wait_for_monitor 5;
1544 end_monitor;
1545
Steven Rostedtddf607e2011-06-14 20:49:13 -04001546 get_grub_index;
1547 get_version;
1548 install;
1549
1550 start_monitor;
1551 return monitor;
1552}
1553
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001554sub check_buildlog {
1555 my ($patch) = @_;
1556
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001557 my @files = `git show $patch | diffstat -l`;
1558
1559 open(IN, "git show $patch |") or
1560 dodie "failed to show $patch";
1561 while (<IN>) {
1562 if (m,^--- a/(.*),) {
1563 chomp $1;
1564 $files[$#files] = $1;
1565 }
1566 }
1567 close(IN);
1568
1569 open(IN, $buildlog) or dodie "Can't open $buildlog";
1570 while (<IN>) {
1571 if (/^\s*(.*?):.*(warning|error)/) {
1572 my $err = $1;
1573 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001574 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001575 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001576 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001577 }
1578 }
1579 }
1580 }
1581 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001582
1583 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001584}
1585
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001586sub apply_min_config {
1587 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001588
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001589 # Read the config file and remove anything that
1590 # is in the force_config hash (from minconfig and others)
1591 # then add the force config back.
1592
1593 doprint "Applying minimum configurations into $output_config.new\n";
1594
1595 open (OUT, ">$outconfig") or
1596 dodie "Can't create $outconfig";
1597
1598 if (-f $output_config) {
1599 open (IN, $output_config) or
1600 dodie "Failed to open $output_config";
1601 while (<IN>) {
1602 if (/^(# )?(CONFIG_[^\s=]*)/) {
1603 next if (defined($force_config{$2}));
1604 }
1605 print OUT;
1606 }
1607 close IN;
1608 }
1609 foreach my $config (keys %force_config) {
1610 print OUT "$force_config{$config}\n";
1611 }
1612 close OUT;
1613
1614 run_command "mv $outconfig $output_config";
1615}
1616
1617sub make_oldconfig {
1618
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001619 my @force_list = keys %force_config;
1620
1621 if ($#force_list >= 0) {
1622 apply_min_config;
1623 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001624
1625 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001626 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1627 # try a yes '' | oldconfig
1628 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001629 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001630 dodie "failed make config oldconfig";
1631 }
1632}
1633
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001634# read a config file and use this to force new configs.
1635sub load_force_config {
1636 my ($config) = @_;
1637
1638 open(IN, $config) or
1639 dodie "failed to read $config";
1640 while (<IN>) {
1641 chomp;
1642 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1643 $force_config{$1} = $_;
1644 } elsif (/^# (CONFIG_\S*) is not set/) {
1645 $force_config{$1} = $_;
1646 }
1647 }
1648 close IN;
1649}
1650
Steven Rostedt2545eb62010-11-02 15:01:32 -04001651sub build {
1652 my ($type) = @_;
1653
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001654 unlink $buildlog;
1655
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001656 # Failed builds should not reboot the target
1657 my $save_no_reboot = $no_reboot;
1658 $no_reboot = 1;
1659
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001660 if (defined($pre_build)) {
1661 my $ret = run_command $pre_build;
1662 if (!$ret && defined($pre_build_die) &&
1663 $pre_build_die) {
1664 dodie "failed to pre_build\n";
1665 }
1666 }
1667
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001668 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001669 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001670 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001671
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001672 $type = "oldconfig";
1673 }
1674
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001675 # old config can ask questions
1676 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001677 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001678
1679 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001680 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001681
Andrew Jones13488232011-08-12 15:32:04 +02001682 if (!$noclean) {
1683 run_command "mv $output_config $outputdir/config_temp" or
1684 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001685
Andrew Jones13488232011-08-12 15:32:04 +02001686 run_command "$make mrproper" or dodie "make mrproper";
1687
1688 run_command "mv $outputdir/config_temp $output_config" or
1689 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001690 }
1691
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001692 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001693 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001694 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001695 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001696 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001697
1698 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001699 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1700 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001701 close(OUT);
1702
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001703 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001704 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001705 }
1706
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001707 if ($type ne "oldnoconfig") {
1708 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001709 dodie "failed make config";
1710 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001711 # Run old config regardless, to enforce min configurations
1712 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001713
Steven Rostedta75fece2010-11-02 14:58:27 -04001714 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001715 my $build_ret = run_command "$make $build_options";
1716 undef $redirect;
1717
1718 if (defined($post_build)) {
1719 my $ret = run_command $post_build;
1720 if (!$ret && defined($post_build_die) &&
1721 $post_build_die) {
1722 dodie "failed to post_build\n";
1723 }
1724 }
1725
1726 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001727 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001728 if ($in_bisect) {
1729 $no_reboot = $save_no_reboot;
1730 return 0;
1731 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001732 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001733 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001734
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001735 $no_reboot = $save_no_reboot;
1736
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001737 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001738}
1739
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001740sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001741 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001742 if (defined($poweroff_after_halt)) {
1743 sleep $poweroff_after_halt;
1744 run_command "$power_off";
1745 }
1746 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001747 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001748 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001749 }
1750}
1751
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001752sub success {
1753 my ($i) = @_;
1754
Steven Rostedte48c5292010-11-02 14:35:37 -04001755 $successes++;
1756
Steven Rostedt9064af52011-06-13 10:38:48 -04001757 my $name = "";
1758
1759 if (defined($test_name)) {
1760 $name = " ($test_name)";
1761 }
1762
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001763 doprint "\n\n*******************************************\n";
1764 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001765 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001766 doprint "*******************************************\n";
1767 doprint "*******************************************\n";
1768
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301769 if (defined($store_successes)) {
1770 save_logs "success", $store_successes;
1771 }
1772
Steven Rostedt576f6272010-11-02 14:58:38 -04001773 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001774 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001775 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001776 }
1777}
1778
Steven Rostedtc960bb92011-03-08 09:22:39 -05001779sub answer_bisect {
1780 for (;;) {
1781 doprint "Pass or fail? [p/f]";
1782 my $ans = <STDIN>;
1783 chomp $ans;
1784 if ($ans eq "p" || $ans eq "P") {
1785 return 1;
1786 } elsif ($ans eq "f" || $ans eq "F") {
1787 return 0;
1788 } else {
1789 print "Please answer 'P' or 'F'\n";
1790 }
1791 }
1792}
1793
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001794sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001795 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001796
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001797 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001798 $reboot_on_error = 0;
1799 $poweroff_on_error = 0;
1800 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001801
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301802 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001803 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301804 undef $redirect;
1805
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001806 exit $failed;
1807}
1808
1809my $child_done;
1810
1811sub child_finished {
1812 $child_done = 1;
1813}
1814
1815sub do_run_test {
1816 my $child_pid;
1817 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001818 my $line;
1819 my $full_line;
1820 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001821
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001822 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001823
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001824 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001825
1826 $child_done = 0;
1827
1828 $SIG{CHLD} = qw(child_finished);
1829
1830 $child_pid = fork;
1831
1832 child_run_test if (!$child_pid);
1833
1834 $full_line = "";
1835
1836 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001837 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001838 if (defined($line)) {
1839
1840 # we are not guaranteed to get a full line
1841 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001842 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001843
1844 if ($full_line =~ /call trace:/i) {
1845 $bug = 1;
1846 }
1847
1848 if ($full_line =~ /Kernel panic -/) {
1849 $bug = 1;
1850 }
1851
1852 if ($line =~ /\n/) {
1853 $full_line = "";
1854 }
1855 }
1856 } while (!$child_done && !$bug);
1857
1858 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001859 my $failure_start = time;
1860 my $now;
1861 do {
1862 $line = wait_for_input($monitor_fp, 1);
1863 if (defined($line)) {
1864 doprint $line;
1865 }
1866 $now = time;
1867 if ($now - $failure_start >= $stop_after_failure) {
1868 last;
1869 }
1870 } while (defined($line));
1871
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001872 doprint "Detected kernel crash!\n";
1873 # kill the child with extreme prejudice
1874 kill 9, $child_pid;
1875 }
1876
1877 waitpid $child_pid, 0;
1878 $child_exit = $?;
1879
Steven Rostedtc5dacb82011-12-22 12:43:57 -05001880 if (!$bug && $in_bisect) {
1881 if (defined($bisect_ret_good)) {
1882 if ($child_exit == $bisect_ret_good) {
1883 return 1;
1884 }
1885 }
1886 if (defined($bisect_ret_skip)) {
1887 if ($child_exit == $bisect_ret_skip) {
1888 return -1;
1889 }
1890 }
1891 if (defined($bisect_ret_abort)) {
1892 if ($child_exit == $bisect_ret_abort) {
1893 fail "test abort" and return -2;
1894 }
1895 }
1896 if (defined($bisect_ret_bad)) {
1897 if ($child_exit == $bisect_ret_skip) {
1898 return 0;
1899 }
1900 }
1901 if (defined($bisect_ret_default)) {
1902 if ($bisect_ret_default eq "good") {
1903 return 1;
1904 } elsif ($bisect_ret_default eq "bad") {
1905 return 0;
1906 } elsif ($bisect_ret_default eq "skip") {
1907 return -1;
1908 } elsif ($bisect_ret_default eq "abort") {
1909 return -2;
1910 } else {
1911 fail "unknown default action: $bisect_ret_default"
1912 and return -2;
1913 }
1914 }
1915 }
1916
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001917 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001918 return 0 if $in_bisect;
1919 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001920 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001921 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001922}
1923
Steven Rostedta75fece2010-11-02 14:58:27 -04001924sub run_git_bisect {
1925 my ($command) = @_;
1926
1927 doprint "$command ... ";
1928
1929 my $output = `$command 2>&1`;
1930 my $ret = $?;
1931
1932 logit $output;
1933
1934 if ($ret) {
1935 doprint "FAILED\n";
1936 dodie "Failed to git bisect";
1937 }
1938
1939 doprint "SUCCESS\n";
1940 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1941 doprint "$1 [$2]\n";
1942 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1943 $bisect_bad = $1;
1944 doprint "Found bad commit... $1\n";
1945 return 0;
1946 } else {
1947 # we already logged it, just print it now.
1948 print $output;
1949 }
1950
1951 return 1;
1952}
1953
Steven Rostedtc23dca72011-03-08 09:26:31 -05001954sub bisect_reboot {
1955 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001956 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001957}
1958
1959# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001960sub run_bisect_test {
1961 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001962
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001963 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001964 my $result;
1965 my $output;
1966 my $ret;
1967
Steven Rostedt0a05c762010-11-08 11:14:10 -05001968 $in_bisect = 1;
1969
1970 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001971
1972 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001973 if ($failed && $bisect_skip) {
1974 $in_bisect = 0;
1975 return -1;
1976 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001977 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001978
1979 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001980 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001981
1982 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001983 if ($failed && $bisect_skip) {
1984 end_monitor;
1985 bisect_reboot;
1986 $in_bisect = 0;
1987 return -1;
1988 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001989 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001990
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001991 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001992 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001993 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001994 }
1995
1996 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001997 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001998 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001999 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002000 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002001
2002 # reboot the box to a kernel we can ssh to
2003 if ($type ne "build") {
2004 bisect_reboot;
2005 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002006 $in_bisect = 0;
2007
2008 return $result;
2009}
2010
2011sub run_bisect {
2012 my ($type) = @_;
2013 my $buildtype = "oldconfig";
2014
2015 # We should have a minconfig to use?
2016 if (defined($minconfig)) {
2017 $buildtype = "useconfig:$minconfig";
2018 }
2019
2020 my $ret = run_bisect_test $type, $buildtype;
2021
Steven Rostedtc960bb92011-03-08 09:22:39 -05002022 if ($bisect_manual) {
2023 $ret = answer_bisect;
2024 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002025
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002026 # Are we looking for where it worked, not failed?
2027 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002028 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002029 }
2030
Steven Rostedtc23dca72011-03-08 09:26:31 -05002031 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002032 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002033 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002034 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002035 } elsif ($bisect_skip) {
2036 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2037 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002038 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002039}
2040
Steven Rostedtdad98752011-11-22 20:48:57 -05002041sub update_bisect_replay {
2042 my $tmp_log = "$tmpdir/ktest_bisect_log";
2043 run_command "git bisect log > $tmp_log" or
2044 die "can't create bisect log";
2045 return $tmp_log;
2046}
2047
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002048sub bisect {
2049 my ($i) = @_;
2050
2051 my $result;
2052
2053 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
2054 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
2055 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
2056
2057 my $good = $opt{"BISECT_GOOD[$i]"};
2058 my $bad = $opt{"BISECT_BAD[$i]"};
2059 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04002060 my $start = $opt{"BISECT_START[$i]"};
2061 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002062 my $start_files = $opt{"BISECT_FILES[$i]"};
2063
2064 if (defined($start_files)) {
2065 $start_files = " -- " . $start_files;
2066 } else {
2067 $start_files = "";
2068 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002069
Steven Rostedta57419b2010-11-02 15:13:54 -04002070 # convert to true sha1's
2071 $good = get_sha1($good);
2072 $bad = get_sha1($bad);
2073
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002074 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
2075 $opt{"BISECT_REVERSE[$i]"} == 1) {
2076 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2077 $reverse_bisect = 1;
2078 } else {
2079 $reverse_bisect = 0;
2080 }
2081
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002082 # Can't have a test without having a test to run
2083 if ($type eq "test" && !defined($run_test)) {
2084 $type = "boot";
2085 }
2086
Steven Rostedtdad98752011-11-22 20:48:57 -05002087 # Check if a bisect was running
2088 my $bisect_start_file = "$builddir/.git/BISECT_START";
2089
Steven Rostedta75fece2010-11-02 14:58:27 -04002090 my $check = $opt{"BISECT_CHECK[$i]"};
Steven Rostedtdad98752011-11-22 20:48:57 -05002091 my $do_check = defined($check) && $check ne "0";
2092
2093 if ( -f $bisect_start_file ) {
2094 print "Bisect in progress found\n";
2095 if ($do_check) {
2096 print " If you say yes, then no checks of good or bad will be done\n";
2097 }
2098 if (defined($replay)) {
2099 print "** BISECT_REPLAY is defined in config file **";
2100 print " Ignore config option and perform new git bisect log?\n";
2101 if (read_ync " (yes, no, or cancel) ") {
2102 $replay = update_bisect_replay;
2103 $do_check = 0;
2104 }
2105 } elsif (read_yn "read git log and continue?") {
2106 $replay = update_bisect_replay;
2107 $do_check = 0;
2108 }
2109 }
2110
2111 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002112
2113 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002114 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002115
2116 if ($check ne "good") {
2117 doprint "TESTING BISECT BAD [$bad]\n";
2118 run_command "git checkout $bad" or
2119 die "Failed to checkout $bad";
2120
2121 $result = run_bisect $type;
2122
2123 if ($result ne "bad") {
2124 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2125 }
2126 }
2127
2128 if ($check ne "bad") {
2129 doprint "TESTING BISECT GOOD [$good]\n";
2130 run_command "git checkout $good" or
2131 die "Failed to checkout $good";
2132
2133 $result = run_bisect $type;
2134
2135 if ($result ne "good") {
2136 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2137 }
2138 }
2139
2140 # checkout where we started
2141 run_command "git checkout $head" or
2142 die "Failed to checkout $head";
2143 }
2144
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002145 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002146 dodie "could not start bisect";
2147
2148 run_command "git bisect good $good" or
2149 dodie "could not set bisect good to $good";
2150
2151 run_git_bisect "git bisect bad $bad" or
2152 dodie "could not set bisect bad to $bad";
2153
2154 if (defined($replay)) {
2155 run_command "git bisect replay $replay" or
2156 dodie "failed to run replay";
2157 }
2158
2159 if (defined($start)) {
2160 run_command "git checkout $start" or
2161 dodie "failed to checkout $start";
2162 }
2163
2164 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002165 do {
2166 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002167 $test = run_git_bisect "git bisect $result";
2168 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002169
2170 run_command "git bisect log" or
2171 dodie "could not capture git bisect log";
2172
2173 run_command "git bisect reset" or
2174 dodie "could not reset git bisect";
2175
2176 doprint "Bad commit was [$bisect_bad]\n";
2177
Steven Rostedt0a05c762010-11-08 11:14:10 -05002178 success $i;
2179}
2180
2181my %config_ignore;
2182my %config_set;
2183
2184my %config_list;
2185my %null_config;
2186
2187my %dependency;
2188
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002189sub assign_configs {
2190 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002191
2192 open (IN, $config)
2193 or dodie "Failed to read $config";
2194
2195 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002196 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002197 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002198 }
2199 }
2200
2201 close(IN);
2202}
2203
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002204sub process_config_ignore {
2205 my ($config) = @_;
2206
2207 assign_configs \%config_ignore, $config;
2208}
2209
Steven Rostedt0a05c762010-11-08 11:14:10 -05002210sub read_current_config {
2211 my ($config_ref) = @_;
2212
2213 %{$config_ref} = ();
2214 undef %{$config_ref};
2215
2216 my @key = keys %{$config_ref};
2217 if ($#key >= 0) {
2218 print "did not delete!\n";
2219 exit;
2220 }
2221 open (IN, "$output_config");
2222
2223 while (<IN>) {
2224 if (/^(CONFIG\S+)=(.*)/) {
2225 ${$config_ref}{$1} = $2;
2226 }
2227 }
2228 close(IN);
2229}
2230
2231sub get_dependencies {
2232 my ($config) = @_;
2233
2234 my $arr = $dependency{$config};
2235 if (!defined($arr)) {
2236 return ();
2237 }
2238
2239 my @deps = @{$arr};
2240
2241 foreach my $dep (@{$arr}) {
2242 print "ADD DEP $dep\n";
2243 @deps = (@deps, get_dependencies $dep);
2244 }
2245
2246 return @deps;
2247}
2248
2249sub create_config {
2250 my @configs = @_;
2251
2252 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2253
2254 foreach my $config (@configs) {
2255 print OUT "$config_set{$config}\n";
2256 my @deps = get_dependencies $config;
2257 foreach my $dep (@deps) {
2258 print OUT "$config_set{$dep}\n";
2259 }
2260 }
2261
2262 foreach my $config (keys %config_ignore) {
2263 print OUT "$config_ignore{$config}\n";
2264 }
2265 close(OUT);
2266
2267# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002268 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002269}
2270
2271sub compare_configs {
2272 my (%a, %b) = @_;
2273
2274 foreach my $item (keys %a) {
2275 if (!defined($b{$item})) {
2276 print "diff $item\n";
2277 return 1;
2278 }
2279 delete $b{$item};
2280 }
2281
2282 my @keys = keys %b;
2283 if ($#keys) {
2284 print "diff2 $keys[0]\n";
2285 }
2286 return -1 if ($#keys >= 0);
2287
2288 return 0;
2289}
2290
2291sub run_config_bisect_test {
2292 my ($type) = @_;
2293
2294 return run_bisect_test $type, "oldconfig";
2295}
2296
2297sub process_passed {
2298 my (%configs) = @_;
2299
2300 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2301 # Passed! All these configs are part of a good compile.
2302 # Add them to the min options.
2303 foreach my $config (keys %configs) {
2304 if (defined($config_list{$config})) {
2305 doprint " removing $config\n";
2306 $config_ignore{$config} = $config_list{$config};
2307 delete $config_list{$config};
2308 }
2309 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002310 doprint "config copied to $outputdir/config_good\n";
2311 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002312}
2313
2314sub process_failed {
2315 my ($config) = @_;
2316
2317 doprint "\n\n***************************************\n";
2318 doprint "Found bad config: $config\n";
2319 doprint "***************************************\n\n";
2320}
2321
2322sub run_config_bisect {
2323
2324 my @start_list = keys %config_list;
2325
2326 if ($#start_list < 0) {
2327 doprint "No more configs to test!!!\n";
2328 return -1;
2329 }
2330
2331 doprint "***** RUN TEST ***\n";
2332 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2333 my $ret;
2334 my %current_config;
2335
2336 my $count = $#start_list + 1;
2337 doprint " $count configs to test\n";
2338
2339 my $half = int($#start_list / 2);
2340
2341 do {
2342 my @tophalf = @start_list[0 .. $half];
2343
2344 create_config @tophalf;
2345 read_current_config \%current_config;
2346
2347 $count = $#tophalf + 1;
2348 doprint "Testing $count configs\n";
2349 my $found = 0;
2350 # make sure we test something
2351 foreach my $config (@tophalf) {
2352 if (defined($current_config{$config})) {
2353 logit " $config\n";
2354 $found = 1;
2355 }
2356 }
2357 if (!$found) {
2358 # try the other half
2359 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002360 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002361 create_config @tophalf;
2362 read_current_config \%current_config;
2363 foreach my $config (@tophalf) {
2364 if (defined($current_config{$config})) {
2365 logit " $config\n";
2366 $found = 1;
2367 }
2368 }
2369 if (!$found) {
2370 doprint "Failed: Can't make new config with current configs\n";
2371 foreach my $config (@start_list) {
2372 doprint " CONFIG: $config\n";
2373 }
2374 return -1;
2375 }
2376 $count = $#tophalf + 1;
2377 doprint "Testing $count configs\n";
2378 }
2379
2380 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002381 if ($bisect_manual) {
2382 $ret = answer_bisect;
2383 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002384 if ($ret) {
2385 process_passed %current_config;
2386 return 0;
2387 }
2388
2389 doprint "This config had a failure.\n";
2390 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002391 doprint "config copied to $outputdir/config_bad\n";
2392 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002393
2394 # A config exists in this group that was bad.
2395 foreach my $config (keys %config_list) {
2396 if (!defined($current_config{$config})) {
2397 doprint " removing $config\n";
2398 delete $config_list{$config};
2399 }
2400 }
2401
2402 @start_list = @tophalf;
2403
2404 if ($#start_list == 0) {
2405 process_failed $start_list[0];
2406 return 1;
2407 }
2408
2409 # remove half the configs we are looking at and see if
2410 # they are good.
2411 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002412 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002413
Steven Rostedtc960bb92011-03-08 09:22:39 -05002414 # we found a single config, try it again unless we are running manually
2415
2416 if ($bisect_manual) {
2417 process_failed $start_list[0];
2418 return 1;
2419 }
2420
Steven Rostedt0a05c762010-11-08 11:14:10 -05002421 my @tophalf = @start_list[0 .. 0];
2422
2423 $ret = run_config_bisect_test $type;
2424 if ($ret) {
2425 process_passed %current_config;
2426 return 0;
2427 }
2428
2429 process_failed $start_list[0];
2430 return 1;
2431}
2432
2433sub config_bisect {
2434 my ($i) = @_;
2435
2436 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2437
2438 my $tmpconfig = "$tmpdir/use_config";
2439
Steven Rostedt30f75da2011-06-13 10:35:35 -04002440 if (defined($config_bisect_good)) {
2441 process_config_ignore $config_bisect_good;
2442 }
2443
Steven Rostedt0a05c762010-11-08 11:14:10 -05002444 # Make the file with the bad config and the min config
2445 if (defined($minconfig)) {
2446 # read the min config for things to ignore
2447 run_command "cp $minconfig $tmpconfig" or
2448 dodie "failed to copy $minconfig to $tmpconfig";
2449 } else {
2450 unlink $tmpconfig;
2451 }
2452
Steven Rostedt0a05c762010-11-08 11:14:10 -05002453 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002454 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002455 process_config_ignore $tmpconfig;
2456 }
2457
2458 # now process the start config
2459 run_command "cp $start_config $output_config" or
2460 dodie "failed to copy $start_config to $output_config";
2461
2462 # read directly what we want to check
2463 my %config_check;
2464 open (IN, $output_config)
2465 or dodie "faied to open $output_config";
2466
2467 while (<IN>) {
2468 if (/^((CONFIG\S*)=.*)/) {
2469 $config_check{$2} = $1;
2470 }
2471 }
2472 close(IN);
2473
Steven Rostedt250bae82011-07-15 22:05:59 -04002474 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002475 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002476
2477 # check to see what we lost (or gained)
2478 open (IN, $output_config)
2479 or dodie "Failed to read $start_config";
2480
2481 my %removed_configs;
2482 my %added_configs;
2483
2484 while (<IN>) {
2485 if (/^((CONFIG\S*)=.*)/) {
2486 # save off all options
2487 $config_set{$2} = $1;
2488 if (defined($config_check{$2})) {
2489 if (defined($config_ignore{$2})) {
2490 $removed_configs{$2} = $1;
2491 } else {
2492 $config_list{$2} = $1;
2493 }
2494 } elsif (!defined($config_ignore{$2})) {
2495 $added_configs{$2} = $1;
2496 $config_list{$2} = $1;
2497 }
2498 }
2499 }
2500 close(IN);
2501
2502 my @confs = keys %removed_configs;
2503 if ($#confs >= 0) {
2504 doprint "Configs overridden by default configs and removed from check:\n";
2505 foreach my $config (@confs) {
2506 doprint " $config\n";
2507 }
2508 }
2509 @confs = keys %added_configs;
2510 if ($#confs >= 0) {
2511 doprint "Configs appearing in make oldconfig and added:\n";
2512 foreach my $config (@confs) {
2513 doprint " $config\n";
2514 }
2515 }
2516
2517 my %config_test;
2518 my $once = 0;
2519
2520 # Sometimes kconfig does weird things. We must make sure
2521 # that the config we autocreate has everything we need
2522 # to test, otherwise we may miss testing configs, or
2523 # may not be able to create a new config.
2524 # Here we create a config with everything set.
2525 create_config (keys %config_list);
2526 read_current_config \%config_test;
2527 foreach my $config (keys %config_list) {
2528 if (!defined($config_test{$config})) {
2529 if (!$once) {
2530 $once = 1;
2531 doprint "Configs not produced by kconfig (will not be checked):\n";
2532 }
2533 doprint " $config\n";
2534 delete $config_list{$config};
2535 }
2536 }
2537 my $ret;
2538 do {
2539 $ret = run_config_bisect;
2540 } while (!$ret);
2541
2542 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002543
2544 success $i;
2545}
2546
Steven Rostedt27d934b2011-05-20 09:18:18 -04002547sub patchcheck_reboot {
2548 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002549 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002550}
2551
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002552sub patchcheck {
2553 my ($i) = @_;
2554
2555 die "PATCHCHECK_START[$i] not defined\n"
2556 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2557 die "PATCHCHECK_TYPE[$i] not defined\n"
2558 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2559
2560 my $start = $opt{"PATCHCHECK_START[$i]"};
2561
2562 my $end = "HEAD";
2563 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2564 $end = $opt{"PATCHCHECK_END[$i]"};
2565 }
2566
Steven Rostedta57419b2010-11-02 15:13:54 -04002567 # Get the true sha1's since we can use things like HEAD~3
2568 $start = get_sha1($start);
2569 $end = get_sha1($end);
2570
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002571 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2572
2573 # Can't have a test without having a test to run
2574 if ($type eq "test" && !defined($run_test)) {
2575 $type = "boot";
2576 }
2577
2578 open (IN, "git log --pretty=oneline $end|") or
2579 dodie "could not get git list";
2580
2581 my @list;
2582
2583 while (<IN>) {
2584 chomp;
2585 $list[$#list+1] = $_;
2586 last if (/^$start/);
2587 }
2588 close(IN);
2589
2590 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002591 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002592 }
2593
2594 # go backwards in the list
2595 @list = reverse @list;
2596
2597 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002598 my %ignored_warnings;
2599
2600 if (defined($ignore_warnings)) {
2601 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2602 $ignored_warnings{$sha1} = 1;
2603 }
2604 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002605
2606 $in_patchcheck = 1;
2607 foreach my $item (@list) {
2608 my $sha1 = $item;
2609 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2610
2611 doprint "\nProcessing commit $item\n\n";
2612
2613 run_command "git checkout $sha1" or
2614 die "Failed to checkout $sha1";
2615
2616 # only clean on the first and last patch
2617 if ($item eq $list[0] ||
2618 $item eq $list[$#list]) {
2619 $noclean = $save_clean;
2620 } else {
2621 $noclean = 1;
2622 }
2623
2624 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002625 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002626 } else {
2627 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002628 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002629 }
2630
Steven Rostedt19902072011-06-14 20:46:25 -04002631
2632 if (!defined($ignored_warnings{$sha1})) {
2633 check_buildlog $sha1 or return 0;
2634 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002635
2636 next if ($type eq "build");
2637
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002638 my $failed = 0;
2639
Steven Rostedtddf607e2011-06-14 20:49:13 -04002640 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002641
2642 if (!$failed && $type ne "boot"){
2643 do_run_test or $failed = 1;
2644 }
2645 end_monitor;
2646 return 0 if ($failed);
2647
Steven Rostedt27d934b2011-05-20 09:18:18 -04002648 patchcheck_reboot;
2649
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002650 }
2651 $in_patchcheck = 0;
2652 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002653
2654 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002655}
2656
Steven Rostedtb9066f62011-07-15 21:25:24 -04002657my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002658my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002659my $iflevel = 0;
2660my @ifdeps;
2661
2662# prevent recursion
2663my %read_kconfigs;
2664
Steven Rostedtac6974c2011-10-04 09:40:17 -04002665sub add_dep {
2666 # $config depends on $dep
2667 my ($config, $dep) = @_;
2668
2669 if (defined($depends{$config})) {
2670 $depends{$config} .= " " . $dep;
2671 } else {
2672 $depends{$config} = $dep;
2673 }
2674
2675 # record the number of configs depending on $dep
2676 if (defined $depcount{$dep}) {
2677 $depcount{$dep}++;
2678 } else {
2679 $depcount{$dep} = 1;
2680 }
2681}
2682
Steven Rostedtb9066f62011-07-15 21:25:24 -04002683# taken from streamline_config.pl
2684sub read_kconfig {
2685 my ($kconfig) = @_;
2686
2687 my $state = "NONE";
2688 my $config;
2689 my @kconfigs;
2690
2691 my $cont = 0;
2692 my $line;
2693
2694
2695 if (! -f $kconfig) {
2696 doprint "file $kconfig does not exist, skipping\n";
2697 return;
2698 }
2699
2700 open(KIN, "$kconfig")
2701 or die "Can't open $kconfig";
2702 while (<KIN>) {
2703 chomp;
2704
2705 # Make sure that lines ending with \ continue
2706 if ($cont) {
2707 $_ = $line . " " . $_;
2708 }
2709
2710 if (s/\\$//) {
2711 $cont = 1;
2712 $line = $_;
2713 next;
2714 }
2715
2716 $cont = 0;
2717
2718 # collect any Kconfig sources
2719 if (/^source\s*"(.*)"/) {
2720 $kconfigs[$#kconfigs+1] = $1;
2721 }
2722
2723 # configs found
2724 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2725 $state = "NEW";
2726 $config = $2;
2727
2728 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002729 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002730 }
2731
2732 # collect the depends for the config
2733 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2734
Steven Rostedtac6974c2011-10-04 09:40:17 -04002735 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002736
2737 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002738 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2739
2740 # selected by depends on config
2741 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002742
2743 # Check for if statements
2744 } elsif (/^if\s+(.*\S)\s*$/) {
2745 my $deps = $1;
2746 # remove beginning and ending non text
2747 $deps =~ s/^[^a-zA-Z0-9_]*//;
2748 $deps =~ s/[^a-zA-Z0-9_]*$//;
2749
2750 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2751
2752 $ifdeps[$iflevel++] = join ':', @deps;
2753
2754 } elsif (/^endif/) {
2755
2756 $iflevel-- if ($iflevel);
2757
2758 # stop on "help"
2759 } elsif (/^\s*help\s*$/) {
2760 $state = "NONE";
2761 }
2762 }
2763 close(KIN);
2764
2765 # read in any configs that were found.
2766 foreach $kconfig (@kconfigs) {
2767 if (!defined($read_kconfigs{$kconfig})) {
2768 $read_kconfigs{$kconfig} = 1;
2769 read_kconfig("$builddir/$kconfig");
2770 }
2771 }
2772}
2773
2774sub read_depends {
2775 # find out which arch this is by the kconfig file
2776 open (IN, $output_config)
2777 or dodie "Failed to read $output_config";
2778 my $arch;
2779 while (<IN>) {
2780 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2781 $arch = $1;
2782 last;
2783 }
2784 }
2785 close IN;
2786
2787 if (!defined($arch)) {
2788 doprint "Could not find arch from config file\n";
2789 doprint "no dependencies used\n";
2790 return;
2791 }
2792
2793 # arch is really the subarch, we need to know
2794 # what directory to look at.
2795 if ($arch eq "i386" || $arch eq "x86_64") {
2796 $arch = "x86";
2797 } elsif ($arch =~ /^tile/) {
2798 $arch = "tile";
2799 }
2800
2801 my $kconfig = "$builddir/arch/$arch/Kconfig";
2802
2803 if (! -f $kconfig && $arch =~ /\d$/) {
2804 my $orig = $arch;
2805 # some subarchs have numbers, truncate them
2806 $arch =~ s/\d*$//;
2807 $kconfig = "$builddir/arch/$arch/Kconfig";
2808 if (! -f $kconfig) {
2809 doprint "No idea what arch dir $orig is for\n";
2810 doprint "no dependencies used\n";
2811 return;
2812 }
2813 }
2814
2815 read_kconfig($kconfig);
2816}
2817
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002818sub read_config_list {
2819 my ($config) = @_;
2820
2821 open (IN, $config)
2822 or dodie "Failed to read $config";
2823
2824 while (<IN>) {
2825 if (/^((CONFIG\S*)=.*)/) {
2826 if (!defined($config_ignore{$2})) {
2827 $config_list{$2} = $1;
2828 }
2829 }
2830 }
2831
2832 close(IN);
2833}
2834
2835sub read_output_config {
2836 my ($config) = @_;
2837
2838 assign_configs \%config_ignore, $config;
2839}
2840
2841sub make_new_config {
2842 my @configs = @_;
2843
2844 open (OUT, ">$output_config")
2845 or dodie "Failed to write $output_config";
2846
2847 foreach my $config (@configs) {
2848 print OUT "$config\n";
2849 }
2850 close OUT;
2851}
2852
Steven Rostedtac6974c2011-10-04 09:40:17 -04002853sub chomp_config {
2854 my ($config) = @_;
2855
2856 $config =~ s/CONFIG_//;
2857
2858 return $config;
2859}
2860
Steven Rostedtb9066f62011-07-15 21:25:24 -04002861sub get_depends {
2862 my ($dep) = @_;
2863
Steven Rostedtac6974c2011-10-04 09:40:17 -04002864 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002865
2866 $dep = $depends{"$kconfig"};
2867
2868 # the dep string we have saves the dependencies as they
2869 # were found, including expressions like ! && ||. We
2870 # want to split this out into just an array of configs.
2871
2872 my $valid = "A-Za-z_0-9";
2873
2874 my @configs;
2875
2876 while ($dep =~ /[$valid]/) {
2877
2878 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2879 my $conf = "CONFIG_" . $1;
2880
2881 $configs[$#configs + 1] = $conf;
2882
2883 $dep =~ s/^[^$valid]*[$valid]+//;
2884 } else {
2885 die "this should never happen";
2886 }
2887 }
2888
2889 return @configs;
2890}
2891
2892my %min_configs;
2893my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002894my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002895my %processed_configs;
2896my %nochange_config;
2897
2898sub test_this_config {
2899 my ($config) = @_;
2900
2901 my $found;
2902
2903 # if we already processed this config, skip it
2904 if (defined($processed_configs{$config})) {
2905 return undef;
2906 }
2907 $processed_configs{$config} = 1;
2908
2909 # if this config failed during this round, skip it
2910 if (defined($nochange_config{$config})) {
2911 return undef;
2912 }
2913
Steven Rostedtac6974c2011-10-04 09:40:17 -04002914 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002915
2916 # Test dependencies first
2917 if (defined($depends{"$kconfig"})) {
2918 my @parents = get_depends $config;
2919 foreach my $parent (@parents) {
2920 # if the parent is in the min config, check it first
2921 next if (!defined($min_configs{$parent}));
2922 $found = test_this_config($parent);
2923 if (defined($found)) {
2924 return $found;
2925 }
2926 }
2927 }
2928
2929 # Remove this config from the list of configs
2930 # do a make oldnoconfig and then read the resulting
2931 # .config to make sure it is missing the config that
2932 # we had before
2933 my %configs = %min_configs;
2934 delete $configs{$config};
2935 make_new_config ((values %configs), (values %keep_configs));
2936 make_oldconfig;
2937 undef %configs;
2938 assign_configs \%configs, $output_config;
2939
2940 return $config if (!defined($configs{$config}));
2941
2942 doprint "disabling config $config did not change .config\n";
2943
2944 $nochange_config{$config} = 1;
2945
2946 return undef;
2947}
2948
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002949sub make_min_config {
2950 my ($i) = @_;
2951
2952 if (!defined($output_minconfig)) {
2953 fail "OUTPUT_MIN_CONFIG not defined" and return;
2954 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002955
2956 # If output_minconfig exists, and the start_minconfig
2957 # came from min_config, than ask if we should use
2958 # that instead.
2959 if (-f $output_minconfig && !$start_minconfig_defined) {
2960 print "$output_minconfig exists\n";
2961 if (read_yn " Use it as minconfig?") {
2962 $start_minconfig = $output_minconfig;
2963 }
2964 }
2965
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002966 if (!defined($start_minconfig)) {
2967 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2968 }
2969
Steven Rostedt35ce5952011-07-15 21:57:25 -04002970 my $temp_config = "$tmpdir/temp_config";
2971
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002972 # First things first. We build an allnoconfig to find
2973 # out what the defaults are that we can't touch.
2974 # Some are selections, but we really can't handle selections.
2975
2976 my $save_minconfig = $minconfig;
2977 undef $minconfig;
2978
2979 run_command "$make allnoconfig" or return 0;
2980
Steven Rostedtb9066f62011-07-15 21:25:24 -04002981 read_depends;
2982
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002983 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002984
Steven Rostedt43d1b652011-07-15 22:01:56 -04002985 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002986 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002987
2988 if (defined($ignore_config)) {
2989 # make sure the file exists
2990 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002991 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002992 }
2993
Steven Rostedt43d1b652011-07-15 22:01:56 -04002994 %keep_configs = %save_configs;
2995
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002996 doprint "Load initial configs from $start_minconfig\n";
2997
2998 # Look at the current min configs, and save off all the
2999 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003000 assign_configs \%min_configs, $start_minconfig;
3001
3002 my @config_keys = keys %min_configs;
3003
Steven Rostedtac6974c2011-10-04 09:40:17 -04003004 # All configs need a depcount
3005 foreach my $config (@config_keys) {
3006 my $kconfig = chomp_config $config;
3007 if (!defined $depcount{$kconfig}) {
3008 $depcount{$kconfig} = 0;
3009 }
3010 }
3011
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003012 # Remove anything that was set by the make allnoconfig
3013 # we shouldn't need them as they get set for us anyway.
3014 foreach my $config (@config_keys) {
3015 # Remove anything in the ignore_config
3016 if (defined($keep_configs{$config})) {
3017 my $file = $ignore_config;
3018 $file =~ s,.*/(.*?)$,$1,;
3019 doprint "$config set by $file ... ignored\n";
3020 delete $min_configs{$config};
3021 next;
3022 }
3023 # But make sure the settings are the same. If a min config
3024 # sets a selection, we do not want to get rid of it if
3025 # it is not the same as what we have. Just move it into
3026 # the keep configs.
3027 if (defined($config_ignore{$config})) {
3028 if ($config_ignore{$config} ne $min_configs{$config}) {
3029 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3030 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3031 $keep_configs{$config} = $min_configs{$config};
3032 } else {
3033 doprint "$config set by allnoconfig ... ignored\n";
3034 }
3035 delete $min_configs{$config};
3036 }
3037 }
3038
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003039 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003040 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003041
3042 while (!$done) {
3043
3044 my $config;
3045 my $found;
3046
3047 # Now disable each config one by one and do a make oldconfig
3048 # till we find a config that changes our list.
3049
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003050 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003051
3052 # Sort keys by who is most dependent on
3053 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3054 @test_configs ;
3055
3056 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003057 my $reset = 1;
3058 for (my $i = 0; $i < $#test_configs; $i++) {
3059 if (!defined($nochange_config{$test_configs[0]})) {
3060 $reset = 0;
3061 last;
3062 }
3063 # This config didn't change the .config last time.
3064 # Place it at the end
3065 my $config = shift @test_configs;
3066 push @test_configs, $config;
3067 }
3068
3069 # if every test config has failed to modify the .config file
3070 # in the past, then reset and start over.
3071 if ($reset) {
3072 undef %nochange_config;
3073 }
3074
Steven Rostedtb9066f62011-07-15 21:25:24 -04003075 undef %processed_configs;
3076
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003077 foreach my $config (@test_configs) {
3078
Steven Rostedtb9066f62011-07-15 21:25:24 -04003079 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003080
Steven Rostedtb9066f62011-07-15 21:25:24 -04003081 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003082
3083 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003084 }
3085
3086 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003087 # we could have failed due to the nochange_config hash
3088 # reset and try again
3089 if (!$take_two) {
3090 undef %nochange_config;
3091 $take_two = 1;
3092 next;
3093 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003094 doprint "No more configs found that we can disable\n";
3095 $done = 1;
3096 last;
3097 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003098 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003099
3100 $config = $found;
3101
3102 doprint "Test with $config disabled\n";
3103
3104 # set in_bisect to keep build and monitor from dieing
3105 $in_bisect = 1;
3106
3107 my $failed = 0;
3108 build "oldconfig";
3109 start_monitor_and_boot or $failed = 1;
3110 end_monitor;
3111
3112 $in_bisect = 0;
3113
3114 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003115 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003116 # this config is needed, add it to the ignore list.
3117 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003118 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003119 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003120
3121 # update new ignore configs
3122 if (defined($ignore_config)) {
3123 open (OUT, ">$temp_config")
3124 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003125 foreach my $config (keys %save_configs) {
3126 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003127 }
3128 close OUT;
3129 run_command "mv $temp_config $ignore_config" or
3130 dodie "failed to copy update to $ignore_config";
3131 }
3132
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003133 } else {
3134 # We booted without this config, remove it from the minconfigs.
3135 doprint "$config is not needed, disabling\n";
3136
3137 delete $min_configs{$config};
3138
3139 # Also disable anything that is not enabled in this config
3140 my %configs;
3141 assign_configs \%configs, $output_config;
3142 my @config_keys = keys %min_configs;
3143 foreach my $config (@config_keys) {
3144 if (!defined($configs{$config})) {
3145 doprint "$config is not set, disabling\n";
3146 delete $min_configs{$config};
3147 }
3148 }
3149
3150 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003151 open (OUT, ">$temp_config")
3152 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003153 foreach my $config (keys %keep_configs) {
3154 print OUT "$keep_configs{$config}\n";
3155 }
3156 foreach my $config (keys %min_configs) {
3157 print OUT "$min_configs{$config}\n";
3158 }
3159 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003160
3161 run_command "mv $temp_config $output_minconfig" or
3162 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003163 }
3164
3165 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003166 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003167 }
3168
3169 success $i;
3170 return 1;
3171}
3172
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003173$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003174
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003175if ($#ARGV == 0) {
3176 $ktest_config = $ARGV[0];
3177 if (! -f $ktest_config) {
3178 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003179 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003180 exit 0;
3181 }
3182 }
3183} else {
3184 $ktest_config = "ktest.conf";
3185}
3186
3187if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003188 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003189 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003190 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3191 print OUT << "EOF"
3192# Generated by ktest.pl
3193#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003194
3195# PWD is a ktest.pl variable that will result in the process working
3196# directory that ktest.pl is executed in.
3197
3198# THIS_DIR is automatically assigned the PWD of the path that generated
3199# the config file. It is best to use this variable when assigning other
3200# directory paths within this directory. This allows you to easily
3201# move the test cases to other locations or to other machines.
3202#
3203THIS_DIR := $variable{"PWD"}
3204
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003205# Define each test with TEST_START
3206# The config options below it will override the defaults
3207TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003208TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003209
3210DEFAULTS
3211EOF
3212;
3213 close(OUT);
3214}
3215read_config $ktest_config;
3216
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003217if (defined($opt{"LOG_FILE"})) {
3218 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3219}
3220
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003221# Append any configs entered in manually to the config file.
3222my @new_configs = keys %entered_configs;
3223if ($#new_configs >= 0) {
3224 print "\nAppending entered in configs to $ktest_config\n";
3225 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3226 foreach my $config (@new_configs) {
3227 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003228 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003229 }
3230}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003231
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003232if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3233 unlink $opt{"LOG_FILE"};
3234}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003235
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003236doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3237
Steven Rostedta57419b2010-11-02 15:13:54 -04003238for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3239
3240 if (!$i) {
3241 doprint "DEFAULT OPTIONS:\n";
3242 } else {
3243 doprint "\nTEST $i OPTIONS";
3244 if (defined($repeat_tests{$i})) {
3245 $repeat = $repeat_tests{$i};
3246 doprint " ITERATE $repeat";
3247 }
3248 doprint "\n";
3249 }
3250
3251 foreach my $option (sort keys %opt) {
3252
3253 if ($option =~ /\[(\d+)\]$/) {
3254 next if ($i != $1);
3255 } else {
3256 next if ($i);
3257 }
3258
3259 doprint "$option = $opt{$option}\n";
3260 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003261}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003262
Steven Rostedt2a625122011-05-20 15:48:59 -04003263sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003264 my ($name, $i) = @_;
3265
3266 my $option = "$name\[$i\]";
3267
3268 if (defined($opt{$option})) {
3269 return $opt{$option};
3270 }
3271
Steven Rostedta57419b2010-11-02 15:13:54 -04003272 foreach my $test (keys %repeat_tests) {
3273 if ($i >= $test &&
3274 $i < $test + $repeat_tests{$test}) {
3275 $option = "$name\[$test\]";
3276 if (defined($opt{$option})) {
3277 return $opt{$option};
3278 }
3279 }
3280 }
3281
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003282 if (defined($opt{$name})) {
3283 return $opt{$name};
3284 }
3285
3286 return undef;
3287}
3288
Steven Rostedt2a625122011-05-20 15:48:59 -04003289sub set_test_option {
3290 my ($name, $i) = @_;
3291
3292 my $option = __set_test_option($name, $i);
3293 return $option if (!defined($option));
3294
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003295 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003296}
3297
Steven Rostedt2545eb62010-11-02 15:01:32 -04003298# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003299for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003300
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003301 # Do not reboot on failing test options
3302 $no_reboot = 1;
3303
Steven Rostedt576f6272010-11-02 14:58:38 -04003304 $iteration = $i;
3305
Steven Rostedta75fece2010-11-02 14:58:27 -04003306 my $makecmd = set_test_option("MAKE_CMD", $i);
3307
3308 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003309 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003310 $tmpdir = set_test_option("TMP_DIR", $i);
3311 $outputdir = set_test_option("OUTPUT_DIR", $i);
3312 $builddir = set_test_option("BUILD_DIR", $i);
3313 $test_type = set_test_option("TEST_TYPE", $i);
3314 $build_type = set_test_option("BUILD_TYPE", $i);
3315 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003316 $pre_build = set_test_option("PRE_BUILD", $i);
3317 $post_build = set_test_option("POST_BUILD", $i);
3318 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3319 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003320 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003321 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003322 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3323 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003324 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3325 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3326 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003327 $run_test = set_test_option("TEST", $i);
3328 $addconfig = set_test_option("ADD_CONFIG", $i);
3329 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3330 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003331 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003332 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003333 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3334 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003335 $switch_to_good = set_test_option("SWITCH_TO_GOOD", $i);
3336 $switch_to_test = set_test_option("SWITCH_TO_TEST", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003337 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3338 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3339 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003340 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3341 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003342 $sleep_time = set_test_option("SLEEP_TIME", $i);
3343 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003344 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003345 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003346 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003347 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003348 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedtc5dacb82011-12-22 12:43:57 -05003349 $bisect_ret_good = set_test_option("BISECT_RET_GOOD", $i);
3350 $bisect_ret_bad = set_test_option("BISECT_RET_BAD", $i);
3351 $bisect_ret_skip = set_test_option("BISECT_RET_SKIP", $i);
3352 $bisect_ret_abort = set_test_option("BISECT_RET_ABORT", $i);
3353 $bisect_ret_default = set_test_option("BISECT_RET_DEFAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003354 $store_failures = set_test_option("STORE_FAILURES", $i);
Rabin Vincentde5b6e32011-11-18 17:05:31 +05303355 $store_successes = set_test_option("STORE_SUCCESSES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003356 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003357 $timeout = set_test_option("TIMEOUT", $i);
3358 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3359 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003360 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003361 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003362 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003363 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3364 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003365 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003366 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003367 $ssh_exec = set_test_option("SSH_EXEC", $i);
3368 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003369 $target_image = set_test_option("TARGET_IMAGE", $i);
3370 $localversion = set_test_option("LOCALVERSION", $i);
3371
Steven Rostedt35ce5952011-07-15 21:57:25 -04003372 $start_minconfig_defined = 1;
3373
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003374 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003375 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003376 $start_minconfig = $minconfig;
3377 }
3378
Steven Rostedta75fece2010-11-02 14:58:27 -04003379 chdir $builddir || die "can't change directory to $builddir";
3380
Andrew Jonesa908a662011-08-12 15:32:03 +02003381 foreach my $dir ($tmpdir, $outputdir) {
3382 if (!-d $dir) {
3383 mkpath($dir) or
3384 die "can't create $dir";
3385 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003386 }
3387
Steven Rostedte48c5292010-11-02 14:35:37 -04003388 $ENV{"SSH_USER"} = $ssh_user;
3389 $ENV{"MACHINE"} = $machine;
3390
Steven Rostedta75fece2010-11-02 14:58:27 -04003391 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303392 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003393 $dmesg = "$tmpdir/dmesg-$machine";
3394 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003395 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003396
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003397 if (!$buildonly) {
3398 $target = "$ssh_user\@$machine";
3399 if ($reboot_type eq "grub") {
3400 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3401 } elsif (!defined($reboot_script)) {
3402 dodie "REBOOT_SCRIPT not defined"
3403 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003404 }
3405
3406 my $run_type = $build_type;
3407 if ($test_type eq "patchcheck") {
3408 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3409 } elsif ($test_type eq "bisect") {
3410 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003411 } elsif ($test_type eq "config_bisect") {
3412 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003413 }
3414
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003415 if ($test_type eq "make_min_config") {
3416 $run_type = "";
3417 }
3418
Steven Rostedta75fece2010-11-02 14:58:27 -04003419 # mistake in config file?
3420 if (!defined($run_type)) {
3421 $run_type = "ERROR";
3422 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003423
Steven Rostedte0a87422011-09-30 17:50:48 -04003424 my $installme = "";
3425 $installme = " no_install" if ($no_install);
3426
Steven Rostedt2545eb62010-11-02 15:01:32 -04003427 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003428 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003429
3430 unlink $dmesg;
3431 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303432 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003433
Steven Rostedt250bae82011-07-15 22:05:59 -04003434 if (defined($addconfig)) {
3435 my $min = $minconfig;
3436 if (!defined($minconfig)) {
3437 $min = "";
3438 }
3439 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003440 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003441 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003442 }
3443
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003444 my $checkout = $opt{"CHECKOUT[$i]"};
3445 if (defined($checkout)) {
3446 run_command "git checkout $checkout" or
3447 die "failed to checkout $checkout";
3448 }
3449
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003450 $no_reboot = 0;
3451
3452
Steven Rostedta75fece2010-11-02 14:58:27 -04003453 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003454 bisect $i;
3455 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003456 } elsif ($test_type eq "config_bisect") {
3457 config_bisect $i;
3458 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003459 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003460 patchcheck $i;
3461 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003462 } elsif ($test_type eq "make_min_config") {
3463 make_min_config $i;
3464 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003465 }
3466
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003467 if ($build_type ne "nobuild") {
3468 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003469 }
3470
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003471 if ($test_type eq "install") {
3472 get_version;
3473 install;
3474 success $i;
3475 next;
3476 }
3477
Steven Rostedta75fece2010-11-02 14:58:27 -04003478 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003479 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003480 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003481
3482 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3483 do_run_test or $failed = 1;
3484 }
3485 end_monitor;
3486 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003487 }
3488
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003489 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003490}
3491
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003492if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003493 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003494} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003495 reboot_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003496}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003497
Steven Rostedte48c5292010-11-02 14:35:37 -04003498doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3499
Steven Rostedt2545eb62010-11-02 15:01:32 -04003500exit 0;