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