blob: 2b547d6683cdc6103b5939fcfdeee3681772bc8e [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002#
Uwe Kleine-Königcce1dac2011-01-24 21:12:01 +01003# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04004# Licensed under the terms of the GNU GPL License version 2
5#
Steven Rostedt2545eb62010-11-02 15:01:32 -04006
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Steven Rostedt7faafbd2010-11-02 14:58:22 -040010use File::Path qw(mkpath);
11use File::Copy qw(cp);
Steven Rostedt2545eb62010-11-02 15:01:32 -040012use FileHandle;
13
Steven Rostedte48c5292010-11-02 14:35:37 -040014my $VERSION = "0.2";
15
Steven Rostedt2545eb62010-11-02 15:01:32 -040016$| = 1;
17
18my %opt;
Steven Rostedta57419b2010-11-02 15:13:54 -040019my %repeat_tests;
20my %repeats;
Steven Rostedta75fece2010-11-02 14:58:27 -040021my %default;
Steven Rostedt2545eb62010-11-02 15:01:32 -040022
23#default opts
Steven Rostedta57419b2010-11-02 15:13:54 -040024$default{"NUM_TESTS"} = 1;
Steven Rostedtbb8474b2011-11-23 15:58:00 -050025$default{"TEST_TYPE"} = "build";
Steven Rostedta75fece2010-11-02 14:58:27 -040026$default{"BUILD_TYPE"} = "randconfig";
27$default{"MAKE_CMD"} = "make";
28$default{"TIMEOUT"} = 120;
Steven Rostedt48920632011-06-14 20:42:19 -040029$default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}";
Steven Rostedta75fece2010-11-02 14:58:27 -040030$default{"SLEEP_TIME"} = 60; # sleep time between tests
31$default{"BUILD_NOCLEAN"} = 0;
32$default{"REBOOT_ON_ERROR"} = 0;
33$default{"POWEROFF_ON_ERROR"} = 0;
34$default{"REBOOT_ON_SUCCESS"} = 1;
35$default{"POWEROFF_ON_SUCCESS"} = 0;
36$default{"BUILD_OPTIONS"} = "";
37$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
Steven Rostedt27d934b2011-05-20 09:18:18 -040038$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
Steven Rostedta75fece2010-11-02 14:58:27 -040039$default{"CLEAR_LOG"} = 0;
Steven Rostedtc960bb92011-03-08 09:22:39 -050040$default{"BISECT_MANUAL"} = 0;
Steven Rostedtc23dca72011-03-08 09:26:31 -050041$default{"BISECT_SKIP"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040042$default{"SUCCESS_LINE"} = "login:";
Steven Rostedtf1a5b962011-06-13 10:30:00 -040043$default{"DETECT_TRIPLE_FAULT"} = 1;
Steven Rostedte0a87422011-09-30 17:50:48 -040044$default{"NO_INSTALL"} = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040045$default{"BOOTED_TIMEOUT"} = 1;
46$default{"DIE_ON_FAILURE"} = 1;
Steven Rostedte48c5292010-11-02 14:35:37 -040047$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
48$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
49$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
Steven Rostedt1c8a6172010-11-09 12:55:40 -050050$default{"STOP_AFTER_SUCCESS"} = 10;
51$default{"STOP_AFTER_FAILURE"} = 60;
Steven Rostedt2d01b262011-03-08 09:47:54 -050052$default{"STOP_TEST_AFTER"} = 600;
Steven Rostedt600bbf02011-11-21 20:12:04 -050053
54# required, and we will ask users if they don't have them but we keep the default
55# value something that is common.
56$default{"REBOOT_TYPE"} = "grub";
Steven Rostedt8d1491b2010-11-18 15:39:48 -050057$default{"LOCALVERSION"} = "-test";
Steven Rostedt600bbf02011-11-21 20:12:04 -050058$default{"SSH_USER"} = "root";
59$default{"BUILD_TARGET"} = "arch/x86/boot/bzImage";
60$default{"TARGET_IMAGE"} = "/boot/vmlinuz-test";
Steven Rostedt2545eb62010-11-02 15:01:32 -040061
Steven Rostedt8d1491b2010-11-18 15:39:48 -050062my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040063my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040064my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040065my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040066my $tmpdir;
67my $builddir;
68my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050069my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040070my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040071my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040072my $build_options;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040073my $pre_build;
74my $post_build;
75my $pre_build_die;
76my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $reboot_type;
78my $reboot_script;
79my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040080my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040081my $reboot_on_error;
82my $poweroff_on_error;
83my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040084my $powercycle_after_reboot;
85my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040086my $ssh_exec;
87my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040088my $power_off;
89my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040090my $grub_number;
91my $target;
92my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040093my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -040094my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040095my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040096my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040097my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -040098my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -040099my $output_minconfig;
100my $ignore_config;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400101my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400102my $in_bisect = 0;
103my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400104my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500105my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500106my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400107my $config_bisect_good;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400108my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400109my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400110my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400111my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530112my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400113my $dmesg;
114my $monitor_fp;
115my $monitor_pid;
116my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400117my $sleep_time;
118my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400119my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400120my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400121my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530122my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400123my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400124my $timeout;
125my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400126my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400127my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400128my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400129my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500130my $stop_after_success;
131my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500132my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400133my $build_target;
134my $target_image;
135my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400136my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400137my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400138
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500139# set when a test is something other that just building
140# which would require more options.
141my $buildonly = 1;
142
Steven 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) {
346 get_ktest_config("SSH_USER");
347 get_ktest_config("BUILD_TARGET");
348 get_ktest_config("TARGET_IMAGE");
349 get_ktest_config("POWER_CYCLE");
350 get_ktest_config("CONSOLE");
351 }
352
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500353 get_ktest_config("LOCALVERSION");
354
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500355 return if ($buildonly);
356
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500357 my $rtype = $opt{"REBOOT_TYPE"};
358
359 if (!defined($rtype)) {
360 if (!defined($opt{"GRUB_MENU"})) {
361 get_ktest_config("REBOOT_TYPE");
362 $rtype = $entered_configs{"REBOOT_TYPE"};
363 } else {
364 $rtype = "grub";
365 }
366 }
367
368 if ($rtype eq "grub") {
369 get_ktest_config("GRUB_MENU");
370 } else {
371 get_ktest_config("REBOOT_SCRIPT");
372 }
373}
374
Steven Rostedt77d942c2011-05-20 13:36:58 -0400375sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400376 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400377 my $retval = "";
378
379 # We want to check for '\', and it is just easier
380 # to check the previous characet of '$' and not need
381 # to worry if '$' is the first character. By adding
382 # a space to $value, we can just check [^\\]\$ and
383 # it will still work.
384 $value = " $value";
385
386 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
387 my $begin = $1;
388 my $var = $2;
389 my $end = $3;
390 # append beginning of value to retval
391 $retval = "$retval$begin";
392 if (defined($variable{$var})) {
393 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400394 } elsif (defined($remove_undef) && $remove_undef) {
395 # for if statements, any variable that is not defined,
396 # we simple convert to 0
397 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400398 } else {
399 # put back the origin piece.
400 $retval = "$retval\$\{$var\}";
401 }
402 $value = $end;
403 }
404 $retval = "$retval$value";
405
406 # remove the space added in the beginning
407 $retval =~ s/ //;
408
409 return "$retval"
410}
411
Steven Rostedta57419b2010-11-02 15:13:54 -0400412sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400413 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400414
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500415 if ($lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $rvalue ne "build") {
416 # Note if a test is something other than build, then we
417 # will need other manditory options.
418 $buildonly = 0;
419 }
420
Steven Rostedta57419b2010-11-02 15:13:54 -0400421 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400422 if (!$override || defined(${$overrides}{$lvalue})) {
423 my $extra = "";
424 if ($override) {
425 $extra = "In the same override section!\n";
426 }
427 die "$name: $.: Option $lvalue defined more than once!\n$extra";
428 }
429 ${$overrides}{$lvalue} = $rvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400430 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500431 if ($rvalue =~ /^\s*$/) {
432 delete $opt{$lvalue};
433 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400434 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500435 $opt{$lvalue} = $rvalue;
436 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400437}
438
Steven Rostedt77d942c2011-05-20 13:36:58 -0400439sub set_variable {
440 my ($lvalue, $rvalue) = @_;
441
442 if ($rvalue =~ /^\s*$/) {
443 delete $variable{$lvalue};
444 } else {
445 $rvalue = process_variables($rvalue);
446 $variable{$lvalue} = $rvalue;
447 }
448}
449
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400450sub process_compare {
451 my ($lval, $cmp, $rval) = @_;
452
453 # remove whitespace
454
455 $lval =~ s/^\s*//;
456 $lval =~ s/\s*$//;
457
458 $rval =~ s/^\s*//;
459 $rval =~ s/\s*$//;
460
461 if ($cmp eq "==") {
462 return $lval eq $rval;
463 } elsif ($cmp eq "!=") {
464 return $lval ne $rval;
465 }
466
467 my $statement = "$lval $cmp $rval";
468 my $ret = eval $statement;
469
470 # $@ stores error of eval
471 if ($@) {
472 return -1;
473 }
474
475 return $ret;
476}
477
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400478sub value_defined {
479 my ($val) = @_;
480
481 return defined($variable{$2}) ||
482 defined($opt{$2});
483}
484
Steven Rostedt8d735212011-10-17 11:36:44 -0400485my $d = 0;
486sub process_expression {
487 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400488
Steven Rostedt8d735212011-10-17 11:36:44 -0400489 my $c = $d++;
490
491 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
492 my $express = $1;
493
494 if (process_expression($name, $express)) {
495 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
496 } else {
497 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
498 }
499 }
500
501 $d--;
502 my $OR = "\\|\\|";
503 my $AND = "\\&\\&";
504
505 while ($val =~ s/^(.*?)($OR|$AND)//) {
506 my $express = $1;
507 my $op = $2;
508
509 if (process_expression($name, $express)) {
510 if ($op eq "||") {
511 return 1;
512 }
513 } else {
514 if ($op eq "&&") {
515 return 0;
516 }
517 }
518 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400519
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400520 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
521 my $ret = process_compare($1, $2, $3);
522 if ($ret < 0) {
523 die "$name: $.: Unable to process comparison\n";
524 }
525 return $ret;
526 }
527
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400528 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
529 if (defined $1) {
530 return !value_defined($2);
531 } else {
532 return value_defined($2);
533 }
534 }
535
Steven Rostedt45d73a52011-09-30 19:44:53 -0400536 if ($val =~ /^\s*0\s*$/) {
537 return 0;
538 } elsif ($val =~ /^\s*\d+\s*$/) {
539 return 1;
540 }
541
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400542 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400543}
544
545sub process_if {
546 my ($name, $value) = @_;
547
548 # Convert variables and replace undefined ones with 0
549 my $val = process_variables($value, 1);
550 my $ret = process_expression $name, $val;
551
552 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400553}
554
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400555sub __read_config {
556 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400557
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400558 my $in;
559 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400560
Steven Rostedta57419b2010-11-02 15:13:54 -0400561 my $name = $config;
562 $name =~ s,.*/(.*),$1,;
563
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400564 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400565 my $default = 1;
566 my $repeat = 1;
567 my $num_tests_set = 0;
568 my $skip = 0;
569 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400570 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400571 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400572 my $if = 0;
573 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400574 my $override = 0;
575
576 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400577
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400578 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400579
580 # ignore blank lines and comments
581 next if (/^\s*$/ || /\s*\#/);
582
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400583 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400584
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400585 my $type = $1;
586 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400587 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400588
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400589 my $old_test_num;
590 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400591 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400592
593 if ($type eq "TEST_START") {
594
595 if ($num_tests_set) {
596 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
597 }
598
599 $old_test_num = $test_num;
600 $old_repeat = $repeat;
601
602 $test_num += $repeat;
603 $default = 0;
604 $repeat = 1;
605 } else {
606 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400607 }
608
Steven Rostedta9f84422011-10-17 11:06:29 -0400609 # If SKIP is anywhere in the line, the command will be skipped
610 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400611 $skip = 1;
612 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400613 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400614 $skip = 0;
615 }
616
Steven Rostedta9f84422011-10-17 11:06:29 -0400617 if ($rest =~ s/\sELSE\b//) {
618 if (!$if) {
619 die "$name: $.: ELSE found with out matching IF section\n$_";
620 }
621 $if = 0;
622
623 if ($if_set) {
624 $skip = 1;
625 } else {
626 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400627 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400628 }
629
Steven Rostedta9f84422011-10-17 11:06:29 -0400630 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400631 if (process_if($name, $1)) {
632 $if_set = 1;
633 } else {
634 $skip = 1;
635 }
636 $if = 1;
637 } else {
638 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400639 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400640 }
641
Steven Rostedta9f84422011-10-17 11:06:29 -0400642 if (!$skip) {
643 if ($type eq "TEST_START") {
644 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
645 $repeat = $1;
646 $repeat_tests{"$test_num"} = $repeat;
647 }
648 } elsif ($rest =~ s/\sOVERRIDE\b//) {
649 # DEFAULT only
650 $override = 1;
651 # Clear previous overrides
652 %overrides = ();
653 }
654 }
655
656 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400657 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400658 }
659
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400660 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400661 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400662 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400663 }
664
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400665 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400666 if (!$if) {
667 die "$name: $.: ELSE found with out matching IF section\n$_";
668 }
669 $rest = $1;
670 if ($if_set) {
671 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400672 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400673 } else {
674 $skip = 0;
675
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400676 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400677 # May be a ELSE IF section.
678 if (!process_if($name, $1)) {
679 $skip = 1;
680 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400681 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400682 } else {
683 $if = 0;
684 }
685 }
686
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400687 if ($rest !~ /^\s*$/) {
688 die "$name: $.: Gargbage found after DEFAULTS\n$_";
689 }
690
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400691 } elsif (/^\s*INCLUDE\s+(\S+)/) {
692
693 next if ($skip);
694
695 if (!$default) {
696 die "$name: $.: INCLUDE can only be done in default sections\n$_";
697 }
698
699 my $file = process_variables($1);
700
701 if ($file !~ m,^/,) {
702 # check the path of the config file first
703 if ($config =~ m,(.*)/,) {
704 if (-f "$1/$file") {
705 $file = "$1/$file";
706 }
707 }
708 }
709
710 if ( ! -r $file ) {
711 die "$name: $.: Can't read file $file\n$_";
712 }
713
714 if (__read_config($file, \$test_num)) {
715 $test_case = 1;
716 }
717
Steven Rostedta57419b2010-11-02 15:13:54 -0400718 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
719
720 next if ($skip);
721
Steven Rostedt2545eb62010-11-02 15:01:32 -0400722 my $lvalue = $1;
723 my $rvalue = $2;
724
Steven Rostedta57419b2010-11-02 15:13:54 -0400725 if (!$default &&
726 ($lvalue eq "NUM_TESTS" ||
727 $lvalue eq "LOG_FILE" ||
728 $lvalue eq "CLEAR_LOG")) {
729 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400730 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400731
732 if ($lvalue eq "NUM_TESTS") {
733 if ($test_num) {
734 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
735 }
736 if (!$default) {
737 die "$name: $.: NUM_TESTS must be set in default section\n";
738 }
739 $num_tests_set = 1;
740 }
741
742 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400743 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400744 } else {
745 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400746 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400747
748 if ($repeat > 1) {
749 $repeats{$val} = $repeat;
750 }
751 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400752 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
753 next if ($skip);
754
755 my $lvalue = $1;
756 my $rvalue = $2;
757
758 # process config variables.
759 # Config variables are only active while reading the
760 # config and can be defined anywhere. They also ignore
761 # TEST_START and DEFAULTS, but are skipped if they are in
762 # on of these sections that have SKIP defined.
763 # The save variable can be
764 # defined multiple times and the new one simply overrides
765 # the prevous one.
766 set_variable($lvalue, $rvalue);
767
Steven Rostedta57419b2010-11-02 15:13:54 -0400768 } else {
769 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400770 }
771 }
772
Steven Rostedta57419b2010-11-02 15:13:54 -0400773 if ($test_num) {
774 $test_num += $repeat - 1;
775 $opt{"NUM_TESTS"} = $test_num;
776 }
777
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400778 close($in);
779
780 $$current_test_num = $test_num;
781
782 return $test_case;
783}
784
Steven Rostedtc4261d02011-11-23 13:41:18 -0500785sub get_test_case {
786 print "What test case would you like to run?\n";
787 print " (build, install or boot)\n";
788 print " Other tests are available but require editing the config file\n";
789 my $ans = <STDIN>;
790 chomp $ans;
791 $default{"TEST_TYPE"} = $ans;
792}
793
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400794sub read_config {
795 my ($config) = @_;
796
797 my $test_case;
798 my $test_num = 0;
799
800 $test_case = __read_config $config, \$test_num;
801
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500802 # make sure we have all mandatory configs
803 get_ktest_configs;
804
Steven Rostedt0df213c2011-06-14 20:51:37 -0400805 # was a test specified?
806 if (!$test_case) {
807 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500808 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400809 }
810
Steven Rostedta75fece2010-11-02 14:58:27 -0400811 # set any defaults
812
813 foreach my $default (keys %default) {
814 if (!defined($opt{$default})) {
815 $opt{$default} = $default{$default};
816 }
817 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400818}
819
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400820sub __eval_option {
821 my ($option, $i) = @_;
822
823 # Add space to evaluate the character before $
824 $option = " $option";
825 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530826 my $repeated = 0;
827 my $parent = 0;
828
829 foreach my $test (keys %repeat_tests) {
830 if ($i >= $test &&
831 $i < $test + $repeat_tests{$test}) {
832
833 $repeated = 1;
834 $parent = $test;
835 last;
836 }
837 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400838
839 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
840 my $start = $1;
841 my $var = $2;
842 my $end = $3;
843
844 # Append beginning of line
845 $retval = "$retval$start";
846
847 # If the iteration option OPT[$i] exists, then use that.
848 # otherwise see if the default OPT (without [$i]) exists.
849
850 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530851 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400852
853 if (defined($opt{$o})) {
854 $o = $opt{$o};
855 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +0530856 } elsif ($repeated && defined($opt{$parento})) {
857 $o = $opt{$parento};
858 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -0400859 } elsif (defined($opt{$var})) {
860 $o = $opt{$var};
861 $retval = "$retval$o";
862 } else {
863 $retval = "$retval\$\{$var\}";
864 }
865
866 $option = $end;
867 }
868
869 $retval = "$retval$option";
870
871 $retval =~ s/^ //;
872
873 return $retval;
874}
875
876sub eval_option {
877 my ($option, $i) = @_;
878
879 my $prev = "";
880
881 # Since an option can evaluate to another option,
882 # keep iterating until we do not evaluate any more
883 # options.
884 my $r = 0;
885 while ($prev ne $option) {
886 # Check for recursive evaluations.
887 # 100 deep should be more than enough.
888 if ($r++ > 100) {
889 die "Over 100 evaluations accurred with $option\n" .
890 "Check for recursive variables\n";
891 }
892 $prev = $option;
893 $option = __eval_option($option, $i);
894 }
895
896 return $option;
897}
898
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500899sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400900 if (defined($opt{"LOG_FILE"})) {
901 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
902 print OUT @_;
903 close(OUT);
904 }
905}
906
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500907sub logit {
908 if (defined($opt{"LOG_FILE"})) {
909 _logit @_;
910 } else {
911 print @_;
912 }
913}
914
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400915sub doprint {
916 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500917 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400918}
919
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400920sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +0200921sub start_monitor;
922sub end_monitor;
923sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400924
925sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +0200926 my ($time) = @_;
927
Steven Rostedt2b803362011-09-30 18:00:23 -0400928 if (defined($time)) {
929 start_monitor;
930 # flush out current monitor
931 # May contain the reboot success line
932 wait_for_monitor 1;
933 }
934
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400935 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400936 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400937 if (defined($powercycle_after_reboot)) {
938 sleep $powercycle_after_reboot;
939 run_command "$power_cycle";
940 }
941 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400942 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400943 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400944 }
Andrew Jones2728be42011-08-12 15:32:05 +0200945
946 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -0400947 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +0200948 end_monitor;
949 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400950}
951
Steven Rostedt576f6272010-11-02 14:58:38 -0400952sub do_not_reboot {
953 my $i = $iteration;
954
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400955 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -0400956 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
957 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
958}
959
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400960sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400961 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400962
Steven Rostedt576f6272010-11-02 14:58:38 -0400963 my $i = $iteration;
964
965 if ($reboot_on_error && !do_not_reboot) {
966
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400967 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400968 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400969
Steven Rostedta75fece2010-11-02 14:58:27 -0400970 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400971 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400972 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400973 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400974
Steven Rostedtf80802c2011-03-07 13:18:47 -0500975 if (defined($opt{"LOG_FILE"})) {
976 print " See $opt{LOG_FILE} for more info.\n";
977 }
978
Steven Rostedt576f6272010-11-02 14:58:38 -0400979 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400980}
981
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400982sub open_console {
983 my ($fp) = @_;
984
985 my $flags;
986
Steven Rostedta75fece2010-11-02 14:58:27 -0400987 my $pid = open($fp, "$console|") or
988 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400989
990 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400991 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400992 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400993 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400994
995 return $pid;
996}
997
998sub close_console {
999 my ($fp, $pid) = @_;
1000
1001 doprint "kill child process $pid\n";
1002 kill 2, $pid;
1003
1004 print "closing!\n";
1005 close($fp);
1006}
1007
1008sub start_monitor {
1009 if ($monitor_cnt++) {
1010 return;
1011 }
1012 $monitor_fp = \*MONFD;
1013 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001014
1015 return;
1016
1017 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001018}
1019
1020sub end_monitor {
1021 if (--$monitor_cnt) {
1022 return;
1023 }
1024 close_console($monitor_fp, $monitor_pid);
1025}
1026
1027sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001028 my ($time, $stop) = @_;
1029 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001030 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001031 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001032
Steven Rostedta75fece2010-11-02 14:58:27 -04001033 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001034
1035 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001036 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001037 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001038 last if (!defined($line));
1039 print "$line";
1040 $full_line .= $line;
1041
1042 if (defined($stop) && $full_line =~ /$stop/) {
1043 doprint "wait for monitor detected $stop\n";
1044 $booted = 1;
1045 }
1046
1047 if ($line =~ /\n/) {
1048 $full_line = "";
1049 }
1050 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001051 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001052}
1053
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301054sub save_logs {
1055 my ($result, $basedir) = @_;
1056 my @t = localtime;
1057 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1058 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1059
1060 my $type = $build_type;
1061 if ($type =~ /useconfig/) {
1062 $type = "useconfig";
1063 }
1064
1065 my $dir = "$machine-$test_type-$type-$result-$date";
1066
1067 $dir = "$basedir/$dir";
1068
1069 if (!-d $dir) {
1070 mkpath($dir) or
1071 die "can't create $dir";
1072 }
1073
1074 my %files = (
1075 "config" => $output_config,
1076 "buildlog" => $buildlog,
1077 "dmesg" => $dmesg,
1078 "testlog" => $testlog,
1079 );
1080
1081 while (my ($name, $source) = each(%files)) {
1082 if (-f "$source") {
1083 cp "$source", "$dir/$name" or
1084 die "failed to copy $source";
1085 }
1086 }
1087
1088 doprint "*** Saved info to $dir ***\n";
1089}
1090
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001091sub fail {
1092
Steven Rostedta75fece2010-11-02 14:58:27 -04001093 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001094 dodie @_;
1095 }
1096
Steven Rostedta75fece2010-11-02 14:58:27 -04001097 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001098
Steven Rostedt576f6272010-11-02 14:58:38 -04001099 my $i = $iteration;
1100
Steven Rostedta75fece2010-11-02 14:58:27 -04001101 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001102 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001103 doprint "REBOOTING\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001104 reboot $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001105 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001106
Steven Rostedt9064af52011-06-13 10:38:48 -04001107 my $name = "";
1108
1109 if (defined($test_name)) {
1110 $name = " ($test_name)";
1111 }
1112
Steven Rostedt576f6272010-11-02 14:58:38 -04001113 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1114 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001115 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001116 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1117 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001118
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301119 if (defined($store_failures)) {
1120 save_logs "fail", $store_failures;
1121 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001122
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001123 return 1;
1124}
1125
Steven Rostedt2545eb62010-11-02 15:01:32 -04001126sub run_command {
1127 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001128 my $dolog = 0;
1129 my $dord = 0;
1130 my $pid;
1131
Steven Rostedte48c5292010-11-02 14:35:37 -04001132 $command =~ s/\$SSH_USER/$ssh_user/g;
1133 $command =~ s/\$MACHINE/$machine/g;
1134
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001135 doprint("$command ... ");
1136
1137 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001138 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001139
1140 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001141 open(LOG, ">>$opt{LOG_FILE}") or
1142 dodie "failed to write to log";
1143 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001144 }
1145
1146 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001147 open (RD, ">$redirect") or
1148 dodie "failed to write to redirect $redirect";
1149 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001150 }
1151
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001152 while (<CMD>) {
1153 print LOG if ($dolog);
1154 print RD if ($dord);
1155 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001156
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001157 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001158 my $failed = $?;
1159
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001160 close(CMD);
1161 close(LOG) if ($dolog);
1162 close(RD) if ($dord);
1163
Steven Rostedt2545eb62010-11-02 15:01:32 -04001164 if ($failed) {
1165 doprint "FAILED!\n";
1166 } else {
1167 doprint "SUCCESS\n";
1168 }
1169
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001170 return !$failed;
1171}
1172
Steven Rostedte48c5292010-11-02 14:35:37 -04001173sub run_ssh {
1174 my ($cmd) = @_;
1175 my $cp_exec = $ssh_exec;
1176
1177 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1178 return run_command "$cp_exec";
1179}
1180
1181sub run_scp {
1182 my ($src, $dst) = @_;
1183 my $cp_scp = $scp_to_target;
1184
1185 $cp_scp =~ s/\$SRC_FILE/$src/g;
1186 $cp_scp =~ s/\$DST_FILE/$dst/g;
1187
1188 return run_command "$cp_scp";
1189}
1190
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001191sub get_grub_index {
1192
Steven Rostedta75fece2010-11-02 14:58:27 -04001193 if ($reboot_type ne "grub") {
1194 return;
1195 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001196 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001197
1198 doprint "Find grub menu ... ";
1199 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001200
1201 my $ssh_grub = $ssh_exec;
1202 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1203
1204 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001205 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001206
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001207 my $found = 0;
1208
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001209 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001210 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001211 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001212 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001213 last;
1214 } elsif (/^\s*title\s/) {
1215 $grub_number++;
1216 }
1217 }
1218 close(IN);
1219
Steven Rostedta75fece2010-11-02 14:58:27 -04001220 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001221 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001222 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001223}
1224
Steven Rostedt2545eb62010-11-02 15:01:32 -04001225sub wait_for_input
1226{
1227 my ($fp, $time) = @_;
1228 my $rin;
1229 my $ready;
1230 my $line;
1231 my $ch;
1232
1233 if (!defined($time)) {
1234 $time = $timeout;
1235 }
1236
1237 $rin = '';
1238 vec($rin, fileno($fp), 1) = 1;
1239 $ready = select($rin, undef, undef, $time);
1240
1241 $line = "";
1242
1243 # try to read one char at a time
1244 while (sysread $fp, $ch, 1) {
1245 $line .= $ch;
1246 last if ($ch eq "\n");
1247 }
1248
1249 if (!length($line)) {
1250 return undef;
1251 }
1252
1253 return $line;
1254}
1255
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001256sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -04001257 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001258 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
1259 reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -04001260 return;
1261 }
1262
1263 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001264}
1265
Steven Rostedta57419b2010-11-02 15:13:54 -04001266sub get_sha1 {
1267 my ($commit) = @_;
1268
1269 doprint "git rev-list --max-count=1 $commit ... ";
1270 my $sha1 = `git rev-list --max-count=1 $commit`;
1271 my $ret = $?;
1272
1273 logit $sha1;
1274
1275 if ($ret) {
1276 doprint "FAILED\n";
1277 dodie "Failed to get git $commit";
1278 }
1279
1280 print "SUCCESS\n";
1281
1282 chomp $sha1;
1283
1284 return $sha1;
1285}
1286
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001287sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001288 my $booted = 0;
1289 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001290 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001291 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001292
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001293 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001294
1295 my $line;
1296 my $full_line = "";
1297
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001298 open(DMESG, "> $dmesg") or
1299 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001300
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001301 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001302
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001303 my $success_start;
1304 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001305 my $monitor_start = time;
1306 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001307 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001308
Steven Rostedt2d01b262011-03-08 09:47:54 -05001309 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001310
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001311 if ($bug && defined($stop_after_failure) &&
1312 $stop_after_failure >= 0) {
1313 my $time = $stop_after_failure - (time - $failure_start);
1314 $line = wait_for_input($monitor_fp, $time);
1315 if (!defined($line)) {
1316 doprint "bug timed out after $booted_timeout seconds\n";
1317 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1318 last;
1319 }
1320 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001321 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001322 if (!defined($line)) {
1323 my $s = $booted_timeout == 1 ? "" : "s";
1324 doprint "Successful boot found: break after $booted_timeout second$s\n";
1325 last;
1326 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001327 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001328 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001329 if (!defined($line)) {
1330 my $s = $timeout == 1 ? "" : "s";
1331 doprint "Timed out after $timeout second$s\n";
1332 last;
1333 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001334 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001335
Steven Rostedt2545eb62010-11-02 15:01:32 -04001336 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001337 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001338
1339 # we are not guaranteed to get a full line
1340 $full_line .= $line;
1341
Steven Rostedta75fece2010-11-02 14:58:27 -04001342 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001343 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001344 $success_start = time;
1345 }
1346
1347 if ($booted && defined($stop_after_success) &&
1348 $stop_after_success >= 0) {
1349 my $now = time;
1350 if ($now - $success_start >= $stop_after_success) {
1351 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1352 last;
1353 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001354 }
1355
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001356 if ($full_line =~ /\[ backtrace testing \]/) {
1357 $skip_call_trace = 1;
1358 }
1359
Steven Rostedt2545eb62010-11-02 15:01:32 -04001360 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -05001361 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001362 $bug = 1;
1363 $failure_start = time;
1364 }
1365 }
1366
1367 if ($bug && defined($stop_after_failure) &&
1368 $stop_after_failure >= 0) {
1369 my $now = time;
1370 if ($now - $failure_start >= $stop_after_failure) {
1371 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1372 last;
1373 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001374 }
1375
1376 if ($full_line =~ /\[ end of backtrace testing \]/) {
1377 $skip_call_trace = 0;
1378 }
1379
1380 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001381 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001382 $bug = 1;
1383 }
1384
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001385 # Detect triple faults by testing the banner
1386 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1387 if ($1 eq $version) {
1388 $version_found = 1;
1389 } elsif ($version_found && $detect_triplefault) {
1390 # We already booted into the kernel we are testing,
1391 # but now we booted into another kernel?
1392 # Consider this a triple fault.
1393 doprint "Aleady booted in Linux kernel $version, but now\n";
1394 doprint "we booted into Linux kernel $1.\n";
1395 doprint "Assuming that this is a triple fault.\n";
1396 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1397 last;
1398 }
1399 }
1400
Steven Rostedt2545eb62010-11-02 15:01:32 -04001401 if ($line =~ /\n/) {
1402 $full_line = "";
1403 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001404
1405 if ($stop_test_after > 0 && !$booted && !$bug) {
1406 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001407 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001408 $done = 1;
1409 }
1410 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001411 }
1412
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001413 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001414
Steven Rostedt2545eb62010-11-02 15:01:32 -04001415 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001416 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001417 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001418 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001419
Steven Rostedta75fece2010-11-02 14:58:27 -04001420 if (!$booted) {
1421 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001422 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001423 }
1424
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001425 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001426}
1427
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001428sub do_post_install {
1429
1430 return if (!defined($post_install));
1431
1432 my $cp_post_install = $post_install;
1433 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
1434 run_command "$cp_post_install" or
1435 dodie "Failed to run post install";
1436}
1437
Steven Rostedt2545eb62010-11-02 15:01:32 -04001438sub install {
1439
Steven Rostedte0a87422011-09-30 17:50:48 -04001440 return if ($no_install);
1441
Steven Rostedte48c5292010-11-02 14:35:37 -04001442 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001443 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001444
1445 my $install_mods = 0;
1446
1447 # should we process modules?
1448 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001449 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001450 while (<IN>) {
1451 if (/CONFIG_MODULES(=y)?/) {
1452 $install_mods = 1 if (defined($1));
1453 last;
1454 }
1455 }
1456 close(IN);
1457
1458 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001459 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001460 doprint "No modules needed\n";
1461 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001462 }
1463
Steven Rostedta75fece2010-11-02 14:58:27 -04001464 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001465 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001466
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001467 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001468 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001469
Steven Rostedte48c5292010-11-02 14:35:37 -04001470 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001471 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001472
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001473 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001474 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001475 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001476
Steven Rostedte48c5292010-11-02 14:35:37 -04001477 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001478 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001479
Steven Rostedta75fece2010-11-02 14:58:27 -04001480 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001481
Steven Rostedte7b13442011-06-14 20:44:36 -04001482 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001483 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001484
Steven Rostedte48c5292010-11-02 14:35:37 -04001485 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001486
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001487 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001488}
1489
Steven Rostedtddf607e2011-06-14 20:49:13 -04001490sub get_version {
1491 # get the release name
1492 doprint "$make kernelrelease ... ";
1493 $version = `$make kernelrelease | tail -1`;
1494 chomp($version);
1495 doprint "$version\n";
1496}
1497
1498sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001499 # Make sure the stable kernel has finished booting
1500 start_monitor;
1501 wait_for_monitor 5;
1502 end_monitor;
1503
Steven Rostedtddf607e2011-06-14 20:49:13 -04001504 get_grub_index;
1505 get_version;
1506 install;
1507
1508 start_monitor;
1509 return monitor;
1510}
1511
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001512sub check_buildlog {
1513 my ($patch) = @_;
1514
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001515 my @files = `git show $patch | diffstat -l`;
1516
1517 open(IN, "git show $patch |") or
1518 dodie "failed to show $patch";
1519 while (<IN>) {
1520 if (m,^--- a/(.*),) {
1521 chomp $1;
1522 $files[$#files] = $1;
1523 }
1524 }
1525 close(IN);
1526
1527 open(IN, $buildlog) or dodie "Can't open $buildlog";
1528 while (<IN>) {
1529 if (/^\s*(.*?):.*(warning|error)/) {
1530 my $err = $1;
1531 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001532 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001533 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001534 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001535 }
1536 }
1537 }
1538 }
1539 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001540
1541 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001542}
1543
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001544sub apply_min_config {
1545 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001546
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001547 # Read the config file and remove anything that
1548 # is in the force_config hash (from minconfig and others)
1549 # then add the force config back.
1550
1551 doprint "Applying minimum configurations into $output_config.new\n";
1552
1553 open (OUT, ">$outconfig") or
1554 dodie "Can't create $outconfig";
1555
1556 if (-f $output_config) {
1557 open (IN, $output_config) or
1558 dodie "Failed to open $output_config";
1559 while (<IN>) {
1560 if (/^(# )?(CONFIG_[^\s=]*)/) {
1561 next if (defined($force_config{$2}));
1562 }
1563 print OUT;
1564 }
1565 close IN;
1566 }
1567 foreach my $config (keys %force_config) {
1568 print OUT "$force_config{$config}\n";
1569 }
1570 close OUT;
1571
1572 run_command "mv $outconfig $output_config";
1573}
1574
1575sub make_oldconfig {
1576
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001577 my @force_list = keys %force_config;
1578
1579 if ($#force_list >= 0) {
1580 apply_min_config;
1581 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001582
1583 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001584 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1585 # try a yes '' | oldconfig
1586 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001587 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001588 dodie "failed make config oldconfig";
1589 }
1590}
1591
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001592# read a config file and use this to force new configs.
1593sub load_force_config {
1594 my ($config) = @_;
1595
1596 open(IN, $config) or
1597 dodie "failed to read $config";
1598 while (<IN>) {
1599 chomp;
1600 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1601 $force_config{$1} = $_;
1602 } elsif (/^# (CONFIG_\S*) is not set/) {
1603 $force_config{$1} = $_;
1604 }
1605 }
1606 close IN;
1607}
1608
Steven Rostedt2545eb62010-11-02 15:01:32 -04001609sub build {
1610 my ($type) = @_;
1611
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001612 unlink $buildlog;
1613
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001614 # Failed builds should not reboot the target
1615 my $save_no_reboot = $no_reboot;
1616 $no_reboot = 1;
1617
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001618 if (defined($pre_build)) {
1619 my $ret = run_command $pre_build;
1620 if (!$ret && defined($pre_build_die) &&
1621 $pre_build_die) {
1622 dodie "failed to pre_build\n";
1623 }
1624 }
1625
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001626 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001627 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001628 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001629
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001630 $type = "oldconfig";
1631 }
1632
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001633 # old config can ask questions
1634 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001635 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001636
1637 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001638 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001639
Andrew Jones13488232011-08-12 15:32:04 +02001640 if (!$noclean) {
1641 run_command "mv $output_config $outputdir/config_temp" or
1642 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001643
Andrew Jones13488232011-08-12 15:32:04 +02001644 run_command "$make mrproper" or dodie "make mrproper";
1645
1646 run_command "mv $outputdir/config_temp $output_config" or
1647 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001648 }
1649
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001650 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001651 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001652 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001653 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001654 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001655
1656 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001657 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1658 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001659 close(OUT);
1660
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001661 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001662 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001663 }
1664
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001665 if ($type ne "oldnoconfig") {
1666 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001667 dodie "failed make config";
1668 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001669 # Run old config regardless, to enforce min configurations
1670 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001671
Steven Rostedta75fece2010-11-02 14:58:27 -04001672 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001673 my $build_ret = run_command "$make $build_options";
1674 undef $redirect;
1675
1676 if (defined($post_build)) {
1677 my $ret = run_command $post_build;
1678 if (!$ret && defined($post_build_die) &&
1679 $post_build_die) {
1680 dodie "failed to post_build\n";
1681 }
1682 }
1683
1684 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001685 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001686 if ($in_bisect) {
1687 $no_reboot = $save_no_reboot;
1688 return 0;
1689 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001690 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001691 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001692
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001693 $no_reboot = $save_no_reboot;
1694
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001695 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001696}
1697
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001698sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001699 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001700 if (defined($poweroff_after_halt)) {
1701 sleep $poweroff_after_halt;
1702 run_command "$power_off";
1703 }
1704 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001705 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001706 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001707 }
1708}
1709
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001710sub success {
1711 my ($i) = @_;
1712
Steven Rostedte48c5292010-11-02 14:35:37 -04001713 $successes++;
1714
Steven Rostedt9064af52011-06-13 10:38:48 -04001715 my $name = "";
1716
1717 if (defined($test_name)) {
1718 $name = " ($test_name)";
1719 }
1720
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001721 doprint "\n\n*******************************************\n";
1722 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001723 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001724 doprint "*******************************************\n";
1725 doprint "*******************************************\n";
1726
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301727 if (defined($store_successes)) {
1728 save_logs "success", $store_successes;
1729 }
1730
Steven Rostedt576f6272010-11-02 14:58:38 -04001731 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001732 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001733 reboot $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001734 }
1735}
1736
Steven Rostedtc960bb92011-03-08 09:22:39 -05001737sub answer_bisect {
1738 for (;;) {
1739 doprint "Pass or fail? [p/f]";
1740 my $ans = <STDIN>;
1741 chomp $ans;
1742 if ($ans eq "p" || $ans eq "P") {
1743 return 1;
1744 } elsif ($ans eq "f" || $ans eq "F") {
1745 return 0;
1746 } else {
1747 print "Please answer 'P' or 'F'\n";
1748 }
1749 }
1750}
1751
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001752sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001753 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001754
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001755 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001756 $reboot_on_error = 0;
1757 $poweroff_on_error = 0;
1758 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001759
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301760 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001761 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05301762 undef $redirect;
1763
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001764 exit $failed;
1765}
1766
1767my $child_done;
1768
1769sub child_finished {
1770 $child_done = 1;
1771}
1772
1773sub do_run_test {
1774 my $child_pid;
1775 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001776 my $line;
1777 my $full_line;
1778 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001779
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001780 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001781
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001782 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001783
1784 $child_done = 0;
1785
1786 $SIG{CHLD} = qw(child_finished);
1787
1788 $child_pid = fork;
1789
1790 child_run_test if (!$child_pid);
1791
1792 $full_line = "";
1793
1794 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001795 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001796 if (defined($line)) {
1797
1798 # we are not guaranteed to get a full line
1799 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001800 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001801
1802 if ($full_line =~ /call trace:/i) {
1803 $bug = 1;
1804 }
1805
1806 if ($full_line =~ /Kernel panic -/) {
1807 $bug = 1;
1808 }
1809
1810 if ($line =~ /\n/) {
1811 $full_line = "";
1812 }
1813 }
1814 } while (!$child_done && !$bug);
1815
1816 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001817 my $failure_start = time;
1818 my $now;
1819 do {
1820 $line = wait_for_input($monitor_fp, 1);
1821 if (defined($line)) {
1822 doprint $line;
1823 }
1824 $now = time;
1825 if ($now - $failure_start >= $stop_after_failure) {
1826 last;
1827 }
1828 } while (defined($line));
1829
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001830 doprint "Detected kernel crash!\n";
1831 # kill the child with extreme prejudice
1832 kill 9, $child_pid;
1833 }
1834
1835 waitpid $child_pid, 0;
1836 $child_exit = $?;
1837
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001838 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001839 return 0 if $in_bisect;
1840 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001841 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001842 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001843}
1844
Steven Rostedta75fece2010-11-02 14:58:27 -04001845sub run_git_bisect {
1846 my ($command) = @_;
1847
1848 doprint "$command ... ";
1849
1850 my $output = `$command 2>&1`;
1851 my $ret = $?;
1852
1853 logit $output;
1854
1855 if ($ret) {
1856 doprint "FAILED\n";
1857 dodie "Failed to git bisect";
1858 }
1859
1860 doprint "SUCCESS\n";
1861 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1862 doprint "$1 [$2]\n";
1863 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1864 $bisect_bad = $1;
1865 doprint "Found bad commit... $1\n";
1866 return 0;
1867 } else {
1868 # we already logged it, just print it now.
1869 print $output;
1870 }
1871
1872 return 1;
1873}
1874
Steven Rostedtc23dca72011-03-08 09:26:31 -05001875sub bisect_reboot {
1876 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02001877 reboot $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05001878}
1879
1880# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001881sub run_bisect_test {
1882 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001883
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001884 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001885 my $result;
1886 my $output;
1887 my $ret;
1888
Steven Rostedt0a05c762010-11-08 11:14:10 -05001889 $in_bisect = 1;
1890
1891 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001892
1893 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001894 if ($failed && $bisect_skip) {
1895 $in_bisect = 0;
1896 return -1;
1897 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001898 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001899
1900 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04001901 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001902
1903 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001904 if ($failed && $bisect_skip) {
1905 end_monitor;
1906 bisect_reboot;
1907 $in_bisect = 0;
1908 return -1;
1909 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001910 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001911
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001912 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001913 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001914 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001915 }
1916
1917 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001918 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001919 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001920 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001921 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001922
1923 # reboot the box to a kernel we can ssh to
1924 if ($type ne "build") {
1925 bisect_reboot;
1926 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001927 $in_bisect = 0;
1928
1929 return $result;
1930}
1931
1932sub run_bisect {
1933 my ($type) = @_;
1934 my $buildtype = "oldconfig";
1935
1936 # We should have a minconfig to use?
1937 if (defined($minconfig)) {
1938 $buildtype = "useconfig:$minconfig";
1939 }
1940
1941 my $ret = run_bisect_test $type, $buildtype;
1942
Steven Rostedtc960bb92011-03-08 09:22:39 -05001943 if ($bisect_manual) {
1944 $ret = answer_bisect;
1945 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001946
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001947 # Are we looking for where it worked, not failed?
1948 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001949 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001950 }
1951
Steven Rostedtc23dca72011-03-08 09:26:31 -05001952 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001953 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001954 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001955 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001956 } elsif ($bisect_skip) {
1957 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1958 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001959 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001960}
1961
Steven Rostedtdad98752011-11-22 20:48:57 -05001962sub update_bisect_replay {
1963 my $tmp_log = "$tmpdir/ktest_bisect_log";
1964 run_command "git bisect log > $tmp_log" or
1965 die "can't create bisect log";
1966 return $tmp_log;
1967}
1968
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001969sub bisect {
1970 my ($i) = @_;
1971
1972 my $result;
1973
1974 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1975 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1976 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1977
1978 my $good = $opt{"BISECT_GOOD[$i]"};
1979 my $bad = $opt{"BISECT_BAD[$i]"};
1980 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001981 my $start = $opt{"BISECT_START[$i]"};
1982 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001983 my $start_files = $opt{"BISECT_FILES[$i]"};
1984
1985 if (defined($start_files)) {
1986 $start_files = " -- " . $start_files;
1987 } else {
1988 $start_files = "";
1989 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001990
Steven Rostedta57419b2010-11-02 15:13:54 -04001991 # convert to true sha1's
1992 $good = get_sha1($good);
1993 $bad = get_sha1($bad);
1994
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001995 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1996 $opt{"BISECT_REVERSE[$i]"} == 1) {
1997 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1998 $reverse_bisect = 1;
1999 } else {
2000 $reverse_bisect = 0;
2001 }
2002
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002003 # Can't have a test without having a test to run
2004 if ($type eq "test" && !defined($run_test)) {
2005 $type = "boot";
2006 }
2007
Steven Rostedtdad98752011-11-22 20:48:57 -05002008 # Check if a bisect was running
2009 my $bisect_start_file = "$builddir/.git/BISECT_START";
2010
Steven Rostedta75fece2010-11-02 14:58:27 -04002011 my $check = $opt{"BISECT_CHECK[$i]"};
Steven Rostedtdad98752011-11-22 20:48:57 -05002012 my $do_check = defined($check) && $check ne "0";
2013
2014 if ( -f $bisect_start_file ) {
2015 print "Bisect in progress found\n";
2016 if ($do_check) {
2017 print " If you say yes, then no checks of good or bad will be done\n";
2018 }
2019 if (defined($replay)) {
2020 print "** BISECT_REPLAY is defined in config file **";
2021 print " Ignore config option and perform new git bisect log?\n";
2022 if (read_ync " (yes, no, or cancel) ") {
2023 $replay = update_bisect_replay;
2024 $do_check = 0;
2025 }
2026 } elsif (read_yn "read git log and continue?") {
2027 $replay = update_bisect_replay;
2028 $do_check = 0;
2029 }
2030 }
2031
2032 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002033
2034 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002035 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002036
2037 if ($check ne "good") {
2038 doprint "TESTING BISECT BAD [$bad]\n";
2039 run_command "git checkout $bad" or
2040 die "Failed to checkout $bad";
2041
2042 $result = run_bisect $type;
2043
2044 if ($result ne "bad") {
2045 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2046 }
2047 }
2048
2049 if ($check ne "bad") {
2050 doprint "TESTING BISECT GOOD [$good]\n";
2051 run_command "git checkout $good" or
2052 die "Failed to checkout $good";
2053
2054 $result = run_bisect $type;
2055
2056 if ($result ne "good") {
2057 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2058 }
2059 }
2060
2061 # checkout where we started
2062 run_command "git checkout $head" or
2063 die "Failed to checkout $head";
2064 }
2065
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002066 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002067 dodie "could not start bisect";
2068
2069 run_command "git bisect good $good" or
2070 dodie "could not set bisect good to $good";
2071
2072 run_git_bisect "git bisect bad $bad" or
2073 dodie "could not set bisect bad to $bad";
2074
2075 if (defined($replay)) {
2076 run_command "git bisect replay $replay" or
2077 dodie "failed to run replay";
2078 }
2079
2080 if (defined($start)) {
2081 run_command "git checkout $start" or
2082 dodie "failed to checkout $start";
2083 }
2084
2085 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002086 do {
2087 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002088 $test = run_git_bisect "git bisect $result";
2089 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002090
2091 run_command "git bisect log" or
2092 dodie "could not capture git bisect log";
2093
2094 run_command "git bisect reset" or
2095 dodie "could not reset git bisect";
2096
2097 doprint "Bad commit was [$bisect_bad]\n";
2098
Steven Rostedt0a05c762010-11-08 11:14:10 -05002099 success $i;
2100}
2101
2102my %config_ignore;
2103my %config_set;
2104
2105my %config_list;
2106my %null_config;
2107
2108my %dependency;
2109
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002110sub assign_configs {
2111 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002112
2113 open (IN, $config)
2114 or dodie "Failed to read $config";
2115
2116 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002117 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002118 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002119 }
2120 }
2121
2122 close(IN);
2123}
2124
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002125sub process_config_ignore {
2126 my ($config) = @_;
2127
2128 assign_configs \%config_ignore, $config;
2129}
2130
Steven Rostedt0a05c762010-11-08 11:14:10 -05002131sub read_current_config {
2132 my ($config_ref) = @_;
2133
2134 %{$config_ref} = ();
2135 undef %{$config_ref};
2136
2137 my @key = keys %{$config_ref};
2138 if ($#key >= 0) {
2139 print "did not delete!\n";
2140 exit;
2141 }
2142 open (IN, "$output_config");
2143
2144 while (<IN>) {
2145 if (/^(CONFIG\S+)=(.*)/) {
2146 ${$config_ref}{$1} = $2;
2147 }
2148 }
2149 close(IN);
2150}
2151
2152sub get_dependencies {
2153 my ($config) = @_;
2154
2155 my $arr = $dependency{$config};
2156 if (!defined($arr)) {
2157 return ();
2158 }
2159
2160 my @deps = @{$arr};
2161
2162 foreach my $dep (@{$arr}) {
2163 print "ADD DEP $dep\n";
2164 @deps = (@deps, get_dependencies $dep);
2165 }
2166
2167 return @deps;
2168}
2169
2170sub create_config {
2171 my @configs = @_;
2172
2173 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2174
2175 foreach my $config (@configs) {
2176 print OUT "$config_set{$config}\n";
2177 my @deps = get_dependencies $config;
2178 foreach my $dep (@deps) {
2179 print OUT "$config_set{$dep}\n";
2180 }
2181 }
2182
2183 foreach my $config (keys %config_ignore) {
2184 print OUT "$config_ignore{$config}\n";
2185 }
2186 close(OUT);
2187
2188# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002189 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002190}
2191
2192sub compare_configs {
2193 my (%a, %b) = @_;
2194
2195 foreach my $item (keys %a) {
2196 if (!defined($b{$item})) {
2197 print "diff $item\n";
2198 return 1;
2199 }
2200 delete $b{$item};
2201 }
2202
2203 my @keys = keys %b;
2204 if ($#keys) {
2205 print "diff2 $keys[0]\n";
2206 }
2207 return -1 if ($#keys >= 0);
2208
2209 return 0;
2210}
2211
2212sub run_config_bisect_test {
2213 my ($type) = @_;
2214
2215 return run_bisect_test $type, "oldconfig";
2216}
2217
2218sub process_passed {
2219 my (%configs) = @_;
2220
2221 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2222 # Passed! All these configs are part of a good compile.
2223 # Add them to the min options.
2224 foreach my $config (keys %configs) {
2225 if (defined($config_list{$config})) {
2226 doprint " removing $config\n";
2227 $config_ignore{$config} = $config_list{$config};
2228 delete $config_list{$config};
2229 }
2230 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002231 doprint "config copied to $outputdir/config_good\n";
2232 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002233}
2234
2235sub process_failed {
2236 my ($config) = @_;
2237
2238 doprint "\n\n***************************************\n";
2239 doprint "Found bad config: $config\n";
2240 doprint "***************************************\n\n";
2241}
2242
2243sub run_config_bisect {
2244
2245 my @start_list = keys %config_list;
2246
2247 if ($#start_list < 0) {
2248 doprint "No more configs to test!!!\n";
2249 return -1;
2250 }
2251
2252 doprint "***** RUN TEST ***\n";
2253 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
2254 my $ret;
2255 my %current_config;
2256
2257 my $count = $#start_list + 1;
2258 doprint " $count configs to test\n";
2259
2260 my $half = int($#start_list / 2);
2261
2262 do {
2263 my @tophalf = @start_list[0 .. $half];
2264
2265 create_config @tophalf;
2266 read_current_config \%current_config;
2267
2268 $count = $#tophalf + 1;
2269 doprint "Testing $count configs\n";
2270 my $found = 0;
2271 # make sure we test something
2272 foreach my $config (@tophalf) {
2273 if (defined($current_config{$config})) {
2274 logit " $config\n";
2275 $found = 1;
2276 }
2277 }
2278 if (!$found) {
2279 # try the other half
2280 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002281 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05002282 create_config @tophalf;
2283 read_current_config \%current_config;
2284 foreach my $config (@tophalf) {
2285 if (defined($current_config{$config})) {
2286 logit " $config\n";
2287 $found = 1;
2288 }
2289 }
2290 if (!$found) {
2291 doprint "Failed: Can't make new config with current configs\n";
2292 foreach my $config (@start_list) {
2293 doprint " CONFIG: $config\n";
2294 }
2295 return -1;
2296 }
2297 $count = $#tophalf + 1;
2298 doprint "Testing $count configs\n";
2299 }
2300
2301 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002302 if ($bisect_manual) {
2303 $ret = answer_bisect;
2304 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002305 if ($ret) {
2306 process_passed %current_config;
2307 return 0;
2308 }
2309
2310 doprint "This config had a failure.\n";
2311 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002312 doprint "config copied to $outputdir/config_bad\n";
2313 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002314
2315 # A config exists in this group that was bad.
2316 foreach my $config (keys %config_list) {
2317 if (!defined($current_config{$config})) {
2318 doprint " removing $config\n";
2319 delete $config_list{$config};
2320 }
2321 }
2322
2323 @start_list = @tophalf;
2324
2325 if ($#start_list == 0) {
2326 process_failed $start_list[0];
2327 return 1;
2328 }
2329
2330 # remove half the configs we are looking at and see if
2331 # they are good.
2332 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002333 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002334
Steven Rostedtc960bb92011-03-08 09:22:39 -05002335 # we found a single config, try it again unless we are running manually
2336
2337 if ($bisect_manual) {
2338 process_failed $start_list[0];
2339 return 1;
2340 }
2341
Steven Rostedt0a05c762010-11-08 11:14:10 -05002342 my @tophalf = @start_list[0 .. 0];
2343
2344 $ret = run_config_bisect_test $type;
2345 if ($ret) {
2346 process_passed %current_config;
2347 return 0;
2348 }
2349
2350 process_failed $start_list[0];
2351 return 1;
2352}
2353
2354sub config_bisect {
2355 my ($i) = @_;
2356
2357 my $start_config = $opt{"CONFIG_BISECT[$i]"};
2358
2359 my $tmpconfig = "$tmpdir/use_config";
2360
Steven Rostedt30f75da2011-06-13 10:35:35 -04002361 if (defined($config_bisect_good)) {
2362 process_config_ignore $config_bisect_good;
2363 }
2364
Steven Rostedt0a05c762010-11-08 11:14:10 -05002365 # Make the file with the bad config and the min config
2366 if (defined($minconfig)) {
2367 # read the min config for things to ignore
2368 run_command "cp $minconfig $tmpconfig" or
2369 dodie "failed to copy $minconfig to $tmpconfig";
2370 } else {
2371 unlink $tmpconfig;
2372 }
2373
Steven Rostedt0a05c762010-11-08 11:14:10 -05002374 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002375 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002376 process_config_ignore $tmpconfig;
2377 }
2378
2379 # now process the start config
2380 run_command "cp $start_config $output_config" or
2381 dodie "failed to copy $start_config to $output_config";
2382
2383 # read directly what we want to check
2384 my %config_check;
2385 open (IN, $output_config)
2386 or dodie "faied to open $output_config";
2387
2388 while (<IN>) {
2389 if (/^((CONFIG\S*)=.*)/) {
2390 $config_check{$2} = $1;
2391 }
2392 }
2393 close(IN);
2394
Steven Rostedt250bae82011-07-15 22:05:59 -04002395 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002396 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002397
2398 # check to see what we lost (or gained)
2399 open (IN, $output_config)
2400 or dodie "Failed to read $start_config";
2401
2402 my %removed_configs;
2403 my %added_configs;
2404
2405 while (<IN>) {
2406 if (/^((CONFIG\S*)=.*)/) {
2407 # save off all options
2408 $config_set{$2} = $1;
2409 if (defined($config_check{$2})) {
2410 if (defined($config_ignore{$2})) {
2411 $removed_configs{$2} = $1;
2412 } else {
2413 $config_list{$2} = $1;
2414 }
2415 } elsif (!defined($config_ignore{$2})) {
2416 $added_configs{$2} = $1;
2417 $config_list{$2} = $1;
2418 }
2419 }
2420 }
2421 close(IN);
2422
2423 my @confs = keys %removed_configs;
2424 if ($#confs >= 0) {
2425 doprint "Configs overridden by default configs and removed from check:\n";
2426 foreach my $config (@confs) {
2427 doprint " $config\n";
2428 }
2429 }
2430 @confs = keys %added_configs;
2431 if ($#confs >= 0) {
2432 doprint "Configs appearing in make oldconfig and added:\n";
2433 foreach my $config (@confs) {
2434 doprint " $config\n";
2435 }
2436 }
2437
2438 my %config_test;
2439 my $once = 0;
2440
2441 # Sometimes kconfig does weird things. We must make sure
2442 # that the config we autocreate has everything we need
2443 # to test, otherwise we may miss testing configs, or
2444 # may not be able to create a new config.
2445 # Here we create a config with everything set.
2446 create_config (keys %config_list);
2447 read_current_config \%config_test;
2448 foreach my $config (keys %config_list) {
2449 if (!defined($config_test{$config})) {
2450 if (!$once) {
2451 $once = 1;
2452 doprint "Configs not produced by kconfig (will not be checked):\n";
2453 }
2454 doprint " $config\n";
2455 delete $config_list{$config};
2456 }
2457 }
2458 my $ret;
2459 do {
2460 $ret = run_config_bisect;
2461 } while (!$ret);
2462
2463 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002464
2465 success $i;
2466}
2467
Steven Rostedt27d934b2011-05-20 09:18:18 -04002468sub patchcheck_reboot {
2469 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02002470 reboot $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002471}
2472
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002473sub patchcheck {
2474 my ($i) = @_;
2475
2476 die "PATCHCHECK_START[$i] not defined\n"
2477 if (!defined($opt{"PATCHCHECK_START[$i]"}));
2478 die "PATCHCHECK_TYPE[$i] not defined\n"
2479 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
2480
2481 my $start = $opt{"PATCHCHECK_START[$i]"};
2482
2483 my $end = "HEAD";
2484 if (defined($opt{"PATCHCHECK_END[$i]"})) {
2485 $end = $opt{"PATCHCHECK_END[$i]"};
2486 }
2487
Steven Rostedta57419b2010-11-02 15:13:54 -04002488 # Get the true sha1's since we can use things like HEAD~3
2489 $start = get_sha1($start);
2490 $end = get_sha1($end);
2491
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002492 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
2493
2494 # Can't have a test without having a test to run
2495 if ($type eq "test" && !defined($run_test)) {
2496 $type = "boot";
2497 }
2498
2499 open (IN, "git log --pretty=oneline $end|") or
2500 dodie "could not get git list";
2501
2502 my @list;
2503
2504 while (<IN>) {
2505 chomp;
2506 $list[$#list+1] = $_;
2507 last if (/^$start/);
2508 }
2509 close(IN);
2510
2511 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002512 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002513 }
2514
2515 # go backwards in the list
2516 @list = reverse @list;
2517
2518 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002519 my %ignored_warnings;
2520
2521 if (defined($ignore_warnings)) {
2522 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2523 $ignored_warnings{$sha1} = 1;
2524 }
2525 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002526
2527 $in_patchcheck = 1;
2528 foreach my $item (@list) {
2529 my $sha1 = $item;
2530 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2531
2532 doprint "\nProcessing commit $item\n\n";
2533
2534 run_command "git checkout $sha1" or
2535 die "Failed to checkout $sha1";
2536
2537 # only clean on the first and last patch
2538 if ($item eq $list[0] ||
2539 $item eq $list[$#list]) {
2540 $noclean = $save_clean;
2541 } else {
2542 $noclean = 1;
2543 }
2544
2545 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002546 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002547 } else {
2548 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002549 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002550 }
2551
Steven Rostedt19902072011-06-14 20:46:25 -04002552
2553 if (!defined($ignored_warnings{$sha1})) {
2554 check_buildlog $sha1 or return 0;
2555 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002556
2557 next if ($type eq "build");
2558
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002559 my $failed = 0;
2560
Steven Rostedtddf607e2011-06-14 20:49:13 -04002561 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002562
2563 if (!$failed && $type ne "boot"){
2564 do_run_test or $failed = 1;
2565 }
2566 end_monitor;
2567 return 0 if ($failed);
2568
Steven Rostedt27d934b2011-05-20 09:18:18 -04002569 patchcheck_reboot;
2570
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002571 }
2572 $in_patchcheck = 0;
2573 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002574
2575 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002576}
2577
Steven Rostedtb9066f62011-07-15 21:25:24 -04002578my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002579my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002580my $iflevel = 0;
2581my @ifdeps;
2582
2583# prevent recursion
2584my %read_kconfigs;
2585
Steven Rostedtac6974c2011-10-04 09:40:17 -04002586sub add_dep {
2587 # $config depends on $dep
2588 my ($config, $dep) = @_;
2589
2590 if (defined($depends{$config})) {
2591 $depends{$config} .= " " . $dep;
2592 } else {
2593 $depends{$config} = $dep;
2594 }
2595
2596 # record the number of configs depending on $dep
2597 if (defined $depcount{$dep}) {
2598 $depcount{$dep}++;
2599 } else {
2600 $depcount{$dep} = 1;
2601 }
2602}
2603
Steven Rostedtb9066f62011-07-15 21:25:24 -04002604# taken from streamline_config.pl
2605sub read_kconfig {
2606 my ($kconfig) = @_;
2607
2608 my $state = "NONE";
2609 my $config;
2610 my @kconfigs;
2611
2612 my $cont = 0;
2613 my $line;
2614
2615
2616 if (! -f $kconfig) {
2617 doprint "file $kconfig does not exist, skipping\n";
2618 return;
2619 }
2620
2621 open(KIN, "$kconfig")
2622 or die "Can't open $kconfig";
2623 while (<KIN>) {
2624 chomp;
2625
2626 # Make sure that lines ending with \ continue
2627 if ($cont) {
2628 $_ = $line . " " . $_;
2629 }
2630
2631 if (s/\\$//) {
2632 $cont = 1;
2633 $line = $_;
2634 next;
2635 }
2636
2637 $cont = 0;
2638
2639 # collect any Kconfig sources
2640 if (/^source\s*"(.*)"/) {
2641 $kconfigs[$#kconfigs+1] = $1;
2642 }
2643
2644 # configs found
2645 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2646 $state = "NEW";
2647 $config = $2;
2648
2649 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002650 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002651 }
2652
2653 # collect the depends for the config
2654 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
2655
Steven Rostedtac6974c2011-10-04 09:40:17 -04002656 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002657
2658 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04002659 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
2660
2661 # selected by depends on config
2662 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002663
2664 # Check for if statements
2665 } elsif (/^if\s+(.*\S)\s*$/) {
2666 my $deps = $1;
2667 # remove beginning and ending non text
2668 $deps =~ s/^[^a-zA-Z0-9_]*//;
2669 $deps =~ s/[^a-zA-Z0-9_]*$//;
2670
2671 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
2672
2673 $ifdeps[$iflevel++] = join ':', @deps;
2674
2675 } elsif (/^endif/) {
2676
2677 $iflevel-- if ($iflevel);
2678
2679 # stop on "help"
2680 } elsif (/^\s*help\s*$/) {
2681 $state = "NONE";
2682 }
2683 }
2684 close(KIN);
2685
2686 # read in any configs that were found.
2687 foreach $kconfig (@kconfigs) {
2688 if (!defined($read_kconfigs{$kconfig})) {
2689 $read_kconfigs{$kconfig} = 1;
2690 read_kconfig("$builddir/$kconfig");
2691 }
2692 }
2693}
2694
2695sub read_depends {
2696 # find out which arch this is by the kconfig file
2697 open (IN, $output_config)
2698 or dodie "Failed to read $output_config";
2699 my $arch;
2700 while (<IN>) {
2701 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
2702 $arch = $1;
2703 last;
2704 }
2705 }
2706 close IN;
2707
2708 if (!defined($arch)) {
2709 doprint "Could not find arch from config file\n";
2710 doprint "no dependencies used\n";
2711 return;
2712 }
2713
2714 # arch is really the subarch, we need to know
2715 # what directory to look at.
2716 if ($arch eq "i386" || $arch eq "x86_64") {
2717 $arch = "x86";
2718 } elsif ($arch =~ /^tile/) {
2719 $arch = "tile";
2720 }
2721
2722 my $kconfig = "$builddir/arch/$arch/Kconfig";
2723
2724 if (! -f $kconfig && $arch =~ /\d$/) {
2725 my $orig = $arch;
2726 # some subarchs have numbers, truncate them
2727 $arch =~ s/\d*$//;
2728 $kconfig = "$builddir/arch/$arch/Kconfig";
2729 if (! -f $kconfig) {
2730 doprint "No idea what arch dir $orig is for\n";
2731 doprint "no dependencies used\n";
2732 return;
2733 }
2734 }
2735
2736 read_kconfig($kconfig);
2737}
2738
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002739sub read_config_list {
2740 my ($config) = @_;
2741
2742 open (IN, $config)
2743 or dodie "Failed to read $config";
2744
2745 while (<IN>) {
2746 if (/^((CONFIG\S*)=.*)/) {
2747 if (!defined($config_ignore{$2})) {
2748 $config_list{$2} = $1;
2749 }
2750 }
2751 }
2752
2753 close(IN);
2754}
2755
2756sub read_output_config {
2757 my ($config) = @_;
2758
2759 assign_configs \%config_ignore, $config;
2760}
2761
2762sub make_new_config {
2763 my @configs = @_;
2764
2765 open (OUT, ">$output_config")
2766 or dodie "Failed to write $output_config";
2767
2768 foreach my $config (@configs) {
2769 print OUT "$config\n";
2770 }
2771 close OUT;
2772}
2773
Steven Rostedtac6974c2011-10-04 09:40:17 -04002774sub chomp_config {
2775 my ($config) = @_;
2776
2777 $config =~ s/CONFIG_//;
2778
2779 return $config;
2780}
2781
Steven Rostedtb9066f62011-07-15 21:25:24 -04002782sub get_depends {
2783 my ($dep) = @_;
2784
Steven Rostedtac6974c2011-10-04 09:40:17 -04002785 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002786
2787 $dep = $depends{"$kconfig"};
2788
2789 # the dep string we have saves the dependencies as they
2790 # were found, including expressions like ! && ||. We
2791 # want to split this out into just an array of configs.
2792
2793 my $valid = "A-Za-z_0-9";
2794
2795 my @configs;
2796
2797 while ($dep =~ /[$valid]/) {
2798
2799 if ($dep =~ /^[^$valid]*([$valid]+)/) {
2800 my $conf = "CONFIG_" . $1;
2801
2802 $configs[$#configs + 1] = $conf;
2803
2804 $dep =~ s/^[^$valid]*[$valid]+//;
2805 } else {
2806 die "this should never happen";
2807 }
2808 }
2809
2810 return @configs;
2811}
2812
2813my %min_configs;
2814my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002815my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002816my %processed_configs;
2817my %nochange_config;
2818
2819sub test_this_config {
2820 my ($config) = @_;
2821
2822 my $found;
2823
2824 # if we already processed this config, skip it
2825 if (defined($processed_configs{$config})) {
2826 return undef;
2827 }
2828 $processed_configs{$config} = 1;
2829
2830 # if this config failed during this round, skip it
2831 if (defined($nochange_config{$config})) {
2832 return undef;
2833 }
2834
Steven Rostedtac6974c2011-10-04 09:40:17 -04002835 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002836
2837 # Test dependencies first
2838 if (defined($depends{"$kconfig"})) {
2839 my @parents = get_depends $config;
2840 foreach my $parent (@parents) {
2841 # if the parent is in the min config, check it first
2842 next if (!defined($min_configs{$parent}));
2843 $found = test_this_config($parent);
2844 if (defined($found)) {
2845 return $found;
2846 }
2847 }
2848 }
2849
2850 # Remove this config from the list of configs
2851 # do a make oldnoconfig and then read the resulting
2852 # .config to make sure it is missing the config that
2853 # we had before
2854 my %configs = %min_configs;
2855 delete $configs{$config};
2856 make_new_config ((values %configs), (values %keep_configs));
2857 make_oldconfig;
2858 undef %configs;
2859 assign_configs \%configs, $output_config;
2860
2861 return $config if (!defined($configs{$config}));
2862
2863 doprint "disabling config $config did not change .config\n";
2864
2865 $nochange_config{$config} = 1;
2866
2867 return undef;
2868}
2869
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002870sub make_min_config {
2871 my ($i) = @_;
2872
2873 if (!defined($output_minconfig)) {
2874 fail "OUTPUT_MIN_CONFIG not defined" and return;
2875 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04002876
2877 # If output_minconfig exists, and the start_minconfig
2878 # came from min_config, than ask if we should use
2879 # that instead.
2880 if (-f $output_minconfig && !$start_minconfig_defined) {
2881 print "$output_minconfig exists\n";
2882 if (read_yn " Use it as minconfig?") {
2883 $start_minconfig = $output_minconfig;
2884 }
2885 }
2886
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002887 if (!defined($start_minconfig)) {
2888 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
2889 }
2890
Steven Rostedt35ce5952011-07-15 21:57:25 -04002891 my $temp_config = "$tmpdir/temp_config";
2892
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002893 # First things first. We build an allnoconfig to find
2894 # out what the defaults are that we can't touch.
2895 # Some are selections, but we really can't handle selections.
2896
2897 my $save_minconfig = $minconfig;
2898 undef $minconfig;
2899
2900 run_command "$make allnoconfig" or return 0;
2901
Steven Rostedtb9066f62011-07-15 21:25:24 -04002902 read_depends;
2903
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002904 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002905
Steven Rostedt43d1b652011-07-15 22:01:56 -04002906 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002907 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002908
2909 if (defined($ignore_config)) {
2910 # make sure the file exists
2911 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04002912 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002913 }
2914
Steven Rostedt43d1b652011-07-15 22:01:56 -04002915 %keep_configs = %save_configs;
2916
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002917 doprint "Load initial configs from $start_minconfig\n";
2918
2919 # Look at the current min configs, and save off all the
2920 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002921 assign_configs \%min_configs, $start_minconfig;
2922
2923 my @config_keys = keys %min_configs;
2924
Steven Rostedtac6974c2011-10-04 09:40:17 -04002925 # All configs need a depcount
2926 foreach my $config (@config_keys) {
2927 my $kconfig = chomp_config $config;
2928 if (!defined $depcount{$kconfig}) {
2929 $depcount{$kconfig} = 0;
2930 }
2931 }
2932
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002933 # Remove anything that was set by the make allnoconfig
2934 # we shouldn't need them as they get set for us anyway.
2935 foreach my $config (@config_keys) {
2936 # Remove anything in the ignore_config
2937 if (defined($keep_configs{$config})) {
2938 my $file = $ignore_config;
2939 $file =~ s,.*/(.*?)$,$1,;
2940 doprint "$config set by $file ... ignored\n";
2941 delete $min_configs{$config};
2942 next;
2943 }
2944 # But make sure the settings are the same. If a min config
2945 # sets a selection, we do not want to get rid of it if
2946 # it is not the same as what we have. Just move it into
2947 # the keep configs.
2948 if (defined($config_ignore{$config})) {
2949 if ($config_ignore{$config} ne $min_configs{$config}) {
2950 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
2951 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
2952 $keep_configs{$config} = $min_configs{$config};
2953 } else {
2954 doprint "$config set by allnoconfig ... ignored\n";
2955 }
2956 delete $min_configs{$config};
2957 }
2958 }
2959
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002960 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002961 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002962
2963 while (!$done) {
2964
2965 my $config;
2966 my $found;
2967
2968 # Now disable each config one by one and do a make oldconfig
2969 # till we find a config that changes our list.
2970
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002971 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002972
2973 # Sort keys by who is most dependent on
2974 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
2975 @test_configs ;
2976
2977 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002978 my $reset = 1;
2979 for (my $i = 0; $i < $#test_configs; $i++) {
2980 if (!defined($nochange_config{$test_configs[0]})) {
2981 $reset = 0;
2982 last;
2983 }
2984 # This config didn't change the .config last time.
2985 # Place it at the end
2986 my $config = shift @test_configs;
2987 push @test_configs, $config;
2988 }
2989
2990 # if every test config has failed to modify the .config file
2991 # in the past, then reset and start over.
2992 if ($reset) {
2993 undef %nochange_config;
2994 }
2995
Steven Rostedtb9066f62011-07-15 21:25:24 -04002996 undef %processed_configs;
2997
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002998 foreach my $config (@test_configs) {
2999
Steven Rostedtb9066f62011-07-15 21:25:24 -04003000 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003001
Steven Rostedtb9066f62011-07-15 21:25:24 -04003002 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003003
3004 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003005 }
3006
3007 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003008 # we could have failed due to the nochange_config hash
3009 # reset and try again
3010 if (!$take_two) {
3011 undef %nochange_config;
3012 $take_two = 1;
3013 next;
3014 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003015 doprint "No more configs found that we can disable\n";
3016 $done = 1;
3017 last;
3018 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003019 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003020
3021 $config = $found;
3022
3023 doprint "Test with $config disabled\n";
3024
3025 # set in_bisect to keep build and monitor from dieing
3026 $in_bisect = 1;
3027
3028 my $failed = 0;
3029 build "oldconfig";
3030 start_monitor_and_boot or $failed = 1;
3031 end_monitor;
3032
3033 $in_bisect = 0;
3034
3035 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003036 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003037 # this config is needed, add it to the ignore list.
3038 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003039 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003040 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003041
3042 # update new ignore configs
3043 if (defined($ignore_config)) {
3044 open (OUT, ">$temp_config")
3045 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003046 foreach my $config (keys %save_configs) {
3047 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003048 }
3049 close OUT;
3050 run_command "mv $temp_config $ignore_config" or
3051 dodie "failed to copy update to $ignore_config";
3052 }
3053
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003054 } else {
3055 # We booted without this config, remove it from the minconfigs.
3056 doprint "$config is not needed, disabling\n";
3057
3058 delete $min_configs{$config};
3059
3060 # Also disable anything that is not enabled in this config
3061 my %configs;
3062 assign_configs \%configs, $output_config;
3063 my @config_keys = keys %min_configs;
3064 foreach my $config (@config_keys) {
3065 if (!defined($configs{$config})) {
3066 doprint "$config is not set, disabling\n";
3067 delete $min_configs{$config};
3068 }
3069 }
3070
3071 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003072 open (OUT, ">$temp_config")
3073 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003074 foreach my $config (keys %keep_configs) {
3075 print OUT "$keep_configs{$config}\n";
3076 }
3077 foreach my $config (keys %min_configs) {
3078 print OUT "$min_configs{$config}\n";
3079 }
3080 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003081
3082 run_command "mv $temp_config $output_minconfig" or
3083 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003084 }
3085
3086 doprint "Reboot and wait $sleep_time seconds\n";
Andrew Jones2728be42011-08-12 15:32:05 +02003087 reboot $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003088 }
3089
3090 success $i;
3091 return 1;
3092}
3093
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003094$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003095
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003096if ($#ARGV == 0) {
3097 $ktest_config = $ARGV[0];
3098 if (! -f $ktest_config) {
3099 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003100 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003101 exit 0;
3102 }
3103 }
3104} else {
3105 $ktest_config = "ktest.conf";
3106}
3107
3108if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003109 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003110 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003111 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3112 print OUT << "EOF"
3113# Generated by ktest.pl
3114#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003115
3116# PWD is a ktest.pl variable that will result in the process working
3117# directory that ktest.pl is executed in.
3118
3119# THIS_DIR is automatically assigned the PWD of the path that generated
3120# the config file. It is best to use this variable when assigning other
3121# directory paths within this directory. This allows you to easily
3122# move the test cases to other locations or to other machines.
3123#
3124THIS_DIR := $variable{"PWD"}
3125
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003126# Define each test with TEST_START
3127# The config options below it will override the defaults
3128TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003129TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003130
3131DEFAULTS
3132EOF
3133;
3134 close(OUT);
3135}
3136read_config $ktest_config;
3137
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003138if (defined($opt{"LOG_FILE"})) {
3139 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3140}
3141
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003142# Append any configs entered in manually to the config file.
3143my @new_configs = keys %entered_configs;
3144if ($#new_configs >= 0) {
3145 print "\nAppending entered in configs to $ktest_config\n";
3146 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3147 foreach my $config (@new_configs) {
3148 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003149 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003150 }
3151}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003152
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003153if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3154 unlink $opt{"LOG_FILE"};
3155}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003156
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003157doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3158
Steven Rostedta57419b2010-11-02 15:13:54 -04003159for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3160
3161 if (!$i) {
3162 doprint "DEFAULT OPTIONS:\n";
3163 } else {
3164 doprint "\nTEST $i OPTIONS";
3165 if (defined($repeat_tests{$i})) {
3166 $repeat = $repeat_tests{$i};
3167 doprint " ITERATE $repeat";
3168 }
3169 doprint "\n";
3170 }
3171
3172 foreach my $option (sort keys %opt) {
3173
3174 if ($option =~ /\[(\d+)\]$/) {
3175 next if ($i != $1);
3176 } else {
3177 next if ($i);
3178 }
3179
3180 doprint "$option = $opt{$option}\n";
3181 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003182}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003183
Steven Rostedt2a625122011-05-20 15:48:59 -04003184sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003185 my ($name, $i) = @_;
3186
3187 my $option = "$name\[$i\]";
3188
3189 if (defined($opt{$option})) {
3190 return $opt{$option};
3191 }
3192
Steven Rostedta57419b2010-11-02 15:13:54 -04003193 foreach my $test (keys %repeat_tests) {
3194 if ($i >= $test &&
3195 $i < $test + $repeat_tests{$test}) {
3196 $option = "$name\[$test\]";
3197 if (defined($opt{$option})) {
3198 return $opt{$option};
3199 }
3200 }
3201 }
3202
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003203 if (defined($opt{$name})) {
3204 return $opt{$name};
3205 }
3206
3207 return undef;
3208}
3209
Steven Rostedt2a625122011-05-20 15:48:59 -04003210sub set_test_option {
3211 my ($name, $i) = @_;
3212
3213 my $option = __set_test_option($name, $i);
3214 return $option if (!defined($option));
3215
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003216 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003217}
3218
Steven Rostedt2545eb62010-11-02 15:01:32 -04003219# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003220for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003221
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003222 # Do not reboot on failing test options
3223 $no_reboot = 1;
3224
Steven Rostedt576f6272010-11-02 14:58:38 -04003225 $iteration = $i;
3226
Steven Rostedta75fece2010-11-02 14:58:27 -04003227 my $makecmd = set_test_option("MAKE_CMD", $i);
3228
3229 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003230 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003231 $tmpdir = set_test_option("TMP_DIR", $i);
3232 $outputdir = set_test_option("OUTPUT_DIR", $i);
3233 $builddir = set_test_option("BUILD_DIR", $i);
3234 $test_type = set_test_option("TEST_TYPE", $i);
3235 $build_type = set_test_option("BUILD_TYPE", $i);
3236 $build_options = set_test_option("BUILD_OPTIONS", $i);
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04003237 $pre_build = set_test_option("PRE_BUILD", $i);
3238 $post_build = set_test_option("POST_BUILD", $i);
3239 $pre_build_die = set_test_option("PRE_BUILD_DIE", $i);
3240 $post_build_die = set_test_option("POST_BUILD_DIE", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003241 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003242 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003243 $noclean = set_test_option("BUILD_NOCLEAN", $i);
3244 $minconfig = set_test_option("MIN_CONFIG", $i);
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003245 $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i);
3246 $start_minconfig = set_test_option("START_MIN_CONFIG", $i);
3247 $ignore_config = set_test_option("IGNORE_CONFIG", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003248 $run_test = set_test_option("TEST", $i);
3249 $addconfig = set_test_option("ADD_CONFIG", $i);
3250 $reboot_type = set_test_option("REBOOT_TYPE", $i);
3251 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04003252 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedte0a87422011-09-30 17:50:48 -04003253 $no_install = set_test_option("NO_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003254 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
3255 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
3256 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
3257 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
3258 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04003259 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
3260 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003261 $sleep_time = set_test_option("SLEEP_TIME", $i);
3262 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04003263 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedt19902072011-06-14 20:46:25 -04003264 $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05003265 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05003266 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04003267 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003268 $store_failures = set_test_option("STORE_FAILURES", $i);
Rabin Vincentde5b6e32011-11-18 17:05:31 +05303269 $store_successes = set_test_option("STORE_SUCCESSES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04003270 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003271 $timeout = set_test_option("TIMEOUT", $i);
3272 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
3273 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04003274 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003275 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt2b803362011-09-30 18:00:23 -04003276 $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05003277 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
3278 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05003279 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003280 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04003281 $ssh_exec = set_test_option("SSH_EXEC", $i);
3282 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04003283 $target_image = set_test_option("TARGET_IMAGE", $i);
3284 $localversion = set_test_option("LOCALVERSION", $i);
3285
Steven Rostedt35ce5952011-07-15 21:57:25 -04003286 $start_minconfig_defined = 1;
3287
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003288 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003289 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003290 $start_minconfig = $minconfig;
3291 }
3292
Steven Rostedta75fece2010-11-02 14:58:27 -04003293 chdir $builddir || die "can't change directory to $builddir";
3294
Andrew Jonesa908a662011-08-12 15:32:03 +02003295 foreach my $dir ($tmpdir, $outputdir) {
3296 if (!-d $dir) {
3297 mkpath($dir) or
3298 die "can't create $dir";
3299 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003300 }
3301
Steven Rostedte48c5292010-11-02 14:35:37 -04003302 $ENV{"SSH_USER"} = $ssh_user;
3303 $ENV{"MACHINE"} = $machine;
3304
Steven Rostedta75fece2010-11-02 14:58:27 -04003305 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303306 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003307 $dmesg = "$tmpdir/dmesg-$machine";
3308 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003309 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003310
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003311 if (!$buildonly) {
3312 $target = "$ssh_user\@$machine";
3313 if ($reboot_type eq "grub") {
3314 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3315 } elsif (!defined($reboot_script)) {
3316 dodie "REBOOT_SCRIPT not defined"
3317 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003318 }
3319
3320 my $run_type = $build_type;
3321 if ($test_type eq "patchcheck") {
3322 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
3323 } elsif ($test_type eq "bisect") {
3324 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003325 } elsif ($test_type eq "config_bisect") {
3326 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04003327 }
3328
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003329 if ($test_type eq "make_min_config") {
3330 $run_type = "";
3331 }
3332
Steven Rostedta75fece2010-11-02 14:58:27 -04003333 # mistake in config file?
3334 if (!defined($run_type)) {
3335 $run_type = "ERROR";
3336 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003337
Steven Rostedte0a87422011-09-30 17:50:48 -04003338 my $installme = "";
3339 $installme = " no_install" if ($no_install);
3340
Steven Rostedt2545eb62010-11-02 15:01:32 -04003341 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003342 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003343
3344 unlink $dmesg;
3345 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303346 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003347
Steven Rostedt250bae82011-07-15 22:05:59 -04003348 if (defined($addconfig)) {
3349 my $min = $minconfig;
3350 if (!defined($minconfig)) {
3351 $min = "";
3352 }
3353 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003354 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003355 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003356 }
3357
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003358 my $checkout = $opt{"CHECKOUT[$i]"};
3359 if (defined($checkout)) {
3360 run_command "git checkout $checkout" or
3361 die "failed to checkout $checkout";
3362 }
3363
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003364 $no_reboot = 0;
3365
3366
Steven Rostedta75fece2010-11-02 14:58:27 -04003367 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003368 bisect $i;
3369 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003370 } elsif ($test_type eq "config_bisect") {
3371 config_bisect $i;
3372 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003373 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003374 patchcheck $i;
3375 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003376 } elsif ($test_type eq "make_min_config") {
3377 make_min_config $i;
3378 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003379 }
3380
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003381 if ($build_type ne "nobuild") {
3382 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003383 }
3384
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003385 if ($test_type eq "install") {
3386 get_version;
3387 install;
3388 success $i;
3389 next;
3390 }
3391
Steven Rostedta75fece2010-11-02 14:58:27 -04003392 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003393 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003394 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003395
3396 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3397 do_run_test or $failed = 1;
3398 }
3399 end_monitor;
3400 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003401 }
3402
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003403 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003404}
3405
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003406if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003407 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04003408} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003409 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003410}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003411
Steven Rostedte48c5292010-11-02 14:35:37 -04003412doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3413
Steven Rostedt2545eb62010-11-02 15:01:32 -04003414exit 0;