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