Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 2 | # |
Uwe Kleine-König | cce1dac | 2011-01-24 21:12:01 +0100 | [diff] [blame] | 3 | # Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc. |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 4 | # Licensed under the terms of the GNU GPL License version 2 |
| 5 | # |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 6 | |
| 7 | use strict; |
| 8 | use IPC::Open2; |
| 9 | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 10 | use File::Path qw(mkpath); |
| 11 | use File::Copy qw(cp); |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 12 | use FileHandle; |
| 13 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 14 | my $VERSION = "0.2"; |
| 15 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 16 | $| = 1; |
| 17 | |
| 18 | my %opt; |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 19 | my %repeat_tests; |
| 20 | my %repeats; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 21 | my %default; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 22 | |
| 23 | #default opts |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 24 | $default{"NUM_TESTS"} = 1; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 25 | $default{"REBOOT_TYPE"} = "grub"; |
| 26 | $default{"TEST_TYPE"} = "test"; |
| 27 | $default{"BUILD_TYPE"} = "randconfig"; |
| 28 | $default{"MAKE_CMD"} = "make"; |
| 29 | $default{"TIMEOUT"} = 120; |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 30 | $default{"TMP_DIR"} = "/tmp/ktest"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 31 | $default{"SLEEP_TIME"} = 60; # sleep time between tests |
| 32 | $default{"BUILD_NOCLEAN"} = 0; |
| 33 | $default{"REBOOT_ON_ERROR"} = 0; |
| 34 | $default{"POWEROFF_ON_ERROR"} = 0; |
| 35 | $default{"REBOOT_ON_SUCCESS"} = 1; |
| 36 | $default{"POWEROFF_ON_SUCCESS"} = 0; |
| 37 | $default{"BUILD_OPTIONS"} = ""; |
| 38 | $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects |
Steven Rostedt | 27d934b | 2011-05-20 09:18:18 -0400 | [diff] [blame] | 39 | $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 40 | $default{"CLEAR_LOG"} = 0; |
Steven Rostedt | c960bb9 | 2011-03-08 09:22:39 -0500 | [diff] [blame] | 41 | $default{"BISECT_MANUAL"} = 0; |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 42 | $default{"BISECT_SKIP"} = 1; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 43 | $default{"SUCCESS_LINE"} = "login:"; |
Steven Rostedt | f1a5b96 | 2011-06-13 10:30:00 -0400 | [diff] [blame] | 44 | $default{"DETECT_TRIPLE_FAULT"} = 1; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 45 | $default{"BOOTED_TIMEOUT"} = 1; |
| 46 | $default{"DIE_ON_FAILURE"} = 1; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 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"; |
Steven Rostedt | 1c8a617 | 2010-11-09 12:55:40 -0500 | [diff] [blame] | 50 | $default{"STOP_AFTER_SUCCESS"} = 10; |
| 51 | $default{"STOP_AFTER_FAILURE"} = 60; |
Steven Rostedt | 2d01b26 | 2011-03-08 09:47:54 -0500 | [diff] [blame] | 52 | $default{"STOP_TEST_AFTER"} = 600; |
Steven Rostedt | 8d1491b | 2010-11-18 15:39:48 -0500 | [diff] [blame] | 53 | $default{"LOCALVERSION"} = "-test"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 54 | |
Steven Rostedt | 8d1491b | 2010-11-18 15:39:48 -0500 | [diff] [blame] | 55 | my $ktest_config; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 56 | my $version; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 57 | my $machine; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 58 | my $ssh_user; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 59 | my $tmpdir; |
| 60 | my $builddir; |
| 61 | my $outputdir; |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 62 | my $output_config; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 63 | my $test_type; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 64 | my $build_type; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 65 | my $build_options; |
| 66 | my $reboot_type; |
| 67 | my $reboot_script; |
| 68 | my $power_cycle; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 69 | my $reboot; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 70 | my $reboot_on_error; |
| 71 | my $poweroff_on_error; |
| 72 | my $die_on_failure; |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 73 | my $powercycle_after_reboot; |
| 74 | my $poweroff_after_halt; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 75 | my $ssh_exec; |
| 76 | my $scp_to_target; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 77 | my $power_off; |
| 78 | my $grub_menu; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 79 | my $grub_number; |
| 80 | my $target; |
| 81 | my $make; |
Steven Rostedt | 8b37ca8 | 2010-11-02 14:58:33 -0400 | [diff] [blame] | 82 | my $post_install; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 83 | my $noclean; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 84 | my $minconfig; |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 85 | my $addconfig; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 86 | my $in_bisect = 0; |
| 87 | my $bisect_bad = ""; |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 88 | my $reverse_bisect; |
Steven Rostedt | c960bb9 | 2011-03-08 09:22:39 -0500 | [diff] [blame] | 89 | my $bisect_manual; |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 90 | my $bisect_skip; |
Steven Rostedt | 30f75da | 2011-06-13 10:35:35 -0400 | [diff] [blame] | 91 | my $config_bisect_good; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 92 | my $in_patchcheck = 0; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 93 | my $run_test; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 94 | my $redirect; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 95 | my $buildlog; |
| 96 | my $dmesg; |
| 97 | my $monitor_fp; |
| 98 | my $monitor_pid; |
| 99 | my $monitor_cnt = 0; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 100 | my $sleep_time; |
| 101 | my $bisect_sleep_time; |
Steven Rostedt | 27d934b | 2011-05-20 09:18:18 -0400 | [diff] [blame] | 102 | my $patchcheck_sleep_time; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 103 | my $store_failures; |
Steven Rostedt | 9064af5 | 2011-06-13 10:38:48 -0400 | [diff] [blame^] | 104 | my $test_name; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 105 | my $timeout; |
| 106 | my $booted_timeout; |
Steven Rostedt | f1a5b96 | 2011-06-13 10:30:00 -0400 | [diff] [blame] | 107 | my $detect_triplefault; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 108 | my $console; |
| 109 | my $success_line; |
Steven Rostedt | 1c8a617 | 2010-11-09 12:55:40 -0500 | [diff] [blame] | 110 | my $stop_after_success; |
| 111 | my $stop_after_failure; |
Steven Rostedt | 2d01b26 | 2011-03-08 09:47:54 -0500 | [diff] [blame] | 112 | my $stop_test_after; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 113 | my $build_target; |
| 114 | my $target_image; |
| 115 | my $localversion; |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 116 | my $iteration = 0; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 117 | my $successes = 0; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 118 | |
Steven Rostedt | 8d1491b | 2010-11-18 15:39:48 -0500 | [diff] [blame] | 119 | my %entered_configs; |
| 120 | my %config_help; |
Steven Rostedt | 77d942c | 2011-05-20 13:36:58 -0400 | [diff] [blame] | 121 | my %variable; |
Steven Rostedt | 8d1491b | 2010-11-18 15:39:48 -0500 | [diff] [blame] | 122 | |
| 123 | $config_help{"MACHINE"} = << "EOF" |
| 124 | The machine hostname that you will test. |
| 125 | EOF |
| 126 | ; |
| 127 | $config_help{"SSH_USER"} = << "EOF" |
| 128 | The box is expected to have ssh on normal bootup, provide the user |
| 129 | (most likely root, since you need privileged operations) |
| 130 | EOF |
| 131 | ; |
| 132 | $config_help{"BUILD_DIR"} = << "EOF" |
| 133 | The directory that contains the Linux source code (full path). |
| 134 | EOF |
| 135 | ; |
| 136 | $config_help{"OUTPUT_DIR"} = << "EOF" |
| 137 | The directory that the objects will be built (full path). |
| 138 | (can not be same as BUILD_DIR) |
| 139 | EOF |
| 140 | ; |
| 141 | $config_help{"BUILD_TARGET"} = << "EOF" |
| 142 | The location of the compiled file to copy to the target. |
| 143 | (relative to OUTPUT_DIR) |
| 144 | EOF |
| 145 | ; |
| 146 | $config_help{"TARGET_IMAGE"} = << "EOF" |
| 147 | The place to put your image on the test machine. |
| 148 | EOF |
| 149 | ; |
| 150 | $config_help{"POWER_CYCLE"} = << "EOF" |
| 151 | A script or command to reboot the box. |
| 152 | |
| 153 | Here is a digital loggers power switch example |
| 154 | POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL' |
| 155 | |
| 156 | Here is an example to reboot a virtual box on the current host |
| 157 | with the name "Guest". |
| 158 | POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest |
| 159 | EOF |
| 160 | ; |
| 161 | $config_help{"CONSOLE"} = << "EOF" |
| 162 | The script or command that reads the console |
| 163 | |
| 164 | If you use ttywatch server, something like the following would work. |
| 165 | CONSOLE = nc -d localhost 3001 |
| 166 | |
| 167 | For a virtual machine with guest name "Guest". |
| 168 | CONSOLE = virsh console Guest |
| 169 | EOF |
| 170 | ; |
| 171 | $config_help{"LOCALVERSION"} = << "EOF" |
| 172 | Required version ending to differentiate the test |
| 173 | from other linux builds on the system. |
| 174 | EOF |
| 175 | ; |
| 176 | $config_help{"REBOOT_TYPE"} = << "EOF" |
| 177 | Way to reboot the box to the test kernel. |
| 178 | Only valid options so far are "grub" and "script". |
| 179 | |
| 180 | If you specify grub, it will assume grub version 1 |
| 181 | and will search in /boot/grub/menu.lst for the title \$GRUB_MENU |
| 182 | and select that target to reboot to the kernel. If this is not |
| 183 | your setup, then specify "script" and have a command or script |
| 184 | specified in REBOOT_SCRIPT to boot to the target. |
| 185 | |
| 186 | The entry in /boot/grub/menu.lst must be entered in manually. |
| 187 | The test will not modify that file. |
| 188 | EOF |
| 189 | ; |
| 190 | $config_help{"GRUB_MENU"} = << "EOF" |
| 191 | The grub title name for the test kernel to boot |
| 192 | (Only mandatory if REBOOT_TYPE = grub) |
| 193 | |
| 194 | Note, ktest.pl will not update the grub menu.lst, you need to |
| 195 | manually add an option for the test. ktest.pl will search |
| 196 | the grub menu.lst for this option to find what kernel to |
| 197 | reboot into. |
| 198 | |
| 199 | For example, if in the /boot/grub/menu.lst the test kernel title has: |
| 200 | title Test Kernel |
| 201 | kernel vmlinuz-test |
| 202 | GRUB_MENU = Test Kernel |
| 203 | EOF |
| 204 | ; |
| 205 | $config_help{"REBOOT_SCRIPT"} = << "EOF" |
| 206 | A script to reboot the target into the test kernel |
| 207 | (Only mandatory if REBOOT_TYPE = script) |
| 208 | EOF |
| 209 | ; |
| 210 | |
| 211 | |
| 212 | sub get_ktest_config { |
| 213 | my ($config) = @_; |
| 214 | |
| 215 | return if (defined($opt{$config})); |
| 216 | |
| 217 | if (defined($config_help{$config})) { |
| 218 | print "\n"; |
| 219 | print $config_help{$config}; |
| 220 | } |
| 221 | |
| 222 | for (;;) { |
| 223 | print "$config = "; |
| 224 | if (defined($default{$config})) { |
| 225 | print "\[$default{$config}\] "; |
| 226 | } |
| 227 | $entered_configs{$config} = <STDIN>; |
| 228 | $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/; |
| 229 | if ($entered_configs{$config} =~ /^\s*$/) { |
| 230 | if ($default{$config}) { |
| 231 | $entered_configs{$config} = $default{$config}; |
| 232 | } else { |
| 233 | print "Your answer can not be blank\n"; |
| 234 | next; |
| 235 | } |
| 236 | } |
| 237 | last; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | sub get_ktest_configs { |
| 242 | get_ktest_config("MACHINE"); |
| 243 | get_ktest_config("SSH_USER"); |
| 244 | get_ktest_config("BUILD_DIR"); |
| 245 | get_ktest_config("OUTPUT_DIR"); |
| 246 | get_ktest_config("BUILD_TARGET"); |
| 247 | get_ktest_config("TARGET_IMAGE"); |
| 248 | get_ktest_config("POWER_CYCLE"); |
| 249 | get_ktest_config("CONSOLE"); |
| 250 | get_ktest_config("LOCALVERSION"); |
| 251 | |
| 252 | my $rtype = $opt{"REBOOT_TYPE"}; |
| 253 | |
| 254 | if (!defined($rtype)) { |
| 255 | if (!defined($opt{"GRUB_MENU"})) { |
| 256 | get_ktest_config("REBOOT_TYPE"); |
| 257 | $rtype = $entered_configs{"REBOOT_TYPE"}; |
| 258 | } else { |
| 259 | $rtype = "grub"; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if ($rtype eq "grub") { |
| 264 | get_ktest_config("GRUB_MENU"); |
| 265 | } else { |
| 266 | get_ktest_config("REBOOT_SCRIPT"); |
| 267 | } |
| 268 | } |
| 269 | |
Steven Rostedt | 77d942c | 2011-05-20 13:36:58 -0400 | [diff] [blame] | 270 | sub process_variables { |
| 271 | my ($value) = @_; |
| 272 | my $retval = ""; |
| 273 | |
| 274 | # We want to check for '\', and it is just easier |
| 275 | # to check the previous characet of '$' and not need |
| 276 | # to worry if '$' is the first character. By adding |
| 277 | # a space to $value, we can just check [^\\]\$ and |
| 278 | # it will still work. |
| 279 | $value = " $value"; |
| 280 | |
| 281 | while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) { |
| 282 | my $begin = $1; |
| 283 | my $var = $2; |
| 284 | my $end = $3; |
| 285 | # append beginning of value to retval |
| 286 | $retval = "$retval$begin"; |
| 287 | if (defined($variable{$var})) { |
| 288 | $retval = "$retval$variable{$var}"; |
| 289 | } else { |
| 290 | # put back the origin piece. |
| 291 | $retval = "$retval\$\{$var\}"; |
| 292 | } |
| 293 | $value = $end; |
| 294 | } |
| 295 | $retval = "$retval$value"; |
| 296 | |
| 297 | # remove the space added in the beginning |
| 298 | $retval =~ s/ //; |
| 299 | |
| 300 | return "$retval" |
| 301 | } |
| 302 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 303 | sub set_value { |
| 304 | my ($lvalue, $rvalue) = @_; |
| 305 | |
| 306 | if (defined($opt{$lvalue})) { |
| 307 | die "Error: Option $lvalue defined more than once!\n"; |
| 308 | } |
Steven Rostedt | 21a9679 | 2010-11-08 16:45:50 -0500 | [diff] [blame] | 309 | if ($rvalue =~ /^\s*$/) { |
| 310 | delete $opt{$lvalue}; |
| 311 | } else { |
Steven Rostedt | 77d942c | 2011-05-20 13:36:58 -0400 | [diff] [blame] | 312 | $rvalue = process_variables($rvalue); |
Steven Rostedt | 21a9679 | 2010-11-08 16:45:50 -0500 | [diff] [blame] | 313 | $opt{$lvalue} = $rvalue; |
| 314 | } |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Steven Rostedt | 77d942c | 2011-05-20 13:36:58 -0400 | [diff] [blame] | 317 | sub set_variable { |
| 318 | my ($lvalue, $rvalue) = @_; |
| 319 | |
| 320 | if ($rvalue =~ /^\s*$/) { |
| 321 | delete $variable{$lvalue}; |
| 322 | } else { |
| 323 | $rvalue = process_variables($rvalue); |
| 324 | $variable{$lvalue} = $rvalue; |
| 325 | } |
| 326 | } |
| 327 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 328 | sub read_config { |
| 329 | my ($config) = @_; |
| 330 | |
| 331 | open(IN, $config) || die "can't read file $config"; |
| 332 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 333 | my $name = $config; |
| 334 | $name =~ s,.*/(.*),$1,; |
| 335 | |
| 336 | my $test_num = 0; |
| 337 | my $default = 1; |
| 338 | my $repeat = 1; |
| 339 | my $num_tests_set = 0; |
| 340 | my $skip = 0; |
| 341 | my $rest; |
| 342 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 343 | while (<IN>) { |
| 344 | |
| 345 | # ignore blank lines and comments |
| 346 | next if (/^\s*$/ || /\s*\#/); |
| 347 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 348 | if (/^\s*TEST_START(.*)/) { |
| 349 | |
| 350 | $rest = $1; |
| 351 | |
| 352 | if ($num_tests_set) { |
| 353 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; |
| 354 | } |
| 355 | |
| 356 | my $old_test_num = $test_num; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 357 | my $old_repeat = $repeat; |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 358 | |
| 359 | $test_num += $repeat; |
| 360 | $default = 0; |
| 361 | $repeat = 1; |
| 362 | |
| 363 | if ($rest =~ /\s+SKIP(.*)/) { |
| 364 | $rest = $1; |
| 365 | $skip = 1; |
| 366 | } else { |
| 367 | $skip = 0; |
| 368 | } |
| 369 | |
| 370 | if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) { |
| 371 | $repeat = $1; |
| 372 | $rest = $2; |
| 373 | $repeat_tests{"$test_num"} = $repeat; |
| 374 | } |
| 375 | |
| 376 | if ($rest =~ /\s+SKIP(.*)/) { |
| 377 | $rest = $1; |
| 378 | $skip = 1; |
| 379 | } |
| 380 | |
| 381 | if ($rest !~ /^\s*$/) { |
| 382 | die "$name: $.: Gargbage found after TEST_START\n$_"; |
| 383 | } |
| 384 | |
| 385 | if ($skip) { |
| 386 | $test_num = $old_test_num; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 387 | $repeat = $old_repeat; |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | } elsif (/^\s*DEFAULTS(.*)$/) { |
| 391 | $default = 1; |
| 392 | |
| 393 | $rest = $1; |
| 394 | |
| 395 | if ($rest =~ /\s+SKIP(.*)/) { |
| 396 | $rest = $1; |
| 397 | $skip = 1; |
| 398 | } else { |
| 399 | $skip = 0; |
| 400 | } |
| 401 | |
| 402 | if ($rest !~ /^\s*$/) { |
| 403 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; |
| 404 | } |
| 405 | |
| 406 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { |
| 407 | |
| 408 | next if ($skip); |
| 409 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 410 | my $lvalue = $1; |
| 411 | my $rvalue = $2; |
| 412 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 413 | if (!$default && |
| 414 | ($lvalue eq "NUM_TESTS" || |
| 415 | $lvalue eq "LOG_FILE" || |
| 416 | $lvalue eq "CLEAR_LOG")) { |
| 417 | die "$name: $.: $lvalue must be set in DEFAULTS section\n"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 418 | } |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 419 | |
| 420 | if ($lvalue eq "NUM_TESTS") { |
| 421 | if ($test_num) { |
| 422 | die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n"; |
| 423 | } |
| 424 | if (!$default) { |
| 425 | die "$name: $.: NUM_TESTS must be set in default section\n"; |
| 426 | } |
| 427 | $num_tests_set = 1; |
| 428 | } |
| 429 | |
| 430 | if ($default || $lvalue =~ /\[\d+\]$/) { |
| 431 | set_value($lvalue, $rvalue); |
| 432 | } else { |
| 433 | my $val = "$lvalue\[$test_num\]"; |
| 434 | set_value($val, $rvalue); |
| 435 | |
| 436 | if ($repeat > 1) { |
| 437 | $repeats{$val} = $repeat; |
| 438 | } |
| 439 | } |
Steven Rostedt | 77d942c | 2011-05-20 13:36:58 -0400 | [diff] [blame] | 440 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) { |
| 441 | next if ($skip); |
| 442 | |
| 443 | my $lvalue = $1; |
| 444 | my $rvalue = $2; |
| 445 | |
| 446 | # process config variables. |
| 447 | # Config variables are only active while reading the |
| 448 | # config and can be defined anywhere. They also ignore |
| 449 | # TEST_START and DEFAULTS, but are skipped if they are in |
| 450 | # on of these sections that have SKIP defined. |
| 451 | # The save variable can be |
| 452 | # defined multiple times and the new one simply overrides |
| 453 | # the prevous one. |
| 454 | set_variable($lvalue, $rvalue); |
| 455 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 456 | } else { |
| 457 | die "$name: $.: Garbage found in config\n$_"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
| 461 | close(IN); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 462 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 463 | if ($test_num) { |
| 464 | $test_num += $repeat - 1; |
| 465 | $opt{"NUM_TESTS"} = $test_num; |
| 466 | } |
| 467 | |
Steven Rostedt | 8d1491b | 2010-11-18 15:39:48 -0500 | [diff] [blame] | 468 | # make sure we have all mandatory configs |
| 469 | get_ktest_configs; |
| 470 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 471 | # set any defaults |
| 472 | |
| 473 | foreach my $default (keys %default) { |
| 474 | if (!defined($opt{$default})) { |
| 475 | $opt{$default} = $default{$default}; |
| 476 | } |
| 477 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 478 | } |
| 479 | |
Steven Rostedt | d1e2f22 | 2010-11-08 16:39:57 -0500 | [diff] [blame] | 480 | sub _logit { |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 481 | if (defined($opt{"LOG_FILE"})) { |
| 482 | open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}"; |
| 483 | print OUT @_; |
| 484 | close(OUT); |
| 485 | } |
| 486 | } |
| 487 | |
Steven Rostedt | d1e2f22 | 2010-11-08 16:39:57 -0500 | [diff] [blame] | 488 | sub logit { |
| 489 | if (defined($opt{"LOG_FILE"})) { |
| 490 | _logit @_; |
| 491 | } else { |
| 492 | print @_; |
| 493 | } |
| 494 | } |
| 495 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 496 | sub doprint { |
| 497 | print @_; |
Steven Rostedt | d1e2f22 | 2010-11-08 16:39:57 -0500 | [diff] [blame] | 498 | _logit @_; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 499 | } |
| 500 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 501 | sub run_command; |
| 502 | |
| 503 | sub reboot { |
| 504 | # try to reboot normally |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 505 | if (run_command $reboot) { |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 506 | if (defined($powercycle_after_reboot)) { |
| 507 | sleep $powercycle_after_reboot; |
| 508 | run_command "$power_cycle"; |
| 509 | } |
| 510 | } else { |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 511 | # nope? power cycle it. |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 512 | run_command "$power_cycle"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 516 | sub do_not_reboot { |
| 517 | my $i = $iteration; |
| 518 | |
| 519 | return $test_type eq "build" || |
| 520 | ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") || |
| 521 | ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build"); |
| 522 | } |
| 523 | |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 524 | sub dodie { |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 525 | doprint "CRITICAL FAILURE... ", @_, "\n"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 526 | |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 527 | my $i = $iteration; |
| 528 | |
| 529 | if ($reboot_on_error && !do_not_reboot) { |
| 530 | |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 531 | doprint "REBOOTING\n"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 532 | reboot; |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 533 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 534 | } elsif ($poweroff_on_error && defined($power_off)) { |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 535 | doprint "POWERING OFF\n"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 536 | `$power_off`; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 537 | } |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 538 | |
Steven Rostedt | f80802c | 2011-03-07 13:18:47 -0500 | [diff] [blame] | 539 | if (defined($opt{"LOG_FILE"})) { |
| 540 | print " See $opt{LOG_FILE} for more info.\n"; |
| 541 | } |
| 542 | |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 543 | die @_, "\n"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 544 | } |
| 545 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 546 | sub open_console { |
| 547 | my ($fp) = @_; |
| 548 | |
| 549 | my $flags; |
| 550 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 551 | my $pid = open($fp, "$console|") or |
| 552 | dodie "Can't open console $console"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 553 | |
| 554 | $flags = fcntl($fp, F_GETFL, 0) or |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 555 | dodie "Can't get flags for the socket: $!"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 556 | $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 557 | dodie "Can't set flags for the socket: $!"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 558 | |
| 559 | return $pid; |
| 560 | } |
| 561 | |
| 562 | sub close_console { |
| 563 | my ($fp, $pid) = @_; |
| 564 | |
| 565 | doprint "kill child process $pid\n"; |
| 566 | kill 2, $pid; |
| 567 | |
| 568 | print "closing!\n"; |
| 569 | close($fp); |
| 570 | } |
| 571 | |
| 572 | sub start_monitor { |
| 573 | if ($monitor_cnt++) { |
| 574 | return; |
| 575 | } |
| 576 | $monitor_fp = \*MONFD; |
| 577 | $monitor_pid = open_console $monitor_fp; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 578 | |
| 579 | return; |
| 580 | |
| 581 | open(MONFD, "Stop perl from warning about single use of MONFD"); |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | sub end_monitor { |
| 585 | if (--$monitor_cnt) { |
| 586 | return; |
| 587 | } |
| 588 | close_console($monitor_fp, $monitor_pid); |
| 589 | } |
| 590 | |
| 591 | sub wait_for_monitor { |
| 592 | my ($time) = @_; |
| 593 | my $line; |
| 594 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 595 | doprint "** Wait for monitor to settle down **\n"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 596 | |
| 597 | # read the monitor and wait for the system to calm down |
| 598 | do { |
| 599 | $line = wait_for_input($monitor_fp, $time); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 600 | print "$line" if (defined($line)); |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 601 | } while (defined($line)); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 602 | print "** Monitor flushed **\n"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 603 | } |
| 604 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 605 | sub fail { |
| 606 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 607 | if ($die_on_failure) { |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 608 | dodie @_; |
| 609 | } |
| 610 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 611 | doprint "FAILED\n"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 612 | |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 613 | my $i = $iteration; |
| 614 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 615 | # no need to reboot for just building. |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 616 | if (!do_not_reboot) { |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 617 | doprint "REBOOTING\n"; |
| 618 | reboot; |
| 619 | start_monitor; |
| 620 | wait_for_monitor $sleep_time; |
| 621 | end_monitor; |
| 622 | } |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 623 | |
Steven Rostedt | 9064af5 | 2011-06-13 10:38:48 -0400 | [diff] [blame^] | 624 | my $name = ""; |
| 625 | |
| 626 | if (defined($test_name)) { |
| 627 | $name = " ($test_name)"; |
| 628 | } |
| 629 | |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 630 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
| 631 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
Steven Rostedt | 9064af5 | 2011-06-13 10:38:48 -0400 | [diff] [blame^] | 632 | doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n"; |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 633 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
| 634 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 635 | |
| 636 | return 1 if (!defined($store_failures)); |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 637 | |
| 638 | my @t = localtime; |
| 639 | my $date = sprintf "%04d%02d%02d%02d%02d%02d", |
| 640 | 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0]; |
| 641 | |
Steven Rostedt | cccae1a | 2010-11-09 12:21:32 -0500 | [diff] [blame] | 642 | my $type = $build_type; |
| 643 | if ($type =~ /useconfig/) { |
| 644 | $type = "useconfig"; |
| 645 | } |
| 646 | |
| 647 | my $dir = "$machine-$test_type-$type-fail-$date"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 648 | my $faildir = "$store_failures/$dir"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 649 | |
| 650 | if (!-d $faildir) { |
| 651 | mkpath($faildir) or |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 652 | die "can't create $faildir"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 653 | } |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 654 | if (-f "$output_config") { |
| 655 | cp "$output_config", "$faildir/config" or |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 656 | die "failed to copy .config"; |
| 657 | } |
| 658 | if (-f $buildlog) { |
| 659 | cp $buildlog, "$faildir/buildlog" or |
| 660 | die "failed to move $buildlog"; |
| 661 | } |
| 662 | if (-f $dmesg) { |
| 663 | cp $dmesg, "$faildir/dmesg" or |
| 664 | die "failed to move $dmesg"; |
| 665 | } |
| 666 | |
| 667 | doprint "*** Saved info to $faildir ***\n"; |
| 668 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 669 | return 1; |
| 670 | } |
| 671 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 672 | sub run_command { |
| 673 | my ($command) = @_; |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 674 | my $dolog = 0; |
| 675 | my $dord = 0; |
| 676 | my $pid; |
| 677 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 678 | $command =~ s/\$SSH_USER/$ssh_user/g; |
| 679 | $command =~ s/\$MACHINE/$machine/g; |
| 680 | |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 681 | doprint("$command ... "); |
| 682 | |
| 683 | $pid = open(CMD, "$command 2>&1 |") or |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 684 | (fail "unable to exec $command" and return 0); |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 685 | |
| 686 | if (defined($opt{"LOG_FILE"})) { |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 687 | open(LOG, ">>$opt{LOG_FILE}") or |
| 688 | dodie "failed to write to log"; |
| 689 | $dolog = 1; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | if (defined($redirect)) { |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 693 | open (RD, ">$redirect") or |
| 694 | dodie "failed to write to redirect $redirect"; |
| 695 | $dord = 1; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 698 | while (<CMD>) { |
| 699 | print LOG if ($dolog); |
| 700 | print RD if ($dord); |
| 701 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 702 | |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 703 | waitpid($pid, 0); |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 704 | my $failed = $?; |
| 705 | |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 706 | close(CMD); |
| 707 | close(LOG) if ($dolog); |
| 708 | close(RD) if ($dord); |
| 709 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 710 | if ($failed) { |
| 711 | doprint "FAILED!\n"; |
| 712 | } else { |
| 713 | doprint "SUCCESS\n"; |
| 714 | } |
| 715 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 716 | return !$failed; |
| 717 | } |
| 718 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 719 | sub run_ssh { |
| 720 | my ($cmd) = @_; |
| 721 | my $cp_exec = $ssh_exec; |
| 722 | |
| 723 | $cp_exec =~ s/\$SSH_COMMAND/$cmd/g; |
| 724 | return run_command "$cp_exec"; |
| 725 | } |
| 726 | |
| 727 | sub run_scp { |
| 728 | my ($src, $dst) = @_; |
| 729 | my $cp_scp = $scp_to_target; |
| 730 | |
| 731 | $cp_scp =~ s/\$SRC_FILE/$src/g; |
| 732 | $cp_scp =~ s/\$DST_FILE/$dst/g; |
| 733 | |
| 734 | return run_command "$cp_scp"; |
| 735 | } |
| 736 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 737 | sub get_grub_index { |
| 738 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 739 | if ($reboot_type ne "grub") { |
| 740 | return; |
| 741 | } |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 742 | return if (defined($grub_number)); |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 743 | |
| 744 | doprint "Find grub menu ... "; |
| 745 | $grub_number = -1; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 746 | |
| 747 | my $ssh_grub = $ssh_exec; |
| 748 | $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g; |
| 749 | |
| 750 | open(IN, "$ssh_grub |") |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 751 | or die "unable to get menu.lst"; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 752 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 753 | while (<IN>) { |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 754 | if (/^\s*title\s+$grub_menu\s*$/) { |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 755 | $grub_number++; |
| 756 | last; |
| 757 | } elsif (/^\s*title\s/) { |
| 758 | $grub_number++; |
| 759 | } |
| 760 | } |
| 761 | close(IN); |
| 762 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 763 | die "Could not find '$grub_menu' in /boot/grub/menu on $machine" |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 764 | if ($grub_number < 0); |
| 765 | doprint "$grub_number\n"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 766 | } |
| 767 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 768 | sub wait_for_input |
| 769 | { |
| 770 | my ($fp, $time) = @_; |
| 771 | my $rin; |
| 772 | my $ready; |
| 773 | my $line; |
| 774 | my $ch; |
| 775 | |
| 776 | if (!defined($time)) { |
| 777 | $time = $timeout; |
| 778 | } |
| 779 | |
| 780 | $rin = ''; |
| 781 | vec($rin, fileno($fp), 1) = 1; |
| 782 | $ready = select($rin, undef, undef, $time); |
| 783 | |
| 784 | $line = ""; |
| 785 | |
| 786 | # try to read one char at a time |
| 787 | while (sysread $fp, $ch, 1) { |
| 788 | $line .= $ch; |
| 789 | last if ($ch eq "\n"); |
| 790 | } |
| 791 | |
| 792 | if (!length($line)) { |
| 793 | return undef; |
| 794 | } |
| 795 | |
| 796 | return $line; |
| 797 | } |
| 798 | |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 799 | sub reboot_to { |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 800 | if ($reboot_type eq "grub") { |
Steven Rostedt | 4da46da | 2011-06-01 23:25:13 -0400 | [diff] [blame] | 801 | run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch && reboot)'"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 802 | return; |
| 803 | } |
| 804 | |
| 805 | run_command "$reboot_script"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 806 | } |
| 807 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 808 | sub get_sha1 { |
| 809 | my ($commit) = @_; |
| 810 | |
| 811 | doprint "git rev-list --max-count=1 $commit ... "; |
| 812 | my $sha1 = `git rev-list --max-count=1 $commit`; |
| 813 | my $ret = $?; |
| 814 | |
| 815 | logit $sha1; |
| 816 | |
| 817 | if ($ret) { |
| 818 | doprint "FAILED\n"; |
| 819 | dodie "Failed to get git $commit"; |
| 820 | } |
| 821 | |
| 822 | print "SUCCESS\n"; |
| 823 | |
| 824 | chomp $sha1; |
| 825 | |
| 826 | return $sha1; |
| 827 | } |
| 828 | |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 829 | sub monitor { |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 830 | my $booted = 0; |
| 831 | my $bug = 0; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 832 | my $skip_call_trace = 0; |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 833 | my $loops; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 834 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 835 | wait_for_monitor 5; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 836 | |
| 837 | my $line; |
| 838 | my $full_line = ""; |
| 839 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 840 | open(DMESG, "> $dmesg") or |
| 841 | die "unable to write to $dmesg"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 842 | |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 843 | reboot_to; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 844 | |
Steven Rostedt | 1c8a617 | 2010-11-09 12:55:40 -0500 | [diff] [blame] | 845 | my $success_start; |
| 846 | my $failure_start; |
Steven Rostedt | 2d01b26 | 2011-03-08 09:47:54 -0500 | [diff] [blame] | 847 | my $monitor_start = time; |
| 848 | my $done = 0; |
Steven Rostedt | f1a5b96 | 2011-06-13 10:30:00 -0400 | [diff] [blame] | 849 | my $version_found = 0; |
Steven Rostedt | 1c8a617 | 2010-11-09 12:55:40 -0500 | [diff] [blame] | 850 | |
Steven Rostedt | 2d01b26 | 2011-03-08 09:47:54 -0500 | [diff] [blame] | 851 | while (!$done) { |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 852 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 853 | if ($booted) { |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 854 | $line = wait_for_input($monitor_fp, $booted_timeout); |
Steven Rostedt | cd4f1d5 | 2011-06-13 10:26:27 -0400 | [diff] [blame] | 855 | if (!defined($line)) { |
| 856 | my $s = $booted_timeout == 1 ? "" : "s"; |
| 857 | doprint "Successful boot found: break after $booted_timeout second$s\n"; |
| 858 | last; |
| 859 | } |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 860 | } else { |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 861 | $line = wait_for_input($monitor_fp); |
Steven Rostedt | cd4f1d5 | 2011-06-13 10:26:27 -0400 | [diff] [blame] | 862 | if (!defined($line)) { |
| 863 | my $s = $timeout == 1 ? "" : "s"; |
| 864 | doprint "Timed out after $timeout second$s\n"; |
| 865 | last; |
| 866 | } |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 867 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 868 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 869 | doprint $line; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 870 | print DMESG $line; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 871 | |
| 872 | # we are not guaranteed to get a full line |
| 873 | $full_line .= $line; |
| 874 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 875 | if ($full_line =~ /$success_line/) { |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 876 | $booted = 1; |
Steven Rostedt | 1c8a617 | 2010-11-09 12:55:40 -0500 | [diff] [blame] | 877 | $success_start = time; |
| 878 | } |
| 879 | |
| 880 | if ($booted && defined($stop_after_success) && |
| 881 | $stop_after_success >= 0) { |
| 882 | my $now = time; |
| 883 | if ($now - $success_start >= $stop_after_success) { |
| 884 | doprint "Test forced to stop after $stop_after_success seconds after success\n"; |
| 885 | last; |
| 886 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 887 | } |
| 888 | |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 889 | if ($full_line =~ /\[ backtrace testing \]/) { |
| 890 | $skip_call_trace = 1; |
| 891 | } |
| 892 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 893 | if ($full_line =~ /call trace:/i) { |
Steven Rostedt | 4651920 | 2011-03-08 09:40:31 -0500 | [diff] [blame] | 894 | if (!$bug && !$skip_call_trace) { |
Steven Rostedt | 1c8a617 | 2010-11-09 12:55:40 -0500 | [diff] [blame] | 895 | $bug = 1; |
| 896 | $failure_start = time; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | if ($bug && defined($stop_after_failure) && |
| 901 | $stop_after_failure >= 0) { |
| 902 | my $now = time; |
| 903 | if ($now - $failure_start >= $stop_after_failure) { |
| 904 | doprint "Test forced to stop after $stop_after_failure seconds after failure\n"; |
| 905 | last; |
| 906 | } |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | if ($full_line =~ /\[ end of backtrace testing \]/) { |
| 910 | $skip_call_trace = 0; |
| 911 | } |
| 912 | |
| 913 | if ($full_line =~ /Kernel panic -/) { |
Steven Rostedt | 10abf11 | 2011-03-07 13:21:00 -0500 | [diff] [blame] | 914 | $failure_start = time; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 915 | $bug = 1; |
| 916 | } |
| 917 | |
Steven Rostedt | f1a5b96 | 2011-06-13 10:30:00 -0400 | [diff] [blame] | 918 | # Detect triple faults by testing the banner |
| 919 | if ($full_line =~ /\bLinux version (\S+).*\n/) { |
| 920 | if ($1 eq $version) { |
| 921 | $version_found = 1; |
| 922 | } elsif ($version_found && $detect_triplefault) { |
| 923 | # We already booted into the kernel we are testing, |
| 924 | # but now we booted into another kernel? |
| 925 | # Consider this a triple fault. |
| 926 | doprint "Aleady booted in Linux kernel $version, but now\n"; |
| 927 | doprint "we booted into Linux kernel $1.\n"; |
| 928 | doprint "Assuming that this is a triple fault.\n"; |
| 929 | doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n"; |
| 930 | last; |
| 931 | } |
| 932 | } |
| 933 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 934 | if ($line =~ /\n/) { |
| 935 | $full_line = ""; |
| 936 | } |
Steven Rostedt | 2d01b26 | 2011-03-08 09:47:54 -0500 | [diff] [blame] | 937 | |
| 938 | if ($stop_test_after > 0 && !$booted && !$bug) { |
| 939 | if (time - $monitor_start > $stop_test_after) { |
Steven Rostedt | 4d62bf5 | 2011-05-20 09:14:35 -0400 | [diff] [blame] | 940 | doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n"; |
Steven Rostedt | 2d01b26 | 2011-03-08 09:47:54 -0500 | [diff] [blame] | 941 | $done = 1; |
| 942 | } |
| 943 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 944 | } |
| 945 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 946 | close(DMESG); |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 947 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 948 | if ($bug) { |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 949 | return 0 if ($in_bisect); |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 950 | fail "failed - got a bug report" and return 0; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 951 | } |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 952 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 953 | if (!$booted) { |
| 954 | return 0 if ($in_bisect); |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 955 | fail "failed - never got a boot prompt." and return 0; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 956 | } |
| 957 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 958 | return 1; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | sub install { |
| 962 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 963 | run_scp "$outputdir/$build_target", "$target_image" or |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 964 | dodie "failed to copy image"; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 965 | |
| 966 | my $install_mods = 0; |
| 967 | |
| 968 | # should we process modules? |
| 969 | $install_mods = 0; |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 970 | open(IN, "$output_config") or dodie("Can't read config file"); |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 971 | while (<IN>) { |
| 972 | if (/CONFIG_MODULES(=y)?/) { |
| 973 | $install_mods = 1 if (defined($1)); |
| 974 | last; |
| 975 | } |
| 976 | } |
| 977 | close(IN); |
| 978 | |
| 979 | if (!$install_mods) { |
| 980 | doprint "No modules needed\n"; |
| 981 | return; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 982 | } |
| 983 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 984 | run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 985 | dodie "Failed to install modules"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 986 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 987 | my $modlib = "/lib/modules/$version"; |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 988 | my $modtar = "ktest-mods.tar.bz2"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 989 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 990 | run_ssh "rm -rf $modlib" or |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 991 | dodie "failed to remove old mods: $modlib"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 992 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 993 | # would be nice if scp -r did not follow symbolic links |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 994 | run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 995 | dodie "making tarball"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 996 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 997 | run_scp "$tmpdir/$modtar", "/tmp" or |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 998 | dodie "failed to copy modules"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 999 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1000 | unlink "$tmpdir/$modtar"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1001 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 1002 | run_ssh "'(cd / && tar xf /tmp/$modtar)'" or |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1003 | dodie "failed to tar modules"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1004 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 1005 | run_ssh "rm -f /tmp/$modtar"; |
Steven Rostedt | 8b37ca8 | 2010-11-02 14:58:33 -0400 | [diff] [blame] | 1006 | |
| 1007 | return if (!defined($post_install)); |
| 1008 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 1009 | my $cp_post_install = $post_install; |
Steven Rostedt | ca6a21f | 2011-03-25 22:42:53 -0400 | [diff] [blame] | 1010 | $cp_post_install =~ s/\$KERNEL_VERSION/$version/g; |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 1011 | run_command "$cp_post_install" or |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 1012 | dodie "Failed to run post install"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1015 | sub check_buildlog { |
| 1016 | my ($patch) = @_; |
| 1017 | |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1018 | my @files = `git show $patch | diffstat -l`; |
| 1019 | |
| 1020 | open(IN, "git show $patch |") or |
| 1021 | dodie "failed to show $patch"; |
| 1022 | while (<IN>) { |
| 1023 | if (m,^--- a/(.*),) { |
| 1024 | chomp $1; |
| 1025 | $files[$#files] = $1; |
| 1026 | } |
| 1027 | } |
| 1028 | close(IN); |
| 1029 | |
| 1030 | open(IN, $buildlog) or dodie "Can't open $buildlog"; |
| 1031 | while (<IN>) { |
| 1032 | if (/^\s*(.*?):.*(warning|error)/) { |
| 1033 | my $err = $1; |
| 1034 | foreach my $file (@files) { |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1035 | my $fullpath = "$builddir/$file"; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1036 | if ($file eq $err || $fullpath eq $err) { |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1037 | fail "$file built with warnings" and return 0; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | close(IN); |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1043 | |
| 1044 | return 1; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
Steven Rostedt | 612b9e9 | 2011-03-07 13:27:43 -0500 | [diff] [blame] | 1047 | sub make_oldconfig { |
| 1048 | my ($defconfig) = @_; |
| 1049 | |
| 1050 | if (!run_command "$defconfig $make oldnoconfig") { |
| 1051 | # Perhaps oldnoconfig doesn't exist in this version of the kernel |
| 1052 | # try a yes '' | oldconfig |
| 1053 | doprint "oldnoconfig failed, trying yes '' | make oldconfig\n"; |
| 1054 | run_command "yes '' | $defconfig $make oldconfig" or |
| 1055 | dodie "failed make config oldconfig"; |
| 1056 | } |
| 1057 | } |
| 1058 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1059 | sub build { |
| 1060 | my ($type) = @_; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1061 | my $defconfig = ""; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1062 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1063 | unlink $buildlog; |
| 1064 | |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1065 | if ($type =~ /^useconfig:(.*)/) { |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 1066 | run_command "cp $1 $output_config" or |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1067 | dodie "could not copy $1 to .config"; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1068 | |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1069 | $type = "oldconfig"; |
| 1070 | } |
| 1071 | |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1072 | # old config can ask questions |
| 1073 | if ($type eq "oldconfig") { |
Steven Rostedt | 9386c6a | 2010-11-08 16:35:48 -0500 | [diff] [blame] | 1074 | $type = "oldnoconfig"; |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1075 | |
| 1076 | # allow for empty configs |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 1077 | run_command "touch $output_config"; |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1078 | |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 1079 | run_command "mv $output_config $outputdir/config_temp" or |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1080 | dodie "moving .config"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1081 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1082 | if (!$noclean && !run_command "$make mrproper") { |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1083 | dodie "make mrproper"; |
| 1084 | } |
| 1085 | |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 1086 | run_command "mv $outputdir/config_temp $output_config" or |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1087 | dodie "moving config_temp"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1088 | |
| 1089 | } elsif (!$noclean) { |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 1090 | unlink "$output_config"; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1091 | run_command "$make mrproper" or |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1092 | dodie "make mrproper"; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 1093 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1094 | |
| 1095 | # add something to distinguish this build |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1096 | open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file"); |
| 1097 | print OUT "$localversion\n"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1098 | close(OUT); |
| 1099 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1100 | if (defined($minconfig)) { |
| 1101 | $defconfig = "KCONFIG_ALLCONFIG=$minconfig"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1102 | } |
| 1103 | |
Steven Rostedt | 612b9e9 | 2011-03-07 13:27:43 -0500 | [diff] [blame] | 1104 | if ($type eq "oldnoconfig") { |
| 1105 | make_oldconfig $defconfig; |
| 1106 | } else { |
| 1107 | run_command "$defconfig $make $type" or |
| 1108 | dodie "failed make config"; |
| 1109 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1110 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1111 | $redirect = "$buildlog"; |
| 1112 | if (!run_command "$make $build_options") { |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1113 | undef $redirect; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1114 | # bisect may need this to pass |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1115 | return 0 if ($in_bisect); |
| 1116 | fail "failed build" and return 0; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1117 | } |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1118 | undef $redirect; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1119 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1120 | return 1; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1121 | } |
| 1122 | |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1123 | sub halt { |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 1124 | if (!run_ssh "halt" or defined($power_off)) { |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 1125 | if (defined($poweroff_after_halt)) { |
| 1126 | sleep $poweroff_after_halt; |
| 1127 | run_command "$power_off"; |
| 1128 | } |
| 1129 | } else { |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1130 | # nope? the zap it! |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1131 | run_command "$power_off"; |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1135 | sub success { |
| 1136 | my ($i) = @_; |
| 1137 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 1138 | $successes++; |
| 1139 | |
Steven Rostedt | 9064af5 | 2011-06-13 10:38:48 -0400 | [diff] [blame^] | 1140 | my $name = ""; |
| 1141 | |
| 1142 | if (defined($test_name)) { |
| 1143 | $name = " ($test_name)"; |
| 1144 | } |
| 1145 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1146 | doprint "\n\n*******************************************\n"; |
| 1147 | doprint "*******************************************\n"; |
Steven Rostedt | 9064af5 | 2011-06-13 10:38:48 -0400 | [diff] [blame^] | 1148 | doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n"; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1149 | doprint "*******************************************\n"; |
| 1150 | doprint "*******************************************\n"; |
| 1151 | |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 1152 | if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) { |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1153 | doprint "Reboot and wait $sleep_time seconds\n"; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1154 | reboot; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1155 | start_monitor; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1156 | wait_for_monitor $sleep_time; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1157 | end_monitor; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | sub get_version { |
| 1162 | # get the release name |
| 1163 | doprint "$make kernelrelease ... "; |
| 1164 | $version = `$make kernelrelease | tail -1`; |
| 1165 | chomp($version); |
| 1166 | doprint "$version\n"; |
| 1167 | } |
| 1168 | |
Steven Rostedt | c960bb9 | 2011-03-08 09:22:39 -0500 | [diff] [blame] | 1169 | sub answer_bisect { |
| 1170 | for (;;) { |
| 1171 | doprint "Pass or fail? [p/f]"; |
| 1172 | my $ans = <STDIN>; |
| 1173 | chomp $ans; |
| 1174 | if ($ans eq "p" || $ans eq "P") { |
| 1175 | return 1; |
| 1176 | } elsif ($ans eq "f" || $ans eq "F") { |
| 1177 | return 0; |
| 1178 | } else { |
| 1179 | print "Please answer 'P' or 'F'\n"; |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1184 | sub child_run_test { |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1185 | my $failed = 0; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1186 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1187 | # child should have no power |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1188 | $reboot_on_error = 0; |
| 1189 | $poweroff_on_error = 0; |
| 1190 | $die_on_failure = 1; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1191 | |
| 1192 | run_command $run_test or $failed = 1; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1193 | exit $failed; |
| 1194 | } |
| 1195 | |
| 1196 | my $child_done; |
| 1197 | |
| 1198 | sub child_finished { |
| 1199 | $child_done = 1; |
| 1200 | } |
| 1201 | |
| 1202 | sub do_run_test { |
| 1203 | my $child_pid; |
| 1204 | my $child_exit; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1205 | my $line; |
| 1206 | my $full_line; |
| 1207 | my $bug = 0; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1208 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1209 | wait_for_monitor 1; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1210 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1211 | doprint "run test $run_test\n"; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1212 | |
| 1213 | $child_done = 0; |
| 1214 | |
| 1215 | $SIG{CHLD} = qw(child_finished); |
| 1216 | |
| 1217 | $child_pid = fork; |
| 1218 | |
| 1219 | child_run_test if (!$child_pid); |
| 1220 | |
| 1221 | $full_line = ""; |
| 1222 | |
| 1223 | do { |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1224 | $line = wait_for_input($monitor_fp, 1); |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1225 | if (defined($line)) { |
| 1226 | |
| 1227 | # we are not guaranteed to get a full line |
| 1228 | $full_line .= $line; |
Steven Rostedt | 8ea0e06 | 2011-03-08 09:44:35 -0500 | [diff] [blame] | 1229 | doprint $line; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1230 | |
| 1231 | if ($full_line =~ /call trace:/i) { |
| 1232 | $bug = 1; |
| 1233 | } |
| 1234 | |
| 1235 | if ($full_line =~ /Kernel panic -/) { |
| 1236 | $bug = 1; |
| 1237 | } |
| 1238 | |
| 1239 | if ($line =~ /\n/) { |
| 1240 | $full_line = ""; |
| 1241 | } |
| 1242 | } |
| 1243 | } while (!$child_done && !$bug); |
| 1244 | |
| 1245 | if ($bug) { |
Steven Rostedt | 8ea0e06 | 2011-03-08 09:44:35 -0500 | [diff] [blame] | 1246 | my $failure_start = time; |
| 1247 | my $now; |
| 1248 | do { |
| 1249 | $line = wait_for_input($monitor_fp, 1); |
| 1250 | if (defined($line)) { |
| 1251 | doprint $line; |
| 1252 | } |
| 1253 | $now = time; |
| 1254 | if ($now - $failure_start >= $stop_after_failure) { |
| 1255 | last; |
| 1256 | } |
| 1257 | } while (defined($line)); |
| 1258 | |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1259 | doprint "Detected kernel crash!\n"; |
| 1260 | # kill the child with extreme prejudice |
| 1261 | kill 9, $child_pid; |
| 1262 | } |
| 1263 | |
| 1264 | waitpid $child_pid, 0; |
| 1265 | $child_exit = $?; |
| 1266 | |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1267 | if ($bug || $child_exit) { |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1268 | return 0 if $in_bisect; |
| 1269 | fail "test failed" and return 0; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1270 | } |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1271 | return 1; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1274 | sub run_git_bisect { |
| 1275 | my ($command) = @_; |
| 1276 | |
| 1277 | doprint "$command ... "; |
| 1278 | |
| 1279 | my $output = `$command 2>&1`; |
| 1280 | my $ret = $?; |
| 1281 | |
| 1282 | logit $output; |
| 1283 | |
| 1284 | if ($ret) { |
| 1285 | doprint "FAILED\n"; |
| 1286 | dodie "Failed to git bisect"; |
| 1287 | } |
| 1288 | |
| 1289 | doprint "SUCCESS\n"; |
| 1290 | if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) { |
| 1291 | doprint "$1 [$2]\n"; |
| 1292 | } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) { |
| 1293 | $bisect_bad = $1; |
| 1294 | doprint "Found bad commit... $1\n"; |
| 1295 | return 0; |
| 1296 | } else { |
| 1297 | # we already logged it, just print it now. |
| 1298 | print $output; |
| 1299 | } |
| 1300 | |
| 1301 | return 1; |
| 1302 | } |
| 1303 | |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 1304 | sub bisect_reboot { |
| 1305 | doprint "Reboot and sleep $bisect_sleep_time seconds\n"; |
| 1306 | reboot; |
| 1307 | start_monitor; |
| 1308 | wait_for_monitor $bisect_sleep_time; |
| 1309 | end_monitor; |
| 1310 | } |
| 1311 | |
| 1312 | # returns 1 on success, 0 on failure, -1 on skip |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1313 | sub run_bisect_test { |
| 1314 | my ($type, $buildtype) = @_; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1315 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1316 | my $failed = 0; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1317 | my $result; |
| 1318 | my $output; |
| 1319 | my $ret; |
| 1320 | |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1321 | $in_bisect = 1; |
| 1322 | |
| 1323 | build $buildtype or $failed = 1; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1324 | |
| 1325 | if ($type ne "build") { |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 1326 | if ($failed && $bisect_skip) { |
| 1327 | $in_bisect = 0; |
| 1328 | return -1; |
| 1329 | } |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1330 | dodie "Failed on build" if $failed; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1331 | |
| 1332 | # Now boot the box |
| 1333 | get_grub_index; |
| 1334 | get_version; |
| 1335 | install; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1336 | |
| 1337 | start_monitor; |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1338 | monitor or $failed = 1; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1339 | |
| 1340 | if ($type ne "boot") { |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 1341 | if ($failed && $bisect_skip) { |
| 1342 | end_monitor; |
| 1343 | bisect_reboot; |
| 1344 | $in_bisect = 0; |
| 1345 | return -1; |
| 1346 | } |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1347 | dodie "Failed on boot" if $failed; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1348 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1349 | do_run_test or $failed = 1; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1350 | } |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1351 | end_monitor; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | if ($failed) { |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1355 | $result = 0; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1356 | } else { |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1357 | $result = 1; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1358 | } |
Steven Rostedt | 4025bc6 | 2011-05-20 09:16:29 -0400 | [diff] [blame] | 1359 | |
| 1360 | # reboot the box to a kernel we can ssh to |
| 1361 | if ($type ne "build") { |
| 1362 | bisect_reboot; |
| 1363 | } |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1364 | $in_bisect = 0; |
| 1365 | |
| 1366 | return $result; |
| 1367 | } |
| 1368 | |
| 1369 | sub run_bisect { |
| 1370 | my ($type) = @_; |
| 1371 | my $buildtype = "oldconfig"; |
| 1372 | |
| 1373 | # We should have a minconfig to use? |
| 1374 | if (defined($minconfig)) { |
| 1375 | $buildtype = "useconfig:$minconfig"; |
| 1376 | } |
| 1377 | |
| 1378 | my $ret = run_bisect_test $type, $buildtype; |
| 1379 | |
Steven Rostedt | c960bb9 | 2011-03-08 09:22:39 -0500 | [diff] [blame] | 1380 | if ($bisect_manual) { |
| 1381 | $ret = answer_bisect; |
| 1382 | } |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1383 | |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 1384 | # Are we looking for where it worked, not failed? |
| 1385 | if ($reverse_bisect) { |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1386 | $ret = !$ret; |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 1389 | if ($ret > 0) { |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1390 | return "good"; |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 1391 | } elsif ($ret == 0) { |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1392 | return "bad"; |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 1393 | } elsif ($bisect_skip) { |
| 1394 | doprint "HIT A BAD COMMIT ... SKIPPING\n"; |
| 1395 | return "skip"; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1396 | } |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | sub bisect { |
| 1400 | my ($i) = @_; |
| 1401 | |
| 1402 | my $result; |
| 1403 | |
| 1404 | die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"})); |
| 1405 | die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"})); |
| 1406 | die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"})); |
| 1407 | |
| 1408 | my $good = $opt{"BISECT_GOOD[$i]"}; |
| 1409 | my $bad = $opt{"BISECT_BAD[$i]"}; |
| 1410 | my $type = $opt{"BISECT_TYPE[$i]"}; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1411 | my $start = $opt{"BISECT_START[$i]"}; |
| 1412 | my $replay = $opt{"BISECT_REPLAY[$i]"}; |
Steven Rostedt | 3410f6f | 2011-03-08 09:38:12 -0500 | [diff] [blame] | 1413 | my $start_files = $opt{"BISECT_FILES[$i]"}; |
| 1414 | |
| 1415 | if (defined($start_files)) { |
| 1416 | $start_files = " -- " . $start_files; |
| 1417 | } else { |
| 1418 | $start_files = ""; |
| 1419 | } |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1420 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 1421 | # convert to true sha1's |
| 1422 | $good = get_sha1($good); |
| 1423 | $bad = get_sha1($bad); |
| 1424 | |
Steven Rostedt | d6ce2a0 | 2010-11-02 14:58:05 -0400 | [diff] [blame] | 1425 | if (defined($opt{"BISECT_REVERSE[$i]"}) && |
| 1426 | $opt{"BISECT_REVERSE[$i]"} == 1) { |
| 1427 | doprint "Performing a reverse bisect (bad is good, good is bad!)\n"; |
| 1428 | $reverse_bisect = 1; |
| 1429 | } else { |
| 1430 | $reverse_bisect = 0; |
| 1431 | } |
| 1432 | |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 1433 | # Can't have a test without having a test to run |
| 1434 | if ($type eq "test" && !defined($run_test)) { |
| 1435 | $type = "boot"; |
| 1436 | } |
| 1437 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1438 | my $check = $opt{"BISECT_CHECK[$i]"}; |
| 1439 | if (defined($check) && $check ne "0") { |
| 1440 | |
| 1441 | # get current HEAD |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 1442 | my $head = get_sha1("HEAD"); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1443 | |
| 1444 | if ($check ne "good") { |
| 1445 | doprint "TESTING BISECT BAD [$bad]\n"; |
| 1446 | run_command "git checkout $bad" or |
| 1447 | die "Failed to checkout $bad"; |
| 1448 | |
| 1449 | $result = run_bisect $type; |
| 1450 | |
| 1451 | if ($result ne "bad") { |
| 1452 | fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0; |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | if ($check ne "bad") { |
| 1457 | doprint "TESTING BISECT GOOD [$good]\n"; |
| 1458 | run_command "git checkout $good" or |
| 1459 | die "Failed to checkout $good"; |
| 1460 | |
| 1461 | $result = run_bisect $type; |
| 1462 | |
| 1463 | if ($result ne "good") { |
| 1464 | fail "Tested BISECT_GOOD [$good] and it failed" and return 0; |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | # checkout where we started |
| 1469 | run_command "git checkout $head" or |
| 1470 | die "Failed to checkout $head"; |
| 1471 | } |
| 1472 | |
Steven Rostedt | 3410f6f | 2011-03-08 09:38:12 -0500 | [diff] [blame] | 1473 | run_command "git bisect start$start_files" or |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1474 | dodie "could not start bisect"; |
| 1475 | |
| 1476 | run_command "git bisect good $good" or |
| 1477 | dodie "could not set bisect good to $good"; |
| 1478 | |
| 1479 | run_git_bisect "git bisect bad $bad" or |
| 1480 | dodie "could not set bisect bad to $bad"; |
| 1481 | |
| 1482 | if (defined($replay)) { |
| 1483 | run_command "git bisect replay $replay" or |
| 1484 | dodie "failed to run replay"; |
| 1485 | } |
| 1486 | |
| 1487 | if (defined($start)) { |
| 1488 | run_command "git checkout $start" or |
| 1489 | dodie "failed to checkout $start"; |
| 1490 | } |
| 1491 | |
| 1492 | my $test; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1493 | do { |
| 1494 | $result = run_bisect $type; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 1495 | $test = run_git_bisect "git bisect $result"; |
| 1496 | } while ($test); |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1497 | |
| 1498 | run_command "git bisect log" or |
| 1499 | dodie "could not capture git bisect log"; |
| 1500 | |
| 1501 | run_command "git bisect reset" or |
| 1502 | dodie "could not reset git bisect"; |
| 1503 | |
| 1504 | doprint "Bad commit was [$bisect_bad]\n"; |
| 1505 | |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1506 | success $i; |
| 1507 | } |
| 1508 | |
| 1509 | my %config_ignore; |
| 1510 | my %config_set; |
| 1511 | |
| 1512 | my %config_list; |
| 1513 | my %null_config; |
| 1514 | |
| 1515 | my %dependency; |
| 1516 | |
| 1517 | sub process_config_ignore { |
| 1518 | my ($config) = @_; |
| 1519 | |
| 1520 | open (IN, $config) |
| 1521 | or dodie "Failed to read $config"; |
| 1522 | |
| 1523 | while (<IN>) { |
Steven Rostedt | 9bf7174 | 2011-06-01 23:27:19 -0400 | [diff] [blame] | 1524 | if (/^((CONFIG\S*)=.*)/) { |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1525 | $config_ignore{$2} = $1; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | close(IN); |
| 1530 | } |
| 1531 | |
| 1532 | sub read_current_config { |
| 1533 | my ($config_ref) = @_; |
| 1534 | |
| 1535 | %{$config_ref} = (); |
| 1536 | undef %{$config_ref}; |
| 1537 | |
| 1538 | my @key = keys %{$config_ref}; |
| 1539 | if ($#key >= 0) { |
| 1540 | print "did not delete!\n"; |
| 1541 | exit; |
| 1542 | } |
| 1543 | open (IN, "$output_config"); |
| 1544 | |
| 1545 | while (<IN>) { |
| 1546 | if (/^(CONFIG\S+)=(.*)/) { |
| 1547 | ${$config_ref}{$1} = $2; |
| 1548 | } |
| 1549 | } |
| 1550 | close(IN); |
| 1551 | } |
| 1552 | |
| 1553 | sub get_dependencies { |
| 1554 | my ($config) = @_; |
| 1555 | |
| 1556 | my $arr = $dependency{$config}; |
| 1557 | if (!defined($arr)) { |
| 1558 | return (); |
| 1559 | } |
| 1560 | |
| 1561 | my @deps = @{$arr}; |
| 1562 | |
| 1563 | foreach my $dep (@{$arr}) { |
| 1564 | print "ADD DEP $dep\n"; |
| 1565 | @deps = (@deps, get_dependencies $dep); |
| 1566 | } |
| 1567 | |
| 1568 | return @deps; |
| 1569 | } |
| 1570 | |
| 1571 | sub create_config { |
| 1572 | my @configs = @_; |
| 1573 | |
| 1574 | open(OUT, ">$output_config") or dodie "Can not write to $output_config"; |
| 1575 | |
| 1576 | foreach my $config (@configs) { |
| 1577 | print OUT "$config_set{$config}\n"; |
| 1578 | my @deps = get_dependencies $config; |
| 1579 | foreach my $dep (@deps) { |
| 1580 | print OUT "$config_set{$dep}\n"; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | foreach my $config (keys %config_ignore) { |
| 1585 | print OUT "$config_ignore{$config}\n"; |
| 1586 | } |
| 1587 | close(OUT); |
| 1588 | |
| 1589 | # exit; |
Steven Rostedt | 612b9e9 | 2011-03-07 13:27:43 -0500 | [diff] [blame] | 1590 | make_oldconfig ""; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | sub compare_configs { |
| 1594 | my (%a, %b) = @_; |
| 1595 | |
| 1596 | foreach my $item (keys %a) { |
| 1597 | if (!defined($b{$item})) { |
| 1598 | print "diff $item\n"; |
| 1599 | return 1; |
| 1600 | } |
| 1601 | delete $b{$item}; |
| 1602 | } |
| 1603 | |
| 1604 | my @keys = keys %b; |
| 1605 | if ($#keys) { |
| 1606 | print "diff2 $keys[0]\n"; |
| 1607 | } |
| 1608 | return -1 if ($#keys >= 0); |
| 1609 | |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | sub run_config_bisect_test { |
| 1614 | my ($type) = @_; |
| 1615 | |
| 1616 | return run_bisect_test $type, "oldconfig"; |
| 1617 | } |
| 1618 | |
| 1619 | sub process_passed { |
| 1620 | my (%configs) = @_; |
| 1621 | |
| 1622 | doprint "These configs had no failure: (Enabling them for further compiles)\n"; |
| 1623 | # Passed! All these configs are part of a good compile. |
| 1624 | # Add them to the min options. |
| 1625 | foreach my $config (keys %configs) { |
| 1626 | if (defined($config_list{$config})) { |
| 1627 | doprint " removing $config\n"; |
| 1628 | $config_ignore{$config} = $config_list{$config}; |
| 1629 | delete $config_list{$config}; |
| 1630 | } |
| 1631 | } |
Steven Rostedt | f1a2785 | 2010-11-11 11:34:38 -0500 | [diff] [blame] | 1632 | doprint "config copied to $outputdir/config_good\n"; |
| 1633 | run_command "cp -f $output_config $outputdir/config_good"; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | sub process_failed { |
| 1637 | my ($config) = @_; |
| 1638 | |
| 1639 | doprint "\n\n***************************************\n"; |
| 1640 | doprint "Found bad config: $config\n"; |
| 1641 | doprint "***************************************\n\n"; |
| 1642 | } |
| 1643 | |
| 1644 | sub run_config_bisect { |
| 1645 | |
| 1646 | my @start_list = keys %config_list; |
| 1647 | |
| 1648 | if ($#start_list < 0) { |
| 1649 | doprint "No more configs to test!!!\n"; |
| 1650 | return -1; |
| 1651 | } |
| 1652 | |
| 1653 | doprint "***** RUN TEST ***\n"; |
| 1654 | my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"}; |
| 1655 | my $ret; |
| 1656 | my %current_config; |
| 1657 | |
| 1658 | my $count = $#start_list + 1; |
| 1659 | doprint " $count configs to test\n"; |
| 1660 | |
| 1661 | my $half = int($#start_list / 2); |
| 1662 | |
| 1663 | do { |
| 1664 | my @tophalf = @start_list[0 .. $half]; |
| 1665 | |
| 1666 | create_config @tophalf; |
| 1667 | read_current_config \%current_config; |
| 1668 | |
| 1669 | $count = $#tophalf + 1; |
| 1670 | doprint "Testing $count configs\n"; |
| 1671 | my $found = 0; |
| 1672 | # make sure we test something |
| 1673 | foreach my $config (@tophalf) { |
| 1674 | if (defined($current_config{$config})) { |
| 1675 | logit " $config\n"; |
| 1676 | $found = 1; |
| 1677 | } |
| 1678 | } |
| 1679 | if (!$found) { |
| 1680 | # try the other half |
| 1681 | doprint "Top half produced no set configs, trying bottom half\n"; |
Steven Rostedt | 4c8cc55 | 2011-06-01 23:22:30 -0400 | [diff] [blame] | 1682 | @tophalf = @start_list[$half + 1 .. $#start_list]; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1683 | create_config @tophalf; |
| 1684 | read_current_config \%current_config; |
| 1685 | foreach my $config (@tophalf) { |
| 1686 | if (defined($current_config{$config})) { |
| 1687 | logit " $config\n"; |
| 1688 | $found = 1; |
| 1689 | } |
| 1690 | } |
| 1691 | if (!$found) { |
| 1692 | doprint "Failed: Can't make new config with current configs\n"; |
| 1693 | foreach my $config (@start_list) { |
| 1694 | doprint " CONFIG: $config\n"; |
| 1695 | } |
| 1696 | return -1; |
| 1697 | } |
| 1698 | $count = $#tophalf + 1; |
| 1699 | doprint "Testing $count configs\n"; |
| 1700 | } |
| 1701 | |
| 1702 | $ret = run_config_bisect_test $type; |
Steven Rostedt | c960bb9 | 2011-03-08 09:22:39 -0500 | [diff] [blame] | 1703 | if ($bisect_manual) { |
| 1704 | $ret = answer_bisect; |
| 1705 | } |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1706 | if ($ret) { |
| 1707 | process_passed %current_config; |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
| 1711 | doprint "This config had a failure.\n"; |
| 1712 | doprint "Removing these configs that were not set in this config:\n"; |
Steven Rostedt | f1a2785 | 2010-11-11 11:34:38 -0500 | [diff] [blame] | 1713 | doprint "config copied to $outputdir/config_bad\n"; |
| 1714 | run_command "cp -f $output_config $outputdir/config_bad"; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1715 | |
| 1716 | # A config exists in this group that was bad. |
| 1717 | foreach my $config (keys %config_list) { |
| 1718 | if (!defined($current_config{$config})) { |
| 1719 | doprint " removing $config\n"; |
| 1720 | delete $config_list{$config}; |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | @start_list = @tophalf; |
| 1725 | |
| 1726 | if ($#start_list == 0) { |
| 1727 | process_failed $start_list[0]; |
| 1728 | return 1; |
| 1729 | } |
| 1730 | |
| 1731 | # remove half the configs we are looking at and see if |
| 1732 | # they are good. |
| 1733 | $half = int($#start_list / 2); |
Steven Rostedt | 4c8cc55 | 2011-06-01 23:22:30 -0400 | [diff] [blame] | 1734 | } while ($#start_list > 0); |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1735 | |
Steven Rostedt | c960bb9 | 2011-03-08 09:22:39 -0500 | [diff] [blame] | 1736 | # we found a single config, try it again unless we are running manually |
| 1737 | |
| 1738 | if ($bisect_manual) { |
| 1739 | process_failed $start_list[0]; |
| 1740 | return 1; |
| 1741 | } |
| 1742 | |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1743 | my @tophalf = @start_list[0 .. 0]; |
| 1744 | |
| 1745 | $ret = run_config_bisect_test $type; |
| 1746 | if ($ret) { |
| 1747 | process_passed %current_config; |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
| 1751 | process_failed $start_list[0]; |
| 1752 | return 1; |
| 1753 | } |
| 1754 | |
| 1755 | sub config_bisect { |
| 1756 | my ($i) = @_; |
| 1757 | |
| 1758 | my $start_config = $opt{"CONFIG_BISECT[$i]"}; |
| 1759 | |
| 1760 | my $tmpconfig = "$tmpdir/use_config"; |
| 1761 | |
Steven Rostedt | 30f75da | 2011-06-13 10:35:35 -0400 | [diff] [blame] | 1762 | if (defined($config_bisect_good)) { |
| 1763 | process_config_ignore $config_bisect_good; |
| 1764 | } |
| 1765 | |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1766 | # Make the file with the bad config and the min config |
| 1767 | if (defined($minconfig)) { |
| 1768 | # read the min config for things to ignore |
| 1769 | run_command "cp $minconfig $tmpconfig" or |
| 1770 | dodie "failed to copy $minconfig to $tmpconfig"; |
| 1771 | } else { |
| 1772 | unlink $tmpconfig; |
| 1773 | } |
| 1774 | |
| 1775 | # Add other configs |
| 1776 | if (defined($addconfig)) { |
| 1777 | run_command "cat $addconfig >> $tmpconfig" or |
| 1778 | dodie "failed to append $addconfig"; |
| 1779 | } |
| 1780 | |
| 1781 | my $defconfig = ""; |
| 1782 | if (-f $tmpconfig) { |
| 1783 | $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig"; |
| 1784 | process_config_ignore $tmpconfig; |
| 1785 | } |
| 1786 | |
| 1787 | # now process the start config |
| 1788 | run_command "cp $start_config $output_config" or |
| 1789 | dodie "failed to copy $start_config to $output_config"; |
| 1790 | |
| 1791 | # read directly what we want to check |
| 1792 | my %config_check; |
| 1793 | open (IN, $output_config) |
| 1794 | or dodie "faied to open $output_config"; |
| 1795 | |
| 1796 | while (<IN>) { |
| 1797 | if (/^((CONFIG\S*)=.*)/) { |
| 1798 | $config_check{$2} = $1; |
| 1799 | } |
| 1800 | } |
| 1801 | close(IN); |
| 1802 | |
| 1803 | # Now run oldconfig with the minconfig (and addconfigs) |
Steven Rostedt | 612b9e9 | 2011-03-07 13:27:43 -0500 | [diff] [blame] | 1804 | make_oldconfig $defconfig; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 1805 | |
| 1806 | # check to see what we lost (or gained) |
| 1807 | open (IN, $output_config) |
| 1808 | or dodie "Failed to read $start_config"; |
| 1809 | |
| 1810 | my %removed_configs; |
| 1811 | my %added_configs; |
| 1812 | |
| 1813 | while (<IN>) { |
| 1814 | if (/^((CONFIG\S*)=.*)/) { |
| 1815 | # save off all options |
| 1816 | $config_set{$2} = $1; |
| 1817 | if (defined($config_check{$2})) { |
| 1818 | if (defined($config_ignore{$2})) { |
| 1819 | $removed_configs{$2} = $1; |
| 1820 | } else { |
| 1821 | $config_list{$2} = $1; |
| 1822 | } |
| 1823 | } elsif (!defined($config_ignore{$2})) { |
| 1824 | $added_configs{$2} = $1; |
| 1825 | $config_list{$2} = $1; |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | close(IN); |
| 1830 | |
| 1831 | my @confs = keys %removed_configs; |
| 1832 | if ($#confs >= 0) { |
| 1833 | doprint "Configs overridden by default configs and removed from check:\n"; |
| 1834 | foreach my $config (@confs) { |
| 1835 | doprint " $config\n"; |
| 1836 | } |
| 1837 | } |
| 1838 | @confs = keys %added_configs; |
| 1839 | if ($#confs >= 0) { |
| 1840 | doprint "Configs appearing in make oldconfig and added:\n"; |
| 1841 | foreach my $config (@confs) { |
| 1842 | doprint " $config\n"; |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | my %config_test; |
| 1847 | my $once = 0; |
| 1848 | |
| 1849 | # Sometimes kconfig does weird things. We must make sure |
| 1850 | # that the config we autocreate has everything we need |
| 1851 | # to test, otherwise we may miss testing configs, or |
| 1852 | # may not be able to create a new config. |
| 1853 | # Here we create a config with everything set. |
| 1854 | create_config (keys %config_list); |
| 1855 | read_current_config \%config_test; |
| 1856 | foreach my $config (keys %config_list) { |
| 1857 | if (!defined($config_test{$config})) { |
| 1858 | if (!$once) { |
| 1859 | $once = 1; |
| 1860 | doprint "Configs not produced by kconfig (will not be checked):\n"; |
| 1861 | } |
| 1862 | doprint " $config\n"; |
| 1863 | delete $config_list{$config}; |
| 1864 | } |
| 1865 | } |
| 1866 | my $ret; |
| 1867 | do { |
| 1868 | $ret = run_config_bisect; |
| 1869 | } while (!$ret); |
| 1870 | |
| 1871 | return $ret if ($ret < 0); |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 1872 | |
| 1873 | success $i; |
| 1874 | } |
| 1875 | |
Steven Rostedt | 27d934b | 2011-05-20 09:18:18 -0400 | [diff] [blame] | 1876 | sub patchcheck_reboot { |
| 1877 | doprint "Reboot and sleep $patchcheck_sleep_time seconds\n"; |
| 1878 | reboot; |
| 1879 | start_monitor; |
| 1880 | wait_for_monitor $patchcheck_sleep_time; |
| 1881 | end_monitor; |
| 1882 | } |
| 1883 | |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1884 | sub patchcheck { |
| 1885 | my ($i) = @_; |
| 1886 | |
| 1887 | die "PATCHCHECK_START[$i] not defined\n" |
| 1888 | if (!defined($opt{"PATCHCHECK_START[$i]"})); |
| 1889 | die "PATCHCHECK_TYPE[$i] not defined\n" |
| 1890 | if (!defined($opt{"PATCHCHECK_TYPE[$i]"})); |
| 1891 | |
| 1892 | my $start = $opt{"PATCHCHECK_START[$i]"}; |
| 1893 | |
| 1894 | my $end = "HEAD"; |
| 1895 | if (defined($opt{"PATCHCHECK_END[$i]"})) { |
| 1896 | $end = $opt{"PATCHCHECK_END[$i]"}; |
| 1897 | } |
| 1898 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 1899 | # Get the true sha1's since we can use things like HEAD~3 |
| 1900 | $start = get_sha1($start); |
| 1901 | $end = get_sha1($end); |
| 1902 | |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1903 | my $type = $opt{"PATCHCHECK_TYPE[$i]"}; |
| 1904 | |
| 1905 | # Can't have a test without having a test to run |
| 1906 | if ($type eq "test" && !defined($run_test)) { |
| 1907 | $type = "boot"; |
| 1908 | } |
| 1909 | |
| 1910 | open (IN, "git log --pretty=oneline $end|") or |
| 1911 | dodie "could not get git list"; |
| 1912 | |
| 1913 | my @list; |
| 1914 | |
| 1915 | while (<IN>) { |
| 1916 | chomp; |
| 1917 | $list[$#list+1] = $_; |
| 1918 | last if (/^$start/); |
| 1919 | } |
| 1920 | close(IN); |
| 1921 | |
| 1922 | if ($list[$#list] !~ /^$start/) { |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1923 | fail "SHA1 $start not found"; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | # go backwards in the list |
| 1927 | @list = reverse @list; |
| 1928 | |
| 1929 | my $save_clean = $noclean; |
| 1930 | |
| 1931 | $in_patchcheck = 1; |
| 1932 | foreach my $item (@list) { |
| 1933 | my $sha1 = $item; |
| 1934 | $sha1 =~ s/^([[:xdigit:]]+).*/$1/; |
| 1935 | |
| 1936 | doprint "\nProcessing commit $item\n\n"; |
| 1937 | |
| 1938 | run_command "git checkout $sha1" or |
| 1939 | die "Failed to checkout $sha1"; |
| 1940 | |
| 1941 | # only clean on the first and last patch |
| 1942 | if ($item eq $list[0] || |
| 1943 | $item eq $list[$#list]) { |
| 1944 | $noclean = $save_clean; |
| 1945 | } else { |
| 1946 | $noclean = 1; |
| 1947 | } |
| 1948 | |
| 1949 | if (defined($minconfig)) { |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1950 | build "useconfig:$minconfig" or return 0; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1951 | } else { |
| 1952 | # ?? no config to use? |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1953 | build "oldconfig" or return 0; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1954 | } |
| 1955 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1956 | check_buildlog $sha1 or return 0; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1957 | |
| 1958 | next if ($type eq "build"); |
| 1959 | |
| 1960 | get_grub_index; |
| 1961 | get_version; |
| 1962 | install; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1963 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 1964 | my $failed = 0; |
| 1965 | |
| 1966 | start_monitor; |
| 1967 | monitor or $failed = 1; |
| 1968 | |
| 1969 | if (!$failed && $type ne "boot"){ |
| 1970 | do_run_test or $failed = 1; |
| 1971 | } |
| 1972 | end_monitor; |
| 1973 | return 0 if ($failed); |
| 1974 | |
Steven Rostedt | 27d934b | 2011-05-20 09:18:18 -0400 | [diff] [blame] | 1975 | patchcheck_reboot; |
| 1976 | |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1977 | } |
| 1978 | $in_patchcheck = 0; |
| 1979 | success $i; |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 1980 | |
| 1981 | return 1; |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 1982 | } |
| 1983 | |
Steven Rostedt | 8d1491b | 2010-11-18 15:39:48 -0500 | [diff] [blame] | 1984 | $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n"; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 1985 | |
Steven Rostedt | 8d1491b | 2010-11-18 15:39:48 -0500 | [diff] [blame] | 1986 | if ($#ARGV == 0) { |
| 1987 | $ktest_config = $ARGV[0]; |
| 1988 | if (! -f $ktest_config) { |
| 1989 | print "$ktest_config does not exist.\n"; |
| 1990 | my $ans; |
| 1991 | for (;;) { |
| 1992 | print "Create it? [Y/n] "; |
| 1993 | $ans = <STDIN>; |
| 1994 | chomp $ans; |
| 1995 | if ($ans =~ /^\s*$/) { |
| 1996 | $ans = "y"; |
| 1997 | } |
| 1998 | last if ($ans =~ /^y$/i || $ans =~ /^n$/i); |
| 1999 | print "Please answer either 'y' or 'n'.\n"; |
| 2000 | } |
| 2001 | if ($ans !~ /^y$/i) { |
| 2002 | exit 0; |
| 2003 | } |
| 2004 | } |
| 2005 | } else { |
| 2006 | $ktest_config = "ktest.conf"; |
| 2007 | } |
| 2008 | |
| 2009 | if (! -f $ktest_config) { |
| 2010 | open(OUT, ">$ktest_config") or die "Can not create $ktest_config"; |
| 2011 | print OUT << "EOF" |
| 2012 | # Generated by ktest.pl |
| 2013 | # |
| 2014 | # Define each test with TEST_START |
| 2015 | # The config options below it will override the defaults |
| 2016 | TEST_START |
| 2017 | |
| 2018 | DEFAULTS |
| 2019 | EOF |
| 2020 | ; |
| 2021 | close(OUT); |
| 2022 | } |
| 2023 | read_config $ktest_config; |
| 2024 | |
| 2025 | # Append any configs entered in manually to the config file. |
| 2026 | my @new_configs = keys %entered_configs; |
| 2027 | if ($#new_configs >= 0) { |
| 2028 | print "\nAppending entered in configs to $ktest_config\n"; |
| 2029 | open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config"; |
| 2030 | foreach my $config (@new_configs) { |
| 2031 | print OUT "$config = $entered_configs{$config}\n"; |
| 2032 | $opt{$config} = $entered_configs{$config}; |
| 2033 | } |
| 2034 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2035 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 2036 | if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) { |
| 2037 | unlink $opt{"LOG_FILE"}; |
| 2038 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2039 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 2040 | doprint "\n\nSTARTING AUTOMATED TESTS\n\n"; |
| 2041 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 2042 | for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) { |
| 2043 | |
| 2044 | if (!$i) { |
| 2045 | doprint "DEFAULT OPTIONS:\n"; |
| 2046 | } else { |
| 2047 | doprint "\nTEST $i OPTIONS"; |
| 2048 | if (defined($repeat_tests{$i})) { |
| 2049 | $repeat = $repeat_tests{$i}; |
| 2050 | doprint " ITERATE $repeat"; |
| 2051 | } |
| 2052 | doprint "\n"; |
| 2053 | } |
| 2054 | |
| 2055 | foreach my $option (sort keys %opt) { |
| 2056 | |
| 2057 | if ($option =~ /\[(\d+)\]$/) { |
| 2058 | next if ($i != $1); |
| 2059 | } else { |
| 2060 | next if ($i); |
| 2061 | } |
| 2062 | |
| 2063 | doprint "$option = $opt{$option}\n"; |
| 2064 | } |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 2065 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2066 | |
Steven Rostedt | 2a62512 | 2011-05-20 15:48:59 -0400 | [diff] [blame] | 2067 | sub __set_test_option { |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 2068 | my ($name, $i) = @_; |
| 2069 | |
| 2070 | my $option = "$name\[$i\]"; |
| 2071 | |
| 2072 | if (defined($opt{$option})) { |
| 2073 | return $opt{$option}; |
| 2074 | } |
| 2075 | |
Steven Rostedt | a57419b | 2010-11-02 15:13:54 -0400 | [diff] [blame] | 2076 | foreach my $test (keys %repeat_tests) { |
| 2077 | if ($i >= $test && |
| 2078 | $i < $test + $repeat_tests{$test}) { |
| 2079 | $option = "$name\[$test\]"; |
| 2080 | if (defined($opt{$option})) { |
| 2081 | return $opt{$option}; |
| 2082 | } |
| 2083 | } |
| 2084 | } |
| 2085 | |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 2086 | if (defined($opt{$name})) { |
| 2087 | return $opt{$name}; |
| 2088 | } |
| 2089 | |
| 2090 | return undef; |
| 2091 | } |
| 2092 | |
Steven Rostedt | 2a62512 | 2011-05-20 15:48:59 -0400 | [diff] [blame] | 2093 | sub eval_option { |
| 2094 | my ($option, $i) = @_; |
| 2095 | |
| 2096 | # Add space to evaluate the character before $ |
| 2097 | $option = " $option"; |
| 2098 | my $retval = ""; |
| 2099 | |
| 2100 | while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) { |
| 2101 | my $start = $1; |
| 2102 | my $var = $2; |
| 2103 | my $end = $3; |
| 2104 | |
| 2105 | # Append beginning of line |
| 2106 | $retval = "$retval$start"; |
| 2107 | |
| 2108 | # If the iteration option OPT[$i] exists, then use that. |
| 2109 | # otherwise see if the default OPT (without [$i]) exists. |
| 2110 | |
| 2111 | my $o = "$var\[$i\]"; |
| 2112 | |
| 2113 | if (defined($opt{$o})) { |
| 2114 | $o = $opt{$o}; |
| 2115 | $retval = "$retval$o"; |
| 2116 | } elsif (defined($opt{$var})) { |
| 2117 | $o = $opt{$var}; |
| 2118 | $retval = "$retval$o"; |
| 2119 | } else { |
| 2120 | $retval = "$retval\$\{$var\}"; |
| 2121 | } |
| 2122 | |
| 2123 | $option = $end; |
| 2124 | } |
| 2125 | |
| 2126 | $retval = "$retval$option"; |
| 2127 | |
| 2128 | $retval =~ s/^ //; |
| 2129 | |
| 2130 | return $retval; |
| 2131 | } |
| 2132 | |
| 2133 | sub set_test_option { |
| 2134 | my ($name, $i) = @_; |
| 2135 | |
| 2136 | my $option = __set_test_option($name, $i); |
| 2137 | return $option if (!defined($option)); |
| 2138 | |
| 2139 | my $prev = ""; |
| 2140 | |
| 2141 | # Since an option can evaluate to another option, |
| 2142 | # keep iterating until we do not evaluate any more |
| 2143 | # options. |
| 2144 | my $r = 0; |
| 2145 | while ($prev ne $option) { |
| 2146 | # Check for recursive evaluations. |
| 2147 | # 100 deep should be more than enough. |
| 2148 | if ($r++ > 100) { |
| 2149 | die "Over 100 evaluations accurred with $name\n" . |
| 2150 | "Check for recursive variables\n"; |
| 2151 | } |
| 2152 | $prev = $option; |
| 2153 | $option = eval_option($option, $i); |
| 2154 | } |
| 2155 | |
| 2156 | return $option; |
| 2157 | } |
| 2158 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2159 | # First we need to do is the builds |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2160 | for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2161 | |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 2162 | $iteration = $i; |
| 2163 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2164 | my $makecmd = set_test_option("MAKE_CMD", $i); |
| 2165 | |
| 2166 | $machine = set_test_option("MACHINE", $i); |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 2167 | $ssh_user = set_test_option("SSH_USER", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2168 | $tmpdir = set_test_option("TMP_DIR", $i); |
| 2169 | $outputdir = set_test_option("OUTPUT_DIR", $i); |
| 2170 | $builddir = set_test_option("BUILD_DIR", $i); |
| 2171 | $test_type = set_test_option("TEST_TYPE", $i); |
| 2172 | $build_type = set_test_option("BUILD_TYPE", $i); |
| 2173 | $build_options = set_test_option("BUILD_OPTIONS", $i); |
| 2174 | $power_cycle = set_test_option("POWER_CYCLE", $i); |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 2175 | $reboot = set_test_option("REBOOT", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2176 | $noclean = set_test_option("BUILD_NOCLEAN", $i); |
| 2177 | $minconfig = set_test_option("MIN_CONFIG", $i); |
| 2178 | $run_test = set_test_option("TEST", $i); |
| 2179 | $addconfig = set_test_option("ADD_CONFIG", $i); |
| 2180 | $reboot_type = set_test_option("REBOOT_TYPE", $i); |
| 2181 | $grub_menu = set_test_option("GRUB_MENU", $i); |
Steven Rostedt | 8b37ca8 | 2010-11-02 14:58:33 -0400 | [diff] [blame] | 2182 | $post_install = set_test_option("POST_INSTALL", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2183 | $reboot_script = set_test_option("REBOOT_SCRIPT", $i); |
| 2184 | $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i); |
| 2185 | $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i); |
| 2186 | $die_on_failure = set_test_option("DIE_ON_FAILURE", $i); |
| 2187 | $power_off = set_test_option("POWER_OFF", $i); |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 2188 | $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i); |
| 2189 | $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2190 | $sleep_time = set_test_option("SLEEP_TIME", $i); |
| 2191 | $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); |
Steven Rostedt | 27d934b | 2011-05-20 09:18:18 -0400 | [diff] [blame] | 2192 | $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i); |
Steven Rostedt | c960bb9 | 2011-03-08 09:22:39 -0500 | [diff] [blame] | 2193 | $bisect_manual = set_test_option("BISECT_MANUAL", $i); |
Steven Rostedt | c23dca7 | 2011-03-08 09:26:31 -0500 | [diff] [blame] | 2194 | $bisect_skip = set_test_option("BISECT_SKIP", $i); |
Steven Rostedt | 30f75da | 2011-06-13 10:35:35 -0400 | [diff] [blame] | 2195 | $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2196 | $store_failures = set_test_option("STORE_FAILURES", $i); |
Steven Rostedt | 9064af5 | 2011-06-13 10:38:48 -0400 | [diff] [blame^] | 2197 | $test_name = set_test_option("TEST_NAME", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2198 | $timeout = set_test_option("TIMEOUT", $i); |
| 2199 | $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i); |
| 2200 | $console = set_test_option("CONSOLE", $i); |
Steven Rostedt | f1a5b96 | 2011-06-13 10:30:00 -0400 | [diff] [blame] | 2201 | $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2202 | $success_line = set_test_option("SUCCESS_LINE", $i); |
Steven Rostedt | 1c8a617 | 2010-11-09 12:55:40 -0500 | [diff] [blame] | 2203 | $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i); |
| 2204 | $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i); |
Steven Rostedt | 2d01b26 | 2011-03-08 09:47:54 -0500 | [diff] [blame] | 2205 | $stop_test_after = set_test_option("STOP_TEST_AFTER", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2206 | $build_target = set_test_option("BUILD_TARGET", $i); |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 2207 | $ssh_exec = set_test_option("SSH_EXEC", $i); |
| 2208 | $scp_to_target = set_test_option("SCP_TO_TARGET", $i); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2209 | $target_image = set_test_option("TARGET_IMAGE", $i); |
| 2210 | $localversion = set_test_option("LOCALVERSION", $i); |
| 2211 | |
| 2212 | chdir $builddir || die "can't change directory to $builddir"; |
| 2213 | |
| 2214 | if (!-d $tmpdir) { |
| 2215 | mkpath($tmpdir) or |
| 2216 | die "can't create $tmpdir"; |
| 2217 | } |
| 2218 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 2219 | $ENV{"SSH_USER"} = $ssh_user; |
| 2220 | $ENV{"MACHINE"} = $machine; |
| 2221 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2222 | $target = "$ssh_user\@$machine"; |
| 2223 | |
| 2224 | $buildlog = "$tmpdir/buildlog-$machine"; |
| 2225 | $dmesg = "$tmpdir/dmesg-$machine"; |
| 2226 | $make = "$makecmd O=$outputdir"; |
Steven Rostedt | 51ad1dd | 2010-11-08 16:43:21 -0500 | [diff] [blame] | 2227 | $output_config = "$outputdir/.config"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2228 | |
| 2229 | if ($reboot_type eq "grub") { |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 2230 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2231 | } elsif (!defined($reboot_script)) { |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 2232 | dodie "REBOOT_SCRIPT not defined" |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | my $run_type = $build_type; |
| 2236 | if ($test_type eq "patchcheck") { |
| 2237 | $run_type = $opt{"PATCHCHECK_TYPE[$i]"}; |
| 2238 | } elsif ($test_type eq "bisect") { |
| 2239 | $run_type = $opt{"BISECT_TYPE[$i]"}; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 2240 | } elsif ($test_type eq "config_bisect") { |
| 2241 | $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"}; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | # mistake in config file? |
| 2245 | if (!defined($run_type)) { |
| 2246 | $run_type = "ERROR"; |
| 2247 | } |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2248 | |
| 2249 | doprint "\n\n"; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2250 | doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n"; |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 2251 | |
| 2252 | unlink $dmesg; |
| 2253 | unlink $buildlog; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2254 | |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 2255 | if (!defined($minconfig)) { |
| 2256 | $minconfig = $addconfig; |
| 2257 | |
| 2258 | } elsif (defined($addconfig)) { |
Steven Rostedt | 9be2e6b | 2010-11-09 12:20:21 -0500 | [diff] [blame] | 2259 | run_command "cat $addconfig $minconfig > $tmpdir/add_config" or |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 2260 | dodie "Failed to create temp config"; |
Steven Rostedt | 9be2e6b | 2010-11-09 12:20:21 -0500 | [diff] [blame] | 2261 | $minconfig = "$tmpdir/add_config"; |
Steven Rostedt | 2b7d9b2 | 2010-11-02 14:58:15 -0400 | [diff] [blame] | 2262 | } |
| 2263 | |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 2264 | my $checkout = $opt{"CHECKOUT[$i]"}; |
| 2265 | if (defined($checkout)) { |
| 2266 | run_command "git checkout $checkout" or |
| 2267 | die "failed to checkout $checkout"; |
| 2268 | } |
| 2269 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2270 | if ($test_type eq "bisect") { |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 2271 | bisect $i; |
| 2272 | next; |
Steven Rostedt | 0a05c76 | 2010-11-08 11:14:10 -0500 | [diff] [blame] | 2273 | } elsif ($test_type eq "config_bisect") { |
| 2274 | config_bisect $i; |
| 2275 | next; |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2276 | } elsif ($test_type eq "patchcheck") { |
Steven Rostedt | 6c5ee0b | 2010-11-02 14:57:58 -0400 | [diff] [blame] | 2277 | patchcheck $i; |
| 2278 | next; |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 2279 | } |
| 2280 | |
Steven Rostedt | 7faafbd | 2010-11-02 14:58:22 -0400 | [diff] [blame] | 2281 | if ($build_type ne "nobuild") { |
| 2282 | build $build_type or next; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2283 | } |
| 2284 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2285 | if ($test_type ne "build") { |
| 2286 | get_grub_index; |
| 2287 | get_version; |
| 2288 | install; |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 2289 | |
Steven Rostedt | a75fece | 2010-11-02 14:58:27 -0400 | [diff] [blame] | 2290 | my $failed = 0; |
| 2291 | start_monitor; |
| 2292 | monitor or $failed = 1;; |
| 2293 | |
| 2294 | if (!$failed && $test_type ne "boot" && defined($run_test)) { |
| 2295 | do_run_test or $failed = 1; |
| 2296 | } |
| 2297 | end_monitor; |
| 2298 | next if ($failed); |
Steven Rostedt | 5a391fb | 2010-11-02 14:57:43 -0400 | [diff] [blame] | 2299 | } |
| 2300 | |
Steven Rostedt | 5f9b6ce | 2010-11-02 14:57:33 -0400 | [diff] [blame] | 2301 | success $i; |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2302 | } |
| 2303 | |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 2304 | if ($opt{"POWEROFF_ON_SUCCESS"}) { |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 2305 | halt; |
Steven Rostedt | 576f627 | 2010-11-02 14:58:38 -0400 | [diff] [blame] | 2306 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) { |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 2307 | reboot; |
Steven Rostedt | 5c42fc5 | 2010-11-02 14:57:01 -0400 | [diff] [blame] | 2308 | } |
Steven Rostedt | 75c3fda7 | 2010-11-02 14:57:21 -0400 | [diff] [blame] | 2309 | |
Steven Rostedt | e48c529 | 2010-11-02 14:35:37 -0400 | [diff] [blame] | 2310 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; |
| 2311 | |
Steven Rostedt | 2545eb6 | 2010-11-02 15:01:32 -0400 | [diff] [blame] | 2312 | exit 0; |