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