blob: a8e1826e0cbadb8e98772155935caa1c970d3d8d [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002#
Uwe Kleine-Königcce1dac2011-01-24 21:12:01 +01003# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04004# Licensed under the terms of the GNU GPL License version 2
5#
Steven Rostedt2545eb62010-11-02 15:01:32 -04006
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Steven Rostedt7faafbd2010-11-02 14:58:22 -040010use File::Path qw(mkpath);
11use File::Copy qw(cp);
Steven Rostedt2545eb62010-11-02 15:01:32 -040012use FileHandle;
13
Steven Rostedte48c5292010-11-02 14:35:37 -040014my $VERSION = "0.2";
15
Steven Rostedt2545eb62010-11-02 15:01:32 -040016$| = 1;
17
18my %opt;
Steven Rostedta57419b2010-11-02 15:13:54 -040019my %repeat_tests;
20my %repeats;
Steven Rostedta75fece2010-11-02 14:58:27 -040021my %default;
Steven Rostedt2545eb62010-11-02 15:01:32 -040022
23#default opts
Steven Rostedta57419b2010-11-02 15:13:54 -040024$default{"NUM_TESTS"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040025$default{"REBOOT_TYPE"} = "grub";
26$default{"TEST_TYPE"} = "test";
27$default{"BUILD_TYPE"} = "randconfig";
28$default{"MAKE_CMD"} = "make";
29$default{"TIMEOUT"} = 120;
Steven Rostedta57419b2010-11-02 15:13:54 -040030$default{"TMP_DIR"} = "/tmp/ktest";
Steven Rostedta75fece2010-11-02 14:58:27 -040031$default{"SLEEP_TIME"} = 60; # sleep time between tests
32$default{"BUILD_NOCLEAN"} = 0;
33$default{"REBOOT_ON_ERROR"} = 0;
34$default{"POWEROFF_ON_ERROR"} = 0;
35$default{"REBOOT_ON_SUCCESS"} = 1;
36$default{"POWEROFF_ON_SUCCESS"} = 0;
37$default{"BUILD_OPTIONS"} = "";
38$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects
Steven Rostedt27d934b2011-05-20 09:18:18 -040039$default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks
Steven Rostedta75fece2010-11-02 14:58:27 -040040$default{"CLEAR_LOG"} = 0;
Steven Rostedtc960bb92011-03-08 09:22:39 -050041$default{"BISECT_MANUAL"} = 0;
Steven Rostedtc23dca72011-03-08 09:26:31 -050042$default{"BISECT_SKIP"} = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -040043$default{"SUCCESS_LINE"} = "login:";
Steven Rostedtf1a5b962011-06-13 10:30:00 -040044$default{"DETECT_TRIPLE_FAULT"} = 1;
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 Rostedt8d1491b2010-11-18 15:39:48 -050053$default{"LOCALVERSION"} = "-test";
Steven Rostedt2545eb62010-11-02 15:01:32 -040054
Steven Rostedt8d1491b2010-11-18 15:39:48 -050055my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040056my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040057my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040058my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040059my $tmpdir;
60my $builddir;
61my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050062my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040063my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040064my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040065my $build_options;
66my $reboot_type;
67my $reboot_script;
68my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040069my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040070my $reboot_on_error;
71my $poweroff_on_error;
72my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040073my $powercycle_after_reboot;
74my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040075my $ssh_exec;
76my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $power_off;
78my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040079my $grub_number;
80my $target;
81my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040082my $post_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040083my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040084my $minconfig;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -040085my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040086my $in_bisect = 0;
87my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -040088my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -050089my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -050090my $bisect_skip;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -040091my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -040092my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -040093my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040094my $buildlog;
95my $dmesg;
96my $monitor_fp;
97my $monitor_pid;
98my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040099my $sleep_time;
100my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400101my $patchcheck_sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -0400102my $store_failures;
103my $timeout;
104my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400105my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400106my $console;
107my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500108my $stop_after_success;
109my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500110my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400111my $build_target;
112my $target_image;
113my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400114my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400115my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400116
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500117my %entered_configs;
118my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400119my %variable;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500120
121$config_help{"MACHINE"} = << "EOF"
122 The machine hostname that you will test.
123EOF
124 ;
125$config_help{"SSH_USER"} = << "EOF"
126 The box is expected to have ssh on normal bootup, provide the user
127 (most likely root, since you need privileged operations)
128EOF
129 ;
130$config_help{"BUILD_DIR"} = << "EOF"
131 The directory that contains the Linux source code (full path).
132EOF
133 ;
134$config_help{"OUTPUT_DIR"} = << "EOF"
135 The directory that the objects will be built (full path).
136 (can not be same as BUILD_DIR)
137EOF
138 ;
139$config_help{"BUILD_TARGET"} = << "EOF"
140 The location of the compiled file to copy to the target.
141 (relative to OUTPUT_DIR)
142EOF
143 ;
144$config_help{"TARGET_IMAGE"} = << "EOF"
145 The place to put your image on the test machine.
146EOF
147 ;
148$config_help{"POWER_CYCLE"} = << "EOF"
149 A script or command to reboot the box.
150
151 Here is a digital loggers power switch example
152 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
153
154 Here is an example to reboot a virtual box on the current host
155 with the name "Guest".
156 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
157EOF
158 ;
159$config_help{"CONSOLE"} = << "EOF"
160 The script or command that reads the console
161
162 If you use ttywatch server, something like the following would work.
163CONSOLE = nc -d localhost 3001
164
165 For a virtual machine with guest name "Guest".
166CONSOLE = virsh console Guest
167EOF
168 ;
169$config_help{"LOCALVERSION"} = << "EOF"
170 Required version ending to differentiate the test
171 from other linux builds on the system.
172EOF
173 ;
174$config_help{"REBOOT_TYPE"} = << "EOF"
175 Way to reboot the box to the test kernel.
176 Only valid options so far are "grub" and "script".
177
178 If you specify grub, it will assume grub version 1
179 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
180 and select that target to reboot to the kernel. If this is not
181 your setup, then specify "script" and have a command or script
182 specified in REBOOT_SCRIPT to boot to the target.
183
184 The entry in /boot/grub/menu.lst must be entered in manually.
185 The test will not modify that file.
186EOF
187 ;
188$config_help{"GRUB_MENU"} = << "EOF"
189 The grub title name for the test kernel to boot
190 (Only mandatory if REBOOT_TYPE = grub)
191
192 Note, ktest.pl will not update the grub menu.lst, you need to
193 manually add an option for the test. ktest.pl will search
194 the grub menu.lst for this option to find what kernel to
195 reboot into.
196
197 For example, if in the /boot/grub/menu.lst the test kernel title has:
198 title Test Kernel
199 kernel vmlinuz-test
200 GRUB_MENU = Test Kernel
201EOF
202 ;
203$config_help{"REBOOT_SCRIPT"} = << "EOF"
204 A script to reboot the target into the test kernel
205 (Only mandatory if REBOOT_TYPE = script)
206EOF
207 ;
208
209
210sub get_ktest_config {
211 my ($config) = @_;
212
213 return if (defined($opt{$config}));
214
215 if (defined($config_help{$config})) {
216 print "\n";
217 print $config_help{$config};
218 }
219
220 for (;;) {
221 print "$config = ";
222 if (defined($default{$config})) {
223 print "\[$default{$config}\] ";
224 }
225 $entered_configs{$config} = <STDIN>;
226 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
227 if ($entered_configs{$config} =~ /^\s*$/) {
228 if ($default{$config}) {
229 $entered_configs{$config} = $default{$config};
230 } else {
231 print "Your answer can not be blank\n";
232 next;
233 }
234 }
235 last;
236 }
237}
238
239sub get_ktest_configs {
240 get_ktest_config("MACHINE");
241 get_ktest_config("SSH_USER");
242 get_ktest_config("BUILD_DIR");
243 get_ktest_config("OUTPUT_DIR");
244 get_ktest_config("BUILD_TARGET");
245 get_ktest_config("TARGET_IMAGE");
246 get_ktest_config("POWER_CYCLE");
247 get_ktest_config("CONSOLE");
248 get_ktest_config("LOCALVERSION");
249
250 my $rtype = $opt{"REBOOT_TYPE"};
251
252 if (!defined($rtype)) {
253 if (!defined($opt{"GRUB_MENU"})) {
254 get_ktest_config("REBOOT_TYPE");
255 $rtype = $entered_configs{"REBOOT_TYPE"};
256 } else {
257 $rtype = "grub";
258 }
259 }
260
261 if ($rtype eq "grub") {
262 get_ktest_config("GRUB_MENU");
263 } else {
264 get_ktest_config("REBOOT_SCRIPT");
265 }
266}
267
Steven Rostedt77d942c2011-05-20 13:36:58 -0400268sub process_variables {
269 my ($value) = @_;
270 my $retval = "";
271
272 # We want to check for '\', and it is just easier
273 # to check the previous characet of '$' and not need
274 # to worry if '$' is the first character. By adding
275 # a space to $value, we can just check [^\\]\$ and
276 # it will still work.
277 $value = " $value";
278
279 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
280 my $begin = $1;
281 my $var = $2;
282 my $end = $3;
283 # append beginning of value to retval
284 $retval = "$retval$begin";
285 if (defined($variable{$var})) {
286 $retval = "$retval$variable{$var}";
287 } else {
288 # put back the origin piece.
289 $retval = "$retval\$\{$var\}";
290 }
291 $value = $end;
292 }
293 $retval = "$retval$value";
294
295 # remove the space added in the beginning
296 $retval =~ s/ //;
297
298 return "$retval"
299}
300
Steven Rostedta57419b2010-11-02 15:13:54 -0400301sub set_value {
302 my ($lvalue, $rvalue) = @_;
303
304 if (defined($opt{$lvalue})) {
305 die "Error: Option $lvalue defined more than once!\n";
306 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500307 if ($rvalue =~ /^\s*$/) {
308 delete $opt{$lvalue};
309 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400310 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500311 $opt{$lvalue} = $rvalue;
312 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400313}
314
Steven Rostedt77d942c2011-05-20 13:36:58 -0400315sub set_variable {
316 my ($lvalue, $rvalue) = @_;
317
318 if ($rvalue =~ /^\s*$/) {
319 delete $variable{$lvalue};
320 } else {
321 $rvalue = process_variables($rvalue);
322 $variable{$lvalue} = $rvalue;
323 }
324}
325
Steven Rostedt2545eb62010-11-02 15:01:32 -0400326sub read_config {
327 my ($config) = @_;
328
329 open(IN, $config) || die "can't read file $config";
330
Steven Rostedta57419b2010-11-02 15:13:54 -0400331 my $name = $config;
332 $name =~ s,.*/(.*),$1,;
333
334 my $test_num = 0;
335 my $default = 1;
336 my $repeat = 1;
337 my $num_tests_set = 0;
338 my $skip = 0;
339 my $rest;
340
Steven Rostedt2545eb62010-11-02 15:01:32 -0400341 while (<IN>) {
342
343 # ignore blank lines and comments
344 next if (/^\s*$/ || /\s*\#/);
345
Steven Rostedta57419b2010-11-02 15:13:54 -0400346 if (/^\s*TEST_START(.*)/) {
347
348 $rest = $1;
349
350 if ($num_tests_set) {
351 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
352 }
353
354 my $old_test_num = $test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400355 my $old_repeat = $repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400356
357 $test_num += $repeat;
358 $default = 0;
359 $repeat = 1;
360
361 if ($rest =~ /\s+SKIP(.*)/) {
362 $rest = $1;
363 $skip = 1;
364 } else {
365 $skip = 0;
366 }
367
368 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
369 $repeat = $1;
370 $rest = $2;
371 $repeat_tests{"$test_num"} = $repeat;
372 }
373
374 if ($rest =~ /\s+SKIP(.*)/) {
375 $rest = $1;
376 $skip = 1;
377 }
378
379 if ($rest !~ /^\s*$/) {
380 die "$name: $.: Gargbage found after TEST_START\n$_";
381 }
382
383 if ($skip) {
384 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400385 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400386 }
387
388 } elsif (/^\s*DEFAULTS(.*)$/) {
389 $default = 1;
390
391 $rest = $1;
392
393 if ($rest =~ /\s+SKIP(.*)/) {
394 $rest = $1;
395 $skip = 1;
396 } else {
397 $skip = 0;
398 }
399
400 if ($rest !~ /^\s*$/) {
401 die "$name: $.: Gargbage found after DEFAULTS\n$_";
402 }
403
404 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
405
406 next if ($skip);
407
Steven Rostedt2545eb62010-11-02 15:01:32 -0400408 my $lvalue = $1;
409 my $rvalue = $2;
410
Steven Rostedta57419b2010-11-02 15:13:54 -0400411 if (!$default &&
412 ($lvalue eq "NUM_TESTS" ||
413 $lvalue eq "LOG_FILE" ||
414 $lvalue eq "CLEAR_LOG")) {
415 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400416 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400417
418 if ($lvalue eq "NUM_TESTS") {
419 if ($test_num) {
420 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
421 }
422 if (!$default) {
423 die "$name: $.: NUM_TESTS must be set in default section\n";
424 }
425 $num_tests_set = 1;
426 }
427
428 if ($default || $lvalue =~ /\[\d+\]$/) {
429 set_value($lvalue, $rvalue);
430 } else {
431 my $val = "$lvalue\[$test_num\]";
432 set_value($val, $rvalue);
433
434 if ($repeat > 1) {
435 $repeats{$val} = $repeat;
436 }
437 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400438 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
439 next if ($skip);
440
441 my $lvalue = $1;
442 my $rvalue = $2;
443
444 # process config variables.
445 # Config variables are only active while reading the
446 # config and can be defined anywhere. They also ignore
447 # TEST_START and DEFAULTS, but are skipped if they are in
448 # on of these sections that have SKIP defined.
449 # The save variable can be
450 # defined multiple times and the new one simply overrides
451 # the prevous one.
452 set_variable($lvalue, $rvalue);
453
Steven Rostedta57419b2010-11-02 15:13:54 -0400454 } else {
455 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400456 }
457 }
458
459 close(IN);
Steven Rostedta75fece2010-11-02 14:58:27 -0400460
Steven Rostedta57419b2010-11-02 15:13:54 -0400461 if ($test_num) {
462 $test_num += $repeat - 1;
463 $opt{"NUM_TESTS"} = $test_num;
464 }
465
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500466 # make sure we have all mandatory configs
467 get_ktest_configs;
468
Steven Rostedta75fece2010-11-02 14:58:27 -0400469 # set any defaults
470
471 foreach my $default (keys %default) {
472 if (!defined($opt{$default})) {
473 $opt{$default} = $default{$default};
474 }
475 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400476}
477
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500478sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400479 if (defined($opt{"LOG_FILE"})) {
480 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
481 print OUT @_;
482 close(OUT);
483 }
484}
485
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500486sub logit {
487 if (defined($opt{"LOG_FILE"})) {
488 _logit @_;
489 } else {
490 print @_;
491 }
492}
493
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400494sub doprint {
495 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500496 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400497}
498
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400499sub run_command;
500
501sub reboot {
502 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400503 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400504 if (defined($powercycle_after_reboot)) {
505 sleep $powercycle_after_reboot;
506 run_command "$power_cycle";
507 }
508 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400509 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400510 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400511 }
512}
513
Steven Rostedt576f6272010-11-02 14:58:38 -0400514sub do_not_reboot {
515 my $i = $iteration;
516
517 return $test_type eq "build" ||
518 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
519 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
520}
521
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400522sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400523 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400524
Steven Rostedt576f6272010-11-02 14:58:38 -0400525 my $i = $iteration;
526
527 if ($reboot_on_error && !do_not_reboot) {
528
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400529 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400530 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400531
Steven Rostedta75fece2010-11-02 14:58:27 -0400532 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400533 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400534 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400535 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400536
Steven Rostedtf80802c2011-03-07 13:18:47 -0500537 if (defined($opt{"LOG_FILE"})) {
538 print " See $opt{LOG_FILE} for more info.\n";
539 }
540
Steven Rostedt576f6272010-11-02 14:58:38 -0400541 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400542}
543
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400544sub open_console {
545 my ($fp) = @_;
546
547 my $flags;
548
Steven Rostedta75fece2010-11-02 14:58:27 -0400549 my $pid = open($fp, "$console|") or
550 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400551
552 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400553 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400554 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400555 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400556
557 return $pid;
558}
559
560sub close_console {
561 my ($fp, $pid) = @_;
562
563 doprint "kill child process $pid\n";
564 kill 2, $pid;
565
566 print "closing!\n";
567 close($fp);
568}
569
570sub start_monitor {
571 if ($monitor_cnt++) {
572 return;
573 }
574 $monitor_fp = \*MONFD;
575 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400576
577 return;
578
579 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400580}
581
582sub end_monitor {
583 if (--$monitor_cnt) {
584 return;
585 }
586 close_console($monitor_fp, $monitor_pid);
587}
588
589sub wait_for_monitor {
590 my ($time) = @_;
591 my $line;
592
Steven Rostedta75fece2010-11-02 14:58:27 -0400593 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400594
595 # read the monitor and wait for the system to calm down
596 do {
597 $line = wait_for_input($monitor_fp, $time);
Steven Rostedta75fece2010-11-02 14:58:27 -0400598 print "$line" if (defined($line));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400599 } while (defined($line));
Steven Rostedta75fece2010-11-02 14:58:27 -0400600 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400601}
602
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400603sub fail {
604
Steven Rostedta75fece2010-11-02 14:58:27 -0400605 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400606 dodie @_;
607 }
608
Steven Rostedta75fece2010-11-02 14:58:27 -0400609 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400610
Steven Rostedt576f6272010-11-02 14:58:38 -0400611 my $i = $iteration;
612
Steven Rostedta75fece2010-11-02 14:58:27 -0400613 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -0400614 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400615 doprint "REBOOTING\n";
616 reboot;
617 start_monitor;
618 wait_for_monitor $sleep_time;
619 end_monitor;
620 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400621
Steven Rostedt576f6272010-11-02 14:58:38 -0400622 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
623 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt7a849cd2010-11-08 16:49:25 -0500624 doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -0400625 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
626 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400627
628 return 1 if (!defined($store_failures));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400629
630 my @t = localtime;
631 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
632 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
633
Steven Rostedtcccae1a2010-11-09 12:21:32 -0500634 my $type = $build_type;
635 if ($type =~ /useconfig/) {
636 $type = "useconfig";
637 }
638
639 my $dir = "$machine-$test_type-$type-fail-$date";
Steven Rostedta75fece2010-11-02 14:58:27 -0400640 my $faildir = "$store_failures/$dir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400641
642 if (!-d $faildir) {
643 mkpath($faildir) or
Steven Rostedta75fece2010-11-02 14:58:27 -0400644 die "can't create $faildir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400645 }
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500646 if (-f "$output_config") {
647 cp "$output_config", "$faildir/config" or
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400648 die "failed to copy .config";
649 }
650 if (-f $buildlog) {
651 cp $buildlog, "$faildir/buildlog" or
652 die "failed to move $buildlog";
653 }
654 if (-f $dmesg) {
655 cp $dmesg, "$faildir/dmesg" or
656 die "failed to move $dmesg";
657 }
658
659 doprint "*** Saved info to $faildir ***\n";
660
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400661 return 1;
662}
663
Steven Rostedt2545eb62010-11-02 15:01:32 -0400664sub run_command {
665 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400666 my $dolog = 0;
667 my $dord = 0;
668 my $pid;
669
Steven Rostedte48c5292010-11-02 14:35:37 -0400670 $command =~ s/\$SSH_USER/$ssh_user/g;
671 $command =~ s/\$MACHINE/$machine/g;
672
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400673 doprint("$command ... ");
674
675 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400676 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400677
678 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400679 open(LOG, ">>$opt{LOG_FILE}") or
680 dodie "failed to write to log";
681 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400682 }
683
684 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400685 open (RD, ">$redirect") or
686 dodie "failed to write to redirect $redirect";
687 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400688 }
689
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400690 while (<CMD>) {
691 print LOG if ($dolog);
692 print RD if ($dord);
693 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400694
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400695 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400696 my $failed = $?;
697
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400698 close(CMD);
699 close(LOG) if ($dolog);
700 close(RD) if ($dord);
701
Steven Rostedt2545eb62010-11-02 15:01:32 -0400702 if ($failed) {
703 doprint "FAILED!\n";
704 } else {
705 doprint "SUCCESS\n";
706 }
707
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400708 return !$failed;
709}
710
Steven Rostedte48c5292010-11-02 14:35:37 -0400711sub run_ssh {
712 my ($cmd) = @_;
713 my $cp_exec = $ssh_exec;
714
715 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
716 return run_command "$cp_exec";
717}
718
719sub run_scp {
720 my ($src, $dst) = @_;
721 my $cp_scp = $scp_to_target;
722
723 $cp_scp =~ s/\$SRC_FILE/$src/g;
724 $cp_scp =~ s/\$DST_FILE/$dst/g;
725
726 return run_command "$cp_scp";
727}
728
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400729sub get_grub_index {
730
Steven Rostedta75fece2010-11-02 14:58:27 -0400731 if ($reboot_type ne "grub") {
732 return;
733 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400734 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400735
736 doprint "Find grub menu ... ";
737 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -0400738
739 my $ssh_grub = $ssh_exec;
740 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
741
742 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400743 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -0400744
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400745 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400746 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400747 $grub_number++;
748 last;
749 } elsif (/^\s*title\s/) {
750 $grub_number++;
751 }
752 }
753 close(IN);
754
Steven Rostedta75fece2010-11-02 14:58:27 -0400755 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400756 if ($grub_number < 0);
757 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400758}
759
Steven Rostedt2545eb62010-11-02 15:01:32 -0400760sub wait_for_input
761{
762 my ($fp, $time) = @_;
763 my $rin;
764 my $ready;
765 my $line;
766 my $ch;
767
768 if (!defined($time)) {
769 $time = $timeout;
770 }
771
772 $rin = '';
773 vec($rin, fileno($fp), 1) = 1;
774 $ready = select($rin, undef, undef, $time);
775
776 $line = "";
777
778 # try to read one char at a time
779 while (sysread $fp, $ch, 1) {
780 $line .= $ch;
781 last if ($ch eq "\n");
782 }
783
784 if (!length($line)) {
785 return undef;
786 }
787
788 return $line;
789}
790
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400791sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -0400792 if ($reboot_type eq "grub") {
Steven Rostedt4da46da2011-06-01 23:25:13 -0400793 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
Steven Rostedta75fece2010-11-02 14:58:27 -0400794 return;
795 }
796
797 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400798}
799
Steven Rostedta57419b2010-11-02 15:13:54 -0400800sub get_sha1 {
801 my ($commit) = @_;
802
803 doprint "git rev-list --max-count=1 $commit ... ";
804 my $sha1 = `git rev-list --max-count=1 $commit`;
805 my $ret = $?;
806
807 logit $sha1;
808
809 if ($ret) {
810 doprint "FAILED\n";
811 dodie "Failed to get git $commit";
812 }
813
814 print "SUCCESS\n";
815
816 chomp $sha1;
817
818 return $sha1;
819}
820
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400821sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400822 my $booted = 0;
823 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400824 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400825 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400826
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400827 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400828
829 my $line;
830 my $full_line = "";
831
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400832 open(DMESG, "> $dmesg") or
833 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400834
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400835 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400836
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500837 my $success_start;
838 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500839 my $monitor_start = time;
840 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400841 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500842
Steven Rostedt2d01b262011-03-08 09:47:54 -0500843 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400844
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400845 if ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400846 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400847 if (!defined($line)) {
848 my $s = $booted_timeout == 1 ? "" : "s";
849 doprint "Successful boot found: break after $booted_timeout second$s\n";
850 last;
851 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400852 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400853 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400854 if (!defined($line)) {
855 my $s = $timeout == 1 ? "" : "s";
856 doprint "Timed out after $timeout second$s\n";
857 last;
858 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400859 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400860
Steven Rostedt2545eb62010-11-02 15:01:32 -0400861 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400862 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400863
864 # we are not guaranteed to get a full line
865 $full_line .= $line;
866
Steven Rostedta75fece2010-11-02 14:58:27 -0400867 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400868 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500869 $success_start = time;
870 }
871
872 if ($booted && defined($stop_after_success) &&
873 $stop_after_success >= 0) {
874 my $now = time;
875 if ($now - $success_start >= $stop_after_success) {
876 doprint "Test forced to stop after $stop_after_success seconds after success\n";
877 last;
878 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400879 }
880
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400881 if ($full_line =~ /\[ backtrace testing \]/) {
882 $skip_call_trace = 1;
883 }
884
Steven Rostedt2545eb62010-11-02 15:01:32 -0400885 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -0500886 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500887 $bug = 1;
888 $failure_start = time;
889 }
890 }
891
892 if ($bug && defined($stop_after_failure) &&
893 $stop_after_failure >= 0) {
894 my $now = time;
895 if ($now - $failure_start >= $stop_after_failure) {
896 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
897 last;
898 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400899 }
900
901 if ($full_line =~ /\[ end of backtrace testing \]/) {
902 $skip_call_trace = 0;
903 }
904
905 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -0500906 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400907 $bug = 1;
908 }
909
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400910 # Detect triple faults by testing the banner
911 if ($full_line =~ /\bLinux version (\S+).*\n/) {
912 if ($1 eq $version) {
913 $version_found = 1;
914 } elsif ($version_found && $detect_triplefault) {
915 # We already booted into the kernel we are testing,
916 # but now we booted into another kernel?
917 # Consider this a triple fault.
918 doprint "Aleady booted in Linux kernel $version, but now\n";
919 doprint "we booted into Linux kernel $1.\n";
920 doprint "Assuming that this is a triple fault.\n";
921 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
922 last;
923 }
924 }
925
Steven Rostedt2545eb62010-11-02 15:01:32 -0400926 if ($line =~ /\n/) {
927 $full_line = "";
928 }
Steven Rostedt2d01b262011-03-08 09:47:54 -0500929
930 if ($stop_test_after > 0 && !$booted && !$bug) {
931 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -0400932 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -0500933 $done = 1;
934 }
935 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400936 }
937
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400938 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400939
Steven Rostedt2545eb62010-11-02 15:01:32 -0400940 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400941 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400942 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400943 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400944
Steven Rostedta75fece2010-11-02 14:58:27 -0400945 if (!$booted) {
946 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400947 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400948 }
949
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400950 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400951}
952
953sub install {
954
Steven Rostedte48c5292010-11-02 14:35:37 -0400955 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400956 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400957
958 my $install_mods = 0;
959
960 # should we process modules?
961 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500962 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400963 while (<IN>) {
964 if (/CONFIG_MODULES(=y)?/) {
965 $install_mods = 1 if (defined($1));
966 last;
967 }
968 }
969 close(IN);
970
971 if (!$install_mods) {
972 doprint "No modules needed\n";
973 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400974 }
975
Steven Rostedta75fece2010-11-02 14:58:27 -0400976 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400977 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400978
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400979 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -0400980 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400981
Steven Rostedte48c5292010-11-02 14:35:37 -0400982 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400983 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400984
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400985 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -0400986 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400987 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400988
Steven Rostedte48c5292010-11-02 14:35:37 -0400989 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400990 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400991
Steven Rostedta75fece2010-11-02 14:58:27 -0400992 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400993
Steven Rostedte48c5292010-11-02 14:35:37 -0400994 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400995 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400996
Steven Rostedte48c5292010-11-02 14:35:37 -0400997 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400998
999 return if (!defined($post_install));
1000
Steven Rostedte48c5292010-11-02 14:35:37 -04001001 my $cp_post_install = $post_install;
Steven Rostedtca6a21f2011-03-25 22:42:53 -04001002 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
Steven Rostedte48c5292010-11-02 14:35:37 -04001003 run_command "$cp_post_install" or
Steven Rostedt576f6272010-11-02 14:58:38 -04001004 dodie "Failed to run post install";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001005}
1006
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001007sub check_buildlog {
1008 my ($patch) = @_;
1009
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001010 my @files = `git show $patch | diffstat -l`;
1011
1012 open(IN, "git show $patch |") or
1013 dodie "failed to show $patch";
1014 while (<IN>) {
1015 if (m,^--- a/(.*),) {
1016 chomp $1;
1017 $files[$#files] = $1;
1018 }
1019 }
1020 close(IN);
1021
1022 open(IN, $buildlog) or dodie "Can't open $buildlog";
1023 while (<IN>) {
1024 if (/^\s*(.*?):.*(warning|error)/) {
1025 my $err = $1;
1026 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001027 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001028 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001029 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001030 }
1031 }
1032 }
1033 }
1034 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001035
1036 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001037}
1038
Steven Rostedt612b9e92011-03-07 13:27:43 -05001039sub make_oldconfig {
1040 my ($defconfig) = @_;
1041
1042 if (!run_command "$defconfig $make oldnoconfig") {
1043 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1044 # try a yes '' | oldconfig
1045 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1046 run_command "yes '' | $defconfig $make oldconfig" or
1047 dodie "failed make config oldconfig";
1048 }
1049}
1050
Steven Rostedt2545eb62010-11-02 15:01:32 -04001051sub build {
1052 my ($type) = @_;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001053 my $defconfig = "";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001054
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001055 unlink $buildlog;
1056
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001057 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001058 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001059 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001060
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001061 $type = "oldconfig";
1062 }
1063
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001064 # old config can ask questions
1065 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001066 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001067
1068 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001069 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001070
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001071 run_command "mv $output_config $outputdir/config_temp" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001072 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001073
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001074 if (!$noclean && !run_command "$make mrproper") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001075 dodie "make mrproper";
1076 }
1077
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001078 run_command "mv $outputdir/config_temp $output_config" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001079 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001080
1081 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001082 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001083 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001084 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001085 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001086
1087 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001088 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1089 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001090 close(OUT);
1091
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001092 if (defined($minconfig)) {
1093 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001094 }
1095
Steven Rostedt612b9e92011-03-07 13:27:43 -05001096 if ($type eq "oldnoconfig") {
1097 make_oldconfig $defconfig;
1098 } else {
1099 run_command "$defconfig $make $type" or
1100 dodie "failed make config";
1101 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001102
Steven Rostedta75fece2010-11-02 14:58:27 -04001103 $redirect = "$buildlog";
1104 if (!run_command "$make $build_options") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001105 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001106 # bisect may need this to pass
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001107 return 0 if ($in_bisect);
1108 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001109 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001110 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001111
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001112 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001113}
1114
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001115sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001116 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001117 if (defined($poweroff_after_halt)) {
1118 sleep $poweroff_after_halt;
1119 run_command "$power_off";
1120 }
1121 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001122 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001123 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001124 }
1125}
1126
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001127sub success {
1128 my ($i) = @_;
1129
Steven Rostedte48c5292010-11-02 14:35:37 -04001130 $successes++;
1131
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001132 doprint "\n\n*******************************************\n";
1133 doprint "*******************************************\n";
Steven Rostedt7a849cd2010-11-08 16:49:25 -05001134 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001135 doprint "*******************************************\n";
1136 doprint "*******************************************\n";
1137
Steven Rostedt576f6272010-11-02 14:58:38 -04001138 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001139 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001140 reboot;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001141 start_monitor;
Steven Rostedta75fece2010-11-02 14:58:27 -04001142 wait_for_monitor $sleep_time;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001143 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001144 }
1145}
1146
1147sub get_version {
1148 # get the release name
1149 doprint "$make kernelrelease ... ";
1150 $version = `$make kernelrelease | tail -1`;
1151 chomp($version);
1152 doprint "$version\n";
1153}
1154
Steven Rostedtc960bb92011-03-08 09:22:39 -05001155sub answer_bisect {
1156 for (;;) {
1157 doprint "Pass or fail? [p/f]";
1158 my $ans = <STDIN>;
1159 chomp $ans;
1160 if ($ans eq "p" || $ans eq "P") {
1161 return 1;
1162 } elsif ($ans eq "f" || $ans eq "F") {
1163 return 0;
1164 } else {
1165 print "Please answer 'P' or 'F'\n";
1166 }
1167 }
1168}
1169
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001170sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001171 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001172
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001173 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001174 $reboot_on_error = 0;
1175 $poweroff_on_error = 0;
1176 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001177
1178 run_command $run_test or $failed = 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001179 exit $failed;
1180}
1181
1182my $child_done;
1183
1184sub child_finished {
1185 $child_done = 1;
1186}
1187
1188sub do_run_test {
1189 my $child_pid;
1190 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001191 my $line;
1192 my $full_line;
1193 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001194
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001195 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001196
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001197 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001198
1199 $child_done = 0;
1200
1201 $SIG{CHLD} = qw(child_finished);
1202
1203 $child_pid = fork;
1204
1205 child_run_test if (!$child_pid);
1206
1207 $full_line = "";
1208
1209 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001210 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001211 if (defined($line)) {
1212
1213 # we are not guaranteed to get a full line
1214 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001215 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001216
1217 if ($full_line =~ /call trace:/i) {
1218 $bug = 1;
1219 }
1220
1221 if ($full_line =~ /Kernel panic -/) {
1222 $bug = 1;
1223 }
1224
1225 if ($line =~ /\n/) {
1226 $full_line = "";
1227 }
1228 }
1229 } while (!$child_done && !$bug);
1230
1231 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001232 my $failure_start = time;
1233 my $now;
1234 do {
1235 $line = wait_for_input($monitor_fp, 1);
1236 if (defined($line)) {
1237 doprint $line;
1238 }
1239 $now = time;
1240 if ($now - $failure_start >= $stop_after_failure) {
1241 last;
1242 }
1243 } while (defined($line));
1244
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001245 doprint "Detected kernel crash!\n";
1246 # kill the child with extreme prejudice
1247 kill 9, $child_pid;
1248 }
1249
1250 waitpid $child_pid, 0;
1251 $child_exit = $?;
1252
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001253 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001254 return 0 if $in_bisect;
1255 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001256 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001257 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001258}
1259
Steven Rostedta75fece2010-11-02 14:58:27 -04001260sub run_git_bisect {
1261 my ($command) = @_;
1262
1263 doprint "$command ... ";
1264
1265 my $output = `$command 2>&1`;
1266 my $ret = $?;
1267
1268 logit $output;
1269
1270 if ($ret) {
1271 doprint "FAILED\n";
1272 dodie "Failed to git bisect";
1273 }
1274
1275 doprint "SUCCESS\n";
1276 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1277 doprint "$1 [$2]\n";
1278 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1279 $bisect_bad = $1;
1280 doprint "Found bad commit... $1\n";
1281 return 0;
1282 } else {
1283 # we already logged it, just print it now.
1284 print $output;
1285 }
1286
1287 return 1;
1288}
1289
Steven Rostedtc23dca72011-03-08 09:26:31 -05001290sub bisect_reboot {
1291 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1292 reboot;
1293 start_monitor;
1294 wait_for_monitor $bisect_sleep_time;
1295 end_monitor;
1296}
1297
1298# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001299sub run_bisect_test {
1300 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001301
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001302 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001303 my $result;
1304 my $output;
1305 my $ret;
1306
Steven Rostedt0a05c762010-11-08 11:14:10 -05001307 $in_bisect = 1;
1308
1309 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001310
1311 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001312 if ($failed && $bisect_skip) {
1313 $in_bisect = 0;
1314 return -1;
1315 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001316 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001317
1318 # Now boot the box
1319 get_grub_index;
1320 get_version;
1321 install;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001322
1323 start_monitor;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001324 monitor or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001325
1326 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001327 if ($failed && $bisect_skip) {
1328 end_monitor;
1329 bisect_reboot;
1330 $in_bisect = 0;
1331 return -1;
1332 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001333 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001334
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001335 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001336 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001337 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001338 }
1339
1340 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001341 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001342 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001343 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001344 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001345
1346 # reboot the box to a kernel we can ssh to
1347 if ($type ne "build") {
1348 bisect_reboot;
1349 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001350 $in_bisect = 0;
1351
1352 return $result;
1353}
1354
1355sub run_bisect {
1356 my ($type) = @_;
1357 my $buildtype = "oldconfig";
1358
1359 # We should have a minconfig to use?
1360 if (defined($minconfig)) {
1361 $buildtype = "useconfig:$minconfig";
1362 }
1363
1364 my $ret = run_bisect_test $type, $buildtype;
1365
Steven Rostedtc960bb92011-03-08 09:22:39 -05001366 if ($bisect_manual) {
1367 $ret = answer_bisect;
1368 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001369
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001370 # Are we looking for where it worked, not failed?
1371 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001372 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001373 }
1374
Steven Rostedtc23dca72011-03-08 09:26:31 -05001375 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001376 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001377 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001378 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001379 } elsif ($bisect_skip) {
1380 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1381 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001382 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001383}
1384
1385sub bisect {
1386 my ($i) = @_;
1387
1388 my $result;
1389
1390 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1391 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1392 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1393
1394 my $good = $opt{"BISECT_GOOD[$i]"};
1395 my $bad = $opt{"BISECT_BAD[$i]"};
1396 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001397 my $start = $opt{"BISECT_START[$i]"};
1398 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001399 my $start_files = $opt{"BISECT_FILES[$i]"};
1400
1401 if (defined($start_files)) {
1402 $start_files = " -- " . $start_files;
1403 } else {
1404 $start_files = "";
1405 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001406
Steven Rostedta57419b2010-11-02 15:13:54 -04001407 # convert to true sha1's
1408 $good = get_sha1($good);
1409 $bad = get_sha1($bad);
1410
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001411 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1412 $opt{"BISECT_REVERSE[$i]"} == 1) {
1413 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1414 $reverse_bisect = 1;
1415 } else {
1416 $reverse_bisect = 0;
1417 }
1418
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001419 # Can't have a test without having a test to run
1420 if ($type eq "test" && !defined($run_test)) {
1421 $type = "boot";
1422 }
1423
Steven Rostedta75fece2010-11-02 14:58:27 -04001424 my $check = $opt{"BISECT_CHECK[$i]"};
1425 if (defined($check) && $check ne "0") {
1426
1427 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001428 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001429
1430 if ($check ne "good") {
1431 doprint "TESTING BISECT BAD [$bad]\n";
1432 run_command "git checkout $bad" or
1433 die "Failed to checkout $bad";
1434
1435 $result = run_bisect $type;
1436
1437 if ($result ne "bad") {
1438 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1439 }
1440 }
1441
1442 if ($check ne "bad") {
1443 doprint "TESTING BISECT GOOD [$good]\n";
1444 run_command "git checkout $good" or
1445 die "Failed to checkout $good";
1446
1447 $result = run_bisect $type;
1448
1449 if ($result ne "good") {
1450 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1451 }
1452 }
1453
1454 # checkout where we started
1455 run_command "git checkout $head" or
1456 die "Failed to checkout $head";
1457 }
1458
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001459 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001460 dodie "could not start bisect";
1461
1462 run_command "git bisect good $good" or
1463 dodie "could not set bisect good to $good";
1464
1465 run_git_bisect "git bisect bad $bad" or
1466 dodie "could not set bisect bad to $bad";
1467
1468 if (defined($replay)) {
1469 run_command "git bisect replay $replay" or
1470 dodie "failed to run replay";
1471 }
1472
1473 if (defined($start)) {
1474 run_command "git checkout $start" or
1475 dodie "failed to checkout $start";
1476 }
1477
1478 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001479 do {
1480 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001481 $test = run_git_bisect "git bisect $result";
1482 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001483
1484 run_command "git bisect log" or
1485 dodie "could not capture git bisect log";
1486
1487 run_command "git bisect reset" or
1488 dodie "could not reset git bisect";
1489
1490 doprint "Bad commit was [$bisect_bad]\n";
1491
Steven Rostedt0a05c762010-11-08 11:14:10 -05001492 success $i;
1493}
1494
1495my %config_ignore;
1496my %config_set;
1497
1498my %config_list;
1499my %null_config;
1500
1501my %dependency;
1502
1503sub process_config_ignore {
1504 my ($config) = @_;
1505
1506 open (IN, $config)
1507 or dodie "Failed to read $config";
1508
1509 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04001510 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001511 $config_ignore{$2} = $1;
1512 }
1513 }
1514
1515 close(IN);
1516}
1517
1518sub read_current_config {
1519 my ($config_ref) = @_;
1520
1521 %{$config_ref} = ();
1522 undef %{$config_ref};
1523
1524 my @key = keys %{$config_ref};
1525 if ($#key >= 0) {
1526 print "did not delete!\n";
1527 exit;
1528 }
1529 open (IN, "$output_config");
1530
1531 while (<IN>) {
1532 if (/^(CONFIG\S+)=(.*)/) {
1533 ${$config_ref}{$1} = $2;
1534 }
1535 }
1536 close(IN);
1537}
1538
1539sub get_dependencies {
1540 my ($config) = @_;
1541
1542 my $arr = $dependency{$config};
1543 if (!defined($arr)) {
1544 return ();
1545 }
1546
1547 my @deps = @{$arr};
1548
1549 foreach my $dep (@{$arr}) {
1550 print "ADD DEP $dep\n";
1551 @deps = (@deps, get_dependencies $dep);
1552 }
1553
1554 return @deps;
1555}
1556
1557sub create_config {
1558 my @configs = @_;
1559
1560 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1561
1562 foreach my $config (@configs) {
1563 print OUT "$config_set{$config}\n";
1564 my @deps = get_dependencies $config;
1565 foreach my $dep (@deps) {
1566 print OUT "$config_set{$dep}\n";
1567 }
1568 }
1569
1570 foreach my $config (keys %config_ignore) {
1571 print OUT "$config_ignore{$config}\n";
1572 }
1573 close(OUT);
1574
1575# exit;
Steven Rostedt612b9e92011-03-07 13:27:43 -05001576 make_oldconfig "";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001577}
1578
1579sub compare_configs {
1580 my (%a, %b) = @_;
1581
1582 foreach my $item (keys %a) {
1583 if (!defined($b{$item})) {
1584 print "diff $item\n";
1585 return 1;
1586 }
1587 delete $b{$item};
1588 }
1589
1590 my @keys = keys %b;
1591 if ($#keys) {
1592 print "diff2 $keys[0]\n";
1593 }
1594 return -1 if ($#keys >= 0);
1595
1596 return 0;
1597}
1598
1599sub run_config_bisect_test {
1600 my ($type) = @_;
1601
1602 return run_bisect_test $type, "oldconfig";
1603}
1604
1605sub process_passed {
1606 my (%configs) = @_;
1607
1608 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1609 # Passed! All these configs are part of a good compile.
1610 # Add them to the min options.
1611 foreach my $config (keys %configs) {
1612 if (defined($config_list{$config})) {
1613 doprint " removing $config\n";
1614 $config_ignore{$config} = $config_list{$config};
1615 delete $config_list{$config};
1616 }
1617 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05001618 doprint "config copied to $outputdir/config_good\n";
1619 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001620}
1621
1622sub process_failed {
1623 my ($config) = @_;
1624
1625 doprint "\n\n***************************************\n";
1626 doprint "Found bad config: $config\n";
1627 doprint "***************************************\n\n";
1628}
1629
1630sub run_config_bisect {
1631
1632 my @start_list = keys %config_list;
1633
1634 if ($#start_list < 0) {
1635 doprint "No more configs to test!!!\n";
1636 return -1;
1637 }
1638
1639 doprint "***** RUN TEST ***\n";
1640 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1641 my $ret;
1642 my %current_config;
1643
1644 my $count = $#start_list + 1;
1645 doprint " $count configs to test\n";
1646
1647 my $half = int($#start_list / 2);
1648
1649 do {
1650 my @tophalf = @start_list[0 .. $half];
1651
1652 create_config @tophalf;
1653 read_current_config \%current_config;
1654
1655 $count = $#tophalf + 1;
1656 doprint "Testing $count configs\n";
1657 my $found = 0;
1658 # make sure we test something
1659 foreach my $config (@tophalf) {
1660 if (defined($current_config{$config})) {
1661 logit " $config\n";
1662 $found = 1;
1663 }
1664 }
1665 if (!$found) {
1666 # try the other half
1667 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001668 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05001669 create_config @tophalf;
1670 read_current_config \%current_config;
1671 foreach my $config (@tophalf) {
1672 if (defined($current_config{$config})) {
1673 logit " $config\n";
1674 $found = 1;
1675 }
1676 }
1677 if (!$found) {
1678 doprint "Failed: Can't make new config with current configs\n";
1679 foreach my $config (@start_list) {
1680 doprint " CONFIG: $config\n";
1681 }
1682 return -1;
1683 }
1684 $count = $#tophalf + 1;
1685 doprint "Testing $count configs\n";
1686 }
1687
1688 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05001689 if ($bisect_manual) {
1690 $ret = answer_bisect;
1691 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001692 if ($ret) {
1693 process_passed %current_config;
1694 return 0;
1695 }
1696
1697 doprint "This config had a failure.\n";
1698 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05001699 doprint "config copied to $outputdir/config_bad\n";
1700 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001701
1702 # A config exists in this group that was bad.
1703 foreach my $config (keys %config_list) {
1704 if (!defined($current_config{$config})) {
1705 doprint " removing $config\n";
1706 delete $config_list{$config};
1707 }
1708 }
1709
1710 @start_list = @tophalf;
1711
1712 if ($#start_list == 0) {
1713 process_failed $start_list[0];
1714 return 1;
1715 }
1716
1717 # remove half the configs we are looking at and see if
1718 # they are good.
1719 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001720 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05001721
Steven Rostedtc960bb92011-03-08 09:22:39 -05001722 # we found a single config, try it again unless we are running manually
1723
1724 if ($bisect_manual) {
1725 process_failed $start_list[0];
1726 return 1;
1727 }
1728
Steven Rostedt0a05c762010-11-08 11:14:10 -05001729 my @tophalf = @start_list[0 .. 0];
1730
1731 $ret = run_config_bisect_test $type;
1732 if ($ret) {
1733 process_passed %current_config;
1734 return 0;
1735 }
1736
1737 process_failed $start_list[0];
1738 return 1;
1739}
1740
1741sub config_bisect {
1742 my ($i) = @_;
1743
1744 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1745
1746 my $tmpconfig = "$tmpdir/use_config";
1747
1748 # Make the file with the bad config and the min config
1749 if (defined($minconfig)) {
1750 # read the min config for things to ignore
1751 run_command "cp $minconfig $tmpconfig" or
1752 dodie "failed to copy $minconfig to $tmpconfig";
1753 } else {
1754 unlink $tmpconfig;
1755 }
1756
1757 # Add other configs
1758 if (defined($addconfig)) {
1759 run_command "cat $addconfig >> $tmpconfig" or
1760 dodie "failed to append $addconfig";
1761 }
1762
1763 my $defconfig = "";
1764 if (-f $tmpconfig) {
1765 $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
1766 process_config_ignore $tmpconfig;
1767 }
1768
1769 # now process the start config
1770 run_command "cp $start_config $output_config" or
1771 dodie "failed to copy $start_config to $output_config";
1772
1773 # read directly what we want to check
1774 my %config_check;
1775 open (IN, $output_config)
1776 or dodie "faied to open $output_config";
1777
1778 while (<IN>) {
1779 if (/^((CONFIG\S*)=.*)/) {
1780 $config_check{$2} = $1;
1781 }
1782 }
1783 close(IN);
1784
1785 # Now run oldconfig with the minconfig (and addconfigs)
Steven Rostedt612b9e92011-03-07 13:27:43 -05001786 make_oldconfig $defconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001787
1788 # check to see what we lost (or gained)
1789 open (IN, $output_config)
1790 or dodie "Failed to read $start_config";
1791
1792 my %removed_configs;
1793 my %added_configs;
1794
1795 while (<IN>) {
1796 if (/^((CONFIG\S*)=.*)/) {
1797 # save off all options
1798 $config_set{$2} = $1;
1799 if (defined($config_check{$2})) {
1800 if (defined($config_ignore{$2})) {
1801 $removed_configs{$2} = $1;
1802 } else {
1803 $config_list{$2} = $1;
1804 }
1805 } elsif (!defined($config_ignore{$2})) {
1806 $added_configs{$2} = $1;
1807 $config_list{$2} = $1;
1808 }
1809 }
1810 }
1811 close(IN);
1812
1813 my @confs = keys %removed_configs;
1814 if ($#confs >= 0) {
1815 doprint "Configs overridden by default configs and removed from check:\n";
1816 foreach my $config (@confs) {
1817 doprint " $config\n";
1818 }
1819 }
1820 @confs = keys %added_configs;
1821 if ($#confs >= 0) {
1822 doprint "Configs appearing in make oldconfig and added:\n";
1823 foreach my $config (@confs) {
1824 doprint " $config\n";
1825 }
1826 }
1827
1828 my %config_test;
1829 my $once = 0;
1830
1831 # Sometimes kconfig does weird things. We must make sure
1832 # that the config we autocreate has everything we need
1833 # to test, otherwise we may miss testing configs, or
1834 # may not be able to create a new config.
1835 # Here we create a config with everything set.
1836 create_config (keys %config_list);
1837 read_current_config \%config_test;
1838 foreach my $config (keys %config_list) {
1839 if (!defined($config_test{$config})) {
1840 if (!$once) {
1841 $once = 1;
1842 doprint "Configs not produced by kconfig (will not be checked):\n";
1843 }
1844 doprint " $config\n";
1845 delete $config_list{$config};
1846 }
1847 }
1848 my $ret;
1849 do {
1850 $ret = run_config_bisect;
1851 } while (!$ret);
1852
1853 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001854
1855 success $i;
1856}
1857
Steven Rostedt27d934b2011-05-20 09:18:18 -04001858sub patchcheck_reboot {
1859 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
1860 reboot;
1861 start_monitor;
1862 wait_for_monitor $patchcheck_sleep_time;
1863 end_monitor;
1864}
1865
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001866sub patchcheck {
1867 my ($i) = @_;
1868
1869 die "PATCHCHECK_START[$i] not defined\n"
1870 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1871 die "PATCHCHECK_TYPE[$i] not defined\n"
1872 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1873
1874 my $start = $opt{"PATCHCHECK_START[$i]"};
1875
1876 my $end = "HEAD";
1877 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1878 $end = $opt{"PATCHCHECK_END[$i]"};
1879 }
1880
Steven Rostedta57419b2010-11-02 15:13:54 -04001881 # Get the true sha1's since we can use things like HEAD~3
1882 $start = get_sha1($start);
1883 $end = get_sha1($end);
1884
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001885 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1886
1887 # Can't have a test without having a test to run
1888 if ($type eq "test" && !defined($run_test)) {
1889 $type = "boot";
1890 }
1891
1892 open (IN, "git log --pretty=oneline $end|") or
1893 dodie "could not get git list";
1894
1895 my @list;
1896
1897 while (<IN>) {
1898 chomp;
1899 $list[$#list+1] = $_;
1900 last if (/^$start/);
1901 }
1902 close(IN);
1903
1904 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001905 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001906 }
1907
1908 # go backwards in the list
1909 @list = reverse @list;
1910
1911 my $save_clean = $noclean;
1912
1913 $in_patchcheck = 1;
1914 foreach my $item (@list) {
1915 my $sha1 = $item;
1916 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1917
1918 doprint "\nProcessing commit $item\n\n";
1919
1920 run_command "git checkout $sha1" or
1921 die "Failed to checkout $sha1";
1922
1923 # only clean on the first and last patch
1924 if ($item eq $list[0] ||
1925 $item eq $list[$#list]) {
1926 $noclean = $save_clean;
1927 } else {
1928 $noclean = 1;
1929 }
1930
1931 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001932 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001933 } else {
1934 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001935 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001936 }
1937
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001938 check_buildlog $sha1 or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001939
1940 next if ($type eq "build");
1941
1942 get_grub_index;
1943 get_version;
1944 install;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001945
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001946 my $failed = 0;
1947
1948 start_monitor;
1949 monitor or $failed = 1;
1950
1951 if (!$failed && $type ne "boot"){
1952 do_run_test or $failed = 1;
1953 }
1954 end_monitor;
1955 return 0 if ($failed);
1956
Steven Rostedt27d934b2011-05-20 09:18:18 -04001957 patchcheck_reboot;
1958
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001959 }
1960 $in_patchcheck = 0;
1961 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001962
1963 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001964}
1965
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001966$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001967
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001968if ($#ARGV == 0) {
1969 $ktest_config = $ARGV[0];
1970 if (! -f $ktest_config) {
1971 print "$ktest_config does not exist.\n";
1972 my $ans;
1973 for (;;) {
1974 print "Create it? [Y/n] ";
1975 $ans = <STDIN>;
1976 chomp $ans;
1977 if ($ans =~ /^\s*$/) {
1978 $ans = "y";
1979 }
1980 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
1981 print "Please answer either 'y' or 'n'.\n";
1982 }
1983 if ($ans !~ /^y$/i) {
1984 exit 0;
1985 }
1986 }
1987} else {
1988 $ktest_config = "ktest.conf";
1989}
1990
1991if (! -f $ktest_config) {
1992 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
1993 print OUT << "EOF"
1994# Generated by ktest.pl
1995#
1996# Define each test with TEST_START
1997# The config options below it will override the defaults
1998TEST_START
1999
2000DEFAULTS
2001EOF
2002;
2003 close(OUT);
2004}
2005read_config $ktest_config;
2006
2007# Append any configs entered in manually to the config file.
2008my @new_configs = keys %entered_configs;
2009if ($#new_configs >= 0) {
2010 print "\nAppending entered in configs to $ktest_config\n";
2011 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2012 foreach my $config (@new_configs) {
2013 print OUT "$config = $entered_configs{$config}\n";
2014 $opt{$config} = $entered_configs{$config};
2015 }
2016}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002017
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002018if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2019 unlink $opt{"LOG_FILE"};
2020}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002021
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002022doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2023
Steven Rostedta57419b2010-11-02 15:13:54 -04002024for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2025
2026 if (!$i) {
2027 doprint "DEFAULT OPTIONS:\n";
2028 } else {
2029 doprint "\nTEST $i OPTIONS";
2030 if (defined($repeat_tests{$i})) {
2031 $repeat = $repeat_tests{$i};
2032 doprint " ITERATE $repeat";
2033 }
2034 doprint "\n";
2035 }
2036
2037 foreach my $option (sort keys %opt) {
2038
2039 if ($option =~ /\[(\d+)\]$/) {
2040 next if ($i != $1);
2041 } else {
2042 next if ($i);
2043 }
2044
2045 doprint "$option = $opt{$option}\n";
2046 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002047}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002048
Steven Rostedt2a625122011-05-20 15:48:59 -04002049sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002050 my ($name, $i) = @_;
2051
2052 my $option = "$name\[$i\]";
2053
2054 if (defined($opt{$option})) {
2055 return $opt{$option};
2056 }
2057
Steven Rostedta57419b2010-11-02 15:13:54 -04002058 foreach my $test (keys %repeat_tests) {
2059 if ($i >= $test &&
2060 $i < $test + $repeat_tests{$test}) {
2061 $option = "$name\[$test\]";
2062 if (defined($opt{$option})) {
2063 return $opt{$option};
2064 }
2065 }
2066 }
2067
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002068 if (defined($opt{$name})) {
2069 return $opt{$name};
2070 }
2071
2072 return undef;
2073}
2074
Steven Rostedt2a625122011-05-20 15:48:59 -04002075sub eval_option {
2076 my ($option, $i) = @_;
2077
2078 # Add space to evaluate the character before $
2079 $option = " $option";
2080 my $retval = "";
2081
2082 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
2083 my $start = $1;
2084 my $var = $2;
2085 my $end = $3;
2086
2087 # Append beginning of line
2088 $retval = "$retval$start";
2089
2090 # If the iteration option OPT[$i] exists, then use that.
2091 # otherwise see if the default OPT (without [$i]) exists.
2092
2093 my $o = "$var\[$i\]";
2094
2095 if (defined($opt{$o})) {
2096 $o = $opt{$o};
2097 $retval = "$retval$o";
2098 } elsif (defined($opt{$var})) {
2099 $o = $opt{$var};
2100 $retval = "$retval$o";
2101 } else {
2102 $retval = "$retval\$\{$var\}";
2103 }
2104
2105 $option = $end;
2106 }
2107
2108 $retval = "$retval$option";
2109
2110 $retval =~ s/^ //;
2111
2112 return $retval;
2113}
2114
2115sub set_test_option {
2116 my ($name, $i) = @_;
2117
2118 my $option = __set_test_option($name, $i);
2119 return $option if (!defined($option));
2120
2121 my $prev = "";
2122
2123 # Since an option can evaluate to another option,
2124 # keep iterating until we do not evaluate any more
2125 # options.
2126 my $r = 0;
2127 while ($prev ne $option) {
2128 # Check for recursive evaluations.
2129 # 100 deep should be more than enough.
2130 if ($r++ > 100) {
2131 die "Over 100 evaluations accurred with $name\n" .
2132 "Check for recursive variables\n";
2133 }
2134 $prev = $option;
2135 $option = eval_option($option, $i);
2136 }
2137
2138 return $option;
2139}
2140
Steven Rostedt2545eb62010-11-02 15:01:32 -04002141# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04002142for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04002143
Steven Rostedt576f6272010-11-02 14:58:38 -04002144 $iteration = $i;
2145
Steven Rostedta75fece2010-11-02 14:58:27 -04002146 my $makecmd = set_test_option("MAKE_CMD", $i);
2147
2148 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002149 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002150 $tmpdir = set_test_option("TMP_DIR", $i);
2151 $outputdir = set_test_option("OUTPUT_DIR", $i);
2152 $builddir = set_test_option("BUILD_DIR", $i);
2153 $test_type = set_test_option("TEST_TYPE", $i);
2154 $build_type = set_test_option("BUILD_TYPE", $i);
2155 $build_options = set_test_option("BUILD_OPTIONS", $i);
2156 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002157 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002158 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2159 $minconfig = set_test_option("MIN_CONFIG", $i);
2160 $run_test = set_test_option("TEST", $i);
2161 $addconfig = set_test_option("ADD_CONFIG", $i);
2162 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2163 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002164 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002165 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2166 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2167 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2168 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2169 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04002170 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2171 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002172 $sleep_time = set_test_option("SLEEP_TIME", $i);
2173 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04002174 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05002175 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05002176 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002177 $store_failures = set_test_option("STORE_FAILURES", $i);
2178 $timeout = set_test_option("TIMEOUT", $i);
2179 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2180 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04002181 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002182 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002183 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2184 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05002185 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002186 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002187 $ssh_exec = set_test_option("SSH_EXEC", $i);
2188 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002189 $target_image = set_test_option("TARGET_IMAGE", $i);
2190 $localversion = set_test_option("LOCALVERSION", $i);
2191
2192 chdir $builddir || die "can't change directory to $builddir";
2193
2194 if (!-d $tmpdir) {
2195 mkpath($tmpdir) or
2196 die "can't create $tmpdir";
2197 }
2198
Steven Rostedte48c5292010-11-02 14:35:37 -04002199 $ENV{"SSH_USER"} = $ssh_user;
2200 $ENV{"MACHINE"} = $machine;
2201
Steven Rostedta75fece2010-11-02 14:58:27 -04002202 $target = "$ssh_user\@$machine";
2203
2204 $buildlog = "$tmpdir/buildlog-$machine";
2205 $dmesg = "$tmpdir/dmesg-$machine";
2206 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002207 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04002208
2209 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04002210 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04002211 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002212 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04002213 }
2214
2215 my $run_type = $build_type;
2216 if ($test_type eq "patchcheck") {
2217 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2218 } elsif ($test_type eq "bisect") {
2219 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002220 } elsif ($test_type eq "config_bisect") {
2221 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04002222 }
2223
2224 # mistake in config file?
2225 if (!defined($run_type)) {
2226 $run_type = "ERROR";
2227 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002228
2229 doprint "\n\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04002230 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002231
2232 unlink $dmesg;
2233 unlink $buildlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002234
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002235 if (!defined($minconfig)) {
2236 $minconfig = $addconfig;
2237
2238 } elsif (defined($addconfig)) {
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002239 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002240 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002241 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002242 }
2243
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002244 my $checkout = $opt{"CHECKOUT[$i]"};
2245 if (defined($checkout)) {
2246 run_command "git checkout $checkout" or
2247 die "failed to checkout $checkout";
2248 }
2249
Steven Rostedta75fece2010-11-02 14:58:27 -04002250 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002251 bisect $i;
2252 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002253 } elsif ($test_type eq "config_bisect") {
2254 config_bisect $i;
2255 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04002256 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002257 patchcheck $i;
2258 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002259 }
2260
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002261 if ($build_type ne "nobuild") {
2262 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002263 }
2264
Steven Rostedta75fece2010-11-02 14:58:27 -04002265 if ($test_type ne "build") {
2266 get_grub_index;
2267 get_version;
2268 install;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002269
Steven Rostedta75fece2010-11-02 14:58:27 -04002270 my $failed = 0;
2271 start_monitor;
2272 monitor or $failed = 1;;
2273
2274 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2275 do_run_test or $failed = 1;
2276 }
2277 end_monitor;
2278 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002279 }
2280
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002281 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002282}
2283
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002284if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002285 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04002286} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002287 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002288}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002289
Steven Rostedte48c5292010-11-02 14:35:37 -04002290doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
2291
Steven Rostedt2545eb62010-11-02 15:01:32 -04002292exit 0;