blob: aa442a9075db966973e79e1de4c15a11a97ae426 [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 Rostedt30f75da2011-06-13 10:35:35 -040091my $config_bisect_good;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -040092my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -040093my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -040094my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040095my $buildlog;
96my $dmesg;
97my $monitor_fp;
98my $monitor_pid;
99my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400100my $sleep_time;
101my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400102my $patchcheck_sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -0400103my $store_failures;
Steven Rostedt9064af52011-06-13 10:38:48 -0400104my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400105my $timeout;
106my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400107my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400108my $console;
109my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500110my $stop_after_success;
111my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500112my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400113my $build_target;
114my $target_image;
115my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400116my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400117my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400118
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500119my %entered_configs;
120my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400121my %variable;
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400122my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500123
124$config_help{"MACHINE"} = << "EOF"
125 The machine hostname that you will test.
126EOF
127 ;
128$config_help{"SSH_USER"} = << "EOF"
129 The box is expected to have ssh on normal bootup, provide the user
130 (most likely root, since you need privileged operations)
131EOF
132 ;
133$config_help{"BUILD_DIR"} = << "EOF"
134 The directory that contains the Linux source code (full path).
135EOF
136 ;
137$config_help{"OUTPUT_DIR"} = << "EOF"
138 The directory that the objects will be built (full path).
139 (can not be same as BUILD_DIR)
140EOF
141 ;
142$config_help{"BUILD_TARGET"} = << "EOF"
143 The location of the compiled file to copy to the target.
144 (relative to OUTPUT_DIR)
145EOF
146 ;
147$config_help{"TARGET_IMAGE"} = << "EOF"
148 The place to put your image on the test machine.
149EOF
150 ;
151$config_help{"POWER_CYCLE"} = << "EOF"
152 A script or command to reboot the box.
153
154 Here is a digital loggers power switch example
155 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
156
157 Here is an example to reboot a virtual box on the current host
158 with the name "Guest".
159 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
160EOF
161 ;
162$config_help{"CONSOLE"} = << "EOF"
163 The script or command that reads the console
164
165 If you use ttywatch server, something like the following would work.
166CONSOLE = nc -d localhost 3001
167
168 For a virtual machine with guest name "Guest".
169CONSOLE = virsh console Guest
170EOF
171 ;
172$config_help{"LOCALVERSION"} = << "EOF"
173 Required version ending to differentiate the test
174 from other linux builds on the system.
175EOF
176 ;
177$config_help{"REBOOT_TYPE"} = << "EOF"
178 Way to reboot the box to the test kernel.
179 Only valid options so far are "grub" and "script".
180
181 If you specify grub, it will assume grub version 1
182 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
183 and select that target to reboot to the kernel. If this is not
184 your setup, then specify "script" and have a command or script
185 specified in REBOOT_SCRIPT to boot to the target.
186
187 The entry in /boot/grub/menu.lst must be entered in manually.
188 The test will not modify that file.
189EOF
190 ;
191$config_help{"GRUB_MENU"} = << "EOF"
192 The grub title name for the test kernel to boot
193 (Only mandatory if REBOOT_TYPE = grub)
194
195 Note, ktest.pl will not update the grub menu.lst, you need to
196 manually add an option for the test. ktest.pl will search
197 the grub menu.lst for this option to find what kernel to
198 reboot into.
199
200 For example, if in the /boot/grub/menu.lst the test kernel title has:
201 title Test Kernel
202 kernel vmlinuz-test
203 GRUB_MENU = Test Kernel
204EOF
205 ;
206$config_help{"REBOOT_SCRIPT"} = << "EOF"
207 A script to reboot the target into the test kernel
208 (Only mandatory if REBOOT_TYPE = script)
209EOF
210 ;
211
212
213sub get_ktest_config {
214 my ($config) = @_;
215
216 return if (defined($opt{$config}));
217
218 if (defined($config_help{$config})) {
219 print "\n";
220 print $config_help{$config};
221 }
222
223 for (;;) {
224 print "$config = ";
225 if (defined($default{$config})) {
226 print "\[$default{$config}\] ";
227 }
228 $entered_configs{$config} = <STDIN>;
229 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
230 if ($entered_configs{$config} =~ /^\s*$/) {
231 if ($default{$config}) {
232 $entered_configs{$config} = $default{$config};
233 } else {
234 print "Your answer can not be blank\n";
235 next;
236 }
237 }
238 last;
239 }
240}
241
242sub get_ktest_configs {
243 get_ktest_config("MACHINE");
244 get_ktest_config("SSH_USER");
245 get_ktest_config("BUILD_DIR");
246 get_ktest_config("OUTPUT_DIR");
247 get_ktest_config("BUILD_TARGET");
248 get_ktest_config("TARGET_IMAGE");
249 get_ktest_config("POWER_CYCLE");
250 get_ktest_config("CONSOLE");
251 get_ktest_config("LOCALVERSION");
252
253 my $rtype = $opt{"REBOOT_TYPE"};
254
255 if (!defined($rtype)) {
256 if (!defined($opt{"GRUB_MENU"})) {
257 get_ktest_config("REBOOT_TYPE");
258 $rtype = $entered_configs{"REBOOT_TYPE"};
259 } else {
260 $rtype = "grub";
261 }
262 }
263
264 if ($rtype eq "grub") {
265 get_ktest_config("GRUB_MENU");
266 } else {
267 get_ktest_config("REBOOT_SCRIPT");
268 }
269}
270
Steven Rostedt77d942c2011-05-20 13:36:58 -0400271sub process_variables {
272 my ($value) = @_;
273 my $retval = "";
274
275 # We want to check for '\', and it is just easier
276 # to check the previous characet of '$' and not need
277 # to worry if '$' is the first character. By adding
278 # a space to $value, we can just check [^\\]\$ and
279 # it will still work.
280 $value = " $value";
281
282 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
283 my $begin = $1;
284 my $var = $2;
285 my $end = $3;
286 # append beginning of value to retval
287 $retval = "$retval$begin";
288 if (defined($variable{$var})) {
289 $retval = "$retval$variable{$var}";
290 } else {
291 # put back the origin piece.
292 $retval = "$retval\$\{$var\}";
293 }
294 $value = $end;
295 }
296 $retval = "$retval$value";
297
298 # remove the space added in the beginning
299 $retval =~ s/ //;
300
301 return "$retval"
302}
303
Steven Rostedta57419b2010-11-02 15:13:54 -0400304sub set_value {
305 my ($lvalue, $rvalue) = @_;
306
307 if (defined($opt{$lvalue})) {
308 die "Error: Option $lvalue defined more than once!\n";
309 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500310 if ($rvalue =~ /^\s*$/) {
311 delete $opt{$lvalue};
312 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400313 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500314 $opt{$lvalue} = $rvalue;
315 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400316}
317
Steven Rostedt77d942c2011-05-20 13:36:58 -0400318sub set_variable {
319 my ($lvalue, $rvalue) = @_;
320
321 if ($rvalue =~ /^\s*$/) {
322 delete $variable{$lvalue};
323 } else {
324 $rvalue = process_variables($rvalue);
325 $variable{$lvalue} = $rvalue;
326 }
327}
328
Steven Rostedt2545eb62010-11-02 15:01:32 -0400329sub read_config {
330 my ($config) = @_;
331
332 open(IN, $config) || die "can't read file $config";
333
Steven Rostedta57419b2010-11-02 15:13:54 -0400334 my $name = $config;
335 $name =~ s,.*/(.*),$1,;
336
337 my $test_num = 0;
338 my $default = 1;
339 my $repeat = 1;
340 my $num_tests_set = 0;
341 my $skip = 0;
342 my $rest;
343
Steven Rostedt2545eb62010-11-02 15:01:32 -0400344 while (<IN>) {
345
346 # ignore blank lines and comments
347 next if (/^\s*$/ || /\s*\#/);
348
Steven Rostedta57419b2010-11-02 15:13:54 -0400349 if (/^\s*TEST_START(.*)/) {
350
351 $rest = $1;
352
353 if ($num_tests_set) {
354 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
355 }
356
357 my $old_test_num = $test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400358 my $old_repeat = $repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400359
360 $test_num += $repeat;
361 $default = 0;
362 $repeat = 1;
363
364 if ($rest =~ /\s+SKIP(.*)/) {
365 $rest = $1;
366 $skip = 1;
367 } else {
368 $skip = 0;
369 }
370
371 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
372 $repeat = $1;
373 $rest = $2;
374 $repeat_tests{"$test_num"} = $repeat;
375 }
376
377 if ($rest =~ /\s+SKIP(.*)/) {
378 $rest = $1;
379 $skip = 1;
380 }
381
382 if ($rest !~ /^\s*$/) {
383 die "$name: $.: Gargbage found after TEST_START\n$_";
384 }
385
386 if ($skip) {
387 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400388 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400389 }
390
391 } elsif (/^\s*DEFAULTS(.*)$/) {
392 $default = 1;
393
394 $rest = $1;
395
396 if ($rest =~ /\s+SKIP(.*)/) {
397 $rest = $1;
398 $skip = 1;
399 } else {
400 $skip = 0;
401 }
402
403 if ($rest !~ /^\s*$/) {
404 die "$name: $.: Gargbage found after DEFAULTS\n$_";
405 }
406
407 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
408
409 next if ($skip);
410
Steven Rostedt2545eb62010-11-02 15:01:32 -0400411 my $lvalue = $1;
412 my $rvalue = $2;
413
Steven Rostedta57419b2010-11-02 15:13:54 -0400414 if (!$default &&
415 ($lvalue eq "NUM_TESTS" ||
416 $lvalue eq "LOG_FILE" ||
417 $lvalue eq "CLEAR_LOG")) {
418 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400419 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400420
421 if ($lvalue eq "NUM_TESTS") {
422 if ($test_num) {
423 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
424 }
425 if (!$default) {
426 die "$name: $.: NUM_TESTS must be set in default section\n";
427 }
428 $num_tests_set = 1;
429 }
430
431 if ($default || $lvalue =~ /\[\d+\]$/) {
432 set_value($lvalue, $rvalue);
433 } else {
434 my $val = "$lvalue\[$test_num\]";
435 set_value($val, $rvalue);
436
437 if ($repeat > 1) {
438 $repeats{$val} = $repeat;
439 }
440 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400441 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
442 next if ($skip);
443
444 my $lvalue = $1;
445 my $rvalue = $2;
446
447 # process config variables.
448 # Config variables are only active while reading the
449 # config and can be defined anywhere. They also ignore
450 # TEST_START and DEFAULTS, but are skipped if they are in
451 # on of these sections that have SKIP defined.
452 # The save variable can be
453 # defined multiple times and the new one simply overrides
454 # the prevous one.
455 set_variable($lvalue, $rvalue);
456
Steven Rostedta57419b2010-11-02 15:13:54 -0400457 } else {
458 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400459 }
460 }
461
462 close(IN);
Steven Rostedta75fece2010-11-02 14:58:27 -0400463
Steven Rostedta57419b2010-11-02 15:13:54 -0400464 if ($test_num) {
465 $test_num += $repeat - 1;
466 $opt{"NUM_TESTS"} = $test_num;
467 }
468
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500469 # make sure we have all mandatory configs
470 get_ktest_configs;
471
Steven Rostedta75fece2010-11-02 14:58:27 -0400472 # set any defaults
473
474 foreach my $default (keys %default) {
475 if (!defined($opt{$default})) {
476 $opt{$default} = $default{$default};
477 }
478 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400479}
480
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500481sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400482 if (defined($opt{"LOG_FILE"})) {
483 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
484 print OUT @_;
485 close(OUT);
486 }
487}
488
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500489sub logit {
490 if (defined($opt{"LOG_FILE"})) {
491 _logit @_;
492 } else {
493 print @_;
494 }
495}
496
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400497sub doprint {
498 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500499 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400500}
501
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400502sub run_command;
503
504sub reboot {
505 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400506 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400507 if (defined($powercycle_after_reboot)) {
508 sleep $powercycle_after_reboot;
509 run_command "$power_cycle";
510 }
511 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400512 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400513 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400514 }
515}
516
Steven Rostedt576f6272010-11-02 14:58:38 -0400517sub do_not_reboot {
518 my $i = $iteration;
519
520 return $test_type eq "build" ||
521 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
522 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
523}
524
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400525sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400526 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400527
Steven Rostedt576f6272010-11-02 14:58:38 -0400528 my $i = $iteration;
529
530 if ($reboot_on_error && !do_not_reboot) {
531
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400532 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400533 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400534
Steven Rostedta75fece2010-11-02 14:58:27 -0400535 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400536 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400537 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400538 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400539
Steven Rostedtf80802c2011-03-07 13:18:47 -0500540 if (defined($opt{"LOG_FILE"})) {
541 print " See $opt{LOG_FILE} for more info.\n";
542 }
543
Steven Rostedt576f6272010-11-02 14:58:38 -0400544 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400545}
546
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400547sub open_console {
548 my ($fp) = @_;
549
550 my $flags;
551
Steven Rostedta75fece2010-11-02 14:58:27 -0400552 my $pid = open($fp, "$console|") or
553 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400554
555 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400556 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400557 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400558 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400559
560 return $pid;
561}
562
563sub close_console {
564 my ($fp, $pid) = @_;
565
566 doprint "kill child process $pid\n";
567 kill 2, $pid;
568
569 print "closing!\n";
570 close($fp);
571}
572
573sub start_monitor {
574 if ($monitor_cnt++) {
575 return;
576 }
577 $monitor_fp = \*MONFD;
578 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400579
580 return;
581
582 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400583}
584
585sub end_monitor {
586 if (--$monitor_cnt) {
587 return;
588 }
589 close_console($monitor_fp, $monitor_pid);
590}
591
592sub wait_for_monitor {
593 my ($time) = @_;
594 my $line;
595
Steven Rostedta75fece2010-11-02 14:58:27 -0400596 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400597
598 # read the monitor and wait for the system to calm down
599 do {
600 $line = wait_for_input($monitor_fp, $time);
Steven Rostedta75fece2010-11-02 14:58:27 -0400601 print "$line" if (defined($line));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400602 } while (defined($line));
Steven Rostedta75fece2010-11-02 14:58:27 -0400603 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400604}
605
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400606sub fail {
607
Steven Rostedta75fece2010-11-02 14:58:27 -0400608 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400609 dodie @_;
610 }
611
Steven Rostedta75fece2010-11-02 14:58:27 -0400612 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400613
Steven Rostedt576f6272010-11-02 14:58:38 -0400614 my $i = $iteration;
615
Steven Rostedta75fece2010-11-02 14:58:27 -0400616 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -0400617 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400618 doprint "REBOOTING\n";
619 reboot;
620 start_monitor;
621 wait_for_monitor $sleep_time;
622 end_monitor;
623 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400624
Steven Rostedt9064af52011-06-13 10:38:48 -0400625 my $name = "";
626
627 if (defined($test_name)) {
628 $name = " ($test_name)";
629 }
630
Steven Rostedt576f6272010-11-02 14:58:38 -0400631 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
632 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -0400633 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -0400634 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
635 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400636
637 return 1 if (!defined($store_failures));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400638
639 my @t = localtime;
640 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
641 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
642
Steven Rostedtcccae1a2010-11-09 12:21:32 -0500643 my $type = $build_type;
644 if ($type =~ /useconfig/) {
645 $type = "useconfig";
646 }
647
648 my $dir = "$machine-$test_type-$type-fail-$date";
Steven Rostedta75fece2010-11-02 14:58:27 -0400649 my $faildir = "$store_failures/$dir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400650
651 if (!-d $faildir) {
652 mkpath($faildir) or
Steven Rostedta75fece2010-11-02 14:58:27 -0400653 die "can't create $faildir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400654 }
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500655 if (-f "$output_config") {
656 cp "$output_config", "$faildir/config" or
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400657 die "failed to copy .config";
658 }
659 if (-f $buildlog) {
660 cp $buildlog, "$faildir/buildlog" or
661 die "failed to move $buildlog";
662 }
663 if (-f $dmesg) {
664 cp $dmesg, "$faildir/dmesg" or
665 die "failed to move $dmesg";
666 }
667
668 doprint "*** Saved info to $faildir ***\n";
669
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400670 return 1;
671}
672
Steven Rostedt2545eb62010-11-02 15:01:32 -0400673sub run_command {
674 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400675 my $dolog = 0;
676 my $dord = 0;
677 my $pid;
678
Steven Rostedte48c5292010-11-02 14:35:37 -0400679 $command =~ s/\$SSH_USER/$ssh_user/g;
680 $command =~ s/\$MACHINE/$machine/g;
681
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400682 doprint("$command ... ");
683
684 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400685 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400686
687 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400688 open(LOG, ">>$opt{LOG_FILE}") or
689 dodie "failed to write to log";
690 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400691 }
692
693 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400694 open (RD, ">$redirect") or
695 dodie "failed to write to redirect $redirect";
696 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400697 }
698
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400699 while (<CMD>) {
700 print LOG if ($dolog);
701 print RD if ($dord);
702 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400703
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400704 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400705 my $failed = $?;
706
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400707 close(CMD);
708 close(LOG) if ($dolog);
709 close(RD) if ($dord);
710
Steven Rostedt2545eb62010-11-02 15:01:32 -0400711 if ($failed) {
712 doprint "FAILED!\n";
713 } else {
714 doprint "SUCCESS\n";
715 }
716
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400717 return !$failed;
718}
719
Steven Rostedte48c5292010-11-02 14:35:37 -0400720sub run_ssh {
721 my ($cmd) = @_;
722 my $cp_exec = $ssh_exec;
723
724 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
725 return run_command "$cp_exec";
726}
727
728sub run_scp {
729 my ($src, $dst) = @_;
730 my $cp_scp = $scp_to_target;
731
732 $cp_scp =~ s/\$SRC_FILE/$src/g;
733 $cp_scp =~ s/\$DST_FILE/$dst/g;
734
735 return run_command "$cp_scp";
736}
737
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400738sub get_grub_index {
739
Steven Rostedta75fece2010-11-02 14:58:27 -0400740 if ($reboot_type ne "grub") {
741 return;
742 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400743 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400744
745 doprint "Find grub menu ... ";
746 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -0400747
748 my $ssh_grub = $ssh_exec;
749 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
750
751 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400752 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -0400753
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400754 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400755 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400756 $grub_number++;
757 last;
758 } elsif (/^\s*title\s/) {
759 $grub_number++;
760 }
761 }
762 close(IN);
763
Steven Rostedta75fece2010-11-02 14:58:27 -0400764 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400765 if ($grub_number < 0);
766 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400767}
768
Steven Rostedt2545eb62010-11-02 15:01:32 -0400769sub wait_for_input
770{
771 my ($fp, $time) = @_;
772 my $rin;
773 my $ready;
774 my $line;
775 my $ch;
776
777 if (!defined($time)) {
778 $time = $timeout;
779 }
780
781 $rin = '';
782 vec($rin, fileno($fp), 1) = 1;
783 $ready = select($rin, undef, undef, $time);
784
785 $line = "";
786
787 # try to read one char at a time
788 while (sysread $fp, $ch, 1) {
789 $line .= $ch;
790 last if ($ch eq "\n");
791 }
792
793 if (!length($line)) {
794 return undef;
795 }
796
797 return $line;
798}
799
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400800sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -0400801 if ($reboot_type eq "grub") {
Steven Rostedt4da46da2011-06-01 23:25:13 -0400802 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
Steven Rostedta75fece2010-11-02 14:58:27 -0400803 return;
804 }
805
806 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400807}
808
Steven Rostedta57419b2010-11-02 15:13:54 -0400809sub get_sha1 {
810 my ($commit) = @_;
811
812 doprint "git rev-list --max-count=1 $commit ... ";
813 my $sha1 = `git rev-list --max-count=1 $commit`;
814 my $ret = $?;
815
816 logit $sha1;
817
818 if ($ret) {
819 doprint "FAILED\n";
820 dodie "Failed to get git $commit";
821 }
822
823 print "SUCCESS\n";
824
825 chomp $sha1;
826
827 return $sha1;
828}
829
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400830sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400831 my $booted = 0;
832 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400833 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400834 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400835
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400836 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400837
838 my $line;
839 my $full_line = "";
840
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400841 open(DMESG, "> $dmesg") or
842 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400843
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400844 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400845
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500846 my $success_start;
847 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500848 my $monitor_start = time;
849 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400850 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500851
Steven Rostedt2d01b262011-03-08 09:47:54 -0500852 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400853
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400854 if ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400855 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400856 if (!defined($line)) {
857 my $s = $booted_timeout == 1 ? "" : "s";
858 doprint "Successful boot found: break after $booted_timeout second$s\n";
859 last;
860 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400861 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400862 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400863 if (!defined($line)) {
864 my $s = $timeout == 1 ? "" : "s";
865 doprint "Timed out after $timeout second$s\n";
866 last;
867 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400868 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400869
Steven Rostedt2545eb62010-11-02 15:01:32 -0400870 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400871 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400872
873 # we are not guaranteed to get a full line
874 $full_line .= $line;
875
Steven Rostedta75fece2010-11-02 14:58:27 -0400876 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400877 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500878 $success_start = time;
879 }
880
881 if ($booted && defined($stop_after_success) &&
882 $stop_after_success >= 0) {
883 my $now = time;
884 if ($now - $success_start >= $stop_after_success) {
885 doprint "Test forced to stop after $stop_after_success seconds after success\n";
886 last;
887 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400888 }
889
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400890 if ($full_line =~ /\[ backtrace testing \]/) {
891 $skip_call_trace = 1;
892 }
893
Steven Rostedt2545eb62010-11-02 15:01:32 -0400894 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -0500895 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500896 $bug = 1;
897 $failure_start = time;
898 }
899 }
900
901 if ($bug && defined($stop_after_failure) &&
902 $stop_after_failure >= 0) {
903 my $now = time;
904 if ($now - $failure_start >= $stop_after_failure) {
905 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
906 last;
907 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400908 }
909
910 if ($full_line =~ /\[ end of backtrace testing \]/) {
911 $skip_call_trace = 0;
912 }
913
914 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -0500915 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400916 $bug = 1;
917 }
918
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400919 # Detect triple faults by testing the banner
920 if ($full_line =~ /\bLinux version (\S+).*\n/) {
921 if ($1 eq $version) {
922 $version_found = 1;
923 } elsif ($version_found && $detect_triplefault) {
924 # We already booted into the kernel we are testing,
925 # but now we booted into another kernel?
926 # Consider this a triple fault.
927 doprint "Aleady booted in Linux kernel $version, but now\n";
928 doprint "we booted into Linux kernel $1.\n";
929 doprint "Assuming that this is a triple fault.\n";
930 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
931 last;
932 }
933 }
934
Steven Rostedt2545eb62010-11-02 15:01:32 -0400935 if ($line =~ /\n/) {
936 $full_line = "";
937 }
Steven Rostedt2d01b262011-03-08 09:47:54 -0500938
939 if ($stop_test_after > 0 && !$booted && !$bug) {
940 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -0400941 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -0500942 $done = 1;
943 }
944 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400945 }
946
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400947 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400948
Steven Rostedt2545eb62010-11-02 15:01:32 -0400949 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400950 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400951 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400952 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400953
Steven Rostedta75fece2010-11-02 14:58:27 -0400954 if (!$booted) {
955 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400956 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400957 }
958
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400959 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400960}
961
962sub install {
963
Steven Rostedte48c5292010-11-02 14:35:37 -0400964 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400965 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400966
967 my $install_mods = 0;
968
969 # should we process modules?
970 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500971 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400972 while (<IN>) {
973 if (/CONFIG_MODULES(=y)?/) {
974 $install_mods = 1 if (defined($1));
975 last;
976 }
977 }
978 close(IN);
979
980 if (!$install_mods) {
981 doprint "No modules needed\n";
982 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400983 }
984
Steven Rostedta75fece2010-11-02 14:58:27 -0400985 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400986 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400987
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400988 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -0400989 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400990
Steven Rostedte48c5292010-11-02 14:35:37 -0400991 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400992 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400993
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400994 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -0400995 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400996 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400997
Steven Rostedte48c5292010-11-02 14:35:37 -0400998 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400999 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001000
Steven Rostedta75fece2010-11-02 14:58:27 -04001001 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001002
Steven Rostedte48c5292010-11-02 14:35:37 -04001003 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001004 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001005
Steven Rostedte48c5292010-11-02 14:35:37 -04001006 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001007
1008 return if (!defined($post_install));
1009
Steven Rostedte48c5292010-11-02 14:35:37 -04001010 my $cp_post_install = $post_install;
Steven Rostedtca6a21f2011-03-25 22:42:53 -04001011 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
Steven Rostedte48c5292010-11-02 14:35:37 -04001012 run_command "$cp_post_install" or
Steven Rostedt576f6272010-11-02 14:58:38 -04001013 dodie "Failed to run post install";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001014}
1015
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001016sub check_buildlog {
1017 my ($patch) = @_;
1018
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001019 my @files = `git show $patch | diffstat -l`;
1020
1021 open(IN, "git show $patch |") or
1022 dodie "failed to show $patch";
1023 while (<IN>) {
1024 if (m,^--- a/(.*),) {
1025 chomp $1;
1026 $files[$#files] = $1;
1027 }
1028 }
1029 close(IN);
1030
1031 open(IN, $buildlog) or dodie "Can't open $buildlog";
1032 while (<IN>) {
1033 if (/^\s*(.*?):.*(warning|error)/) {
1034 my $err = $1;
1035 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001036 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001037 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001038 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001039 }
1040 }
1041 }
1042 }
1043 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001044
1045 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001046}
1047
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001048sub apply_min_config {
1049 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001050
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001051 # Read the config file and remove anything that
1052 # is in the force_config hash (from minconfig and others)
1053 # then add the force config back.
1054
1055 doprint "Applying minimum configurations into $output_config.new\n";
1056
1057 open (OUT, ">$outconfig") or
1058 dodie "Can't create $outconfig";
1059
1060 if (-f $output_config) {
1061 open (IN, $output_config) or
1062 dodie "Failed to open $output_config";
1063 while (<IN>) {
1064 if (/^(# )?(CONFIG_[^\s=]*)/) {
1065 next if (defined($force_config{$2}));
1066 }
1067 print OUT;
1068 }
1069 close IN;
1070 }
1071 foreach my $config (keys %force_config) {
1072 print OUT "$force_config{$config}\n";
1073 }
1074 close OUT;
1075
1076 run_command "mv $outconfig $output_config";
1077}
1078
1079sub make_oldconfig {
1080
1081 apply_min_config;
1082
1083 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001084 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1085 # try a yes '' | oldconfig
1086 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001087 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001088 dodie "failed make config oldconfig";
1089 }
1090}
1091
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001092# read a config file and use this to force new configs.
1093sub load_force_config {
1094 my ($config) = @_;
1095
1096 open(IN, $config) or
1097 dodie "failed to read $config";
1098 while (<IN>) {
1099 chomp;
1100 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1101 $force_config{$1} = $_;
1102 } elsif (/^# (CONFIG_\S*) is not set/) {
1103 $force_config{$1} = $_;
1104 }
1105 }
1106 close IN;
1107}
1108
Steven Rostedt2545eb62010-11-02 15:01:32 -04001109sub build {
1110 my ($type) = @_;
1111
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001112 unlink $buildlog;
1113
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001114 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001115 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001116 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001117
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001118 $type = "oldconfig";
1119 }
1120
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001121 # old config can ask questions
1122 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001123 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001124
1125 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001126 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001127
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001128 run_command "mv $output_config $outputdir/config_temp" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001129 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001130
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001131 if (!$noclean && !run_command "$make mrproper") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001132 dodie "make mrproper";
1133 }
1134
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001135 run_command "mv $outputdir/config_temp $output_config" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001136 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001137
1138 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001139 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001140 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001141 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001142 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001143
1144 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001145 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1146 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001147 close(OUT);
1148
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001149 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001150 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001151 }
1152
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001153 if ($type ne "oldnoconfig") {
1154 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001155 dodie "failed make config";
1156 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001157 # Run old config regardless, to enforce min configurations
1158 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001159
Steven Rostedta75fece2010-11-02 14:58:27 -04001160 $redirect = "$buildlog";
1161 if (!run_command "$make $build_options") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001162 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001163 # bisect may need this to pass
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001164 return 0 if ($in_bisect);
1165 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001166 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001167 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001168
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001169 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001170}
1171
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001172sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001173 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001174 if (defined($poweroff_after_halt)) {
1175 sleep $poweroff_after_halt;
1176 run_command "$power_off";
1177 }
1178 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001179 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001180 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001181 }
1182}
1183
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001184sub success {
1185 my ($i) = @_;
1186
Steven Rostedte48c5292010-11-02 14:35:37 -04001187 $successes++;
1188
Steven Rostedt9064af52011-06-13 10:38:48 -04001189 my $name = "";
1190
1191 if (defined($test_name)) {
1192 $name = " ($test_name)";
1193 }
1194
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001195 doprint "\n\n*******************************************\n";
1196 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001197 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001198 doprint "*******************************************\n";
1199 doprint "*******************************************\n";
1200
Steven Rostedt576f6272010-11-02 14:58:38 -04001201 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001202 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001203 reboot;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001204 start_monitor;
Steven Rostedta75fece2010-11-02 14:58:27 -04001205 wait_for_monitor $sleep_time;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001206 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001207 }
1208}
1209
1210sub get_version {
1211 # get the release name
1212 doprint "$make kernelrelease ... ";
1213 $version = `$make kernelrelease | tail -1`;
1214 chomp($version);
1215 doprint "$version\n";
1216}
1217
Steven Rostedtc960bb92011-03-08 09:22:39 -05001218sub answer_bisect {
1219 for (;;) {
1220 doprint "Pass or fail? [p/f]";
1221 my $ans = <STDIN>;
1222 chomp $ans;
1223 if ($ans eq "p" || $ans eq "P") {
1224 return 1;
1225 } elsif ($ans eq "f" || $ans eq "F") {
1226 return 0;
1227 } else {
1228 print "Please answer 'P' or 'F'\n";
1229 }
1230 }
1231}
1232
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001233sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001234 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001235
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001236 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001237 $reboot_on_error = 0;
1238 $poweroff_on_error = 0;
1239 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001240
1241 run_command $run_test or $failed = 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001242 exit $failed;
1243}
1244
1245my $child_done;
1246
1247sub child_finished {
1248 $child_done = 1;
1249}
1250
1251sub do_run_test {
1252 my $child_pid;
1253 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001254 my $line;
1255 my $full_line;
1256 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001257
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001258 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001259
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001260 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001261
1262 $child_done = 0;
1263
1264 $SIG{CHLD} = qw(child_finished);
1265
1266 $child_pid = fork;
1267
1268 child_run_test if (!$child_pid);
1269
1270 $full_line = "";
1271
1272 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001273 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001274 if (defined($line)) {
1275
1276 # we are not guaranteed to get a full line
1277 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001278 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001279
1280 if ($full_line =~ /call trace:/i) {
1281 $bug = 1;
1282 }
1283
1284 if ($full_line =~ /Kernel panic -/) {
1285 $bug = 1;
1286 }
1287
1288 if ($line =~ /\n/) {
1289 $full_line = "";
1290 }
1291 }
1292 } while (!$child_done && !$bug);
1293
1294 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001295 my $failure_start = time;
1296 my $now;
1297 do {
1298 $line = wait_for_input($monitor_fp, 1);
1299 if (defined($line)) {
1300 doprint $line;
1301 }
1302 $now = time;
1303 if ($now - $failure_start >= $stop_after_failure) {
1304 last;
1305 }
1306 } while (defined($line));
1307
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001308 doprint "Detected kernel crash!\n";
1309 # kill the child with extreme prejudice
1310 kill 9, $child_pid;
1311 }
1312
1313 waitpid $child_pid, 0;
1314 $child_exit = $?;
1315
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001316 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001317 return 0 if $in_bisect;
1318 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001319 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001320 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001321}
1322
Steven Rostedta75fece2010-11-02 14:58:27 -04001323sub run_git_bisect {
1324 my ($command) = @_;
1325
1326 doprint "$command ... ";
1327
1328 my $output = `$command 2>&1`;
1329 my $ret = $?;
1330
1331 logit $output;
1332
1333 if ($ret) {
1334 doprint "FAILED\n";
1335 dodie "Failed to git bisect";
1336 }
1337
1338 doprint "SUCCESS\n";
1339 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1340 doprint "$1 [$2]\n";
1341 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1342 $bisect_bad = $1;
1343 doprint "Found bad commit... $1\n";
1344 return 0;
1345 } else {
1346 # we already logged it, just print it now.
1347 print $output;
1348 }
1349
1350 return 1;
1351}
1352
Steven Rostedtc23dca72011-03-08 09:26:31 -05001353sub bisect_reboot {
1354 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1355 reboot;
1356 start_monitor;
1357 wait_for_monitor $bisect_sleep_time;
1358 end_monitor;
1359}
1360
1361# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001362sub run_bisect_test {
1363 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001364
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001365 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001366 my $result;
1367 my $output;
1368 my $ret;
1369
Steven Rostedt0a05c762010-11-08 11:14:10 -05001370 $in_bisect = 1;
1371
1372 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001373
1374 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001375 if ($failed && $bisect_skip) {
1376 $in_bisect = 0;
1377 return -1;
1378 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001379 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001380
1381 # Now boot the box
1382 get_grub_index;
1383 get_version;
1384 install;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001385
1386 start_monitor;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001387 monitor or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001388
1389 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001390 if ($failed && $bisect_skip) {
1391 end_monitor;
1392 bisect_reboot;
1393 $in_bisect = 0;
1394 return -1;
1395 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001396 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001397
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001398 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001399 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001400 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001401 }
1402
1403 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001404 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001405 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001406 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001407 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001408
1409 # reboot the box to a kernel we can ssh to
1410 if ($type ne "build") {
1411 bisect_reboot;
1412 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001413 $in_bisect = 0;
1414
1415 return $result;
1416}
1417
1418sub run_bisect {
1419 my ($type) = @_;
1420 my $buildtype = "oldconfig";
1421
1422 # We should have a minconfig to use?
1423 if (defined($minconfig)) {
1424 $buildtype = "useconfig:$minconfig";
1425 }
1426
1427 my $ret = run_bisect_test $type, $buildtype;
1428
Steven Rostedtc960bb92011-03-08 09:22:39 -05001429 if ($bisect_manual) {
1430 $ret = answer_bisect;
1431 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001432
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001433 # Are we looking for where it worked, not failed?
1434 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001435 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001436 }
1437
Steven Rostedtc23dca72011-03-08 09:26:31 -05001438 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001439 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001440 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001441 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001442 } elsif ($bisect_skip) {
1443 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1444 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001445 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001446}
1447
1448sub bisect {
1449 my ($i) = @_;
1450
1451 my $result;
1452
1453 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1454 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1455 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1456
1457 my $good = $opt{"BISECT_GOOD[$i]"};
1458 my $bad = $opt{"BISECT_BAD[$i]"};
1459 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001460 my $start = $opt{"BISECT_START[$i]"};
1461 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001462 my $start_files = $opt{"BISECT_FILES[$i]"};
1463
1464 if (defined($start_files)) {
1465 $start_files = " -- " . $start_files;
1466 } else {
1467 $start_files = "";
1468 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001469
Steven Rostedta57419b2010-11-02 15:13:54 -04001470 # convert to true sha1's
1471 $good = get_sha1($good);
1472 $bad = get_sha1($bad);
1473
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001474 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1475 $opt{"BISECT_REVERSE[$i]"} == 1) {
1476 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1477 $reverse_bisect = 1;
1478 } else {
1479 $reverse_bisect = 0;
1480 }
1481
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001482 # Can't have a test without having a test to run
1483 if ($type eq "test" && !defined($run_test)) {
1484 $type = "boot";
1485 }
1486
Steven Rostedta75fece2010-11-02 14:58:27 -04001487 my $check = $opt{"BISECT_CHECK[$i]"};
1488 if (defined($check) && $check ne "0") {
1489
1490 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001491 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001492
1493 if ($check ne "good") {
1494 doprint "TESTING BISECT BAD [$bad]\n";
1495 run_command "git checkout $bad" or
1496 die "Failed to checkout $bad";
1497
1498 $result = run_bisect $type;
1499
1500 if ($result ne "bad") {
1501 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1502 }
1503 }
1504
1505 if ($check ne "bad") {
1506 doprint "TESTING BISECT GOOD [$good]\n";
1507 run_command "git checkout $good" or
1508 die "Failed to checkout $good";
1509
1510 $result = run_bisect $type;
1511
1512 if ($result ne "good") {
1513 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1514 }
1515 }
1516
1517 # checkout where we started
1518 run_command "git checkout $head" or
1519 die "Failed to checkout $head";
1520 }
1521
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001522 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001523 dodie "could not start bisect";
1524
1525 run_command "git bisect good $good" or
1526 dodie "could not set bisect good to $good";
1527
1528 run_git_bisect "git bisect bad $bad" or
1529 dodie "could not set bisect bad to $bad";
1530
1531 if (defined($replay)) {
1532 run_command "git bisect replay $replay" or
1533 dodie "failed to run replay";
1534 }
1535
1536 if (defined($start)) {
1537 run_command "git checkout $start" or
1538 dodie "failed to checkout $start";
1539 }
1540
1541 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001542 do {
1543 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001544 $test = run_git_bisect "git bisect $result";
1545 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001546
1547 run_command "git bisect log" or
1548 dodie "could not capture git bisect log";
1549
1550 run_command "git bisect reset" or
1551 dodie "could not reset git bisect";
1552
1553 doprint "Bad commit was [$bisect_bad]\n";
1554
Steven Rostedt0a05c762010-11-08 11:14:10 -05001555 success $i;
1556}
1557
1558my %config_ignore;
1559my %config_set;
1560
1561my %config_list;
1562my %null_config;
1563
1564my %dependency;
1565
1566sub process_config_ignore {
1567 my ($config) = @_;
1568
1569 open (IN, $config)
1570 or dodie "Failed to read $config";
1571
1572 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04001573 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001574 $config_ignore{$2} = $1;
1575 }
1576 }
1577
1578 close(IN);
1579}
1580
1581sub read_current_config {
1582 my ($config_ref) = @_;
1583
1584 %{$config_ref} = ();
1585 undef %{$config_ref};
1586
1587 my @key = keys %{$config_ref};
1588 if ($#key >= 0) {
1589 print "did not delete!\n";
1590 exit;
1591 }
1592 open (IN, "$output_config");
1593
1594 while (<IN>) {
1595 if (/^(CONFIG\S+)=(.*)/) {
1596 ${$config_ref}{$1} = $2;
1597 }
1598 }
1599 close(IN);
1600}
1601
1602sub get_dependencies {
1603 my ($config) = @_;
1604
1605 my $arr = $dependency{$config};
1606 if (!defined($arr)) {
1607 return ();
1608 }
1609
1610 my @deps = @{$arr};
1611
1612 foreach my $dep (@{$arr}) {
1613 print "ADD DEP $dep\n";
1614 @deps = (@deps, get_dependencies $dep);
1615 }
1616
1617 return @deps;
1618}
1619
1620sub create_config {
1621 my @configs = @_;
1622
1623 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1624
1625 foreach my $config (@configs) {
1626 print OUT "$config_set{$config}\n";
1627 my @deps = get_dependencies $config;
1628 foreach my $dep (@deps) {
1629 print OUT "$config_set{$dep}\n";
1630 }
1631 }
1632
1633 foreach my $config (keys %config_ignore) {
1634 print OUT "$config_ignore{$config}\n";
1635 }
1636 close(OUT);
1637
1638# exit;
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001639 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001640}
1641
1642sub compare_configs {
1643 my (%a, %b) = @_;
1644
1645 foreach my $item (keys %a) {
1646 if (!defined($b{$item})) {
1647 print "diff $item\n";
1648 return 1;
1649 }
1650 delete $b{$item};
1651 }
1652
1653 my @keys = keys %b;
1654 if ($#keys) {
1655 print "diff2 $keys[0]\n";
1656 }
1657 return -1 if ($#keys >= 0);
1658
1659 return 0;
1660}
1661
1662sub run_config_bisect_test {
1663 my ($type) = @_;
1664
1665 return run_bisect_test $type, "oldconfig";
1666}
1667
1668sub process_passed {
1669 my (%configs) = @_;
1670
1671 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1672 # Passed! All these configs are part of a good compile.
1673 # Add them to the min options.
1674 foreach my $config (keys %configs) {
1675 if (defined($config_list{$config})) {
1676 doprint " removing $config\n";
1677 $config_ignore{$config} = $config_list{$config};
1678 delete $config_list{$config};
1679 }
1680 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05001681 doprint "config copied to $outputdir/config_good\n";
1682 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001683}
1684
1685sub process_failed {
1686 my ($config) = @_;
1687
1688 doprint "\n\n***************************************\n";
1689 doprint "Found bad config: $config\n";
1690 doprint "***************************************\n\n";
1691}
1692
1693sub run_config_bisect {
1694
1695 my @start_list = keys %config_list;
1696
1697 if ($#start_list < 0) {
1698 doprint "No more configs to test!!!\n";
1699 return -1;
1700 }
1701
1702 doprint "***** RUN TEST ***\n";
1703 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1704 my $ret;
1705 my %current_config;
1706
1707 my $count = $#start_list + 1;
1708 doprint " $count configs to test\n";
1709
1710 my $half = int($#start_list / 2);
1711
1712 do {
1713 my @tophalf = @start_list[0 .. $half];
1714
1715 create_config @tophalf;
1716 read_current_config \%current_config;
1717
1718 $count = $#tophalf + 1;
1719 doprint "Testing $count configs\n";
1720 my $found = 0;
1721 # make sure we test something
1722 foreach my $config (@tophalf) {
1723 if (defined($current_config{$config})) {
1724 logit " $config\n";
1725 $found = 1;
1726 }
1727 }
1728 if (!$found) {
1729 # try the other half
1730 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001731 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05001732 create_config @tophalf;
1733 read_current_config \%current_config;
1734 foreach my $config (@tophalf) {
1735 if (defined($current_config{$config})) {
1736 logit " $config\n";
1737 $found = 1;
1738 }
1739 }
1740 if (!$found) {
1741 doprint "Failed: Can't make new config with current configs\n";
1742 foreach my $config (@start_list) {
1743 doprint " CONFIG: $config\n";
1744 }
1745 return -1;
1746 }
1747 $count = $#tophalf + 1;
1748 doprint "Testing $count configs\n";
1749 }
1750
1751 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05001752 if ($bisect_manual) {
1753 $ret = answer_bisect;
1754 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001755 if ($ret) {
1756 process_passed %current_config;
1757 return 0;
1758 }
1759
1760 doprint "This config had a failure.\n";
1761 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05001762 doprint "config copied to $outputdir/config_bad\n";
1763 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001764
1765 # A config exists in this group that was bad.
1766 foreach my $config (keys %config_list) {
1767 if (!defined($current_config{$config})) {
1768 doprint " removing $config\n";
1769 delete $config_list{$config};
1770 }
1771 }
1772
1773 @start_list = @tophalf;
1774
1775 if ($#start_list == 0) {
1776 process_failed $start_list[0];
1777 return 1;
1778 }
1779
1780 # remove half the configs we are looking at and see if
1781 # they are good.
1782 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001783 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05001784
Steven Rostedtc960bb92011-03-08 09:22:39 -05001785 # we found a single config, try it again unless we are running manually
1786
1787 if ($bisect_manual) {
1788 process_failed $start_list[0];
1789 return 1;
1790 }
1791
Steven Rostedt0a05c762010-11-08 11:14:10 -05001792 my @tophalf = @start_list[0 .. 0];
1793
1794 $ret = run_config_bisect_test $type;
1795 if ($ret) {
1796 process_passed %current_config;
1797 return 0;
1798 }
1799
1800 process_failed $start_list[0];
1801 return 1;
1802}
1803
1804sub config_bisect {
1805 my ($i) = @_;
1806
1807 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1808
1809 my $tmpconfig = "$tmpdir/use_config";
1810
Steven Rostedt30f75da2011-06-13 10:35:35 -04001811 if (defined($config_bisect_good)) {
1812 process_config_ignore $config_bisect_good;
1813 }
1814
Steven Rostedt0a05c762010-11-08 11:14:10 -05001815 # Make the file with the bad config and the min config
1816 if (defined($minconfig)) {
1817 # read the min config for things to ignore
1818 run_command "cp $minconfig $tmpconfig" or
1819 dodie "failed to copy $minconfig to $tmpconfig";
1820 } else {
1821 unlink $tmpconfig;
1822 }
1823
1824 # Add other configs
1825 if (defined($addconfig)) {
1826 run_command "cat $addconfig >> $tmpconfig" or
1827 dodie "failed to append $addconfig";
1828 }
1829
Steven Rostedt0a05c762010-11-08 11:14:10 -05001830 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001831 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05001832 process_config_ignore $tmpconfig;
1833 }
1834
1835 # now process the start config
1836 run_command "cp $start_config $output_config" or
1837 dodie "failed to copy $start_config to $output_config";
1838
1839 # read directly what we want to check
1840 my %config_check;
1841 open (IN, $output_config)
1842 or dodie "faied to open $output_config";
1843
1844 while (<IN>) {
1845 if (/^((CONFIG\S*)=.*)/) {
1846 $config_check{$2} = $1;
1847 }
1848 }
1849 close(IN);
1850
1851 # Now run oldconfig with the minconfig (and addconfigs)
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001852 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001853
1854 # check to see what we lost (or gained)
1855 open (IN, $output_config)
1856 or dodie "Failed to read $start_config";
1857
1858 my %removed_configs;
1859 my %added_configs;
1860
1861 while (<IN>) {
1862 if (/^((CONFIG\S*)=.*)/) {
1863 # save off all options
1864 $config_set{$2} = $1;
1865 if (defined($config_check{$2})) {
1866 if (defined($config_ignore{$2})) {
1867 $removed_configs{$2} = $1;
1868 } else {
1869 $config_list{$2} = $1;
1870 }
1871 } elsif (!defined($config_ignore{$2})) {
1872 $added_configs{$2} = $1;
1873 $config_list{$2} = $1;
1874 }
1875 }
1876 }
1877 close(IN);
1878
1879 my @confs = keys %removed_configs;
1880 if ($#confs >= 0) {
1881 doprint "Configs overridden by default configs and removed from check:\n";
1882 foreach my $config (@confs) {
1883 doprint " $config\n";
1884 }
1885 }
1886 @confs = keys %added_configs;
1887 if ($#confs >= 0) {
1888 doprint "Configs appearing in make oldconfig and added:\n";
1889 foreach my $config (@confs) {
1890 doprint " $config\n";
1891 }
1892 }
1893
1894 my %config_test;
1895 my $once = 0;
1896
1897 # Sometimes kconfig does weird things. We must make sure
1898 # that the config we autocreate has everything we need
1899 # to test, otherwise we may miss testing configs, or
1900 # may not be able to create a new config.
1901 # Here we create a config with everything set.
1902 create_config (keys %config_list);
1903 read_current_config \%config_test;
1904 foreach my $config (keys %config_list) {
1905 if (!defined($config_test{$config})) {
1906 if (!$once) {
1907 $once = 1;
1908 doprint "Configs not produced by kconfig (will not be checked):\n";
1909 }
1910 doprint " $config\n";
1911 delete $config_list{$config};
1912 }
1913 }
1914 my $ret;
1915 do {
1916 $ret = run_config_bisect;
1917 } while (!$ret);
1918
1919 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001920
1921 success $i;
1922}
1923
Steven Rostedt27d934b2011-05-20 09:18:18 -04001924sub patchcheck_reboot {
1925 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
1926 reboot;
1927 start_monitor;
1928 wait_for_monitor $patchcheck_sleep_time;
1929 end_monitor;
1930}
1931
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001932sub patchcheck {
1933 my ($i) = @_;
1934
1935 die "PATCHCHECK_START[$i] not defined\n"
1936 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1937 die "PATCHCHECK_TYPE[$i] not defined\n"
1938 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1939
1940 my $start = $opt{"PATCHCHECK_START[$i]"};
1941
1942 my $end = "HEAD";
1943 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1944 $end = $opt{"PATCHCHECK_END[$i]"};
1945 }
1946
Steven Rostedta57419b2010-11-02 15:13:54 -04001947 # Get the true sha1's since we can use things like HEAD~3
1948 $start = get_sha1($start);
1949 $end = get_sha1($end);
1950
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001951 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1952
1953 # Can't have a test without having a test to run
1954 if ($type eq "test" && !defined($run_test)) {
1955 $type = "boot";
1956 }
1957
1958 open (IN, "git log --pretty=oneline $end|") or
1959 dodie "could not get git list";
1960
1961 my @list;
1962
1963 while (<IN>) {
1964 chomp;
1965 $list[$#list+1] = $_;
1966 last if (/^$start/);
1967 }
1968 close(IN);
1969
1970 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001971 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001972 }
1973
1974 # go backwards in the list
1975 @list = reverse @list;
1976
1977 my $save_clean = $noclean;
1978
1979 $in_patchcheck = 1;
1980 foreach my $item (@list) {
1981 my $sha1 = $item;
1982 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1983
1984 doprint "\nProcessing commit $item\n\n";
1985
1986 run_command "git checkout $sha1" or
1987 die "Failed to checkout $sha1";
1988
1989 # only clean on the first and last patch
1990 if ($item eq $list[0] ||
1991 $item eq $list[$#list]) {
1992 $noclean = $save_clean;
1993 } else {
1994 $noclean = 1;
1995 }
1996
1997 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001998 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001999 } else {
2000 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002001 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002002 }
2003
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002004 check_buildlog $sha1 or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002005
2006 next if ($type eq "build");
2007
2008 get_grub_index;
2009 get_version;
2010 install;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002011
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002012 my $failed = 0;
2013
2014 start_monitor;
2015 monitor or $failed = 1;
2016
2017 if (!$failed && $type ne "boot"){
2018 do_run_test or $failed = 1;
2019 }
2020 end_monitor;
2021 return 0 if ($failed);
2022
Steven Rostedt27d934b2011-05-20 09:18:18 -04002023 patchcheck_reboot;
2024
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002025 }
2026 $in_patchcheck = 0;
2027 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002028
2029 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002030}
2031
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002032$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002033
Steven Rostedt8d1491b2010-11-18 15:39:48 -05002034if ($#ARGV == 0) {
2035 $ktest_config = $ARGV[0];
2036 if (! -f $ktest_config) {
2037 print "$ktest_config does not exist.\n";
2038 my $ans;
2039 for (;;) {
2040 print "Create it? [Y/n] ";
2041 $ans = <STDIN>;
2042 chomp $ans;
2043 if ($ans =~ /^\s*$/) {
2044 $ans = "y";
2045 }
2046 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
2047 print "Please answer either 'y' or 'n'.\n";
2048 }
2049 if ($ans !~ /^y$/i) {
2050 exit 0;
2051 }
2052 }
2053} else {
2054 $ktest_config = "ktest.conf";
2055}
2056
2057if (! -f $ktest_config) {
2058 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2059 print OUT << "EOF"
2060# Generated by ktest.pl
2061#
2062# Define each test with TEST_START
2063# The config options below it will override the defaults
2064TEST_START
2065
2066DEFAULTS
2067EOF
2068;
2069 close(OUT);
2070}
2071read_config $ktest_config;
2072
2073# Append any configs entered in manually to the config file.
2074my @new_configs = keys %entered_configs;
2075if ($#new_configs >= 0) {
2076 print "\nAppending entered in configs to $ktest_config\n";
2077 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2078 foreach my $config (@new_configs) {
2079 print OUT "$config = $entered_configs{$config}\n";
2080 $opt{$config} = $entered_configs{$config};
2081 }
2082}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002083
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002084if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2085 unlink $opt{"LOG_FILE"};
2086}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002087
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002088doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2089
Steven Rostedta57419b2010-11-02 15:13:54 -04002090for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2091
2092 if (!$i) {
2093 doprint "DEFAULT OPTIONS:\n";
2094 } else {
2095 doprint "\nTEST $i OPTIONS";
2096 if (defined($repeat_tests{$i})) {
2097 $repeat = $repeat_tests{$i};
2098 doprint " ITERATE $repeat";
2099 }
2100 doprint "\n";
2101 }
2102
2103 foreach my $option (sort keys %opt) {
2104
2105 if ($option =~ /\[(\d+)\]$/) {
2106 next if ($i != $1);
2107 } else {
2108 next if ($i);
2109 }
2110
2111 doprint "$option = $opt{$option}\n";
2112 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002113}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002114
Steven Rostedt2a625122011-05-20 15:48:59 -04002115sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002116 my ($name, $i) = @_;
2117
2118 my $option = "$name\[$i\]";
2119
2120 if (defined($opt{$option})) {
2121 return $opt{$option};
2122 }
2123
Steven Rostedta57419b2010-11-02 15:13:54 -04002124 foreach my $test (keys %repeat_tests) {
2125 if ($i >= $test &&
2126 $i < $test + $repeat_tests{$test}) {
2127 $option = "$name\[$test\]";
2128 if (defined($opt{$option})) {
2129 return $opt{$option};
2130 }
2131 }
2132 }
2133
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002134 if (defined($opt{$name})) {
2135 return $opt{$name};
2136 }
2137
2138 return undef;
2139}
2140
Steven Rostedt2a625122011-05-20 15:48:59 -04002141sub eval_option {
2142 my ($option, $i) = @_;
2143
2144 # Add space to evaluate the character before $
2145 $option = " $option";
2146 my $retval = "";
2147
2148 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
2149 my $start = $1;
2150 my $var = $2;
2151 my $end = $3;
2152
2153 # Append beginning of line
2154 $retval = "$retval$start";
2155
2156 # If the iteration option OPT[$i] exists, then use that.
2157 # otherwise see if the default OPT (without [$i]) exists.
2158
2159 my $o = "$var\[$i\]";
2160
2161 if (defined($opt{$o})) {
2162 $o = $opt{$o};
2163 $retval = "$retval$o";
2164 } elsif (defined($opt{$var})) {
2165 $o = $opt{$var};
2166 $retval = "$retval$o";
2167 } else {
2168 $retval = "$retval\$\{$var\}";
2169 }
2170
2171 $option = $end;
2172 }
2173
2174 $retval = "$retval$option";
2175
2176 $retval =~ s/^ //;
2177
2178 return $retval;
2179}
2180
2181sub set_test_option {
2182 my ($name, $i) = @_;
2183
2184 my $option = __set_test_option($name, $i);
2185 return $option if (!defined($option));
2186
2187 my $prev = "";
2188
2189 # Since an option can evaluate to another option,
2190 # keep iterating until we do not evaluate any more
2191 # options.
2192 my $r = 0;
2193 while ($prev ne $option) {
2194 # Check for recursive evaluations.
2195 # 100 deep should be more than enough.
2196 if ($r++ > 100) {
2197 die "Over 100 evaluations accurred with $name\n" .
2198 "Check for recursive variables\n";
2199 }
2200 $prev = $option;
2201 $option = eval_option($option, $i);
2202 }
2203
2204 return $option;
2205}
2206
Steven Rostedt2545eb62010-11-02 15:01:32 -04002207# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04002208for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04002209
Steven Rostedt576f6272010-11-02 14:58:38 -04002210 $iteration = $i;
2211
Steven Rostedta75fece2010-11-02 14:58:27 -04002212 my $makecmd = set_test_option("MAKE_CMD", $i);
2213
2214 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002215 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002216 $tmpdir = set_test_option("TMP_DIR", $i);
2217 $outputdir = set_test_option("OUTPUT_DIR", $i);
2218 $builddir = set_test_option("BUILD_DIR", $i);
2219 $test_type = set_test_option("TEST_TYPE", $i);
2220 $build_type = set_test_option("BUILD_TYPE", $i);
2221 $build_options = set_test_option("BUILD_OPTIONS", $i);
2222 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002223 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002224 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2225 $minconfig = set_test_option("MIN_CONFIG", $i);
2226 $run_test = set_test_option("TEST", $i);
2227 $addconfig = set_test_option("ADD_CONFIG", $i);
2228 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2229 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002230 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002231 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2232 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2233 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2234 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2235 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04002236 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2237 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002238 $sleep_time = set_test_option("SLEEP_TIME", $i);
2239 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04002240 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05002241 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05002242 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04002243 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002244 $store_failures = set_test_option("STORE_FAILURES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04002245 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002246 $timeout = set_test_option("TIMEOUT", $i);
2247 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2248 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04002249 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002250 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002251 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2252 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05002253 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002254 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002255 $ssh_exec = set_test_option("SSH_EXEC", $i);
2256 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002257 $target_image = set_test_option("TARGET_IMAGE", $i);
2258 $localversion = set_test_option("LOCALVERSION", $i);
2259
2260 chdir $builddir || die "can't change directory to $builddir";
2261
2262 if (!-d $tmpdir) {
2263 mkpath($tmpdir) or
2264 die "can't create $tmpdir";
2265 }
2266
Steven Rostedte48c5292010-11-02 14:35:37 -04002267 $ENV{"SSH_USER"} = $ssh_user;
2268 $ENV{"MACHINE"} = $machine;
2269
Steven Rostedta75fece2010-11-02 14:58:27 -04002270 $target = "$ssh_user\@$machine";
2271
2272 $buildlog = "$tmpdir/buildlog-$machine";
2273 $dmesg = "$tmpdir/dmesg-$machine";
2274 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002275 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04002276
2277 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04002278 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04002279 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002280 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04002281 }
2282
2283 my $run_type = $build_type;
2284 if ($test_type eq "patchcheck") {
2285 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2286 } elsif ($test_type eq "bisect") {
2287 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002288 } elsif ($test_type eq "config_bisect") {
2289 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04002290 }
2291
2292 # mistake in config file?
2293 if (!defined($run_type)) {
2294 $run_type = "ERROR";
2295 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002296
2297 doprint "\n\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04002298 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002299
2300 unlink $dmesg;
2301 unlink $buildlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002302
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002303 if (!defined($minconfig)) {
2304 $minconfig = $addconfig;
2305
2306 } elsif (defined($addconfig)) {
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002307 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002308 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002309 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002310 }
2311
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002312 my $checkout = $opt{"CHECKOUT[$i]"};
2313 if (defined($checkout)) {
2314 run_command "git checkout $checkout" or
2315 die "failed to checkout $checkout";
2316 }
2317
Steven Rostedta75fece2010-11-02 14:58:27 -04002318 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002319 bisect $i;
2320 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002321 } elsif ($test_type eq "config_bisect") {
2322 config_bisect $i;
2323 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04002324 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002325 patchcheck $i;
2326 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002327 }
2328
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002329 if ($build_type ne "nobuild") {
2330 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002331 }
2332
Steven Rostedta75fece2010-11-02 14:58:27 -04002333 if ($test_type ne "build") {
2334 get_grub_index;
2335 get_version;
2336 install;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002337
Steven Rostedta75fece2010-11-02 14:58:27 -04002338 my $failed = 0;
2339 start_monitor;
2340 monitor or $failed = 1;;
2341
2342 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2343 do_run_test or $failed = 1;
2344 }
2345 end_monitor;
2346 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002347 }
2348
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002349 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002350}
2351
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002352if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002353 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04002354} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002355 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002356}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002357
Steven Rostedte48c5292010-11-02 14:35:37 -04002358doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
2359
Steven Rostedt2545eb62010-11-02 15:01:32 -04002360exit 0;