Commit | Line | Data |
---|---|---|
2545eb61 | 1 | #!/usr/bin/perl -w |
d6ce2a0b | 2 | # |
cce1dac8 | 3 | # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc. |
d6ce2a0b SR |
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 | ||
2545eb61 SR |
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; |
bb8474b1 | 25 | $default{"TEST_TYPE"} = "build"; |
a75fecec SR |
26 | $default{"BUILD_TYPE"} = "randconfig"; |
27 | $default{"MAKE_CMD"} = "make"; | |
28 | $default{"TIMEOUT"} = 120; | |
48920630 | 29 | $default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}"; |
a75fecec SR |
30 | $default{"SLEEP_TIME"} = 60; # sleep time between tests |
31 | $default{"BUILD_NOCLEAN"} = 0; | |
32 | $default{"REBOOT_ON_ERROR"} = 0; | |
33 | $default{"POWEROFF_ON_ERROR"} = 0; | |
34 | $default{"REBOOT_ON_SUCCESS"} = 1; | |
35 | $default{"POWEROFF_ON_SUCCESS"} = 0; | |
36 | $default{"BUILD_OPTIONS"} = ""; | |
37 | $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects | |
27d934b2 | 38 | $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks |
a75fecec | 39 | $default{"CLEAR_LOG"} = 0; |
c960bb9f | 40 | $default{"BISECT_MANUAL"} = 0; |
c23dca7c | 41 | $default{"BISECT_SKIP"} = 1; |
a75fecec | 42 | $default{"SUCCESS_LINE"} = "login:"; |
f1a5b962 | 43 | $default{"DETECT_TRIPLE_FAULT"} = 1; |
e0a8742e | 44 | $default{"NO_INSTALL"} = 0; |
a75fecec SR |
45 | $default{"BOOTED_TIMEOUT"} = 1; |
46 | $default{"DIE_ON_FAILURE"} = 1; | |
e48c5293 SR |
47 | $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND"; |
48 | $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE"; | |
49 | $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot"; | |
1c8a617a SR |
50 | $default{"STOP_AFTER_SUCCESS"} = 10; |
51 | $default{"STOP_AFTER_FAILURE"} = 60; | |
2d01b26a | 52 | $default{"STOP_TEST_AFTER"} = 600; |
600bbf0a SR |
53 | |
54 | # required, and we will ask users if they don't have them but we keep the default | |
55 | # value something that is common. | |
56 | $default{"REBOOT_TYPE"} = "grub"; | |
8d1491ba | 57 | $default{"LOCALVERSION"} = "-test"; |
600bbf0a SR |
58 | $default{"SSH_USER"} = "root"; |
59 | $default{"BUILD_TARGET"} = "arch/x86/boot/bzImage"; | |
60 | $default{"TARGET_IMAGE"} = "/boot/vmlinuz-test"; | |
2545eb61 | 61 | |
8d1491ba | 62 | my $ktest_config; |
2545eb61 | 63 | my $version; |
a75fecec | 64 | my $machine; |
e48c5293 | 65 | my $ssh_user; |
a75fecec SR |
66 | my $tmpdir; |
67 | my $builddir; | |
68 | my $outputdir; | |
51ad1dd1 | 69 | my $output_config; |
a75fecec | 70 | my $test_type; |
7faafbd6 | 71 | my $build_type; |
a75fecec | 72 | my $build_options; |
0bd6c1a3 SR |
73 | my $pre_build; |
74 | my $post_build; | |
75 | my $pre_build_die; | |
76 | my $post_build_die; | |
a75fecec SR |
77 | my $reboot_type; |
78 | my $reboot_script; | |
79 | my $power_cycle; | |
e48c5293 | 80 | my $reboot; |
a75fecec SR |
81 | my $reboot_on_error; |
82 | my $poweroff_on_error; | |
83 | my $die_on_failure; | |
576f627c SR |
84 | my $powercycle_after_reboot; |
85 | my $poweroff_after_halt; | |
e48c5293 SR |
86 | my $ssh_exec; |
87 | my $scp_to_target; | |
a75fecec SR |
88 | my $power_off; |
89 | my $grub_menu; | |
2545eb61 SR |
90 | my $grub_number; |
91 | my $target; | |
92 | my $make; | |
8b37ca8c | 93 | my $post_install; |
e0a8742e | 94 | my $no_install; |
5c42fc5b | 95 | my $noclean; |
5f9b6ced | 96 | my $minconfig; |
4c4ab120 | 97 | my $start_minconfig; |
35ce5952 | 98 | my $start_minconfig_defined; |
4c4ab120 SR |
99 | my $output_minconfig; |
100 | my $ignore_config; | |
2b7d9b21 | 101 | my $addconfig; |
5f9b6ced SR |
102 | my $in_bisect = 0; |
103 | my $bisect_bad = ""; | |
d6ce2a0b | 104 | my $reverse_bisect; |
c960bb9f | 105 | my $bisect_manual; |
c23dca7c | 106 | my $bisect_skip; |
30f75da5 | 107 | my $config_bisect_good; |
6c5ee0be | 108 | my $in_patchcheck = 0; |
5a391fbf | 109 | my $run_test; |
6c5ee0be | 110 | my $redirect; |
7faafbd6 | 111 | my $buildlog; |
a9dd5d63 | 112 | my $testlog; |
7faafbd6 SR |
113 | my $dmesg; |
114 | my $monitor_fp; | |
115 | my $monitor_pid; | |
116 | my $monitor_cnt = 0; | |
a75fecec SR |
117 | my $sleep_time; |
118 | my $bisect_sleep_time; | |
27d934b2 | 119 | my $patchcheck_sleep_time; |
1990207d | 120 | my $ignore_warnings; |
a75fecec | 121 | my $store_failures; |
de5b6e3b | 122 | my $store_successes; |
9064af52 | 123 | my $test_name; |
a75fecec SR |
124 | my $timeout; |
125 | my $booted_timeout; | |
f1a5b962 | 126 | my $detect_triplefault; |
a75fecec | 127 | my $console; |
2b803365 | 128 | my $reboot_success_line; |
a75fecec | 129 | my $success_line; |
1c8a617a SR |
130 | my $stop_after_success; |
131 | my $stop_after_failure; | |
2d01b26a | 132 | my $stop_test_after; |
a75fecec SR |
133 | my $build_target; |
134 | my $target_image; | |
135 | my $localversion; | |
576f627c | 136 | my $iteration = 0; |
e48c5293 | 137 | my $successes = 0; |
2545eb61 | 138 | |
bb8474b1 SR |
139 | # set when a test is something other that just building |
140 | # which would require more options. | |
141 | my $buildonly = 1; | |
142 | ||
8d1491ba SR |
143 | my %entered_configs; |
144 | my %config_help; | |
77d942ce | 145 | my %variable; |
fcb3f16a | 146 | my %force_config; |
8d1491ba | 147 | |
4ab1cce5 SR |
148 | # do not force reboots on config problems |
149 | my $no_reboot = 1; | |
150 | ||
7bf51073 SR |
151 | # default variables that can be used |
152 | chomp ($variable{"PWD"} = `pwd`); | |
153 | ||
8d1491ba SR |
154 | $config_help{"MACHINE"} = << "EOF" |
155 | The machine hostname that you will test. | |
bb8474b1 | 156 | For build only tests, it is still needed to differentiate log files. |
8d1491ba SR |
157 | EOF |
158 | ; | |
159 | $config_help{"SSH_USER"} = << "EOF" | |
160 | The box is expected to have ssh on normal bootup, provide the user | |
161 | (most likely root, since you need privileged operations) | |
162 | EOF | |
163 | ; | |
164 | $config_help{"BUILD_DIR"} = << "EOF" | |
165 | The directory that contains the Linux source code (full path). | |
0e7a22de SR |
166 | You can use \${PWD} that will be the path where ktest.pl is run, or use |
167 | \${THIS_DIR} which is assigned \${PWD} but may be changed later. | |
8d1491ba SR |
168 | EOF |
169 | ; | |
170 | $config_help{"OUTPUT_DIR"} = << "EOF" | |
171 | The directory that the objects will be built (full path). | |
172 | (can not be same as BUILD_DIR) | |
0e7a22de SR |
173 | You can use \${PWD} that will be the path where ktest.pl is run, or use |
174 | \${THIS_DIR} which is assigned \${PWD} but may be changed later. | |
8d1491ba SR |
175 | EOF |
176 | ; | |
177 | $config_help{"BUILD_TARGET"} = << "EOF" | |
178 | The location of the compiled file to copy to the target. | |
179 | (relative to OUTPUT_DIR) | |
180 | EOF | |
181 | ; | |
182 | $config_help{"TARGET_IMAGE"} = << "EOF" | |
183 | The place to put your image on the test machine. | |
184 | EOF | |
185 | ; | |
186 | $config_help{"POWER_CYCLE"} = << "EOF" | |
187 | A script or command to reboot the box. | |
188 | ||
189 | Here is a digital loggers power switch example | |
190 | POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL' | |
191 | ||
192 | Here is an example to reboot a virtual box on the current host | |
193 | with the name "Guest". | |
194 | POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest | |
195 | EOF | |
196 | ; | |
197 | $config_help{"CONSOLE"} = << "EOF" | |
198 | The script or command that reads the console | |
199 | ||
200 | If you use ttywatch server, something like the following would work. | |
201 | CONSOLE = nc -d localhost 3001 | |
202 | ||
203 | For a virtual machine with guest name "Guest". | |
204 | CONSOLE = virsh console Guest | |
205 | EOF | |
206 | ; | |
207 | $config_help{"LOCALVERSION"} = << "EOF" | |
208 | Required version ending to differentiate the test | |
209 | from other linux builds on the system. | |
210 | EOF | |
211 | ; | |
212 | $config_help{"REBOOT_TYPE"} = << "EOF" | |
213 | Way to reboot the box to the test kernel. | |
214 | Only valid options so far are "grub" and "script". | |
215 | ||
216 | If you specify grub, it will assume grub version 1 | |
217 | and will search in /boot/grub/menu.lst for the title \$GRUB_MENU | |
218 | and select that target to reboot to the kernel. If this is not | |
219 | your setup, then specify "script" and have a command or script | |
220 | specified in REBOOT_SCRIPT to boot to the target. | |
221 | ||
222 | The entry in /boot/grub/menu.lst must be entered in manually. | |
223 | The test will not modify that file. | |
224 | EOF | |
225 | ; | |
226 | $config_help{"GRUB_MENU"} = << "EOF" | |
227 | The grub title name for the test kernel to boot | |
228 | (Only mandatory if REBOOT_TYPE = grub) | |
229 | ||
230 | Note, ktest.pl will not update the grub menu.lst, you need to | |
231 | manually add an option for the test. ktest.pl will search | |
232 | the grub menu.lst for this option to find what kernel to | |
233 | reboot into. | |
234 | ||
235 | For example, if in the /boot/grub/menu.lst the test kernel title has: | |
236 | title Test Kernel | |
237 | kernel vmlinuz-test | |
238 | GRUB_MENU = Test Kernel | |
239 | EOF | |
240 | ; | |
241 | $config_help{"REBOOT_SCRIPT"} = << "EOF" | |
242 | A script to reboot the target into the test kernel | |
243 | (Only mandatory if REBOOT_TYPE = script) | |
244 | EOF | |
245 | ; | |
246 | ||
dad98754 SR |
247 | sub read_prompt { |
248 | my ($cancel, $prompt) = @_; | |
35ce5952 SR |
249 | |
250 | my $ans; | |
251 | ||
252 | for (;;) { | |
dad98754 SR |
253 | if ($cancel) { |
254 | print "$prompt [y/n/C] "; | |
255 | } else { | |
256 | print "$prompt [Y/n] "; | |
257 | } | |
35ce5952 SR |
258 | $ans = <STDIN>; |
259 | chomp $ans; | |
260 | if ($ans =~ /^\s*$/) { | |
dad98754 SR |
261 | if ($cancel) { |
262 | $ans = "c"; | |
263 | } else { | |
264 | $ans = "y"; | |
265 | } | |
35ce5952 SR |
266 | } |
267 | last if ($ans =~ /^y$/i || $ans =~ /^n$/i); | |
dad98754 SR |
268 | if ($cancel) { |
269 | last if ($ans =~ /^c$/i); | |
270 | print "Please answer either 'y', 'n' or 'c'.\n"; | |
271 | } else { | |
272 | print "Please answer either 'y' or 'n'.\n"; | |
273 | } | |
274 | } | |
275 | if ($ans =~ /^c/i) { | |
276 | exit; | |
35ce5952 SR |
277 | } |
278 | if ($ans !~ /^y$/i) { | |
279 | return 0; | |
280 | } | |
281 | return 1; | |
282 | } | |
8d1491ba | 283 | |
dad98754 SR |
284 | sub read_yn { |
285 | my ($prompt) = @_; | |
286 | ||
287 | return read_prompt 0, $prompt; | |
288 | } | |
289 | ||
290 | sub read_ync { | |
291 | my ($prompt) = @_; | |
292 | ||
293 | return read_prompt 1, $prompt; | |
294 | } | |
295 | ||
8d1491ba SR |
296 | sub get_ktest_config { |
297 | my ($config) = @_; | |
815e2bd7 | 298 | my $ans; |
8d1491ba SR |
299 | |
300 | return if (defined($opt{$config})); | |
301 | ||
302 | if (defined($config_help{$config})) { | |
303 | print "\n"; | |
304 | print $config_help{$config}; | |
305 | } | |
306 | ||
307 | for (;;) { | |
308 | print "$config = "; | |
309 | if (defined($default{$config})) { | |
310 | print "\[$default{$config}\] "; | |
311 | } | |
815e2bd7 SR |
312 | $ans = <STDIN>; |
313 | $ans =~ s/^\s*(.*\S)\s*$/$1/; | |
314 | if ($ans =~ /^\s*$/) { | |
8d1491ba | 315 | if ($default{$config}) { |
815e2bd7 | 316 | $ans = $default{$config}; |
8d1491ba SR |
317 | } else { |
318 | print "Your answer can not be blank\n"; | |
319 | next; | |
320 | } | |
321 | } | |
0e7a22de | 322 | $entered_configs{$config} = ${ans}; |
8d1491ba SR |
323 | last; |
324 | } | |
325 | } | |
326 | ||
327 | sub get_ktest_configs { | |
328 | get_ktest_config("MACHINE"); | |
8d1491ba SR |
329 | get_ktest_config("BUILD_DIR"); |
330 | get_ktest_config("OUTPUT_DIR"); | |
bb8474b1 SR |
331 | |
332 | # options required for other than just building a kernel | |
333 | if (!$buildonly) { | |
334 | get_ktest_config("SSH_USER"); | |
335 | get_ktest_config("BUILD_TARGET"); | |
336 | get_ktest_config("TARGET_IMAGE"); | |
337 | get_ktest_config("POWER_CYCLE"); | |
338 | get_ktest_config("CONSOLE"); | |
339 | } | |
340 | ||
8d1491ba SR |
341 | get_ktest_config("LOCALVERSION"); |
342 | ||
bb8474b1 SR |
343 | return if ($buildonly); |
344 | ||
8d1491ba SR |
345 | my $rtype = $opt{"REBOOT_TYPE"}; |
346 | ||
347 | if (!defined($rtype)) { | |
348 | if (!defined($opt{"GRUB_MENU"})) { | |
349 | get_ktest_config("REBOOT_TYPE"); | |
350 | $rtype = $entered_configs{"REBOOT_TYPE"}; | |
351 | } else { | |
352 | $rtype = "grub"; | |
353 | } | |
354 | } | |
355 | ||
356 | if ($rtype eq "grub") { | |
357 | get_ktest_config("GRUB_MENU"); | |
358 | } else { | |
359 | get_ktest_config("REBOOT_SCRIPT"); | |
360 | } | |
361 | } | |
362 | ||
77d942ce | 363 | sub process_variables { |
8d735212 | 364 | my ($value, $remove_undef) = @_; |
77d942ce SR |
365 | my $retval = ""; |
366 | ||
367 | # We want to check for '\', and it is just easier | |
368 | # to check the previous characet of '$' and not need | |
369 | # to worry if '$' is the first character. By adding | |
370 | # a space to $value, we can just check [^\\]\$ and | |
371 | # it will still work. | |
372 | $value = " $value"; | |
373 | ||
374 | while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) { | |
375 | my $begin = $1; | |
376 | my $var = $2; | |
377 | my $end = $3; | |
378 | # append beginning of value to retval | |
379 | $retval = "$retval$begin"; | |
380 | if (defined($variable{$var})) { | |
381 | $retval = "$retval$variable{$var}"; | |
8d735212 SR |
382 | } elsif (defined($remove_undef) && $remove_undef) { |
383 | # for if statements, any variable that is not defined, | |
384 | # we simple convert to 0 | |
385 | $retval = "${retval}0"; | |
77d942ce SR |
386 | } else { |
387 | # put back the origin piece. | |
388 | $retval = "$retval\$\{$var\}"; | |
389 | } | |
390 | $value = $end; | |
391 | } | |
392 | $retval = "$retval$value"; | |
393 | ||
394 | # remove the space added in the beginning | |
395 | $retval =~ s/ //; | |
396 | ||
397 | return "$retval" | |
398 | } | |
399 | ||
a57419b3 | 400 | sub set_value { |
3d1cc414 | 401 | my ($lvalue, $rvalue, $override, $overrides, $name) = @_; |
a57419b3 | 402 | |
bb8474b1 SR |
403 | if ($lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $rvalue ne "build") { |
404 | # Note if a test is something other than build, then we | |
405 | # will need other manditory options. | |
406 | $buildonly = 0; | |
407 | } | |
408 | ||
a57419b3 | 409 | if (defined($opt{$lvalue})) { |
3d1cc414 SR |
410 | if (!$override || defined(${$overrides}{$lvalue})) { |
411 | my $extra = ""; | |
412 | if ($override) { | |
413 | $extra = "In the same override section!\n"; | |
414 | } | |
415 | die "$name: $.: Option $lvalue defined more than once!\n$extra"; | |
416 | } | |
417 | ${$overrides}{$lvalue} = $rvalue; | |
a57419b3 | 418 | } |
21a9679f SR |
419 | if ($rvalue =~ /^\s*$/) { |
420 | delete $opt{$lvalue}; | |
421 | } else { | |
77d942ce | 422 | $rvalue = process_variables($rvalue); |
21a9679f SR |
423 | $opt{$lvalue} = $rvalue; |
424 | } | |
a57419b3 SR |
425 | } |
426 | ||
77d942ce SR |
427 | sub set_variable { |
428 | my ($lvalue, $rvalue) = @_; | |
429 | ||
430 | if ($rvalue =~ /^\s*$/) { | |
431 | delete $variable{$lvalue}; | |
432 | } else { | |
433 | $rvalue = process_variables($rvalue); | |
434 | $variable{$lvalue} = $rvalue; | |
435 | } | |
436 | } | |
437 | ||
ab7a3f52 SR |
438 | sub process_compare { |
439 | my ($lval, $cmp, $rval) = @_; | |
440 | ||
441 | # remove whitespace | |
442 | ||
443 | $lval =~ s/^\s*//; | |
444 | $lval =~ s/\s*$//; | |
445 | ||
446 | $rval =~ s/^\s*//; | |
447 | $rval =~ s/\s*$//; | |
448 | ||
449 | if ($cmp eq "==") { | |
450 | return $lval eq $rval; | |
451 | } elsif ($cmp eq "!=") { | |
452 | return $lval ne $rval; | |
453 | } | |
454 | ||
455 | my $statement = "$lval $cmp $rval"; | |
456 | my $ret = eval $statement; | |
457 | ||
458 | # $@ stores error of eval | |
459 | if ($@) { | |
460 | return -1; | |
461 | } | |
462 | ||
463 | return $ret; | |
464 | } | |
465 | ||
9900b5dc SR |
466 | sub value_defined { |
467 | my ($val) = @_; | |
468 | ||
469 | return defined($variable{$2}) || | |
470 | defined($opt{$2}); | |
471 | } | |
472 | ||
8d735212 SR |
473 | my $d = 0; |
474 | sub process_expression { | |
475 | my ($name, $val) = @_; | |
476 | ||
477 | my $c = $d++; | |
478 | ||
479 | while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) { | |
480 | my $express = $1; | |
481 | ||
482 | if (process_expression($name, $express)) { | |
483 | $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /; | |
484 | } else { | |
485 | $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /; | |
486 | } | |
487 | } | |
488 | ||
489 | $d--; | |
490 | my $OR = "\\|\\|"; | |
491 | my $AND = "\\&\\&"; | |
45d73a5d | 492 | |
8d735212 SR |
493 | while ($val =~ s/^(.*?)($OR|$AND)//) { |
494 | my $express = $1; | |
495 | my $op = $2; | |
496 | ||
497 | if (process_expression($name, $express)) { | |
498 | if ($op eq "||") { | |
499 | return 1; | |
500 | } | |
501 | } else { | |
502 | if ($op eq "&&") { | |
503 | return 0; | |
504 | } | |
505 | } | |
506 | } | |
45d73a5d | 507 | |
ab7a3f52 SR |
508 | if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) { |
509 | my $ret = process_compare($1, $2, $3); | |
510 | if ($ret < 0) { | |
511 | die "$name: $.: Unable to process comparison\n"; | |
512 | } | |
513 | return $ret; | |
514 | } | |
515 | ||
9900b5dc SR |
516 | if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) { |
517 | if (defined $1) { | |
518 | return !value_defined($2); | |
519 | } else { | |
520 | return value_defined($2); | |
521 | } | |
522 | } | |
523 | ||
45d73a5d SR |
524 | if ($val =~ /^\s*0\s*$/) { |
525 | return 0; | |
526 | } elsif ($val =~ /^\s*\d+\s*$/) { | |
527 | return 1; | |
528 | } | |
529 | ||
9900b5dc | 530 | die ("$name: $.: Undefined content $val in if statement\n"); |
8d735212 SR |
531 | } |
532 | ||
533 | sub process_if { | |
534 | my ($name, $value) = @_; | |
535 | ||
536 | # Convert variables and replace undefined ones with 0 | |
537 | my $val = process_variables($value, 1); | |
538 | my $ret = process_expression $name, $val; | |
539 | ||
540 | return $ret; | |
45d73a5d SR |
541 | } |
542 | ||
2ed3b161 SR |
543 | sub __read_config { |
544 | my ($config, $current_test_num) = @_; | |
2545eb61 | 545 | |
2ed3b161 SR |
546 | my $in; |
547 | open($in, $config) || die "can't read file $config"; | |
2545eb61 | 548 | |
a57419b3 SR |
549 | my $name = $config; |
550 | $name =~ s,.*/(.*),$1,; | |
551 | ||
2ed3b161 | 552 | my $test_num = $$current_test_num; |
a57419b3 SR |
553 | my $default = 1; |
554 | my $repeat = 1; | |
555 | my $num_tests_set = 0; | |
556 | my $skip = 0; | |
557 | my $rest; | |
a9f84424 | 558 | my $line; |
0df213ca | 559 | my $test_case = 0; |
45d73a5d SR |
560 | my $if = 0; |
561 | my $if_set = 0; | |
3d1cc414 SR |
562 | my $override = 0; |
563 | ||
564 | my %overrides; | |
a57419b3 | 565 | |
2ed3b161 | 566 | while (<$in>) { |
2545eb61 SR |
567 | |
568 | # ignore blank lines and comments | |
569 | next if (/^\s*$/ || /\s*\#/); | |
570 | ||
0050b6bb | 571 | if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) { |
a57419b3 | 572 | |
0050b6bb SR |
573 | my $type = $1; |
574 | $rest = $2; | |
a9f84424 | 575 | $line = $2; |
a57419b3 | 576 | |
0050b6bb SR |
577 | my $old_test_num; |
578 | my $old_repeat; | |
3d1cc414 | 579 | $override = 0; |
0050b6bb SR |
580 | |
581 | if ($type eq "TEST_START") { | |
582 | ||
583 | if ($num_tests_set) { | |
584 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; | |
585 | } | |
a57419b3 | 586 | |
0050b6bb SR |
587 | $old_test_num = $test_num; |
588 | $old_repeat = $repeat; | |
a57419b3 | 589 | |
0050b6bb SR |
590 | $test_num += $repeat; |
591 | $default = 0; | |
592 | $repeat = 1; | |
593 | } else { | |
594 | $default = 1; | |
595 | } | |
a57419b3 | 596 | |
a9f84424 SR |
597 | # If SKIP is anywhere in the line, the command will be skipped |
598 | if ($rest =~ s/\s+SKIP\b//) { | |
a57419b3 SR |
599 | $skip = 1; |
600 | } else { | |
0df213ca | 601 | $test_case = 1; |
a57419b3 SR |
602 | $skip = 0; |
603 | } | |
604 | ||
a9f84424 SR |
605 | if ($rest =~ s/\sELSE\b//) { |
606 | if (!$if) { | |
607 | die "$name: $.: ELSE found with out matching IF section\n$_"; | |
608 | } | |
609 | $if = 0; | |
610 | ||
611 | if ($if_set) { | |
612 | $skip = 1; | |
613 | } else { | |
614 | $skip = 0; | |
3d1cc414 | 615 | } |
a57419b3 SR |
616 | } |
617 | ||
a9f84424 | 618 | if ($rest =~ s/\sIF\s+(.*)//) { |
45d73a5d SR |
619 | if (process_if($name, $1)) { |
620 | $if_set = 1; | |
621 | } else { | |
622 | $skip = 1; | |
623 | } | |
624 | $if = 1; | |
625 | } else { | |
626 | $if = 0; | |
a9f84424 SR |
627 | $if_set = 0; |
628 | } | |
629 | ||
630 | if (!$skip) { | |
631 | if ($type eq "TEST_START") { | |
632 | if ($rest =~ s/\s+ITERATE\s+(\d+)//) { | |
633 | $repeat = $1; | |
634 | $repeat_tests{"$test_num"} = $repeat; | |
635 | } | |
636 | } elsif ($rest =~ s/\sOVERRIDE\b//) { | |
637 | # DEFAULT only | |
638 | $override = 1; | |
639 | # Clear previous overrides | |
640 | %overrides = (); | |
641 | } | |
a57419b3 SR |
642 | } |
643 | ||
a9f84424 | 644 | if (!$skip && $rest !~ /^\s*$/) { |
0050b6bb | 645 | die "$name: $.: Gargbage found after $type\n$_"; |
a57419b3 SR |
646 | } |
647 | ||
0050b6bb | 648 | if ($skip && $type eq "TEST_START") { |
a57419b3 | 649 | $test_num = $old_test_num; |
e48c5293 | 650 | $repeat = $old_repeat; |
a57419b3 SR |
651 | } |
652 | ||
ab7a3f52 | 653 | } elsif (/^\s*ELSE\b(.*)$/) { |
45d73a5d SR |
654 | if (!$if) { |
655 | die "$name: $.: ELSE found with out matching IF section\n$_"; | |
656 | } | |
657 | $rest = $1; | |
658 | if ($if_set) { | |
659 | $skip = 1; | |
ab7a3f52 | 660 | $rest = ""; |
45d73a5d SR |
661 | } else { |
662 | $skip = 0; | |
663 | ||
ab7a3f52 | 664 | if ($rest =~ /\sIF\s+(.*)/) { |
45d73a5d SR |
665 | # May be a ELSE IF section. |
666 | if (!process_if($name, $1)) { | |
667 | $skip = 1; | |
668 | } | |
ab7a3f52 | 669 | $rest = ""; |
45d73a5d SR |
670 | } else { |
671 | $if = 0; | |
672 | } | |
673 | } | |
674 | ||
ab7a3f52 SR |
675 | if ($rest !~ /^\s*$/) { |
676 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; | |
677 | } | |
678 | ||
2ed3b161 SR |
679 | } elsif (/^\s*INCLUDE\s+(\S+)/) { |
680 | ||
681 | next if ($skip); | |
682 | ||
683 | if (!$default) { | |
684 | die "$name: $.: INCLUDE can only be done in default sections\n$_"; | |
685 | } | |
686 | ||
687 | my $file = process_variables($1); | |
688 | ||
689 | if ($file !~ m,^/,) { | |
690 | # check the path of the config file first | |
691 | if ($config =~ m,(.*)/,) { | |
692 | if (-f "$1/$file") { | |
693 | $file = "$1/$file"; | |
694 | } | |
695 | } | |
696 | } | |
697 | ||
698 | if ( ! -r $file ) { | |
699 | die "$name: $.: Can't read file $file\n$_"; | |
700 | } | |
701 | ||
702 | if (__read_config($file, \$test_num)) { | |
703 | $test_case = 1; | |
704 | } | |
705 | ||
a57419b3 SR |
706 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { |
707 | ||
708 | next if ($skip); | |
709 | ||
2545eb61 SR |
710 | my $lvalue = $1; |
711 | my $rvalue = $2; | |
712 | ||
a57419b3 SR |
713 | if (!$default && |
714 | ($lvalue eq "NUM_TESTS" || | |
715 | $lvalue eq "LOG_FILE" || | |
716 | $lvalue eq "CLEAR_LOG")) { | |
717 | die "$name: $.: $lvalue must be set in DEFAULTS section\n"; | |
718 | } | |
719 | ||
720 | if ($lvalue eq "NUM_TESTS") { | |
721 | if ($test_num) { | |
722 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; | |
723 | } | |
724 | if (!$default) { | |
725 | die "$name: $.: NUM_TESTS must be set in default section\n"; | |
726 | } | |
727 | $num_tests_set = 1; | |
728 | } | |
729 | ||
730 | if ($default || $lvalue =~ /\[\d+\]$/) { | |
3d1cc414 | 731 | set_value($lvalue, $rvalue, $override, \%overrides, $name); |
a57419b3 SR |
732 | } else { |
733 | my $val = "$lvalue\[$test_num\]"; | |
3d1cc414 | 734 | set_value($val, $rvalue, $override, \%overrides, $name); |
a57419b3 SR |
735 | |
736 | if ($repeat > 1) { | |
737 | $repeats{$val} = $repeat; | |
738 | } | |
a75fecec | 739 | } |
77d942ce SR |
740 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) { |
741 | next if ($skip); | |
742 | ||
743 | my $lvalue = $1; | |
744 | my $rvalue = $2; | |
745 | ||
746 | # process config variables. | |
747 | # Config variables are only active while reading the | |
748 | # config and can be defined anywhere. They also ignore | |
749 | # TEST_START and DEFAULTS, but are skipped if they are in | |
750 | # on of these sections that have SKIP defined. | |
751 | # The save variable can be | |
752 | # defined multiple times and the new one simply overrides | |
753 | # the prevous one. | |
754 | set_variable($lvalue, $rvalue); | |
755 | ||
a57419b3 SR |
756 | } else { |
757 | die "$name: $.: Garbage found in config\n$_"; | |
2545eb61 SR |
758 | } |
759 | } | |
760 | ||
a57419b3 SR |
761 | if ($test_num) { |
762 | $test_num += $repeat - 1; | |
763 | $opt{"NUM_TESTS"} = $test_num; | |
764 | } | |
765 | ||
2ed3b161 SR |
766 | close($in); |
767 | ||
768 | $$current_test_num = $test_num; | |
769 | ||
770 | return $test_case; | |
771 | } | |
772 | ||
c4261d0f SR |
773 | sub get_test_case { |
774 | print "What test case would you like to run?\n"; | |
775 | print " (build, install or boot)\n"; | |
776 | print " Other tests are available but require editing the config file\n"; | |
777 | my $ans = <STDIN>; | |
778 | chomp $ans; | |
779 | $default{"TEST_TYPE"} = $ans; | |
780 | } | |
781 | ||
2ed3b161 SR |
782 | sub read_config { |
783 | my ($config) = @_; | |
784 | ||
785 | my $test_case; | |
786 | my $test_num = 0; | |
787 | ||
788 | $test_case = __read_config $config, \$test_num; | |
789 | ||
8d1491ba SR |
790 | # make sure we have all mandatory configs |
791 | get_ktest_configs; | |
792 | ||
0df213ca SR |
793 | # was a test specified? |
794 | if (!$test_case) { | |
795 | print "No test case specified.\n"; | |
c4261d0f | 796 | get_test_case; |
0df213ca SR |
797 | } |
798 | ||
a75fecec SR |
799 | # set any defaults |
800 | ||
801 | foreach my $default (keys %default) { | |
802 | if (!defined($opt{$default})) { | |
803 | $opt{$default} = $default{$default}; | |
804 | } | |
805 | } | |
2545eb61 SR |
806 | } |
807 | ||
23715c3c SR |
808 | sub __eval_option { |
809 | my ($option, $i) = @_; | |
810 | ||
811 | # Add space to evaluate the character before $ | |
812 | $option = " $option"; | |
813 | my $retval = ""; | |
f9dfb65b RV |
814 | my $repeated = 0; |
815 | my $parent = 0; | |
816 | ||
817 | foreach my $test (keys %repeat_tests) { | |
818 | if ($i >= $test && | |
819 | $i < $test + $repeat_tests{$test}) { | |
820 | ||
821 | $repeated = 1; | |
822 | $parent = $test; | |
823 | last; | |
824 | } | |
825 | } | |
23715c3c SR |
826 | |
827 | while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) { | |
828 | my $start = $1; | |
829 | my $var = $2; | |
830 | my $end = $3; | |
831 | ||
832 | # Append beginning of line | |
833 | $retval = "$retval$start"; | |
834 | ||
835 | # If the iteration option OPT[$i] exists, then use that. | |
836 | # otherwise see if the default OPT (without [$i]) exists. | |
837 | ||
838 | my $o = "$var\[$i\]"; | |
f9dfb65b | 839 | my $parento = "$var\[$parent\]"; |
23715c3c SR |
840 | |
841 | if (defined($opt{$o})) { | |
842 | $o = $opt{$o}; | |
843 | $retval = "$retval$o"; | |
f9dfb65b RV |
844 | } elsif ($repeated && defined($opt{$parento})) { |
845 | $o = $opt{$parento}; | |
846 | $retval = "$retval$o"; | |
23715c3c SR |
847 | } elsif (defined($opt{$var})) { |
848 | $o = $opt{$var}; | |
849 | $retval = "$retval$o"; | |
850 | } else { | |
851 | $retval = "$retval\$\{$var\}"; | |
852 | } | |
853 | ||
854 | $option = $end; | |
855 | } | |
856 | ||
857 | $retval = "$retval$option"; | |
858 | ||
859 | $retval =~ s/^ //; | |
860 | ||
861 | return $retval; | |
862 | } | |
863 | ||
864 | sub eval_option { | |
865 | my ($option, $i) = @_; | |
866 | ||
867 | my $prev = ""; | |
868 | ||
869 | # Since an option can evaluate to another option, | |
870 | # keep iterating until we do not evaluate any more | |
871 | # options. | |
872 | my $r = 0; | |
873 | while ($prev ne $option) { | |
874 | # Check for recursive evaluations. | |
875 | # 100 deep should be more than enough. | |
876 | if ($r++ > 100) { | |
877 | die "Over 100 evaluations accurred with $option\n" . | |
878 | "Check for recursive variables\n"; | |
879 | } | |
880 | $prev = $option; | |
881 | $option = __eval_option($option, $i); | |
882 | } | |
883 | ||
884 | return $option; | |
885 | } | |
886 | ||
d1e2f22a | 887 | sub _logit { |
2545eb61 SR |
888 | if (defined($opt{"LOG_FILE"})) { |
889 | open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}"; | |
890 | print OUT @_; | |
891 | close(OUT); | |
892 | } | |
893 | } | |
894 | ||
d1e2f22a SR |
895 | sub logit { |
896 | if (defined($opt{"LOG_FILE"})) { | |
897 | _logit @_; | |
898 | } else { | |
899 | print @_; | |
900 | } | |
901 | } | |
902 | ||
5f9b6ced SR |
903 | sub doprint { |
904 | print @_; | |
d1e2f22a | 905 | _logit @_; |
5f9b6ced SR |
906 | } |
907 | ||
7faafbd6 | 908 | sub run_command; |
2728be41 AJ |
909 | sub start_monitor; |
910 | sub end_monitor; | |
911 | sub wait_for_monitor; | |
7faafbd6 SR |
912 | |
913 | sub reboot { | |
2728be41 AJ |
914 | my ($time) = @_; |
915 | ||
2b803365 SR |
916 | if (defined($time)) { |
917 | start_monitor; | |
918 | # flush out current monitor | |
919 | # May contain the reboot success line | |
920 | wait_for_monitor 1; | |
921 | } | |
922 | ||
7faafbd6 | 923 | # try to reboot normally |
e48c5293 | 924 | if (run_command $reboot) { |
576f627c SR |
925 | if (defined($powercycle_after_reboot)) { |
926 | sleep $powercycle_after_reboot; | |
927 | run_command "$power_cycle"; | |
928 | } | |
929 | } else { | |
7faafbd6 | 930 | # nope? power cycle it. |
a75fecec | 931 | run_command "$power_cycle"; |
7faafbd6 | 932 | } |
2728be41 AJ |
933 | |
934 | if (defined($time)) { | |
2b803365 | 935 | wait_for_monitor($time, $reboot_success_line); |
2728be41 AJ |
936 | end_monitor; |
937 | } | |
7faafbd6 SR |
938 | } |
939 | ||
576f627c SR |
940 | sub do_not_reboot { |
941 | my $i = $iteration; | |
942 | ||
4ab1cce5 | 943 | return $test_type eq "build" || $no_reboot || |
576f627c SR |
944 | ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") || |
945 | ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build"); | |
946 | } | |
947 | ||
5c42fc5b | 948 | sub dodie { |
5a391fbf | 949 | doprint "CRITICAL FAILURE... ", @_, "\n"; |
5c42fc5b | 950 | |
576f627c SR |
951 | my $i = $iteration; |
952 | ||
953 | if ($reboot_on_error && !do_not_reboot) { | |
954 | ||
75c3fda7 | 955 | doprint "REBOOTING\n"; |
7faafbd6 | 956 | reboot; |
75c3fda7 | 957 | |
a75fecec | 958 | } elsif ($poweroff_on_error && defined($power_off)) { |
5c42fc5b | 959 | doprint "POWERING OFF\n"; |
a75fecec | 960 | `$power_off`; |
5c42fc5b | 961 | } |
75c3fda7 | 962 | |
f80802cb SR |
963 | if (defined($opt{"LOG_FILE"})) { |
964 | print " See $opt{LOG_FILE} for more info.\n"; | |
965 | } | |
966 | ||
576f627c | 967 | die @_, "\n"; |
5c42fc5b SR |
968 | } |
969 | ||
7faafbd6 SR |
970 | sub open_console { |
971 | my ($fp) = @_; | |
972 | ||
973 | my $flags; | |
974 | ||
a75fecec SR |
975 | my $pid = open($fp, "$console|") or |
976 | dodie "Can't open console $console"; | |
7faafbd6 SR |
977 | |
978 | $flags = fcntl($fp, F_GETFL, 0) or | |
576f627c | 979 | dodie "Can't get flags for the socket: $!"; |
7faafbd6 | 980 | $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or |
576f627c | 981 | dodie "Can't set flags for the socket: $!"; |
7faafbd6 SR |
982 | |
983 | return $pid; | |
984 | } | |
985 | ||
986 | sub close_console { | |
987 | my ($fp, $pid) = @_; | |
988 | ||
989 | doprint "kill child process $pid\n"; | |
990 | kill 2, $pid; | |
991 | ||
992 | print "closing!\n"; | |
993 | close($fp); | |
994 | } | |
995 | ||
996 | sub start_monitor { | |
997 | if ($monitor_cnt++) { | |
998 | return; | |
999 | } | |
1000 | $monitor_fp = \*MONFD; | |
1001 | $monitor_pid = open_console $monitor_fp; | |
a75fecec SR |
1002 | |
1003 | return; | |
1004 | ||
1005 | open(MONFD, "Stop perl from warning about single use of MONFD"); | |
7faafbd6 SR |
1006 | } |
1007 | ||
1008 | sub end_monitor { | |
1009 | if (--$monitor_cnt) { | |
1010 | return; | |
1011 | } | |
1012 | close_console($monitor_fp, $monitor_pid); | |
1013 | } | |
1014 | ||
1015 | sub wait_for_monitor { | |
2b803365 SR |
1016 | my ($time, $stop) = @_; |
1017 | my $full_line = ""; | |
7faafbd6 | 1018 | my $line; |
2b803365 | 1019 | my $booted = 0; |
7faafbd6 | 1020 | |
a75fecec | 1021 | doprint "** Wait for monitor to settle down **\n"; |
7faafbd6 SR |
1022 | |
1023 | # read the monitor and wait for the system to calm down | |
2b803365 | 1024 | while (!$booted) { |
7faafbd6 | 1025 | $line = wait_for_input($monitor_fp, $time); |
2b803365 SR |
1026 | last if (!defined($line)); |
1027 | print "$line"; | |
1028 | $full_line .= $line; | |
1029 | ||
1030 | if (defined($stop) && $full_line =~ /$stop/) { | |
1031 | doprint "wait for monitor detected $stop\n"; | |
1032 | $booted = 1; | |
1033 | } | |
1034 | ||
1035 | if ($line =~ /\n/) { | |
1036 | $full_line = ""; | |
1037 | } | |
1038 | } | |
a75fecec | 1039 | print "** Monitor flushed **\n"; |
7faafbd6 SR |
1040 | } |
1041 | ||
de5b6e3b RV |
1042 | sub save_logs { |
1043 | my ($result, $basedir) = @_; | |
1044 | my @t = localtime; | |
1045 | my $date = sprintf "%04d%02d%02d%02d%02d%02d", | |
1046 | 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0]; | |
1047 | ||
1048 | my $type = $build_type; | |
1049 | if ($type =~ /useconfig/) { | |
1050 | $type = "useconfig"; | |
1051 | } | |
1052 | ||
1053 | my $dir = "$machine-$test_type-$type-$result-$date"; | |
1054 | ||
1055 | $dir = "$basedir/$dir"; | |
1056 | ||
1057 | if (!-d $dir) { | |
1058 | mkpath($dir) or | |
1059 | die "can't create $dir"; | |
1060 | } | |
1061 | ||
1062 | my %files = ( | |
1063 | "config" => $output_config, | |
1064 | "buildlog" => $buildlog, | |
1065 | "dmesg" => $dmesg, | |
1066 | "testlog" => $testlog, | |
1067 | ); | |
1068 | ||
1069 | while (my ($name, $source) = each(%files)) { | |
1070 | if (-f "$source") { | |
1071 | cp "$source", "$dir/$name" or | |
1072 | die "failed to copy $source"; | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | doprint "*** Saved info to $dir ***\n"; | |
1077 | } | |
1078 | ||
2b7d9b21 SR |
1079 | sub fail { |
1080 | ||
a75fecec | 1081 | if ($die_on_failure) { |
2b7d9b21 SR |
1082 | dodie @_; |
1083 | } | |
1084 | ||
a75fecec | 1085 | doprint "FAILED\n"; |
7faafbd6 | 1086 | |
576f627c SR |
1087 | my $i = $iteration; |
1088 | ||
a75fecec | 1089 | # no need to reboot for just building. |
576f627c | 1090 | if (!do_not_reboot) { |
a75fecec | 1091 | doprint "REBOOTING\n"; |
2728be41 | 1092 | reboot $sleep_time; |
a75fecec | 1093 | } |
7faafbd6 | 1094 | |
9064af52 SR |
1095 | my $name = ""; |
1096 | ||
1097 | if (defined($test_name)) { | |
1098 | $name = " ($test_name)"; | |
1099 | } | |
1100 | ||
576f627c SR |
1101 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
1102 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | |
9064af52 | 1103 | doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n"; |
576f627c SR |
1104 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
1105 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | |
a75fecec | 1106 | |
de5b6e3b RV |
1107 | if (defined($store_failures)) { |
1108 | save_logs "fail", $store_failures; | |
1109 | } | |
7faafbd6 | 1110 | |
2b7d9b21 SR |
1111 | return 1; |
1112 | } | |
1113 | ||
2545eb61 SR |
1114 | sub run_command { |
1115 | my ($command) = @_; | |
d6ce2a0b SR |
1116 | my $dolog = 0; |
1117 | my $dord = 0; | |
1118 | my $pid; | |
1119 | ||
e48c5293 SR |
1120 | $command =~ s/\$SSH_USER/$ssh_user/g; |
1121 | $command =~ s/\$MACHINE/$machine/g; | |
1122 | ||
d6ce2a0b SR |
1123 | doprint("$command ... "); |
1124 | ||
1125 | $pid = open(CMD, "$command 2>&1 |") or | |
2b7d9b21 | 1126 | (fail "unable to exec $command" and return 0); |
2545eb61 SR |
1127 | |
1128 | if (defined($opt{"LOG_FILE"})) { | |
d6ce2a0b SR |
1129 | open(LOG, ">>$opt{LOG_FILE}") or |
1130 | dodie "failed to write to log"; | |
1131 | $dolog = 1; | |
6c5ee0be SR |
1132 | } |
1133 | ||
1134 | if (defined($redirect)) { | |
d6ce2a0b SR |
1135 | open (RD, ">$redirect") or |
1136 | dodie "failed to write to redirect $redirect"; | |
1137 | $dord = 1; | |
2545eb61 SR |
1138 | } |
1139 | ||
d6ce2a0b SR |
1140 | while (<CMD>) { |
1141 | print LOG if ($dolog); | |
1142 | print RD if ($dord); | |
1143 | } | |
2545eb61 | 1144 | |
d6ce2a0b | 1145 | waitpid($pid, 0); |
2545eb61 SR |
1146 | my $failed = $?; |
1147 | ||
d6ce2a0b SR |
1148 | close(CMD); |
1149 | close(LOG) if ($dolog); | |
1150 | close(RD) if ($dord); | |
1151 | ||
2545eb61 SR |
1152 | if ($failed) { |
1153 | doprint "FAILED!\n"; | |
1154 | } else { | |
1155 | doprint "SUCCESS\n"; | |
1156 | } | |
1157 | ||
5f9b6ced SR |
1158 | return !$failed; |
1159 | } | |
1160 | ||
e48c5293 SR |
1161 | sub run_ssh { |
1162 | my ($cmd) = @_; | |
1163 | my $cp_exec = $ssh_exec; | |
1164 | ||
1165 | $cp_exec =~ s/\$SSH_COMMAND/$cmd/g; | |
1166 | return run_command "$cp_exec"; | |
1167 | } | |
1168 | ||
1169 | sub run_scp { | |
1170 | my ($src, $dst) = @_; | |
1171 | my $cp_scp = $scp_to_target; | |
1172 | ||
1173 | $cp_scp =~ s/\$SRC_FILE/$src/g; | |
1174 | $cp_scp =~ s/\$DST_FILE/$dst/g; | |
1175 | ||
1176 | return run_command "$cp_scp"; | |
1177 | } | |
1178 | ||
5f9b6ced SR |
1179 | sub get_grub_index { |
1180 | ||
a75fecec SR |
1181 | if ($reboot_type ne "grub") { |
1182 | return; | |
1183 | } | |
5a391fbf | 1184 | return if (defined($grub_number)); |
5f9b6ced SR |
1185 | |
1186 | doprint "Find grub menu ... "; | |
1187 | $grub_number = -1; | |
e48c5293 SR |
1188 | |
1189 | my $ssh_grub = $ssh_exec; | |
1190 | $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g; | |
1191 | ||
1192 | open(IN, "$ssh_grub |") | |
5f9b6ced | 1193 | or die "unable to get menu.lst"; |
e48c5293 | 1194 | |
eaa1fe25 SR |
1195 | my $found = 0; |
1196 | ||
5f9b6ced | 1197 | while (<IN>) { |
a75fecec | 1198 | if (/^\s*title\s+$grub_menu\s*$/) { |
5f9b6ced | 1199 | $grub_number++; |
eaa1fe25 | 1200 | $found = 1; |
5f9b6ced SR |
1201 | last; |
1202 | } elsif (/^\s*title\s/) { | |
1203 | $grub_number++; | |
1204 | } | |
1205 | } | |
1206 | close(IN); | |
1207 | ||
a75fecec | 1208 | die "Could not find '$grub_menu' in /boot/grub/menu on $machine" |
eaa1fe25 | 1209 | if (!$found); |
5f9b6ced | 1210 | doprint "$grub_number\n"; |
2545eb61 SR |
1211 | } |
1212 | ||
2545eb61 SR |
1213 | sub wait_for_input |
1214 | { | |
1215 | my ($fp, $time) = @_; | |
1216 | my $rin; | |
1217 | my $ready; | |
1218 | my $line; | |
1219 | my $ch; | |
1220 | ||
1221 | if (!defined($time)) { | |
1222 | $time = $timeout; | |
1223 | } | |
1224 | ||
1225 | $rin = ''; | |
1226 | vec($rin, fileno($fp), 1) = 1; | |
1227 | $ready = select($rin, undef, undef, $time); | |
1228 | ||
1229 | $line = ""; | |
1230 | ||
1231 | # try to read one char at a time | |
1232 | while (sysread $fp, $ch, 1) { | |
1233 | $line .= $ch; | |
1234 | last if ($ch eq "\n"); | |
1235 | } | |
1236 | ||
1237 | if (!length($line)) { | |
1238 | return undef; | |
1239 | } | |
1240 | ||
1241 | return $line; | |
1242 | } | |
1243 | ||
75c3fda7 | 1244 | sub reboot_to { |
a75fecec | 1245 | if ($reboot_type eq "grub") { |
c54367f9 SR |
1246 | run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; |
1247 | reboot; | |
a75fecec SR |
1248 | return; |
1249 | } | |
1250 | ||
1251 | run_command "$reboot_script"; | |
2545eb61 SR |
1252 | } |
1253 | ||
a57419b3 SR |
1254 | sub get_sha1 { |
1255 | my ($commit) = @_; | |
1256 | ||
1257 | doprint "git rev-list --max-count=1 $commit ... "; | |
1258 | my $sha1 = `git rev-list --max-count=1 $commit`; | |
1259 | my $ret = $?; | |
1260 | ||
1261 | logit $sha1; | |
1262 | ||
1263 | if ($ret) { | |
1264 | doprint "FAILED\n"; | |
1265 | dodie "Failed to get git $commit"; | |
1266 | } | |
1267 | ||
1268 | print "SUCCESS\n"; | |
1269 | ||
1270 | chomp $sha1; | |
1271 | ||
1272 | return $sha1; | |
1273 | } | |
1274 | ||
5a391fbf | 1275 | sub monitor { |
2545eb61 SR |
1276 | my $booted = 0; |
1277 | my $bug = 0; | |
5c42fc5b | 1278 | my $skip_call_trace = 0; |
2b7d9b21 | 1279 | my $loops; |
2545eb61 | 1280 | |
7faafbd6 | 1281 | wait_for_monitor 5; |
2545eb61 SR |
1282 | |
1283 | my $line; | |
1284 | my $full_line = ""; | |
1285 | ||
7faafbd6 SR |
1286 | open(DMESG, "> $dmesg") or |
1287 | die "unable to write to $dmesg"; | |
2545eb61 | 1288 | |
75c3fda7 | 1289 | reboot_to; |
2545eb61 | 1290 | |
1c8a617a SR |
1291 | my $success_start; |
1292 | my $failure_start; | |
2d01b26a SR |
1293 | my $monitor_start = time; |
1294 | my $done = 0; | |
f1a5b962 | 1295 | my $version_found = 0; |
1c8a617a | 1296 | |
2d01b26a | 1297 | while (!$done) { |
2545eb61 | 1298 | |
ecaf8e52 SR |
1299 | if ($bug && defined($stop_after_failure) && |
1300 | $stop_after_failure >= 0) { | |
1301 | my $time = $stop_after_failure - (time - $failure_start); | |
1302 | $line = wait_for_input($monitor_fp, $time); | |
1303 | if (!defined($line)) { | |
1304 | doprint "bug timed out after $booted_timeout seconds\n"; | |
1305 | doprint "Test forced to stop after $stop_after_failure seconds after failure\n"; | |
1306 | last; | |
1307 | } | |
1308 | } elsif ($booted) { | |
a75fecec | 1309 | $line = wait_for_input($monitor_fp, $booted_timeout); |
cd4f1d53 SR |
1310 | if (!defined($line)) { |
1311 | my $s = $booted_timeout == 1 ? "" : "s"; | |
1312 | doprint "Successful boot found: break after $booted_timeout second$s\n"; | |
1313 | last; | |
1314 | } | |
2b7d9b21 | 1315 | } else { |
7faafbd6 | 1316 | $line = wait_for_input($monitor_fp); |
cd4f1d53 SR |
1317 | if (!defined($line)) { |
1318 | my $s = $timeout == 1 ? "" : "s"; | |
1319 | doprint "Timed out after $timeout second$s\n"; | |
1320 | last; | |
1321 | } | |
2b7d9b21 | 1322 | } |
2545eb61 | 1323 | |
2545eb61 | 1324 | doprint $line; |
7faafbd6 | 1325 | print DMESG $line; |
2545eb61 SR |
1326 | |
1327 | # we are not guaranteed to get a full line | |
1328 | $full_line .= $line; | |
1329 | ||
a75fecec | 1330 | if ($full_line =~ /$success_line/) { |
2545eb61 | 1331 | $booted = 1; |
1c8a617a SR |
1332 | $success_start = time; |
1333 | } | |
1334 | ||
1335 | if ($booted && defined($stop_after_success) && | |
1336 | $stop_after_success >= 0) { | |
1337 | my $now = time; | |
1338 | if ($now - $success_start >= $stop_after_success) { | |
1339 | doprint "Test forced to stop after $stop_after_success seconds after success\n"; | |
1340 | last; | |
1341 | } | |
2545eb61 SR |
1342 | } |
1343 | ||
5c42fc5b SR |
1344 | if ($full_line =~ /\[ backtrace testing \]/) { |
1345 | $skip_call_trace = 1; | |
1346 | } | |
1347 | ||
2545eb61 | 1348 | if ($full_line =~ /call trace:/i) { |
4651920e | 1349 | if (!$bug && !$skip_call_trace) { |
1c8a617a SR |
1350 | $bug = 1; |
1351 | $failure_start = time; | |
1352 | } | |
1353 | } | |
1354 | ||
1355 | if ($bug && defined($stop_after_failure) && | |
1356 | $stop_after_failure >= 0) { | |
1357 | my $now = time; | |
1358 | if ($now - $failure_start >= $stop_after_failure) { | |
1359 | doprint "Test forced to stop after $stop_after_failure seconds after failure\n"; | |
1360 | last; | |
1361 | } | |
5c42fc5b SR |
1362 | } |
1363 | ||
1364 | if ($full_line =~ /\[ end of backtrace testing \]/) { | |
1365 | $skip_call_trace = 0; | |
1366 | } | |
1367 | ||
1368 | if ($full_line =~ /Kernel panic -/) { | |
10abf118 | 1369 | $failure_start = time; |
2545eb61 SR |
1370 | $bug = 1; |
1371 | } | |
1372 | ||
f1a5b962 SR |
1373 | # Detect triple faults by testing the banner |
1374 | if ($full_line =~ /\bLinux version (\S+).*\n/) { | |
1375 | if ($1 eq $version) { | |
1376 | $version_found = 1; | |
1377 | } elsif ($version_found && $detect_triplefault) { | |
1378 | # We already booted into the kernel we are testing, | |
1379 | # but now we booted into another kernel? | |
1380 | # Consider this a triple fault. | |
1381 | doprint "Aleady booted in Linux kernel $version, but now\n"; | |
1382 | doprint "we booted into Linux kernel $1.\n"; | |
1383 | doprint "Assuming that this is a triple fault.\n"; | |
1384 | doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n"; | |
1385 | last; | |
1386 | } | |
1387 | } | |
1388 | ||
2545eb61 SR |
1389 | if ($line =~ /\n/) { |
1390 | $full_line = ""; | |
1391 | } | |
2d01b26a SR |
1392 | |
1393 | if ($stop_test_after > 0 && !$booted && !$bug) { | |
1394 | if (time - $monitor_start > $stop_test_after) { | |
4d62bf51 | 1395 | doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n"; |
2d01b26a SR |
1396 | $done = 1; |
1397 | } | |
1398 | } | |
2545eb61 SR |
1399 | } |
1400 | ||
7faafbd6 | 1401 | close(DMESG); |
2545eb61 | 1402 | |
a75fecec | 1403 | if ($bug) { |
2b7d9b21 | 1404 | return 0 if ($in_bisect); |
576f627c | 1405 | fail "failed - got a bug report" and return 0; |
2545eb61 SR |
1406 | } |
1407 | ||
a75fecec | 1408 | if (!$booted) { |
2b7d9b21 | 1409 | return 0 if ($in_bisect); |
576f627c | 1410 | fail "failed - never got a boot prompt." and return 0; |
2545eb61 | 1411 | } |
5f9b6ced | 1412 | |
2b7d9b21 | 1413 | return 1; |
2545eb61 SR |
1414 | } |
1415 | ||
db05cfef SR |
1416 | sub do_post_install { |
1417 | ||
1418 | return if (!defined($post_install)); | |
1419 | ||
1420 | my $cp_post_install = $post_install; | |
1421 | $cp_post_install =~ s/\$KERNEL_VERSION/$version/g; | |
1422 | run_command "$cp_post_install" or | |
1423 | dodie "Failed to run post install"; | |
1424 | } | |
1425 | ||
2545eb61 SR |
1426 | sub install { |
1427 | ||
e0a8742e SR |
1428 | return if ($no_install); |
1429 | ||
e48c5293 | 1430 | run_scp "$outputdir/$build_target", "$target_image" or |
5c42fc5b | 1431 | dodie "failed to copy image"; |
2545eb61 | 1432 | |
5f9b6ced | 1433 | my $install_mods = 0; |
2545eb61 | 1434 | |
5f9b6ced SR |
1435 | # should we process modules? |
1436 | $install_mods = 0; | |
51ad1dd1 | 1437 | open(IN, "$output_config") or dodie("Can't read config file"); |
5f9b6ced SR |
1438 | while (<IN>) { |
1439 | if (/CONFIG_MODULES(=y)?/) { | |
1440 | $install_mods = 1 if (defined($1)); | |
1441 | last; | |
5c42fc5b | 1442 | } |
5f9b6ced SR |
1443 | } |
1444 | close(IN); | |
5c42fc5b | 1445 | |
5f9b6ced | 1446 | if (!$install_mods) { |
db05cfef | 1447 | do_post_install; |
5f9b6ced SR |
1448 | doprint "No modules needed\n"; |
1449 | return; | |
1450 | } | |
2545eb61 | 1451 | |
a75fecec | 1452 | run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or |
5f9b6ced | 1453 | dodie "Failed to install modules"; |
5c42fc5b | 1454 | |
5f9b6ced | 1455 | my $modlib = "/lib/modules/$version"; |
a57419b3 | 1456 | my $modtar = "ktest-mods.tar.bz2"; |
5c42fc5b | 1457 | |
e48c5293 | 1458 | run_ssh "rm -rf $modlib" or |
5f9b6ced | 1459 | dodie "failed to remove old mods: $modlib"; |
5c42fc5b | 1460 | |
5f9b6ced | 1461 | # would be nice if scp -r did not follow symbolic links |
a75fecec | 1462 | run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or |
5f9b6ced SR |
1463 | dodie "making tarball"; |
1464 | ||
e48c5293 | 1465 | run_scp "$tmpdir/$modtar", "/tmp" or |
5f9b6ced SR |
1466 | dodie "failed to copy modules"; |
1467 | ||
a75fecec | 1468 | unlink "$tmpdir/$modtar"; |
5f9b6ced | 1469 | |
e7b13441 | 1470 | run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or |
5f9b6ced | 1471 | dodie "failed to tar modules"; |
2545eb61 | 1472 | |
e48c5293 | 1473 | run_ssh "rm -f /tmp/$modtar"; |
8b37ca8c | 1474 | |
db05cfef | 1475 | do_post_install; |
2545eb61 SR |
1476 | } |
1477 | ||
ddf607e5 SR |
1478 | sub get_version { |
1479 | # get the release name | |
1480 | doprint "$make kernelrelease ... "; | |
1481 | $version = `$make kernelrelease | tail -1`; | |
1482 | chomp($version); | |
1483 | doprint "$version\n"; | |
1484 | } | |
1485 | ||
1486 | sub start_monitor_and_boot { | |
9f7424cc SR |
1487 | # Make sure the stable kernel has finished booting |
1488 | start_monitor; | |
1489 | wait_for_monitor 5; | |
1490 | end_monitor; | |
1491 | ||
ddf607e5 SR |
1492 | get_grub_index; |
1493 | get_version; | |
1494 | install; | |
1495 | ||
1496 | start_monitor; | |
1497 | return monitor; | |
1498 | } | |
1499 | ||
6c5ee0be SR |
1500 | sub check_buildlog { |
1501 | my ($patch) = @_; | |
1502 | ||
6c5ee0be SR |
1503 | my @files = `git show $patch | diffstat -l`; |
1504 | ||
1505 | open(IN, "git show $patch |") or | |
1506 | dodie "failed to show $patch"; | |
1507 | while (<IN>) { | |
1508 | if (m,^--- a/(.*),) { | |
1509 | chomp $1; | |
1510 | $files[$#files] = $1; | |
1511 | } | |
1512 | } | |
1513 | close(IN); | |
1514 | ||
1515 | open(IN, $buildlog) or dodie "Can't open $buildlog"; | |
1516 | while (<IN>) { | |
1517 | if (/^\s*(.*?):.*(warning|error)/) { | |
1518 | my $err = $1; | |
1519 | foreach my $file (@files) { | |
a75fecec | 1520 | my $fullpath = "$builddir/$file"; |
6c5ee0be | 1521 | if ($file eq $err || $fullpath eq $err) { |
2b7d9b21 | 1522 | fail "$file built with warnings" and return 0; |
6c5ee0be SR |
1523 | } |
1524 | } | |
1525 | } | |
1526 | } | |
1527 | close(IN); | |
2b7d9b21 SR |
1528 | |
1529 | return 1; | |
6c5ee0be SR |
1530 | } |
1531 | ||
fcb3f16a SR |
1532 | sub apply_min_config { |
1533 | my $outconfig = "$output_config.new"; | |
1534 | ||
1535 | # Read the config file and remove anything that | |
1536 | # is in the force_config hash (from minconfig and others) | |
1537 | # then add the force config back. | |
1538 | ||
1539 | doprint "Applying minimum configurations into $output_config.new\n"; | |
1540 | ||
1541 | open (OUT, ">$outconfig") or | |
1542 | dodie "Can't create $outconfig"; | |
1543 | ||
1544 | if (-f $output_config) { | |
1545 | open (IN, $output_config) or | |
1546 | dodie "Failed to open $output_config"; | |
1547 | while (<IN>) { | |
1548 | if (/^(# )?(CONFIG_[^\s=]*)/) { | |
1549 | next if (defined($force_config{$2})); | |
1550 | } | |
1551 | print OUT; | |
1552 | } | |
1553 | close IN; | |
1554 | } | |
1555 | foreach my $config (keys %force_config) { | |
1556 | print OUT "$force_config{$config}\n"; | |
1557 | } | |
1558 | close OUT; | |
1559 | ||
1560 | run_command "mv $outconfig $output_config"; | |
1561 | } | |
1562 | ||
612b9e9b | 1563 | sub make_oldconfig { |
612b9e9b | 1564 | |
4c4ab120 SR |
1565 | my @force_list = keys %force_config; |
1566 | ||
1567 | if ($#force_list >= 0) { | |
1568 | apply_min_config; | |
1569 | } | |
fcb3f16a SR |
1570 | |
1571 | if (!run_command "$make oldnoconfig") { | |
612b9e9b SR |
1572 | # Perhaps oldnoconfig doesn't exist in this version of the kernel |
1573 | # try a yes '' | oldconfig | |
1574 | doprint "oldnoconfig failed, trying yes '' | make oldconfig\n"; | |
fcb3f16a | 1575 | run_command "yes '' | $make oldconfig" or |
612b9e9b SR |
1576 | dodie "failed make config oldconfig"; |
1577 | } | |
1578 | } | |
1579 | ||
fcb3f16a SR |
1580 | # read a config file and use this to force new configs. |
1581 | sub load_force_config { | |
1582 | my ($config) = @_; | |
1583 | ||
1584 | open(IN, $config) or | |
1585 | dodie "failed to read $config"; | |
1586 | while (<IN>) { | |
1587 | chomp; | |
1588 | if (/^(CONFIG[^\s=]*)(\s*=.*)/) { | |
1589 | $force_config{$1} = $_; | |
1590 | } elsif (/^# (CONFIG_\S*) is not set/) { | |
1591 | $force_config{$1} = $_; | |
1592 | } | |
1593 | } | |
1594 | close IN; | |
1595 | } | |
1596 | ||
2545eb61 SR |
1597 | sub build { |
1598 | my ($type) = @_; | |
5c42fc5b | 1599 | |
7faafbd6 SR |
1600 | unlink $buildlog; |
1601 | ||
4ab1cce5 SR |
1602 | # Failed builds should not reboot the target |
1603 | my $save_no_reboot = $no_reboot; | |
1604 | $no_reboot = 1; | |
1605 | ||
0bd6c1a3 SR |
1606 | if (defined($pre_build)) { |
1607 | my $ret = run_command $pre_build; | |
1608 | if (!$ret && defined($pre_build_die) && | |
1609 | $pre_build_die) { | |
1610 | dodie "failed to pre_build\n"; | |
1611 | } | |
1612 | } | |
1613 | ||
75c3fda7 | 1614 | if ($type =~ /^useconfig:(.*)/) { |
51ad1dd1 | 1615 | run_command "cp $1 $output_config" or |
75c3fda7 | 1616 | dodie "could not copy $1 to .config"; |
5f9b6ced | 1617 | |
75c3fda7 SR |
1618 | $type = "oldconfig"; |
1619 | } | |
1620 | ||
5c42fc5b SR |
1621 | # old config can ask questions |
1622 | if ($type eq "oldconfig") { | |
9386c6ab | 1623 | $type = "oldnoconfig"; |
75c3fda7 SR |
1624 | |
1625 | # allow for empty configs | |
51ad1dd1 | 1626 | run_command "touch $output_config"; |
75c3fda7 | 1627 | |
13488231 AJ |
1628 | if (!$noclean) { |
1629 | run_command "mv $output_config $outputdir/config_temp" or | |
1630 | dodie "moving .config"; | |
2545eb61 | 1631 | |
13488231 | 1632 | run_command "$make mrproper" or dodie "make mrproper"; |
2545eb61 | 1633 | |
13488231 AJ |
1634 | run_command "mv $outputdir/config_temp $output_config" or |
1635 | dodie "moving config_temp"; | |
1636 | } | |
5c42fc5b SR |
1637 | |
1638 | } elsif (!$noclean) { | |
51ad1dd1 | 1639 | unlink "$output_config"; |
5f9b6ced | 1640 | run_command "$make mrproper" or |
5c42fc5b | 1641 | dodie "make mrproper"; |
5c42fc5b | 1642 | } |
2545eb61 SR |
1643 | |
1644 | # add something to distinguish this build | |
a75fecec SR |
1645 | open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file"); |
1646 | print OUT "$localversion\n"; | |
2545eb61 SR |
1647 | close(OUT); |
1648 | ||
5f9b6ced | 1649 | if (defined($minconfig)) { |
fcb3f16a | 1650 | load_force_config($minconfig); |
2545eb61 SR |
1651 | } |
1652 | ||
fcb3f16a SR |
1653 | if ($type ne "oldnoconfig") { |
1654 | run_command "$make $type" or | |
612b9e9b SR |
1655 | dodie "failed make config"; |
1656 | } | |
fcb3f16a SR |
1657 | # Run old config regardless, to enforce min configurations |
1658 | make_oldconfig; | |
2545eb61 | 1659 | |
a75fecec | 1660 | $redirect = "$buildlog"; |
0bd6c1a3 SR |
1661 | my $build_ret = run_command "$make $build_options"; |
1662 | undef $redirect; | |
1663 | ||
1664 | if (defined($post_build)) { | |
1665 | my $ret = run_command $post_build; | |
1666 | if (!$ret && defined($post_build_die) && | |
1667 | $post_build_die) { | |
1668 | dodie "failed to post_build\n"; | |
1669 | } | |
1670 | } | |
1671 | ||
1672 | if (!$build_ret) { | |
5f9b6ced | 1673 | # bisect may need this to pass |
4ab1cce5 SR |
1674 | if ($in_bisect) { |
1675 | $no_reboot = $save_no_reboot; | |
1676 | return 0; | |
1677 | } | |
2b7d9b21 | 1678 | fail "failed build" and return 0; |
2545eb61 | 1679 | } |
5f9b6ced | 1680 | |
4ab1cce5 SR |
1681 | $no_reboot = $save_no_reboot; |
1682 | ||
2b7d9b21 | 1683 | return 1; |
2545eb61 SR |
1684 | } |
1685 | ||
75c3fda7 | 1686 | sub halt { |
e48c5293 | 1687 | if (!run_ssh "halt" or defined($power_off)) { |
576f627c SR |
1688 | if (defined($poweroff_after_halt)) { |
1689 | sleep $poweroff_after_halt; | |
1690 | run_command "$power_off"; | |
1691 | } | |
1692 | } else { | |
75c3fda7 | 1693 | # nope? the zap it! |
a75fecec | 1694 | run_command "$power_off"; |
75c3fda7 SR |
1695 | } |
1696 | } | |
1697 | ||
5f9b6ced SR |
1698 | sub success { |
1699 | my ($i) = @_; | |
1700 | ||
e48c5293 SR |
1701 | $successes++; |
1702 | ||
9064af52 SR |
1703 | my $name = ""; |
1704 | ||
1705 | if (defined($test_name)) { | |
1706 | $name = " ($test_name)"; | |
1707 | } | |
1708 | ||
5f9b6ced SR |
1709 | doprint "\n\n*******************************************\n"; |
1710 | doprint "*******************************************\n"; | |
9064af52 | 1711 | doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n"; |
5f9b6ced SR |
1712 | doprint "*******************************************\n"; |
1713 | doprint "*******************************************\n"; | |
1714 | ||
de5b6e3b RV |
1715 | if (defined($store_successes)) { |
1716 | save_logs "success", $store_successes; | |
1717 | } | |
1718 | ||
576f627c | 1719 | if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) { |
a75fecec | 1720 | doprint "Reboot and wait $sleep_time seconds\n"; |
2728be41 | 1721 | reboot $sleep_time; |
5f9b6ced SR |
1722 | } |
1723 | } | |
1724 | ||
c960bb9f SR |
1725 | sub answer_bisect { |
1726 | for (;;) { | |
1727 | doprint "Pass or fail? [p/f]"; | |
1728 | my $ans = <STDIN>; | |
1729 | chomp $ans; | |
1730 | if ($ans eq "p" || $ans eq "P") { | |
1731 | return 1; | |
1732 | } elsif ($ans eq "f" || $ans eq "F") { | |
1733 | return 0; | |
1734 | } else { | |
1735 | print "Please answer 'P' or 'F'\n"; | |
1736 | } | |
1737 | } | |
1738 | } | |
1739 | ||
5a391fbf | 1740 | sub child_run_test { |
7faafbd6 | 1741 | my $failed = 0; |
5a391fbf | 1742 | |
7faafbd6 | 1743 | # child should have no power |
a75fecec SR |
1744 | $reboot_on_error = 0; |
1745 | $poweroff_on_error = 0; | |
1746 | $die_on_failure = 1; | |
7faafbd6 | 1747 | |
a9dd5d63 | 1748 | $redirect = "$testlog"; |
7faafbd6 | 1749 | run_command $run_test or $failed = 1; |
a9dd5d63 RV |
1750 | undef $redirect; |
1751 | ||
5a391fbf SR |
1752 | exit $failed; |
1753 | } | |
1754 | ||
1755 | my $child_done; | |
1756 | ||
1757 | sub child_finished { | |
1758 | $child_done = 1; | |
1759 | } | |
1760 | ||
1761 | sub do_run_test { | |
1762 | my $child_pid; | |
1763 | my $child_exit; | |
5a391fbf SR |
1764 | my $line; |
1765 | my $full_line; | |
1766 | my $bug = 0; | |
5a391fbf | 1767 | |
7faafbd6 | 1768 | wait_for_monitor 1; |
5a391fbf | 1769 | |
7faafbd6 | 1770 | doprint "run test $run_test\n"; |
5a391fbf SR |
1771 | |
1772 | $child_done = 0; | |
1773 | ||
1774 | $SIG{CHLD} = qw(child_finished); | |
1775 | ||
1776 | $child_pid = fork; | |
1777 | ||
1778 | child_run_test if (!$child_pid); | |
1779 | ||
1780 | $full_line = ""; | |
1781 | ||
1782 | do { | |
7faafbd6 | 1783 | $line = wait_for_input($monitor_fp, 1); |
5a391fbf SR |
1784 | if (defined($line)) { |
1785 | ||
1786 | # we are not guaranteed to get a full line | |
1787 | $full_line .= $line; | |
8ea0e063 | 1788 | doprint $line; |
5a391fbf SR |
1789 | |
1790 | if ($full_line =~ /call trace:/i) { | |
1791 | $bug = 1; | |
1792 | } | |
1793 | ||
1794 | if ($full_line =~ /Kernel panic -/) { | |
1795 | $bug = 1; | |
1796 | } | |
1797 | ||
1798 | if ($line =~ /\n/) { | |
1799 | $full_line = ""; | |
1800 | } | |
1801 | } | |
1802 | } while (!$child_done && !$bug); | |
1803 | ||
1804 | if ($bug) { | |
8ea0e063 SR |
1805 | my $failure_start = time; |
1806 | my $now; | |
1807 | do { | |
1808 | $line = wait_for_input($monitor_fp, 1); | |
1809 | if (defined($line)) { | |
1810 | doprint $line; | |
1811 | } | |
1812 | $now = time; | |
1813 | if ($now - $failure_start >= $stop_after_failure) { | |
1814 | last; | |
1815 | } | |
1816 | } while (defined($line)); | |
1817 | ||
5a391fbf SR |
1818 | doprint "Detected kernel crash!\n"; |
1819 | # kill the child with extreme prejudice | |
1820 | kill 9, $child_pid; | |
1821 | } | |
1822 | ||
1823 | waitpid $child_pid, 0; | |
1824 | $child_exit = $?; | |
1825 | ||
5a391fbf | 1826 | if ($bug || $child_exit) { |
2b7d9b21 SR |
1827 | return 0 if $in_bisect; |
1828 | fail "test failed" and return 0; | |
5a391fbf | 1829 | } |
2b7d9b21 | 1830 | return 1; |
5a391fbf SR |
1831 | } |
1832 | ||
a75fecec SR |
1833 | sub run_git_bisect { |
1834 | my ($command) = @_; | |
1835 | ||
1836 | doprint "$command ... "; | |
1837 | ||
1838 | my $output = `$command 2>&1`; | |
1839 | my $ret = $?; | |
1840 | ||
1841 | logit $output; | |
1842 | ||
1843 | if ($ret) { | |
1844 | doprint "FAILED\n"; | |
1845 | dodie "Failed to git bisect"; | |
1846 | } | |
1847 | ||
1848 | doprint "SUCCESS\n"; | |
1849 | if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) { | |
1850 | doprint "$1 [$2]\n"; | |
1851 | } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) { | |
1852 | $bisect_bad = $1; | |
1853 | doprint "Found bad commit... $1\n"; | |
1854 | return 0; | |
1855 | } else { | |
1856 | # we already logged it, just print it now. | |
1857 | print $output; | |
1858 | } | |
1859 | ||
1860 | return 1; | |
1861 | } | |
1862 | ||
c23dca7c SR |
1863 | sub bisect_reboot { |
1864 | doprint "Reboot and sleep $bisect_sleep_time seconds\n"; | |
2728be41 | 1865 | reboot $bisect_sleep_time; |
c23dca7c SR |
1866 | } |
1867 | ||
1868 | # returns 1 on success, 0 on failure, -1 on skip | |
0a05c769 SR |
1869 | sub run_bisect_test { |
1870 | my ($type, $buildtype) = @_; | |
5f9b6ced | 1871 | |
2b7d9b21 | 1872 | my $failed = 0; |
5f9b6ced SR |
1873 | my $result; |
1874 | my $output; | |
1875 | my $ret; | |
1876 | ||
0a05c769 SR |
1877 | $in_bisect = 1; |
1878 | ||
1879 | build $buildtype or $failed = 1; | |
5f9b6ced SR |
1880 | |
1881 | if ($type ne "build") { | |
c23dca7c SR |
1882 | if ($failed && $bisect_skip) { |
1883 | $in_bisect = 0; | |
1884 | return -1; | |
1885 | } | |
7faafbd6 | 1886 | dodie "Failed on build" if $failed; |
5f9b6ced SR |
1887 | |
1888 | # Now boot the box | |
ddf607e5 | 1889 | start_monitor_and_boot or $failed = 1; |
5f9b6ced SR |
1890 | |
1891 | if ($type ne "boot") { | |
c23dca7c SR |
1892 | if ($failed && $bisect_skip) { |
1893 | end_monitor; | |
1894 | bisect_reboot; | |
1895 | $in_bisect = 0; | |
1896 | return -1; | |
1897 | } | |
7faafbd6 | 1898 | dodie "Failed on boot" if $failed; |
5a391fbf | 1899 | |
2b7d9b21 | 1900 | do_run_test or $failed = 1; |
5f9b6ced | 1901 | } |
7faafbd6 | 1902 | end_monitor; |
5f9b6ced SR |
1903 | } |
1904 | ||
1905 | if ($failed) { | |
0a05c769 | 1906 | $result = 0; |
5f9b6ced | 1907 | } else { |
0a05c769 SR |
1908 | $result = 1; |
1909 | } | |
4025bc62 SR |
1910 | |
1911 | # reboot the box to a kernel we can ssh to | |
1912 | if ($type ne "build") { | |
1913 | bisect_reboot; | |
1914 | } | |
0a05c769 SR |
1915 | $in_bisect = 0; |
1916 | ||
1917 | return $result; | |
1918 | } | |
1919 | ||
1920 | sub run_bisect { | |
1921 | my ($type) = @_; | |
1922 | my $buildtype = "oldconfig"; | |
1923 | ||
1924 | # We should have a minconfig to use? | |
1925 | if (defined($minconfig)) { | |
1926 | $buildtype = "useconfig:$minconfig"; | |
5f9b6ced SR |
1927 | } |
1928 | ||
0a05c769 SR |
1929 | my $ret = run_bisect_test $type, $buildtype; |
1930 | ||
c960bb9f SR |
1931 | if ($bisect_manual) { |
1932 | $ret = answer_bisect; | |
1933 | } | |
0a05c769 | 1934 | |
d6ce2a0b SR |
1935 | # Are we looking for where it worked, not failed? |
1936 | if ($reverse_bisect) { | |
0a05c769 | 1937 | $ret = !$ret; |
d6ce2a0b SR |
1938 | } |
1939 | ||
c23dca7c | 1940 | if ($ret > 0) { |
0a05c769 | 1941 | return "good"; |
c23dca7c | 1942 | } elsif ($ret == 0) { |
0a05c769 | 1943 | return "bad"; |
c23dca7c SR |
1944 | } elsif ($bisect_skip) { |
1945 | doprint "HIT A BAD COMMIT ... SKIPPING\n"; | |
1946 | return "skip"; | |
0a05c769 | 1947 | } |
5f9b6ced SR |
1948 | } |
1949 | ||
dad98754 SR |
1950 | sub update_bisect_replay { |
1951 | my $tmp_log = "$tmpdir/ktest_bisect_log"; | |
1952 | run_command "git bisect log > $tmp_log" or | |
1953 | die "can't create bisect log"; | |
1954 | return $tmp_log; | |
1955 | } | |
1956 | ||
5f9b6ced SR |
1957 | sub bisect { |
1958 | my ($i) = @_; | |
1959 | ||
1960 | my $result; | |
1961 | ||
1962 | die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"})); | |
1963 | die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"})); | |
1964 | die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"})); | |
1965 | ||
1966 | my $good = $opt{"BISECT_GOOD[$i]"}; | |
1967 | my $bad = $opt{"BISECT_BAD[$i]"}; | |
1968 | my $type = $opt{"BISECT_TYPE[$i]"}; | |
a75fecec SR |
1969 | my $start = $opt{"BISECT_START[$i]"}; |
1970 | my $replay = $opt{"BISECT_REPLAY[$i]"}; | |
3410f6fd SR |
1971 | my $start_files = $opt{"BISECT_FILES[$i]"}; |
1972 | ||
1973 | if (defined($start_files)) { | |
1974 | $start_files = " -- " . $start_files; | |
1975 | } else { | |
1976 | $start_files = ""; | |
1977 | } | |
5f9b6ced | 1978 | |
a57419b3 SR |
1979 | # convert to true sha1's |
1980 | $good = get_sha1($good); | |
1981 | $bad = get_sha1($bad); | |
1982 | ||
d6ce2a0b SR |
1983 | if (defined($opt{"BISECT_REVERSE[$i]"}) && |
1984 | $opt{"BISECT_REVERSE[$i]"} == 1) { | |
1985 | doprint "Performing a reverse bisect (bad is good, good is bad!)\n"; | |
1986 | $reverse_bisect = 1; | |
1987 | } else { | |
1988 | $reverse_bisect = 0; | |
1989 | } | |
1990 | ||
a75fecec SR |
1991 | # Can't have a test without having a test to run |
1992 | if ($type eq "test" && !defined($run_test)) { | |
1993 | $type = "boot"; | |
1994 | } | |
1995 | ||
dad98754 SR |
1996 | # Check if a bisect was running |
1997 | my $bisect_start_file = "$builddir/.git/BISECT_START"; | |
1998 | ||
a75fecec | 1999 | my $check = $opt{"BISECT_CHECK[$i]"}; |
dad98754 SR |
2000 | my $do_check = defined($check) && $check ne "0"; |
2001 | ||
2002 | if ( -f $bisect_start_file ) { | |
2003 | print "Bisect in progress found\n"; | |
2004 | if ($do_check) { | |
2005 | print " If you say yes, then no checks of good or bad will be done\n"; | |
2006 | } | |
2007 | if (defined($replay)) { | |
2008 | print "** BISECT_REPLAY is defined in config file **"; | |
2009 | print " Ignore config option and perform new git bisect log?\n"; | |
2010 | if (read_ync " (yes, no, or cancel) ") { | |
2011 | $replay = update_bisect_replay; | |
2012 | $do_check = 0; | |
2013 | } | |
2014 | } elsif (read_yn "read git log and continue?") { | |
2015 | $replay = update_bisect_replay; | |
2016 | $do_check = 0; | |
2017 | } | |
2018 | } | |
2019 | ||
2020 | if ($do_check) { | |
a75fecec SR |
2021 | |
2022 | # get current HEAD | |
a57419b3 | 2023 | my $head = get_sha1("HEAD"); |
a75fecec SR |
2024 | |
2025 | if ($check ne "good") { | |
2026 | doprint "TESTING BISECT BAD [$bad]\n"; | |
2027 | run_command "git checkout $bad" or | |
2028 | die "Failed to checkout $bad"; | |
2029 | ||
2030 | $result = run_bisect $type; | |
2031 | ||
2032 | if ($result ne "bad") { | |
2033 | fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0; | |
2034 | } | |
2035 | } | |
2036 | ||
2037 | if ($check ne "bad") { | |
2038 | doprint "TESTING BISECT GOOD [$good]\n"; | |
2039 | run_command "git checkout $good" or | |
2040 | die "Failed to checkout $good"; | |
2041 | ||
2042 | $result = run_bisect $type; | |
2043 | ||
2044 | if ($result ne "good") { | |
2045 | fail "Tested BISECT_GOOD [$good] and it failed" and return 0; | |
2046 | } | |
2047 | } | |
2048 | ||
2049 | # checkout where we started | |
2050 | run_command "git checkout $head" or | |
2051 | die "Failed to checkout $head"; | |
2052 | } | |
2053 | ||
3410f6fd | 2054 | run_command "git bisect start$start_files" or |
a75fecec | 2055 | dodie "could not start bisect"; |
5f9b6ced SR |
2056 | |
2057 | run_command "git bisect good $good" or | |
a75fecec | 2058 | dodie "could not set bisect good to $good"; |
5f9b6ced | 2059 | |
a75fecec SR |
2060 | run_git_bisect "git bisect bad $bad" or |
2061 | dodie "could not set bisect bad to $bad"; | |
5f9b6ced | 2062 | |
a75fecec SR |
2063 | if (defined($replay)) { |
2064 | run_command "git bisect replay $replay" or | |
2065 | dodie "failed to run replay"; | |
5a391fbf SR |
2066 | } |
2067 | ||
a75fecec SR |
2068 | if (defined($start)) { |
2069 | run_command "git checkout $start" or | |
2070 | dodie "failed to checkout $start"; | |
2071 | } | |
2072 | ||
2073 | my $test; | |
5f9b6ced SR |
2074 | do { |
2075 | $result = run_bisect $type; | |
a75fecec SR |
2076 | $test = run_git_bisect "git bisect $result"; |
2077 | } while ($test); | |
5f9b6ced SR |
2078 | |
2079 | run_command "git bisect log" or | |
2080 | dodie "could not capture git bisect log"; | |
2081 | ||
2082 | run_command "git bisect reset" or | |
2083 | dodie "could not reset git bisect"; | |
2084 | ||
2085 | doprint "Bad commit was [$bisect_bad]\n"; | |
2086 | ||
0a05c769 SR |
2087 | success $i; |
2088 | } | |
2089 | ||
2090 | my %config_ignore; | |
2091 | my %config_set; | |
2092 | ||
2093 | my %config_list; | |
2094 | my %null_config; | |
2095 | ||
2096 | my %dependency; | |
2097 | ||
4c4ab120 SR |
2098 | sub assign_configs { |
2099 | my ($hash, $config) = @_; | |
0a05c769 SR |
2100 | |
2101 | open (IN, $config) | |
2102 | or dodie "Failed to read $config"; | |
2103 | ||
2104 | while (<IN>) { | |
9bf71749 | 2105 | if (/^((CONFIG\S*)=.*)/) { |
4c4ab120 | 2106 | ${$hash}{$2} = $1; |
0a05c769 SR |
2107 | } |
2108 | } | |
2109 | ||
2110 | close(IN); | |
2111 | } | |
2112 | ||
4c4ab120 SR |
2113 | sub process_config_ignore { |
2114 | my ($config) = @_; | |
2115 | ||
2116 | assign_configs \%config_ignore, $config; | |
2117 | } | |
2118 | ||
0a05c769 SR |
2119 | sub read_current_config { |
2120 | my ($config_ref) = @_; | |
2121 | ||
2122 | %{$config_ref} = (); | |
2123 | undef %{$config_ref}; | |
2124 | ||
2125 | my @key = keys %{$config_ref}; | |
2126 | if ($#key >= 0) { | |
2127 | print "did not delete!\n"; | |
2128 | exit; | |
2129 | } | |
2130 | open (IN, "$output_config"); | |
2131 | ||
2132 | while (<IN>) { | |
2133 | if (/^(CONFIG\S+)=(.*)/) { | |
2134 | ${$config_ref}{$1} = $2; | |
2135 | } | |
2136 | } | |
2137 | close(IN); | |
2138 | } | |
2139 | ||
2140 | sub get_dependencies { | |
2141 | my ($config) = @_; | |
2142 | ||
2143 | my $arr = $dependency{$config}; | |
2144 | if (!defined($arr)) { | |
2145 | return (); | |
2146 | } | |
2147 | ||
2148 | my @deps = @{$arr}; | |
2149 | ||
2150 | foreach my $dep (@{$arr}) { | |
2151 | print "ADD DEP $dep\n"; | |
2152 | @deps = (@deps, get_dependencies $dep); | |
2153 | } | |
2154 | ||
2155 | return @deps; | |
2156 | } | |
2157 | ||
2158 | sub create_config { | |
2159 | my @configs = @_; | |
2160 | ||
2161 | open(OUT, ">$output_config") or dodie "Can not write to $output_config"; | |
2162 | ||
2163 | foreach my $config (@configs) { | |
2164 | print OUT "$config_set{$config}\n"; | |
2165 | my @deps = get_dependencies $config; | |
2166 | foreach my $dep (@deps) { | |
2167 | print OUT "$config_set{$dep}\n"; | |
2168 | } | |
2169 | } | |
2170 | ||
2171 | foreach my $config (keys %config_ignore) { | |
2172 | print OUT "$config_ignore{$config}\n"; | |
2173 | } | |
2174 | close(OUT); | |
2175 | ||
2176 | # exit; | |
fcb3f16a | 2177 | make_oldconfig; |
0a05c769 SR |
2178 | } |
2179 | ||
2180 | sub compare_configs { | |
2181 | my (%a, %b) = @_; | |
2182 | ||
2183 | foreach my $item (keys %a) { | |
2184 | if (!defined($b{$item})) { | |
2185 | print "diff $item\n"; | |
2186 | return 1; | |
2187 | } | |
2188 | delete $b{$item}; | |
2189 | } | |
2190 | ||
2191 | my @keys = keys %b; | |
2192 | if ($#keys) { | |
2193 | print "diff2 $keys[0]\n"; | |
2194 | } | |
2195 | return -1 if ($#keys >= 0); | |
2196 | ||
2197 | return 0; | |
2198 | } | |
2199 | ||
2200 | sub run_config_bisect_test { | |
2201 | my ($type) = @_; | |
2202 | ||
2203 | return run_bisect_test $type, "oldconfig"; | |
2204 | } | |
2205 | ||
2206 | sub process_passed { | |
2207 | my (%configs) = @_; | |
2208 | ||
2209 | doprint "These configs had no failure: (Enabling them for further compiles)\n"; | |
2210 | # Passed! All these configs are part of a good compile. | |
2211 | # Add them to the min options. | |
2212 | foreach my $config (keys %configs) { | |
2213 | if (defined($config_list{$config})) { | |
2214 | doprint " removing $config\n"; | |
2215 | $config_ignore{$config} = $config_list{$config}; | |
2216 | delete $config_list{$config}; | |
2217 | } | |
2218 | } | |
f1a27850 SR |
2219 | doprint "config copied to $outputdir/config_good\n"; |
2220 | run_command "cp -f $output_config $outputdir/config_good"; | |
0a05c769 SR |
2221 | } |
2222 | ||
2223 | sub process_failed { | |
2224 | my ($config) = @_; | |
2225 | ||
2226 | doprint "\n\n***************************************\n"; | |
2227 | doprint "Found bad config: $config\n"; | |
2228 | doprint "***************************************\n\n"; | |
2229 | } | |
2230 | ||
2231 | sub run_config_bisect { | |
2232 | ||
2233 | my @start_list = keys %config_list; | |
2234 | ||
2235 | if ($#start_list < 0) { | |
2236 | doprint "No more configs to test!!!\n"; | |
2237 | return -1; | |
2238 | } | |
2239 | ||
2240 | doprint "***** RUN TEST ***\n"; | |
2241 | my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"}; | |
2242 | my $ret; | |
2243 | my %current_config; | |
2244 | ||
2245 | my $count = $#start_list + 1; | |
2246 | doprint " $count configs to test\n"; | |
2247 | ||
2248 | my $half = int($#start_list / 2); | |
2249 | ||
2250 | do { | |
2251 | my @tophalf = @start_list[0 .. $half]; | |
2252 | ||
2253 | create_config @tophalf; | |
2254 | read_current_config \%current_config; | |
2255 | ||
2256 | $count = $#tophalf + 1; | |
2257 | doprint "Testing $count configs\n"; | |
2258 | my $found = 0; | |
2259 | # make sure we test something | |
2260 | foreach my $config (@tophalf) { | |
2261 | if (defined($current_config{$config})) { | |
2262 | logit " $config\n"; | |
2263 | $found = 1; | |
2264 | } | |
2265 | } | |
2266 | if (!$found) { | |
2267 | # try the other half | |
2268 | doprint "Top half produced no set configs, trying bottom half\n"; | |
4c8cc55b | 2269 | @tophalf = @start_list[$half + 1 .. $#start_list]; |
0a05c769 SR |
2270 | create_config @tophalf; |
2271 | read_current_config \%current_config; | |
2272 | foreach my $config (@tophalf) { | |
2273 | if (defined($current_config{$config})) { | |
2274 | logit " $config\n"; | |
2275 | $found = 1; | |
2276 | } | |
2277 | } | |
2278 | if (!$found) { | |
2279 | doprint "Failed: Can't make new config with current configs\n"; | |
2280 | foreach my $config (@start_list) { | |
2281 | doprint " CONFIG: $config\n"; | |
2282 | } | |
2283 | return -1; | |
2284 | } | |
2285 | $count = $#tophalf + 1; | |
2286 | doprint "Testing $count configs\n"; | |
2287 | } | |
2288 | ||
2289 | $ret = run_config_bisect_test $type; | |
c960bb9f SR |
2290 | if ($bisect_manual) { |
2291 | $ret = answer_bisect; | |
2292 | } | |
0a05c769 SR |
2293 | if ($ret) { |
2294 | process_passed %current_config; | |
2295 | return 0; | |
2296 | } | |
2297 | ||
2298 | doprint "This config had a failure.\n"; | |
2299 | doprint "Removing these configs that were not set in this config:\n"; | |
f1a27850 SR |
2300 | doprint "config copied to $outputdir/config_bad\n"; |
2301 | run_command "cp -f $output_config $outputdir/config_bad"; | |
0a05c769 SR |
2302 | |
2303 | # A config exists in this group that was bad. | |
2304 | foreach my $config (keys %config_list) { | |
2305 | if (!defined($current_config{$config})) { | |
2306 | doprint " removing $config\n"; | |
2307 | delete $config_list{$config}; | |
2308 | } | |
2309 | } | |
2310 | ||
2311 | @start_list = @tophalf; | |
2312 | ||
2313 | if ($#start_list == 0) { | |
2314 | process_failed $start_list[0]; | |
2315 | return 1; | |
2316 | } | |
2317 | ||
2318 | # remove half the configs we are looking at and see if | |
2319 | # they are good. | |
2320 | $half = int($#start_list / 2); | |
4c8cc55b | 2321 | } while ($#start_list > 0); |
0a05c769 | 2322 | |
c960bb9f SR |
2323 | # we found a single config, try it again unless we are running manually |
2324 | ||
2325 | if ($bisect_manual) { | |
2326 | process_failed $start_list[0]; | |
2327 | return 1; | |
2328 | } | |
2329 | ||
0a05c769 SR |
2330 | my @tophalf = @start_list[0 .. 0]; |
2331 | ||
2332 | $ret = run_config_bisect_test $type; | |
2333 | if ($ret) { | |
2334 | process_passed %current_config; | |
2335 | return 0; | |
2336 | } | |
2337 | ||
2338 | process_failed $start_list[0]; | |
2339 | return 1; | |
2340 | } | |
2341 | ||
2342 | sub config_bisect { | |
2343 | my ($i) = @_; | |
2344 | ||
2345 | my $start_config = $opt{"CONFIG_BISECT[$i]"}; | |
2346 | ||
2347 | my $tmpconfig = "$tmpdir/use_config"; | |
2348 | ||
30f75da5 SR |
2349 | if (defined($config_bisect_good)) { |
2350 | process_config_ignore $config_bisect_good; | |
2351 | } | |
2352 | ||
0a05c769 SR |
2353 | # Make the file with the bad config and the min config |
2354 | if (defined($minconfig)) { | |
2355 | # read the min config for things to ignore | |
2356 | run_command "cp $minconfig $tmpconfig" or | |
2357 | dodie "failed to copy $minconfig to $tmpconfig"; | |
2358 | } else { | |
2359 | unlink $tmpconfig; | |
2360 | } | |
2361 | ||
0a05c769 | 2362 | if (-f $tmpconfig) { |
fcb3f16a | 2363 | load_force_config($tmpconfig); |
0a05c769 SR |
2364 | process_config_ignore $tmpconfig; |
2365 | } | |
2366 | ||
2367 | # now process the start config | |
2368 | run_command "cp $start_config $output_config" or | |
2369 | dodie "failed to copy $start_config to $output_config"; | |
2370 | ||
2371 | # read directly what we want to check | |
2372 | my %config_check; | |
2373 | open (IN, $output_config) | |
2374 | or dodie "faied to open $output_config"; | |
2375 | ||
2376 | while (<IN>) { | |
2377 | if (/^((CONFIG\S*)=.*)/) { | |
2378 | $config_check{$2} = $1; | |
2379 | } | |
2380 | } | |
2381 | close(IN); | |
2382 | ||
250bae8b | 2383 | # Now run oldconfig with the minconfig |
fcb3f16a | 2384 | make_oldconfig; |
0a05c769 SR |
2385 | |
2386 | # check to see what we lost (or gained) | |
2387 | open (IN, $output_config) | |
2388 | or dodie "Failed to read $start_config"; | |
2389 | ||
2390 | my %removed_configs; | |
2391 | my %added_configs; | |
2392 | ||
2393 | while (<IN>) { | |
2394 | if (/^((CONFIG\S*)=.*)/) { | |
2395 | # save off all options | |
2396 | $config_set{$2} = $1; | |
2397 | if (defined($config_check{$2})) { | |
2398 | if (defined($config_ignore{$2})) { | |
2399 | $removed_configs{$2} = $1; | |
2400 | } else { | |
2401 | $config_list{$2} = $1; | |
2402 | } | |
2403 | } elsif (!defined($config_ignore{$2})) { | |
2404 | $added_configs{$2} = $1; | |
2405 | $config_list{$2} = $1; | |
2406 | } | |
2407 | } | |
2408 | } | |
2409 | close(IN); | |
2410 | ||
2411 | my @confs = keys %removed_configs; | |
2412 | if ($#confs >= 0) { | |
2413 | doprint "Configs overridden by default configs and removed from check:\n"; | |
2414 | foreach my $config (@confs) { | |
2415 | doprint " $config\n"; | |
2416 | } | |
2417 | } | |
2418 | @confs = keys %added_configs; | |
2419 | if ($#confs >= 0) { | |
2420 | doprint "Configs appearing in make oldconfig and added:\n"; | |
2421 | foreach my $config (@confs) { | |
2422 | doprint " $config\n"; | |
2423 | } | |
2424 | } | |
2425 | ||
2426 | my %config_test; | |
2427 | my $once = 0; | |
2428 | ||
2429 | # Sometimes kconfig does weird things. We must make sure | |
2430 | # that the config we autocreate has everything we need | |
2431 | # to test, otherwise we may miss testing configs, or | |
2432 | # may not be able to create a new config. | |
2433 | # Here we create a config with everything set. | |
2434 | create_config (keys %config_list); | |
2435 | read_current_config \%config_test; | |
2436 | foreach my $config (keys %config_list) { | |
2437 | if (!defined($config_test{$config})) { | |
2438 | if (!$once) { | |
2439 | $once = 1; | |
2440 | doprint "Configs not produced by kconfig (will not be checked):\n"; | |
2441 | } | |
2442 | doprint " $config\n"; | |
2443 | delete $config_list{$config}; | |
2444 | } | |
2445 | } | |
2446 | my $ret; | |
2447 | do { | |
2448 | $ret = run_config_bisect; | |
2449 | } while (!$ret); | |
2450 | ||
2451 | return $ret if ($ret < 0); | |
5f9b6ced SR |
2452 | |
2453 | success $i; | |
2454 | } | |
2455 | ||
27d934b2 SR |
2456 | sub patchcheck_reboot { |
2457 | doprint "Reboot and sleep $patchcheck_sleep_time seconds\n"; | |
2728be41 | 2458 | reboot $patchcheck_sleep_time; |
27d934b2 SR |
2459 | } |
2460 | ||
6c5ee0be SR |
2461 | sub patchcheck { |
2462 | my ($i) = @_; | |
2463 | ||
2464 | die "PATCHCHECK_START[$i] not defined\n" | |
2465 | if (!defined($opt{"PATCHCHECK_START[$i]"})); | |
2466 | die "PATCHCHECK_TYPE[$i] not defined\n" | |
2467 | if (!defined($opt{"PATCHCHECK_TYPE[$i]"})); | |
2468 | ||
2469 | my $start = $opt{"PATCHCHECK_START[$i]"}; | |
2470 | ||
2471 | my $end = "HEAD"; | |
2472 | if (defined($opt{"PATCHCHECK_END[$i]"})) { | |
2473 | $end = $opt{"PATCHCHECK_END[$i]"}; | |
2474 | } | |
2475 | ||
a57419b3 SR |
2476 | # Get the true sha1's since we can use things like HEAD~3 |
2477 | $start = get_sha1($start); | |
2478 | $end = get_sha1($end); | |
2479 | ||
6c5ee0be SR |
2480 | my $type = $opt{"PATCHCHECK_TYPE[$i]"}; |
2481 | ||
2482 | # Can't have a test without having a test to run | |
2483 | if ($type eq "test" && !defined($run_test)) { | |
2484 | $type = "boot"; | |
2485 | } | |
2486 | ||
2487 | open (IN, "git log --pretty=oneline $end|") or | |
2488 | dodie "could not get git list"; | |
2489 | ||
2490 | my @list; | |
2491 | ||
2492 | while (<IN>) { | |
2493 | chomp; | |
2494 | $list[$#list+1] = $_; | |
2495 | last if (/^$start/); | |
2496 | } | |
2497 | close(IN); | |
2498 | ||
2499 | if ($list[$#list] !~ /^$start/) { | |
2b7d9b21 | 2500 | fail "SHA1 $start not found"; |
6c5ee0be SR |
2501 | } |
2502 | ||
2503 | # go backwards in the list | |
2504 | @list = reverse @list; | |
2505 | ||
2506 | my $save_clean = $noclean; | |
1990207d SR |
2507 | my %ignored_warnings; |
2508 | ||
2509 | if (defined($ignore_warnings)) { | |
2510 | foreach my $sha1 (split /\s+/, $ignore_warnings) { | |
2511 | $ignored_warnings{$sha1} = 1; | |
2512 | } | |
2513 | } | |
6c5ee0be SR |
2514 | |
2515 | $in_patchcheck = 1; | |
2516 | foreach my $item (@list) { | |
2517 | my $sha1 = $item; | |
2518 | $sha1 =~ s/^([[:xdigit:]]+).*/$1/; | |
2519 | ||
2520 | doprint "\nProcessing commit $item\n\n"; | |
2521 | ||
2522 | run_command "git checkout $sha1" or | |
2523 | die "Failed to checkout $sha1"; | |
2524 | ||
2525 | # only clean on the first and last patch | |
2526 | if ($item eq $list[0] || | |
2527 | $item eq $list[$#list]) { | |
2528 | $noclean = $save_clean; | |
2529 | } else { | |
2530 | $noclean = 1; | |
2531 | } | |
2532 | ||
2533 | if (defined($minconfig)) { | |
2b7d9b21 | 2534 | build "useconfig:$minconfig" or return 0; |
6c5ee0be SR |
2535 | } else { |
2536 | # ?? no config to use? | |
2b7d9b21 | 2537 | build "oldconfig" or return 0; |
6c5ee0be SR |
2538 | } |
2539 | ||
1990207d SR |
2540 | |
2541 | if (!defined($ignored_warnings{$sha1})) { | |
2542 | check_buildlog $sha1 or return 0; | |
2543 | } | |
6c5ee0be SR |
2544 | |
2545 | next if ($type eq "build"); | |
2546 | ||
7faafbd6 SR |
2547 | my $failed = 0; |
2548 | ||
ddf607e5 | 2549 | start_monitor_and_boot or $failed = 1; |
7faafbd6 SR |
2550 | |
2551 | if (!$failed && $type ne "boot"){ | |
2552 | do_run_test or $failed = 1; | |
2553 | } | |
2554 | end_monitor; | |
2555 | return 0 if ($failed); | |
2556 | ||
27d934b2 SR |
2557 | patchcheck_reboot; |
2558 | ||
6c5ee0be SR |
2559 | } |
2560 | $in_patchcheck = 0; | |
2561 | success $i; | |
2b7d9b21 SR |
2562 | |
2563 | return 1; | |
6c5ee0be SR |
2564 | } |
2565 | ||
b9066f6c | 2566 | my %depends; |
ac6974c7 | 2567 | my %depcount; |
b9066f6c SR |
2568 | my $iflevel = 0; |
2569 | my @ifdeps; | |
2570 | ||
2571 | # prevent recursion | |
2572 | my %read_kconfigs; | |
2573 | ||
ac6974c7 SR |
2574 | sub add_dep { |
2575 | # $config depends on $dep | |
2576 | my ($config, $dep) = @_; | |
2577 | ||
2578 | if (defined($depends{$config})) { | |
2579 | $depends{$config} .= " " . $dep; | |
2580 | } else { | |
2581 | $depends{$config} = $dep; | |
2582 | } | |
2583 | ||
2584 | # record the number of configs depending on $dep | |
2585 | if (defined $depcount{$dep}) { | |
2586 | $depcount{$dep}++; | |
2587 | } else { | |
2588 | $depcount{$dep} = 1; | |
2589 | } | |
2590 | } | |
2591 | ||
b9066f6c SR |
2592 | # taken from streamline_config.pl |
2593 | sub read_kconfig { | |
2594 | my ($kconfig) = @_; | |
2595 | ||
2596 | my $state = "NONE"; | |
2597 | my $config; | |
2598 | my @kconfigs; | |
2599 | ||
2600 | my $cont = 0; | |
2601 | my $line; | |
2602 | ||
2603 | ||
2604 | if (! -f $kconfig) { | |
2605 | doprint "file $kconfig does not exist, skipping\n"; | |
2606 | return; | |
2607 | } | |
2608 | ||
2609 | open(KIN, "$kconfig") | |
2610 | or die "Can't open $kconfig"; | |
2611 | while (<KIN>) { | |
2612 | chomp; | |
2613 | ||
2614 | # Make sure that lines ending with \ continue | |
2615 | if ($cont) { | |
2616 | $_ = $line . " " . $_; | |
2617 | } | |
2618 | ||
2619 | if (s/\\$//) { | |
2620 | $cont = 1; | |
2621 | $line = $_; | |
2622 | next; | |
2623 | } | |
2624 | ||
2625 | $cont = 0; | |
2626 | ||
2627 | # collect any Kconfig sources | |
2628 | if (/^source\s*"(.*)"/) { | |
2629 | $kconfigs[$#kconfigs+1] = $1; | |
2630 | } | |
2631 | ||
2632 | # configs found | |
2633 | if (/^\s*(menu)?config\s+(\S+)\s*$/) { | |
2634 | $state = "NEW"; | |
2635 | $config = $2; | |
2636 | ||
2637 | for (my $i = 0; $i < $iflevel; $i++) { | |
ac6974c7 | 2638 | add_dep $config, $ifdeps[$i]; |
b9066f6c SR |
2639 | } |
2640 | ||
2641 | # collect the depends for the config | |
2642 | } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) { | |
2643 | ||
ac6974c7 | 2644 | add_dep $config, $1; |
b9066f6c SR |
2645 | |
2646 | # Get the configs that select this config | |
ac6974c7 SR |
2647 | } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) { |
2648 | ||
2649 | # selected by depends on config | |
2650 | add_dep $1, $config; | |
b9066f6c SR |
2651 | |
2652 | # Check for if statements | |
2653 | } elsif (/^if\s+(.*\S)\s*$/) { | |
2654 | my $deps = $1; | |
2655 | # remove beginning and ending non text | |
2656 | $deps =~ s/^[^a-zA-Z0-9_]*//; | |
2657 | $deps =~ s/[^a-zA-Z0-9_]*$//; | |
2658 | ||
2659 | my @deps = split /[^a-zA-Z0-9_]+/, $deps; | |
2660 | ||
2661 | $ifdeps[$iflevel++] = join ':', @deps; | |
2662 | ||
2663 | } elsif (/^endif/) { | |
2664 | ||
2665 | $iflevel-- if ($iflevel); | |
2666 | ||
2667 | # stop on "help" | |
2668 | } elsif (/^\s*help\s*$/) { | |
2669 | $state = "NONE"; | |
2670 | } | |
2671 | } | |
2672 | close(KIN); | |
2673 | ||
2674 | # read in any configs that were found. | |
2675 | foreach $kconfig (@kconfigs) { | |
2676 | if (!defined($read_kconfigs{$kconfig})) { | |
2677 | $read_kconfigs{$kconfig} = 1; | |
2678 | read_kconfig("$builddir/$kconfig"); | |
2679 | } | |
2680 | } | |
2681 | } | |
2682 | ||
2683 | sub read_depends { | |
2684 | # find out which arch this is by the kconfig file | |
2685 | open (IN, $output_config) | |
2686 | or dodie "Failed to read $output_config"; | |
2687 | my $arch; | |
2688 | while (<IN>) { | |
2689 | if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) { | |
2690 | $arch = $1; | |
2691 | last; | |
2692 | } | |
2693 | } | |
2694 | close IN; | |
2695 | ||
2696 | if (!defined($arch)) { | |
2697 | doprint "Could not find arch from config file\n"; | |
2698 | doprint "no dependencies used\n"; | |
2699 | return; | |
2700 | } | |
2701 | ||
2702 | # arch is really the subarch, we need to know | |
2703 | # what directory to look at. | |
2704 | if ($arch eq "i386" || $arch eq "x86_64") { | |
2705 | $arch = "x86"; | |
2706 | } elsif ($arch =~ /^tile/) { | |
2707 | $arch = "tile"; | |
2708 | } | |
2709 | ||
2710 | my $kconfig = "$builddir/arch/$arch/Kconfig"; | |
2711 | ||
2712 | if (! -f $kconfig && $arch =~ /\d$/) { | |
2713 | my $orig = $arch; | |
2714 | # some subarchs have numbers, truncate them | |
2715 | $arch =~ s/\d*$//; | |
2716 | $kconfig = "$builddir/arch/$arch/Kconfig"; | |
2717 | if (! -f $kconfig) { | |
2718 | doprint "No idea what arch dir $orig is for\n"; | |
2719 | doprint "no dependencies used\n"; | |
2720 | return; | |
2721 | } | |
2722 | } | |
2723 | ||
2724 | read_kconfig($kconfig); | |
2725 | } | |
2726 | ||
4c4ab120 SR |
2727 | sub read_config_list { |
2728 | my ($config) = @_; | |
2729 | ||
2730 | open (IN, $config) | |
2731 | or dodie "Failed to read $config"; | |
2732 | ||
2733 | while (<IN>) { | |
2734 | if (/^((CONFIG\S*)=.*)/) { | |
2735 | if (!defined($config_ignore{$2})) { | |
2736 | $config_list{$2} = $1; | |
2737 | } | |
2738 | } | |
2739 | } | |
2740 | ||
2741 | close(IN); | |
2742 | } | |
2743 | ||
2744 | sub read_output_config { | |
2745 | my ($config) = @_; | |
2746 | ||
2747 | assign_configs \%config_ignore, $config; | |
2748 | } | |
2749 | ||
2750 | sub make_new_config { | |
2751 | my @configs = @_; | |
2752 | ||
2753 | open (OUT, ">$output_config") | |
2754 | or dodie "Failed to write $output_config"; | |
2755 | ||
2756 | foreach my $config (@configs) { | |
2757 | print OUT "$config\n"; | |
2758 | } | |
2759 | close OUT; | |
2760 | } | |
2761 | ||
ac6974c7 SR |
2762 | sub chomp_config { |
2763 | my ($config) = @_; | |
2764 | ||
2765 | $config =~ s/CONFIG_//; | |
2766 | ||
2767 | return $config; | |
2768 | } | |
2769 | ||
b9066f6c SR |
2770 | sub get_depends { |
2771 | my ($dep) = @_; | |
2772 | ||
ac6974c7 | 2773 | my $kconfig = chomp_config $dep; |
b9066f6c SR |
2774 | |
2775 | $dep = $depends{"$kconfig"}; | |
2776 | ||
2777 | # the dep string we have saves the dependencies as they | |
2778 | # were found, including expressions like ! && ||. We | |
2779 | # want to split this out into just an array of configs. | |
2780 | ||
2781 | my $valid = "A-Za-z_0-9"; | |
2782 | ||
2783 | my @configs; | |
2784 | ||
2785 | while ($dep =~ /[$valid]/) { | |
2786 | ||
2787 | if ($dep =~ /^[^$valid]*([$valid]+)/) { | |
2788 | my $conf = "CONFIG_" . $1; | |
2789 | ||
2790 | $configs[$#configs + 1] = $conf; | |
2791 | ||
2792 | $dep =~ s/^[^$valid]*[$valid]+//; | |
2793 | } else { | |
2794 | die "this should never happen"; | |
2795 | } | |
2796 | } | |
2797 | ||
2798 | return @configs; | |
2799 | } | |
2800 | ||
2801 | my %min_configs; | |
2802 | my %keep_configs; | |
43d1b651 | 2803 | my %save_configs; |
b9066f6c SR |
2804 | my %processed_configs; |
2805 | my %nochange_config; | |
2806 | ||
2807 | sub test_this_config { | |
2808 | my ($config) = @_; | |
2809 | ||
2810 | my $found; | |
2811 | ||
2812 | # if we already processed this config, skip it | |
2813 | if (defined($processed_configs{$config})) { | |
2814 | return undef; | |
2815 | } | |
2816 | $processed_configs{$config} = 1; | |
2817 | ||
2818 | # if this config failed during this round, skip it | |
2819 | if (defined($nochange_config{$config})) { | |
2820 | return undef; | |
2821 | } | |
2822 | ||
ac6974c7 | 2823 | my $kconfig = chomp_config $config; |
b9066f6c SR |
2824 | |
2825 | # Test dependencies first | |
2826 | if (defined($depends{"$kconfig"})) { | |
2827 | my @parents = get_depends $config; | |
2828 | foreach my $parent (@parents) { | |
2829 | # if the parent is in the min config, check it first | |
2830 | next if (!defined($min_configs{$parent})); | |
2831 | $found = test_this_config($parent); | |
2832 | if (defined($found)) { | |
2833 | return $found; | |
2834 | } | |
2835 | } | |
2836 | } | |
2837 | ||
2838 | # Remove this config from the list of configs | |
2839 | # do a make oldnoconfig and then read the resulting | |
2840 | # .config to make sure it is missing the config that | |
2841 | # we had before | |
2842 | my %configs = %min_configs; | |
2843 | delete $configs{$config}; | |
2844 | make_new_config ((values %configs), (values %keep_configs)); | |
2845 | make_oldconfig; | |
2846 | undef %configs; | |
2847 | assign_configs \%configs, $output_config; | |
2848 | ||
2849 | return $config if (!defined($configs{$config})); | |
2850 | ||
2851 | doprint "disabling config $config did not change .config\n"; | |
2852 | ||
2853 | $nochange_config{$config} = 1; | |
2854 | ||
2855 | return undef; | |
2856 | } | |
2857 | ||
4c4ab120 SR |
2858 | sub make_min_config { |
2859 | my ($i) = @_; | |
2860 | ||
2861 | if (!defined($output_minconfig)) { | |
2862 | fail "OUTPUT_MIN_CONFIG not defined" and return; | |
2863 | } | |
35ce5952 SR |
2864 | |
2865 | # If output_minconfig exists, and the start_minconfig | |
2866 | # came from min_config, than ask if we should use | |
2867 | # that instead. | |
2868 | if (-f $output_minconfig && !$start_minconfig_defined) { | |
2869 | print "$output_minconfig exists\n"; | |
2870 | if (read_yn " Use it as minconfig?") { | |
2871 | $start_minconfig = $output_minconfig; | |
2872 | } | |
2873 | } | |
2874 | ||
4c4ab120 SR |
2875 | if (!defined($start_minconfig)) { |
2876 | fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return; | |
2877 | } | |
2878 | ||
35ce5952 SR |
2879 | my $temp_config = "$tmpdir/temp_config"; |
2880 | ||
4c4ab120 SR |
2881 | # First things first. We build an allnoconfig to find |
2882 | # out what the defaults are that we can't touch. | |
2883 | # Some are selections, but we really can't handle selections. | |
2884 | ||
2885 | my $save_minconfig = $minconfig; | |
2886 | undef $minconfig; | |
2887 | ||
2888 | run_command "$make allnoconfig" or return 0; | |
2889 | ||
b9066f6c SR |
2890 | read_depends; |
2891 | ||
4c4ab120 | 2892 | process_config_ignore $output_config; |
b9066f6c | 2893 | |
43d1b651 | 2894 | undef %save_configs; |
b9066f6c | 2895 | undef %min_configs; |
4c4ab120 SR |
2896 | |
2897 | if (defined($ignore_config)) { | |
2898 | # make sure the file exists | |
2899 | `touch $ignore_config`; | |
43d1b651 | 2900 | assign_configs \%save_configs, $ignore_config; |
4c4ab120 SR |
2901 | } |
2902 | ||
43d1b651 SR |
2903 | %keep_configs = %save_configs; |
2904 | ||
4c4ab120 SR |
2905 | doprint "Load initial configs from $start_minconfig\n"; |
2906 | ||
2907 | # Look at the current min configs, and save off all the | |
2908 | # ones that were set via the allnoconfig | |
4c4ab120 SR |
2909 | assign_configs \%min_configs, $start_minconfig; |
2910 | ||
2911 | my @config_keys = keys %min_configs; | |
2912 | ||
ac6974c7 SR |
2913 | # All configs need a depcount |
2914 | foreach my $config (@config_keys) { | |
2915 | my $kconfig = chomp_config $config; | |
2916 | if (!defined $depcount{$kconfig}) { | |
2917 | $depcount{$kconfig} = 0; | |
2918 | } | |
2919 | } | |
2920 | ||
4c4ab120 SR |
2921 | # Remove anything that was set by the make allnoconfig |
2922 | # we shouldn't need them as they get set for us anyway. | |
2923 | foreach my $config (@config_keys) { | |
2924 | # Remove anything in the ignore_config | |
2925 | if (defined($keep_configs{$config})) { | |
2926 | my $file = $ignore_config; | |
2927 | $file =~ s,.*/(.*?)$,$1,; | |
2928 | doprint "$config set by $file ... ignored\n"; | |
2929 | delete $min_configs{$config}; | |
2930 | next; | |
2931 | } | |
2932 | # But make sure the settings are the same. If a min config | |
2933 | # sets a selection, we do not want to get rid of it if | |
2934 | # it is not the same as what we have. Just move it into | |
2935 | # the keep configs. | |
2936 | if (defined($config_ignore{$config})) { | |
2937 | if ($config_ignore{$config} ne $min_configs{$config}) { | |
2938 | doprint "$config is in allnoconfig as '$config_ignore{$config}'"; | |
2939 | doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n"; | |
2940 | $keep_configs{$config} = $min_configs{$config}; | |
2941 | } else { | |
2942 | doprint "$config set by allnoconfig ... ignored\n"; | |
2943 | } | |
2944 | delete $min_configs{$config}; | |
2945 | } | |
2946 | } | |
2947 | ||
4c4ab120 | 2948 | my $done = 0; |
b9066f6c | 2949 | my $take_two = 0; |
4c4ab120 SR |
2950 | |
2951 | while (!$done) { | |
2952 | ||
2953 | my $config; | |
2954 | my $found; | |
2955 | ||
2956 | # Now disable each config one by one and do a make oldconfig | |
2957 | # till we find a config that changes our list. | |
2958 | ||
4c4ab120 | 2959 | my @test_configs = keys %min_configs; |
ac6974c7 SR |
2960 | |
2961 | # Sort keys by who is most dependent on | |
2962 | @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} } | |
2963 | @test_configs ; | |
2964 | ||
2965 | # Put configs that did not modify the config at the end. | |
4c4ab120 SR |
2966 | my $reset = 1; |
2967 | for (my $i = 0; $i < $#test_configs; $i++) { | |
2968 | if (!defined($nochange_config{$test_configs[0]})) { | |
2969 | $reset = 0; | |
2970 | last; | |
2971 | } | |
2972 | # This config didn't change the .config last time. | |
2973 | # Place it at the end | |
2974 | my $config = shift @test_configs; | |
2975 | push @test_configs, $config; | |
2976 | } | |
2977 | ||
2978 | # if every test config has failed to modify the .config file | |
2979 | # in the past, then reset and start over. | |
2980 | if ($reset) { | |
2981 | undef %nochange_config; | |
2982 | } | |
2983 | ||
b9066f6c SR |
2984 | undef %processed_configs; |
2985 | ||
4c4ab120 SR |
2986 | foreach my $config (@test_configs) { |
2987 | ||
b9066f6c | 2988 | $found = test_this_config $config; |
4c4ab120 | 2989 | |
b9066f6c | 2990 | last if (defined($found)); |
4c4ab120 SR |
2991 | |
2992 | # oh well, try another config | |
4c4ab120 SR |
2993 | } |
2994 | ||
2995 | if (!defined($found)) { | |
b9066f6c SR |
2996 | # we could have failed due to the nochange_config hash |
2997 | # reset and try again | |
2998 | if (!$take_two) { | |
2999 | undef %nochange_config; | |
3000 | $take_two = 1; | |
3001 | next; | |
3002 | } | |
4c4ab120 SR |
3003 | doprint "No more configs found that we can disable\n"; |
3004 | $done = 1; | |
3005 | last; | |
3006 | } | |
b9066f6c | 3007 | $take_two = 0; |
4c4ab120 SR |
3008 | |
3009 | $config = $found; | |
3010 | ||
3011 | doprint "Test with $config disabled\n"; | |
3012 | ||
3013 | # set in_bisect to keep build and monitor from dieing | |
3014 | $in_bisect = 1; | |
3015 | ||
3016 | my $failed = 0; | |
3017 | build "oldconfig"; | |
3018 | start_monitor_and_boot or $failed = 1; | |
3019 | end_monitor; | |
3020 | ||
3021 | $in_bisect = 0; | |
3022 | ||
3023 | if ($failed) { | |
b9066f6c | 3024 | doprint "$min_configs{$config} is needed to boot the box... keeping\n"; |
4c4ab120 SR |
3025 | # this config is needed, add it to the ignore list. |
3026 | $keep_configs{$config} = $min_configs{$config}; | |
43d1b651 | 3027 | $save_configs{$config} = $min_configs{$config}; |
4c4ab120 | 3028 | delete $min_configs{$config}; |
35ce5952 SR |
3029 | |
3030 | # update new ignore configs | |
3031 | if (defined($ignore_config)) { | |
3032 | open (OUT, ">$temp_config") | |
3033 | or die "Can't write to $temp_config"; | |
43d1b651 SR |
3034 | foreach my $config (keys %save_configs) { |
3035 | print OUT "$save_configs{$config}\n"; | |
35ce5952 SR |
3036 | } |
3037 | close OUT; | |
3038 | run_command "mv $temp_config $ignore_config" or | |
3039 | dodie "failed to copy update to $ignore_config"; | |
3040 | } | |
3041 | ||
4c4ab120 SR |
3042 | } else { |
3043 | # We booted without this config, remove it from the minconfigs. | |
3044 | doprint "$config is not needed, disabling\n"; | |
3045 | ||
3046 | delete $min_configs{$config}; | |
3047 | ||
3048 | # Also disable anything that is not enabled in this config | |
3049 | my %configs; | |
3050 | assign_configs \%configs, $output_config; | |
3051 | my @config_keys = keys %min_configs; | |
3052 | foreach my $config (@config_keys) { | |
3053 | if (!defined($configs{$config})) { | |
3054 | doprint "$config is not set, disabling\n"; | |
3055 | delete $min_configs{$config}; | |
3056 | } | |
3057 | } | |
3058 | ||
3059 | # Save off all the current mandidory configs | |
35ce5952 SR |
3060 | open (OUT, ">$temp_config") |
3061 | or die "Can't write to $temp_config"; | |
4c4ab120 SR |
3062 | foreach my $config (keys %keep_configs) { |
3063 | print OUT "$keep_configs{$config}\n"; | |
3064 | } | |
3065 | foreach my $config (keys %min_configs) { | |
3066 | print OUT "$min_configs{$config}\n"; | |
3067 | } | |
3068 | close OUT; | |
35ce5952 SR |
3069 | |
3070 | run_command "mv $temp_config $output_minconfig" or | |
3071 | dodie "failed to copy update to $output_minconfig"; | |
4c4ab120 SR |
3072 | } |
3073 | ||
3074 | doprint "Reboot and wait $sleep_time seconds\n"; | |
2728be41 | 3075 | reboot $sleep_time; |
4c4ab120 SR |
3076 | } |
3077 | ||
3078 | success $i; | |
3079 | return 1; | |
3080 | } | |
3081 | ||
8d1491ba SR |
3082 | $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n"; |
3083 | ||
3084 | if ($#ARGV == 0) { | |
3085 | $ktest_config = $ARGV[0]; | |
3086 | if (! -f $ktest_config) { | |
3087 | print "$ktest_config does not exist.\n"; | |
35ce5952 | 3088 | if (!read_yn "Create it?") { |
8d1491ba SR |
3089 | exit 0; |
3090 | } | |
3091 | } | |
3092 | } else { | |
3093 | $ktest_config = "ktest.conf"; | |
3094 | } | |
3095 | ||
3096 | if (! -f $ktest_config) { | |
c4261d0f | 3097 | get_test_case; |
8d1491ba SR |
3098 | open(OUT, ">$ktest_config") or die "Can not create $ktest_config"; |
3099 | print OUT << "EOF" | |
3100 | # Generated by ktest.pl | |
3101 | # | |
0e7a22de SR |
3102 | |
3103 | # PWD is a ktest.pl variable that will result in the process working | |
3104 | # directory that ktest.pl is executed in. | |
3105 | ||
3106 | # THIS_DIR is automatically assigned the PWD of the path that generated | |
3107 | # the config file. It is best to use this variable when assigning other | |
3108 | # directory paths within this directory. This allows you to easily | |
3109 | # move the test cases to other locations or to other machines. | |
3110 | # | |
3111 | THIS_DIR := $variable{"PWD"} | |
3112 | ||
8d1491ba SR |
3113 | # Define each test with TEST_START |
3114 | # The config options below it will override the defaults | |
3115 | TEST_START | |
c4261d0f | 3116 | TEST_TYPE = $default{"TEST_TYPE"} |
8d1491ba SR |
3117 | |
3118 | DEFAULTS | |
3119 | EOF | |
3120 | ; | |
3121 | close(OUT); | |
3122 | } | |
3123 | read_config $ktest_config; | |
3124 | ||
23715c3c SR |
3125 | if (defined($opt{"LOG_FILE"})) { |
3126 | $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1); | |
3127 | } | |
3128 | ||
8d1491ba SR |
3129 | # Append any configs entered in manually to the config file. |
3130 | my @new_configs = keys %entered_configs; | |
3131 | if ($#new_configs >= 0) { | |
3132 | print "\nAppending entered in configs to $ktest_config\n"; | |
3133 | open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config"; | |
3134 | foreach my $config (@new_configs) { | |
3135 | print OUT "$config = $entered_configs{$config}\n"; | |
0e7a22de | 3136 | $opt{$config} = process_variables($entered_configs{$config}); |
8d1491ba SR |
3137 | } |
3138 | } | |
2545eb61 | 3139 | |
2b7d9b21 SR |
3140 | if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { |
3141 | unlink $opt{"LOG_FILE"}; | |
3142 | } | |
2545eb61 | 3143 | |
2b7d9b21 SR |
3144 | doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; |
3145 | ||
a57419b3 SR |
3146 | for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { |
3147 | ||
3148 | if (!$i) { | |
3149 | doprint "DEFAULT OPTIONS:\n"; | |
3150 | } else { | |
3151 | doprint "\nTEST $i OPTIONS"; | |
3152 | if (defined($repeat_tests{$i})) { | |
3153 | $repeat = $repeat_tests{$i}; | |
3154 | doprint " ITERATE $repeat"; | |
3155 | } | |
3156 | doprint "\n"; | |
3157 | } | |
3158 | ||
3159 | foreach my $option (sort keys %opt) { | |
3160 | ||
3161 | if ($option =~ /\[(\d+)\]$/) { | |
3162 | next if ($i != $1); | |
3163 | } else { | |
3164 | next if ($i); | |
3165 | } | |
3166 | ||
3167 | doprint "$option = $opt{$option}\n"; | |
3168 | } | |
2b7d9b21 | 3169 | } |
2545eb61 | 3170 | |
2a62512b | 3171 | sub __set_test_option { |
5a391fbf | 3172 | my ($name, $i) = @_; |
2545eb61 | 3173 | |
5a391fbf | 3174 | my $option = "$name\[$i\]"; |
5c42fc5b | 3175 | |
5a391fbf SR |
3176 | if (defined($opt{$option})) { |
3177 | return $opt{$option}; | |
5f9b6ced SR |
3178 | } |
3179 | ||
a57419b3 SR |
3180 | foreach my $test (keys %repeat_tests) { |
3181 | if ($i >= $test && | |
3182 | $i < $test + $repeat_tests{$test}) { | |
3183 | $option = "$name\[$test\]"; | |
3184 | if (defined($opt{$option})) { | |
3185 | return $opt{$option}; | |
3186 | } | |
3187 | } | |
3188 | } | |
3189 | ||
5a391fbf SR |
3190 | if (defined($opt{$name})) { |
3191 | return $opt{$name}; | |
2545eb61 SR |
3192 | } |
3193 | ||
5a391fbf SR |
3194 | return undef; |
3195 | } | |
3196 | ||
2a62512b SR |
3197 | sub set_test_option { |
3198 | my ($name, $i) = @_; | |
3199 | ||
3200 | my $option = __set_test_option($name, $i); | |
3201 | return $option if (!defined($option)); | |
3202 | ||
23715c3c | 3203 | return eval_option($option, $i); |
2a62512b SR |
3204 | } |
3205 | ||
5a391fbf | 3206 | # First we need to do is the builds |
a75fecec SR |
3207 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { |
3208 | ||
4ab1cce5 SR |
3209 | # Do not reboot on failing test options |
3210 | $no_reboot = 1; | |
3211 | ||
576f627c SR |
3212 | $iteration = $i; |
3213 | ||
a75fecec SR |
3214 | my $makecmd = set_test_option("MAKE_CMD", $i); |
3215 | ||
3216 | $machine = set_test_option("MACHINE", $i); | |
e48c5293 | 3217 | $ssh_user = set_test_option("SSH_USER", $i); |
a75fecec SR |
3218 | $tmpdir = set_test_option("TMP_DIR", $i); |
3219 | $outputdir = set_test_option("OUTPUT_DIR", $i); | |
3220 | $builddir = set_test_option("BUILD_DIR", $i); | |
3221 | $test_type = set_test_option("TEST_TYPE", $i); | |
3222 | $build_type = set_test_option("BUILD_TYPE", $i); | |
3223 | $build_options = set_test_option("BUILD_OPTIONS", $i); | |
0bd6c1a3 SR |
3224 | $pre_build = set_test_option("PRE_BUILD", $i); |
3225 | $post_build = set_test_option("POST_BUILD", $i); | |
3226 | $pre_build_die = set_test_option("PRE_BUILD_DIE", $i); | |
3227 | $post_build_die = set_test_option("POST_BUILD_DIE", $i); | |
a75fecec | 3228 | $power_cycle = set_test_option("POWER_CYCLE", $i); |
e48c5293 | 3229 | $reboot = set_test_option("REBOOT", $i); |
a75fecec SR |
3230 | $noclean = set_test_option("BUILD_NOCLEAN", $i); |
3231 | $minconfig = set_test_option("MIN_CONFIG", $i); | |
4c4ab120 SR |
3232 | $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i); |
3233 | $start_minconfig = set_test_option("START_MIN_CONFIG", $i); | |
3234 | $ignore_config = set_test_option("IGNORE_CONFIG", $i); | |
a75fecec SR |
3235 | $run_test = set_test_option("TEST", $i); |
3236 | $addconfig = set_test_option("ADD_CONFIG", $i); | |
3237 | $reboot_type = set_test_option("REBOOT_TYPE", $i); | |
3238 | $grub_menu = set_test_option("GRUB_MENU", $i); | |
8b37ca8c | 3239 | $post_install = set_test_option("POST_INSTALL", $i); |
e0a8742e | 3240 | $no_install = set_test_option("NO_INSTALL", $i); |
a75fecec SR |
3241 | $reboot_script = set_test_option("REBOOT_SCRIPT", $i); |
3242 | $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i); | |
3243 | $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i); | |
3244 | $die_on_failure = set_test_option("DIE_ON_FAILURE", $i); | |
3245 | $power_off = set_test_option("POWER_OFF", $i); | |
576f627c SR |
3246 | $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i); |
3247 | $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i); | |
a75fecec SR |
3248 | $sleep_time = set_test_option("SLEEP_TIME", $i); |
3249 | $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); | |
27d934b2 | 3250 | $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i); |
1990207d | 3251 | $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i); |
c960bb9f | 3252 | $bisect_manual = set_test_option("BISECT_MANUAL", $i); |
c23dca7c | 3253 | $bisect_skip = set_test_option("BISECT_SKIP", $i); |
30f75da5 | 3254 | $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i); |
a75fecec | 3255 | $store_failures = set_test_option("STORE_FAILURES", $i); |
de5b6e3b | 3256 | $store_successes = set_test_option("STORE_SUCCESSES", $i); |
9064af52 | 3257 | $test_name = set_test_option("TEST_NAME", $i); |
a75fecec SR |
3258 | $timeout = set_test_option("TIMEOUT", $i); |
3259 | $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i); | |
3260 | $console = set_test_option("CONSOLE", $i); | |
f1a5b962 | 3261 | $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i); |
a75fecec | 3262 | $success_line = set_test_option("SUCCESS_LINE", $i); |
2b803365 | 3263 | $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i); |
1c8a617a SR |
3264 | $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i); |
3265 | $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i); | |
2d01b26a | 3266 | $stop_test_after = set_test_option("STOP_TEST_AFTER", $i); |
a75fecec | 3267 | $build_target = set_test_option("BUILD_TARGET", $i); |
e48c5293 SR |
3268 | $ssh_exec = set_test_option("SSH_EXEC", $i); |
3269 | $scp_to_target = set_test_option("SCP_TO_TARGET", $i); | |
a75fecec SR |
3270 | $target_image = set_test_option("TARGET_IMAGE", $i); |
3271 | $localversion = set_test_option("LOCALVERSION", $i); | |
3272 | ||
35ce5952 SR |
3273 | $start_minconfig_defined = 1; |
3274 | ||
4c4ab120 | 3275 | if (!defined($start_minconfig)) { |
35ce5952 | 3276 | $start_minconfig_defined = 0; |
4c4ab120 SR |
3277 | $start_minconfig = $minconfig; |
3278 | } | |
3279 | ||
a75fecec SR |
3280 | chdir $builddir || die "can't change directory to $builddir"; |
3281 | ||
a908a665 AJ |
3282 | foreach my $dir ($tmpdir, $outputdir) { |
3283 | if (!-d $dir) { | |
3284 | mkpath($dir) or | |
3285 | die "can't create $dir"; | |
3286 | } | |
a75fecec | 3287 | } |
1a5cfce3 | 3288 | |
e48c5293 SR |
3289 | $ENV{"SSH_USER"} = $ssh_user; |
3290 | $ENV{"MACHINE"} = $machine; | |
3291 | ||
a75fecec | 3292 | $buildlog = "$tmpdir/buildlog-$machine"; |
a9dd5d63 | 3293 | $testlog = "$tmpdir/testlog-$machine"; |
a75fecec SR |
3294 | $dmesg = "$tmpdir/dmesg-$machine"; |
3295 | $make = "$makecmd O=$outputdir"; | |
51ad1dd1 | 3296 | $output_config = "$outputdir/.config"; |
a75fecec | 3297 | |
bb8474b1 SR |
3298 | if (!$buildonly) { |
3299 | $target = "$ssh_user\@$machine"; | |
3300 | if ($reboot_type eq "grub") { | |
3301 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); | |
3302 | } elsif (!defined($reboot_script)) { | |
3303 | dodie "REBOOT_SCRIPT not defined" | |
3304 | } | |
a75fecec SR |
3305 | } |
3306 | ||
3307 | my $run_type = $build_type; | |
3308 | if ($test_type eq "patchcheck") { | |
3309 | $run_type = $opt{"PATCHCHECK_TYPE[$i]"}; | |
3310 | } elsif ($test_type eq "bisect") { | |
3311 | $run_type = $opt{"BISECT_TYPE[$i]"}; | |
0a05c769 SR |
3312 | } elsif ($test_type eq "config_bisect") { |
3313 | $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"}; | |
a75fecec SR |
3314 | } |
3315 | ||
4c4ab120 SR |
3316 | if ($test_type eq "make_min_config") { |
3317 | $run_type = ""; | |
3318 | } | |
3319 | ||
a75fecec SR |
3320 | # mistake in config file? |
3321 | if (!defined($run_type)) { | |
3322 | $run_type = "ERROR"; | |
3323 | } | |
5a391fbf | 3324 | |
e0a8742e SR |
3325 | my $installme = ""; |
3326 | $installme = " no_install" if ($no_install); | |
3327 | ||
2545eb61 | 3328 | doprint "\n\n"; |
e0a8742e | 3329 | doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n"; |
7faafbd6 SR |
3330 | |
3331 | unlink $dmesg; | |
3332 | unlink $buildlog; | |
a9dd5d63 | 3333 | unlink $testlog; |
2545eb61 | 3334 | |
250bae8b SR |
3335 | if (defined($addconfig)) { |
3336 | my $min = $minconfig; | |
3337 | if (!defined($minconfig)) { | |
3338 | $min = ""; | |
3339 | } | |
3340 | run_command "cat $addconfig $min > $tmpdir/add_config" or | |
2b7d9b21 | 3341 | dodie "Failed to create temp config"; |
9be2e6b5 | 3342 | $minconfig = "$tmpdir/add_config"; |
2b7d9b21 SR |
3343 | } |
3344 | ||
6c5ee0be SR |
3345 | my $checkout = $opt{"CHECKOUT[$i]"}; |
3346 | if (defined($checkout)) { | |
3347 | run_command "git checkout $checkout" or | |
3348 | die "failed to checkout $checkout"; | |
3349 | } | |
3350 | ||
4ab1cce5 SR |
3351 | $no_reboot = 0; |
3352 | ||
3353 | ||
a75fecec | 3354 | if ($test_type eq "bisect") { |
5f9b6ced SR |
3355 | bisect $i; |
3356 | next; | |
0a05c769 SR |
3357 | } elsif ($test_type eq "config_bisect") { |
3358 | config_bisect $i; | |
3359 | next; | |
a75fecec | 3360 | } elsif ($test_type eq "patchcheck") { |
6c5ee0be SR |
3361 | patchcheck $i; |
3362 | next; | |
4c4ab120 SR |
3363 | } elsif ($test_type eq "make_min_config") { |
3364 | make_min_config $i; | |
3365 | next; | |
2545eb61 | 3366 | } |
2545eb61 | 3367 | |
7faafbd6 SR |
3368 | if ($build_type ne "nobuild") { |
3369 | build $build_type or next; | |
2545eb61 SR |
3370 | } |
3371 | ||
cd8e368f SR |
3372 | if ($test_type eq "install") { |
3373 | get_version; | |
3374 | install; | |
3375 | success $i; | |
3376 | next; | |
3377 | } | |
3378 | ||
a75fecec | 3379 | if ($test_type ne "build") { |
a75fecec | 3380 | my $failed = 0; |
ddf607e5 | 3381 | start_monitor_and_boot or $failed = 1; |
a75fecec SR |
3382 | |
3383 | if (!$failed && $test_type ne "boot" && defined($run_test)) { | |
3384 | do_run_test or $failed = 1; | |
3385 | } | |
3386 | end_monitor; | |
3387 | next if ($failed); | |
5a391fbf SR |
3388 | } |
3389 | ||
5f9b6ced | 3390 | success $i; |
2545eb61 SR |
3391 | } |
3392 | ||
5c42fc5b | 3393 | if ($opt{"POWEROFF_ON_SUCCESS"}) { |
75c3fda7 | 3394 | halt; |
576f627c | 3395 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) { |
75c3fda7 | 3396 | reboot; |
5c42fc5b | 3397 | } |
75c3fda7 | 3398 | |
e48c5293 SR |
3399 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; |
3400 | ||
2545eb61 | 3401 | exit 0; |