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