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 | ||
e48c5293 SR |
14 | my $VERSION = "0.2"; |
15 | ||
16 | $#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n"; | |
2545eb61 SR |
17 | |
18 | $| = 1; | |
19 | ||
20 | my %opt; | |
a57419b3 SR |
21 | my %repeat_tests; |
22 | my %repeats; | |
a75fecec | 23 | my %default; |
2545eb61 SR |
24 | |
25 | #default opts | |
a57419b3 | 26 | $default{"NUM_TESTS"} = 1; |
a75fecec SR |
27 | $default{"REBOOT_TYPE"} = "grub"; |
28 | $default{"TEST_TYPE"} = "test"; | |
29 | $default{"BUILD_TYPE"} = "randconfig"; | |
30 | $default{"MAKE_CMD"} = "make"; | |
31 | $default{"TIMEOUT"} = 120; | |
a57419b3 | 32 | $default{"TMP_DIR"} = "/tmp/ktest"; |
a75fecec SR |
33 | $default{"SLEEP_TIME"} = 60; # sleep time between tests |
34 | $default{"BUILD_NOCLEAN"} = 0; | |
35 | $default{"REBOOT_ON_ERROR"} = 0; | |
36 | $default{"POWEROFF_ON_ERROR"} = 0; | |
37 | $default{"REBOOT_ON_SUCCESS"} = 1; | |
38 | $default{"POWEROFF_ON_SUCCESS"} = 0; | |
39 | $default{"BUILD_OPTIONS"} = ""; | |
40 | $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects | |
41 | $default{"CLEAR_LOG"} = 0; | |
42 | $default{"SUCCESS_LINE"} = "login:"; | |
43 | $default{"BOOTED_TIMEOUT"} = 1; | |
44 | $default{"DIE_ON_FAILURE"} = 1; | |
e48c5293 SR |
45 | $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND"; |
46 | $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE"; | |
47 | $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot"; | |
2545eb61 SR |
48 | |
49 | my $version; | |
a75fecec | 50 | my $machine; |
e48c5293 | 51 | my $ssh_user; |
a75fecec SR |
52 | my $tmpdir; |
53 | my $builddir; | |
54 | my $outputdir; | |
51ad1dd1 | 55 | my $output_config; |
a75fecec | 56 | my $test_type; |
7faafbd6 | 57 | my $build_type; |
a75fecec SR |
58 | my $build_options; |
59 | my $reboot_type; | |
60 | my $reboot_script; | |
61 | my $power_cycle; | |
e48c5293 | 62 | my $reboot; |
a75fecec SR |
63 | my $reboot_on_error; |
64 | my $poweroff_on_error; | |
65 | my $die_on_failure; | |
576f627c SR |
66 | my $powercycle_after_reboot; |
67 | my $poweroff_after_halt; | |
e48c5293 SR |
68 | my $ssh_exec; |
69 | my $scp_to_target; | |
a75fecec SR |
70 | my $power_off; |
71 | my $grub_menu; | |
2545eb61 SR |
72 | my $grub_number; |
73 | my $target; | |
74 | my $make; | |
8b37ca8c | 75 | my $post_install; |
5c42fc5b | 76 | my $noclean; |
5f9b6ced | 77 | my $minconfig; |
2b7d9b21 | 78 | my $addconfig; |
5f9b6ced SR |
79 | my $in_bisect = 0; |
80 | my $bisect_bad = ""; | |
d6ce2a0b | 81 | my $reverse_bisect; |
6c5ee0be | 82 | my $in_patchcheck = 0; |
5a391fbf | 83 | my $run_test; |
6c5ee0be | 84 | my $redirect; |
7faafbd6 SR |
85 | my $buildlog; |
86 | my $dmesg; | |
87 | my $monitor_fp; | |
88 | my $monitor_pid; | |
89 | my $monitor_cnt = 0; | |
a75fecec SR |
90 | my $sleep_time; |
91 | my $bisect_sleep_time; | |
92 | my $store_failures; | |
93 | my $timeout; | |
94 | my $booted_timeout; | |
95 | my $console; | |
96 | my $success_line; | |
97 | my $build_target; | |
98 | my $target_image; | |
99 | my $localversion; | |
576f627c | 100 | my $iteration = 0; |
e48c5293 | 101 | my $successes = 0; |
2545eb61 | 102 | |
a57419b3 SR |
103 | sub set_value { |
104 | my ($lvalue, $rvalue) = @_; | |
105 | ||
106 | if (defined($opt{$lvalue})) { | |
107 | die "Error: Option $lvalue defined more than once!\n"; | |
108 | } | |
21a9679f SR |
109 | if ($rvalue =~ /^\s*$/) { |
110 | delete $opt{$lvalue}; | |
111 | } else { | |
112 | $opt{$lvalue} = $rvalue; | |
113 | } | |
a57419b3 SR |
114 | } |
115 | ||
2545eb61 SR |
116 | sub read_config { |
117 | my ($config) = @_; | |
118 | ||
119 | open(IN, $config) || die "can't read file $config"; | |
120 | ||
a57419b3 SR |
121 | my $name = $config; |
122 | $name =~ s,.*/(.*),$1,; | |
123 | ||
124 | my $test_num = 0; | |
125 | my $default = 1; | |
126 | my $repeat = 1; | |
127 | my $num_tests_set = 0; | |
128 | my $skip = 0; | |
129 | my $rest; | |
130 | ||
2545eb61 SR |
131 | while (<IN>) { |
132 | ||
133 | # ignore blank lines and comments | |
134 | next if (/^\s*$/ || /\s*\#/); | |
135 | ||
a57419b3 SR |
136 | if (/^\s*TEST_START(.*)/) { |
137 | ||
138 | $rest = $1; | |
139 | ||
140 | if ($num_tests_set) { | |
141 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; | |
142 | } | |
143 | ||
144 | my $old_test_num = $test_num; | |
e48c5293 | 145 | my $old_repeat = $repeat; |
a57419b3 SR |
146 | |
147 | $test_num += $repeat; | |
148 | $default = 0; | |
149 | $repeat = 1; | |
150 | ||
151 | if ($rest =~ /\s+SKIP(.*)/) { | |
152 | $rest = $1; | |
153 | $skip = 1; | |
154 | } else { | |
155 | $skip = 0; | |
156 | } | |
157 | ||
158 | if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) { | |
159 | $repeat = $1; | |
160 | $rest = $2; | |
161 | $repeat_tests{"$test_num"} = $repeat; | |
162 | } | |
163 | ||
164 | if ($rest =~ /\s+SKIP(.*)/) { | |
165 | $rest = $1; | |
166 | $skip = 1; | |
167 | } | |
168 | ||
169 | if ($rest !~ /^\s*$/) { | |
170 | die "$name: $.: Gargbage found after TEST_START\n$_"; | |
171 | } | |
172 | ||
173 | if ($skip) { | |
174 | $test_num = $old_test_num; | |
e48c5293 | 175 | $repeat = $old_repeat; |
a57419b3 SR |
176 | } |
177 | ||
178 | } elsif (/^\s*DEFAULTS(.*)$/) { | |
179 | $default = 1; | |
180 | ||
181 | $rest = $1; | |
182 | ||
183 | if ($rest =~ /\s+SKIP(.*)/) { | |
184 | $rest = $1; | |
185 | $skip = 1; | |
186 | } else { | |
187 | $skip = 0; | |
188 | } | |
189 | ||
190 | if ($rest !~ /^\s*$/) { | |
191 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; | |
192 | } | |
193 | ||
194 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { | |
195 | ||
196 | next if ($skip); | |
197 | ||
2545eb61 SR |
198 | my $lvalue = $1; |
199 | my $rvalue = $2; | |
200 | ||
a57419b3 SR |
201 | if (!$default && |
202 | ($lvalue eq "NUM_TESTS" || | |
203 | $lvalue eq "LOG_FILE" || | |
204 | $lvalue eq "CLEAR_LOG")) { | |
205 | die "$name: $.: $lvalue must be set in DEFAULTS section\n"; | |
206 | } | |
207 | ||
208 | if ($lvalue eq "NUM_TESTS") { | |
209 | if ($test_num) { | |
210 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; | |
211 | } | |
212 | if (!$default) { | |
213 | die "$name: $.: NUM_TESTS must be set in default section\n"; | |
214 | } | |
215 | $num_tests_set = 1; | |
216 | } | |
217 | ||
218 | if ($default || $lvalue =~ /\[\d+\]$/) { | |
219 | set_value($lvalue, $rvalue); | |
220 | } else { | |
221 | my $val = "$lvalue\[$test_num\]"; | |
222 | set_value($val, $rvalue); | |
223 | ||
224 | if ($repeat > 1) { | |
225 | $repeats{$val} = $repeat; | |
226 | } | |
a75fecec | 227 | } |
a57419b3 SR |
228 | } else { |
229 | die "$name: $.: Garbage found in config\n$_"; | |
2545eb61 SR |
230 | } |
231 | } | |
232 | ||
233 | close(IN); | |
a75fecec | 234 | |
a57419b3 SR |
235 | if ($test_num) { |
236 | $test_num += $repeat - 1; | |
237 | $opt{"NUM_TESTS"} = $test_num; | |
238 | } | |
239 | ||
a75fecec SR |
240 | # set any defaults |
241 | ||
242 | foreach my $default (keys %default) { | |
243 | if (!defined($opt{$default})) { | |
244 | $opt{$default} = $default{$default}; | |
245 | } | |
246 | } | |
2545eb61 SR |
247 | } |
248 | ||
d1e2f22a | 249 | sub _logit { |
2545eb61 SR |
250 | if (defined($opt{"LOG_FILE"})) { |
251 | open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}"; | |
252 | print OUT @_; | |
253 | close(OUT); | |
254 | } | |
255 | } | |
256 | ||
d1e2f22a SR |
257 | sub logit { |
258 | if (defined($opt{"LOG_FILE"})) { | |
259 | _logit @_; | |
260 | } else { | |
261 | print @_; | |
262 | } | |
263 | } | |
264 | ||
5f9b6ced SR |
265 | sub doprint { |
266 | print @_; | |
d1e2f22a | 267 | _logit @_; |
5f9b6ced SR |
268 | } |
269 | ||
7faafbd6 SR |
270 | sub run_command; |
271 | ||
272 | sub reboot { | |
273 | # try to reboot normally | |
e48c5293 | 274 | if (run_command $reboot) { |
576f627c SR |
275 | if (defined($powercycle_after_reboot)) { |
276 | sleep $powercycle_after_reboot; | |
277 | run_command "$power_cycle"; | |
278 | } | |
279 | } else { | |
7faafbd6 | 280 | # nope? power cycle it. |
a75fecec | 281 | run_command "$power_cycle"; |
7faafbd6 SR |
282 | } |
283 | } | |
284 | ||
576f627c SR |
285 | sub do_not_reboot { |
286 | my $i = $iteration; | |
287 | ||
288 | return $test_type eq "build" || | |
289 | ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") || | |
290 | ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build"); | |
291 | } | |
292 | ||
5c42fc5b | 293 | sub dodie { |
5a391fbf | 294 | doprint "CRITICAL FAILURE... ", @_, "\n"; |
5c42fc5b | 295 | |
576f627c SR |
296 | my $i = $iteration; |
297 | ||
298 | if ($reboot_on_error && !do_not_reboot) { | |
299 | ||
75c3fda7 | 300 | doprint "REBOOTING\n"; |
7faafbd6 | 301 | reboot; |
75c3fda7 | 302 | |
a75fecec | 303 | } elsif ($poweroff_on_error && defined($power_off)) { |
5c42fc5b | 304 | doprint "POWERING OFF\n"; |
a75fecec | 305 | `$power_off`; |
5c42fc5b | 306 | } |
75c3fda7 | 307 | |
576f627c | 308 | die @_, "\n"; |
5c42fc5b SR |
309 | } |
310 | ||
7faafbd6 SR |
311 | sub open_console { |
312 | my ($fp) = @_; | |
313 | ||
314 | my $flags; | |
315 | ||
a75fecec SR |
316 | my $pid = open($fp, "$console|") or |
317 | dodie "Can't open console $console"; | |
7faafbd6 SR |
318 | |
319 | $flags = fcntl($fp, F_GETFL, 0) or | |
576f627c | 320 | dodie "Can't get flags for the socket: $!"; |
7faafbd6 | 321 | $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or |
576f627c | 322 | dodie "Can't set flags for the socket: $!"; |
7faafbd6 SR |
323 | |
324 | return $pid; | |
325 | } | |
326 | ||
327 | sub close_console { | |
328 | my ($fp, $pid) = @_; | |
329 | ||
330 | doprint "kill child process $pid\n"; | |
331 | kill 2, $pid; | |
332 | ||
333 | print "closing!\n"; | |
334 | close($fp); | |
335 | } | |
336 | ||
337 | sub start_monitor { | |
338 | if ($monitor_cnt++) { | |
339 | return; | |
340 | } | |
341 | $monitor_fp = \*MONFD; | |
342 | $monitor_pid = open_console $monitor_fp; | |
a75fecec SR |
343 | |
344 | return; | |
345 | ||
346 | open(MONFD, "Stop perl from warning about single use of MONFD"); | |
7faafbd6 SR |
347 | } |
348 | ||
349 | sub end_monitor { | |
350 | if (--$monitor_cnt) { | |
351 | return; | |
352 | } | |
353 | close_console($monitor_fp, $monitor_pid); | |
354 | } | |
355 | ||
356 | sub wait_for_monitor { | |
357 | my ($time) = @_; | |
358 | my $line; | |
359 | ||
a75fecec | 360 | doprint "** Wait for monitor to settle down **\n"; |
7faafbd6 SR |
361 | |
362 | # read the monitor and wait for the system to calm down | |
363 | do { | |
364 | $line = wait_for_input($monitor_fp, $time); | |
a75fecec | 365 | print "$line" if (defined($line)); |
7faafbd6 | 366 | } while (defined($line)); |
a75fecec | 367 | print "** Monitor flushed **\n"; |
7faafbd6 SR |
368 | } |
369 | ||
2b7d9b21 SR |
370 | sub fail { |
371 | ||
a75fecec | 372 | if ($die_on_failure) { |
2b7d9b21 SR |
373 | dodie @_; |
374 | } | |
375 | ||
a75fecec | 376 | doprint "FAILED\n"; |
7faafbd6 | 377 | |
576f627c SR |
378 | my $i = $iteration; |
379 | ||
a75fecec | 380 | # no need to reboot for just building. |
576f627c | 381 | if (!do_not_reboot) { |
a75fecec SR |
382 | doprint "REBOOTING\n"; |
383 | reboot; | |
384 | start_monitor; | |
385 | wait_for_monitor $sleep_time; | |
386 | end_monitor; | |
387 | } | |
7faafbd6 | 388 | |
576f627c SR |
389 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
390 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | |
7a849cd9 | 391 | doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n"; |
576f627c SR |
392 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
393 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | |
a75fecec SR |
394 | |
395 | return 1 if (!defined($store_failures)); | |
7faafbd6 SR |
396 | |
397 | my @t = localtime; | |
398 | my $date = sprintf "%04d%02d%02d%02d%02d%02d", | |
399 | 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0]; | |
400 | ||
cccae1a6 SR |
401 | my $type = $build_type; |
402 | if ($type =~ /useconfig/) { | |
403 | $type = "useconfig"; | |
404 | } | |
405 | ||
406 | my $dir = "$machine-$test_type-$type-fail-$date"; | |
a75fecec | 407 | my $faildir = "$store_failures/$dir"; |
7faafbd6 SR |
408 | |
409 | if (!-d $faildir) { | |
410 | mkpath($faildir) or | |
a75fecec | 411 | die "can't create $faildir"; |
7faafbd6 | 412 | } |
51ad1dd1 SR |
413 | if (-f "$output_config") { |
414 | cp "$output_config", "$faildir/config" or | |
7faafbd6 SR |
415 | die "failed to copy .config"; |
416 | } | |
417 | if (-f $buildlog) { | |
418 | cp $buildlog, "$faildir/buildlog" or | |
419 | die "failed to move $buildlog"; | |
420 | } | |
421 | if (-f $dmesg) { | |
422 | cp $dmesg, "$faildir/dmesg" or | |
423 | die "failed to move $dmesg"; | |
424 | } | |
425 | ||
426 | doprint "*** Saved info to $faildir ***\n"; | |
427 | ||
2b7d9b21 SR |
428 | return 1; |
429 | } | |
430 | ||
2545eb61 SR |
431 | sub run_command { |
432 | my ($command) = @_; | |
d6ce2a0b SR |
433 | my $dolog = 0; |
434 | my $dord = 0; | |
435 | my $pid; | |
436 | ||
e48c5293 SR |
437 | $command =~ s/\$SSH_USER/$ssh_user/g; |
438 | $command =~ s/\$MACHINE/$machine/g; | |
439 | ||
d6ce2a0b SR |
440 | doprint("$command ... "); |
441 | ||
442 | $pid = open(CMD, "$command 2>&1 |") or | |
2b7d9b21 | 443 | (fail "unable to exec $command" and return 0); |
2545eb61 SR |
444 | |
445 | if (defined($opt{"LOG_FILE"})) { | |
d6ce2a0b SR |
446 | open(LOG, ">>$opt{LOG_FILE}") or |
447 | dodie "failed to write to log"; | |
448 | $dolog = 1; | |
6c5ee0be SR |
449 | } |
450 | ||
451 | if (defined($redirect)) { | |
d6ce2a0b SR |
452 | open (RD, ">$redirect") or |
453 | dodie "failed to write to redirect $redirect"; | |
454 | $dord = 1; | |
2545eb61 SR |
455 | } |
456 | ||
d6ce2a0b SR |
457 | while (<CMD>) { |
458 | print LOG if ($dolog); | |
459 | print RD if ($dord); | |
460 | } | |
2545eb61 | 461 | |
d6ce2a0b | 462 | waitpid($pid, 0); |
2545eb61 SR |
463 | my $failed = $?; |
464 | ||
d6ce2a0b SR |
465 | close(CMD); |
466 | close(LOG) if ($dolog); | |
467 | close(RD) if ($dord); | |
468 | ||
2545eb61 SR |
469 | if ($failed) { |
470 | doprint "FAILED!\n"; | |
471 | } else { | |
472 | doprint "SUCCESS\n"; | |
473 | } | |
474 | ||
5f9b6ced SR |
475 | return !$failed; |
476 | } | |
477 | ||
e48c5293 SR |
478 | sub run_ssh { |
479 | my ($cmd) = @_; | |
480 | my $cp_exec = $ssh_exec; | |
481 | ||
482 | $cp_exec =~ s/\$SSH_COMMAND/$cmd/g; | |
483 | return run_command "$cp_exec"; | |
484 | } | |
485 | ||
486 | sub run_scp { | |
487 | my ($src, $dst) = @_; | |
488 | my $cp_scp = $scp_to_target; | |
489 | ||
490 | $cp_scp =~ s/\$SRC_FILE/$src/g; | |
491 | $cp_scp =~ s/\$DST_FILE/$dst/g; | |
492 | ||
493 | return run_command "$cp_scp"; | |
494 | } | |
495 | ||
5f9b6ced SR |
496 | sub get_grub_index { |
497 | ||
a75fecec SR |
498 | if ($reboot_type ne "grub") { |
499 | return; | |
500 | } | |
5a391fbf | 501 | return if (defined($grub_number)); |
5f9b6ced SR |
502 | |
503 | doprint "Find grub menu ... "; | |
504 | $grub_number = -1; | |
e48c5293 SR |
505 | |
506 | my $ssh_grub = $ssh_exec; | |
507 | $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g; | |
508 | ||
509 | open(IN, "$ssh_grub |") | |
5f9b6ced | 510 | or die "unable to get menu.lst"; |
e48c5293 | 511 | |
5f9b6ced | 512 | while (<IN>) { |
a75fecec | 513 | if (/^\s*title\s+$grub_menu\s*$/) { |
5f9b6ced SR |
514 | $grub_number++; |
515 | last; | |
516 | } elsif (/^\s*title\s/) { | |
517 | $grub_number++; | |
518 | } | |
519 | } | |
520 | close(IN); | |
521 | ||
a75fecec | 522 | die "Could not find '$grub_menu' in /boot/grub/menu on $machine" |
5f9b6ced SR |
523 | if ($grub_number < 0); |
524 | doprint "$grub_number\n"; | |
2545eb61 SR |
525 | } |
526 | ||
2545eb61 SR |
527 | sub wait_for_input |
528 | { | |
529 | my ($fp, $time) = @_; | |
530 | my $rin; | |
531 | my $ready; | |
532 | my $line; | |
533 | my $ch; | |
534 | ||
535 | if (!defined($time)) { | |
536 | $time = $timeout; | |
537 | } | |
538 | ||
539 | $rin = ''; | |
540 | vec($rin, fileno($fp), 1) = 1; | |
541 | $ready = select($rin, undef, undef, $time); | |
542 | ||
543 | $line = ""; | |
544 | ||
545 | # try to read one char at a time | |
546 | while (sysread $fp, $ch, 1) { | |
547 | $line .= $ch; | |
548 | last if ($ch eq "\n"); | |
549 | } | |
550 | ||
551 | if (!length($line)) { | |
552 | return undef; | |
553 | } | |
554 | ||
555 | return $line; | |
556 | } | |
557 | ||
75c3fda7 | 558 | sub reboot_to { |
a75fecec | 559 | if ($reboot_type eq "grub") { |
e48c5293 | 560 | run_command "$ssh_exec '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'"; |
a75fecec SR |
561 | return; |
562 | } | |
563 | ||
564 | run_command "$reboot_script"; | |
2545eb61 SR |
565 | } |
566 | ||
a57419b3 SR |
567 | sub get_sha1 { |
568 | my ($commit) = @_; | |
569 | ||
570 | doprint "git rev-list --max-count=1 $commit ... "; | |
571 | my $sha1 = `git rev-list --max-count=1 $commit`; | |
572 | my $ret = $?; | |
573 | ||
574 | logit $sha1; | |
575 | ||
576 | if ($ret) { | |
577 | doprint "FAILED\n"; | |
578 | dodie "Failed to get git $commit"; | |
579 | } | |
580 | ||
581 | print "SUCCESS\n"; | |
582 | ||
583 | chomp $sha1; | |
584 | ||
585 | return $sha1; | |
586 | } | |
587 | ||
5a391fbf | 588 | sub monitor { |
2545eb61 SR |
589 | my $booted = 0; |
590 | my $bug = 0; | |
5c42fc5b | 591 | my $skip_call_trace = 0; |
2b7d9b21 | 592 | my $loops; |
2545eb61 | 593 | |
7faafbd6 | 594 | wait_for_monitor 5; |
2545eb61 SR |
595 | |
596 | my $line; | |
597 | my $full_line = ""; | |
598 | ||
7faafbd6 SR |
599 | open(DMESG, "> $dmesg") or |
600 | die "unable to write to $dmesg"; | |
2545eb61 | 601 | |
75c3fda7 | 602 | reboot_to; |
2545eb61 SR |
603 | |
604 | for (;;) { | |
605 | ||
2b7d9b21 | 606 | if ($booted) { |
a75fecec | 607 | $line = wait_for_input($monitor_fp, $booted_timeout); |
2b7d9b21 | 608 | } else { |
7faafbd6 | 609 | $line = wait_for_input($monitor_fp); |
2b7d9b21 | 610 | } |
2545eb61 SR |
611 | |
612 | last if (!defined($line)); | |
613 | ||
614 | doprint $line; | |
7faafbd6 | 615 | print DMESG $line; |
2545eb61 SR |
616 | |
617 | # we are not guaranteed to get a full line | |
618 | $full_line .= $line; | |
619 | ||
a75fecec | 620 | if ($full_line =~ /$success_line/) { |
2545eb61 SR |
621 | $booted = 1; |
622 | } | |
623 | ||
5c42fc5b SR |
624 | if ($full_line =~ /\[ backtrace testing \]/) { |
625 | $skip_call_trace = 1; | |
626 | } | |
627 | ||
2545eb61 | 628 | if ($full_line =~ /call trace:/i) { |
5c42fc5b SR |
629 | $bug = 1 if (!$skip_call_trace); |
630 | } | |
631 | ||
632 | if ($full_line =~ /\[ end of backtrace testing \]/) { | |
633 | $skip_call_trace = 0; | |
634 | } | |
635 | ||
636 | if ($full_line =~ /Kernel panic -/) { | |
2545eb61 SR |
637 | $bug = 1; |
638 | } | |
639 | ||
640 | if ($line =~ /\n/) { | |
641 | $full_line = ""; | |
642 | } | |
643 | } | |
644 | ||
7faafbd6 | 645 | close(DMESG); |
2545eb61 | 646 | |
a75fecec | 647 | if ($bug) { |
2b7d9b21 | 648 | return 0 if ($in_bisect); |
576f627c | 649 | fail "failed - got a bug report" and return 0; |
2545eb61 SR |
650 | } |
651 | ||
a75fecec | 652 | if (!$booted) { |
2b7d9b21 | 653 | return 0 if ($in_bisect); |
576f627c | 654 | fail "failed - never got a boot prompt." and return 0; |
2545eb61 | 655 | } |
5f9b6ced | 656 | |
2b7d9b21 | 657 | return 1; |
2545eb61 SR |
658 | } |
659 | ||
660 | sub install { | |
661 | ||
e48c5293 | 662 | run_scp "$outputdir/$build_target", "$target_image" or |
5c42fc5b | 663 | dodie "failed to copy image"; |
2545eb61 | 664 | |
5f9b6ced | 665 | my $install_mods = 0; |
2545eb61 | 666 | |
5f9b6ced SR |
667 | # should we process modules? |
668 | $install_mods = 0; | |
51ad1dd1 | 669 | open(IN, "$output_config") or dodie("Can't read config file"); |
5f9b6ced SR |
670 | while (<IN>) { |
671 | if (/CONFIG_MODULES(=y)?/) { | |
672 | $install_mods = 1 if (defined($1)); | |
673 | last; | |
5c42fc5b | 674 | } |
5f9b6ced SR |
675 | } |
676 | close(IN); | |
5c42fc5b | 677 | |
5f9b6ced SR |
678 | if (!$install_mods) { |
679 | doprint "No modules needed\n"; | |
680 | return; | |
681 | } | |
2545eb61 | 682 | |
a75fecec | 683 | run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or |
5f9b6ced | 684 | dodie "Failed to install modules"; |
5c42fc5b | 685 | |
5f9b6ced | 686 | my $modlib = "/lib/modules/$version"; |
a57419b3 | 687 | my $modtar = "ktest-mods.tar.bz2"; |
5c42fc5b | 688 | |
e48c5293 | 689 | run_ssh "rm -rf $modlib" or |
5f9b6ced | 690 | dodie "failed to remove old mods: $modlib"; |
5c42fc5b | 691 | |
5f9b6ced | 692 | # would be nice if scp -r did not follow symbolic links |
a75fecec | 693 | run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or |
5f9b6ced SR |
694 | dodie "making tarball"; |
695 | ||
e48c5293 | 696 | run_scp "$tmpdir/$modtar", "/tmp" or |
5f9b6ced SR |
697 | dodie "failed to copy modules"; |
698 | ||
a75fecec | 699 | unlink "$tmpdir/$modtar"; |
5f9b6ced | 700 | |
e48c5293 | 701 | run_ssh "'(cd / && tar xf /tmp/$modtar)'" or |
5f9b6ced | 702 | dodie "failed to tar modules"; |
2545eb61 | 703 | |
e48c5293 | 704 | run_ssh "rm -f /tmp/$modtar"; |
8b37ca8c SR |
705 | |
706 | return if (!defined($post_install)); | |
707 | ||
e48c5293 SR |
708 | my $cp_post_install = $post_install; |
709 | $cp_post_install = s/\$KERNEL_VERSION/$version/g; | |
710 | run_command "$cp_post_install" or | |
576f627c | 711 | dodie "Failed to run post install"; |
2545eb61 SR |
712 | } |
713 | ||
6c5ee0be SR |
714 | sub check_buildlog { |
715 | my ($patch) = @_; | |
716 | ||
6c5ee0be SR |
717 | my @files = `git show $patch | diffstat -l`; |
718 | ||
719 | open(IN, "git show $patch |") or | |
720 | dodie "failed to show $patch"; | |
721 | while (<IN>) { | |
722 | if (m,^--- a/(.*),) { | |
723 | chomp $1; | |
724 | $files[$#files] = $1; | |
725 | } | |
726 | } | |
727 | close(IN); | |
728 | ||
729 | open(IN, $buildlog) or dodie "Can't open $buildlog"; | |
730 | while (<IN>) { | |
731 | if (/^\s*(.*?):.*(warning|error)/) { | |
732 | my $err = $1; | |
733 | foreach my $file (@files) { | |
a75fecec | 734 | my $fullpath = "$builddir/$file"; |
6c5ee0be | 735 | if ($file eq $err || $fullpath eq $err) { |
2b7d9b21 | 736 | fail "$file built with warnings" and return 0; |
6c5ee0be SR |
737 | } |
738 | } | |
739 | } | |
740 | } | |
741 | close(IN); | |
2b7d9b21 SR |
742 | |
743 | return 1; | |
6c5ee0be SR |
744 | } |
745 | ||
2545eb61 SR |
746 | sub build { |
747 | my ($type) = @_; | |
5c42fc5b | 748 | my $defconfig = ""; |
5c42fc5b | 749 | |
7faafbd6 SR |
750 | unlink $buildlog; |
751 | ||
75c3fda7 | 752 | if ($type =~ /^useconfig:(.*)/) { |
51ad1dd1 | 753 | run_command "cp $1 $output_config" or |
75c3fda7 | 754 | dodie "could not copy $1 to .config"; |
5f9b6ced | 755 | |
75c3fda7 SR |
756 | $type = "oldconfig"; |
757 | } | |
758 | ||
5c42fc5b SR |
759 | # old config can ask questions |
760 | if ($type eq "oldconfig") { | |
9386c6ab | 761 | $type = "oldnoconfig"; |
75c3fda7 SR |
762 | |
763 | # allow for empty configs | |
51ad1dd1 | 764 | run_command "touch $output_config"; |
75c3fda7 | 765 | |
51ad1dd1 | 766 | run_command "mv $output_config $outputdir/config_temp" or |
5c42fc5b | 767 | dodie "moving .config"; |
2545eb61 | 768 | |
5f9b6ced | 769 | if (!$noclean && !run_command "$make mrproper") { |
5c42fc5b SR |
770 | dodie "make mrproper"; |
771 | } | |
2545eb61 | 772 | |
51ad1dd1 | 773 | run_command "mv $outputdir/config_temp $output_config" or |
5c42fc5b | 774 | dodie "moving config_temp"; |
5c42fc5b SR |
775 | |
776 | } elsif (!$noclean) { | |
51ad1dd1 | 777 | unlink "$output_config"; |
5f9b6ced | 778 | run_command "$make mrproper" or |
5c42fc5b | 779 | dodie "make mrproper"; |
5c42fc5b | 780 | } |
2545eb61 SR |
781 | |
782 | # add something to distinguish this build | |
a75fecec SR |
783 | open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file"); |
784 | print OUT "$localversion\n"; | |
2545eb61 SR |
785 | close(OUT); |
786 | ||
5f9b6ced SR |
787 | if (defined($minconfig)) { |
788 | $defconfig = "KCONFIG_ALLCONFIG=$minconfig"; | |
2545eb61 SR |
789 | } |
790 | ||
9386c6ab | 791 | run_command "$defconfig $make $type" or |
5c42fc5b | 792 | dodie "failed make config"; |
2545eb61 | 793 | |
a75fecec SR |
794 | $redirect = "$buildlog"; |
795 | if (!run_command "$make $build_options") { | |
6c5ee0be | 796 | undef $redirect; |
5f9b6ced | 797 | # bisect may need this to pass |
2b7d9b21 SR |
798 | return 0 if ($in_bisect); |
799 | fail "failed build" and return 0; | |
2545eb61 | 800 | } |
6c5ee0be | 801 | undef $redirect; |
5f9b6ced | 802 | |
2b7d9b21 | 803 | return 1; |
2545eb61 SR |
804 | } |
805 | ||
75c3fda7 | 806 | sub halt { |
e48c5293 | 807 | if (!run_ssh "halt" or defined($power_off)) { |
576f627c SR |
808 | if (defined($poweroff_after_halt)) { |
809 | sleep $poweroff_after_halt; | |
810 | run_command "$power_off"; | |
811 | } | |
812 | } else { | |
75c3fda7 | 813 | # nope? the zap it! |
a75fecec | 814 | run_command "$power_off"; |
75c3fda7 SR |
815 | } |
816 | } | |
817 | ||
5f9b6ced SR |
818 | sub success { |
819 | my ($i) = @_; | |
820 | ||
e48c5293 SR |
821 | $successes++; |
822 | ||
5f9b6ced SR |
823 | doprint "\n\n*******************************************\n"; |
824 | doprint "*******************************************\n"; | |
7a849cd9 | 825 | doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n"; |
5f9b6ced SR |
826 | doprint "*******************************************\n"; |
827 | doprint "*******************************************\n"; | |
828 | ||
576f627c | 829 | if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) { |
a75fecec | 830 | doprint "Reboot and wait $sleep_time seconds\n"; |
5f9b6ced | 831 | reboot; |
7faafbd6 | 832 | start_monitor; |
a75fecec | 833 | wait_for_monitor $sleep_time; |
7faafbd6 | 834 | end_monitor; |
5f9b6ced SR |
835 | } |
836 | } | |
837 | ||
838 | sub get_version { | |
839 | # get the release name | |
840 | doprint "$make kernelrelease ... "; | |
841 | $version = `$make kernelrelease | tail -1`; | |
842 | chomp($version); | |
843 | doprint "$version\n"; | |
844 | } | |
845 | ||
5a391fbf | 846 | sub child_run_test { |
7faafbd6 | 847 | my $failed = 0; |
5a391fbf | 848 | |
7faafbd6 | 849 | # child should have no power |
a75fecec SR |
850 | $reboot_on_error = 0; |
851 | $poweroff_on_error = 0; | |
852 | $die_on_failure = 1; | |
7faafbd6 SR |
853 | |
854 | run_command $run_test or $failed = 1; | |
5a391fbf SR |
855 | exit $failed; |
856 | } | |
857 | ||
858 | my $child_done; | |
859 | ||
860 | sub child_finished { | |
861 | $child_done = 1; | |
862 | } | |
863 | ||
864 | sub do_run_test { | |
865 | my $child_pid; | |
866 | my $child_exit; | |
5a391fbf SR |
867 | my $line; |
868 | my $full_line; | |
869 | my $bug = 0; | |
5a391fbf | 870 | |
7faafbd6 | 871 | wait_for_monitor 1; |
5a391fbf | 872 | |
7faafbd6 | 873 | doprint "run test $run_test\n"; |
5a391fbf SR |
874 | |
875 | $child_done = 0; | |
876 | ||
877 | $SIG{CHLD} = qw(child_finished); | |
878 | ||
879 | $child_pid = fork; | |
880 | ||
881 | child_run_test if (!$child_pid); | |
882 | ||
883 | $full_line = ""; | |
884 | ||
885 | do { | |
7faafbd6 | 886 | $line = wait_for_input($monitor_fp, 1); |
5a391fbf SR |
887 | if (defined($line)) { |
888 | ||
889 | # we are not guaranteed to get a full line | |
890 | $full_line .= $line; | |
891 | ||
892 | if ($full_line =~ /call trace:/i) { | |
893 | $bug = 1; | |
894 | } | |
895 | ||
896 | if ($full_line =~ /Kernel panic -/) { | |
897 | $bug = 1; | |
898 | } | |
899 | ||
900 | if ($line =~ /\n/) { | |
901 | $full_line = ""; | |
902 | } | |
903 | } | |
904 | } while (!$child_done && !$bug); | |
905 | ||
906 | if ($bug) { | |
907 | doprint "Detected kernel crash!\n"; | |
908 | # kill the child with extreme prejudice | |
909 | kill 9, $child_pid; | |
910 | } | |
911 | ||
912 | waitpid $child_pid, 0; | |
913 | $child_exit = $?; | |
914 | ||
5a391fbf | 915 | if ($bug || $child_exit) { |
2b7d9b21 SR |
916 | return 0 if $in_bisect; |
917 | fail "test failed" and return 0; | |
5a391fbf | 918 | } |
2b7d9b21 | 919 | return 1; |
5a391fbf SR |
920 | } |
921 | ||
a75fecec SR |
922 | sub run_git_bisect { |
923 | my ($command) = @_; | |
924 | ||
925 | doprint "$command ... "; | |
926 | ||
927 | my $output = `$command 2>&1`; | |
928 | my $ret = $?; | |
929 | ||
930 | logit $output; | |
931 | ||
932 | if ($ret) { | |
933 | doprint "FAILED\n"; | |
934 | dodie "Failed to git bisect"; | |
935 | } | |
936 | ||
937 | doprint "SUCCESS\n"; | |
938 | if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) { | |
939 | doprint "$1 [$2]\n"; | |
940 | } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) { | |
941 | $bisect_bad = $1; | |
942 | doprint "Found bad commit... $1\n"; | |
943 | return 0; | |
944 | } else { | |
945 | # we already logged it, just print it now. | |
946 | print $output; | |
947 | } | |
948 | ||
949 | return 1; | |
950 | } | |
951 | ||
0a05c769 SR |
952 | # returns 1 on success, 0 on failure |
953 | sub run_bisect_test { | |
954 | my ($type, $buildtype) = @_; | |
5f9b6ced | 955 | |
2b7d9b21 | 956 | my $failed = 0; |
5f9b6ced SR |
957 | my $result; |
958 | my $output; | |
959 | my $ret; | |
960 | ||
0a05c769 SR |
961 | $in_bisect = 1; |
962 | ||
963 | build $buildtype or $failed = 1; | |
5f9b6ced SR |
964 | |
965 | if ($type ne "build") { | |
7faafbd6 | 966 | dodie "Failed on build" if $failed; |
5f9b6ced SR |
967 | |
968 | # Now boot the box | |
969 | get_grub_index; | |
970 | get_version; | |
971 | install; | |
7faafbd6 SR |
972 | |
973 | start_monitor; | |
2b7d9b21 | 974 | monitor or $failed = 1; |
5f9b6ced SR |
975 | |
976 | if ($type ne "boot") { | |
7faafbd6 | 977 | dodie "Failed on boot" if $failed; |
5a391fbf | 978 | |
2b7d9b21 | 979 | do_run_test or $failed = 1; |
5f9b6ced | 980 | } |
7faafbd6 | 981 | end_monitor; |
5f9b6ced SR |
982 | } |
983 | ||
984 | if ($failed) { | |
0a05c769 | 985 | $result = 0; |
5a391fbf SR |
986 | |
987 | # reboot the box to a good kernel | |
a75fecec SR |
988 | if ($type ne "build") { |
989 | doprint "Reboot and sleep $bisect_sleep_time seconds\n"; | |
5a391fbf | 990 | reboot; |
7faafbd6 | 991 | start_monitor; |
a75fecec | 992 | wait_for_monitor $bisect_sleep_time; |
7faafbd6 | 993 | end_monitor; |
5a391fbf | 994 | } |
5f9b6ced | 995 | } else { |
0a05c769 SR |
996 | $result = 1; |
997 | } | |
998 | $in_bisect = 0; | |
999 | ||
1000 | return $result; | |
1001 | } | |
1002 | ||
1003 | sub run_bisect { | |
1004 | my ($type) = @_; | |
1005 | my $buildtype = "oldconfig"; | |
1006 | ||
1007 | # We should have a minconfig to use? | |
1008 | if (defined($minconfig)) { | |
1009 | $buildtype = "useconfig:$minconfig"; | |
5f9b6ced SR |
1010 | } |
1011 | ||
0a05c769 SR |
1012 | my $ret = run_bisect_test $type, $buildtype; |
1013 | ||
1014 | ||
d6ce2a0b SR |
1015 | # Are we looking for where it worked, not failed? |
1016 | if ($reverse_bisect) { | |
0a05c769 | 1017 | $ret = !$ret; |
d6ce2a0b SR |
1018 | } |
1019 | ||
0a05c769 SR |
1020 | if ($ret) { |
1021 | return "good"; | |
1022 | } else { | |
1023 | return "bad"; | |
1024 | } | |
5f9b6ced SR |
1025 | } |
1026 | ||
1027 | sub bisect { | |
1028 | my ($i) = @_; | |
1029 | ||
1030 | my $result; | |
1031 | ||
1032 | die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"})); | |
1033 | die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"})); | |
1034 | die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"})); | |
1035 | ||
1036 | my $good = $opt{"BISECT_GOOD[$i]"}; | |
1037 | my $bad = $opt{"BISECT_BAD[$i]"}; | |
1038 | my $type = $opt{"BISECT_TYPE[$i]"}; | |
a75fecec SR |
1039 | my $start = $opt{"BISECT_START[$i]"}; |
1040 | my $replay = $opt{"BISECT_REPLAY[$i]"}; | |
5f9b6ced | 1041 | |
a57419b3 SR |
1042 | # convert to true sha1's |
1043 | $good = get_sha1($good); | |
1044 | $bad = get_sha1($bad); | |
1045 | ||
d6ce2a0b SR |
1046 | if (defined($opt{"BISECT_REVERSE[$i]"}) && |
1047 | $opt{"BISECT_REVERSE[$i]"} == 1) { | |
1048 | doprint "Performing a reverse bisect (bad is good, good is bad!)\n"; | |
1049 | $reverse_bisect = 1; | |
1050 | } else { | |
1051 | $reverse_bisect = 0; | |
1052 | } | |
1053 | ||
a75fecec SR |
1054 | # Can't have a test without having a test to run |
1055 | if ($type eq "test" && !defined($run_test)) { | |
1056 | $type = "boot"; | |
1057 | } | |
1058 | ||
1059 | my $check = $opt{"BISECT_CHECK[$i]"}; | |
1060 | if (defined($check) && $check ne "0") { | |
1061 | ||
1062 | # get current HEAD | |
a57419b3 | 1063 | my $head = get_sha1("HEAD"); |
a75fecec SR |
1064 | |
1065 | if ($check ne "good") { | |
1066 | doprint "TESTING BISECT BAD [$bad]\n"; | |
1067 | run_command "git checkout $bad" or | |
1068 | die "Failed to checkout $bad"; | |
1069 | ||
1070 | $result = run_bisect $type; | |
1071 | ||
1072 | if ($result ne "bad") { | |
1073 | fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0; | |
1074 | } | |
1075 | } | |
1076 | ||
1077 | if ($check ne "bad") { | |
1078 | doprint "TESTING BISECT GOOD [$good]\n"; | |
1079 | run_command "git checkout $good" or | |
1080 | die "Failed to checkout $good"; | |
1081 | ||
1082 | $result = run_bisect $type; | |
1083 | ||
1084 | if ($result ne "good") { | |
1085 | fail "Tested BISECT_GOOD [$good] and it failed" and return 0; | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | # checkout where we started | |
1090 | run_command "git checkout $head" or | |
1091 | die "Failed to checkout $head"; | |
1092 | } | |
1093 | ||
5f9b6ced | 1094 | run_command "git bisect start" or |
a75fecec | 1095 | dodie "could not start bisect"; |
5f9b6ced SR |
1096 | |
1097 | run_command "git bisect good $good" or | |
a75fecec | 1098 | dodie "could not set bisect good to $good"; |
5f9b6ced | 1099 | |
a75fecec SR |
1100 | run_git_bisect "git bisect bad $bad" or |
1101 | dodie "could not set bisect bad to $bad"; | |
5f9b6ced | 1102 | |
a75fecec SR |
1103 | if (defined($replay)) { |
1104 | run_command "git bisect replay $replay" or | |
1105 | dodie "failed to run replay"; | |
5a391fbf SR |
1106 | } |
1107 | ||
a75fecec SR |
1108 | if (defined($start)) { |
1109 | run_command "git checkout $start" or | |
1110 | dodie "failed to checkout $start"; | |
1111 | } | |
1112 | ||
1113 | my $test; | |
5f9b6ced SR |
1114 | do { |
1115 | $result = run_bisect $type; | |
a75fecec SR |
1116 | $test = run_git_bisect "git bisect $result"; |
1117 | } while ($test); | |
5f9b6ced SR |
1118 | |
1119 | run_command "git bisect log" or | |
1120 | dodie "could not capture git bisect log"; | |
1121 | ||
1122 | run_command "git bisect reset" or | |
1123 | dodie "could not reset git bisect"; | |
1124 | ||
1125 | doprint "Bad commit was [$bisect_bad]\n"; | |
1126 | ||
0a05c769 SR |
1127 | success $i; |
1128 | } | |
1129 | ||
1130 | my %config_ignore; | |
1131 | my %config_set; | |
1132 | ||
1133 | my %config_list; | |
1134 | my %null_config; | |
1135 | ||
1136 | my %dependency; | |
1137 | ||
1138 | sub process_config_ignore { | |
1139 | my ($config) = @_; | |
1140 | ||
1141 | open (IN, $config) | |
1142 | or dodie "Failed to read $config"; | |
1143 | ||
1144 | while (<IN>) { | |
1145 | if (/^(.*?(CONFIG\S*)(=.*| is not set))/) { | |
1146 | $config_ignore{$2} = $1; | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | close(IN); | |
1151 | } | |
1152 | ||
1153 | sub read_current_config { | |
1154 | my ($config_ref) = @_; | |
1155 | ||
1156 | %{$config_ref} = (); | |
1157 | undef %{$config_ref}; | |
1158 | ||
1159 | my @key = keys %{$config_ref}; | |
1160 | if ($#key >= 0) { | |
1161 | print "did not delete!\n"; | |
1162 | exit; | |
1163 | } | |
1164 | open (IN, "$output_config"); | |
1165 | ||
1166 | while (<IN>) { | |
1167 | if (/^(CONFIG\S+)=(.*)/) { | |
1168 | ${$config_ref}{$1} = $2; | |
1169 | } | |
1170 | } | |
1171 | close(IN); | |
1172 | } | |
1173 | ||
1174 | sub get_dependencies { | |
1175 | my ($config) = @_; | |
1176 | ||
1177 | my $arr = $dependency{$config}; | |
1178 | if (!defined($arr)) { | |
1179 | return (); | |
1180 | } | |
1181 | ||
1182 | my @deps = @{$arr}; | |
1183 | ||
1184 | foreach my $dep (@{$arr}) { | |
1185 | print "ADD DEP $dep\n"; | |
1186 | @deps = (@deps, get_dependencies $dep); | |
1187 | } | |
1188 | ||
1189 | return @deps; | |
1190 | } | |
1191 | ||
1192 | sub create_config { | |
1193 | my @configs = @_; | |
1194 | ||
1195 | open(OUT, ">$output_config") or dodie "Can not write to $output_config"; | |
1196 | ||
1197 | foreach my $config (@configs) { | |
1198 | print OUT "$config_set{$config}\n"; | |
1199 | my @deps = get_dependencies $config; | |
1200 | foreach my $dep (@deps) { | |
1201 | print OUT "$config_set{$dep}\n"; | |
1202 | } | |
1203 | } | |
1204 | ||
1205 | foreach my $config (keys %config_ignore) { | |
1206 | print OUT "$config_ignore{$config}\n"; | |
1207 | } | |
1208 | close(OUT); | |
1209 | ||
1210 | # exit; | |
1211 | run_command "$make oldnoconfig" or | |
1212 | dodie "failed make config oldconfig"; | |
1213 | ||
1214 | } | |
1215 | ||
1216 | sub compare_configs { | |
1217 | my (%a, %b) = @_; | |
1218 | ||
1219 | foreach my $item (keys %a) { | |
1220 | if (!defined($b{$item})) { | |
1221 | print "diff $item\n"; | |
1222 | return 1; | |
1223 | } | |
1224 | delete $b{$item}; | |
1225 | } | |
1226 | ||
1227 | my @keys = keys %b; | |
1228 | if ($#keys) { | |
1229 | print "diff2 $keys[0]\n"; | |
1230 | } | |
1231 | return -1 if ($#keys >= 0); | |
1232 | ||
1233 | return 0; | |
1234 | } | |
1235 | ||
1236 | sub run_config_bisect_test { | |
1237 | my ($type) = @_; | |
1238 | ||
1239 | return run_bisect_test $type, "oldconfig"; | |
1240 | } | |
1241 | ||
1242 | sub process_passed { | |
1243 | my (%configs) = @_; | |
1244 | ||
1245 | doprint "These configs had no failure: (Enabling them for further compiles)\n"; | |
1246 | # Passed! All these configs are part of a good compile. | |
1247 | # Add them to the min options. | |
1248 | foreach my $config (keys %configs) { | |
1249 | if (defined($config_list{$config})) { | |
1250 | doprint " removing $config\n"; | |
1251 | $config_ignore{$config} = $config_list{$config}; | |
1252 | delete $config_list{$config}; | |
1253 | } | |
1254 | } | |
1255 | } | |
1256 | ||
1257 | sub process_failed { | |
1258 | my ($config) = @_; | |
1259 | ||
1260 | doprint "\n\n***************************************\n"; | |
1261 | doprint "Found bad config: $config\n"; | |
1262 | doprint "***************************************\n\n"; | |
1263 | } | |
1264 | ||
1265 | sub run_config_bisect { | |
1266 | ||
1267 | my @start_list = keys %config_list; | |
1268 | ||
1269 | if ($#start_list < 0) { | |
1270 | doprint "No more configs to test!!!\n"; | |
1271 | return -1; | |
1272 | } | |
1273 | ||
1274 | doprint "***** RUN TEST ***\n"; | |
1275 | my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"}; | |
1276 | my $ret; | |
1277 | my %current_config; | |
1278 | ||
1279 | my $count = $#start_list + 1; | |
1280 | doprint " $count configs to test\n"; | |
1281 | ||
1282 | my $half = int($#start_list / 2); | |
1283 | ||
1284 | do { | |
1285 | my @tophalf = @start_list[0 .. $half]; | |
1286 | ||
1287 | create_config @tophalf; | |
1288 | read_current_config \%current_config; | |
1289 | ||
1290 | $count = $#tophalf + 1; | |
1291 | doprint "Testing $count configs\n"; | |
1292 | my $found = 0; | |
1293 | # make sure we test something | |
1294 | foreach my $config (@tophalf) { | |
1295 | if (defined($current_config{$config})) { | |
1296 | logit " $config\n"; | |
1297 | $found = 1; | |
1298 | } | |
1299 | } | |
1300 | if (!$found) { | |
1301 | # try the other half | |
1302 | doprint "Top half produced no set configs, trying bottom half\n"; | |
1303 | @tophalf = @start_list[$half .. $#start_list]; | |
1304 | create_config @tophalf; | |
1305 | read_current_config \%current_config; | |
1306 | foreach my $config (@tophalf) { | |
1307 | if (defined($current_config{$config})) { | |
1308 | logit " $config\n"; | |
1309 | $found = 1; | |
1310 | } | |
1311 | } | |
1312 | if (!$found) { | |
1313 | doprint "Failed: Can't make new config with current configs\n"; | |
1314 | foreach my $config (@start_list) { | |
1315 | doprint " CONFIG: $config\n"; | |
1316 | } | |
1317 | return -1; | |
1318 | } | |
1319 | $count = $#tophalf + 1; | |
1320 | doprint "Testing $count configs\n"; | |
1321 | } | |
1322 | ||
1323 | $ret = run_config_bisect_test $type; | |
1324 | ||
1325 | if ($ret) { | |
1326 | process_passed %current_config; | |
1327 | return 0; | |
1328 | } | |
1329 | ||
1330 | doprint "This config had a failure.\n"; | |
1331 | doprint "Removing these configs that were not set in this config:\n"; | |
1332 | ||
1333 | # A config exists in this group that was bad. | |
1334 | foreach my $config (keys %config_list) { | |
1335 | if (!defined($current_config{$config})) { | |
1336 | doprint " removing $config\n"; | |
1337 | delete $config_list{$config}; | |
1338 | } | |
1339 | } | |
1340 | ||
1341 | @start_list = @tophalf; | |
1342 | ||
1343 | if ($#start_list == 0) { | |
1344 | process_failed $start_list[0]; | |
1345 | return 1; | |
1346 | } | |
1347 | ||
1348 | # remove half the configs we are looking at and see if | |
1349 | # they are good. | |
1350 | $half = int($#start_list / 2); | |
1351 | } while ($half > 0); | |
1352 | ||
1353 | # we found a single config, try it again | |
1354 | my @tophalf = @start_list[0 .. 0]; | |
1355 | ||
1356 | $ret = run_config_bisect_test $type; | |
1357 | if ($ret) { | |
1358 | process_passed %current_config; | |
1359 | return 0; | |
1360 | } | |
1361 | ||
1362 | process_failed $start_list[0]; | |
1363 | return 1; | |
1364 | } | |
1365 | ||
1366 | sub config_bisect { | |
1367 | my ($i) = @_; | |
1368 | ||
1369 | my $start_config = $opt{"CONFIG_BISECT[$i]"}; | |
1370 | ||
1371 | my $tmpconfig = "$tmpdir/use_config"; | |
1372 | ||
1373 | # Make the file with the bad config and the min config | |
1374 | if (defined($minconfig)) { | |
1375 | # read the min config for things to ignore | |
1376 | run_command "cp $minconfig $tmpconfig" or | |
1377 | dodie "failed to copy $minconfig to $tmpconfig"; | |
1378 | } else { | |
1379 | unlink $tmpconfig; | |
1380 | } | |
1381 | ||
1382 | # Add other configs | |
1383 | if (defined($addconfig)) { | |
1384 | run_command "cat $addconfig >> $tmpconfig" or | |
1385 | dodie "failed to append $addconfig"; | |
1386 | } | |
1387 | ||
1388 | my $defconfig = ""; | |
1389 | if (-f $tmpconfig) { | |
1390 | $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig"; | |
1391 | process_config_ignore $tmpconfig; | |
1392 | } | |
1393 | ||
1394 | # now process the start config | |
1395 | run_command "cp $start_config $output_config" or | |
1396 | dodie "failed to copy $start_config to $output_config"; | |
1397 | ||
1398 | # read directly what we want to check | |
1399 | my %config_check; | |
1400 | open (IN, $output_config) | |
1401 | or dodie "faied to open $output_config"; | |
1402 | ||
1403 | while (<IN>) { | |
1404 | if (/^((CONFIG\S*)=.*)/) { | |
1405 | $config_check{$2} = $1; | |
1406 | } | |
1407 | } | |
1408 | close(IN); | |
1409 | ||
1410 | # Now run oldconfig with the minconfig (and addconfigs) | |
1411 | run_command "$defconfig $make oldnoconfig" or | |
1412 | dodie "failed make config oldconfig"; | |
1413 | ||
1414 | # check to see what we lost (or gained) | |
1415 | open (IN, $output_config) | |
1416 | or dodie "Failed to read $start_config"; | |
1417 | ||
1418 | my %removed_configs; | |
1419 | my %added_configs; | |
1420 | ||
1421 | while (<IN>) { | |
1422 | if (/^((CONFIG\S*)=.*)/) { | |
1423 | # save off all options | |
1424 | $config_set{$2} = $1; | |
1425 | if (defined($config_check{$2})) { | |
1426 | if (defined($config_ignore{$2})) { | |
1427 | $removed_configs{$2} = $1; | |
1428 | } else { | |
1429 | $config_list{$2} = $1; | |
1430 | } | |
1431 | } elsif (!defined($config_ignore{$2})) { | |
1432 | $added_configs{$2} = $1; | |
1433 | $config_list{$2} = $1; | |
1434 | } | |
1435 | } | |
1436 | } | |
1437 | close(IN); | |
1438 | ||
1439 | my @confs = keys %removed_configs; | |
1440 | if ($#confs >= 0) { | |
1441 | doprint "Configs overridden by default configs and removed from check:\n"; | |
1442 | foreach my $config (@confs) { | |
1443 | doprint " $config\n"; | |
1444 | } | |
1445 | } | |
1446 | @confs = keys %added_configs; | |
1447 | if ($#confs >= 0) { | |
1448 | doprint "Configs appearing in make oldconfig and added:\n"; | |
1449 | foreach my $config (@confs) { | |
1450 | doprint " $config\n"; | |
1451 | } | |
1452 | } | |
1453 | ||
1454 | my %config_test; | |
1455 | my $once = 0; | |
1456 | ||
1457 | # Sometimes kconfig does weird things. We must make sure | |
1458 | # that the config we autocreate has everything we need | |
1459 | # to test, otherwise we may miss testing configs, or | |
1460 | # may not be able to create a new config. | |
1461 | # Here we create a config with everything set. | |
1462 | create_config (keys %config_list); | |
1463 | read_current_config \%config_test; | |
1464 | foreach my $config (keys %config_list) { | |
1465 | if (!defined($config_test{$config})) { | |
1466 | if (!$once) { | |
1467 | $once = 1; | |
1468 | doprint "Configs not produced by kconfig (will not be checked):\n"; | |
1469 | } | |
1470 | doprint " $config\n"; | |
1471 | delete $config_list{$config}; | |
1472 | } | |
1473 | } | |
1474 | my $ret; | |
1475 | do { | |
1476 | $ret = run_config_bisect; | |
1477 | } while (!$ret); | |
1478 | ||
1479 | return $ret if ($ret < 0); | |
5f9b6ced SR |
1480 | |
1481 | success $i; | |
1482 | } | |
1483 | ||
6c5ee0be SR |
1484 | sub patchcheck { |
1485 | my ($i) = @_; | |
1486 | ||
1487 | die "PATCHCHECK_START[$i] not defined\n" | |
1488 | if (!defined($opt{"PATCHCHECK_START[$i]"})); | |
1489 | die "PATCHCHECK_TYPE[$i] not defined\n" | |
1490 | if (!defined($opt{"PATCHCHECK_TYPE[$i]"})); | |
1491 | ||
1492 | my $start = $opt{"PATCHCHECK_START[$i]"}; | |
1493 | ||
1494 | my $end = "HEAD"; | |
1495 | if (defined($opt{"PATCHCHECK_END[$i]"})) { | |
1496 | $end = $opt{"PATCHCHECK_END[$i]"}; | |
1497 | } | |
1498 | ||
a57419b3 SR |
1499 | # Get the true sha1's since we can use things like HEAD~3 |
1500 | $start = get_sha1($start); | |
1501 | $end = get_sha1($end); | |
1502 | ||
6c5ee0be SR |
1503 | my $type = $opt{"PATCHCHECK_TYPE[$i]"}; |
1504 | ||
1505 | # Can't have a test without having a test to run | |
1506 | if ($type eq "test" && !defined($run_test)) { | |
1507 | $type = "boot"; | |
1508 | } | |
1509 | ||
1510 | open (IN, "git log --pretty=oneline $end|") or | |
1511 | dodie "could not get git list"; | |
1512 | ||
1513 | my @list; | |
1514 | ||
1515 | while (<IN>) { | |
1516 | chomp; | |
1517 | $list[$#list+1] = $_; | |
1518 | last if (/^$start/); | |
1519 | } | |
1520 | close(IN); | |
1521 | ||
1522 | if ($list[$#list] !~ /^$start/) { | |
2b7d9b21 | 1523 | fail "SHA1 $start not found"; |
6c5ee0be SR |
1524 | } |
1525 | ||
1526 | # go backwards in the list | |
1527 | @list = reverse @list; | |
1528 | ||
1529 | my $save_clean = $noclean; | |
1530 | ||
1531 | $in_patchcheck = 1; | |
1532 | foreach my $item (@list) { | |
1533 | my $sha1 = $item; | |
1534 | $sha1 =~ s/^([[:xdigit:]]+).*/$1/; | |
1535 | ||
1536 | doprint "\nProcessing commit $item\n\n"; | |
1537 | ||
1538 | run_command "git checkout $sha1" or | |
1539 | die "Failed to checkout $sha1"; | |
1540 | ||
1541 | # only clean on the first and last patch | |
1542 | if ($item eq $list[0] || | |
1543 | $item eq $list[$#list]) { | |
1544 | $noclean = $save_clean; | |
1545 | } else { | |
1546 | $noclean = 1; | |
1547 | } | |
1548 | ||
1549 | if (defined($minconfig)) { | |
2b7d9b21 | 1550 | build "useconfig:$minconfig" or return 0; |
6c5ee0be SR |
1551 | } else { |
1552 | # ?? no config to use? | |
2b7d9b21 | 1553 | build "oldconfig" or return 0; |
6c5ee0be SR |
1554 | } |
1555 | ||
2b7d9b21 | 1556 | check_buildlog $sha1 or return 0; |
6c5ee0be SR |
1557 | |
1558 | next if ($type eq "build"); | |
1559 | ||
1560 | get_grub_index; | |
1561 | get_version; | |
1562 | install; | |
6c5ee0be | 1563 | |
7faafbd6 SR |
1564 | my $failed = 0; |
1565 | ||
1566 | start_monitor; | |
1567 | monitor or $failed = 1; | |
1568 | ||
1569 | if (!$failed && $type ne "boot"){ | |
1570 | do_run_test or $failed = 1; | |
1571 | } | |
1572 | end_monitor; | |
1573 | return 0 if ($failed); | |
1574 | ||
6c5ee0be SR |
1575 | } |
1576 | $in_patchcheck = 0; | |
1577 | success $i; | |
2b7d9b21 SR |
1578 | |
1579 | return 1; | |
6c5ee0be SR |
1580 | } |
1581 | ||
2545eb61 SR |
1582 | read_config $ARGV[0]; |
1583 | ||
1584 | # mandatory configs | |
1585 | die "MACHINE not defined\n" if (!defined($opt{"MACHINE"})); | |
1586 | die "SSH_USER not defined\n" if (!defined($opt{"SSH_USER"})); | |
1587 | die "BUILD_DIR not defined\n" if (!defined($opt{"BUILD_DIR"})); | |
1588 | die "OUTPUT_DIR not defined\n" if (!defined($opt{"OUTPUT_DIR"})); | |
1589 | die "BUILD_TARGET not defined\n" if (!defined($opt{"BUILD_TARGET"})); | |
75c3fda7 | 1590 | die "TARGET_IMAGE not defined\n" if (!defined($opt{"TARGET_IMAGE"})); |
2545eb61 SR |
1591 | die "POWER_CYCLE not defined\n" if (!defined($opt{"POWER_CYCLE"})); |
1592 | die "CONSOLE not defined\n" if (!defined($opt{"CONSOLE"})); | |
1593 | die "LOCALVERSION not defined\n" if (!defined($opt{"LOCALVERSION"})); | |
2545eb61 | 1594 | |
2b7d9b21 SR |
1595 | if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { |
1596 | unlink $opt{"LOG_FILE"}; | |
1597 | } | |
2545eb61 | 1598 | |
2b7d9b21 SR |
1599 | doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; |
1600 | ||
a57419b3 SR |
1601 | for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { |
1602 | ||
1603 | if (!$i) { | |
1604 | doprint "DEFAULT OPTIONS:\n"; | |
1605 | } else { | |
1606 | doprint "\nTEST $i OPTIONS"; | |
1607 | if (defined($repeat_tests{$i})) { | |
1608 | $repeat = $repeat_tests{$i}; | |
1609 | doprint " ITERATE $repeat"; | |
1610 | } | |
1611 | doprint "\n"; | |
1612 | } | |
1613 | ||
1614 | foreach my $option (sort keys %opt) { | |
1615 | ||
1616 | if ($option =~ /\[(\d+)\]$/) { | |
1617 | next if ($i != $1); | |
1618 | } else { | |
1619 | next if ($i); | |
1620 | } | |
1621 | ||
1622 | doprint "$option = $opt{$option}\n"; | |
1623 | } | |
2b7d9b21 | 1624 | } |
2545eb61 | 1625 | |
a75fecec | 1626 | sub set_test_option { |
5a391fbf | 1627 | my ($name, $i) = @_; |
2545eb61 | 1628 | |
5a391fbf | 1629 | my $option = "$name\[$i\]"; |
5c42fc5b | 1630 | |
5a391fbf SR |
1631 | if (defined($opt{$option})) { |
1632 | return $opt{$option}; | |
5f9b6ced SR |
1633 | } |
1634 | ||
a57419b3 SR |
1635 | foreach my $test (keys %repeat_tests) { |
1636 | if ($i >= $test && | |
1637 | $i < $test + $repeat_tests{$test}) { | |
1638 | $option = "$name\[$test\]"; | |
1639 | if (defined($opt{$option})) { | |
1640 | return $opt{$option}; | |
1641 | } | |
1642 | } | |
1643 | } | |
1644 | ||
5a391fbf SR |
1645 | if (defined($opt{$name})) { |
1646 | return $opt{$name}; | |
2545eb61 SR |
1647 | } |
1648 | ||
5a391fbf SR |
1649 | return undef; |
1650 | } | |
1651 | ||
1652 | # First we need to do is the builds | |
a75fecec SR |
1653 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { |
1654 | ||
576f627c SR |
1655 | $iteration = $i; |
1656 | ||
a75fecec SR |
1657 | my $makecmd = set_test_option("MAKE_CMD", $i); |
1658 | ||
1659 | $machine = set_test_option("MACHINE", $i); | |
e48c5293 | 1660 | $ssh_user = set_test_option("SSH_USER", $i); |
a75fecec SR |
1661 | $tmpdir = set_test_option("TMP_DIR", $i); |
1662 | $outputdir = set_test_option("OUTPUT_DIR", $i); | |
1663 | $builddir = set_test_option("BUILD_DIR", $i); | |
1664 | $test_type = set_test_option("TEST_TYPE", $i); | |
1665 | $build_type = set_test_option("BUILD_TYPE", $i); | |
1666 | $build_options = set_test_option("BUILD_OPTIONS", $i); | |
1667 | $power_cycle = set_test_option("POWER_CYCLE", $i); | |
e48c5293 | 1668 | $reboot = set_test_option("REBOOT", $i); |
a75fecec SR |
1669 | $noclean = set_test_option("BUILD_NOCLEAN", $i); |
1670 | $minconfig = set_test_option("MIN_CONFIG", $i); | |
1671 | $run_test = set_test_option("TEST", $i); | |
1672 | $addconfig = set_test_option("ADD_CONFIG", $i); | |
1673 | $reboot_type = set_test_option("REBOOT_TYPE", $i); | |
1674 | $grub_menu = set_test_option("GRUB_MENU", $i); | |
8b37ca8c | 1675 | $post_install = set_test_option("POST_INSTALL", $i); |
a75fecec SR |
1676 | $reboot_script = set_test_option("REBOOT_SCRIPT", $i); |
1677 | $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i); | |
1678 | $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i); | |
1679 | $die_on_failure = set_test_option("DIE_ON_FAILURE", $i); | |
1680 | $power_off = set_test_option("POWER_OFF", $i); | |
576f627c SR |
1681 | $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i); |
1682 | $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i); | |
a75fecec SR |
1683 | $sleep_time = set_test_option("SLEEP_TIME", $i); |
1684 | $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); | |
1685 | $store_failures = set_test_option("STORE_FAILURES", $i); | |
1686 | $timeout = set_test_option("TIMEOUT", $i); | |
1687 | $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i); | |
1688 | $console = set_test_option("CONSOLE", $i); | |
1689 | $success_line = set_test_option("SUCCESS_LINE", $i); | |
1690 | $build_target = set_test_option("BUILD_TARGET", $i); | |
e48c5293 SR |
1691 | $ssh_exec = set_test_option("SSH_EXEC", $i); |
1692 | $scp_to_target = set_test_option("SCP_TO_TARGET", $i); | |
a75fecec SR |
1693 | $target_image = set_test_option("TARGET_IMAGE", $i); |
1694 | $localversion = set_test_option("LOCALVERSION", $i); | |
1695 | ||
1696 | chdir $builddir || die "can't change directory to $builddir"; | |
1697 | ||
1698 | if (!-d $tmpdir) { | |
1699 | mkpath($tmpdir) or | |
1700 | die "can't create $tmpdir"; | |
1701 | } | |
1a5cfce3 | 1702 | |
e48c5293 SR |
1703 | $ENV{"SSH_USER"} = $ssh_user; |
1704 | $ENV{"MACHINE"} = $machine; | |
1705 | ||
a75fecec SR |
1706 | $target = "$ssh_user\@$machine"; |
1707 | ||
1708 | $buildlog = "$tmpdir/buildlog-$machine"; | |
1709 | $dmesg = "$tmpdir/dmesg-$machine"; | |
1710 | $make = "$makecmd O=$outputdir"; | |
51ad1dd1 | 1711 | $output_config = "$outputdir/.config"; |
a75fecec SR |
1712 | |
1713 | if ($reboot_type eq "grub") { | |
576f627c | 1714 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); |
a75fecec | 1715 | } elsif (!defined($reboot_script)) { |
576f627c | 1716 | dodie "REBOOT_SCRIPT not defined" |
a75fecec SR |
1717 | } |
1718 | ||
1719 | my $run_type = $build_type; | |
1720 | if ($test_type eq "patchcheck") { | |
1721 | $run_type = $opt{"PATCHCHECK_TYPE[$i]"}; | |
1722 | } elsif ($test_type eq "bisect") { | |
1723 | $run_type = $opt{"BISECT_TYPE[$i]"}; | |
0a05c769 SR |
1724 | } elsif ($test_type eq "config_bisect") { |
1725 | $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"}; | |
a75fecec SR |
1726 | } |
1727 | ||
1728 | # mistake in config file? | |
1729 | if (!defined($run_type)) { | |
1730 | $run_type = "ERROR"; | |
1731 | } | |
5a391fbf | 1732 | |
2545eb61 | 1733 | doprint "\n\n"; |
a75fecec | 1734 | doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n"; |
7faafbd6 SR |
1735 | |
1736 | unlink $dmesg; | |
1737 | unlink $buildlog; | |
2545eb61 | 1738 | |
2b7d9b21 SR |
1739 | if (!defined($minconfig)) { |
1740 | $minconfig = $addconfig; | |
1741 | ||
1742 | } elsif (defined($addconfig)) { | |
9be2e6b5 | 1743 | run_command "cat $addconfig $minconfig > $tmpdir/add_config" or |
2b7d9b21 | 1744 | dodie "Failed to create temp config"; |
9be2e6b5 | 1745 | $minconfig = "$tmpdir/add_config"; |
2b7d9b21 SR |
1746 | } |
1747 | ||
6c5ee0be SR |
1748 | my $checkout = $opt{"CHECKOUT[$i]"}; |
1749 | if (defined($checkout)) { | |
1750 | run_command "git checkout $checkout" or | |
1751 | die "failed to checkout $checkout"; | |
1752 | } | |
1753 | ||
a75fecec | 1754 | if ($test_type eq "bisect") { |
5f9b6ced SR |
1755 | bisect $i; |
1756 | next; | |
0a05c769 SR |
1757 | } elsif ($test_type eq "config_bisect") { |
1758 | config_bisect $i; | |
1759 | next; | |
a75fecec | 1760 | } elsif ($test_type eq "patchcheck") { |
6c5ee0be SR |
1761 | patchcheck $i; |
1762 | next; | |
2545eb61 | 1763 | } |
2545eb61 | 1764 | |
7faafbd6 SR |
1765 | if ($build_type ne "nobuild") { |
1766 | build $build_type or next; | |
2545eb61 SR |
1767 | } |
1768 | ||
a75fecec SR |
1769 | if ($test_type ne "build") { |
1770 | get_grub_index; | |
1771 | get_version; | |
1772 | install; | |
5a391fbf | 1773 | |
a75fecec SR |
1774 | my $failed = 0; |
1775 | start_monitor; | |
1776 | monitor or $failed = 1;; | |
1777 | ||
1778 | if (!$failed && $test_type ne "boot" && defined($run_test)) { | |
1779 | do_run_test or $failed = 1; | |
1780 | } | |
1781 | end_monitor; | |
1782 | next if ($failed); | |
5a391fbf SR |
1783 | } |
1784 | ||
5f9b6ced | 1785 | success $i; |
2545eb61 SR |
1786 | } |
1787 | ||
5c42fc5b | 1788 | if ($opt{"POWEROFF_ON_SUCCESS"}) { |
75c3fda7 | 1789 | halt; |
576f627c | 1790 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) { |
75c3fda7 | 1791 | reboot; |
5c42fc5b | 1792 | } |
75c3fda7 | 1793 | |
e48c5293 SR |
1794 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; |
1795 | ||
2545eb61 | 1796 | exit 0; |