blob: b96d3819c42e9d37a3c8548a1e70d8cc5e885089 [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:";
44$default{"BOOTED_TIMEOUT"} = 1;
45$default{"DIE_ON_FAILURE"} = 1;
Steven Rostedte48c5292010-11-02 14:35:37 -040046$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
47$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
48$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
Steven Rostedt1c8a6172010-11-09 12:55:40 -050049$default{"STOP_AFTER_SUCCESS"} = 10;
50$default{"STOP_AFTER_FAILURE"} = 60;
Steven Rostedt2d01b262011-03-08 09:47:54 -050051$default{"STOP_TEST_AFTER"} = 600;
Steven Rostedt8d1491b2010-11-18 15:39:48 -050052$default{"LOCALVERSION"} = "-test";
Steven Rostedt2545eb62010-11-02 15:01:32 -040053
Steven Rostedt8d1491b2010-11-18 15:39:48 -050054my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040055my $version;
Steven Rostedta75fece2010-11-02 14:58:27 -040056my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040057my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040058my $tmpdir;
59my $builddir;
60my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050061my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040062my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040063my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040064my $build_options;
65my $reboot_type;
66my $reboot_script;
67my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040068my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040069my $reboot_on_error;
70my $poweroff_on_error;
71my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040072my $powercycle_after_reboot;
73my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -040074my $ssh_exec;
75my $scp_to_target;
Steven Rostedta75fece2010-11-02 14:58:27 -040076my $power_off;
77my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -040078my $grub_number;
79my $target;
80my $make;
Steven Rostedt8b37ca82010-11-02 14:58:33 -040081my $post_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -040082my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040083my $minconfig;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -040084my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -040085my $in_bisect = 0;
86my $bisect_bad = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -040087my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -050088my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -050089my $bisect_skip;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -040090my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -040091my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -040092my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040093my $buildlog;
94my $dmesg;
95my $monitor_fp;
96my $monitor_pid;
97my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040098my $sleep_time;
99my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400100my $patchcheck_sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -0400101my $store_failures;
102my $timeout;
103my $booted_timeout;
104my $console;
105my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500106my $stop_after_success;
107my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500108my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400109my $build_target;
110my $target_image;
111my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400112my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400113my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400114
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500115my %entered_configs;
116my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400117my %variable;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500118
119$config_help{"MACHINE"} = << "EOF"
120 The machine hostname that you will test.
121EOF
122 ;
123$config_help{"SSH_USER"} = << "EOF"
124 The box is expected to have ssh on normal bootup, provide the user
125 (most likely root, since you need privileged operations)
126EOF
127 ;
128$config_help{"BUILD_DIR"} = << "EOF"
129 The directory that contains the Linux source code (full path).
130EOF
131 ;
132$config_help{"OUTPUT_DIR"} = << "EOF"
133 The directory that the objects will be built (full path).
134 (can not be same as BUILD_DIR)
135EOF
136 ;
137$config_help{"BUILD_TARGET"} = << "EOF"
138 The location of the compiled file to copy to the target.
139 (relative to OUTPUT_DIR)
140EOF
141 ;
142$config_help{"TARGET_IMAGE"} = << "EOF"
143 The place to put your image on the test machine.
144EOF
145 ;
146$config_help{"POWER_CYCLE"} = << "EOF"
147 A script or command to reboot the box.
148
149 Here is a digital loggers power switch example
150 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
151
152 Here is an example to reboot a virtual box on the current host
153 with the name "Guest".
154 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
155EOF
156 ;
157$config_help{"CONSOLE"} = << "EOF"
158 The script or command that reads the console
159
160 If you use ttywatch server, something like the following would work.
161CONSOLE = nc -d localhost 3001
162
163 For a virtual machine with guest name "Guest".
164CONSOLE = virsh console Guest
165EOF
166 ;
167$config_help{"LOCALVERSION"} = << "EOF"
168 Required version ending to differentiate the test
169 from other linux builds on the system.
170EOF
171 ;
172$config_help{"REBOOT_TYPE"} = << "EOF"
173 Way to reboot the box to the test kernel.
174 Only valid options so far are "grub" and "script".
175
176 If you specify grub, it will assume grub version 1
177 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
178 and select that target to reboot to the kernel. If this is not
179 your setup, then specify "script" and have a command or script
180 specified in REBOOT_SCRIPT to boot to the target.
181
182 The entry in /boot/grub/menu.lst must be entered in manually.
183 The test will not modify that file.
184EOF
185 ;
186$config_help{"GRUB_MENU"} = << "EOF"
187 The grub title name for the test kernel to boot
188 (Only mandatory if REBOOT_TYPE = grub)
189
190 Note, ktest.pl will not update the grub menu.lst, you need to
191 manually add an option for the test. ktest.pl will search
192 the grub menu.lst for this option to find what kernel to
193 reboot into.
194
195 For example, if in the /boot/grub/menu.lst the test kernel title has:
196 title Test Kernel
197 kernel vmlinuz-test
198 GRUB_MENU = Test Kernel
199EOF
200 ;
201$config_help{"REBOOT_SCRIPT"} = << "EOF"
202 A script to reboot the target into the test kernel
203 (Only mandatory if REBOOT_TYPE = script)
204EOF
205 ;
206
207
208sub get_ktest_config {
209 my ($config) = @_;
210
211 return if (defined($opt{$config}));
212
213 if (defined($config_help{$config})) {
214 print "\n";
215 print $config_help{$config};
216 }
217
218 for (;;) {
219 print "$config = ";
220 if (defined($default{$config})) {
221 print "\[$default{$config}\] ";
222 }
223 $entered_configs{$config} = <STDIN>;
224 $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;
225 if ($entered_configs{$config} =~ /^\s*$/) {
226 if ($default{$config}) {
227 $entered_configs{$config} = $default{$config};
228 } else {
229 print "Your answer can not be blank\n";
230 next;
231 }
232 }
233 last;
234 }
235}
236
237sub get_ktest_configs {
238 get_ktest_config("MACHINE");
239 get_ktest_config("SSH_USER");
240 get_ktest_config("BUILD_DIR");
241 get_ktest_config("OUTPUT_DIR");
242 get_ktest_config("BUILD_TARGET");
243 get_ktest_config("TARGET_IMAGE");
244 get_ktest_config("POWER_CYCLE");
245 get_ktest_config("CONSOLE");
246 get_ktest_config("LOCALVERSION");
247
248 my $rtype = $opt{"REBOOT_TYPE"};
249
250 if (!defined($rtype)) {
251 if (!defined($opt{"GRUB_MENU"})) {
252 get_ktest_config("REBOOT_TYPE");
253 $rtype = $entered_configs{"REBOOT_TYPE"};
254 } else {
255 $rtype = "grub";
256 }
257 }
258
259 if ($rtype eq "grub") {
260 get_ktest_config("GRUB_MENU");
261 } else {
262 get_ktest_config("REBOOT_SCRIPT");
263 }
264}
265
Steven Rostedt77d942c2011-05-20 13:36:58 -0400266sub process_variables {
267 my ($value) = @_;
268 my $retval = "";
269
270 # We want to check for '\', and it is just easier
271 # to check the previous characet of '$' and not need
272 # to worry if '$' is the first character. By adding
273 # a space to $value, we can just check [^\\]\$ and
274 # it will still work.
275 $value = " $value";
276
277 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
278 my $begin = $1;
279 my $var = $2;
280 my $end = $3;
281 # append beginning of value to retval
282 $retval = "$retval$begin";
283 if (defined($variable{$var})) {
284 $retval = "$retval$variable{$var}";
285 } else {
286 # put back the origin piece.
287 $retval = "$retval\$\{$var\}";
288 }
289 $value = $end;
290 }
291 $retval = "$retval$value";
292
293 # remove the space added in the beginning
294 $retval =~ s/ //;
295
296 return "$retval"
297}
298
Steven Rostedta57419b2010-11-02 15:13:54 -0400299sub set_value {
300 my ($lvalue, $rvalue) = @_;
301
302 if (defined($opt{$lvalue})) {
303 die "Error: Option $lvalue defined more than once!\n";
304 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500305 if ($rvalue =~ /^\s*$/) {
306 delete $opt{$lvalue};
307 } else {
Steven Rostedt77d942c2011-05-20 13:36:58 -0400308 $rvalue = process_variables($rvalue);
Steven Rostedt21a96792010-11-08 16:45:50 -0500309 $opt{$lvalue} = $rvalue;
310 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400311}
312
Steven Rostedt77d942c2011-05-20 13:36:58 -0400313sub set_variable {
314 my ($lvalue, $rvalue) = @_;
315
316 if ($rvalue =~ /^\s*$/) {
317 delete $variable{$lvalue};
318 } else {
319 $rvalue = process_variables($rvalue);
320 $variable{$lvalue} = $rvalue;
321 }
322}
323
Steven Rostedt2545eb62010-11-02 15:01:32 -0400324sub read_config {
325 my ($config) = @_;
326
327 open(IN, $config) || die "can't read file $config";
328
Steven Rostedta57419b2010-11-02 15:13:54 -0400329 my $name = $config;
330 $name =~ s,.*/(.*),$1,;
331
332 my $test_num = 0;
333 my $default = 1;
334 my $repeat = 1;
335 my $num_tests_set = 0;
336 my $skip = 0;
337 my $rest;
338
Steven Rostedt2545eb62010-11-02 15:01:32 -0400339 while (<IN>) {
340
341 # ignore blank lines and comments
342 next if (/^\s*$/ || /\s*\#/);
343
Steven Rostedta57419b2010-11-02 15:13:54 -0400344 if (/^\s*TEST_START(.*)/) {
345
346 $rest = $1;
347
348 if ($num_tests_set) {
349 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
350 }
351
352 my $old_test_num = $test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400353 my $old_repeat = $repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400354
355 $test_num += $repeat;
356 $default = 0;
357 $repeat = 1;
358
359 if ($rest =~ /\s+SKIP(.*)/) {
360 $rest = $1;
361 $skip = 1;
362 } else {
363 $skip = 0;
364 }
365
366 if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {
367 $repeat = $1;
368 $rest = $2;
369 $repeat_tests{"$test_num"} = $repeat;
370 }
371
372 if ($rest =~ /\s+SKIP(.*)/) {
373 $rest = $1;
374 $skip = 1;
375 }
376
377 if ($rest !~ /^\s*$/) {
378 die "$name: $.: Gargbage found after TEST_START\n$_";
379 }
380
381 if ($skip) {
382 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400383 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400384 }
385
386 } elsif (/^\s*DEFAULTS(.*)$/) {
387 $default = 1;
388
389 $rest = $1;
390
391 if ($rest =~ /\s+SKIP(.*)/) {
392 $rest = $1;
393 $skip = 1;
394 } else {
395 $skip = 0;
396 }
397
398 if ($rest !~ /^\s*$/) {
399 die "$name: $.: Gargbage found after DEFAULTS\n$_";
400 }
401
402 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
403
404 next if ($skip);
405
Steven Rostedt2545eb62010-11-02 15:01:32 -0400406 my $lvalue = $1;
407 my $rvalue = $2;
408
Steven Rostedta57419b2010-11-02 15:13:54 -0400409 if (!$default &&
410 ($lvalue eq "NUM_TESTS" ||
411 $lvalue eq "LOG_FILE" ||
412 $lvalue eq "CLEAR_LOG")) {
413 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400414 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400415
416 if ($lvalue eq "NUM_TESTS") {
417 if ($test_num) {
418 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
419 }
420 if (!$default) {
421 die "$name: $.: NUM_TESTS must be set in default section\n";
422 }
423 $num_tests_set = 1;
424 }
425
426 if ($default || $lvalue =~ /\[\d+\]$/) {
427 set_value($lvalue, $rvalue);
428 } else {
429 my $val = "$lvalue\[$test_num\]";
430 set_value($val, $rvalue);
431
432 if ($repeat > 1) {
433 $repeats{$val} = $repeat;
434 }
435 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400436 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
437 next if ($skip);
438
439 my $lvalue = $1;
440 my $rvalue = $2;
441
442 # process config variables.
443 # Config variables are only active while reading the
444 # config and can be defined anywhere. They also ignore
445 # TEST_START and DEFAULTS, but are skipped if they are in
446 # on of these sections that have SKIP defined.
447 # The save variable can be
448 # defined multiple times and the new one simply overrides
449 # the prevous one.
450 set_variable($lvalue, $rvalue);
451
Steven Rostedta57419b2010-11-02 15:13:54 -0400452 } else {
453 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400454 }
455 }
456
457 close(IN);
Steven Rostedta75fece2010-11-02 14:58:27 -0400458
Steven Rostedta57419b2010-11-02 15:13:54 -0400459 if ($test_num) {
460 $test_num += $repeat - 1;
461 $opt{"NUM_TESTS"} = $test_num;
462 }
463
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500464 # make sure we have all mandatory configs
465 get_ktest_configs;
466
Steven Rostedta75fece2010-11-02 14:58:27 -0400467 # set any defaults
468
469 foreach my $default (keys %default) {
470 if (!defined($opt{$default})) {
471 $opt{$default} = $default{$default};
472 }
473 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400474}
475
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500476sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400477 if (defined($opt{"LOG_FILE"})) {
478 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
479 print OUT @_;
480 close(OUT);
481 }
482}
483
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500484sub logit {
485 if (defined($opt{"LOG_FILE"})) {
486 _logit @_;
487 } else {
488 print @_;
489 }
490}
491
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400492sub doprint {
493 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -0500494 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400495}
496
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400497sub run_command;
498
499sub reboot {
500 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -0400501 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -0400502 if (defined($powercycle_after_reboot)) {
503 sleep $powercycle_after_reboot;
504 run_command "$power_cycle";
505 }
506 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400507 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -0400508 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400509 }
510}
511
Steven Rostedt576f6272010-11-02 14:58:38 -0400512sub do_not_reboot {
513 my $i = $iteration;
514
515 return $test_type eq "build" ||
516 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
517 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
518}
519
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400520sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400521 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400522
Steven Rostedt576f6272010-11-02 14:58:38 -0400523 my $i = $iteration;
524
525 if ($reboot_on_error && !do_not_reboot) {
526
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400527 doprint "REBOOTING\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400528 reboot;
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400529
Steven Rostedta75fece2010-11-02 14:58:27 -0400530 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400531 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400532 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400533 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400534
Steven Rostedtf80802c2011-03-07 13:18:47 -0500535 if (defined($opt{"LOG_FILE"})) {
536 print " See $opt{LOG_FILE} for more info.\n";
537 }
538
Steven Rostedt576f6272010-11-02 14:58:38 -0400539 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400540}
541
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400542sub open_console {
543 my ($fp) = @_;
544
545 my $flags;
546
Steven Rostedta75fece2010-11-02 14:58:27 -0400547 my $pid = open($fp, "$console|") or
548 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400549
550 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400551 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400552 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -0400553 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400554
555 return $pid;
556}
557
558sub close_console {
559 my ($fp, $pid) = @_;
560
561 doprint "kill child process $pid\n";
562 kill 2, $pid;
563
564 print "closing!\n";
565 close($fp);
566}
567
568sub start_monitor {
569 if ($monitor_cnt++) {
570 return;
571 }
572 $monitor_fp = \*MONFD;
573 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -0400574
575 return;
576
577 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400578}
579
580sub end_monitor {
581 if (--$monitor_cnt) {
582 return;
583 }
584 close_console($monitor_fp, $monitor_pid);
585}
586
587sub wait_for_monitor {
588 my ($time) = @_;
589 my $line;
590
Steven Rostedta75fece2010-11-02 14:58:27 -0400591 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400592
593 # read the monitor and wait for the system to calm down
594 do {
595 $line = wait_for_input($monitor_fp, $time);
Steven Rostedta75fece2010-11-02 14:58:27 -0400596 print "$line" if (defined($line));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400597 } while (defined($line));
Steven Rostedta75fece2010-11-02 14:58:27 -0400598 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400599}
600
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400601sub fail {
602
Steven Rostedta75fece2010-11-02 14:58:27 -0400603 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400604 dodie @_;
605 }
606
Steven Rostedta75fece2010-11-02 14:58:27 -0400607 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400608
Steven Rostedt576f6272010-11-02 14:58:38 -0400609 my $i = $iteration;
610
Steven Rostedta75fece2010-11-02 14:58:27 -0400611 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -0400612 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400613 doprint "REBOOTING\n";
614 reboot;
615 start_monitor;
616 wait_for_monitor $sleep_time;
617 end_monitor;
618 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400619
Steven Rostedt576f6272010-11-02 14:58:38 -0400620 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
621 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt7a849cd2010-11-08 16:49:25 -0500622 doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -0400623 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
624 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400625
626 return 1 if (!defined($store_failures));
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400627
628 my @t = localtime;
629 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
630 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
631
Steven Rostedtcccae1a2010-11-09 12:21:32 -0500632 my $type = $build_type;
633 if ($type =~ /useconfig/) {
634 $type = "useconfig";
635 }
636
637 my $dir = "$machine-$test_type-$type-fail-$date";
Steven Rostedta75fece2010-11-02 14:58:27 -0400638 my $faildir = "$store_failures/$dir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400639
640 if (!-d $faildir) {
641 mkpath($faildir) or
Steven Rostedta75fece2010-11-02 14:58:27 -0400642 die "can't create $faildir";
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400643 }
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500644 if (-f "$output_config") {
645 cp "$output_config", "$faildir/config" or
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400646 die "failed to copy .config";
647 }
648 if (-f $buildlog) {
649 cp $buildlog, "$faildir/buildlog" or
650 die "failed to move $buildlog";
651 }
652 if (-f $dmesg) {
653 cp $dmesg, "$faildir/dmesg" or
654 die "failed to move $dmesg";
655 }
656
657 doprint "*** Saved info to $faildir ***\n";
658
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400659 return 1;
660}
661
Steven Rostedt2545eb62010-11-02 15:01:32 -0400662sub run_command {
663 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400664 my $dolog = 0;
665 my $dord = 0;
666 my $pid;
667
Steven Rostedte48c5292010-11-02 14:35:37 -0400668 $command =~ s/\$SSH_USER/$ssh_user/g;
669 $command =~ s/\$MACHINE/$machine/g;
670
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400671 doprint("$command ... ");
672
673 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400674 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400675
676 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400677 open(LOG, ">>$opt{LOG_FILE}") or
678 dodie "failed to write to log";
679 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400680 }
681
682 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400683 open (RD, ">$redirect") or
684 dodie "failed to write to redirect $redirect";
685 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400686 }
687
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400688 while (<CMD>) {
689 print LOG if ($dolog);
690 print RD if ($dord);
691 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400692
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400693 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400694 my $failed = $?;
695
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400696 close(CMD);
697 close(LOG) if ($dolog);
698 close(RD) if ($dord);
699
Steven Rostedt2545eb62010-11-02 15:01:32 -0400700 if ($failed) {
701 doprint "FAILED!\n";
702 } else {
703 doprint "SUCCESS\n";
704 }
705
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400706 return !$failed;
707}
708
Steven Rostedte48c5292010-11-02 14:35:37 -0400709sub run_ssh {
710 my ($cmd) = @_;
711 my $cp_exec = $ssh_exec;
712
713 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
714 return run_command "$cp_exec";
715}
716
717sub run_scp {
718 my ($src, $dst) = @_;
719 my $cp_scp = $scp_to_target;
720
721 $cp_scp =~ s/\$SRC_FILE/$src/g;
722 $cp_scp =~ s/\$DST_FILE/$dst/g;
723
724 return run_command "$cp_scp";
725}
726
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400727sub get_grub_index {
728
Steven Rostedta75fece2010-11-02 14:58:27 -0400729 if ($reboot_type ne "grub") {
730 return;
731 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400732 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400733
734 doprint "Find grub menu ... ";
735 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -0400736
737 my $ssh_grub = $ssh_exec;
738 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
739
740 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400741 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -0400742
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400743 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400744 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400745 $grub_number++;
746 last;
747 } elsif (/^\s*title\s/) {
748 $grub_number++;
749 }
750 }
751 close(IN);
752
Steven Rostedta75fece2010-11-02 14:58:27 -0400753 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400754 if ($grub_number < 0);
755 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400756}
757
Steven Rostedt2545eb62010-11-02 15:01:32 -0400758sub wait_for_input
759{
760 my ($fp, $time) = @_;
761 my $rin;
762 my $ready;
763 my $line;
764 my $ch;
765
766 if (!defined($time)) {
767 $time = $timeout;
768 }
769
770 $rin = '';
771 vec($rin, fileno($fp), 1) = 1;
772 $ready = select($rin, undef, undef, $time);
773
774 $line = "";
775
776 # try to read one char at a time
777 while (sysread $fp, $ch, 1) {
778 $line .= $ch;
779 last if ($ch eq "\n");
780 }
781
782 if (!length($line)) {
783 return undef;
784 }
785
786 return $line;
787}
788
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400789sub reboot_to {
Steven Rostedta75fece2010-11-02 14:58:27 -0400790 if ($reboot_type eq "grub") {
Steven Rostedt4da46da2011-06-01 23:25:13 -0400791 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'";
Steven Rostedta75fece2010-11-02 14:58:27 -0400792 return;
793 }
794
795 run_command "$reboot_script";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400796}
797
Steven Rostedta57419b2010-11-02 15:13:54 -0400798sub get_sha1 {
799 my ($commit) = @_;
800
801 doprint "git rev-list --max-count=1 $commit ... ";
802 my $sha1 = `git rev-list --max-count=1 $commit`;
803 my $ret = $?;
804
805 logit $sha1;
806
807 if ($ret) {
808 doprint "FAILED\n";
809 dodie "Failed to get git $commit";
810 }
811
812 print "SUCCESS\n";
813
814 chomp $sha1;
815
816 return $sha1;
817}
818
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400819sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400820 my $booted = 0;
821 my $bug = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400822 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400823 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400824
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400825 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400826
827 my $line;
828 my $full_line = "";
829
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400830 open(DMESG, "> $dmesg") or
831 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400832
Steven Rostedt75c3fda72010-11-02 14:57:21 -0400833 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400834
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500835 my $success_start;
836 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500837 my $monitor_start = time;
838 my $done = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500839
Steven Rostedt2d01b262011-03-08 09:47:54 -0500840 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400841
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400842 if ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -0400843 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400844 if (!defined($line)) {
845 my $s = $booted_timeout == 1 ? "" : "s";
846 doprint "Successful boot found: break after $booted_timeout second$s\n";
847 last;
848 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400849 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400850 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -0400851 if (!defined($line)) {
852 my $s = $timeout == 1 ? "" : "s";
853 doprint "Timed out after $timeout second$s\n";
854 last;
855 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400856 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400857
Steven Rostedt2545eb62010-11-02 15:01:32 -0400858 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400859 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400860
861 # we are not guaranteed to get a full line
862 $full_line .= $line;
863
Steven Rostedta75fece2010-11-02 14:58:27 -0400864 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400865 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500866 $success_start = time;
867 }
868
869 if ($booted && defined($stop_after_success) &&
870 $stop_after_success >= 0) {
871 my $now = time;
872 if ($now - $success_start >= $stop_after_success) {
873 doprint "Test forced to stop after $stop_after_success seconds after success\n";
874 last;
875 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400876 }
877
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400878 if ($full_line =~ /\[ backtrace testing \]/) {
879 $skip_call_trace = 1;
880 }
881
Steven Rostedt2545eb62010-11-02 15:01:32 -0400882 if ($full_line =~ /call trace:/i) {
Steven Rostedt46519202011-03-08 09:40:31 -0500883 if (!$bug && !$skip_call_trace) {
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500884 $bug = 1;
885 $failure_start = time;
886 }
887 }
888
889 if ($bug && defined($stop_after_failure) &&
890 $stop_after_failure >= 0) {
891 my $now = time;
892 if ($now - $failure_start >= $stop_after_failure) {
893 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
894 last;
895 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400896 }
897
898 if ($full_line =~ /\[ end of backtrace testing \]/) {
899 $skip_call_trace = 0;
900 }
901
902 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -0500903 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400904 $bug = 1;
905 }
906
907 if ($line =~ /\n/) {
908 $full_line = "";
909 }
Steven Rostedt2d01b262011-03-08 09:47:54 -0500910
911 if ($stop_test_after > 0 && !$booted && !$bug) {
912 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -0400913 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -0500914 $done = 1;
915 }
916 }
Steven Rostedt2545eb62010-11-02 15:01:32 -0400917 }
918
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400919 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -0400920
Steven Rostedt2545eb62010-11-02 15:01:32 -0400921 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400922 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400923 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400924 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400925
Steven Rostedta75fece2010-11-02 14:58:27 -0400926 if (!$booted) {
927 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -0400928 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400929 }
930
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400931 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400932}
933
934sub install {
935
Steven Rostedte48c5292010-11-02 14:35:37 -0400936 run_scp "$outputdir/$build_target", "$target_image" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400937 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400938
939 my $install_mods = 0;
940
941 # should we process modules?
942 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -0500943 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400944 while (<IN>) {
945 if (/CONFIG_MODULES(=y)?/) {
946 $install_mods = 1 if (defined($1));
947 last;
948 }
949 }
950 close(IN);
951
952 if (!$install_mods) {
953 doprint "No modules needed\n";
954 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400955 }
956
Steven Rostedta75fece2010-11-02 14:58:27 -0400957 run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400958 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400959
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400960 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -0400961 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400962
Steven Rostedte48c5292010-11-02 14:35:37 -0400963 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400964 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400965
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400966 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -0400967 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400968 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400969
Steven Rostedte48c5292010-11-02 14:35:37 -0400970 run_scp "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400971 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400972
Steven Rostedta75fece2010-11-02 14:58:27 -0400973 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400974
Steven Rostedte48c5292010-11-02 14:35:37 -0400975 run_ssh "'(cd / && tar xf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400976 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400977
Steven Rostedte48c5292010-11-02 14:35:37 -0400978 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400979
980 return if (!defined($post_install));
981
Steven Rostedte48c5292010-11-02 14:35:37 -0400982 my $cp_post_install = $post_install;
Steven Rostedtca6a21f2011-03-25 22:42:53 -0400983 $cp_post_install =~ s/\$KERNEL_VERSION/$version/g;
Steven Rostedte48c5292010-11-02 14:35:37 -0400984 run_command "$cp_post_install" or
Steven Rostedt576f6272010-11-02 14:58:38 -0400985 dodie "Failed to run post install";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400986}
987
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400988sub check_buildlog {
989 my ($patch) = @_;
990
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400991 my @files = `git show $patch | diffstat -l`;
992
993 open(IN, "git show $patch |") or
994 dodie "failed to show $patch";
995 while (<IN>) {
996 if (m,^--- a/(.*),) {
997 chomp $1;
998 $files[$#files] = $1;
999 }
1000 }
1001 close(IN);
1002
1003 open(IN, $buildlog) or dodie "Can't open $buildlog";
1004 while (<IN>) {
1005 if (/^\s*(.*?):.*(warning|error)/) {
1006 my $err = $1;
1007 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001008 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001009 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001010 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001011 }
1012 }
1013 }
1014 }
1015 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001016
1017 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001018}
1019
Steven Rostedt612b9e92011-03-07 13:27:43 -05001020sub make_oldconfig {
1021 my ($defconfig) = @_;
1022
1023 if (!run_command "$defconfig $make oldnoconfig") {
1024 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1025 # try a yes '' | oldconfig
1026 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
1027 run_command "yes '' | $defconfig $make oldconfig" or
1028 dodie "failed make config oldconfig";
1029 }
1030}
1031
Steven Rostedt2545eb62010-11-02 15:01:32 -04001032sub build {
1033 my ($type) = @_;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001034 my $defconfig = "";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001035
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001036 unlink $buildlog;
1037
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001038 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001039 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001040 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001041
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001042 $type = "oldconfig";
1043 }
1044
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001045 # old config can ask questions
1046 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001047 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001048
1049 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001050 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001051
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001052 run_command "mv $output_config $outputdir/config_temp" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001053 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001054
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001055 if (!$noclean && !run_command "$make mrproper") {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001056 dodie "make mrproper";
1057 }
1058
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001059 run_command "mv $outputdir/config_temp $output_config" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001060 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001061
1062 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001063 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001064 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001065 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001066 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001067
1068 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001069 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1070 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001071 close(OUT);
1072
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001073 if (defined($minconfig)) {
1074 $defconfig = "KCONFIG_ALLCONFIG=$minconfig";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001075 }
1076
Steven Rostedt612b9e92011-03-07 13:27:43 -05001077 if ($type eq "oldnoconfig") {
1078 make_oldconfig $defconfig;
1079 } else {
1080 run_command "$defconfig $make $type" or
1081 dodie "failed make config";
1082 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001083
Steven Rostedta75fece2010-11-02 14:58:27 -04001084 $redirect = "$buildlog";
1085 if (!run_command "$make $build_options") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001086 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001087 # bisect may need this to pass
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001088 return 0 if ($in_bisect);
1089 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001090 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001091 undef $redirect;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001092
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001093 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001094}
1095
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001096sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001097 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001098 if (defined($poweroff_after_halt)) {
1099 sleep $poweroff_after_halt;
1100 run_command "$power_off";
1101 }
1102 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001103 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001104 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001105 }
1106}
1107
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001108sub success {
1109 my ($i) = @_;
1110
Steven Rostedte48c5292010-11-02 14:35:37 -04001111 $successes++;
1112
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001113 doprint "\n\n*******************************************\n";
1114 doprint "*******************************************\n";
Steven Rostedt7a849cd2010-11-08 16:49:25 -05001115 doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001116 doprint "*******************************************\n";
1117 doprint "*******************************************\n";
1118
Steven Rostedt576f6272010-11-02 14:58:38 -04001119 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001120 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001121 reboot;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001122 start_monitor;
Steven Rostedta75fece2010-11-02 14:58:27 -04001123 wait_for_monitor $sleep_time;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001124 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001125 }
1126}
1127
1128sub get_version {
1129 # get the release name
1130 doprint "$make kernelrelease ... ";
1131 $version = `$make kernelrelease | tail -1`;
1132 chomp($version);
1133 doprint "$version\n";
1134}
1135
Steven Rostedtc960bb92011-03-08 09:22:39 -05001136sub answer_bisect {
1137 for (;;) {
1138 doprint "Pass or fail? [p/f]";
1139 my $ans = <STDIN>;
1140 chomp $ans;
1141 if ($ans eq "p" || $ans eq "P") {
1142 return 1;
1143 } elsif ($ans eq "f" || $ans eq "F") {
1144 return 0;
1145 } else {
1146 print "Please answer 'P' or 'F'\n";
1147 }
1148 }
1149}
1150
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001151sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001152 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001153
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001154 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04001155 $reboot_on_error = 0;
1156 $poweroff_on_error = 0;
1157 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001158
1159 run_command $run_test or $failed = 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001160 exit $failed;
1161}
1162
1163my $child_done;
1164
1165sub child_finished {
1166 $child_done = 1;
1167}
1168
1169sub do_run_test {
1170 my $child_pid;
1171 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001172 my $line;
1173 my $full_line;
1174 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001175
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001176 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001177
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001178 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001179
1180 $child_done = 0;
1181
1182 $SIG{CHLD} = qw(child_finished);
1183
1184 $child_pid = fork;
1185
1186 child_run_test if (!$child_pid);
1187
1188 $full_line = "";
1189
1190 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001191 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001192 if (defined($line)) {
1193
1194 # we are not guaranteed to get a full line
1195 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001196 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001197
1198 if ($full_line =~ /call trace:/i) {
1199 $bug = 1;
1200 }
1201
1202 if ($full_line =~ /Kernel panic -/) {
1203 $bug = 1;
1204 }
1205
1206 if ($line =~ /\n/) {
1207 $full_line = "";
1208 }
1209 }
1210 } while (!$child_done && !$bug);
1211
1212 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05001213 my $failure_start = time;
1214 my $now;
1215 do {
1216 $line = wait_for_input($monitor_fp, 1);
1217 if (defined($line)) {
1218 doprint $line;
1219 }
1220 $now = time;
1221 if ($now - $failure_start >= $stop_after_failure) {
1222 last;
1223 }
1224 } while (defined($line));
1225
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001226 doprint "Detected kernel crash!\n";
1227 # kill the child with extreme prejudice
1228 kill 9, $child_pid;
1229 }
1230
1231 waitpid $child_pid, 0;
1232 $child_exit = $?;
1233
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001234 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001235 return 0 if $in_bisect;
1236 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001237 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001238 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001239}
1240
Steven Rostedta75fece2010-11-02 14:58:27 -04001241sub run_git_bisect {
1242 my ($command) = @_;
1243
1244 doprint "$command ... ";
1245
1246 my $output = `$command 2>&1`;
1247 my $ret = $?;
1248
1249 logit $output;
1250
1251 if ($ret) {
1252 doprint "FAILED\n";
1253 dodie "Failed to git bisect";
1254 }
1255
1256 doprint "SUCCESS\n";
1257 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
1258 doprint "$1 [$2]\n";
1259 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
1260 $bisect_bad = $1;
1261 doprint "Found bad commit... $1\n";
1262 return 0;
1263 } else {
1264 # we already logged it, just print it now.
1265 print $output;
1266 }
1267
1268 return 1;
1269}
1270
Steven Rostedtc23dca72011-03-08 09:26:31 -05001271sub bisect_reboot {
1272 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
1273 reboot;
1274 start_monitor;
1275 wait_for_monitor $bisect_sleep_time;
1276 end_monitor;
1277}
1278
1279# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05001280sub run_bisect_test {
1281 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001282
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001283 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001284 my $result;
1285 my $output;
1286 my $ret;
1287
Steven Rostedt0a05c762010-11-08 11:14:10 -05001288 $in_bisect = 1;
1289
1290 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001291
1292 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001293 if ($failed && $bisect_skip) {
1294 $in_bisect = 0;
1295 return -1;
1296 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001297 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001298
1299 # Now boot the box
1300 get_grub_index;
1301 get_version;
1302 install;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001303
1304 start_monitor;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001305 monitor or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001306
1307 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05001308 if ($failed && $bisect_skip) {
1309 end_monitor;
1310 bisect_reboot;
1311 $in_bisect = 0;
1312 return -1;
1313 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001314 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001315
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001316 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001317 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001318 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001319 }
1320
1321 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001322 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001323 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001324 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001325 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04001326
1327 # reboot the box to a kernel we can ssh to
1328 if ($type ne "build") {
1329 bisect_reboot;
1330 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001331 $in_bisect = 0;
1332
1333 return $result;
1334}
1335
1336sub run_bisect {
1337 my ($type) = @_;
1338 my $buildtype = "oldconfig";
1339
1340 # We should have a minconfig to use?
1341 if (defined($minconfig)) {
1342 $buildtype = "useconfig:$minconfig";
1343 }
1344
1345 my $ret = run_bisect_test $type, $buildtype;
1346
Steven Rostedtc960bb92011-03-08 09:22:39 -05001347 if ($bisect_manual) {
1348 $ret = answer_bisect;
1349 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001350
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001351 # Are we looking for where it worked, not failed?
1352 if ($reverse_bisect) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001353 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001354 }
1355
Steven Rostedtc23dca72011-03-08 09:26:31 -05001356 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001357 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001358 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001359 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05001360 } elsif ($bisect_skip) {
1361 doprint "HIT A BAD COMMIT ... SKIPPING\n";
1362 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001363 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001364}
1365
1366sub bisect {
1367 my ($i) = @_;
1368
1369 my $result;
1370
1371 die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));
1372 die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));
1373 die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));
1374
1375 my $good = $opt{"BISECT_GOOD[$i]"};
1376 my $bad = $opt{"BISECT_BAD[$i]"};
1377 my $type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04001378 my $start = $opt{"BISECT_START[$i]"};
1379 my $replay = $opt{"BISECT_REPLAY[$i]"};
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001380 my $start_files = $opt{"BISECT_FILES[$i]"};
1381
1382 if (defined($start_files)) {
1383 $start_files = " -- " . $start_files;
1384 } else {
1385 $start_files = "";
1386 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001387
Steven Rostedta57419b2010-11-02 15:13:54 -04001388 # convert to true sha1's
1389 $good = get_sha1($good);
1390 $bad = get_sha1($bad);
1391
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001392 if (defined($opt{"BISECT_REVERSE[$i]"}) &&
1393 $opt{"BISECT_REVERSE[$i]"} == 1) {
1394 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
1395 $reverse_bisect = 1;
1396 } else {
1397 $reverse_bisect = 0;
1398 }
1399
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001400 # Can't have a test without having a test to run
1401 if ($type eq "test" && !defined($run_test)) {
1402 $type = "boot";
1403 }
1404
Steven Rostedta75fece2010-11-02 14:58:27 -04001405 my $check = $opt{"BISECT_CHECK[$i]"};
1406 if (defined($check) && $check ne "0") {
1407
1408 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04001409 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04001410
1411 if ($check ne "good") {
1412 doprint "TESTING BISECT BAD [$bad]\n";
1413 run_command "git checkout $bad" or
1414 die "Failed to checkout $bad";
1415
1416 $result = run_bisect $type;
1417
1418 if ($result ne "bad") {
1419 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
1420 }
1421 }
1422
1423 if ($check ne "bad") {
1424 doprint "TESTING BISECT GOOD [$good]\n";
1425 run_command "git checkout $good" or
1426 die "Failed to checkout $good";
1427
1428 $result = run_bisect $type;
1429
1430 if ($result ne "good") {
1431 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
1432 }
1433 }
1434
1435 # checkout where we started
1436 run_command "git checkout $head" or
1437 die "Failed to checkout $head";
1438 }
1439
Steven Rostedt3410f6f2011-03-08 09:38:12 -05001440 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04001441 dodie "could not start bisect";
1442
1443 run_command "git bisect good $good" or
1444 dodie "could not set bisect good to $good";
1445
1446 run_git_bisect "git bisect bad $bad" or
1447 dodie "could not set bisect bad to $bad";
1448
1449 if (defined($replay)) {
1450 run_command "git bisect replay $replay" or
1451 dodie "failed to run replay";
1452 }
1453
1454 if (defined($start)) {
1455 run_command "git checkout $start" or
1456 dodie "failed to checkout $start";
1457 }
1458
1459 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001460 do {
1461 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04001462 $test = run_git_bisect "git bisect $result";
1463 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001464
1465 run_command "git bisect log" or
1466 dodie "could not capture git bisect log";
1467
1468 run_command "git bisect reset" or
1469 dodie "could not reset git bisect";
1470
1471 doprint "Bad commit was [$bisect_bad]\n";
1472
Steven Rostedt0a05c762010-11-08 11:14:10 -05001473 success $i;
1474}
1475
1476my %config_ignore;
1477my %config_set;
1478
1479my %config_list;
1480my %null_config;
1481
1482my %dependency;
1483
1484sub process_config_ignore {
1485 my ($config) = @_;
1486
1487 open (IN, $config)
1488 or dodie "Failed to read $config";
1489
1490 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04001491 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05001492 $config_ignore{$2} = $1;
1493 }
1494 }
1495
1496 close(IN);
1497}
1498
1499sub read_current_config {
1500 my ($config_ref) = @_;
1501
1502 %{$config_ref} = ();
1503 undef %{$config_ref};
1504
1505 my @key = keys %{$config_ref};
1506 if ($#key >= 0) {
1507 print "did not delete!\n";
1508 exit;
1509 }
1510 open (IN, "$output_config");
1511
1512 while (<IN>) {
1513 if (/^(CONFIG\S+)=(.*)/) {
1514 ${$config_ref}{$1} = $2;
1515 }
1516 }
1517 close(IN);
1518}
1519
1520sub get_dependencies {
1521 my ($config) = @_;
1522
1523 my $arr = $dependency{$config};
1524 if (!defined($arr)) {
1525 return ();
1526 }
1527
1528 my @deps = @{$arr};
1529
1530 foreach my $dep (@{$arr}) {
1531 print "ADD DEP $dep\n";
1532 @deps = (@deps, get_dependencies $dep);
1533 }
1534
1535 return @deps;
1536}
1537
1538sub create_config {
1539 my @configs = @_;
1540
1541 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
1542
1543 foreach my $config (@configs) {
1544 print OUT "$config_set{$config}\n";
1545 my @deps = get_dependencies $config;
1546 foreach my $dep (@deps) {
1547 print OUT "$config_set{$dep}\n";
1548 }
1549 }
1550
1551 foreach my $config (keys %config_ignore) {
1552 print OUT "$config_ignore{$config}\n";
1553 }
1554 close(OUT);
1555
1556# exit;
Steven Rostedt612b9e92011-03-07 13:27:43 -05001557 make_oldconfig "";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001558}
1559
1560sub compare_configs {
1561 my (%a, %b) = @_;
1562
1563 foreach my $item (keys %a) {
1564 if (!defined($b{$item})) {
1565 print "diff $item\n";
1566 return 1;
1567 }
1568 delete $b{$item};
1569 }
1570
1571 my @keys = keys %b;
1572 if ($#keys) {
1573 print "diff2 $keys[0]\n";
1574 }
1575 return -1 if ($#keys >= 0);
1576
1577 return 0;
1578}
1579
1580sub run_config_bisect_test {
1581 my ($type) = @_;
1582
1583 return run_bisect_test $type, "oldconfig";
1584}
1585
1586sub process_passed {
1587 my (%configs) = @_;
1588
1589 doprint "These configs had no failure: (Enabling them for further compiles)\n";
1590 # Passed! All these configs are part of a good compile.
1591 # Add them to the min options.
1592 foreach my $config (keys %configs) {
1593 if (defined($config_list{$config})) {
1594 doprint " removing $config\n";
1595 $config_ignore{$config} = $config_list{$config};
1596 delete $config_list{$config};
1597 }
1598 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05001599 doprint "config copied to $outputdir/config_good\n";
1600 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001601}
1602
1603sub process_failed {
1604 my ($config) = @_;
1605
1606 doprint "\n\n***************************************\n";
1607 doprint "Found bad config: $config\n";
1608 doprint "***************************************\n\n";
1609}
1610
1611sub run_config_bisect {
1612
1613 my @start_list = keys %config_list;
1614
1615 if ($#start_list < 0) {
1616 doprint "No more configs to test!!!\n";
1617 return -1;
1618 }
1619
1620 doprint "***** RUN TEST ***\n";
1621 my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};
1622 my $ret;
1623 my %current_config;
1624
1625 my $count = $#start_list + 1;
1626 doprint " $count configs to test\n";
1627
1628 my $half = int($#start_list / 2);
1629
1630 do {
1631 my @tophalf = @start_list[0 .. $half];
1632
1633 create_config @tophalf;
1634 read_current_config \%current_config;
1635
1636 $count = $#tophalf + 1;
1637 doprint "Testing $count configs\n";
1638 my $found = 0;
1639 # make sure we test something
1640 foreach my $config (@tophalf) {
1641 if (defined($current_config{$config})) {
1642 logit " $config\n";
1643 $found = 1;
1644 }
1645 }
1646 if (!$found) {
1647 # try the other half
1648 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001649 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedt0a05c762010-11-08 11:14:10 -05001650 create_config @tophalf;
1651 read_current_config \%current_config;
1652 foreach my $config (@tophalf) {
1653 if (defined($current_config{$config})) {
1654 logit " $config\n";
1655 $found = 1;
1656 }
1657 }
1658 if (!$found) {
1659 doprint "Failed: Can't make new config with current configs\n";
1660 foreach my $config (@start_list) {
1661 doprint " CONFIG: $config\n";
1662 }
1663 return -1;
1664 }
1665 $count = $#tophalf + 1;
1666 doprint "Testing $count configs\n";
1667 }
1668
1669 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05001670 if ($bisect_manual) {
1671 $ret = answer_bisect;
1672 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05001673 if ($ret) {
1674 process_passed %current_config;
1675 return 0;
1676 }
1677
1678 doprint "This config had a failure.\n";
1679 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05001680 doprint "config copied to $outputdir/config_bad\n";
1681 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05001682
1683 # A config exists in this group that was bad.
1684 foreach my $config (keys %config_list) {
1685 if (!defined($current_config{$config})) {
1686 doprint " removing $config\n";
1687 delete $config_list{$config};
1688 }
1689 }
1690
1691 @start_list = @tophalf;
1692
1693 if ($#start_list == 0) {
1694 process_failed $start_list[0];
1695 return 1;
1696 }
1697
1698 # remove half the configs we are looking at and see if
1699 # they are good.
1700 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04001701 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05001702
Steven Rostedtc960bb92011-03-08 09:22:39 -05001703 # we found a single config, try it again unless we are running manually
1704
1705 if ($bisect_manual) {
1706 process_failed $start_list[0];
1707 return 1;
1708 }
1709
Steven Rostedt0a05c762010-11-08 11:14:10 -05001710 my @tophalf = @start_list[0 .. 0];
1711
1712 $ret = run_config_bisect_test $type;
1713 if ($ret) {
1714 process_passed %current_config;
1715 return 0;
1716 }
1717
1718 process_failed $start_list[0];
1719 return 1;
1720}
1721
1722sub config_bisect {
1723 my ($i) = @_;
1724
1725 my $start_config = $opt{"CONFIG_BISECT[$i]"};
1726
1727 my $tmpconfig = "$tmpdir/use_config";
1728
1729 # Make the file with the bad config and the min config
1730 if (defined($minconfig)) {
1731 # read the min config for things to ignore
1732 run_command "cp $minconfig $tmpconfig" or
1733 dodie "failed to copy $minconfig to $tmpconfig";
1734 } else {
1735 unlink $tmpconfig;
1736 }
1737
1738 # Add other configs
1739 if (defined($addconfig)) {
1740 run_command "cat $addconfig >> $tmpconfig" or
1741 dodie "failed to append $addconfig";
1742 }
1743
1744 my $defconfig = "";
1745 if (-f $tmpconfig) {
1746 $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";
1747 process_config_ignore $tmpconfig;
1748 }
1749
1750 # now process the start config
1751 run_command "cp $start_config $output_config" or
1752 dodie "failed to copy $start_config to $output_config";
1753
1754 # read directly what we want to check
1755 my %config_check;
1756 open (IN, $output_config)
1757 or dodie "faied to open $output_config";
1758
1759 while (<IN>) {
1760 if (/^((CONFIG\S*)=.*)/) {
1761 $config_check{$2} = $1;
1762 }
1763 }
1764 close(IN);
1765
1766 # Now run oldconfig with the minconfig (and addconfigs)
Steven Rostedt612b9e92011-03-07 13:27:43 -05001767 make_oldconfig $defconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05001768
1769 # check to see what we lost (or gained)
1770 open (IN, $output_config)
1771 or dodie "Failed to read $start_config";
1772
1773 my %removed_configs;
1774 my %added_configs;
1775
1776 while (<IN>) {
1777 if (/^((CONFIG\S*)=.*)/) {
1778 # save off all options
1779 $config_set{$2} = $1;
1780 if (defined($config_check{$2})) {
1781 if (defined($config_ignore{$2})) {
1782 $removed_configs{$2} = $1;
1783 } else {
1784 $config_list{$2} = $1;
1785 }
1786 } elsif (!defined($config_ignore{$2})) {
1787 $added_configs{$2} = $1;
1788 $config_list{$2} = $1;
1789 }
1790 }
1791 }
1792 close(IN);
1793
1794 my @confs = keys %removed_configs;
1795 if ($#confs >= 0) {
1796 doprint "Configs overridden by default configs and removed from check:\n";
1797 foreach my $config (@confs) {
1798 doprint " $config\n";
1799 }
1800 }
1801 @confs = keys %added_configs;
1802 if ($#confs >= 0) {
1803 doprint "Configs appearing in make oldconfig and added:\n";
1804 foreach my $config (@confs) {
1805 doprint " $config\n";
1806 }
1807 }
1808
1809 my %config_test;
1810 my $once = 0;
1811
1812 # Sometimes kconfig does weird things. We must make sure
1813 # that the config we autocreate has everything we need
1814 # to test, otherwise we may miss testing configs, or
1815 # may not be able to create a new config.
1816 # Here we create a config with everything set.
1817 create_config (keys %config_list);
1818 read_current_config \%config_test;
1819 foreach my $config (keys %config_list) {
1820 if (!defined($config_test{$config})) {
1821 if (!$once) {
1822 $once = 1;
1823 doprint "Configs not produced by kconfig (will not be checked):\n";
1824 }
1825 doprint " $config\n";
1826 delete $config_list{$config};
1827 }
1828 }
1829 my $ret;
1830 do {
1831 $ret = run_config_bisect;
1832 } while (!$ret);
1833
1834 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001835
1836 success $i;
1837}
1838
Steven Rostedt27d934b2011-05-20 09:18:18 -04001839sub patchcheck_reboot {
1840 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
1841 reboot;
1842 start_monitor;
1843 wait_for_monitor $patchcheck_sleep_time;
1844 end_monitor;
1845}
1846
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001847sub patchcheck {
1848 my ($i) = @_;
1849
1850 die "PATCHCHECK_START[$i] not defined\n"
1851 if (!defined($opt{"PATCHCHECK_START[$i]"}));
1852 die "PATCHCHECK_TYPE[$i] not defined\n"
1853 if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));
1854
1855 my $start = $opt{"PATCHCHECK_START[$i]"};
1856
1857 my $end = "HEAD";
1858 if (defined($opt{"PATCHCHECK_END[$i]"})) {
1859 $end = $opt{"PATCHCHECK_END[$i]"};
1860 }
1861
Steven Rostedta57419b2010-11-02 15:13:54 -04001862 # Get the true sha1's since we can use things like HEAD~3
1863 $start = get_sha1($start);
1864 $end = get_sha1($end);
1865
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001866 my $type = $opt{"PATCHCHECK_TYPE[$i]"};
1867
1868 # Can't have a test without having a test to run
1869 if ($type eq "test" && !defined($run_test)) {
1870 $type = "boot";
1871 }
1872
1873 open (IN, "git log --pretty=oneline $end|") or
1874 dodie "could not get git list";
1875
1876 my @list;
1877
1878 while (<IN>) {
1879 chomp;
1880 $list[$#list+1] = $_;
1881 last if (/^$start/);
1882 }
1883 close(IN);
1884
1885 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001886 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001887 }
1888
1889 # go backwards in the list
1890 @list = reverse @list;
1891
1892 my $save_clean = $noclean;
1893
1894 $in_patchcheck = 1;
1895 foreach my $item (@list) {
1896 my $sha1 = $item;
1897 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
1898
1899 doprint "\nProcessing commit $item\n\n";
1900
1901 run_command "git checkout $sha1" or
1902 die "Failed to checkout $sha1";
1903
1904 # only clean on the first and last patch
1905 if ($item eq $list[0] ||
1906 $item eq $list[$#list]) {
1907 $noclean = $save_clean;
1908 } else {
1909 $noclean = 1;
1910 }
1911
1912 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001913 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001914 } else {
1915 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001916 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001917 }
1918
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001919 check_buildlog $sha1 or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001920
1921 next if ($type eq "build");
1922
1923 get_grub_index;
1924 get_version;
1925 install;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001926
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001927 my $failed = 0;
1928
1929 start_monitor;
1930 monitor or $failed = 1;
1931
1932 if (!$failed && $type ne "boot"){
1933 do_run_test or $failed = 1;
1934 }
1935 end_monitor;
1936 return 0 if ($failed);
1937
Steven Rostedt27d934b2011-05-20 09:18:18 -04001938 patchcheck_reboot;
1939
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001940 }
1941 $in_patchcheck = 0;
1942 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001943
1944 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001945}
1946
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001947$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001948
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001949if ($#ARGV == 0) {
1950 $ktest_config = $ARGV[0];
1951 if (! -f $ktest_config) {
1952 print "$ktest_config does not exist.\n";
1953 my $ans;
1954 for (;;) {
1955 print "Create it? [Y/n] ";
1956 $ans = <STDIN>;
1957 chomp $ans;
1958 if ($ans =~ /^\s*$/) {
1959 $ans = "y";
1960 }
1961 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
1962 print "Please answer either 'y' or 'n'.\n";
1963 }
1964 if ($ans !~ /^y$/i) {
1965 exit 0;
1966 }
1967 }
1968} else {
1969 $ktest_config = "ktest.conf";
1970}
1971
1972if (! -f $ktest_config) {
1973 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
1974 print OUT << "EOF"
1975# Generated by ktest.pl
1976#
1977# Define each test with TEST_START
1978# The config options below it will override the defaults
1979TEST_START
1980
1981DEFAULTS
1982EOF
1983;
1984 close(OUT);
1985}
1986read_config $ktest_config;
1987
1988# Append any configs entered in manually to the config file.
1989my @new_configs = keys %entered_configs;
1990if ($#new_configs >= 0) {
1991 print "\nAppending entered in configs to $ktest_config\n";
1992 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
1993 foreach my $config (@new_configs) {
1994 print OUT "$config = $entered_configs{$config}\n";
1995 $opt{$config} = $entered_configs{$config};
1996 }
1997}
Steven Rostedt2545eb62010-11-02 15:01:32 -04001998
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001999if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
2000 unlink $opt{"LOG_FILE"};
2001}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002002
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002003doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
2004
Steven Rostedta57419b2010-11-02 15:13:54 -04002005for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
2006
2007 if (!$i) {
2008 doprint "DEFAULT OPTIONS:\n";
2009 } else {
2010 doprint "\nTEST $i OPTIONS";
2011 if (defined($repeat_tests{$i})) {
2012 $repeat = $repeat_tests{$i};
2013 doprint " ITERATE $repeat";
2014 }
2015 doprint "\n";
2016 }
2017
2018 foreach my $option (sort keys %opt) {
2019
2020 if ($option =~ /\[(\d+)\]$/) {
2021 next if ($i != $1);
2022 } else {
2023 next if ($i);
2024 }
2025
2026 doprint "$option = $opt{$option}\n";
2027 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002028}
Steven Rostedt2545eb62010-11-02 15:01:32 -04002029
Steven Rostedt2a625122011-05-20 15:48:59 -04002030sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002031 my ($name, $i) = @_;
2032
2033 my $option = "$name\[$i\]";
2034
2035 if (defined($opt{$option})) {
2036 return $opt{$option};
2037 }
2038
Steven Rostedta57419b2010-11-02 15:13:54 -04002039 foreach my $test (keys %repeat_tests) {
2040 if ($i >= $test &&
2041 $i < $test + $repeat_tests{$test}) {
2042 $option = "$name\[$test\]";
2043 if (defined($opt{$option})) {
2044 return $opt{$option};
2045 }
2046 }
2047 }
2048
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002049 if (defined($opt{$name})) {
2050 return $opt{$name};
2051 }
2052
2053 return undef;
2054}
2055
Steven Rostedt2a625122011-05-20 15:48:59 -04002056sub eval_option {
2057 my ($option, $i) = @_;
2058
2059 # Add space to evaluate the character before $
2060 $option = " $option";
2061 my $retval = "";
2062
2063 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
2064 my $start = $1;
2065 my $var = $2;
2066 my $end = $3;
2067
2068 # Append beginning of line
2069 $retval = "$retval$start";
2070
2071 # If the iteration option OPT[$i] exists, then use that.
2072 # otherwise see if the default OPT (without [$i]) exists.
2073
2074 my $o = "$var\[$i\]";
2075
2076 if (defined($opt{$o})) {
2077 $o = $opt{$o};
2078 $retval = "$retval$o";
2079 } elsif (defined($opt{$var})) {
2080 $o = $opt{$var};
2081 $retval = "$retval$o";
2082 } else {
2083 $retval = "$retval\$\{$var\}";
2084 }
2085
2086 $option = $end;
2087 }
2088
2089 $retval = "$retval$option";
2090
2091 $retval =~ s/^ //;
2092
2093 return $retval;
2094}
2095
2096sub set_test_option {
2097 my ($name, $i) = @_;
2098
2099 my $option = __set_test_option($name, $i);
2100 return $option if (!defined($option));
2101
2102 my $prev = "";
2103
2104 # Since an option can evaluate to another option,
2105 # keep iterating until we do not evaluate any more
2106 # options.
2107 my $r = 0;
2108 while ($prev ne $option) {
2109 # Check for recursive evaluations.
2110 # 100 deep should be more than enough.
2111 if ($r++ > 100) {
2112 die "Over 100 evaluations accurred with $name\n" .
2113 "Check for recursive variables\n";
2114 }
2115 $prev = $option;
2116 $option = eval_option($option, $i);
2117 }
2118
2119 return $option;
2120}
2121
Steven Rostedt2545eb62010-11-02 15:01:32 -04002122# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04002123for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04002124
Steven Rostedt576f6272010-11-02 14:58:38 -04002125 $iteration = $i;
2126
Steven Rostedta75fece2010-11-02 14:58:27 -04002127 my $makecmd = set_test_option("MAKE_CMD", $i);
2128
2129 $machine = set_test_option("MACHINE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002130 $ssh_user = set_test_option("SSH_USER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002131 $tmpdir = set_test_option("TMP_DIR", $i);
2132 $outputdir = set_test_option("OUTPUT_DIR", $i);
2133 $builddir = set_test_option("BUILD_DIR", $i);
2134 $test_type = set_test_option("TEST_TYPE", $i);
2135 $build_type = set_test_option("BUILD_TYPE", $i);
2136 $build_options = set_test_option("BUILD_OPTIONS", $i);
2137 $power_cycle = set_test_option("POWER_CYCLE", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002138 $reboot = set_test_option("REBOOT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002139 $noclean = set_test_option("BUILD_NOCLEAN", $i);
2140 $minconfig = set_test_option("MIN_CONFIG", $i);
2141 $run_test = set_test_option("TEST", $i);
2142 $addconfig = set_test_option("ADD_CONFIG", $i);
2143 $reboot_type = set_test_option("REBOOT_TYPE", $i);
2144 $grub_menu = set_test_option("GRUB_MENU", $i);
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002145 $post_install = set_test_option("POST_INSTALL", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002146 $reboot_script = set_test_option("REBOOT_SCRIPT", $i);
2147 $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);
2148 $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);
2149 $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);
2150 $power_off = set_test_option("POWER_OFF", $i);
Steven Rostedt576f6272010-11-02 14:58:38 -04002151 $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);
2152 $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002153 $sleep_time = set_test_option("SLEEP_TIME", $i);
2154 $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);
Steven Rostedt27d934b2011-05-20 09:18:18 -04002155 $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i);
Steven Rostedtc960bb92011-03-08 09:22:39 -05002156 $bisect_manual = set_test_option("BISECT_MANUAL", $i);
Steven Rostedtc23dca72011-03-08 09:26:31 -05002157 $bisect_skip = set_test_option("BISECT_SKIP", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002158 $store_failures = set_test_option("STORE_FAILURES", $i);
2159 $timeout = set_test_option("TIMEOUT", $i);
2160 $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);
2161 $console = set_test_option("CONSOLE", $i);
2162 $success_line = set_test_option("SUCCESS_LINE", $i);
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002163 $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);
2164 $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);
Steven Rostedt2d01b262011-03-08 09:47:54 -05002165 $stop_test_after = set_test_option("STOP_TEST_AFTER", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002166 $build_target = set_test_option("BUILD_TARGET", $i);
Steven Rostedte48c5292010-11-02 14:35:37 -04002167 $ssh_exec = set_test_option("SSH_EXEC", $i);
2168 $scp_to_target = set_test_option("SCP_TO_TARGET", $i);
Steven Rostedta75fece2010-11-02 14:58:27 -04002169 $target_image = set_test_option("TARGET_IMAGE", $i);
2170 $localversion = set_test_option("LOCALVERSION", $i);
2171
2172 chdir $builddir || die "can't change directory to $builddir";
2173
2174 if (!-d $tmpdir) {
2175 mkpath($tmpdir) or
2176 die "can't create $tmpdir";
2177 }
2178
Steven Rostedte48c5292010-11-02 14:35:37 -04002179 $ENV{"SSH_USER"} = $ssh_user;
2180 $ENV{"MACHINE"} = $machine;
2181
Steven Rostedta75fece2010-11-02 14:58:27 -04002182 $target = "$ssh_user\@$machine";
2183
2184 $buildlog = "$tmpdir/buildlog-$machine";
2185 $dmesg = "$tmpdir/dmesg-$machine";
2186 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002187 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04002188
2189 if ($reboot_type eq "grub") {
Steven Rostedt576f6272010-11-02 14:58:38 -04002190 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta75fece2010-11-02 14:58:27 -04002191 } elsif (!defined($reboot_script)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002192 dodie "REBOOT_SCRIPT not defined"
Steven Rostedta75fece2010-11-02 14:58:27 -04002193 }
2194
2195 my $run_type = $build_type;
2196 if ($test_type eq "patchcheck") {
2197 $run_type = $opt{"PATCHCHECK_TYPE[$i]"};
2198 } elsif ($test_type eq "bisect") {
2199 $run_type = $opt{"BISECT_TYPE[$i]"};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002200 } elsif ($test_type eq "config_bisect") {
2201 $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};
Steven Rostedta75fece2010-11-02 14:58:27 -04002202 }
2203
2204 # mistake in config file?
2205 if (!defined($run_type)) {
2206 $run_type = "ERROR";
2207 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002208
2209 doprint "\n\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04002210 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002211
2212 unlink $dmesg;
2213 unlink $buildlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002214
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002215 if (!defined($minconfig)) {
2216 $minconfig = $addconfig;
2217
2218 } elsif (defined($addconfig)) {
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002219 run_command "cat $addconfig $minconfig > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002220 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05002221 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002222 }
2223
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002224 my $checkout = $opt{"CHECKOUT[$i]"};
2225 if (defined($checkout)) {
2226 run_command "git checkout $checkout" or
2227 die "failed to checkout $checkout";
2228 }
2229
Steven Rostedta75fece2010-11-02 14:58:27 -04002230 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002231 bisect $i;
2232 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002233 } elsif ($test_type eq "config_bisect") {
2234 config_bisect $i;
2235 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04002236 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002237 patchcheck $i;
2238 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002239 }
2240
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002241 if ($build_type ne "nobuild") {
2242 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002243 }
2244
Steven Rostedta75fece2010-11-02 14:58:27 -04002245 if ($test_type ne "build") {
2246 get_grub_index;
2247 get_version;
2248 install;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002249
Steven Rostedta75fece2010-11-02 14:58:27 -04002250 my $failed = 0;
2251 start_monitor;
2252 monitor or $failed = 1;;
2253
2254 if (!$failed && $test_type ne "boot" && defined($run_test)) {
2255 do_run_test or $failed = 1;
2256 }
2257 end_monitor;
2258 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002259 }
2260
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002261 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002262}
2263
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002264if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002265 halt;
Steven Rostedt576f6272010-11-02 14:58:38 -04002266} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002267 reboot;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002268}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002269
Steven Rostedte48c5292010-11-02 14:35:37 -04002270doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
2271
Steven Rostedt2545eb62010-11-02 15:01:32 -04002272exit 0;