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