blob: 59738aa6ca7310e278dc01a5f68f5e891cc7c943 [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002#
Uwe Kleine-Königcce1dac2011-01-24 21:12:01 +01003# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04004# Licensed under the terms of the GNU GPL License version 2
5#
Steven Rostedt2545eb62010-11-02 15:01:32 -04006
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Steven Rostedt7faafbd2010-11-02 14:58:22 -040010use File::Path qw(mkpath);
11use File::Copy qw(cp);
Steven Rostedt2545eb62010-11-02 15:01:32 -040012use FileHandle;
13
Steven Rostedte48c5292010-11-02 14:35:37 -040014my $VERSION = "0.2";
15
Steven Rostedt2545eb62010-11-02 15:01:32 -040016$| = 1;
17
18my %opt;
Steven Rostedta57419b2010-11-02 15:13:54 -040019my %repeat_tests;
20my %repeats;
Steven Rostedta75fece2010-11-02 14:58:27 -040021my %default;
Steven Rostedt2545eb62010-11-02 15:01:32 -040022
23#default opts
Steven Rostedta57419b2010-11-02 15:13:54 -040024$default{"NUM_TESTS"} = 1;
Steven Rostedtbb8474b2011-11-23 15:58:00 -050025$default{"TEST_TYPE"} = "build";
Steven Rostedta75fece2010-11-02 14:58:27 -040026$default{"BUILD_TYPE"} = "randconfig";
27$default{"MAKE_CMD"} = "make";
28$default{"TIMEOUT"} = 120;
Steven Rostedt48920632011-06-14 20:42:19 -040029$default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
Steven Rostedta75fece2010-11-02 14:58:27 -040030$default{"SLEEP_TIME"} = 60; # sleep time between tests
31$default{"BUILD_NOCLEAN"} = 0;
32$default{"REBOOT_ON_ERROR"} = 0;
33$default{"POWEROFF_ON_ERROR"} = 0;
34$default{"REBOOT_ON_SUCCESS"} = 1;
35$default{"POWEROFF_ON_SUCCESS"} = 0;
36$default{"BUILD_OPTIONS"} = "";
37$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
Steven Rostedt27d934b2011-05-20 09:18:18 -040038$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
Steven Rostedta75fece2010-11-02 14:58:27 -040039$default{"CLEAR_LOG"} = 0;
Steven Rostedtc960bb92011-03-08 09:22:39 -050040$default{"BISECT_MANUAL"} = 0;
Steven Rostedtc23dca72011-03-08 09:26:31 -050041$default{"BISECT_SKIP"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040042$default{"SUCCESS_LINE"} = "login:";
Steven Rostedtf1a5b962011-06-13 10:30:00 -040043$default{"DETECT_TRIPLE_FAULT"} = 1;
Steven Rostedte0a87422011-09-30 17:50:48 -040044$default{"NO_INSTALL"} = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040045$default{"BOOTED_TIMEOUT"} = 1;
46$default{"DIE_ON_FAILURE"} = 1;
Steven Rostedte48c5292010-11-02 14:35:37 -040047$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
48$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
49$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
Steven Rostedt1c8a6172010-11-09 12:55:40 -050050$default{"STOP_AFTER_SUCCESS"} = 10;
51$default{"STOP_AFTER_FAILURE"} = 60;
Steven Rostedt2d01b262011-03-08 09:47:54 -050052$default{"STOP_TEST_AFTER"} = 600;
Steven Rostedt600bbf02011-11-21 20:12:04 -050053
54# required, and we will ask users if they don't have them but we keep the default
55# value something that is common.
56$default{"REBOOT_TYPE"} = "grub";
Steven Rostedt8d1491b2010-11-18 15:39:48 -050057$default{"LOCALVERSION"} = "-test";
Steven Rostedt600bbf02011-11-21 20:12:04 -050058$default{"SSH_USER"} = "root";
59$default{"BUILD_TARGET"} = "arch/x86/boot/bzImage";
60$default{"TARGET_IMAGE"} = "/boot/vmlinuz-test";
Steven Rostedt2545eb62010-11-02 15:01:32 -040061
Steven Rostedt8d1491b2010-11-18 15:39:48 -050062my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040063my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040064my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040065my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040066my $tmpdir;
67my $builddir;
68my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050069my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040070my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040071my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040072my $build_options;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040073my $pre_build;
74my $post_build;
75my $pre_build_die;
76my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $reboot_type;
78my $reboot_script;
79my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040080my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040081my $reboot_on_error;
82my $poweroff_on_error;
83my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040084my $powercycle_after_reboot;
85my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040086my $ssh_exec;
87my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040088my $power_off;
89my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040090my $grub_number;
91my $target;
92my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040093my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -040094my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040095my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040096my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040097my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -040098my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040099my $output_minconfig;
100my $ignore_config;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400101my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400102my $in_bisect = 0;
103my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400104my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500105my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500106my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400107my $config_bisect_good;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400108my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400109my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400110my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400111my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530112my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400113my $dmesg;
114my $monitor_fp;
115my $monitor_pid;
116my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400117my $sleep_time;
118my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400119my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400120my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400121my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530122my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400123my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400124my $timeout;
125my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400126my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400127my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400128my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400129my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500130my $stop_after_success;
131my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500132my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400133my $build_target;
134my $target_image;
135my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400136my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400137my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400138
Steven Rostedt165708b2011-11-26 20:56:52 -0500139# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500140# which would require more options.
141my $buildonly = 1;
142
Steven Rostedtdbd37832011-11-23 16:00:48 -0500143# set when creating a new config
144my $newconfig = 0;
145
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500146my %entered_configs;
147my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400148my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400149my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500150
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400151# do not force reboots on config problems
152my $no_reboot = 1;
153
Steven Rostedt7bf51072011-10-22 09:07:03 -0400154# default variables that can be used
155chomp ($variable{"PWD"} = `pwd`);
156
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500157$config_help{"MACHINE"} = << "EOF"
158 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500159 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500160EOF
161 ;
162$config_help{"SSH_USER"} = << "EOF"
163 The box is expected to have ssh on normal bootup, provide the user
164 (most likely root, since you need privileged operations)
165EOF
166 ;
167$config_help{"BUILD_DIR"} = << "EOF"
168 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500169 You can use \${PWD} that will be the path where ktest.pl is run, or use
170 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500171EOF
172 ;
173$config_help{"OUTPUT_DIR"} = << "EOF"
174 The directory that the objects will be built (full path).
175 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500176 You can use \${PWD} that will be the path where ktest.pl is run, or use
177 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500178EOF
179 ;
180$config_help{"BUILD_TARGET"} = << "EOF"
181 The location of the compiled file to copy to the target.
182 (relative to OUTPUT_DIR)
183EOF
184 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500185$config_help{"BUILD_OPTIONS"} = << "EOF"
186 Options to add to \"make\" when building.
187 i.e. -j20
188EOF
189 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500190$config_help{"TARGET_IMAGE"} = << "EOF"
191 The place to put your image on the test machine.
192EOF
193 ;
194$config_help{"POWER_CYCLE"} = << "EOF"
195 A script or command to reboot the box.
196
197 Here is a digital loggers power switch example
198 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
199
200 Here is an example to reboot a virtual box on the current host
201 with the name "Guest".
202 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
203EOF
204 ;
205$config_help{"CONSOLE"} = << "EOF"
206 The script or command that reads the console
207
208 If you use ttywatch server, something like the following would work.
209CONSOLE = nc -d localhost 3001
210
211 For a virtual machine with guest name "Guest".
212CONSOLE = virsh console Guest
213EOF
214 ;
215$config_help{"LOCALVERSION"} = << "EOF"
216 Required version ending to differentiate the test
217 from other linux builds on the system.
218EOF
219 ;
220$config_help{"REBOOT_TYPE"} = << "EOF"
221 Way to reboot the box to the test kernel.
222 Only valid options so far are "grub" and "script".
223
224 If you specify grub, it will assume grub version 1
225 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
226 and select that target to reboot to the kernel. If this is not
227 your setup, then specify "script" and have a command or script
228 specified in REBOOT_SCRIPT to boot to the target.
229
230 The entry in /boot/grub/menu.lst must be entered in manually.
231 The test will not modify that file.
232EOF
233 ;
234$config_help{"GRUB_MENU"} = << "EOF"
235 The grub title name for the test kernel to boot
236 (Only mandatory if REBOOT_TYPE = grub)
237
238 Note, ktest.pl will not update the grub menu.lst, you need to
239 manually add an option for the test. ktest.pl will search
240 the grub menu.lst for this option to find what kernel to
241 reboot into.
242
243 For example, if in the /boot/grub/menu.lst the test kernel title has:
244 title Test Kernel
245 kernel vmlinuz-test
246 GRUB_MENU = Test Kernel
247EOF
248 ;
249$config_help{"REBOOT_SCRIPT"} = << "EOF"
250 A script to reboot the target into the test kernel
251 (Only mandatory if REBOOT_TYPE = script)
252EOF
253 ;
254
Steven Rostedtdad98752011-11-22 20:48:57 -0500255sub read_prompt {
256 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400257
258 my $ans;
259
260 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500261 if ($cancel) {
262 print "$prompt [y/n/C] ";
263 } else {
264 print "$prompt [Y/n] ";
265 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400266 $ans = <STDIN>;
267 chomp $ans;
268 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500269 if ($cancel) {
270 $ans = "c";
271 } else {
272 $ans = "y";
273 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400274 }
275 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500276 if ($cancel) {
277 last if ($ans =~ /^c$/i);
278 print "Please answer either 'y', 'n' or 'c'.\n";
279 } else {
280 print "Please answer either 'y' or 'n'.\n";
281 }
282 }
283 if ($ans =~ /^c/i) {
284 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400285 }
286 if ($ans !~ /^y$/i) {
287 return 0;
288 }
289 return 1;
290}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500291
Steven Rostedtdad98752011-11-22 20:48:57 -0500292sub read_yn {
293 my ($prompt) = @_;
294
295 return read_prompt 0, $prompt;
296}
297
298sub read_ync {
299 my ($prompt) = @_;
300
301 return read_prompt 1, $prompt;
302}
303
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500304sub get_ktest_config {
305 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400306 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500307
308 return if (defined($opt{$config}));
309
310 if (defined($config_help{$config})) {
311 print "\n";
312 print $config_help{$config};
313 }
314
315 for (;;) {
316 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500317 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500318 print "\[$default{$config}\] ";
319 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400320 $ans = <STDIN>;
321 $ans =~ s/^\s*(.*\S)\s*$/$1/;
322 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500323 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400324 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500325 } else {
326 print "Your answer can not be blank\n";
327 next;
328 }
329 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500330 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500331 last;
332 }
333}
334
335sub get_ktest_configs {
336 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500337 get_ktest_config("BUILD_DIR");
338 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500339
Steven Rostedtdbd37832011-11-23 16:00:48 -0500340 if ($newconfig) {
341 get_ktest_config("BUILD_OPTIONS");
342 }
343
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500344 # options required for other than just building a kernel
345 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500346 get_ktest_config("POWER_CYCLE");
347 get_ktest_config("CONSOLE");
348 }
349
350 # options required for install and more
351 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500352 get_ktest_config("SSH_USER");
353 get_ktest_config("BUILD_TARGET");
354 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500355 }
356
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500357 get_ktest_config("LOCALVERSION");
358
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500359 return if ($buildonly);
360
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500361 my $rtype = $opt{"REBOOT_TYPE"};
362
363 if (!defined($rtype)) {
364 if (!defined($opt{"GRUB_MENU"})) {
365 get_ktest_config("REBOOT_TYPE");
366 $rtype = $entered_configs{"REBOOT_TYPE"};
367 } else {
368 $rtype = "grub";
369 }
370 }
371
372 if ($rtype eq "grub") {
373 get_ktest_config("GRUB_MENU");
374 } else {
375 get_ktest_config("REBOOT_SCRIPT");
376 }
377}
378
Steven Rostedt77d942c2011-05-20 13:36:58 -0400379sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400380 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400381 my $retval = "";
382
383 # We want to check for '\', and it is just easier
384 # to check the previous characet of '$' and not need
385 # to worry if '$' is the first character. By adding
386 # a space to $value, we can just check [^\\]\$ and
387 # it will still work.
388 $value = " $value";
389
390 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
391 my $begin = $1;
392 my $var = $2;
393 my $end = $3;
394 # append beginning of value to retval
395 $retval = "$retval$begin";
396 if (defined($variable{$var})) {
397 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400398 } elsif (defined($remove_undef) && $remove_undef) {
399 # for if statements, any variable that is not defined,
400 # we simple convert to 0
401 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400402 } else {
403 # put back the origin piece.
404 $retval = "$retval\$\{$var\}";
405 }
406 $value = $end;
407 }
408 $retval = "$retval$value";
409
410 # remove the space added in the beginning
411 $retval =~ s/ //;
412
413 return "$retval"
414}
415
Steven Rostedta57419b2010-11-02 15:13:54 -0400416sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400417 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400418
Steven Rostedt165708b2011-11-26 20:56:52 -0500419 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $rvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500420 # Note if a test is something other than build, then we
421 # will need other manditory options.
Steven Rostedt165708b2011-11-26 20:56:52 -0500422 if ($rvalue ne "install") {
423 $buildonly = 0;
424 } else {
425 # install still limits some manditory options.
426 $buildonly = 2;
427 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500428 }
429
Steven Rostedta57419b2010-11-02 15:13:54 -0400430 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400431 if (!$override || defined(${$overrides}{$lvalue})) {
432 my $extra = "";
433 if ($override) {
434 $extra = "In the same override section!\n";
435 }
436 die "$name: $.: Option $lvalue defined more than once!\n$extra";
437 }
438 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400439 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500440 if ($rvalue =~ /^\s*$/) {
441 delete $opt{$lvalue};
442 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400443 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500444 $opt{$lvalue} = $rvalue;
445 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400446}
447
Steven Rostedt77d942c2011-05-20 13:36:58 -0400448sub set_variable {
449 my ($lvalue, $rvalue) = @_;
450
451 if ($rvalue =~ /^\s*$/) {
452 delete $variable{$lvalue};
453 } else {
454 $rvalue = process_variables($rvalue);
455 $variable{$lvalue} = $rvalue;
456 }
457}
458
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400459sub process_compare {
460 my ($lval, $cmp, $rval) = @_;
461
462 # remove whitespace
463
464 $lval =~ s/^\s*//;
465 $lval =~ s/\s*$//;
466
467 $rval =~ s/^\s*//;
468 $rval =~ s/\s*$//;
469
470 if ($cmp eq "==") {
471 return $lval eq $rval;
472 } elsif ($cmp eq "!=") {
473 return $lval ne $rval;
474 }
475
476 my $statement = "$lval $cmp $rval";
477 my $ret = eval $statement;
478
479 # $@ stores error of eval
480 if ($@) {
481 return -1;
482 }
483
484 return $ret;
485}
486
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400487sub value_defined {
488 my ($val) = @_;
489
490 return defined($variable{$2}) ||
491 defined($opt{$2});
492}
493
Steven Rostedt8d735212011-10-17 11:36:44 -0400494my $d = 0;
495sub process_expression {
496 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400497
Steven Rostedt8d735212011-10-17 11:36:44 -0400498 my $c = $d++;
499
500 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
501 my $express = $1;
502
503 if (process_expression($name, $express)) {
504 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
505 } else {
506 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
507 }
508 }
509
510 $d--;
511 my $OR = "\\|\\|";
512 my $AND = "\\&\\&";
513
514 while ($val =~ s/^(.*?)($OR|$AND)//) {
515 my $express = $1;
516 my $op = $2;
517
518 if (process_expression($name, $express)) {
519 if ($op eq "||") {
520 return 1;
521 }
522 } else {
523 if ($op eq "&&") {
524 return 0;
525 }
526 }
527 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400528
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400529 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
530 my $ret = process_compare($1, $2, $3);
531 if ($ret < 0) {
532 die "$name: $.: Unable to process comparison\n";
533 }
534 return $ret;
535 }
536
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400537 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
538 if (defined $1) {
539 return !value_defined($2);
540 } else {
541 return value_defined($2);
542 }
543 }
544
Steven Rostedt45d73a52011-09-30 19:44:53 -0400545 if ($val =~ /^\s*0\s*$/) {
546 return 0;
547 } elsif ($val =~ /^\s*\d+\s*$/) {
548 return 1;
549 }
550
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400551 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400552}
553
554sub process_if {
555 my ($name, $value) = @_;
556
557 # Convert variables and replace undefined ones with 0
558 my $val = process_variables($value, 1);
559 my $ret = process_expression $name, $val;
560
561 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400562}
563
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400564sub __read_config {
565 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400566
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400567 my $in;
568 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400569
Steven Rostedta57419b2010-11-02 15:13:54 -0400570 my $name = $config;
571 $name =~ s,.*/(.*),$1,;
572
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400573 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400574 my $default = 1;
575 my $repeat = 1;
576 my $num_tests_set = 0;
577 my $skip = 0;
578 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400579 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400580 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400581 my $if = 0;
582 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400583 my $override = 0;
584
585 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400586
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400587 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400588
589 # ignore blank lines and comments
590 next if (/^\s*$/ || /\s*\#/);
591
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400592 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400593
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400594 my $type = $1;
595 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400596 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400597
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400598 my $old_test_num;
599 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400600 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400601
602 if ($type eq "TEST_START") {
603
604 if ($num_tests_set) {
605 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
606 }
607
608 $old_test_num = $test_num;
609 $old_repeat = $repeat;
610
611 $test_num += $repeat;
612 $default = 0;
613 $repeat = 1;
614 } else {
615 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400616 }
617
Steven Rostedta9f84422011-10-17 11:06:29 -0400618 # If SKIP is anywhere in the line, the command will be skipped
619 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400620 $skip = 1;
621 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400622 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400623 $skip = 0;
624 }
625
Steven Rostedta9f84422011-10-17 11:06:29 -0400626 if ($rest =~ s/\sELSE\b//) {
627 if (!$if) {
628 die "$name: $.: ELSE found with out matching IF section\n$_";
629 }
630 $if = 0;
631
632 if ($if_set) {
633 $skip = 1;
634 } else {
635 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400636 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400637 }
638
Steven Rostedta9f84422011-10-17 11:06:29 -0400639 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400640 if (process_if($name, $1)) {
641 $if_set = 1;
642 } else {
643 $skip = 1;
644 }
645 $if = 1;
646 } else {
647 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400648 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400649 }
650
Steven Rostedta9f84422011-10-17 11:06:29 -0400651 if (!$skip) {
652 if ($type eq "TEST_START") {
653 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
654 $repeat = $1;
655 $repeat_tests{"$test_num"} = $repeat;
656 }
657 } elsif ($rest =~ s/\sOVERRIDE\b//) {
658 # DEFAULT only
659 $override = 1;
660 # Clear previous overrides
661 %overrides = ();
662 }
663 }
664
665 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400666 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400667 }
668
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400669 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400670 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400671 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400672 }
673
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400674 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400675 if (!$if) {
676 die "$name: $.: ELSE found with out matching IF section\n$_";
677 }
678 $rest = $1;
679 if ($if_set) {
680 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400681 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400682 } else {
683 $skip = 0;
684
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400685 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400686 # May be a ELSE IF section.
687 if (!process_if($name, $1)) {
688 $skip = 1;
689 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400690 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400691 } else {
692 $if = 0;
693 }
694 }
695
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400696 if ($rest !~ /^\s*$/) {
697 die "$name: $.: Gargbage found after DEFAULTS\n$_";
698 }
699
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400700 } elsif (/^\s*INCLUDE\s+(\S+)/) {
701
702 next if ($skip);
703
704 if (!$default) {
705 die "$name: $.: INCLUDE can only be done in default sections\n$_";
706 }
707
708 my $file = process_variables($1);
709
710 if ($file !~ m,^/,) {
711 # check the path of the config file first
712 if ($config =~ m,(.*)/,) {
713 if (-f "$1/$file") {
714 $file = "$1/$file";
715 }
716 }
717 }
718
719 if ( ! -r $file ) {
720 die "$name: $.: Can't read file $file\n$_";
721 }
722
723 if (__read_config($file, \$test_num)) {
724 $test_case = 1;
725 }
726
Steven Rostedta57419b2010-11-02 15:13:54 -0400727 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
728
729 next if ($skip);
730
Steven Rostedt2545eb62010-11-02 15:01:32 -0400731 my $lvalue = $1;
732 my $rvalue = $2;
733
Steven Rostedta57419b2010-11-02 15:13:54 -0400734 if (!$default &&
735 ($lvalue eq "NUM_TESTS" ||
736 $lvalue eq "LOG_FILE" ||
737 $lvalue eq "CLEAR_LOG")) {
738 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400739 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400740
741 if ($lvalue eq "NUM_TESTS") {
742 if ($test_num) {
743 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
744 }
745 if (!$default) {
746 die "$name: $.: NUM_TESTS must be set in default section\n";
747 }
748 $num_tests_set = 1;
749 }
750
751 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400752 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400753 } else {
754 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400755 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400756
757 if ($repeat > 1) {
758 $repeats{$val} = $repeat;
759 }
760 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400761 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
762 next if ($skip);
763
764 my $lvalue = $1;
765 my $rvalue = $2;
766
767 # process config variables.
768 # Config variables are only active while reading the
769 # config and can be defined anywhere. They also ignore
770 # TEST_START and DEFAULTS, but are skipped if they are in
771 # on of these sections that have SKIP defined.
772 # The save variable can be
773 # defined multiple times and the new one simply overrides
774 # the prevous one.
775 set_variable($lvalue, $rvalue);
776
Steven Rostedta57419b2010-11-02 15:13:54 -0400777 } else {
778 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400779 }
780 }
781
Steven Rostedta57419b2010-11-02 15:13:54 -0400782 if ($test_num) {
783 $test_num += $repeat - 1;
784 $opt{"NUM_TESTS"} = $test_num;
785 }
786
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400787 close($in);
788
789 $$current_test_num = $test_num;
790
791 return $test_case;
792}
793
Steven Rostedtc4261d02011-11-23 13:41:18 -0500794sub get_test_case {
795 print "What test case would you like to run?\n";
796 print " (build, install or boot)\n";
797 print " Other tests are available but require editing the config file\n";
798 my $ans = <STDIN>;
799 chomp $ans;
800 $default{"TEST_TYPE"} = $ans;
801}
802
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400803sub read_config {
804 my ($config) = @_;
805
806 my $test_case;
807 my $test_num = 0;
808
809 $test_case = __read_config $config, \$test_num;
810
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500811 # make sure we have all mandatory configs
812 get_ktest_configs;
813
Steven Rostedt0df213c2011-06-14 20:51:37 -0400814 # was a test specified?
815 if (!$test_case) {
816 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500817 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400818 }
819
Steven Rostedta75fece2010-11-02 14:58:27 -0400820 # set any defaults
821
822 foreach my $default (keys %default) {
823 if (!defined($opt{$default})) {
824 $opt{$default} = $default{$default};
825 }
826 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400827}
828
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400829sub __eval_option {
830 my ($option, $i) = @_;
831
832 # Add space to evaluate the character before $
833 $option = " $option";
834 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530835 my $repeated = 0;
836 my $parent = 0;
837
838 foreach my $test (keys %repeat_tests) {
839 if ($i >= $test &&
840 $i < $test + $repeat_tests{$test}) {
841
842 $repeated = 1;
843 $parent = $test;
844 last;
845 }
846 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400847
848 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
849 my $start = $1;
850 my $var = $2;
851 my $end = $3;
852
853 # Append beginning of line
854 $retval = "$retval$start";
855
856 # If the iteration option OPT[$i] exists, then use that.
857 # otherwise see if the default OPT (without [$i]) exists.
858
859 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530860 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400861
862 if (defined($opt{$o})) {
863 $o = $opt{$o};
864 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530865 } elsif ($repeated && defined($opt{$parento})) {
866 $o = $opt{$parento};
867 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400868 } elsif (defined($opt{$var})) {
869 $o = $opt{$var};
870 $retval = "$retval$o";
871 } else {
872 $retval = "$retval\$\{$var\}";
873 }
874
875 $option = $end;
876 }
877
878 $retval = "$retval$option";
879
880 $retval =~ s/^ //;
881
882 return $retval;
883}
884
885sub eval_option {
886 my ($option, $i) = @_;
887
888 my $prev = "";
889
890 # Since an option can evaluate to another option,
891 # keep iterating until we do not evaluate any more
892 # options.
893 my $r = 0;
894 while ($prev ne $option) {
895 # Check for recursive evaluations.
896 # 100 deep should be more than enough.
897 if ($r++ > 100) {
898 die "Over 100 evaluations accurred with $option\n" .
899 "Check for recursive variables\n";
900 }
901 $prev = $option;
902 $option = __eval_option($option, $i);
903 }
904
905 return $option;
906}
907
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500908sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400909 if (defined($opt{"LOG_FILE"})) {
910 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
911 print OUT @_;
912 close(OUT);
913 }
914}
915
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500916sub logit {
917 if (defined($opt{"LOG_FILE"})) {
918 _logit @_;
919 } else {
920 print @_;
921 }
922}
923
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400924sub doprint {
925 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500926 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400927}
928
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400929sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200930sub start_monitor;
931sub end_monitor;
932sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400933
934sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200935 my ($time) = @_;
936
Steven Rostedt2b803362011-09-30 18:00:23 -0400937 if (defined($time)) {
938 start_monitor;
939 # flush out current monitor
940 # May contain the reboot success line
941 wait_for_monitor 1;
942 }
943
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400944 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400945 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400946 if (defined($powercycle_after_reboot)) {
947 sleep $powercycle_after_reboot;
948 run_command "$power_cycle";
949 }
950 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400951 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400952 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400953 }
Andrew Jones2728be42011-08-12 15:32:05 +0200954
955 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400956 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200957 end_monitor;
958 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400959}
960
Steven Rostedt576f6272010-11-02 14:58:38 -0400961sub do_not_reboot {
962 my $i = $iteration;
963
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400964 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400965 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
966 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
967}
968
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400969sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400970 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400971
Steven Rostedt576f6272010-11-02 14:58:38 -0400972 my $i = $iteration;
973
974 if ($reboot_on_error && !do_not_reboot) {
975
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400976 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400977 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400978
Steven Rostedta75fece2010-11-02 14:58:27 -0400979 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400980 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400981 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400982 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400983
Steven Rostedtf80802c2011-03-07 13:18:47 -0500984 if (defined($opt{"LOG_FILE"})) {
985 print " See $opt{LOG_FILE} for more info.\n";
986 }
987
Steven Rostedt576f6272010-11-02 14:58:38 -0400988 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400989}
990
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400991sub open_console {
992 my ($fp) = @_;
993
994 my $flags;
995
Steven Rostedta75fece2010-11-02 14:58:27 -0400996 my $pid = open($fp, "$console|") or
997 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400998
999 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001000 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001001 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001002 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001003
1004 return $pid;
1005}
1006
1007sub close_console {
1008 my ($fp, $pid) = @_;
1009
1010 doprint "kill child process $pid\n";
1011 kill 2, $pid;
1012
1013 print "closing!\n";
1014 close($fp);
1015}
1016
1017sub start_monitor {
1018 if ($monitor_cnt++) {
1019 return;
1020 }
1021 $monitor_fp = \*MONFD;
1022 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001023
1024 return;
1025
1026 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001027}
1028
1029sub end_monitor {
1030 if (--$monitor_cnt) {
1031 return;
1032 }
1033 close_console($monitor_fp, $monitor_pid);
1034}
1035
1036sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001037 my ($time, $stop) = @_;
1038 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001039 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001040 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001041
Steven Rostedta75fece2010-11-02 14:58:27 -04001042 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001043
1044 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001045 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001046 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001047 last if (!defined($line));
1048 print "$line";
1049 $full_line .= $line;
1050
1051 if (defined($stop) && $full_line =~ /$stop/) {
1052 doprint "wait for monitor detected $stop\n";
1053 $booted = 1;
1054 }
1055
1056 if ($line =~ /\n/) {
1057 $full_line = "";
1058 }
1059 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001060 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001061}
1062
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301063sub save_logs {
1064 my ($result, $basedir) = @_;
1065 my @t = localtime;
1066 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1067 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1068
1069 my $type = $build_type;
1070 if ($type =~ /useconfig/) {
1071 $type = "useconfig";
1072 }
1073
1074 my $dir = "$machine-$test_type-$type-$result-$date";
1075
1076 $dir = "$basedir/$dir";
1077
1078 if (!-d $dir) {
1079 mkpath($dir) or
1080 die "can't create $dir";
1081 }
1082
1083 my %files = (
1084 "config" => $output_config,
1085 "buildlog" => $buildlog,
1086 "dmesg" => $dmesg,
1087 "testlog" => $testlog,
1088 );
1089
1090 while (my ($name, $source) = each(%files)) {
1091 if (-f "$source") {
1092 cp "$source", "$dir/$name" or
1093 die "failed to copy $source";
1094 }
1095 }
1096
1097 doprint "*** Saved info to $dir ***\n";
1098}
1099
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001100sub fail {
1101
Steven Rostedta75fece2010-11-02 14:58:27 -04001102 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001103 dodie @_;
1104 }
1105
Steven Rostedta75fece2010-11-02 14:58:27 -04001106 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001107
Steven Rostedt576f6272010-11-02 14:58:38 -04001108 my $i = $iteration;
1109
Steven Rostedta75fece2010-11-02 14:58:27 -04001110 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001111 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001112 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001113 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001114 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001115
Steven Rostedt9064af52011-06-13 10:38:48 -04001116 my $name = "";
1117
1118 if (defined($test_name)) {
1119 $name = " ($test_name)";
1120 }
1121
Steven Rostedt576f6272010-11-02 14:58:38 -04001122 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1123 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001124 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001125 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1126 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001127
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301128 if (defined($store_failures)) {
1129 save_logs "fail", $store_failures;
1130 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001131
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001132 return 1;
1133}
1134
Steven Rostedt2545eb62010-11-02 15:01:32 -04001135sub run_command {
1136 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001137 my $dolog = 0;
1138 my $dord = 0;
1139 my $pid;
1140
Steven Rostedte48c5292010-11-02 14:35:37 -04001141 $command =~ s/\$SSH_USER/$ssh_user/g;
1142 $command =~ s/\$MACHINE/$machine/g;
1143
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001144 doprint("$command ... ");
1145
1146 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001147 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001148
1149 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001150 open(LOG, ">>$opt{LOG_FILE}") or
1151 dodie "failed to write to log";
1152 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001153 }
1154
1155 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001156 open (RD, ">$redirect") or
1157 dodie "failed to write to redirect $redirect";
1158 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001159 }
1160
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001161 while (<CMD>) {
1162 print LOG if ($dolog);
1163 print RD if ($dord);
1164 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001165
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001166 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001167 my $failed = $?;
1168
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001169 close(CMD);
1170 close(LOG) if ($dolog);
1171 close(RD) if ($dord);
1172
Steven Rostedt2545eb62010-11-02 15:01:32 -04001173 if ($failed) {
1174 doprint "FAILED!\n";
1175 } else {
1176 doprint "SUCCESS\n";
1177 }
1178
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001179 return !$failed;
1180}
1181
Steven Rostedte48c5292010-11-02 14:35:37 -04001182sub run_ssh {
1183 my ($cmd) = @_;
1184 my $cp_exec = $ssh_exec;
1185
1186 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1187 return run_command "$cp_exec";
1188}
1189
1190sub run_scp {
1191 my ($src, $dst) = @_;
1192 my $cp_scp = $scp_to_target;
1193
1194 $cp_scp =~ s/\$SRC_FILE/$src/g;
1195 $cp_scp =~ s/\$DST_FILE/$dst/g;
1196
1197 return run_command "$cp_scp";
1198}
1199
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001200sub get_grub_index {
1201
Steven Rostedta75fece2010-11-02 14:58:27 -04001202 if ($reboot_type ne "grub") {
1203 return;
1204 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001205 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001206
1207 doprint "Find grub menu ... ";
1208 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001209
1210 my $ssh_grub = $ssh_exec;
1211 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1212
1213 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001214 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001215
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001216 my $found = 0;
1217
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001218 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001219 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001220 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001221 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001222 last;
1223 } elsif (/^\s*title\s/) {
1224 $grub_number++;
1225 }
1226 }
1227 close(IN);
1228
Steven Rostedta75fece2010-11-02 14:58:27 -04001229 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001230 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001231 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001232}
1233
Steven Rostedt2545eb62010-11-02 15:01:32 -04001234sub wait_for_input
1235{
1236 my ($fp, $time) = @_;
1237 my $rin;
1238 my $ready;
1239 my $line;
1240 my $ch;
1241
1242 if (!defined($time)) {
1243 $time = $timeout;
1244 }
1245
1246 $rin = '';
1247 vec($rin, fileno($fp), 1) = 1;
1248 $ready = select($rin, undef, undef, $time);
1249
1250 $line = "";
1251
1252 # try to read one char at a time
1253 while (sysread $fp, $ch, 1) {
1254 $line .= $ch;
1255 last if ($ch eq "\n");
1256 }
1257
1258 if (!length($line)) {
1259 return undef;
1260 }
1261
1262 return $line;
1263}
1264
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001265sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001266 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001267 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1268 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001269 return;
1270 }
1271
1272 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001273}
1274
Steven Rostedta57419b2010-11-02 15:13:54 -04001275sub get_sha1 {
1276 my ($commit) = @_;
1277
1278 doprint "git rev-list --max-count=1 $commit ... ";
1279 my $sha1 = `git rev-list --max-count=1 $commit`;
1280 my $ret = $?;
1281
1282 logit $sha1;
1283
1284 if ($ret) {
1285 doprint "FAILED\n";
1286 dodie "Failed to get git $commit";
1287 }
1288
1289 print "SUCCESS\n";
1290
1291 chomp $sha1;
1292
1293 return $sha1;
1294}
1295
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001296sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001297 my $booted = 0;
1298 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001299 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001300 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001301
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001302 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001303
1304 my $line;
1305 my $full_line = "";
1306
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001307 open(DMESG, "> $dmesg") or
1308 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001309
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001310 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001311
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001312 my $success_start;
1313 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001314 my $monitor_start = time;
1315 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001316 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001317
Steven Rostedt2d01b262011-03-08 09:47:54 -05001318 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001319
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001320 if ($bug && defined($stop_after_failure) &&
1321 $stop_after_failure >= 0) {
1322 my $time = $stop_after_failure - (time - $failure_start);
1323 $line = wait_for_input($monitor_fp, $time);
1324 if (!defined($line)) {
1325 doprint "bug timed out after $booted_timeout seconds\n";
1326 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1327 last;
1328 }
1329 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001330 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001331 if (!defined($line)) {
1332 my $s = $booted_timeout == 1 ? "" : "s";
1333 doprint "Successful boot found: break after $booted_timeout second$s\n";
1334 last;
1335 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001336 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001337 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001338 if (!defined($line)) {
1339 my $s = $timeout == 1 ? "" : "s";
1340 doprint "Timed out after $timeout second$s\n";
1341 last;
1342 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001343 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001344
Steven Rostedt2545eb62010-11-02 15:01:32 -04001345 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001346 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001347
1348 # we are not guaranteed to get a full line
1349 $full_line .= $line;
1350
Steven Rostedta75fece2010-11-02 14:58:27 -04001351 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001352 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001353 $success_start = time;
1354 }
1355
1356 if ($booted && defined($stop_after_success) &&
1357 $stop_after_success >= 0) {
1358 my $now = time;
1359 if ($now - $success_start >= $stop_after_success) {
1360 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1361 last;
1362 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001363 }
1364
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001365 if ($full_line =~ /\[ backtrace testing \]/) {
1366 $skip_call_trace = 1;
1367 }
1368
Steven Rostedt2545eb62010-11-02 15:01:32 -04001369 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001370 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001371 $bug = 1;
1372 $failure_start = time;
1373 }
1374 }
1375
1376 if ($bug && defined($stop_after_failure) &&
1377 $stop_after_failure >= 0) {
1378 my $now = time;
1379 if ($now - $failure_start >= $stop_after_failure) {
1380 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1381 last;
1382 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001383 }
1384
1385 if ($full_line =~ /\[ end of backtrace testing \]/) {
1386 $skip_call_trace = 0;
1387 }
1388
1389 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001390 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001391 $bug = 1;
1392 }
1393
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001394 # Detect triple faults by testing the banner
1395 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1396 if ($1 eq $version) {
1397 $version_found = 1;
1398 } elsif ($version_found && $detect_triplefault) {
1399 # We already booted into the kernel we are testing,
1400 # but now we booted into another kernel?
1401 # Consider this a triple fault.
1402 doprint "Aleady booted in Linux kernel $version, but now\n";
1403 doprint "we booted into Linux kernel $1.\n";
1404 doprint "Assuming that this is a triple fault.\n";
1405 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1406 last;
1407 }
1408 }
1409
Steven Rostedt2545eb62010-11-02 15:01:32 -04001410 if ($line =~ /\n/) {
1411 $full_line = "";
1412 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001413
1414 if ($stop_test_after > 0 && !$booted && !$bug) {
1415 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001416 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001417 $done = 1;
1418 }
1419 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001420 }
1421
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001422 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001423
Steven Rostedt2545eb62010-11-02 15:01:32 -04001424 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001425 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001426 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001427 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001428
Steven Rostedta75fece2010-11-02 14:58:27 -04001429 if (!$booted) {
1430 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001431 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001432 }
1433
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001434 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001435}
1436
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001437sub eval_kernel_version {
1438 my ($option) = @_;
1439
1440 $option =~ s/\$KERNEL_VERSION/$version/g;
1441
1442 return $option;
1443}
1444
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001445sub do_post_install {
1446
1447 return if (!defined($post_install));
1448
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001449 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001450 run_command "$cp_post_install" or
1451 dodie "Failed to run post install";
1452}
1453
Steven Rostedt2545eb62010-11-02 15:01:32 -04001454sub install {
1455
Steven Rostedte0a87422011-09-30 17:50:48 -04001456 return if ($no_install);
1457
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001458 my $cp_target = eval_kernel_version $target_image;
1459
1460 run_scp "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001461 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001462
1463 my $install_mods = 0;
1464
1465 # should we process modules?
1466 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001467 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001468 while (<IN>) {
1469 if (/CONFIG_MODULES(=y)?/) {
1470 $install_mods = 1 if (defined($1));
1471 last;
1472 }
1473 }
1474 close(IN);
1475
1476 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001477 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001478 doprint "No modules needed\n";
1479 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001480 }
1481
Steven Rostedta75fece2010-11-02 14:58:27 -04001482 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001483 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001484
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001485 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001486 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001487
Steven Rostedte48c5292010-11-02 14:35:37 -04001488 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001489 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001490
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001491 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001492 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001493 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001494
Steven Rostedte48c5292010-11-02 14:35:37 -04001495 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001496 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001497
Steven Rostedta75fece2010-11-02 14:58:27 -04001498 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001499
Steven Rostedte7b13442011-06-14 20:44:36 -04001500 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001501 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001502
Steven Rostedte48c5292010-11-02 14:35:37 -04001503 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001504
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001505 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001506}
1507
Steven Rostedtddf607e2011-06-14 20:49:13 -04001508sub get_version {
1509 # get the release name
1510 doprint "$make kernelrelease ... ";
1511 $version = `$make kernelrelease | tail -1`;
1512 chomp($version);
1513 doprint "$version\n";
1514}
1515
1516sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001517 # Make sure the stable kernel has finished booting
1518 start_monitor;
1519 wait_for_monitor 5;
1520 end_monitor;
1521
Steven Rostedtddf607e2011-06-14 20:49:13 -04001522 get_grub_index;
1523 get_version;
1524 install;
1525
1526 start_monitor;
1527 return monitor;
1528}
1529
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001530sub check_buildlog {
1531 my ($patch) = @_;
1532
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001533 my @files = `git show $patch | diffstat -l`;
1534
1535 open(IN, "git show $patch |") or
1536 dodie "failed to show $patch";
1537 while (<IN>) {
1538 if (m,^--- a/(.*),) {
1539 chomp $1;
1540 $files[$#files] = $1;
1541 }
1542 }
1543 close(IN);
1544
1545 open(IN, $buildlog) or dodie "Can't open $buildlog";
1546 while (<IN>) {
1547 if (/^\s*(.*?):.*(warning|error)/) {
1548 my $err = $1;
1549 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001550 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001551 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001552 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001553 }
1554 }
1555 }
1556 }
1557 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001558
1559 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001560}
1561
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001562sub apply_min_config {
1563 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001564
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001565 # Read the config file and remove anything that
1566 # is in the force_config hash (from minconfig and others)
1567 # then add the force config back.
1568
1569 doprint "Applying minimum configurations into $output_config.new\n";
1570
1571 open (OUT, ">$outconfig") or
1572 dodie "Can't create $outconfig";
1573
1574 if (-f $output_config) {
1575 open (IN, $output_config) or
1576 dodie "Failed to open $output_config";
1577 while (<IN>) {
1578 if (/^(# )?(CONFIG_[^\s=]*)/) {
1579 next if (defined($force_config{$2}));
1580 }
1581 print OUT;
1582 }
1583 close IN;
1584 }
1585 foreach my $config (keys %force_config) {
1586 print OUT "$force_config{$config}\n";
1587 }
1588 close OUT;
1589
1590 run_command "mv $outconfig $output_config";
1591}
1592
1593sub make_oldconfig {
1594
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001595 my @force_list = keys %force_config;
1596
1597 if ($#force_list >= 0) {
1598 apply_min_config;
1599 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001600
1601 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001602 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1603 # try a yes '' | oldconfig
1604 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001605 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001606 dodie "failed make config oldconfig";
1607 }
1608}
1609
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001610# read a config file and use this to force new configs.
1611sub load_force_config {
1612 my ($config) = @_;
1613
1614 open(IN, $config) or
1615 dodie "failed to read $config";
1616 while (<IN>) {
1617 chomp;
1618 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1619 $force_config{$1} = $_;
1620 } elsif (/^# (CONFIG_\S*) is not set/) {
1621 $force_config{$1} = $_;
1622 }
1623 }
1624 close IN;
1625}
1626
Steven Rostedt2545eb62010-11-02 15:01:32 -04001627sub build {
1628 my ($type) = @_;
1629
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001630 unlink $buildlog;
1631
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001632 # Failed builds should not reboot the target
1633 my $save_no_reboot = $no_reboot;
1634 $no_reboot = 1;
1635
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001636 if (defined($pre_build)) {
1637 my $ret = run_command $pre_build;
1638 if (!$ret && defined($pre_build_die) &&
1639 $pre_build_die) {
1640 dodie "failed to pre_build\n";
1641 }
1642 }
1643
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001644 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001645 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001646 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001647
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001648 $type = "oldconfig";
1649 }
1650
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001651 # old config can ask questions
1652 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001653 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001654
1655 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001656 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001657
Andrew Jones13488232011-08-12 15:32:04 +02001658 if (!$noclean) {
1659 run_command "mv $output_config $outputdir/config_temp" or
1660 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001661
Andrew Jones13488232011-08-12 15:32:04 +02001662 run_command "$make mrproper" or dodie "make mrproper";
1663
1664 run_command "mv $outputdir/config_temp $output_config" or
1665 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001666 }
1667
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001668 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001669 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001670 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001671 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001672 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001673
1674 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001675 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1676 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001677 close(OUT);
1678
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001679 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001680 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001681 }
1682
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001683 if ($type ne "oldnoconfig") {
1684 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001685 dodie "failed make config";
1686 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001687 # Run old config regardless, to enforce min configurations
1688 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001689
Steven Rostedta75fece2010-11-02 14:58:27 -04001690 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001691 my $build_ret = run_command "$make $build_options";
1692 undef $redirect;
1693
1694 if (defined($post_build)) {
1695 my $ret = run_command $post_build;
1696 if (!$ret && defined($post_build_die) &&
1697 $post_build_die) {
1698 dodie "failed to post_build\n";
1699 }
1700 }
1701
1702 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001703 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001704 if ($in_bisect) {
1705 $no_reboot = $save_no_reboot;
1706 return 0;
1707 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001708 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001709 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001710
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001711 $no_reboot = $save_no_reboot;
1712
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001713 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001714}
1715
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001716sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001717 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001718 if (defined($poweroff_after_halt)) {
1719 sleep $poweroff_after_halt;
1720 run_command "$power_off";
1721 }
1722 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001723 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001724 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001725 }
1726}
1727
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001728sub success {
1729 my ($i) = @_;
1730
Steven Rostedte48c5292010-11-02 14:35:37 -04001731 $successes++;
1732
Steven Rostedt9064af52011-06-13 10:38:48 -04001733 my $name = "";
1734
1735 if (defined($test_name)) {
1736 $name = " ($test_name)";
1737 }
1738
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001739 doprint "\n\n*******************************************\n";
1740 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001741 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001742 doprint "*******************************************\n";
1743 doprint "*******************************************\n";
1744
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301745 if (defined($store_successes)) {
1746 save_logs "success", $store_successes;
1747 }
1748
Steven Rostedt576f6272010-11-02 14:58:38 -04001749 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001750 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001751 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001752 }
1753}
1754
Steven Rostedtc960bb92011-03-08 09:22:39 -05001755sub answer_bisect {
1756 for (;;) {
1757 doprint "Pass or fail? [p/f]";
1758 my $ans = <STDIN>;
1759 chomp $ans;
1760 if ($ans eq "p" || $ans eq "P") {
1761 return 1;
1762 } elsif ($ans eq "f" || $ans eq "F") {
1763 return 0;
1764 } else {
1765 print "Please answer 'P' or 'F'\n";
1766 }
1767 }
1768}
1769
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001770sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001771 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001772
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001773 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001774 $reboot_on_error = 0;
1775 $poweroff_on_error = 0;
1776 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001777
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301778 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001779 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301780 undef $redirect;
1781
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001782 exit $failed;
1783}
1784
1785my $child_done;
1786
1787sub child_finished {
1788 $child_done = 1;
1789}
1790
1791sub do_run_test {
1792 my $child_pid;
1793 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001794 my $line;
1795 my $full_line;
1796 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001797
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001798 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001799
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001800 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001801
1802 $child_done = 0;
1803
1804 $SIG{CHLD} = qw(child_finished);
1805
1806 $child_pid = fork;
1807
1808 child_run_test if (!$child_pid);
1809
1810 $full_line = "";
1811
1812 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001813 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001814 if (defined($line)) {
1815
1816 # we are not guaranteed to get a full line
1817 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001818 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001819
1820 if ($full_line =~ /call trace:/i) {
1821 $bug = 1;
1822 }
1823
1824 if ($full_line =~ /Kernel panic -/) {
1825 $bug = 1;
1826 }
1827
1828 if ($line =~ /\n/) {
1829 $full_line = "";
1830 }
1831 }
1832 } while (!$child_done && !$bug);
1833
1834 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001835 my $failure_start = time;
1836 my $now;
1837 do {
1838 $line = wait_for_input($monitor_fp, 1);
1839 if (defined($line)) {
1840 doprint $line;
1841 }
1842 $now = time;
1843 if ($now - $failure_start >= $stop_after_failure) {
1844 last;
1845 }
1846 } while (defined($line));
1847
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001848 doprint "Detected kernel crash!\n";
1849 # kill the child with extreme prejudice
1850 kill 9, $child_pid;
1851 }
1852
1853 waitpid $child_pid, 0;
1854 $child_exit = $?;
1855
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001856 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001857 return 0 if $in_bisect;
1858 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001859 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001860 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001861}
1862
Steven Rostedta75fece2010-11-02 14:58:27 -04001863sub run_git_bisect {
1864 my ($command) = @_;
1865
1866 doprint "$command ... ";
1867
1868 my $output = `$command 2>&1`;
1869 my $ret = $?;
1870
1871 logit $output;
1872
1873 if ($ret) {
1874 doprint "FAILED\n";
1875 dodie "Failed to git bisect";
1876 }
1877
1878 doprint "SUCCESS\n";
1879 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1880 doprint "$1 [$2]\n";
1881 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1882 $bisect_bad = $1;
1883 doprint "Found bad commit... $1\n";
1884 return 0;
1885 } else {
1886 # we already logged it, just print it now.
1887 print $output;
1888 }
1889
1890 return 1;
1891}
1892
Steven Rostedtc23dca72011-03-08 09:26:31 -05001893sub bisect_reboot {
1894 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001895 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001896}
1897
1898# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001899sub run_bisect_test {
1900 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001901
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001902 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001903 my $result;
1904 my $output;
1905 my $ret;
1906
Steven Rostedt0a05c762010-11-08 11:14:10 -05001907 $in_bisect = 1;
1908
1909 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001910
1911 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001912 if ($failed && $bisect_skip) {
1913 $in_bisect = 0;
1914 return -1;
1915 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001916 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001917
1918 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001919 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001920
1921 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001922 if ($failed && $bisect_skip) {
1923 end_monitor;
1924 bisect_reboot;
1925 $in_bisect = 0;
1926 return -1;
1927 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001928 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001929
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001930 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001931 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001932 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001933 }
1934
1935 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001936 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001937 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001938 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001939 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001940
1941 # reboot the box to a kernel we can ssh to
1942 if ($type ne "build") {
1943 bisect_reboot;
1944 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001945 $in_bisect = 0;
1946
1947 return $result;
1948}
1949
1950sub run_bisect {
1951 my ($type) = @_;
1952 my $buildtype = "oldconfig";
1953
1954 # We should have a minconfig to use?
1955 if (defined($minconfig)) {
1956 $buildtype = "useconfig:$minconfig";
1957 }
1958
1959 my $ret = run_bisect_test $type, $buildtype;
1960
Steven Rostedtc960bb92011-03-08 09:22:39 -05001961 if ($bisect_manual) {
1962 $ret = answer_bisect;
1963 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001964
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001965 # Are we looking for where it worked, not failed?
1966 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001967 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001968 }
1969
Steven Rostedtc23dca72011-03-08 09:26:31 -05001970 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001971 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001972 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001973 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001974 } elsif ($bisect_skip) {
1975 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1976 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001977 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001978}
1979
Steven Rostedtdad98752011-11-22 20:48:57 -05001980sub update_bisect_replay {
1981 my $tmp_log = "$tmpdir/ktest_bisect_log";
1982 run_command "git bisect log > $tmp_log" or
1983 die "can't create bisect log";
1984 return $tmp_log;
1985}
1986
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001987sub bisect {
1988 my ($i) = @_;
1989
1990 my $result;
1991
1992 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1993 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1994 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1995
1996 my $good = $opt{"BISECT_GOOD[$i]"};
1997 my $bad = $opt{"BISECT_BAD[$i]"};
1998 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001999 my $start = $opt{"BISECT_START[$i]"};
2000 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002001 my $start_files = $opt{"BISECT_FILES[$i]"};
2002
2003 if (defined($start_files)) {
2004 $start_files = " -- " . $start_files;
2005 } else {
2006 $start_files = "";
2007 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002008
Steven Rostedta57419b2010-11-02 15:13:54 -04002009 # convert to true sha1's
2010 $good = get_sha1($good);
2011 $bad = get_sha1($bad);
2012
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002013 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
2014 $opt{"BISECT_REVERSE[$i]"} == 1) {
2015 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2016 $reverse_bisect = 1;
2017 } else {
2018 $reverse_bisect = 0;
2019 }
2020
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002021 # Can't have a test without having a test to run
2022 if ($type eq "test" && !defined($run_test)) {
2023 $type = "boot";
2024 }
2025
Steven Rostedtdad98752011-11-22 20:48:57 -05002026 # Check if a bisect was running
2027 my $bisect_start_file = "$builddir/.git/BISECT_START";
2028
Steven Rostedta75fece2010-11-02 14:58:27 -04002029 my $check = $opt{"BISECT_CHECK[$i]"};
Steven Rostedtdad98752011-11-22 20:48:57 -05002030 my $do_check = defined($check) && $check ne "0";
2031
2032 if ( -f $bisect_start_file ) {
2033 print "Bisect in progress found\n";
2034 if ($do_check) {
2035 print " If you say yes, then no checks of good or bad will be done\n";
2036 }
2037 if (defined($replay)) {
2038 print "** BISECT_REPLAY is defined in config file **";
2039 print " Ignore config option and perform new git bisect log?\n";
2040 if (read_ync " (yes, no, or cancel) ") {
2041 $replay = update_bisect_replay;
2042 $do_check = 0;
2043 }
2044 } elsif (read_yn "read git log and continue?") {
2045 $replay = update_bisect_replay;
2046 $do_check = 0;
2047 }
2048 }
2049
2050 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002051
2052 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002053 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002054
2055 if ($check ne "good") {
2056 doprint "TESTING BISECT BAD [$bad]\n";
2057 run_command "git checkout $bad" or
2058 die "Failed to checkout $bad";
2059
2060 $result = run_bisect $type;
2061
2062 if ($result ne "bad") {
2063 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2064 }
2065 }
2066
2067 if ($check ne "bad") {
2068 doprint "TESTING BISECT GOOD [$good]\n";
2069 run_command "git checkout $good" or
2070 die "Failed to checkout $good";
2071
2072 $result = run_bisect $type;
2073
2074 if ($result ne "good") {
2075 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2076 }
2077 }
2078
2079 # checkout where we started
2080 run_command "git checkout $head" or
2081 die "Failed to checkout $head";
2082 }
2083
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002084 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002085 dodie "could not start bisect";
2086
2087 run_command "git bisect good $good" or
2088 dodie "could not set bisect good to $good";
2089
2090 run_git_bisect "git bisect bad $bad" or
2091 dodie "could not set bisect bad to $bad";
2092
2093 if (defined($replay)) {
2094 run_command "git bisect replay $replay" or
2095 dodie "failed to run replay";
2096 }
2097
2098 if (defined($start)) {
2099 run_command "git checkout $start" or
2100 dodie "failed to checkout $start";
2101 }
2102
2103 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002104 do {
2105 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002106 $test = run_git_bisect "git bisect $result";
2107 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002108
2109 run_command "git bisect log" or
2110 dodie "could not capture git bisect log";
2111
2112 run_command "git bisect reset" or
2113 dodie "could not reset git bisect";
2114
2115 doprint "Bad commit was [$bisect_bad]\n";
2116
Steven Rostedt0a05c762010-11-08 11:14:10 -05002117 success $i;
2118}
2119
2120my %config_ignore;
2121my %config_set;
2122
2123my %config_list;
2124my %null_config;
2125
2126my %dependency;
2127
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002128sub assign_configs {
2129 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002130
2131 open (IN, $config)
2132 or dodie "Failed to read $config";
2133
2134 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002135 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002136 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002137 }
2138 }
2139
2140 close(IN);
2141}
2142
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002143sub process_config_ignore {
2144 my ($config) = @_;
2145
2146 assign_configs \%config_ignore, $config;
2147}
2148
Steven Rostedt0a05c762010-11-08 11:14:10 -05002149sub read_current_config {
2150 my ($config_ref) = @_;
2151
2152 %{$config_ref} = ();
2153 undef %{$config_ref};
2154
2155 my @key = keys %{$config_ref};
2156 if ($#key >= 0) {
2157 print "did not delete!\n";
2158 exit;
2159 }
2160 open (IN, "$output_config");
2161
2162 while (<IN>) {
2163 if (/^(CONFIG\S+)=(.*)/) {
2164 ${$config_ref}{$1} = $2;
2165 }
2166 }
2167 close(IN);
2168}
2169
2170sub get_dependencies {
2171 my ($config) = @_;
2172
2173 my $arr = $dependency{$config};
2174 if (!defined($arr)) {
2175 return ();
2176 }
2177
2178 my @deps = @{$arr};
2179
2180 foreach my $dep (@{$arr}) {
2181 print "ADD DEP $dep\n";
2182 @deps = (@deps, get_dependencies $dep);
2183 }
2184
2185 return @deps;
2186}
2187
2188sub create_config {
2189 my @configs = @_;
2190
2191 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2192
2193 foreach my $config (@configs) {
2194 print OUT "$config_set{$config}\n";
2195 my @deps = get_dependencies $config;
2196 foreach my $dep (@deps) {
2197 print OUT "$config_set{$dep}\n";
2198 }
2199 }
2200
2201 foreach my $config (keys %config_ignore) {
2202 print OUT "$config_ignore{$config}\n";
2203 }
2204 close(OUT);
2205
2206# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002207 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002208}
2209
2210sub compare_configs {
2211 my (%a, %b) = @_;
2212
2213 foreach my $item (keys %a) {
2214 if (!defined($b{$item})) {
2215 print "diff $item\n";
2216 return 1;
2217 }
2218 delete $b{$item};
2219 }
2220
2221 my @keys = keys %b;
2222 if ($#keys) {
2223 print "diff2 $keys[0]\n";
2224 }
2225 return -1 if ($#keys >= 0);
2226
2227 return 0;
2228}
2229
2230sub run_config_bisect_test {
2231 my ($type) = @_;
2232
2233 return run_bisect_test $type, "oldconfig";
2234}
2235
2236sub process_passed {
2237 my (%configs) = @_;
2238
2239 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2240 # Passed! All these configs are part of a good compile.
2241 # Add them to the min options.
2242 foreach my $config (keys %configs) {
2243 if (defined($config_list{$config})) {
2244 doprint " removing $config\n";
2245 $config_ignore{$config} = $config_list{$config};
2246 delete $config_list{$config};
2247 }
2248 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002249 doprint "config copied to $outputdir/config_good\n";
2250 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002251}
2252
2253sub process_failed {
2254 my ($config) = @_;
2255
2256 doprint "\n\n***************************************\n";
2257 doprint "Found bad config: $config\n";
2258 doprint "***************************************\n\n";
2259}
2260
2261sub run_config_bisect {
2262
2263 my @start_list = keys %config_list;
2264
2265 if ($#start_list < 0) {
2266 doprint "No more configs to test!!!\n";
2267 return -1;
2268 }
2269
2270 doprint "***** RUN TEST ***\n";
2271 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2272 my $ret;
2273 my %current_config;
2274
2275 my $count = $#start_list + 1;
2276 doprint " $count configs to test\n";
2277
2278 my $half = int($#start_list / 2);
2279
2280 do {
2281 my @tophalf = @start_list[0 .. $half];
2282
2283 create_config @tophalf;
2284 read_current_config \%current_config;
2285
2286 $count = $#tophalf + 1;
2287 doprint "Testing $count configs\n";
2288 my $found = 0;
2289 # make sure we test something
2290 foreach my $config (@tophalf) {
2291 if (defined($current_config{$config})) {
2292 logit " $config\n";
2293 $found = 1;
2294 }
2295 }
2296 if (!$found) {
2297 # try the other half
2298 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002299 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002300 create_config @tophalf;
2301 read_current_config \%current_config;
2302 foreach my $config (@tophalf) {
2303 if (defined($current_config{$config})) {
2304 logit " $config\n";
2305 $found = 1;
2306 }
2307 }
2308 if (!$found) {
2309 doprint "Failed: Can't make new config with current configs\n";
2310 foreach my $config (@start_list) {
2311 doprint " CONFIG: $config\n";
2312 }
2313 return -1;
2314 }
2315 $count = $#tophalf + 1;
2316 doprint "Testing $count configs\n";
2317 }
2318
2319 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002320 if ($bisect_manual) {
2321 $ret = answer_bisect;
2322 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002323 if ($ret) {
2324 process_passed %current_config;
2325 return 0;
2326 }
2327
2328 doprint "This config had a failure.\n";
2329 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002330 doprint "config copied to $outputdir/config_bad\n";
2331 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002332
2333 # A config exists in this group that was bad.
2334 foreach my $config (keys %config_list) {
2335 if (!defined($current_config{$config})) {
2336 doprint " removing $config\n";
2337 delete $config_list{$config};
2338 }
2339 }
2340
2341 @start_list = @tophalf;
2342
2343 if ($#start_list == 0) {
2344 process_failed $start_list[0];
2345 return 1;
2346 }
2347
2348 # remove half the configs we are looking at and see if
2349 # they are good.
2350 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002351 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002352
Steven Rostedtc960bb92011-03-08 09:22:39 -05002353 # we found a single config, try it again unless we are running manually
2354
2355 if ($bisect_manual) {
2356 process_failed $start_list[0];
2357 return 1;
2358 }
2359
Steven Rostedt0a05c762010-11-08 11:14:10 -05002360 my @tophalf = @start_list[0 .. 0];
2361
2362 $ret = run_config_bisect_test $type;
2363 if ($ret) {
2364 process_passed %current_config;
2365 return 0;
2366 }
2367
2368 process_failed $start_list[0];
2369 return 1;
2370}
2371
2372sub config_bisect {
2373 my ($i) = @_;
2374
2375 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2376
2377 my $tmpconfig = "$tmpdir/use_config";
2378
Steven Rostedt30f75da2011-06-13 10:35:35 -04002379 if (defined($config_bisect_good)) {
2380 process_config_ignore $config_bisect_good;
2381 }
2382
Steven Rostedt0a05c762010-11-08 11:14:10 -05002383 # Make the file with the bad config and the min config
2384 if (defined($minconfig)) {
2385 # read the min config for things to ignore
2386 run_command "cp $minconfig $tmpconfig" or
2387 dodie "failed to copy $minconfig to $tmpconfig";
2388 } else {
2389 unlink $tmpconfig;
2390 }
2391
Steven Rostedt0a05c762010-11-08 11:14:10 -05002392 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002393 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002394 process_config_ignore $tmpconfig;
2395 }
2396
2397 # now process the start config
2398 run_command "cp $start_config $output_config" or
2399 dodie "failed to copy $start_config to $output_config";
2400
2401 # read directly what we want to check
2402 my %config_check;
2403 open (IN, $output_config)
2404 or dodie "faied to open $output_config";
2405
2406 while (<IN>) {
2407 if (/^((CONFIG\S*)=.*)/) {
2408 $config_check{$2} = $1;
2409 }
2410 }
2411 close(IN);
2412
Steven Rostedt250bae82011-07-15 22:05:59 -04002413 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002414 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002415
2416 # check to see what we lost (or gained)
2417 open (IN, $output_config)
2418 or dodie "Failed to read $start_config";
2419
2420 my %removed_configs;
2421 my %added_configs;
2422
2423 while (<IN>) {
2424 if (/^((CONFIG\S*)=.*)/) {
2425 # save off all options
2426 $config_set{$2} = $1;
2427 if (defined($config_check{$2})) {
2428 if (defined($config_ignore{$2})) {
2429 $removed_configs{$2} = $1;
2430 } else {
2431 $config_list{$2} = $1;
2432 }
2433 } elsif (!defined($config_ignore{$2})) {
2434 $added_configs{$2} = $1;
2435 $config_list{$2} = $1;
2436 }
2437 }
2438 }
2439 close(IN);
2440
2441 my @confs = keys %removed_configs;
2442 if ($#confs >= 0) {
2443 doprint "Configs overridden by default configs and removed from check:\n";
2444 foreach my $config (@confs) {
2445 doprint " $config\n";
2446 }
2447 }
2448 @confs = keys %added_configs;
2449 if ($#confs >= 0) {
2450 doprint "Configs appearing in make oldconfig and added:\n";
2451 foreach my $config (@confs) {
2452 doprint " $config\n";
2453 }
2454 }
2455
2456 my %config_test;
2457 my $once = 0;
2458
2459 # Sometimes kconfig does weird things. We must make sure
2460 # that the config we autocreate has everything we need
2461 # to test, otherwise we may miss testing configs, or
2462 # may not be able to create a new config.
2463 # Here we create a config with everything set.
2464 create_config (keys %config_list);
2465 read_current_config \%config_test;
2466 foreach my $config (keys %config_list) {
2467 if (!defined($config_test{$config})) {
2468 if (!$once) {
2469 $once = 1;
2470 doprint "Configs not produced by kconfig (will not be checked):\n";
2471 }
2472 doprint " $config\n";
2473 delete $config_list{$config};
2474 }
2475 }
2476 my $ret;
2477 do {
2478 $ret = run_config_bisect;
2479 } while (!$ret);
2480
2481 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002482
2483 success $i;
2484}
2485
Steven Rostedt27d934b2011-05-20 09:18:18 -04002486sub patchcheck_reboot {
2487 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002488 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002489}
2490
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002491sub patchcheck {
2492 my ($i) = @_;
2493
2494 die "PATCHCHECK_START[$i] not defined\n"
2495 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2496 die "PATCHCHECK_TYPE[$i] not defined\n"
2497 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2498
2499 my $start = $opt{"PATCHCHECK_START[$i]"};
2500
2501 my $end = "HEAD";
2502 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2503 $end = $opt{"PATCHCHECK_END[$i]"};
2504 }
2505
Steven Rostedta57419b2010-11-02 15:13:54 -04002506 # Get the true sha1's since we can use things like HEAD~3
2507 $start = get_sha1($start);
2508 $end = get_sha1($end);
2509
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002510 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2511
2512 # Can't have a test without having a test to run
2513 if ($type eq "test" && !defined($run_test)) {
2514 $type = "boot";
2515 }
2516
2517 open (IN, "git log --pretty=oneline $end|") or
2518 dodie "could not get git list";
2519
2520 my @list;
2521
2522 while (<IN>) {
2523 chomp;
2524 $list[$#list+1] = $_;
2525 last if (/^$start/);
2526 }
2527 close(IN);
2528
2529 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002530 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002531 }
2532
2533 # go backwards in the list
2534 @list = reverse @list;
2535
2536 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002537 my %ignored_warnings;
2538
2539 if (defined($ignore_warnings)) {
2540 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2541 $ignored_warnings{$sha1} = 1;
2542 }
2543 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002544
2545 $in_patchcheck = 1;
2546 foreach my $item (@list) {
2547 my $sha1 = $item;
2548 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2549
2550 doprint "\nProcessing commit $item\n\n";
2551
2552 run_command "git checkout $sha1" or
2553 die "Failed to checkout $sha1";
2554
2555 # only clean on the first and last patch
2556 if ($item eq $list[0] ||
2557 $item eq $list[$#list]) {
2558 $noclean = $save_clean;
2559 } else {
2560 $noclean = 1;
2561 }
2562
2563 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002564 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002565 } else {
2566 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002567 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002568 }
2569
Steven Rostedt19902072011-06-14 20:46:25 -04002570
2571 if (!defined($ignored_warnings{$sha1})) {
2572 check_buildlog $sha1 or return 0;
2573 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002574
2575 next if ($type eq "build");
2576
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002577 my $failed = 0;
2578
Steven Rostedtddf607e2011-06-14 20:49:13 -04002579 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002580
2581 if (!$failed && $type ne "boot"){
2582 do_run_test or $failed = 1;
2583 }
2584 end_monitor;
2585 return 0 if ($failed);
2586
Steven Rostedt27d934b2011-05-20 09:18:18 -04002587 patchcheck_reboot;
2588
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002589 }
2590 $in_patchcheck = 0;
2591 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002592
2593 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002594}
2595
Steven Rostedtb9066f62011-07-15 21:25:24 -04002596my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002597my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002598my $iflevel = 0;
2599my @ifdeps;
2600
2601# prevent recursion
2602my %read_kconfigs;
2603
Steven Rostedtac6974c2011-10-04 09:40:17 -04002604sub add_dep {
2605 # $config depends on $dep
2606 my ($config, $dep) = @_;
2607
2608 if (defined($depends{$config})) {
2609 $depends{$config} .= " " . $dep;
2610 } else {
2611 $depends{$config} = $dep;
2612 }
2613
2614 # record the number of configs depending on $dep
2615 if (defined $depcount{$dep}) {
2616 $depcount{$dep}++;
2617 } else {
2618 $depcount{$dep} = 1;
2619 }
2620}
2621
Steven Rostedtb9066f62011-07-15 21:25:24 -04002622# taken from streamline_config.pl
2623sub read_kconfig {
2624 my ($kconfig) = @_;
2625
2626 my $state = "NONE";
2627 my $config;
2628 my @kconfigs;
2629
2630 my $cont = 0;
2631 my $line;
2632
2633
2634 if (! -f $kconfig) {
2635 doprint "file $kconfig does not exist, skipping\n";
2636 return;
2637 }
2638
2639 open(KIN, "$kconfig")
2640 or die "Can't open $kconfig";
2641 while (<KIN>) {
2642 chomp;
2643
2644 # Make sure that lines ending with \ continue
2645 if ($cont) {
2646 $_ = $line . " " . $_;
2647 }
2648
2649 if (s/\\$//) {
2650 $cont = 1;
2651 $line = $_;
2652 next;
2653 }
2654
2655 $cont = 0;
2656
2657 # collect any Kconfig sources
2658 if (/^source\s*"(.*)"/) {
2659 $kconfigs[$#kconfigs+1] = $1;
2660 }
2661
2662 # configs found
2663 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2664 $state = "NEW";
2665 $config = $2;
2666
2667 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002668 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002669 }
2670
2671 # collect the depends for the config
2672 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2673
Steven Rostedtac6974c2011-10-04 09:40:17 -04002674 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002675
2676 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002677 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2678
2679 # selected by depends on config
2680 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002681
2682 # Check for if statements
2683 } elsif (/^if\s+(.*\S)\s*$/) {
2684 my $deps = $1;
2685 # remove beginning and ending non text
2686 $deps =~ s/^[^a-zA-Z0-9_]*//;
2687 $deps =~ s/[^a-zA-Z0-9_]*$//;
2688
2689 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2690
2691 $ifdeps[$iflevel++] = join ':', @deps;
2692
2693 } elsif (/^endif/) {
2694
2695 $iflevel-- if ($iflevel);
2696
2697 # stop on "help"
2698 } elsif (/^\s*help\s*$/) {
2699 $state = "NONE";
2700 }
2701 }
2702 close(KIN);
2703
2704 # read in any configs that were found.
2705 foreach $kconfig (@kconfigs) {
2706 if (!defined($read_kconfigs{$kconfig})) {
2707 $read_kconfigs{$kconfig} = 1;
2708 read_kconfig("$builddir/$kconfig");
2709 }
2710 }
2711}
2712
2713sub read_depends {
2714 # find out which arch this is by the kconfig file
2715 open (IN, $output_config)
2716 or dodie "Failed to read $output_config";
2717 my $arch;
2718 while (<IN>) {
2719 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2720 $arch = $1;
2721 last;
2722 }
2723 }
2724 close IN;
2725
2726 if (!defined($arch)) {
2727 doprint "Could not find arch from config file\n";
2728 doprint "no dependencies used\n";
2729 return;
2730 }
2731
2732 # arch is really the subarch, we need to know
2733 # what directory to look at.
2734 if ($arch eq "i386" || $arch eq "x86_64") {
2735 $arch = "x86";
2736 } elsif ($arch =~ /^tile/) {
2737 $arch = "tile";
2738 }
2739
2740 my $kconfig = "$builddir/arch/$arch/Kconfig";
2741
2742 if (! -f $kconfig && $arch =~ /\d$/) {
2743 my $orig = $arch;
2744 # some subarchs have numbers, truncate them
2745 $arch =~ s/\d*$//;
2746 $kconfig = "$builddir/arch/$arch/Kconfig";
2747 if (! -f $kconfig) {
2748 doprint "No idea what arch dir $orig is for\n";
2749 doprint "no dependencies used\n";
2750 return;
2751 }
2752 }
2753
2754 read_kconfig($kconfig);
2755}
2756
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002757sub read_config_list {
2758 my ($config) = @_;
2759
2760 open (IN, $config)
2761 or dodie "Failed to read $config";
2762
2763 while (<IN>) {
2764 if (/^((CONFIG\S*)=.*)/) {
2765 if (!defined($config_ignore{$2})) {
2766 $config_list{$2} = $1;
2767 }
2768 }
2769 }
2770
2771 close(IN);
2772}
2773
2774sub read_output_config {
2775 my ($config) = @_;
2776
2777 assign_configs \%config_ignore, $config;
2778}
2779
2780sub make_new_config {
2781 my @configs = @_;
2782
2783 open (OUT, ">$output_config")
2784 or dodie "Failed to write $output_config";
2785
2786 foreach my $config (@configs) {
2787 print OUT "$config\n";
2788 }
2789 close OUT;
2790}
2791
Steven Rostedtac6974c2011-10-04 09:40:17 -04002792sub chomp_config {
2793 my ($config) = @_;
2794
2795 $config =~ s/CONFIG_//;
2796
2797 return $config;
2798}
2799
Steven Rostedtb9066f62011-07-15 21:25:24 -04002800sub get_depends {
2801 my ($dep) = @_;
2802
Steven Rostedtac6974c2011-10-04 09:40:17 -04002803 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002804
2805 $dep = $depends{"$kconfig"};
2806
2807 # the dep string we have saves the dependencies as they
2808 # were found, including expressions like ! && ||. We
2809 # want to split this out into just an array of configs.
2810
2811 my $valid = "A-Za-z_0-9";
2812
2813 my @configs;
2814
2815 while ($dep =~ /[$valid]/) {
2816
2817 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2818 my $conf = "CONFIG_" . $1;
2819
2820 $configs[$#configs + 1] = $conf;
2821
2822 $dep =~ s/^[^$valid]*[$valid]+//;
2823 } else {
2824 die "this should never happen";
2825 }
2826 }
2827
2828 return @configs;
2829}
2830
2831my %min_configs;
2832my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002833my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002834my %processed_configs;
2835my %nochange_config;
2836
2837sub test_this_config {
2838 my ($config) = @_;
2839
2840 my $found;
2841
2842 # if we already processed this config, skip it
2843 if (defined($processed_configs{$config})) {
2844 return undef;
2845 }
2846 $processed_configs{$config} = 1;
2847
2848 # if this config failed during this round, skip it
2849 if (defined($nochange_config{$config})) {
2850 return undef;
2851 }
2852
Steven Rostedtac6974c2011-10-04 09:40:17 -04002853 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002854
2855 # Test dependencies first
2856 if (defined($depends{"$kconfig"})) {
2857 my @parents = get_depends $config;
2858 foreach my $parent (@parents) {
2859 # if the parent is in the min config, check it first
2860 next if (!defined($min_configs{$parent}));
2861 $found = test_this_config($parent);
2862 if (defined($found)) {
2863 return $found;
2864 }
2865 }
2866 }
2867
2868 # Remove this config from the list of configs
2869 # do a make oldnoconfig and then read the resulting
2870 # .config to make sure it is missing the config that
2871 # we had before
2872 my %configs = %min_configs;
2873 delete $configs{$config};
2874 make_new_config ((values %configs), (values %keep_configs));
2875 make_oldconfig;
2876 undef %configs;
2877 assign_configs \%configs, $output_config;
2878
2879 return $config if (!defined($configs{$config}));
2880
2881 doprint "disabling config $config did not change .config\n";
2882
2883 $nochange_config{$config} = 1;
2884
2885 return undef;
2886}
2887
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002888sub make_min_config {
2889 my ($i) = @_;
2890
2891 if (!defined($output_minconfig)) {
2892 fail "OUTPUT_MIN_CONFIG not defined" and return;
2893 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002894
2895 # If output_minconfig exists, and the start_minconfig
2896 # came from min_config, than ask if we should use
2897 # that instead.
2898 if (-f $output_minconfig && !$start_minconfig_defined) {
2899 print "$output_minconfig exists\n";
2900 if (read_yn " Use it as minconfig?") {
2901 $start_minconfig = $output_minconfig;
2902 }
2903 }
2904
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002905 if (!defined($start_minconfig)) {
2906 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2907 }
2908
Steven Rostedt35ce5952011-07-15 21:57:25 -04002909 my $temp_config = "$tmpdir/temp_config";
2910
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002911 # First things first. We build an allnoconfig to find
2912 # out what the defaults are that we can't touch.
2913 # Some are selections, but we really can't handle selections.
2914
2915 my $save_minconfig = $minconfig;
2916 undef $minconfig;
2917
2918 run_command "$make allnoconfig" or return 0;
2919
Steven Rostedtb9066f62011-07-15 21:25:24 -04002920 read_depends;
2921
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002922 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002923
Steven Rostedt43d1b652011-07-15 22:01:56 -04002924 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002925 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002926
2927 if (defined($ignore_config)) {
2928 # make sure the file exists
2929 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002930 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002931 }
2932
Steven Rostedt43d1b652011-07-15 22:01:56 -04002933 %keep_configs = %save_configs;
2934
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002935 doprint "Load initial configs from $start_minconfig\n";
2936
2937 # Look at the current min configs, and save off all the
2938 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002939 assign_configs \%min_configs, $start_minconfig;
2940
2941 my @config_keys = keys %min_configs;
2942
Steven Rostedtac6974c2011-10-04 09:40:17 -04002943 # All configs need a depcount
2944 foreach my $config (@config_keys) {
2945 my $kconfig = chomp_config $config;
2946 if (!defined $depcount{$kconfig}) {
2947 $depcount{$kconfig} = 0;
2948 }
2949 }
2950
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002951 # Remove anything that was set by the make allnoconfig
2952 # we shouldn't need them as they get set for us anyway.
2953 foreach my $config (@config_keys) {
2954 # Remove anything in the ignore_config
2955 if (defined($keep_configs{$config})) {
2956 my $file = $ignore_config;
2957 $file =~ s,.*/(.*?)$,$1,;
2958 doprint "$config set by $file ... ignored\n";
2959 delete $min_configs{$config};
2960 next;
2961 }
2962 # But make sure the settings are the same. If a min config
2963 # sets a selection, we do not want to get rid of it if
2964 # it is not the same as what we have. Just move it into
2965 # the keep configs.
2966 if (defined($config_ignore{$config})) {
2967 if ($config_ignore{$config} ne $min_configs{$config}) {
2968 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2969 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2970 $keep_configs{$config} = $min_configs{$config};
2971 } else {
2972 doprint "$config set by allnoconfig ... ignored\n";
2973 }
2974 delete $min_configs{$config};
2975 }
2976 }
2977
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002978 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002979 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002980
2981 while (!$done) {
2982
2983 my $config;
2984 my $found;
2985
2986 # Now disable each config one by one and do a make oldconfig
2987 # till we find a config that changes our list.
2988
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002989 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002990
2991 # Sort keys by who is most dependent on
2992 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2993 @test_configs ;
2994
2995 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002996 my $reset = 1;
2997 for (my $i = 0; $i < $#test_configs; $i++) {
2998 if (!defined($nochange_config{$test_configs[0]})) {
2999 $reset = 0;
3000 last;
3001 }
3002 # This config didn't change the .config last time.
3003 # Place it at the end
3004 my $config = shift @test_configs;
3005 push @test_configs, $config;
3006 }
3007
3008 # if every test config has failed to modify the .config file
3009 # in the past, then reset and start over.
3010 if ($reset) {
3011 undef %nochange_config;
3012 }
3013
Steven Rostedtb9066f62011-07-15 21:25:24 -04003014 undef %processed_configs;
3015
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003016 foreach my $config (@test_configs) {
3017
Steven Rostedtb9066f62011-07-15 21:25:24 -04003018 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003019
Steven Rostedtb9066f62011-07-15 21:25:24 -04003020 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003021
3022 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003023 }
3024
3025 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003026 # we could have failed due to the nochange_config hash
3027 # reset and try again
3028 if (!$take_two) {
3029 undef %nochange_config;
3030 $take_two = 1;
3031 next;
3032 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003033 doprint "No more configs found that we can disable\n";
3034 $done = 1;
3035 last;
3036 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003037 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003038
3039 $config = $found;
3040
3041 doprint "Test with $config disabled\n";
3042
3043 # set in_bisect to keep build and monitor from dieing
3044 $in_bisect = 1;
3045
3046 my $failed = 0;
3047 build "oldconfig";
3048 start_monitor_and_boot or $failed = 1;
3049 end_monitor;
3050
3051 $in_bisect = 0;
3052
3053 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003054 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003055 # this config is needed, add it to the ignore list.
3056 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003057 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003058 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003059
3060 # update new ignore configs
3061 if (defined($ignore_config)) {
3062 open (OUT, ">$temp_config")
3063 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003064 foreach my $config (keys %save_configs) {
3065 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003066 }
3067 close OUT;
3068 run_command "mv $temp_config $ignore_config" or
3069 dodie "failed to copy update to $ignore_config";
3070 }
3071
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003072 } else {
3073 # We booted without this config, remove it from the minconfigs.
3074 doprint "$config is not needed, disabling\n";
3075
3076 delete $min_configs{$config};
3077
3078 # Also disable anything that is not enabled in this config
3079 my %configs;
3080 assign_configs \%configs, $output_config;
3081 my @config_keys = keys %min_configs;
3082 foreach my $config (@config_keys) {
3083 if (!defined($configs{$config})) {
3084 doprint "$config is not set, disabling\n";
3085 delete $min_configs{$config};
3086 }
3087 }
3088
3089 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003090 open (OUT, ">$temp_config")
3091 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003092 foreach my $config (keys %keep_configs) {
3093 print OUT "$keep_configs{$config}\n";
3094 }
3095 foreach my $config (keys %min_configs) {
3096 print OUT "$min_configs{$config}\n";
3097 }
3098 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003099
3100 run_command "mv $temp_config $output_minconfig" or
3101 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003102 }
3103
3104 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02003105 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003106 }
3107
3108 success $i;
3109 return 1;
3110}
3111
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003112$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003113
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003114if ($#ARGV == 0) {
3115 $ktest_config = $ARGV[0];
3116 if (! -f $ktest_config) {
3117 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003118 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003119 exit 0;
3120 }
3121 }
3122} else {
3123 $ktest_config = "ktest.conf";
3124}
3125
3126if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003127 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003128 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003129 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3130 print OUT << "EOF"
3131# Generated by ktest.pl
3132#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003133
3134# PWD is a ktest.pl variable that will result in the process working
3135# directory that ktest.pl is executed in.
3136
3137# THIS_DIR is automatically assigned the PWD of the path that generated
3138# the config file. It is best to use this variable when assigning other
3139# directory paths within this directory. This allows you to easily
3140# move the test cases to other locations or to other machines.
3141#
3142THIS_DIR := $variable{"PWD"}
3143
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003144# Define each test with TEST_START
3145# The config options below it will override the defaults
3146TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003147TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003148
3149DEFAULTS
3150EOF
3151;
3152 close(OUT);
3153}
3154read_config $ktest_config;
3155
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003156if (defined($opt{"LOG_FILE"})) {
3157 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3158}
3159
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003160# Append any configs entered in manually to the config file.
3161my @new_configs = keys %entered_configs;
3162if ($#new_configs >= 0) {
3163 print "\nAppending entered in configs to $ktest_config\n";
3164 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3165 foreach my $config (@new_configs) {
3166 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003167 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003168 }
3169}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003170
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003171if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3172 unlink $opt{"LOG_FILE"};
3173}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003174
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003175doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3176
Steven Rostedta57419b2010-11-02 15:13:54 -04003177for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3178
3179 if (!$i) {
3180 doprint "DEFAULT OPTIONS:\n";
3181 } else {
3182 doprint "\nTEST $i OPTIONS";
3183 if (defined($repeat_tests{$i})) {
3184 $repeat = $repeat_tests{$i};
3185 doprint " ITERATE $repeat";
3186 }
3187 doprint "\n";
3188 }
3189
3190 foreach my $option (sort keys %opt) {
3191
3192 if ($option =~ /\[(\d+)\]$/) {
3193 next if ($i != $1);
3194 } else {
3195 next if ($i);
3196 }
3197
3198 doprint "$option = $opt{$option}\n";
3199 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003200}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003201
Steven Rostedt2a625122011-05-20 15:48:59 -04003202sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003203 my ($name, $i) = @_;
3204
3205 my $option = "$name\[$i\]";
3206
3207 if (defined($opt{$option})) {
3208 return $opt{$option};
3209 }
3210
Steven Rostedta57419b2010-11-02 15:13:54 -04003211 foreach my $test (keys %repeat_tests) {
3212 if ($i >= $test &&
3213 $i < $test + $repeat_tests{$test}) {
3214 $option = "$name\[$test\]";
3215 if (defined($opt{$option})) {
3216 return $opt{$option};
3217 }
3218 }
3219 }
3220
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003221 if (defined($opt{$name})) {
3222 return $opt{$name};
3223 }
3224
3225 return undef;
3226}
3227
Steven Rostedt2a625122011-05-20 15:48:59 -04003228sub set_test_option {
3229 my ($name, $i) = @_;
3230
3231 my $option = __set_test_option($name, $i);
3232 return $option if (!defined($option));
3233
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003234 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003235}
3236
Steven Rostedt2545eb62010-11-02 15:01:32 -04003237# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003238for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003239
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003240 # Do not reboot on failing test options
3241 $no_reboot = 1;
3242
Steven Rostedt576f6272010-11-02 14:58:38 -04003243 $iteration = $i;
3244
Steven Rostedta75fece2010-11-02 14:58:27 -04003245 my $makecmd = set_test_option("MAKE_CMD", $i);
3246
3247 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003248 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003249 $tmpdir = set_test_option("TMP_DIR", $i);
3250 $outputdir = set_test_option("OUTPUT_DIR", $i);
3251 $builddir = set_test_option("BUILD_DIR", $i);
3252 $test_type = set_test_option("TEST_TYPE", $i);
3253 $build_type = set_test_option("BUILD_TYPE", $i);
3254 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003255 $pre_build = set_test_option("PRE_BUILD", $i);
3256 $post_build = set_test_option("POST_BUILD", $i);
3257 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3258 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003259 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003260 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003261 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3262 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003263 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3264 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3265 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003266 $run_test = set_test_option("TEST", $i);
3267 $addconfig = set_test_option("ADD_CONFIG", $i);
3268 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3269 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003270 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003271 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003272 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3273 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3274 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3275 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3276 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003277 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3278 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003279 $sleep_time = set_test_option("SLEEP_TIME", $i);
3280 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003281 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003282 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003283 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003284 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003285 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003286 $store_failures = set_test_option("STORE_FAILURES", $i);
Rabin Vincentde5b6e32011-11-18 17:05:31 +05303287 $store_successes = set_test_option("STORE_SUCCESSES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003288 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003289 $timeout = set_test_option("TIMEOUT", $i);
3290 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3291 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003292 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003293 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003294 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003295 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3296 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003297 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003298 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003299 $ssh_exec = set_test_option("SSH_EXEC", $i);
3300 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003301 $target_image = set_test_option("TARGET_IMAGE", $i);
3302 $localversion = set_test_option("LOCALVERSION", $i);
3303
Steven Rostedt35ce5952011-07-15 21:57:25 -04003304 $start_minconfig_defined = 1;
3305
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003306 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003307 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003308 $start_minconfig = $minconfig;
3309 }
3310
Steven Rostedta75fece2010-11-02 14:58:27 -04003311 chdir $builddir || die "can't change directory to $builddir";
3312
Andrew Jonesa908a662011-08-12 15:32:03 +02003313 foreach my $dir ($tmpdir, $outputdir) {
3314 if (!-d $dir) {
3315 mkpath($dir) or
3316 die "can't create $dir";
3317 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003318 }
3319
Steven Rostedte48c5292010-11-02 14:35:37 -04003320 $ENV{"SSH_USER"} = $ssh_user;
3321 $ENV{"MACHINE"} = $machine;
3322
Steven Rostedta75fece2010-11-02 14:58:27 -04003323 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303324 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003325 $dmesg = "$tmpdir/dmesg-$machine";
3326 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003327 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003328
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003329 if (!$buildonly) {
3330 $target = "$ssh_user\@$machine";
3331 if ($reboot_type eq "grub") {
3332 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3333 } elsif (!defined($reboot_script)) {
3334 dodie "REBOOT_SCRIPT not defined"
3335 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003336 }
3337
3338 my $run_type = $build_type;
3339 if ($test_type eq "patchcheck") {
3340 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3341 } elsif ($test_type eq "bisect") {
3342 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003343 } elsif ($test_type eq "config_bisect") {
3344 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003345 }
3346
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003347 if ($test_type eq "make_min_config") {
3348 $run_type = "";
3349 }
3350
Steven Rostedta75fece2010-11-02 14:58:27 -04003351 # mistake in config file?
3352 if (!defined($run_type)) {
3353 $run_type = "ERROR";
3354 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003355
Steven Rostedte0a87422011-09-30 17:50:48 -04003356 my $installme = "";
3357 $installme = " no_install" if ($no_install);
3358
Steven Rostedt2545eb62010-11-02 15:01:32 -04003359 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003360 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003361
3362 unlink $dmesg;
3363 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303364 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003365
Steven Rostedt250bae82011-07-15 22:05:59 -04003366 if (defined($addconfig)) {
3367 my $min = $minconfig;
3368 if (!defined($minconfig)) {
3369 $min = "";
3370 }
3371 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003372 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003373 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003374 }
3375
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003376 my $checkout = $opt{"CHECKOUT[$i]"};
3377 if (defined($checkout)) {
3378 run_command "git checkout $checkout" or
3379 die "failed to checkout $checkout";
3380 }
3381
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003382 $no_reboot = 0;
3383
3384
Steven Rostedta75fece2010-11-02 14:58:27 -04003385 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003386 bisect $i;
3387 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003388 } elsif ($test_type eq "config_bisect") {
3389 config_bisect $i;
3390 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003391 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003392 patchcheck $i;
3393 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003394 } elsif ($test_type eq "make_min_config") {
3395 make_min_config $i;
3396 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003397 }
3398
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003399 if ($build_type ne "nobuild") {
3400 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003401 }
3402
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003403 if ($test_type eq "install") {
3404 get_version;
3405 install;
3406 success $i;
3407 next;
3408 }
3409
Steven Rostedta75fece2010-11-02 14:58:27 -04003410 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003411 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003412 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003413
3414 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3415 do_run_test or $failed = 1;
3416 }
3417 end_monitor;
3418 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003419 }
3420
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003421 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003422}
3423
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003424if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003425 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003426} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003427 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003428}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003429
Steven Rostedte48c5292010-11-02 14:35:37 -04003430doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3431
Steven Rostedt2545eb62010-11-02 15:01:32 -04003432exit 0;