Commit | Line | Data |
---|---|---|
2545eb61 | 1 | #!/usr/bin/perl -w |
d6ce2a0b SR |
2 | # |
3 | # Copywrite 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc. | |
4 | # Licensed under the terms of the GNU GPL License version 2 | |
5 | # | |
2545eb61 SR |
6 | |
7 | use strict; | |
8 | use IPC::Open2; | |
9 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); | |
7faafbd6 SR |
10 | use File::Path qw(mkpath); |
11 | use File::Copy qw(cp); | |
2545eb61 SR |
12 | use FileHandle; |
13 | ||
a57419b3 | 14 | $#ARGV >= 0 || die "usage: ktest.pl config-file\n"; |
2545eb61 SR |
15 | |
16 | $| = 1; | |
17 | ||
18 | my %opt; | |
a57419b3 SR |
19 | my %repeat_tests; |
20 | my %repeats; | |
a75fecec | 21 | my %default; |
2545eb61 SR |
22 | |
23 | #default opts | |
a57419b3 | 24 | $default{"NUM_TESTS"} = 1; |
a75fecec SR |
25 | $default{"REBOOT_TYPE"} = "grub"; |
26 | $default{"TEST_TYPE"} = "test"; | |
27 | $default{"BUILD_TYPE"} = "randconfig"; | |
28 | $default{"MAKE_CMD"} = "make"; | |
29 | $default{"TIMEOUT"} = 120; | |
a57419b3 | 30 | $default{"TMP_DIR"} = "/tmp/ktest"; |
a75fecec SR |
31 | $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 | |
39 | $default{"CLEAR_LOG"} = 0; | |
40 | $default{"SUCCESS_LINE"} = "login:"; | |
41 | $default{"BOOTED_TIMEOUT"} = 1; | |
42 | $default{"DIE_ON_FAILURE"} = 1; | |
2545eb61 SR |
43 | |
44 | my $version; | |
a75fecec SR |
45 | my $machine; |
46 | my $tmpdir; | |
47 | my $builddir; | |
48 | my $outputdir; | |
49 | my $test_type; | |
7faafbd6 | 50 | my $build_type; |
a75fecec SR |
51 | my $build_options; |
52 | my $reboot_type; | |
53 | my $reboot_script; | |
54 | my $power_cycle; | |
55 | my $reboot_on_error; | |
56 | my $poweroff_on_error; | |
57 | my $die_on_failure; | |
576f627c SR |
58 | my $powercycle_after_reboot; |
59 | my $poweroff_after_halt; | |
a75fecec SR |
60 | my $power_off; |
61 | my $grub_menu; | |
2545eb61 SR |
62 | my $grub_number; |
63 | my $target; | |
64 | my $make; | |
8b37ca8c | 65 | my $post_install; |
5c42fc5b | 66 | my $noclean; |
5f9b6ced | 67 | my $minconfig; |
2b7d9b21 | 68 | my $addconfig; |
5f9b6ced SR |
69 | my $in_bisect = 0; |
70 | my $bisect_bad = ""; | |
d6ce2a0b | 71 | my $reverse_bisect; |
6c5ee0be | 72 | my $in_patchcheck = 0; |
5a391fbf | 73 | my $run_test; |
6c5ee0be | 74 | my $redirect; |
7faafbd6 SR |
75 | my $buildlog; |
76 | my $dmesg; | |
77 | my $monitor_fp; | |
78 | my $monitor_pid; | |
79 | my $monitor_cnt = 0; | |
a75fecec SR |
80 | my $sleep_time; |
81 | my $bisect_sleep_time; | |
82 | my $store_failures; | |
83 | my $timeout; | |
84 | my $booted_timeout; | |
85 | my $console; | |
86 | my $success_line; | |
87 | my $build_target; | |
88 | my $target_image; | |
89 | my $localversion; | |
576f627c | 90 | my $iteration = 0; |
2545eb61 | 91 | |
a57419b3 SR |
92 | sub set_value { |
93 | my ($lvalue, $rvalue) = @_; | |
94 | ||
95 | if (defined($opt{$lvalue})) { | |
96 | die "Error: Option $lvalue defined more than once!\n"; | |
97 | } | |
98 | $opt{$lvalue} = $rvalue; | |
99 | } | |
100 | ||
2545eb61 SR |
101 | sub read_config { |
102 | my ($config) = @_; | |
103 | ||
104 | open(IN, $config) || die "can't read file $config"; | |
105 | ||
a57419b3 SR |
106 | my $name = $config; |
107 | $name =~ s,.*/(.*),$1,; | |
108 | ||
109 | my $test_num = 0; | |
110 | my $default = 1; | |
111 | my $repeat = 1; | |
112 | my $num_tests_set = 0; | |
113 | my $skip = 0; | |
114 | my $rest; | |
115 | ||
2545eb61 SR |
116 | while (<IN>) { |
117 | ||
118 | # ignore blank lines and comments | |
119 | next if (/^\s*$/ || /\s*\#/); | |
120 | ||
a57419b3 SR |
121 | if (/^\s*TEST_START(.*)/) { |
122 | ||
123 | $rest = $1; | |
124 | ||
125 | if ($num_tests_set) { | |
126 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; | |
127 | } | |
128 | ||
129 | my $old_test_num = $test_num; | |
130 | ||
131 | $test_num += $repeat; | |
132 | $default = 0; | |
133 | $repeat = 1; | |
134 | ||
135 | if ($rest =~ /\s+SKIP(.*)/) { | |
136 | $rest = $1; | |
137 | $skip = 1; | |
138 | } else { | |
139 | $skip = 0; | |
140 | } | |
141 | ||
142 | if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) { | |
143 | $repeat = $1; | |
144 | $rest = $2; | |
145 | $repeat_tests{"$test_num"} = $repeat; | |
146 | } | |
147 | ||
148 | if ($rest =~ /\s+SKIP(.*)/) { | |
149 | $rest = $1; | |
150 | $skip = 1; | |
151 | } | |
152 | ||
153 | if ($rest !~ /^\s*$/) { | |
154 | die "$name: $.: Gargbage found after TEST_START\n$_"; | |
155 | } | |
156 | ||
157 | if ($skip) { | |
158 | $test_num = $old_test_num; | |
159 | $repeat = 1; | |
160 | } | |
161 | ||
162 | } elsif (/^\s*DEFAULTS(.*)$/) { | |
163 | $default = 1; | |
164 | ||
165 | $rest = $1; | |
166 | ||
167 | if ($rest =~ /\s+SKIP(.*)/) { | |
168 | $rest = $1; | |
169 | $skip = 1; | |
170 | } else { | |
171 | $skip = 0; | |
172 | } | |
173 | ||
174 | if ($rest !~ /^\s*$/) { | |
175 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; | |
176 | } | |
177 | ||
178 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { | |
179 | ||
180 | next if ($skip); | |
181 | ||
2545eb61 SR |
182 | my $lvalue = $1; |
183 | my $rvalue = $2; | |
184 | ||
a57419b3 SR |
185 | if (!$default && |
186 | ($lvalue eq "NUM_TESTS" || | |
187 | $lvalue eq "LOG_FILE" || | |
188 | $lvalue eq "CLEAR_LOG")) { | |
189 | die "$name: $.: $lvalue must be set in DEFAULTS section\n"; | |
190 | } | |
191 | ||
192 | if ($lvalue eq "NUM_TESTS") { | |
193 | if ($test_num) { | |
194 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; | |
195 | } | |
196 | if (!$default) { | |
197 | die "$name: $.: NUM_TESTS must be set in default section\n"; | |
198 | } | |
199 | $num_tests_set = 1; | |
200 | } | |
201 | ||
202 | if ($default || $lvalue =~ /\[\d+\]$/) { | |
203 | set_value($lvalue, $rvalue); | |
204 | } else { | |
205 | my $val = "$lvalue\[$test_num\]"; | |
206 | set_value($val, $rvalue); | |
207 | ||
208 | if ($repeat > 1) { | |
209 | $repeats{$val} = $repeat; | |
210 | } | |
a75fecec | 211 | } |
a57419b3 SR |
212 | } else { |
213 | die "$name: $.: Garbage found in config\n$_"; | |
2545eb61 SR |
214 | } |
215 | } | |
216 | ||
217 | close(IN); | |
a75fecec | 218 | |
a57419b3 SR |
219 | if ($test_num) { |
220 | $test_num += $repeat - 1; | |
221 | $opt{"NUM_TESTS"} = $test_num; | |
222 | } | |
223 | ||
a75fecec SR |
224 | # set any defaults |
225 | ||
226 | foreach my $default (keys %default) { | |
227 | if (!defined($opt{$default})) { | |
228 | $opt{$default} = $default{$default}; | |
229 | } | |
230 | } | |
2545eb61 SR |
231 | } |
232 | ||
5f9b6ced | 233 | sub logit { |
2545eb61 SR |
234 | if (defined($opt{"LOG_FILE"})) { |
235 | open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}"; | |
236 | print OUT @_; | |
237 | close(OUT); | |
238 | } | |
239 | } | |
240 | ||
5f9b6ced SR |
241 | sub doprint { |
242 | print @_; | |
243 | logit @_; | |
244 | } | |
245 | ||
7faafbd6 SR |
246 | sub run_command; |
247 | ||
248 | sub reboot { | |
249 | # try to reboot normally | |
576f627c SR |
250 | if (run_command "ssh $target reboot") { |
251 | if (defined($powercycle_after_reboot)) { | |
252 | sleep $powercycle_after_reboot; | |
253 | run_command "$power_cycle"; | |
254 | } | |
255 | } else { | |
7faafbd6 | 256 | # nope? power cycle it. |
a75fecec | 257 | run_command "$power_cycle"; |
7faafbd6 SR |
258 | } |
259 | } | |
260 | ||
576f627c SR |
261 | sub do_not_reboot { |
262 | my $i = $iteration; | |
263 | ||
264 | return $test_type eq "build" || | |
265 | ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") || | |
266 | ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build"); | |
267 | } | |
268 | ||
5c42fc5b | 269 | sub dodie { |
5a391fbf | 270 | doprint "CRITICAL FAILURE... ", @_, "\n"; |
5c42fc5b | 271 | |
576f627c SR |
272 | my $i = $iteration; |
273 | ||
274 | if ($reboot_on_error && !do_not_reboot) { | |
275 | ||
75c3fda7 | 276 | doprint "REBOOTING\n"; |
7faafbd6 | 277 | reboot; |
75c3fda7 | 278 | |
a75fecec | 279 | } elsif ($poweroff_on_error && defined($power_off)) { |
5c42fc5b | 280 | doprint "POWERING OFF\n"; |
a75fecec | 281 | `$power_off`; |
5c42fc5b | 282 | } |
75c3fda7 | 283 | |
576f627c | 284 | die @_, "\n"; |
5c42fc5b SR |
285 | } |
286 | ||
7faafbd6 SR |
287 | sub open_console { |
288 | my ($fp) = @_; | |
289 | ||
290 | my $flags; | |
291 | ||
a75fecec SR |
292 | my $pid = open($fp, "$console|") or |
293 | dodie "Can't open console $console"; | |
7faafbd6 SR |
294 | |
295 | $flags = fcntl($fp, F_GETFL, 0) or | |
576f627c | 296 | dodie "Can't get flags for the socket: $!"; |
7faafbd6 | 297 | $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or |
576f627c | 298 | dodie "Can't set flags for the socket: $!"; |
7faafbd6 SR |
299 | |
300 | return $pid; | |
301 | } | |
302 | ||
303 | sub close_console { | |
304 | my ($fp, $pid) = @_; | |
305 | ||
306 | doprint "kill child process $pid\n"; | |
307 | kill 2, $pid; | |
308 | ||
309 | print "closing!\n"; | |
310 | close($fp); | |
311 | } | |
312 | ||
313 | sub start_monitor { | |
314 | if ($monitor_cnt++) { | |
315 | return; | |
316 | } | |
317 | $monitor_fp = \*MONFD; | |
318 | $monitor_pid = open_console $monitor_fp; | |
a75fecec SR |
319 | |
320 | return; | |
321 | ||
322 | open(MONFD, "Stop perl from warning about single use of MONFD"); | |
7faafbd6 SR |
323 | } |
324 | ||
325 | sub end_monitor { | |
326 | if (--$monitor_cnt) { | |
327 | return; | |
328 | } | |
329 | close_console($monitor_fp, $monitor_pid); | |
330 | } | |
331 | ||
332 | sub wait_for_monitor { | |
333 | my ($time) = @_; | |
334 | my $line; | |
335 | ||
a75fecec | 336 | doprint "** Wait for monitor to settle down **\n"; |
7faafbd6 SR |
337 | |
338 | # read the monitor and wait for the system to calm down | |
339 | do { | |
340 | $line = wait_for_input($monitor_fp, $time); | |
a75fecec | 341 | print "$line" if (defined($line)); |
7faafbd6 | 342 | } while (defined($line)); |
a75fecec | 343 | print "** Monitor flushed **\n"; |
7faafbd6 SR |
344 | } |
345 | ||
2b7d9b21 SR |
346 | sub fail { |
347 | ||
a75fecec | 348 | if ($die_on_failure) { |
2b7d9b21 SR |
349 | dodie @_; |
350 | } | |
351 | ||
a75fecec | 352 | doprint "FAILED\n"; |
7faafbd6 | 353 | |
576f627c SR |
354 | my $i = $iteration; |
355 | ||
a75fecec | 356 | # no need to reboot for just building. |
576f627c | 357 | if (!do_not_reboot) { |
a75fecec SR |
358 | doprint "REBOOTING\n"; |
359 | reboot; | |
360 | start_monitor; | |
361 | wait_for_monitor $sleep_time; | |
362 | end_monitor; | |
363 | } | |
7faafbd6 | 364 | |
576f627c SR |
365 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
366 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | |
a75fecec | 367 | doprint "**** Failed: ", @_, " ****\n"; |
576f627c SR |
368 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
369 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | |
a75fecec SR |
370 | |
371 | return 1 if (!defined($store_failures)); | |
7faafbd6 SR |
372 | |
373 | my @t = localtime; | |
374 | my $date = sprintf "%04d%02d%02d%02d%02d%02d", | |
375 | 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0]; | |
376 | ||
a75fecec SR |
377 | my $dir = "$machine-$test_type-$build_type-fail-$date"; |
378 | my $faildir = "$store_failures/$dir"; | |
7faafbd6 SR |
379 | |
380 | if (!-d $faildir) { | |
381 | mkpath($faildir) or | |
a75fecec | 382 | die "can't create $faildir"; |
7faafbd6 | 383 | } |
a75fecec SR |
384 | if (-f "$outputdir/.config") { |
385 | cp "$outputdir/.config", "$faildir/config" or | |
7faafbd6 SR |
386 | die "failed to copy .config"; |
387 | } | |
388 | if (-f $buildlog) { | |
389 | cp $buildlog, "$faildir/buildlog" or | |
390 | die "failed to move $buildlog"; | |
391 | } | |
392 | if (-f $dmesg) { | |
393 | cp $dmesg, "$faildir/dmesg" or | |
394 | die "failed to move $dmesg"; | |
395 | } | |
396 | ||
397 | doprint "*** Saved info to $faildir ***\n"; | |
398 | ||
2b7d9b21 SR |
399 | return 1; |
400 | } | |
401 | ||
2545eb61 SR |
402 | sub run_command { |
403 | my ($command) = @_; | |
d6ce2a0b SR |
404 | my $dolog = 0; |
405 | my $dord = 0; | |
406 | my $pid; | |
407 | ||
408 | doprint("$command ... "); | |
409 | ||
410 | $pid = open(CMD, "$command 2>&1 |") or | |
2b7d9b21 | 411 | (fail "unable to exec $command" and return 0); |
2545eb61 SR |
412 | |
413 | if (defined($opt{"LOG_FILE"})) { | |
d6ce2a0b SR |
414 | open(LOG, ">>$opt{LOG_FILE}") or |
415 | dodie "failed to write to log"; | |
416 | $dolog = 1; | |
6c5ee0be SR |
417 | } |
418 | ||
419 | if (defined($redirect)) { | |
d6ce2a0b SR |
420 | open (RD, ">$redirect") or |
421 | dodie "failed to write to redirect $redirect"; | |
422 | $dord = 1; | |
2545eb61 SR |
423 | } |
424 | ||
d6ce2a0b SR |
425 | while (<CMD>) { |
426 | print LOG if ($dolog); | |
427 | print RD if ($dord); | |
428 | } | |
2545eb61 | 429 | |
d6ce2a0b | 430 | waitpid($pid, 0); |
2545eb61 SR |
431 | my $failed = $?; |
432 | ||
d6ce2a0b SR |
433 | close(CMD); |
434 | close(LOG) if ($dolog); | |
435 | close(RD) if ($dord); | |
436 | ||
2545eb61 SR |
437 | if ($failed) { |
438 | doprint "FAILED!\n"; | |
439 | } else { | |
440 | doprint "SUCCESS\n"; | |
441 | } | |
442 | ||
5f9b6ced SR |
443 | return !$failed; |
444 | } | |
445 | ||
446 | sub get_grub_index { | |
447 | ||
a75fecec SR |
448 | if ($reboot_type ne "grub") { |
449 | return; | |
450 | } | |
5a391fbf | 451 | return if (defined($grub_number)); |
5f9b6ced SR |
452 | |
453 | doprint "Find grub menu ... "; | |
454 | $grub_number = -1; | |
455 | open(IN, "ssh $target cat /boot/grub/menu.lst |") | |
456 | or die "unable to get menu.lst"; | |
457 | while (<IN>) { | |
a75fecec | 458 | if (/^\s*title\s+$grub_menu\s*$/) { |
5f9b6ced SR |
459 | $grub_number++; |
460 | last; | |
461 | } elsif (/^\s*title\s/) { | |
462 | $grub_number++; | |
463 | } | |
464 | } | |
465 | close(IN); | |
466 | ||
a75fecec | 467 | die "Could not find '$grub_menu' in /boot/grub/menu on $machine" |
5f9b6ced SR |
468 | if ($grub_number < 0); |
469 | doprint "$grub_number\n"; | |
2545eb61 SR |
470 | } |
471 | ||
2545eb61 SR |
472 | sub wait_for_input |
473 | { | |
474 | my ($fp, $time) = @_; | |
475 | my $rin; | |
476 | my $ready; | |
477 | my $line; | |
478 | my $ch; | |
479 | ||
480 | if (!defined($time)) { | |
481 | $time = $timeout; | |
482 | } | |
483 | ||
484 | $rin = ''; | |
485 | vec($rin, fileno($fp), 1) = 1; | |
486 | $ready = select($rin, undef, undef, $time); | |
487 | ||
488 | $line = ""; | |
489 | ||
490 | # try to read one char at a time | |
491 | while (sysread $fp, $ch, 1) { | |
492 | $line .= $ch; | |
493 | last if ($ch eq "\n"); | |
494 | } | |
495 | ||
496 | if (!length($line)) { | |
497 | return undef; | |
498 | } | |
499 | ||
500 | return $line; | |
501 | } | |
502 | ||
75c3fda7 | 503 | sub reboot_to { |
a75fecec SR |
504 | if ($reboot_type eq "grub") { |
505 | run_command "ssh $target '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'"; | |
506 | return; | |
507 | } | |
508 | ||
509 | run_command "$reboot_script"; | |
2545eb61 SR |
510 | } |
511 | ||
a57419b3 SR |
512 | sub get_sha1 { |
513 | my ($commit) = @_; | |
514 | ||
515 | doprint "git rev-list --max-count=1 $commit ... "; | |
516 | my $sha1 = `git rev-list --max-count=1 $commit`; | |
517 | my $ret = $?; | |
518 | ||
519 | logit $sha1; | |
520 | ||
521 | if ($ret) { | |
522 | doprint "FAILED\n"; | |
523 | dodie "Failed to get git $commit"; | |
524 | } | |
525 | ||
526 | print "SUCCESS\n"; | |
527 | ||
528 | chomp $sha1; | |
529 | ||
530 | return $sha1; | |
531 | } | |
532 | ||
5a391fbf | 533 | sub monitor { |
2545eb61 SR |
534 | my $booted = 0; |
535 | my $bug = 0; | |
5c42fc5b | 536 | my $skip_call_trace = 0; |
2b7d9b21 | 537 | my $loops; |
2545eb61 | 538 | |
7faafbd6 | 539 | wait_for_monitor 5; |
2545eb61 SR |
540 | |
541 | my $line; | |
542 | my $full_line = ""; | |
543 | ||
7faafbd6 SR |
544 | open(DMESG, "> $dmesg") or |
545 | die "unable to write to $dmesg"; | |
2545eb61 | 546 | |
75c3fda7 | 547 | reboot_to; |
2545eb61 SR |
548 | |
549 | for (;;) { | |
550 | ||
2b7d9b21 | 551 | if ($booted) { |
a75fecec | 552 | $line = wait_for_input($monitor_fp, $booted_timeout); |
2b7d9b21 | 553 | } else { |
7faafbd6 | 554 | $line = wait_for_input($monitor_fp); |
2b7d9b21 | 555 | } |
2545eb61 SR |
556 | |
557 | last if (!defined($line)); | |
558 | ||
559 | doprint $line; | |
7faafbd6 | 560 | print DMESG $line; |
2545eb61 SR |
561 | |
562 | # we are not guaranteed to get a full line | |
563 | $full_line .= $line; | |
564 | ||
a75fecec | 565 | if ($full_line =~ /$success_line/) { |
2545eb61 SR |
566 | $booted = 1; |
567 | } | |
568 | ||
5c42fc5b SR |
569 | if ($full_line =~ /\[ backtrace testing \]/) { |
570 | $skip_call_trace = 1; | |
571 | } | |
572 | ||
2545eb61 | 573 | if ($full_line =~ /call trace:/i) { |
5c42fc5b SR |
574 | $bug = 1 if (!$skip_call_trace); |
575 | } | |
576 | ||
577 | if ($full_line =~ /\[ end of backtrace testing \]/) { | |
578 | $skip_call_trace = 0; | |
579 | } | |
580 | ||
581 | if ($full_line =~ /Kernel panic -/) { | |
2545eb61 SR |
582 | $bug = 1; |
583 | } | |
584 | ||
585 | if ($line =~ /\n/) { | |
586 | $full_line = ""; | |
587 | } | |
588 | } | |
589 | ||
7faafbd6 | 590 | close(DMESG); |
2545eb61 | 591 | |
a75fecec | 592 | if ($bug) { |
2b7d9b21 | 593 | return 0 if ($in_bisect); |
576f627c | 594 | fail "failed - got a bug report" and return 0; |
2545eb61 SR |
595 | } |
596 | ||
a75fecec | 597 | if (!$booted) { |
2b7d9b21 | 598 | return 0 if ($in_bisect); |
576f627c | 599 | fail "failed - never got a boot prompt." and return 0; |
2545eb61 | 600 | } |
5f9b6ced | 601 | |
2b7d9b21 | 602 | return 1; |
2545eb61 SR |
603 | } |
604 | ||
605 | sub install { | |
606 | ||
a75fecec | 607 | run_command "scp $outputdir/$build_target $target:$target_image" or |
5c42fc5b | 608 | dodie "failed to copy image"; |
2545eb61 | 609 | |
5f9b6ced | 610 | my $install_mods = 0; |
2545eb61 | 611 | |
5f9b6ced SR |
612 | # should we process modules? |
613 | $install_mods = 0; | |
a75fecec | 614 | open(IN, "$outputdir/.config") or dodie("Can't read config file"); |
5f9b6ced SR |
615 | while (<IN>) { |
616 | if (/CONFIG_MODULES(=y)?/) { | |
617 | $install_mods = 1 if (defined($1)); | |
618 | last; | |
5c42fc5b | 619 | } |
5f9b6ced SR |
620 | } |
621 | close(IN); | |
5c42fc5b | 622 | |
5f9b6ced SR |
623 | if (!$install_mods) { |
624 | doprint "No modules needed\n"; | |
625 | return; | |
626 | } | |
2545eb61 | 627 | |
a75fecec | 628 | run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or |
5f9b6ced | 629 | dodie "Failed to install modules"; |
5c42fc5b | 630 | |
5f9b6ced | 631 | my $modlib = "/lib/modules/$version"; |
a57419b3 | 632 | my $modtar = "ktest-mods.tar.bz2"; |
5c42fc5b | 633 | |
5f9b6ced SR |
634 | run_command "ssh $target rm -rf $modlib" or |
635 | dodie "failed to remove old mods: $modlib"; | |
5c42fc5b | 636 | |
5f9b6ced | 637 | # would be nice if scp -r did not follow symbolic links |
a75fecec | 638 | run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or |
5f9b6ced SR |
639 | dodie "making tarball"; |
640 | ||
a75fecec | 641 | run_command "scp $tmpdir/$modtar $target:/tmp" or |
5f9b6ced SR |
642 | dodie "failed to copy modules"; |
643 | ||
a75fecec | 644 | unlink "$tmpdir/$modtar"; |
5f9b6ced SR |
645 | |
646 | run_command "ssh $target '(cd / && tar xf /tmp/$modtar)'" or | |
647 | dodie "failed to tar modules"; | |
2545eb61 | 648 | |
5f9b6ced | 649 | run_command "ssh $target rm -f /tmp/$modtar"; |
8b37ca8c SR |
650 | |
651 | return if (!defined($post_install)); | |
652 | ||
653 | my $save_env = $ENV{KERNEL_VERSION}; | |
654 | ||
655 | $ENV{KERNEL_VERSION} = $version; | |
576f627c SR |
656 | run_command "$post_install" or |
657 | dodie "Failed to run post install"; | |
8b37ca8c SR |
658 | |
659 | $ENV{KERNEL_VERSION} = $save_env; | |
2545eb61 SR |
660 | } |
661 | ||
6c5ee0be SR |
662 | sub check_buildlog { |
663 | my ($patch) = @_; | |
664 | ||
6c5ee0be SR |
665 | my @files = `git show $patch | diffstat -l`; |
666 | ||
667 | open(IN, "git show $patch |") or | |
668 | dodie "failed to show $patch"; | |
669 | while (<IN>) { | |
670 | if (m,^--- a/(.*),) { | |
671 | chomp $1; | |
672 | $files[$#files] = $1; | |
673 | } | |
674 | } | |
675 | close(IN); | |
676 | ||
677 | open(IN, $buildlog) or dodie "Can't open $buildlog"; | |
678 | while (<IN>) { | |
679 | if (/^\s*(.*?):.*(warning|error)/) { | |
680 | my $err = $1; | |
681 | foreach my $file (@files) { | |
a75fecec | 682 | my $fullpath = "$builddir/$file"; |
6c5ee0be | 683 | if ($file eq $err || $fullpath eq $err) { |
2b7d9b21 | 684 | fail "$file built with warnings" and return 0; |
6c5ee0be SR |
685 | } |
686 | } | |
687 | } | |
688 | } | |
689 | close(IN); | |
2b7d9b21 SR |
690 | |
691 | return 1; | |
6c5ee0be SR |
692 | } |
693 | ||
2545eb61 SR |
694 | sub build { |
695 | my ($type) = @_; | |
5c42fc5b SR |
696 | my $defconfig = ""; |
697 | my $append = ""; | |
698 | ||
7faafbd6 SR |
699 | unlink $buildlog; |
700 | ||
75c3fda7 | 701 | if ($type =~ /^useconfig:(.*)/) { |
a75fecec | 702 | run_command "cp $1 $outputdir/.config" or |
75c3fda7 | 703 | dodie "could not copy $1 to .config"; |
5f9b6ced | 704 | |
75c3fda7 SR |
705 | $type = "oldconfig"; |
706 | } | |
707 | ||
5c42fc5b SR |
708 | # old config can ask questions |
709 | if ($type eq "oldconfig") { | |
710 | $append = "yes ''|"; | |
75c3fda7 SR |
711 | |
712 | # allow for empty configs | |
a75fecec | 713 | run_command "touch $outputdir/.config"; |
75c3fda7 | 714 | |
a75fecec | 715 | run_command "mv $outputdir/.config $outputdir/config_temp" or |
5c42fc5b | 716 | dodie "moving .config"; |
2545eb61 | 717 | |
5f9b6ced | 718 | if (!$noclean && !run_command "$make mrproper") { |
5c42fc5b SR |
719 | dodie "make mrproper"; |
720 | } | |
2545eb61 | 721 | |
a75fecec | 722 | run_command "mv $outputdir/config_temp $outputdir/.config" or |
5c42fc5b | 723 | dodie "moving config_temp"; |
5c42fc5b SR |
724 | |
725 | } elsif (!$noclean) { | |
a75fecec | 726 | unlink "$outputdir/.config"; |
5f9b6ced | 727 | run_command "$make mrproper" or |
5c42fc5b | 728 | dodie "make mrproper"; |
5c42fc5b | 729 | } |
2545eb61 SR |
730 | |
731 | # add something to distinguish this build | |
a75fecec SR |
732 | open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file"); |
733 | print OUT "$localversion\n"; | |
2545eb61 SR |
734 | close(OUT); |
735 | ||
5f9b6ced SR |
736 | if (defined($minconfig)) { |
737 | $defconfig = "KCONFIG_ALLCONFIG=$minconfig"; | |
2545eb61 SR |
738 | } |
739 | ||
a75fecec | 740 | run_command "$append $defconfig $make $type" or |
5c42fc5b | 741 | dodie "failed make config"; |
2545eb61 | 742 | |
a75fecec SR |
743 | $redirect = "$buildlog"; |
744 | if (!run_command "$make $build_options") { | |
6c5ee0be | 745 | undef $redirect; |
5f9b6ced | 746 | # bisect may need this to pass |
2b7d9b21 SR |
747 | return 0 if ($in_bisect); |
748 | fail "failed build" and return 0; | |
2545eb61 | 749 | } |
6c5ee0be | 750 | undef $redirect; |
5f9b6ced | 751 | |
2b7d9b21 | 752 | return 1; |
2545eb61 SR |
753 | } |
754 | ||
75c3fda7 | 755 | sub halt { |
a75fecec | 756 | if (!run_command "ssh $target halt" or defined($power_off)) { |
576f627c SR |
757 | if (defined($poweroff_after_halt)) { |
758 | sleep $poweroff_after_halt; | |
759 | run_command "$power_off"; | |
760 | } | |
761 | } else { | |
75c3fda7 | 762 | # nope? the zap it! |
a75fecec | 763 | run_command "$power_off"; |
75c3fda7 SR |
764 | } |
765 | } | |
766 | ||
5f9b6ced SR |
767 | sub success { |
768 | my ($i) = @_; | |
769 | ||
770 | doprint "\n\n*******************************************\n"; | |
771 | doprint "*******************************************\n"; | |
a75fecec | 772 | doprint "** TEST $i SUCCESS!!!! **\n"; |
5f9b6ced SR |
773 | doprint "*******************************************\n"; |
774 | doprint "*******************************************\n"; | |
775 | ||
576f627c | 776 | if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) { |
a75fecec | 777 | doprint "Reboot and wait $sleep_time seconds\n"; |
5f9b6ced | 778 | reboot; |
7faafbd6 | 779 | start_monitor; |
a75fecec | 780 | wait_for_monitor $sleep_time; |
7faafbd6 | 781 | end_monitor; |
5f9b6ced SR |
782 | } |
783 | } | |
784 | ||
785 | sub get_version { | |
786 | # get the release name | |
787 | doprint "$make kernelrelease ... "; | |
788 | $version = `$make kernelrelease | tail -1`; | |
789 | chomp($version); | |
790 | doprint "$version\n"; | |
791 | } | |
792 | ||
5a391fbf | 793 | sub child_run_test { |
7faafbd6 | 794 | my $failed = 0; |
5a391fbf | 795 | |
7faafbd6 | 796 | # child should have no power |
a75fecec SR |
797 | $reboot_on_error = 0; |
798 | $poweroff_on_error = 0; | |
799 | $die_on_failure = 1; | |
7faafbd6 SR |
800 | |
801 | run_command $run_test or $failed = 1; | |
5a391fbf SR |
802 | exit $failed; |
803 | } | |
804 | ||
805 | my $child_done; | |
806 | ||
807 | sub child_finished { | |
808 | $child_done = 1; | |
809 | } | |
810 | ||
811 | sub do_run_test { | |
812 | my $child_pid; | |
813 | my $child_exit; | |
5a391fbf SR |
814 | my $line; |
815 | my $full_line; | |
816 | my $bug = 0; | |
5a391fbf | 817 | |
7faafbd6 | 818 | wait_for_monitor 1; |
5a391fbf | 819 | |
7faafbd6 | 820 | doprint "run test $run_test\n"; |
5a391fbf SR |
821 | |
822 | $child_done = 0; | |
823 | ||
824 | $SIG{CHLD} = qw(child_finished); | |
825 | ||
826 | $child_pid = fork; | |
827 | ||
828 | child_run_test if (!$child_pid); | |
829 | ||
830 | $full_line = ""; | |
831 | ||
832 | do { | |
7faafbd6 | 833 | $line = wait_for_input($monitor_fp, 1); |
5a391fbf SR |
834 | if (defined($line)) { |
835 | ||
836 | # we are not guaranteed to get a full line | |
837 | $full_line .= $line; | |
838 | ||
839 | if ($full_line =~ /call trace:/i) { | |
840 | $bug = 1; | |
841 | } | |
842 | ||
843 | if ($full_line =~ /Kernel panic -/) { | |
844 | $bug = 1; | |
845 | } | |
846 | ||
847 | if ($line =~ /\n/) { | |
848 | $full_line = ""; | |
849 | } | |
850 | } | |
851 | } while (!$child_done && !$bug); | |
852 | ||
853 | if ($bug) { | |
854 | doprint "Detected kernel crash!\n"; | |
855 | # kill the child with extreme prejudice | |
856 | kill 9, $child_pid; | |
857 | } | |
858 | ||
859 | waitpid $child_pid, 0; | |
860 | $child_exit = $?; | |
861 | ||
5a391fbf | 862 | if ($bug || $child_exit) { |
2b7d9b21 SR |
863 | return 0 if $in_bisect; |
864 | fail "test failed" and return 0; | |
5a391fbf | 865 | } |
2b7d9b21 | 866 | return 1; |
5a391fbf SR |
867 | } |
868 | ||
a75fecec SR |
869 | sub run_git_bisect { |
870 | my ($command) = @_; | |
871 | ||
872 | doprint "$command ... "; | |
873 | ||
874 | my $output = `$command 2>&1`; | |
875 | my $ret = $?; | |
876 | ||
877 | logit $output; | |
878 | ||
879 | if ($ret) { | |
880 | doprint "FAILED\n"; | |
881 | dodie "Failed to git bisect"; | |
882 | } | |
883 | ||
884 | doprint "SUCCESS\n"; | |
885 | if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) { | |
886 | doprint "$1 [$2]\n"; | |
887 | } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) { | |
888 | $bisect_bad = $1; | |
889 | doprint "Found bad commit... $1\n"; | |
890 | return 0; | |
891 | } else { | |
892 | # we already logged it, just print it now. | |
893 | print $output; | |
894 | } | |
895 | ||
896 | return 1; | |
897 | } | |
898 | ||
5f9b6ced SR |
899 | sub run_bisect { |
900 | my ($type) = @_; | |
901 | ||
2b7d9b21 | 902 | my $failed = 0; |
5f9b6ced SR |
903 | my $result; |
904 | my $output; | |
905 | my $ret; | |
906 | ||
5f9b6ced | 907 | if (defined($minconfig)) { |
2b7d9b21 | 908 | build "useconfig:$minconfig" or $failed = 1; |
5f9b6ced SR |
909 | } else { |
910 | # ?? no config to use? | |
2b7d9b21 | 911 | build "oldconfig" or $failed = 1; |
5f9b6ced SR |
912 | } |
913 | ||
914 | if ($type ne "build") { | |
7faafbd6 | 915 | dodie "Failed on build" if $failed; |
5f9b6ced SR |
916 | |
917 | # Now boot the box | |
918 | get_grub_index; | |
919 | get_version; | |
920 | install; | |
7faafbd6 SR |
921 | |
922 | start_monitor; | |
2b7d9b21 | 923 | monitor or $failed = 1; |
5f9b6ced SR |
924 | |
925 | if ($type ne "boot") { | |
7faafbd6 | 926 | dodie "Failed on boot" if $failed; |
5a391fbf | 927 | |
2b7d9b21 | 928 | do_run_test or $failed = 1; |
5f9b6ced | 929 | } |
7faafbd6 | 930 | end_monitor; |
5f9b6ced SR |
931 | } |
932 | ||
933 | if ($failed) { | |
934 | $result = "bad"; | |
5a391fbf SR |
935 | |
936 | # reboot the box to a good kernel | |
a75fecec SR |
937 | if ($type ne "build") { |
938 | doprint "Reboot and sleep $bisect_sleep_time seconds\n"; | |
5a391fbf | 939 | reboot; |
7faafbd6 | 940 | start_monitor; |
a75fecec | 941 | wait_for_monitor $bisect_sleep_time; |
7faafbd6 | 942 | end_monitor; |
5a391fbf | 943 | } |
5f9b6ced SR |
944 | } else { |
945 | $result = "good"; | |
946 | } | |
947 | ||
d6ce2a0b SR |
948 | # Are we looking for where it worked, not failed? |
949 | if ($reverse_bisect) { | |
950 | if ($failed) { | |
951 | $result = "good"; | |
952 | } else { | |
953 | $result = "bad"; | |
954 | } | |
955 | } | |
956 | ||
a75fecec | 957 | return $result; |
5f9b6ced SR |
958 | } |
959 | ||
960 | sub bisect { | |
961 | my ($i) = @_; | |
962 | ||
963 | my $result; | |
964 | ||
965 | die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"})); | |
966 | die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"})); | |
967 | die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"})); | |
968 | ||
969 | my $good = $opt{"BISECT_GOOD[$i]"}; | |
970 | my $bad = $opt{"BISECT_BAD[$i]"}; | |
971 | my $type = $opt{"BISECT_TYPE[$i]"}; | |
a75fecec SR |
972 | my $start = $opt{"BISECT_START[$i]"}; |
973 | my $replay = $opt{"BISECT_REPLAY[$i]"}; | |
5f9b6ced | 974 | |
a57419b3 SR |
975 | # convert to true sha1's |
976 | $good = get_sha1($good); | |
977 | $bad = get_sha1($bad); | |
978 | ||
d6ce2a0b SR |
979 | if (defined($opt{"BISECT_REVERSE[$i]"}) && |
980 | $opt{"BISECT_REVERSE[$i]"} == 1) { | |
981 | doprint "Performing a reverse bisect (bad is good, good is bad!)\n"; | |
982 | $reverse_bisect = 1; | |
983 | } else { | |
984 | $reverse_bisect = 0; | |
985 | } | |
986 | ||
5f9b6ced SR |
987 | $in_bisect = 1; |
988 | ||
a75fecec SR |
989 | # Can't have a test without having a test to run |
990 | if ($type eq "test" && !defined($run_test)) { | |
991 | $type = "boot"; | |
992 | } | |
993 | ||
994 | my $check = $opt{"BISECT_CHECK[$i]"}; | |
995 | if (defined($check) && $check ne "0") { | |
996 | ||
997 | # get current HEAD | |
a57419b3 | 998 | my $head = get_sha1("HEAD"); |
a75fecec SR |
999 | |
1000 | if ($check ne "good") { | |
1001 | doprint "TESTING BISECT BAD [$bad]\n"; | |
1002 | run_command "git checkout $bad" or | |
1003 | die "Failed to checkout $bad"; | |
1004 | ||
1005 | $result = run_bisect $type; | |
1006 | ||
1007 | if ($result ne "bad") { | |
1008 | fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0; | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | if ($check ne "bad") { | |
1013 | doprint "TESTING BISECT GOOD [$good]\n"; | |
1014 | run_command "git checkout $good" or | |
1015 | die "Failed to checkout $good"; | |
1016 | ||
1017 | $result = run_bisect $type; | |
1018 | ||
1019 | if ($result ne "good") { | |
1020 | fail "Tested BISECT_GOOD [$good] and it failed" and return 0; | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | # checkout where we started | |
1025 | run_command "git checkout $head" or | |
1026 | die "Failed to checkout $head"; | |
1027 | } | |
1028 | ||
5f9b6ced | 1029 | run_command "git bisect start" or |
a75fecec | 1030 | dodie "could not start bisect"; |
5f9b6ced SR |
1031 | |
1032 | run_command "git bisect good $good" or | |
a75fecec | 1033 | dodie "could not set bisect good to $good"; |
5f9b6ced | 1034 | |
a75fecec SR |
1035 | run_git_bisect "git bisect bad $bad" or |
1036 | dodie "could not set bisect bad to $bad"; | |
5f9b6ced | 1037 | |
a75fecec SR |
1038 | if (defined($replay)) { |
1039 | run_command "git bisect replay $replay" or | |
1040 | dodie "failed to run replay"; | |
5a391fbf SR |
1041 | } |
1042 | ||
a75fecec SR |
1043 | if (defined($start)) { |
1044 | run_command "git checkout $start" or | |
1045 | dodie "failed to checkout $start"; | |
1046 | } | |
1047 | ||
1048 | my $test; | |
5f9b6ced SR |
1049 | do { |
1050 | $result = run_bisect $type; | |
a75fecec SR |
1051 | $test = run_git_bisect "git bisect $result"; |
1052 | } while ($test); | |
5f9b6ced SR |
1053 | |
1054 | run_command "git bisect log" or | |
1055 | dodie "could not capture git bisect log"; | |
1056 | ||
1057 | run_command "git bisect reset" or | |
1058 | dodie "could not reset git bisect"; | |
1059 | ||
1060 | doprint "Bad commit was [$bisect_bad]\n"; | |
1061 | ||
1062 | $in_bisect = 0; | |
1063 | ||
1064 | success $i; | |
1065 | } | |
1066 | ||
6c5ee0be SR |
1067 | sub patchcheck { |
1068 | my ($i) = @_; | |
1069 | ||
1070 | die "PATCHCHECK_START[$i] not defined\n" | |
1071 | if (!defined($opt{"PATCHCHECK_START[$i]"})); | |
1072 | die "PATCHCHECK_TYPE[$i] not defined\n" | |
1073 | if (!defined($opt{"PATCHCHECK_TYPE[$i]"})); | |
1074 | ||
1075 | my $start = $opt{"PATCHCHECK_START[$i]"}; | |
1076 | ||
1077 | my $end = "HEAD"; | |
1078 | if (defined($opt{"PATCHCHECK_END[$i]"})) { | |
1079 | $end = $opt{"PATCHCHECK_END[$i]"}; | |
1080 | } | |
1081 | ||
a57419b3 SR |
1082 | # Get the true sha1's since we can use things like HEAD~3 |
1083 | $start = get_sha1($start); | |
1084 | $end = get_sha1($end); | |
1085 | ||
6c5ee0be SR |
1086 | my $type = $opt{"PATCHCHECK_TYPE[$i]"}; |
1087 | ||
1088 | # Can't have a test without having a test to run | |
1089 | if ($type eq "test" && !defined($run_test)) { | |
1090 | $type = "boot"; | |
1091 | } | |
1092 | ||
1093 | open (IN, "git log --pretty=oneline $end|") or | |
1094 | dodie "could not get git list"; | |
1095 | ||
1096 | my @list; | |
1097 | ||
1098 | while (<IN>) { | |
1099 | chomp; | |
1100 | $list[$#list+1] = $_; | |
1101 | last if (/^$start/); | |
1102 | } | |
1103 | close(IN); | |
1104 | ||
1105 | if ($list[$#list] !~ /^$start/) { | |
2b7d9b21 | 1106 | fail "SHA1 $start not found"; |
6c5ee0be SR |
1107 | } |
1108 | ||
1109 | # go backwards in the list | |
1110 | @list = reverse @list; | |
1111 | ||
1112 | my $save_clean = $noclean; | |
1113 | ||
1114 | $in_patchcheck = 1; | |
1115 | foreach my $item (@list) { | |
1116 | my $sha1 = $item; | |
1117 | $sha1 =~ s/^([[:xdigit:]]+).*/$1/; | |
1118 | ||
1119 | doprint "\nProcessing commit $item\n\n"; | |
1120 | ||
1121 | run_command "git checkout $sha1" or | |
1122 | die "Failed to checkout $sha1"; | |
1123 | ||
1124 | # only clean on the first and last patch | |
1125 | if ($item eq $list[0] || | |
1126 | $item eq $list[$#list]) { | |
1127 | $noclean = $save_clean; | |
1128 | } else { | |
1129 | $noclean = 1; | |
1130 | } | |
1131 | ||
1132 | if (defined($minconfig)) { | |
2b7d9b21 | 1133 | build "useconfig:$minconfig" or return 0; |
6c5ee0be SR |
1134 | } else { |
1135 | # ?? no config to use? | |
2b7d9b21 | 1136 | build "oldconfig" or return 0; |
6c5ee0be SR |
1137 | } |
1138 | ||
2b7d9b21 | 1139 | check_buildlog $sha1 or return 0; |
6c5ee0be SR |
1140 | |
1141 | next if ($type eq "build"); | |
1142 | ||
1143 | get_grub_index; | |
1144 | get_version; | |
1145 | install; | |
6c5ee0be | 1146 | |
7faafbd6 SR |
1147 | my $failed = 0; |
1148 | ||
1149 | start_monitor; | |
1150 | monitor or $failed = 1; | |
1151 | ||
1152 | if (!$failed && $type ne "boot"){ | |
1153 | do_run_test or $failed = 1; | |
1154 | } | |
1155 | end_monitor; | |
1156 | return 0 if ($failed); | |
1157 | ||
6c5ee0be SR |
1158 | } |
1159 | $in_patchcheck = 0; | |
1160 | success $i; | |
2b7d9b21 SR |
1161 | |
1162 | return 1; | |
6c5ee0be SR |
1163 | } |
1164 | ||
2545eb61 SR |
1165 | read_config $ARGV[0]; |
1166 | ||
1167 | # mandatory configs | |
1168 | die "MACHINE not defined\n" if (!defined($opt{"MACHINE"})); | |
1169 | die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"})); | |
1170 | die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"})); | |
1171 | die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"})); | |
1172 | die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"})); | |
75c3fda7 | 1173 | die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"})); |
2545eb61 SR |
1174 | die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"})); |
1175 | die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"})); | |
1176 | die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"})); | |
2545eb61 | 1177 | |
2b7d9b21 SR |
1178 | if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { |
1179 | unlink $opt{"LOG_FILE"}; | |
1180 | } | |
2545eb61 | 1181 | |
2b7d9b21 SR |
1182 | doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; |
1183 | ||
a57419b3 SR |
1184 | for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { |
1185 | ||
1186 | if (!$i) { | |
1187 | doprint "DEFAULT OPTIONS:\n"; | |
1188 | } else { | |
1189 | doprint "\nTEST $i OPTIONS"; | |
1190 | if (defined($repeat_tests{$i})) { | |
1191 | $repeat = $repeat_tests{$i}; | |
1192 | doprint " ITERATE $repeat"; | |
1193 | } | |
1194 | doprint "\n"; | |
1195 | } | |
1196 | ||
1197 | foreach my $option (sort keys %opt) { | |
1198 | ||
1199 | if ($option =~ /\[(\d+)\]$/) { | |
1200 | next if ($i != $1); | |
1201 | } else { | |
1202 | next if ($i); | |
1203 | } | |
1204 | ||
1205 | doprint "$option = $opt{$option}\n"; | |
1206 | } | |
2b7d9b21 | 1207 | } |
2545eb61 | 1208 | |
a75fecec | 1209 | sub set_test_option { |
5a391fbf | 1210 | my ($name, $i) = @_; |
2545eb61 | 1211 | |
5a391fbf | 1212 | my $option = "$name\[$i\]"; |
5c42fc5b | 1213 | |
5a391fbf SR |
1214 | if (defined($opt{$option})) { |
1215 | return $opt{$option}; | |
5f9b6ced SR |
1216 | } |
1217 | ||
a57419b3 SR |
1218 | foreach my $test (keys %repeat_tests) { |
1219 | if ($i >= $test && | |
1220 | $i < $test + $repeat_tests{$test}) { | |
1221 | $option = "$name\[$test\]"; | |
1222 | if (defined($opt{$option})) { | |
1223 | return $opt{$option}; | |
1224 | } | |
1225 | } | |
1226 | } | |
1227 | ||
5a391fbf SR |
1228 | if (defined($opt{$name})) { |
1229 | return $opt{$name}; | |
2545eb61 SR |
1230 | } |
1231 | ||
5a391fbf SR |
1232 | return undef; |
1233 | } | |
1234 | ||
1235 | # First we need to do is the builds | |
a75fecec SR |
1236 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { |
1237 | ||
576f627c SR |
1238 | $iteration = $i; |
1239 | ||
a75fecec SR |
1240 | my $ssh_user = set_test_option("SSH_USER", $i); |
1241 | my $makecmd = set_test_option("MAKE_CMD", $i); | |
1242 | ||
1243 | $machine = set_test_option("MACHINE", $i); | |
1244 | $tmpdir = set_test_option("TMP_DIR", $i); | |
1245 | $outputdir = set_test_option("OUTPUT_DIR", $i); | |
1246 | $builddir = set_test_option("BUILD_DIR", $i); | |
1247 | $test_type = set_test_option("TEST_TYPE", $i); | |
1248 | $build_type = set_test_option("BUILD_TYPE", $i); | |
1249 | $build_options = set_test_option("BUILD_OPTIONS", $i); | |
1250 | $power_cycle = set_test_option("POWER_CYCLE", $i); | |
1251 | $noclean = set_test_option("BUILD_NOCLEAN", $i); | |
1252 | $minconfig = set_test_option("MIN_CONFIG", $i); | |
1253 | $run_test = set_test_option("TEST", $i); | |
1254 | $addconfig = set_test_option("ADD_CONFIG", $i); | |
1255 | $reboot_type = set_test_option("REBOOT_TYPE", $i); | |
1256 | $grub_menu = set_test_option("GRUB_MENU", $i); | |
8b37ca8c | 1257 | $post_install = set_test_option("POST_INSTALL", $i); |
a75fecec SR |
1258 | $reboot_script = set_test_option("REBOOT_SCRIPT", $i); |
1259 | $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i); | |
1260 | $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i); | |
1261 | $die_on_failure = set_test_option("DIE_ON_FAILURE", $i); | |
1262 | $power_off = set_test_option("POWER_OFF", $i); | |
576f627c SR |
1263 | $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i); |
1264 | $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i); | |
a75fecec SR |
1265 | $sleep_time = set_test_option("SLEEP_TIME", $i); |
1266 | $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); | |
1267 | $store_failures = set_test_option("STORE_FAILURES", $i); | |
1268 | $timeout = set_test_option("TIMEOUT", $i); | |
1269 | $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i); | |
1270 | $console = set_test_option("CONSOLE", $i); | |
1271 | $success_line = set_test_option("SUCCESS_LINE", $i); | |
1272 | $build_target = set_test_option("BUILD_TARGET", $i); | |
1273 | $target_image = set_test_option("TARGET_IMAGE", $i); | |
1274 | $localversion = set_test_option("LOCALVERSION", $i); | |
1275 | ||
1276 | chdir $builddir || die "can't change directory to $builddir"; | |
1277 | ||
1278 | if (!-d $tmpdir) { | |
1279 | mkpath($tmpdir) or | |
1280 | die "can't create $tmpdir"; | |
1281 | } | |
1a5cfce3 | 1282 | |
a75fecec SR |
1283 | $target = "$ssh_user\@$machine"; |
1284 | ||
1285 | $buildlog = "$tmpdir/buildlog-$machine"; | |
1286 | $dmesg = "$tmpdir/dmesg-$machine"; | |
1287 | $make = "$makecmd O=$outputdir"; | |
1288 | ||
1289 | if ($reboot_type eq "grub") { | |
576f627c | 1290 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); |
a75fecec | 1291 | } elsif (!defined($reboot_script)) { |
576f627c | 1292 | dodie "REBOOT_SCRIPT not defined" |
a75fecec SR |
1293 | } |
1294 | ||
1295 | my $run_type = $build_type; | |
1296 | if ($test_type eq "patchcheck") { | |
1297 | $run_type = $opt{"PATCHCHECK_TYPE[$i]"}; | |
1298 | } elsif ($test_type eq "bisect") { | |
1299 | $run_type = $opt{"BISECT_TYPE[$i]"}; | |
1300 | } | |
1301 | ||
1302 | # mistake in config file? | |
1303 | if (!defined($run_type)) { | |
1304 | $run_type = "ERROR"; | |
1305 | } | |
5a391fbf | 1306 | |
2545eb61 | 1307 | doprint "\n\n"; |
a75fecec | 1308 | doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n"; |
7faafbd6 SR |
1309 | |
1310 | unlink $dmesg; | |
1311 | unlink $buildlog; | |
2545eb61 | 1312 | |
2b7d9b21 SR |
1313 | if (!defined($minconfig)) { |
1314 | $minconfig = $addconfig; | |
1315 | ||
1316 | } elsif (defined($addconfig)) { | |
a75fecec | 1317 | run_command "cat $addconfig $minconfig > $tmpdir/use_config" or |
2b7d9b21 | 1318 | dodie "Failed to create temp config"; |
a75fecec | 1319 | $minconfig = "$tmpdir/use_config"; |
2b7d9b21 SR |
1320 | } |
1321 | ||
6c5ee0be SR |
1322 | my $checkout = $opt{"CHECKOUT[$i]"}; |
1323 | if (defined($checkout)) { | |
1324 | run_command "git checkout $checkout" or | |
1325 | die "failed to checkout $checkout"; | |
1326 | } | |
1327 | ||
a75fecec | 1328 | if ($test_type eq "bisect") { |
5f9b6ced SR |
1329 | bisect $i; |
1330 | next; | |
a75fecec | 1331 | } elsif ($test_type eq "patchcheck") { |
6c5ee0be SR |
1332 | patchcheck $i; |
1333 | next; | |
2545eb61 | 1334 | } |
2545eb61 | 1335 | |
7faafbd6 SR |
1336 | if ($build_type ne "nobuild") { |
1337 | build $build_type or next; | |
2545eb61 SR |
1338 | } |
1339 | ||
a75fecec SR |
1340 | if ($test_type ne "build") { |
1341 | get_grub_index; | |
1342 | get_version; | |
1343 | install; | |
5a391fbf | 1344 | |
a75fecec SR |
1345 | my $failed = 0; |
1346 | start_monitor; | |
1347 | monitor or $failed = 1;; | |
1348 | ||
1349 | if (!$failed && $test_type ne "boot" && defined($run_test)) { | |
1350 | do_run_test or $failed = 1; | |
1351 | } | |
1352 | end_monitor; | |
1353 | next if ($failed); | |
5a391fbf SR |
1354 | } |
1355 | ||
5f9b6ced | 1356 | success $i; |
2545eb61 SR |
1357 | } |
1358 | ||
5c42fc5b | 1359 | if ($opt{"POWEROFF_ON_SUCCESS"}) { |
75c3fda7 | 1360 | halt; |
576f627c | 1361 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) { |
75c3fda7 | 1362 | reboot; |
5c42fc5b | 1363 | } |
75c3fda7 | 1364 | |
2545eb61 | 1365 | exit 0; |