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