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