blob: 579569f57b067afd8e1006441563aa3d267b8dfd [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 Rostedt8d1491b2010-11-18 15:39:48 -0500122
123$config_help{"MACHINE"} = << "EOF"
124 The machine hostname that you will test.
125EOF
126 ;
127$config_help{"SSH_USER"} = << "EOF"
128 The box is expected to have ssh on normal bootup, provide the user
129 (most likely root, since you need privileged operations)
130EOF
131 ;
132$config_help{"BUILD_DIR"} = << "EOF"
133 The directory that contains the Linux source code (full path).
134EOF
135 ;
136$config_help{"OUTPUT_DIR"} = << "EOF"
137 The directory that the objects will be built (full path).
138 (can not be same as BUILD_DIR)
139EOF
140 ;
141$config_help{"BUILD_TARGET"} = << "EOF"
142 The location of the compiled file to copy to the target.
143 (relative to OUTPUT_DIR)
144EOF
145 ;
146$config_help{"TARGET_IMAGE"} = << "EOF"
147 The place to put your image on the test machine.
148EOF
149 ;
150$config_help{"POWER_CYCLE"} = << "EOF"
151 A script or command to reboot the box.
152
153 Here is a digital loggers power switch example
154 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
155
156 Here is an example to reboot a virtual box on the current host
157 with the name "Guest".
158 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
159EOF
160 ;
161$config_help{"CONSOLE"} = << "EOF"
162 The script or command that reads the console
163
164 If you use ttywatch server, something like the following would work.
165CONSOLE = nc -d localhost 3001
166
167 For a virtual machine with guest name "Guest".
168CONSOLE = virsh console Guest
169EOF
170 ;
171$config_help{"LOCALVERSION"} = << "EOF"
172 Required version ending to differentiate the test
173 from other linux builds on the system.
174EOF
175 ;
176$config_help{"REBOOT_TYPE"} = << "EOF"
177 Way to reboot the box to the test kernel.
178 Only valid options so far are "grub" and "script".
179
180 If you specify grub, it will assume grub version 1
181 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
182 and select that target to reboot to the kernel. If this is not
183 your setup, then specify "script" and have a command or script
184 specified in REBOOT_SCRIPT to boot to the target.
185
186 The entry in /boot/grub/menu.lst must be entered in manually.
187 The test will not modify that file.
188EOF
189 ;
190$config_help{"GRUB_MENU"} = << "EOF"
191 The grub title name for the test kernel to boot
192 (Only mandatory if REBOOT_TYPE = grub)
193
194 Note, ktest.pl will not update the grub menu.lst, you need to
195 manually add an option for the test. ktest.pl will search
196 the grub menu.lst for this option to find what kernel to
197 reboot into.
198
199 For example, if in the /boot/grub/menu.lst the test kernel title has:
200 title Test Kernel
201 kernel vmlinuz-test
202 GRUB_MENU = Test Kernel
203EOF
204 ;
205$config_help{"REBOOT_SCRIPT"} = << "EOF"
206 A script to reboot the target into the test kernel
207 (Only mandatory if REBOOT_TYPE = script)
208EOF
209 ;
210
211
212sub get_ktest_config {
213 my ($config) = @_;
214
215 return if (defined($opt{$config}));
216
217 if (defined($config_help{$config})) {
218 print "\n";
219 print $config_help{$config};
220 }
221
222 for (;;) {
223 print "$config = ";
224 if (defined($default{$config})) {
225 print "\[$default{$config}\] ";
226 }
227 $entered_configs{$config} = <STDIN>;
228 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
229 if ($entered_configs{$config} =~ /^\s*$/) {
230 if ($default{$config}) {
231 $entered_configs{$config} = $default{$config};
232 } else {
233 print "Your answer can not be blank\n";
234 next;
235 }
236 }
237 last;
238 }
239}
240
241sub get_ktest_configs {
242 get_ktest_config("MACHINE");
243 get_ktest_config("SSH_USER");
244 get_ktest_config("BUILD_DIR");
245 get_ktest_config("OUTPUT_DIR");
246 get_ktest_config("BUILD_TARGET");
247 get_ktest_config("TARGET_IMAGE");
248 get_ktest_config("POWER_CYCLE");
249 get_ktest_config("CONSOLE");
250 get_ktest_config("LOCALVERSION");
251
252 my $rtype = $opt{"REBOOT_TYPE"};
253
254 if (!defined($rtype)) {
255 if (!defined($opt{"GRUB_MENU"})) {
256 get_ktest_config("REBOOT_TYPE");
257 $rtype = $entered_configs{"REBOOT_TYPE"};
258 } else {
259 $rtype = "grub";
260 }
261 }
262
263 if ($rtype eq "grub") {
264 get_ktest_config("GRUB_MENU");
265 } else {
266 get_ktest_config("REBOOT_SCRIPT");
267 }
268}
269
Steven Rostedt77d942c2011-05-20 13:36:58 -0400270sub process_variables {
271 my ($value) = @_;
272 my $retval = "";
273
274 # We want to check for '\', and it is just easier
275 # to check the previous characet of '$' and not need
276 # to worry if '$' is the first character. By adding
277 # a space to $value, we can just check [^\\]\$ and
278 # it will still work.
279 $value = " $value";
280
281 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
282 my $begin = $1;
283 my $var = $2;
284 my $end = $3;
285 # append beginning of value to retval
286 $retval = "$retval$begin";
287 if (defined($variable{$var})) {
288 $retval = "$retval$variable{$var}";
289 } else {
290 # put back the origin piece.
291 $retval = "$retval\$\{$var\}";
292 }
293 $value = $end;
294 }
295 $retval = "$retval$value";
296
297 # remove the space added in the beginning
298 $retval =~ s/ //;
299
300 return "$retval"
301}
302
Steven Rostedta57419b2010-11-02 15:13:54 -0400303sub set_value {
304 my ($lvalue, $rvalue) = @_;
305
306 if (defined($opt{$lvalue})) {
307 die "Error: Option $lvalue defined more than once!\n";
308 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500309 if ($rvalue =~ /^\s*$/) {
310 delete $opt{$lvalue};
311 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400312 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500313 $opt{$lvalue} = $rvalue;
314 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400315}
316
Steven Rostedt77d942c2011-05-20 13:36:58 -0400317sub set_variable {
318 my ($lvalue, $rvalue) = @_;
319
320 if ($rvalue =~ /^\s*$/) {
321 delete $variable{$lvalue};
322 } else {
323 $rvalue = process_variables($rvalue);
324 $variable{$lvalue} = $rvalue;
325 }
326}
327
Steven Rostedt2545eb62010-11-02 15:01:32 -0400328sub read_config {
329 my ($config) = @_;
330
331 open(IN, $config) || die "can't read file $config";
332
Steven Rostedta57419b2010-11-02 15:13:54 -0400333 my $name = $config;
334 $name =~ s,.*/(.*),$1,;
335
336 my $test_num = 0;
337 my $default = 1;
338 my $repeat = 1;
339 my $num_tests_set = 0;
340 my $skip = 0;
341 my $rest;
342
Steven Rostedt2545eb62010-11-02 15:01:32 -0400343 while (<IN>) {
344
345 # ignore blank lines and comments
346 next if (/^\s*$/ || /\s*\#/);
347
Steven Rostedta57419b2010-11-02 15:13:54 -0400348 if (/^\s*TEST_START(.*)/) {
349
350 $rest = $1;
351
352 if ($num_tests_set) {
353 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
354 }
355
356 my $old_test_num = $test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400357 my $old_repeat = $repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400358
359 $test_num += $repeat;
360 $default = 0;
361 $repeat = 1;
362
363 if ($rest =~ /\s+SKIP(.*)/) {
364 $rest = $1;
365 $skip = 1;
366 } else {
367 $skip = 0;
368 }
369
370 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
371 $repeat = $1;
372 $rest = $2;
373 $repeat_tests{"$test_num"} = $repeat;
374 }
375
376 if ($rest =~ /\s+SKIP(.*)/) {
377 $rest = $1;
378 $skip = 1;
379 }
380
381 if ($rest !~ /^\s*$/) {
382 die "$name: $.: Gargbage found after TEST_START\n$_";
383 }
384
385 if ($skip) {
386 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400387 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400388 }
389
390 } elsif (/^\s*DEFAULTS(.*)$/) {
391 $default = 1;
392
393 $rest = $1;
394
395 if ($rest =~ /\s+SKIP(.*)/) {
396 $rest = $1;
397 $skip = 1;
398 } else {
399 $skip = 0;
400 }
401
402 if ($rest !~ /^\s*$/) {
403 die "$name: $.: Gargbage found after DEFAULTS\n$_";
404 }
405
406 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
407
408 next if ($skip);
409
Steven Rostedt2545eb62010-11-02 15:01:32 -0400410 my $lvalue = $1;
411 my $rvalue = $2;
412
Steven Rostedta57419b2010-11-02 15:13:54 -0400413 if (!$default &&
414 ($lvalue eq "NUM_TESTS" ||
415 $lvalue eq "LOG_FILE" ||
416 $lvalue eq "CLEAR_LOG")) {
417 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400418 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400419
420 if ($lvalue eq "NUM_TESTS") {
421 if ($test_num) {
422 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
423 }
424 if (!$default) {
425 die "$name: $.: NUM_TESTS must be set in default section\n";
426 }
427 $num_tests_set = 1;
428 }
429
430 if ($default || $lvalue =~ /\[\d+\]$/) {
431 set_value($lvalue, $rvalue);
432 } else {
433 my $val = "$lvalue\[$test_num\]";
434 set_value($val, $rvalue);
435
436 if ($repeat > 1) {
437 $repeats{$val} = $repeat;
438 }
439 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400440 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
441 next if ($skip);
442
443 my $lvalue = $1;
444 my $rvalue = $2;
445
446 # process config variables.
447 # Config variables are only active while reading the
448 # config and can be defined anywhere. They also ignore
449 # TEST_START and DEFAULTS, but are skipped if they are in
450 # on of these sections that have SKIP defined.
451 # The save variable can be
452 # defined multiple times and the new one simply overrides
453 # the prevous one.
454 set_variable($lvalue, $rvalue);
455
Steven Rostedta57419b2010-11-02 15:13:54 -0400456 } else {
457 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400458 }
459 }
460
461 close(IN);
Steven Rostedta75fece2010-11-02 14:58:27 -0400462
Steven Rostedta57419b2010-11-02 15:13:54 -0400463 if ($test_num) {
464 $test_num += $repeat - 1;
465 $opt{"NUM_TESTS"} = $test_num;
466 }
467
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500468 # make sure we have all mandatory configs
469 get_ktest_configs;
470
Steven Rostedta75fece2010-11-02 14:58:27 -0400471 # set any defaults
472
473 foreach my $default (keys %default) {
474 if (!defined($opt{$default})) {
475 $opt{$default} = $default{$default};
476 }
477 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400478}
479
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500480sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400481 if (defined($opt{"LOG_FILE"})) {
482 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
483 print OUT @_;
484 close(OUT);
485 }
486}
487
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500488sub logit {
489 if (defined($opt{"LOG_FILE"})) {
490 _logit @_;
491 } else {
492 print @_;
493 }
494}
495
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400496sub doprint {
497 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500498 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400499}
500
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400501sub run_command;
502
503sub reboot {
504 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400505 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400506 if (defined($powercycle_after_reboot)) {
507 sleep $powercycle_after_reboot;
508 run_command "$power_cycle";
509 }
510 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400511 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400512 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400513 }
514}
515
Steven Rostedt576f6272010-11-02 14:58:38 -0400516sub do_not_reboot {
517 my $i = $iteration;
518
519 return $test_type eq "build" ||
520 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
521 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
522}
523
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400524sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400525 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400526
Steven Rostedt576f6272010-11-02 14:58:38 -0400527 my $i = $iteration;
528
529 if ($reboot_on_error && !do_not_reboot) {
530
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400531 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400532 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400533
Steven Rostedta75fece2010-11-02 14:58:27 -0400534 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400535 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400536 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400537 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400538
Steven Rostedtf80802c2011-03-07 13:18:47 -0500539 if (defined($opt{"LOG_FILE"})) {
540 print " See $opt{LOG_FILE} for more info.\n";
541 }
542
Steven Rostedt576f6272010-11-02 14:58:38 -0400543 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400544}
545
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400546sub open_console {
547 my ($fp) = @_;
548
549 my $flags;
550
Steven Rostedta75fece2010-11-02 14:58:27 -0400551 my $pid = open($fp, "$console|") or
552 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400553
554 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400555 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400556 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400557 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400558
559 return $pid;
560}
561
562sub close_console {
563 my ($fp, $pid) = @_;
564
565 doprint "kill child process $pid\n";
566 kill 2, $pid;
567
568 print "closing!\n";
569 close($fp);
570}
571
572sub start_monitor {
573 if ($monitor_cnt++) {
574 return;
575 }
576 $monitor_fp = \*MONFD;
577 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400578
579 return;
580
581 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400582}
583
584sub end_monitor {
585 if (--$monitor_cnt) {
586 return;
587 }
588 close_console($monitor_fp, $monitor_pid);
589}
590
591sub wait_for_monitor {
592 my ($time) = @_;
593 my $line;
594
Steven Rostedta75fece2010-11-02 14:58:27 -0400595 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400596
597 # read the monitor and wait for the system to calm down
598 do {
599 $line = wait_for_input($monitor_fp, $time);
Steven Rostedta75fece2010-11-02 14:58:27 -0400600 print "$line" if (defined($line));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400601 } while (defined($line));
Steven Rostedta75fece2010-11-02 14:58:27 -0400602 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400603}
604
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400605sub fail {
606
Steven Rostedta75fece2010-11-02 14:58:27 -0400607 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400608 dodie @_;
609 }
610
Steven Rostedta75fece2010-11-02 14:58:27 -0400611 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400612
Steven Rostedt576f6272010-11-02 14:58:38 -0400613 my $i = $iteration;
614
Steven Rostedta75fece2010-11-02 14:58:27 -0400615 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -0400616 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400617 doprint "REBOOTING\n";
618 reboot;
619 start_monitor;
620 wait_for_monitor $sleep_time;
621 end_monitor;
622 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400623
Steven Rostedt9064af52011-06-13 10:38:48 -0400624 my $name = "";
625
626 if (defined($test_name)) {
627 $name = " ($test_name)";
628 }
629
Steven Rostedt576f6272010-11-02 14:58:38 -0400630 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
631 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -0400632 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -0400633 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
634 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400635
636 return 1 if (!defined($store_failures));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400637
638 my @t = localtime;
639 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
640 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
641
Steven Rostedtcccae1a2010-11-09 12:21:32 -0500642 my $type = $build_type;
643 if ($type =~ /useconfig/) {
644 $type = "useconfig";
645 }
646
647 my $dir = "$machine-$test_type-$type-fail-$date";
Steven Rostedta75fece2010-11-02 14:58:27 -0400648 my $faildir = "$store_failures/$dir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400649
650 if (!-d $faildir) {
651 mkpath($faildir) or
Steven Rostedta75fece2010-11-02 14:58:27 -0400652 die "can't create $faildir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400653 }
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500654 if (-f "$output_config") {
655 cp "$output_config", "$faildir/config" or
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400656 die "failed to copy .config";
657 }
658 if (-f $buildlog) {
659 cp $buildlog, "$faildir/buildlog" or
660 die "failed to move $buildlog";
661 }
662 if (-f $dmesg) {
663 cp $dmesg, "$faildir/dmesg" or
664 die "failed to move $dmesg";
665 }
666
667 doprint "*** Saved info to $faildir ***\n";
668
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400669 return 1;
670}
671
Steven Rostedt2545eb62010-11-02 15:01:32 -0400672sub run_command {
673 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400674 my $dolog = 0;
675 my $dord = 0;
676 my $pid;
677
Steven Rostedte48c5292010-11-02 14:35:37 -0400678 $command =~ s/\$SSH_USER/$ssh_user/g;
679 $command =~ s/\$MACHINE/$machine/g;
680
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400681 doprint("$command ... ");
682
683 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400684 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400685
686 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400687 open(LOG, ">>$opt{LOG_FILE}") or
688 dodie "failed to write to log";
689 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400690 }
691
692 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400693 open (RD, ">$redirect") or
694 dodie "failed to write to redirect $redirect";
695 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400696 }
697
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400698 while (<CMD>) {
699 print LOG if ($dolog);
700 print RD if ($dord);
701 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400702
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400703 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400704 my $failed = $?;
705
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400706 close(CMD);
707 close(LOG) if ($dolog);
708 close(RD) if ($dord);
709
Steven Rostedt2545eb62010-11-02 15:01:32 -0400710 if ($failed) {
711 doprint "FAILED!\n";
712 } else {
713 doprint "SUCCESS\n";
714 }
715
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400716 return !$failed;
717}
718
Steven Rostedte48c5292010-11-02 14:35:37 -0400719sub run_ssh {
720 my ($cmd) = @_;
721 my $cp_exec = $ssh_exec;
722
723 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
724 return run_command "$cp_exec";
725}
726
727sub run_scp {
728 my ($src, $dst) = @_;
729 my $cp_scp = $scp_to_target;
730
731 $cp_scp =~ s/\$SRC_FILE/$src/g;
732 $cp_scp =~ s/\$DST_FILE/$dst/g;
733
734 return run_command "$cp_scp";
735}
736
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400737sub get_grub_index {
738
Steven Rostedta75fece2010-11-02 14:58:27 -0400739 if ($reboot_type ne "grub") {
740 return;
741 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400742 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400743
744 doprint "Find grub menu ... ";
745 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -0400746
747 my $ssh_grub = $ssh_exec;
748 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
749
750 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400751 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -0400752
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400753 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400754 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400755 $grub_number++;
756 last;
757 } elsif (/^\s*title\s/) {
758 $grub_number++;
759 }
760 }
761 close(IN);
762
Steven Rostedta75fece2010-11-02 14:58:27 -0400763 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400764 if ($grub_number < 0);
765 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400766}
767
Steven Rostedt2545eb62010-11-02 15:01:32 -0400768sub wait_for_input
769{
770 my ($fp, $time) = @_;
771 my $rin;
772 my $ready;
773 my $line;
774 my $ch;
775
776 if (!defined($time)) {
777 $time = $timeout;
778 }
779
780 $rin = '';
781 vec($rin, fileno($fp), 1) = 1;
782 $ready = select($rin, undef, undef, $time);
783
784 $line = "";
785
786 # try to read one char at a time
787 while (sysread $fp, $ch, 1) {
788 $line .= $ch;
789 last if ($ch eq "\n");
790 }
791
792 if (!length($line)) {
793 return undef;
794 }
795
796 return $line;
797}
798
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400799sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -0400800 if ($reboot_type eq "grub") {
Steven Rostedt4da46da2011-06-01 23:25:13 -0400801 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
Steven Rostedta75fece2010-11-02 14:58:27 -0400802 return;
803 }
804
805 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400806}
807
Steven Rostedta57419b2010-11-02 15:13:54 -0400808sub get_sha1 {
809 my ($commit) = @_;
810
811 doprint "git rev-list --max-count=1 $commit ... ";
812 my $sha1 = `git rev-list --max-count=1 $commit`;
813 my $ret = $?;
814
815 logit $sha1;
816
817 if ($ret) {
818 doprint "FAILED\n";
819 dodie "Failed to get git $commit";
820 }
821
822 print "SUCCESS\n";
823
824 chomp $sha1;
825
826 return $sha1;
827}
828
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400829sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400830 my $booted = 0;
831 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400832 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400833 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400834
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400835 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400836
837 my $line;
838 my $full_line = "";
839
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400840 open(DMESG, "> $dmesg") or
841 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400842
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400843 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400844
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500845 my $success_start;
846 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500847 my $monitor_start = time;
848 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400849 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500850
Steven Rostedt2d01b262011-03-08 09:47:54 -0500851 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400852
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400853 if ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400854 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400855 if (!defined($line)) {
856 my $s = $booted_timeout == 1 ? "" : "s";
857 doprint "Successful boot found: break after $booted_timeout second$s\n";
858 last;
859 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400860 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400861 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400862 if (!defined($line)) {
863 my $s = $timeout == 1 ? "" : "s";
864 doprint "Timed out after $timeout second$s\n";
865 last;
866 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400867 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400868
Steven Rostedt2545eb62010-11-02 15:01:32 -0400869 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400870 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400871
872 # we are not guaranteed to get a full line
873 $full_line .= $line;
874
Steven Rostedta75fece2010-11-02 14:58:27 -0400875 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400876 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500877 $success_start = time;
878 }
879
880 if ($booted && defined($stop_after_success) &&
881 $stop_after_success >= 0) {
882 my $now = time;
883 if ($now - $success_start >= $stop_after_success) {
884 doprint "Test forced to stop after $stop_after_success seconds after success\n";
885 last;
886 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400887 }
888
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400889 if ($full_line =~ /\[ backtrace testing \]/) {
890 $skip_call_trace = 1;
891 }
892
Steven Rostedt2545eb62010-11-02 15:01:32 -0400893 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -0500894 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500895 $bug = 1;
896 $failure_start = time;
897 }
898 }
899
900 if ($bug && defined($stop_after_failure) &&
901 $stop_after_failure >= 0) {
902 my $now = time;
903 if ($now - $failure_start >= $stop_after_failure) {
904 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
905 last;
906 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400907 }
908
909 if ($full_line =~ /\[ end of backtrace testing \]/) {
910 $skip_call_trace = 0;
911 }
912
913 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -0500914 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400915 $bug = 1;
916 }
917
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400918 # Detect triple faults by testing the banner
919 if ($full_line =~ /\bLinux version (\S+).*\n/) {
920 if ($1 eq $version) {
921 $version_found = 1;
922 } elsif ($version_found && $detect_triplefault) {
923 # We already booted into the kernel we are testing,
924 # but now we booted into another kernel?
925 # Consider this a triple fault.
926 doprint "Aleady booted in Linux kernel $version, but now\n";
927 doprint "we booted into Linux kernel $1.\n";
928 doprint "Assuming that this is a triple fault.\n";
929 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
930 last;
931 }
932 }
933
Steven Rostedt2545eb62010-11-02 15:01:32 -0400934 if ($line =~ /\n/) {
935 $full_line = "";
936 }
Steven Rostedt2d01b262011-03-08 09:47:54 -0500937
938 if ($stop_test_after > 0 && !$booted && !$bug) {
939 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -0400940 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -0500941 $done = 1;
942 }
943 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400944 }
945
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400946 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400947
Steven Rostedt2545eb62010-11-02 15:01:32 -0400948 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400949 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400950 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400951 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400952
Steven Rostedta75fece2010-11-02 14:58:27 -0400953 if (!$booted) {
954 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400955 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400956 }
957
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400958 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400959}
960
961sub install {
962
Steven Rostedte48c5292010-11-02 14:35:37 -0400963 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400964 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400965
966 my $install_mods = 0;
967
968 # should we process modules?
969 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500970 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400971 while (<IN>) {
972 if (/CONFIG_MODULES(=y)?/) {
973 $install_mods = 1 if (defined($1));
974 last;
975 }
976 }
977 close(IN);
978
979 if (!$install_mods) {
980 doprint "No modules needed\n";
981 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400982 }
983
Steven Rostedta75fece2010-11-02 14:58:27 -0400984 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400985 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400986
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400987 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -0400988 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400989
Steven Rostedte48c5292010-11-02 14:35:37 -0400990 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400991 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400992
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400993 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -0400994 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400995 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400996
Steven Rostedte48c5292010-11-02 14:35:37 -0400997 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400998 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400999
Steven Rostedta75fece2010-11-02 14:58:27 -04001000 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001001
Steven Rostedte48c5292010-11-02 14:35:37 -04001002 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001003 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001004
Steven Rostedte48c5292010-11-02 14:35:37 -04001005 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001006
1007 return if (!defined($post_install));
1008
Steven Rostedte48c5292010-11-02 14:35:37 -04001009 my $cp_post_install = $post_install;
Steven Rostedtca6a21f2011-03-25 22:42:53 -04001010 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
Steven Rostedte48c5292010-11-02 14:35:37 -04001011 run_command "$cp_post_install" or
Steven Rostedt576f6272010-11-02 14:58:38 -04001012 dodie "Failed to run post install";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001013}
1014
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001015sub check_buildlog {
1016 my ($patch) = @_;
1017
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001018 my @files = `git show $patch | diffstat -l`;
1019
1020 open(IN, "git show $patch |") or
1021 dodie "failed to show $patch";
1022 while (<IN>) {
1023 if (m,^--- a/(.*),) {
1024 chomp $1;
1025 $files[$#files] = $1;
1026 }
1027 }
1028 close(IN);
1029
1030 open(IN, $buildlog) or dodie "Can't open $buildlog";
1031 while (<IN>) {
1032 if (/^\s*(.*?):.*(warning|error)/) {
1033 my $err = $1;
1034 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001035 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001036 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001037 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001038 }
1039 }
1040 }
1041 }
1042 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001043
1044 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001045}
1046
Steven Rostedt612b9e92011-03-07 13:27:43 -05001047sub make_oldconfig {
1048 my ($defconfig) = @_;
1049
1050 if (!run_command "$defconfig $make oldnoconfig") {
1051 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1052 # try a yes '' | oldconfig
1053 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1054 run_command "yes '' | $defconfig $make oldconfig" or
1055 dodie "failed make config oldconfig";
1056 }
1057}
1058
Steven Rostedt2545eb62010-11-02 15:01:32 -04001059sub build {
1060 my ($type) = @_;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001061 my $defconfig = "";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001062
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001063 unlink $buildlog;
1064
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001065 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001066 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001067 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001068
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001069 $type = "oldconfig";
1070 }
1071
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001072 # old config can ask questions
1073 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001074 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001075
1076 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001077 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001078
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001079 run_command "mv $output_config $outputdir/config_temp" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001080 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001081
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001082 if (!$noclean && !run_command "$make mrproper") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001083 dodie "make mrproper";
1084 }
1085
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001086 run_command "mv $outputdir/config_temp $output_config" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001087 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001088
1089 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001090 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001091 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001092 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001093 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001094
1095 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001096 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1097 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001098 close(OUT);
1099
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001100 if (defined($minconfig)) {
1101 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001102 }
1103
Steven Rostedt612b9e92011-03-07 13:27:43 -05001104 if ($type eq "oldnoconfig") {
1105 make_oldconfig $defconfig;
1106 } else {
1107 run_command "$defconfig $make $type" or
1108 dodie "failed make config";
1109 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001110
Steven Rostedta75fece2010-11-02 14:58:27 -04001111 $redirect = "$buildlog";
1112 if (!run_command "$make $build_options") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001113 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001114 # bisect may need this to pass
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001115 return 0 if ($in_bisect);
1116 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001117 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001118 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001119
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001120 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001121}
1122
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001123sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001124 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001125 if (defined($poweroff_after_halt)) {
1126 sleep $poweroff_after_halt;
1127 run_command "$power_off";
1128 }
1129 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001130 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001131 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001132 }
1133}
1134
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001135sub success {
1136 my ($i) = @_;
1137
Steven Rostedte48c5292010-11-02 14:35:37 -04001138 $successes++;
1139
Steven Rostedt9064af52011-06-13 10:38:48 -04001140 my $name = "";
1141
1142 if (defined($test_name)) {
1143 $name = " ($test_name)";
1144 }
1145
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001146 doprint "\n\n*******************************************\n";
1147 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001148 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001149 doprint "*******************************************\n";
1150 doprint "*******************************************\n";
1151
Steven Rostedt576f6272010-11-02 14:58:38 -04001152 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001153 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001154 reboot;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001155 start_monitor;
Steven Rostedta75fece2010-11-02 14:58:27 -04001156 wait_for_monitor $sleep_time;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001157 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001158 }
1159}
1160
1161sub get_version {
1162 # get the release name
1163 doprint "$make kernelrelease ... ";
1164 $version = `$make kernelrelease | tail -1`;
1165 chomp($version);
1166 doprint "$version\n";
1167}
1168
Steven Rostedtc960bb92011-03-08 09:22:39 -05001169sub answer_bisect {
1170 for (;;) {
1171 doprint "Pass or fail? [p/f]";
1172 my $ans = <STDIN>;
1173 chomp $ans;
1174 if ($ans eq "p" || $ans eq "P") {
1175 return 1;
1176 } elsif ($ans eq "f" || $ans eq "F") {
1177 return 0;
1178 } else {
1179 print "Please answer 'P' or 'F'\n";
1180 }
1181 }
1182}
1183
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001184sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001185 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001186
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001187 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001188 $reboot_on_error = 0;
1189 $poweroff_on_error = 0;
1190 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001191
1192 run_command $run_test or $failed = 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001193 exit $failed;
1194}
1195
1196my $child_done;
1197
1198sub child_finished {
1199 $child_done = 1;
1200}
1201
1202sub do_run_test {
1203 my $child_pid;
1204 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001205 my $line;
1206 my $full_line;
1207 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001208
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001209 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001210
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001211 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001212
1213 $child_done = 0;
1214
1215 $SIG{CHLD} = qw(child_finished);
1216
1217 $child_pid = fork;
1218
1219 child_run_test if (!$child_pid);
1220
1221 $full_line = "";
1222
1223 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001224 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001225 if (defined($line)) {
1226
1227 # we are not guaranteed to get a full line
1228 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001229 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001230
1231 if ($full_line =~ /call trace:/i) {
1232 $bug = 1;
1233 }
1234
1235 if ($full_line =~ /Kernel panic -/) {
1236 $bug = 1;
1237 }
1238
1239 if ($line =~ /\n/) {
1240 $full_line = "";
1241 }
1242 }
1243 } while (!$child_done && !$bug);
1244
1245 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001246 my $failure_start = time;
1247 my $now;
1248 do {
1249 $line = wait_for_input($monitor_fp, 1);
1250 if (defined($line)) {
1251 doprint $line;
1252 }
1253 $now = time;
1254 if ($now - $failure_start >= $stop_after_failure) {
1255 last;
1256 }
1257 } while (defined($line));
1258
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001259 doprint "Detected kernel crash!\n";
1260 # kill the child with extreme prejudice
1261 kill 9, $child_pid;
1262 }
1263
1264 waitpid $child_pid, 0;
1265 $child_exit = $?;
1266
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001267 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001268 return 0 if $in_bisect;
1269 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001270 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001271 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001272}
1273
Steven Rostedta75fece2010-11-02 14:58:27 -04001274sub run_git_bisect {
1275 my ($command) = @_;
1276
1277 doprint "$command ... ";
1278
1279 my $output = `$command 2>&1`;
1280 my $ret = $?;
1281
1282 logit $output;
1283
1284 if ($ret) {
1285 doprint "FAILED\n";
1286 dodie "Failed to git bisect";
1287 }
1288
1289 doprint "SUCCESS\n";
1290 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1291 doprint "$1 [$2]\n";
1292 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1293 $bisect_bad = $1;
1294 doprint "Found bad commit... $1\n";
1295 return 0;
1296 } else {
1297 # we already logged it, just print it now.
1298 print $output;
1299 }
1300
1301 return 1;
1302}
1303
Steven Rostedtc23dca72011-03-08 09:26:31 -05001304sub bisect_reboot {
1305 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1306 reboot;
1307 start_monitor;
1308 wait_for_monitor $bisect_sleep_time;
1309 end_monitor;
1310}
1311
1312# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001313sub run_bisect_test {
1314 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001315
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001316 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001317 my $result;
1318 my $output;
1319 my $ret;
1320
Steven Rostedt0a05c762010-11-08 11:14:10 -05001321 $in_bisect = 1;
1322
1323 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001324
1325 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001326 if ($failed && $bisect_skip) {
1327 $in_bisect = 0;
1328 return -1;
1329 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001330 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001331
1332 # Now boot the box
1333 get_grub_index;
1334 get_version;
1335 install;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001336
1337 start_monitor;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001338 monitor or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001339
1340 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001341 if ($failed && $bisect_skip) {
1342 end_monitor;
1343 bisect_reboot;
1344 $in_bisect = 0;
1345 return -1;
1346 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001347 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001348
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001349 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001350 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001351 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001352 }
1353
1354 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001355 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001356 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001357 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001358 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001359
1360 # reboot the box to a kernel we can ssh to
1361 if ($type ne "build") {
1362 bisect_reboot;
1363 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001364 $in_bisect = 0;
1365
1366 return $result;
1367}
1368
1369sub run_bisect {
1370 my ($type) = @_;
1371 my $buildtype = "oldconfig";
1372
1373 # We should have a minconfig to use?
1374 if (defined($minconfig)) {
1375 $buildtype = "useconfig:$minconfig";
1376 }
1377
1378 my $ret = run_bisect_test $type, $buildtype;
1379
Steven Rostedtc960bb92011-03-08 09:22:39 -05001380 if ($bisect_manual) {
1381 $ret = answer_bisect;
1382 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001383
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001384 # Are we looking for where it worked, not failed?
1385 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001386 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001387 }
1388
Steven Rostedtc23dca72011-03-08 09:26:31 -05001389 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001390 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001391 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001392 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001393 } elsif ($bisect_skip) {
1394 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1395 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001396 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001397}
1398
1399sub bisect {
1400 my ($i) = @_;
1401
1402 my $result;
1403
1404 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1405 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1406 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1407
1408 my $good = $opt{"BISECT_GOOD[$i]"};
1409 my $bad = $opt{"BISECT_BAD[$i]"};
1410 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001411 my $start = $opt{"BISECT_START[$i]"};
1412 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001413 my $start_files = $opt{"BISECT_FILES[$i]"};
1414
1415 if (defined($start_files)) {
1416 $start_files = " -- " . $start_files;
1417 } else {
1418 $start_files = "";
1419 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001420
Steven Rostedta57419b2010-11-02 15:13:54 -04001421 # convert to true sha1's
1422 $good = get_sha1($good);
1423 $bad = get_sha1($bad);
1424
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001425 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1426 $opt{"BISECT_REVERSE[$i]"} == 1) {
1427 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1428 $reverse_bisect = 1;
1429 } else {
1430 $reverse_bisect = 0;
1431 }
1432
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001433 # Can't have a test without having a test to run
1434 if ($type eq "test" && !defined($run_test)) {
1435 $type = "boot";
1436 }
1437
Steven Rostedta75fece2010-11-02 14:58:27 -04001438 my $check = $opt{"BISECT_CHECK[$i]"};
1439 if (defined($check) && $check ne "0") {
1440
1441 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001442 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001443
1444 if ($check ne "good") {
1445 doprint "TESTING BISECT BAD [$bad]\n";
1446 run_command "git checkout $bad" or
1447 die "Failed to checkout $bad";
1448
1449 $result = run_bisect $type;
1450
1451 if ($result ne "bad") {
1452 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1453 }
1454 }
1455
1456 if ($check ne "bad") {
1457 doprint "TESTING BISECT GOOD [$good]\n";
1458 run_command "git checkout $good" or
1459 die "Failed to checkout $good";
1460
1461 $result = run_bisect $type;
1462
1463 if ($result ne "good") {
1464 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1465 }
1466 }
1467
1468 # checkout where we started
1469 run_command "git checkout $head" or
1470 die "Failed to checkout $head";
1471 }
1472
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001473 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001474 dodie "could not start bisect";
1475
1476 run_command "git bisect good $good" or
1477 dodie "could not set bisect good to $good";
1478
1479 run_git_bisect "git bisect bad $bad" or
1480 dodie "could not set bisect bad to $bad";
1481
1482 if (defined($replay)) {
1483 run_command "git bisect replay $replay" or
1484 dodie "failed to run replay";
1485 }
1486
1487 if (defined($start)) {
1488 run_command "git checkout $start" or
1489 dodie "failed to checkout $start";
1490 }
1491
1492 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001493 do {
1494 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001495 $test = run_git_bisect "git bisect $result";
1496 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001497
1498 run_command "git bisect log" or
1499 dodie "could not capture git bisect log";
1500
1501 run_command "git bisect reset" or
1502 dodie "could not reset git bisect";
1503
1504 doprint "Bad commit was [$bisect_bad]\n";
1505
Steven Rostedt0a05c762010-11-08 11:14:10 -05001506 success $i;
1507}
1508
1509my %config_ignore;
1510my %config_set;
1511
1512my %config_list;
1513my %null_config;
1514
1515my %dependency;
1516
1517sub process_config_ignore {
1518 my ($config) = @_;
1519
1520 open (IN, $config)
1521 or dodie "Failed to read $config";
1522
1523 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04001524 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001525 $config_ignore{$2} = $1;
1526 }
1527 }
1528
1529 close(IN);
1530}
1531
1532sub read_current_config {
1533 my ($config_ref) = @_;
1534
1535 %{$config_ref} = ();
1536 undef %{$config_ref};
1537
1538 my @key = keys %{$config_ref};
1539 if ($#key >= 0) {
1540 print "did not delete!\n";
1541 exit;
1542 }
1543 open (IN, "$output_config");
1544
1545 while (<IN>) {
1546 if (/^(CONFIG\S+)=(.*)/) {
1547 ${$config_ref}{$1} = $2;
1548 }
1549 }
1550 close(IN);
1551}
1552
1553sub get_dependencies {
1554 my ($config) = @_;
1555
1556 my $arr = $dependency{$config};
1557 if (!defined($arr)) {
1558 return ();
1559 }
1560
1561 my @deps = @{$arr};
1562
1563 foreach my $dep (@{$arr}) {
1564 print "ADD DEP $dep\n";
1565 @deps = (@deps, get_dependencies $dep);
1566 }
1567
1568 return @deps;
1569}
1570
1571sub create_config {
1572 my @configs = @_;
1573
1574 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1575
1576 foreach my $config (@configs) {
1577 print OUT "$config_set{$config}\n";
1578 my @deps = get_dependencies $config;
1579 foreach my $dep (@deps) {
1580 print OUT "$config_set{$dep}\n";
1581 }
1582 }
1583
1584 foreach my $config (keys %config_ignore) {
1585 print OUT "$config_ignore{$config}\n";
1586 }
1587 close(OUT);
1588
1589# exit;
Steven Rostedt612b9e92011-03-07 13:27:43 -05001590 make_oldconfig "";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001591}
1592
1593sub compare_configs {
1594 my (%a, %b) = @_;
1595
1596 foreach my $item (keys %a) {
1597 if (!defined($b{$item})) {
1598 print "diff $item\n";
1599 return 1;
1600 }
1601 delete $b{$item};
1602 }
1603
1604 my @keys = keys %b;
1605 if ($#keys) {
1606 print "diff2 $keys[0]\n";
1607 }
1608 return -1 if ($#keys >= 0);
1609
1610 return 0;
1611}
1612
1613sub run_config_bisect_test {
1614 my ($type) = @_;
1615
1616 return run_bisect_test $type, "oldconfig";
1617}
1618
1619sub process_passed {
1620 my (%configs) = @_;
1621
1622 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1623 # Passed! All these configs are part of a good compile.
1624 # Add them to the min options.
1625 foreach my $config (keys %configs) {
1626 if (defined($config_list{$config})) {
1627 doprint " removing $config\n";
1628 $config_ignore{$config} = $config_list{$config};
1629 delete $config_list{$config};
1630 }
1631 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05001632 doprint "config copied to $outputdir/config_good\n";
1633 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001634}
1635
1636sub process_failed {
1637 my ($config) = @_;
1638
1639 doprint "\n\n***************************************\n";
1640 doprint "Found bad config: $config\n";
1641 doprint "***************************************\n\n";
1642}
1643
1644sub run_config_bisect {
1645
1646 my @start_list = keys %config_list;
1647
1648 if ($#start_list < 0) {
1649 doprint "No more configs to test!!!\n";
1650 return -1;
1651 }
1652
1653 doprint "***** RUN TEST ***\n";
1654 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1655 my $ret;
1656 my %current_config;
1657
1658 my $count = $#start_list + 1;
1659 doprint " $count configs to test\n";
1660
1661 my $half = int($#start_list / 2);
1662
1663 do {
1664 my @tophalf = @start_list[0 .. $half];
1665
1666 create_config @tophalf;
1667 read_current_config \%current_config;
1668
1669 $count = $#tophalf + 1;
1670 doprint "Testing $count configs\n";
1671 my $found = 0;
1672 # make sure we test something
1673 foreach my $config (@tophalf) {
1674 if (defined($current_config{$config})) {
1675 logit " $config\n";
1676 $found = 1;
1677 }
1678 }
1679 if (!$found) {
1680 # try the other half
1681 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001682 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05001683 create_config @tophalf;
1684 read_current_config \%current_config;
1685 foreach my $config (@tophalf) {
1686 if (defined($current_config{$config})) {
1687 logit " $config\n";
1688 $found = 1;
1689 }
1690 }
1691 if (!$found) {
1692 doprint "Failed: Can't make new config with current configs\n";
1693 foreach my $config (@start_list) {
1694 doprint " CONFIG: $config\n";
1695 }
1696 return -1;
1697 }
1698 $count = $#tophalf + 1;
1699 doprint "Testing $count configs\n";
1700 }
1701
1702 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05001703 if ($bisect_manual) {
1704 $ret = answer_bisect;
1705 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001706 if ($ret) {
1707 process_passed %current_config;
1708 return 0;
1709 }
1710
1711 doprint "This config had a failure.\n";
1712 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05001713 doprint "config copied to $outputdir/config_bad\n";
1714 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001715
1716 # A config exists in this group that was bad.
1717 foreach my $config (keys %config_list) {
1718 if (!defined($current_config{$config})) {
1719 doprint " removing $config\n";
1720 delete $config_list{$config};
1721 }
1722 }
1723
1724 @start_list = @tophalf;
1725
1726 if ($#start_list == 0) {
1727 process_failed $start_list[0];
1728 return 1;
1729 }
1730
1731 # remove half the configs we are looking at and see if
1732 # they are good.
1733 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001734 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05001735
Steven Rostedtc960bb92011-03-08 09:22:39 -05001736 # we found a single config, try it again unless we are running manually
1737
1738 if ($bisect_manual) {
1739 process_failed $start_list[0];
1740 return 1;
1741 }
1742
Steven Rostedt0a05c762010-11-08 11:14:10 -05001743 my @tophalf = @start_list[0 .. 0];
1744
1745 $ret = run_config_bisect_test $type;
1746 if ($ret) {
1747 process_passed %current_config;
1748 return 0;
1749 }
1750
1751 process_failed $start_list[0];
1752 return 1;
1753}
1754
1755sub config_bisect {
1756 my ($i) = @_;
1757
1758 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1759
1760 my $tmpconfig = "$tmpdir/use_config";
1761
Steven Rostedt30f75da2011-06-13 10:35:35 -04001762 if (defined($config_bisect_good)) {
1763 process_config_ignore $config_bisect_good;
1764 }
1765
Steven Rostedt0a05c762010-11-08 11:14:10 -05001766 # Make the file with the bad config and the min config
1767 if (defined($minconfig)) {
1768 # read the min config for things to ignore
1769 run_command "cp $minconfig $tmpconfig" or
1770 dodie "failed to copy $minconfig to $tmpconfig";
1771 } else {
1772 unlink $tmpconfig;
1773 }
1774
1775 # Add other configs
1776 if (defined($addconfig)) {
1777 run_command "cat $addconfig >> $tmpconfig" or
1778 dodie "failed to append $addconfig";
1779 }
1780
1781 my $defconfig = "";
1782 if (-f $tmpconfig) {
1783 $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
1784 process_config_ignore $tmpconfig;
1785 }
1786
1787 # now process the start config
1788 run_command "cp $start_config $output_config" or
1789 dodie "failed to copy $start_config to $output_config";
1790
1791 # read directly what we want to check
1792 my %config_check;
1793 open (IN, $output_config)
1794 or dodie "faied to open $output_config";
1795
1796 while (<IN>) {
1797 if (/^((CONFIG\S*)=.*)/) {
1798 $config_check{$2} = $1;
1799 }
1800 }
1801 close(IN);
1802
1803 # Now run oldconfig with the minconfig (and addconfigs)
Steven Rostedt612b9e92011-03-07 13:27:43 -05001804 make_oldconfig $defconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001805
1806 # check to see what we lost (or gained)
1807 open (IN, $output_config)
1808 or dodie "Failed to read $start_config";
1809
1810 my %removed_configs;
1811 my %added_configs;
1812
1813 while (<IN>) {
1814 if (/^((CONFIG\S*)=.*)/) {
1815 # save off all options
1816 $config_set{$2} = $1;
1817 if (defined($config_check{$2})) {
1818 if (defined($config_ignore{$2})) {
1819 $removed_configs{$2} = $1;
1820 } else {
1821 $config_list{$2} = $1;
1822 }
1823 } elsif (!defined($config_ignore{$2})) {
1824 $added_configs{$2} = $1;
1825 $config_list{$2} = $1;
1826 }
1827 }
1828 }
1829 close(IN);
1830
1831 my @confs = keys %removed_configs;
1832 if ($#confs >= 0) {
1833 doprint "Configs overridden by default configs and removed from check:\n";
1834 foreach my $config (@confs) {
1835 doprint " $config\n";
1836 }
1837 }
1838 @confs = keys %added_configs;
1839 if ($#confs >= 0) {
1840 doprint "Configs appearing in make oldconfig and added:\n";
1841 foreach my $config (@confs) {
1842 doprint " $config\n";
1843 }
1844 }
1845
1846 my %config_test;
1847 my $once = 0;
1848
1849 # Sometimes kconfig does weird things. We must make sure
1850 # that the config we autocreate has everything we need
1851 # to test, otherwise we may miss testing configs, or
1852 # may not be able to create a new config.
1853 # Here we create a config with everything set.
1854 create_config (keys %config_list);
1855 read_current_config \%config_test;
1856 foreach my $config (keys %config_list) {
1857 if (!defined($config_test{$config})) {
1858 if (!$once) {
1859 $once = 1;
1860 doprint "Configs not produced by kconfig (will not be checked):\n";
1861 }
1862 doprint " $config\n";
1863 delete $config_list{$config};
1864 }
1865 }
1866 my $ret;
1867 do {
1868 $ret = run_config_bisect;
1869 } while (!$ret);
1870
1871 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001872
1873 success $i;
1874}
1875
Steven Rostedt27d934b2011-05-20 09:18:18 -04001876sub patchcheck_reboot {
1877 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
1878 reboot;
1879 start_monitor;
1880 wait_for_monitor $patchcheck_sleep_time;
1881 end_monitor;
1882}
1883
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001884sub patchcheck {
1885 my ($i) = @_;
1886
1887 die "PATCHCHECK_START[$i] not defined\n"
1888 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1889 die "PATCHCHECK_TYPE[$i] not defined\n"
1890 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1891
1892 my $start = $opt{"PATCHCHECK_START[$i]"};
1893
1894 my $end = "HEAD";
1895 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1896 $end = $opt{"PATCHCHECK_END[$i]"};
1897 }
1898
Steven Rostedta57419b2010-11-02 15:13:54 -04001899 # Get the true sha1's since we can use things like HEAD~3
1900 $start = get_sha1($start);
1901 $end = get_sha1($end);
1902
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001903 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1904
1905 # Can't have a test without having a test to run
1906 if ($type eq "test" && !defined($run_test)) {
1907 $type = "boot";
1908 }
1909
1910 open (IN, "git log --pretty=oneline $end|") or
1911 dodie "could not get git list";
1912
1913 my @list;
1914
1915 while (<IN>) {
1916 chomp;
1917 $list[$#list+1] = $_;
1918 last if (/^$start/);
1919 }
1920 close(IN);
1921
1922 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001923 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001924 }
1925
1926 # go backwards in the list
1927 @list = reverse @list;
1928
1929 my $save_clean = $noclean;
1930
1931 $in_patchcheck = 1;
1932 foreach my $item (@list) {
1933 my $sha1 = $item;
1934 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1935
1936 doprint "\nProcessing commit $item\n\n";
1937
1938 run_command "git checkout $sha1" or
1939 die "Failed to checkout $sha1";
1940
1941 # only clean on the first and last patch
1942 if ($item eq $list[0] ||
1943 $item eq $list[$#list]) {
1944 $noclean = $save_clean;
1945 } else {
1946 $noclean = 1;
1947 }
1948
1949 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001950 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001951 } else {
1952 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001953 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001954 }
1955
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001956 check_buildlog $sha1 or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001957
1958 next if ($type eq "build");
1959
1960 get_grub_index;
1961 get_version;
1962 install;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001963
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001964 my $failed = 0;
1965
1966 start_monitor;
1967 monitor or $failed = 1;
1968
1969 if (!$failed && $type ne "boot"){
1970 do_run_test or $failed = 1;
1971 }
1972 end_monitor;
1973 return 0 if ($failed);
1974
Steven Rostedt27d934b2011-05-20 09:18:18 -04001975 patchcheck_reboot;
1976
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001977 }
1978 $in_patchcheck = 0;
1979 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001980
1981 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001982}
1983
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001984$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001985
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001986if ($#ARGV == 0) {
1987 $ktest_config = $ARGV[0];
1988 if (! -f $ktest_config) {
1989 print "$ktest_config does not exist.\n";
1990 my $ans;
1991 for (;;) {
1992 print "Create it? [Y/n] ";
1993 $ans = <STDIN>;
1994 chomp $ans;
1995 if ($ans =~ /^\s*$/) {
1996 $ans = "y";
1997 }
1998 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
1999 print "Please answer either 'y' or 'n'.\n";
2000 }
2001 if ($ans !~ /^y$/i) {
2002 exit 0;
2003 }
2004 }
2005} else {
2006 $ktest_config = "ktest.conf";
2007}
2008
2009if (! -f $ktest_config) {
2010 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
2011 print OUT << "EOF"
2012# Generated by ktest.pl
2013#
2014# Define each test with TEST_START
2015# The config options below it will override the defaults
2016TEST_START
2017
2018DEFAULTS
2019EOF
2020;
2021 close(OUT);
2022}
2023read_config $ktest_config;
2024
2025# Append any configs entered in manually to the config file.
2026my @new_configs = keys %entered_configs;
2027if ($#new_configs >= 0) {
2028 print "\nAppending entered in configs to $ktest_config\n";
2029 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
2030 foreach my $config (@new_configs) {
2031 print OUT "$config = $entered_configs{$config}\n";
2032 $opt{$config} = $entered_configs{$config};
2033 }
2034}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002035
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002036if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2037 unlink $opt{"LOG_FILE"};
2038}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002039
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002040doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2041
Steven Rostedta57419b2010-11-02 15:13:54 -04002042for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2043
2044 if (!$i) {
2045 doprint "DEFAULT OPTIONS:\n";
2046 } else {
2047 doprint "\nTEST $i OPTIONS";
2048 if (defined($repeat_tests{$i})) {
2049 $repeat = $repeat_tests{$i};
2050 doprint " ITERATE $repeat";
2051 }
2052 doprint "\n";
2053 }
2054
2055 foreach my $option (sort keys %opt) {
2056
2057 if ($option =~ /\[(\d+)\]$/) {
2058 next if ($i != $1);
2059 } else {
2060 next if ($i);
2061 }
2062
2063 doprint "$option = $opt{$option}\n";
2064 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002065}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002066
Steven Rostedt2a625122011-05-20 15:48:59 -04002067sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002068 my ($name, $i) = @_;
2069
2070 my $option = "$name\[$i\]";
2071
2072 if (defined($opt{$option})) {
2073 return $opt{$option};
2074 }
2075
Steven Rostedta57419b2010-11-02 15:13:54 -04002076 foreach my $test (keys %repeat_tests) {
2077 if ($i >= $test &&
2078 $i < $test + $repeat_tests{$test}) {
2079 $option = "$name\[$test\]";
2080 if (defined($opt{$option})) {
2081 return $opt{$option};
2082 }
2083 }
2084 }
2085
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002086 if (defined($opt{$name})) {
2087 return $opt{$name};
2088 }
2089
2090 return undef;
2091}
2092
Steven Rostedt2a625122011-05-20 15:48:59 -04002093sub eval_option {
2094 my ($option, $i) = @_;
2095
2096 # Add space to evaluate the character before $
2097 $option = " $option";
2098 my $retval = "";
2099
2100 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
2101 my $start = $1;
2102 my $var = $2;
2103 my $end = $3;
2104
2105 # Append beginning of line
2106 $retval = "$retval$start";
2107
2108 # If the iteration option OPT[$i] exists, then use that.
2109 # otherwise see if the default OPT (without [$i]) exists.
2110
2111 my $o = "$var\[$i\]";
2112
2113 if (defined($opt{$o})) {
2114 $o = $opt{$o};
2115 $retval = "$retval$o";
2116 } elsif (defined($opt{$var})) {
2117 $o = $opt{$var};
2118 $retval = "$retval$o";
2119 } else {
2120 $retval = "$retval\$\{$var\}";
2121 }
2122
2123 $option = $end;
2124 }
2125
2126 $retval = "$retval$option";
2127
2128 $retval =~ s/^ //;
2129
2130 return $retval;
2131}
2132
2133sub set_test_option {
2134 my ($name, $i) = @_;
2135
2136 my $option = __set_test_option($name, $i);
2137 return $option if (!defined($option));
2138
2139 my $prev = "";
2140
2141 # Since an option can evaluate to another option,
2142 # keep iterating until we do not evaluate any more
2143 # options.
2144 my $r = 0;
2145 while ($prev ne $option) {
2146 # Check for recursive evaluations.
2147 # 100 deep should be more than enough.
2148 if ($r++ > 100) {
2149 die "Over 100 evaluations accurred with $name\n" .
2150 "Check for recursive variables\n";
2151 }
2152 $prev = $option;
2153 $option = eval_option($option, $i);
2154 }
2155
2156 return $option;
2157}
2158
Steven Rostedt2545eb62010-11-02 15:01:32 -04002159# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04002160for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04002161
Steven Rostedt576f6272010-11-02 14:58:38 -04002162 $iteration = $i;
2163
Steven Rostedta75fece2010-11-02 14:58:27 -04002164 my $makecmd = set_test_option("MAKE_CMD", $i);
2165
2166 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002167 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002168 $tmpdir = set_test_option("TMP_DIR", $i);
2169 $outputdir = set_test_option("OUTPUT_DIR", $i);
2170 $builddir = set_test_option("BUILD_DIR", $i);
2171 $test_type = set_test_option("TEST_TYPE", $i);
2172 $build_type = set_test_option("BUILD_TYPE", $i);
2173 $build_options = set_test_option("BUILD_OPTIONS", $i);
2174 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002175 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002176 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2177 $minconfig = set_test_option("MIN_CONFIG", $i);
2178 $run_test = set_test_option("TEST", $i);
2179 $addconfig = set_test_option("ADD_CONFIG", $i);
2180 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2181 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002182 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002183 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2184 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2185 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2186 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2187 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04002188 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2189 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002190 $sleep_time = set_test_option("SLEEP_TIME", $i);
2191 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04002192 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05002193 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05002194 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedt30f75da2011-06-13 10:35:35 -04002195 $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002196 $store_failures = set_test_option("STORE_FAILURES", $i);
Steven Rostedt9064af52011-06-13 10:38:48 -04002197 $test_name = set_test_option("TEST_NAME", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002198 $timeout = set_test_option("TIMEOUT", $i);
2199 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2200 $console = set_test_option("CONSOLE", $i);
Steven Rostedtf1a5b962011-06-13 10:30:00 -04002201 $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002202 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002203 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2204 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05002205 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002206 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002207 $ssh_exec = set_test_option("SSH_EXEC", $i);
2208 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002209 $target_image = set_test_option("TARGET_IMAGE", $i);
2210 $localversion = set_test_option("LOCALVERSION", $i);
2211
2212 chdir $builddir || die "can't change directory to $builddir";
2213
2214 if (!-d $tmpdir) {
2215 mkpath($tmpdir) or
2216 die "can't create $tmpdir";
2217 }
2218
Steven Rostedte48c5292010-11-02 14:35:37 -04002219 $ENV{"SSH_USER"} = $ssh_user;
2220 $ENV{"MACHINE"} = $machine;
2221
Steven Rostedta75fece2010-11-02 14:58:27 -04002222 $target = "$ssh_user\@$machine";
2223
2224 $buildlog = "$tmpdir/buildlog-$machine";
2225 $dmesg = "$tmpdir/dmesg-$machine";
2226 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002227 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04002228
2229 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04002230 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04002231 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002232 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04002233 }
2234
2235 my $run_type = $build_type;
2236 if ($test_type eq "patchcheck") {
2237 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2238 } elsif ($test_type eq "bisect") {
2239 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002240 } elsif ($test_type eq "config_bisect") {
2241 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04002242 }
2243
2244 # mistake in config file?
2245 if (!defined($run_type)) {
2246 $run_type = "ERROR";
2247 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002248
2249 doprint "\n\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04002250 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002251
2252 unlink $dmesg;
2253 unlink $buildlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002254
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002255 if (!defined($minconfig)) {
2256 $minconfig = $addconfig;
2257
2258 } elsif (defined($addconfig)) {
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002259 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002260 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002261 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002262 }
2263
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002264 my $checkout = $opt{"CHECKOUT[$i]"};
2265 if (defined($checkout)) {
2266 run_command "git checkout $checkout" or
2267 die "failed to checkout $checkout";
2268 }
2269
Steven Rostedta75fece2010-11-02 14:58:27 -04002270 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002271 bisect $i;
2272 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002273 } elsif ($test_type eq "config_bisect") {
2274 config_bisect $i;
2275 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04002276 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002277 patchcheck $i;
2278 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002279 }
2280
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002281 if ($build_type ne "nobuild") {
2282 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002283 }
2284
Steven Rostedta75fece2010-11-02 14:58:27 -04002285 if ($test_type ne "build") {
2286 get_grub_index;
2287 get_version;
2288 install;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002289
Steven Rostedta75fece2010-11-02 14:58:27 -04002290 my $failed = 0;
2291 start_monitor;
2292 monitor or $failed = 1;;
2293
2294 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2295 do_run_test or $failed = 1;
2296 }
2297 end_monitor;
2298 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002299 }
2300
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002301 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002302}
2303
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002304if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002305 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04002306} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002307 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002308}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002309
Steven Rostedte48c5292010-11-02 14:35:37 -04002310doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
2311
Steven Rostedt2545eb62010-11-02 15:01:32 -04002312exit 0;