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