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