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