blob: 7958cd4d65679af0448ca6c8073197493c933b0a [file] [log] [blame]
Steven Rostedt2545eb62010-11-02 15:01:32 -04001#!/usr/bin/perl -w
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002#
Uwe Kleine-Königcce1dac2011-01-24 21:12:01 +01003# Copyright 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04004# Licensed under the terms of the GNU GPL License version 2
5#
Steven Rostedt2545eb62010-11-02 15:01:32 -04006
7use strict;
8use IPC::Open2;
9use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Steven Rostedt7faafbd2010-11-02 14:58:22 -040010use File::Path qw(mkpath);
11use File::Copy qw(cp);
Steven Rostedt2545eb62010-11-02 15:01:32 -040012use FileHandle;
13
Steven Rostedte48c5292010-11-02 14:35:37 -040014my $VERSION = "0.2";
15
Steven Rostedt2545eb62010-11-02 15:01:32 -040016$| = 1;
17
18my %opt;
Steven Rostedta57419b2010-11-02 15:13:54 -040019my %repeat_tests;
20my %repeats;
Steven Rostedt2545eb62010-11-02 15:01:32 -040021
22#default opts
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050023my %default = (
24 "NUM_TESTS" => 1,
25 "TEST_TYPE" => "build",
26 "BUILD_TYPE" => "randconfig",
27 "MAKE_CMD" => "make",
28 "TIMEOUT" => 120,
29 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
30 "SLEEP_TIME" => 60, # sleep time between tests
31 "BUILD_NOCLEAN" => 0,
32 "REBOOT_ON_ERROR" => 0,
33 "POWEROFF_ON_ERROR" => 0,
34 "REBOOT_ON_SUCCESS" => 1,
35 "POWEROFF_ON_SUCCESS" => 0,
36 "BUILD_OPTIONS" => "",
37 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
38 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
39 "CLEAR_LOG" => 0,
40 "BISECT_MANUAL" => 0,
41 "BISECT_SKIP" => 1,
Steven Rostedtccc513b2012-05-21 17:13:40 -040042 "MIN_CONFIG_TYPE" => "boot",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050043 "SUCCESS_LINE" => "login:",
44 "DETECT_TRIPLE_FAULT" => 1,
45 "NO_INSTALL" => 0,
46 "BOOTED_TIMEOUT" => 1,
47 "DIE_ON_FAILURE" => 1,
48 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
49 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
Steven Rostedt02ad2612012-03-21 08:21:24 -040050 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050051 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
52 "STOP_AFTER_SUCCESS" => 10,
53 "STOP_AFTER_FAILURE" => 60,
54 "STOP_TEST_AFTER" => 600,
Steven Rostedt407b95b2012-07-19 16:05:42 -040055 "MAX_MONITOR_WAIT" => 1800,
Steven Rostedta15ba912012-11-13 14:30:37 -050056 "GRUB_REBOOT" => "grub2-reboot",
Steven Rostedt77869542012-12-11 17:37:41 -050057 "SYSLINUX" => "extlinux",
58 "SYSLINUX_PATH" => "/boot/extlinux",
Steven Rostedt600bbf02011-11-21 20:12:04 -050059
60# required, and we will ask users if they don't have them but we keep the default
61# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050062 "REBOOT_TYPE" => "grub",
63 "LOCALVERSION" => "-test",
64 "SSH_USER" => "root",
65 "BUILD_TARGET" => "arch/x86/boot/bzImage",
66 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050067
68 "LOG_FILE" => undef,
69 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050070);
Steven Rostedt2545eb62010-11-02 15:01:32 -040071
Steven Rostedt8d1491b2010-11-18 15:39:48 -050072my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040073my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040074my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040075my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040076my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $tmpdir;
78my $builddir;
79my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050080my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040081my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040082my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040083my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040084my $final_post_ktest;
85my $pre_ktest;
86my $post_ktest;
87my $pre_test;
88my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040089my $pre_build;
90my $post_build;
91my $pre_build_die;
92my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040093my $reboot_type;
94my $reboot_script;
95my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040096my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040097my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -050098my $switch_to_good;
99my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -0400100my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -0400101my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -0400102my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -0400103my $powercycle_after_reboot;
104my $poweroff_after_halt;
Steven Rostedt407b95b2012-07-19 16:05:42 -0400105my $max_monitor_wait;
Steven Rostedte48c5292010-11-02 14:35:37 -0400106my $ssh_exec;
107my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400108my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400109my $power_off;
110my $grub_menu;
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -0500111my $last_grub_menu;
Steven Rostedta15ba912012-11-13 14:30:37 -0500112my $grub_file;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400113my $grub_number;
Steven Rostedta15ba912012-11-13 14:30:37 -0500114my $grub_reboot;
Steven Rostedt77869542012-12-11 17:37:41 -0500115my $syslinux;
116my $syslinux_path;
117my $syslinux_label;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400118my $target;
119my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400120my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400121my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400122my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400123my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400124my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400125my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400126my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400127my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400128my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400129my $use_output_minconfig;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500130my $warnings_file;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400131my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500132my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400133my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400134my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500135my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400136my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500137my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500138my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400139my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500140my $bisect_ret_good;
141my $bisect_ret_bad;
142my $bisect_ret_skip;
143my $bisect_ret_abort;
144my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400145my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400146my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400147my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400148my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530149my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400150my $dmesg;
151my $monitor_fp;
152my $monitor_pid;
153my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400154my $sleep_time;
155my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400156my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400157my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400158my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530159my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400160my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400161my $timeout;
162my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400163my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400164my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400165my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400166my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500167my $stop_after_success;
168my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500169my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400170my $build_target;
171my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500172my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400173my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400174my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400175my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400176
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500177my $bisect_good;
178my $bisect_bad;
179my $bisect_type;
180my $bisect_start;
181my $bisect_replay;
182my $bisect_files;
183my $bisect_reverse;
184my $bisect_check;
185
186my $config_bisect;
187my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400188my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500189
190my $patchcheck_type;
191my $patchcheck_start;
192my $patchcheck_end;
193
Steven Rostedt165708b2011-11-26 20:56:52 -0500194# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500195# which would require more options.
196my $buildonly = 1;
197
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500198# tell build not to worry about warnings, even when WARNINGS_FILE is set
199my $warnings_ok = 0;
200
Steven Rostedtdbd37832011-11-23 16:00:48 -0500201# set when creating a new config
202my $newconfig = 0;
203
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500204my %entered_configs;
205my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400206my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400207
208# force_config is the list of configs that we force enabled (or disabled)
209# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400210my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500211
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400212# do not force reboots on config problems
213my $no_reboot = 1;
214
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400215# reboot on success
216my $reboot_success = 0;
217
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500218my %option_map = (
219 "MACHINE" => \$machine,
220 "SSH_USER" => \$ssh_user,
221 "TMP_DIR" => \$tmpdir,
222 "OUTPUT_DIR" => \$outputdir,
223 "BUILD_DIR" => \$builddir,
224 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400225 "PRE_KTEST" => \$pre_ktest,
226 "POST_KTEST" => \$post_ktest,
227 "PRE_TEST" => \$pre_test,
228 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500229 "BUILD_TYPE" => \$build_type,
230 "BUILD_OPTIONS" => \$build_options,
231 "PRE_BUILD" => \$pre_build,
232 "POST_BUILD" => \$post_build,
233 "PRE_BUILD_DIE" => \$pre_build_die,
234 "POST_BUILD_DIE" => \$post_build_die,
235 "POWER_CYCLE" => \$power_cycle,
236 "REBOOT" => \$reboot,
237 "BUILD_NOCLEAN" => \$noclean,
238 "MIN_CONFIG" => \$minconfig,
239 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
240 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400241 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400242 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500243 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500244 "IGNORE_CONFIG" => \$ignore_config,
245 "TEST" => \$run_test,
246 "ADD_CONFIG" => \$addconfig,
247 "REBOOT_TYPE" => \$reboot_type,
248 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500249 "GRUB_FILE" => \$grub_file,
250 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500251 "SYSLINUX" => \$syslinux,
252 "SYSLINUX_PATH" => \$syslinux_path,
253 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400254 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500255 "POST_INSTALL" => \$post_install,
256 "NO_INSTALL" => \$no_install,
257 "REBOOT_SCRIPT" => \$reboot_script,
258 "REBOOT_ON_ERROR" => \$reboot_on_error,
259 "SWITCH_TO_GOOD" => \$switch_to_good,
260 "SWITCH_TO_TEST" => \$switch_to_test,
261 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400262 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500263 "DIE_ON_FAILURE" => \$die_on_failure,
264 "POWER_OFF" => \$power_off,
265 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
266 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400267 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500268 "SLEEP_TIME" => \$sleep_time,
269 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
270 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
271 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500272 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500273 "BISECT_MANUAL" => \$bisect_manual,
274 "BISECT_SKIP" => \$bisect_skip,
275 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
276 "BISECT_RET_GOOD" => \$bisect_ret_good,
277 "BISECT_RET_BAD" => \$bisect_ret_bad,
278 "BISECT_RET_SKIP" => \$bisect_ret_skip,
279 "BISECT_RET_ABORT" => \$bisect_ret_abort,
280 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
281 "STORE_FAILURES" => \$store_failures,
282 "STORE_SUCCESSES" => \$store_successes,
283 "TEST_NAME" => \$test_name,
284 "TIMEOUT" => \$timeout,
285 "BOOTED_TIMEOUT" => \$booted_timeout,
286 "CONSOLE" => \$console,
287 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
288 "SUCCESS_LINE" => \$success_line,
289 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
290 "STOP_AFTER_SUCCESS" => \$stop_after_success,
291 "STOP_AFTER_FAILURE" => \$stop_after_failure,
292 "STOP_TEST_AFTER" => \$stop_test_after,
293 "BUILD_TARGET" => \$build_target,
294 "SSH_EXEC" => \$ssh_exec,
295 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400296 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500297 "CHECKOUT" => \$checkout,
298 "TARGET_IMAGE" => \$target_image,
299 "LOCALVERSION" => \$localversion,
300
301 "BISECT_GOOD" => \$bisect_good,
302 "BISECT_BAD" => \$bisect_bad,
303 "BISECT_TYPE" => \$bisect_type,
304 "BISECT_START" => \$bisect_start,
305 "BISECT_REPLAY" => \$bisect_replay,
306 "BISECT_FILES" => \$bisect_files,
307 "BISECT_REVERSE" => \$bisect_reverse,
308 "BISECT_CHECK" => \$bisect_check,
309
310 "CONFIG_BISECT" => \$config_bisect,
311 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400312 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500313
314 "PATCHCHECK_TYPE" => \$patchcheck_type,
315 "PATCHCHECK_START" => \$patchcheck_start,
316 "PATCHCHECK_END" => \$patchcheck_end,
317);
318
319# Options may be used by other options, record them.
320my %used_options;
321
Steven Rostedt7bf51072011-10-22 09:07:03 -0400322# default variables that can be used
323chomp ($variable{"PWD"} = `pwd`);
324
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500325$config_help{"MACHINE"} = << "EOF"
326 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500327 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500328EOF
329 ;
330$config_help{"SSH_USER"} = << "EOF"
331 The box is expected to have ssh on normal bootup, provide the user
332 (most likely root, since you need privileged operations)
333EOF
334 ;
335$config_help{"BUILD_DIR"} = << "EOF"
336 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500337 You can use \${PWD} that will be the path where ktest.pl is run, or use
338 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500339EOF
340 ;
341$config_help{"OUTPUT_DIR"} = << "EOF"
342 The directory that the objects will be built (full path).
343 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500344 You can use \${PWD} that will be the path where ktest.pl is run, or use
345 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500346EOF
347 ;
348$config_help{"BUILD_TARGET"} = << "EOF"
349 The location of the compiled file to copy to the target.
350 (relative to OUTPUT_DIR)
351EOF
352 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500353$config_help{"BUILD_OPTIONS"} = << "EOF"
354 Options to add to \"make\" when building.
355 i.e. -j20
356EOF
357 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500358$config_help{"TARGET_IMAGE"} = << "EOF"
359 The place to put your image on the test machine.
360EOF
361 ;
362$config_help{"POWER_CYCLE"} = << "EOF"
363 A script or command to reboot the box.
364
365 Here is a digital loggers power switch example
366 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
367
368 Here is an example to reboot a virtual box on the current host
369 with the name "Guest".
370 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
371EOF
372 ;
373$config_help{"CONSOLE"} = << "EOF"
374 The script or command that reads the console
375
376 If you use ttywatch server, something like the following would work.
377CONSOLE = nc -d localhost 3001
378
379 For a virtual machine with guest name "Guest".
380CONSOLE = virsh console Guest
381EOF
382 ;
383$config_help{"LOCALVERSION"} = << "EOF"
384 Required version ending to differentiate the test
385 from other linux builds on the system.
386EOF
387 ;
388$config_help{"REBOOT_TYPE"} = << "EOF"
389 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500390 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500391
392 If you specify grub, it will assume grub version 1
393 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
394 and select that target to reboot to the kernel. If this is not
395 your setup, then specify "script" and have a command or script
396 specified in REBOOT_SCRIPT to boot to the target.
397
398 The entry in /boot/grub/menu.lst must be entered in manually.
399 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500400
401 If you specify grub2, then you also need to specify both \$GRUB_MENU
402 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500403
404 If you specify syslinux, then you may use SYSLINUX to define the syslinux
405 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
406 the syslinux install (defaults to /boot/extlinux). But you have to specify
407 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500408EOF
409 ;
410$config_help{"GRUB_MENU"} = << "EOF"
411 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500412 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500413
414 Note, ktest.pl will not update the grub menu.lst, you need to
415 manually add an option for the test. ktest.pl will search
416 the grub menu.lst for this option to find what kernel to
417 reboot into.
418
419 For example, if in the /boot/grub/menu.lst the test kernel title has:
420 title Test Kernel
421 kernel vmlinuz-test
422 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500423
424 For grub2, a search of \$GRUB_FILE is performed for the lines
425 that begin with "menuentry". It will not detect submenus. The
426 menu must be a non-nested menu. Add the quotes used in the menu
427 to guarantee your selection, as the first menuentry with the content
428 of \$GRUB_MENU that is found will be used.
429EOF
430 ;
431$config_help{"GRUB_FILE"} = << "EOF"
432 If grub2 is used, the full path for the grub.cfg file is placed
433 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500434EOF
435 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500436$config_help{"SYSLINUX_LABEL"} = << "EOF"
437 If syslinux is used, the label that boots the target kernel must
438 be specified with SYSLINUX_LABEL.
439EOF
440 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500441$config_help{"REBOOT_SCRIPT"} = << "EOF"
442 A script to reboot the target into the test kernel
443 (Only mandatory if REBOOT_TYPE = script)
444EOF
445 ;
446
Steven Rostedtdad98752011-11-22 20:48:57 -0500447sub read_prompt {
448 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400449
450 my $ans;
451
452 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500453 if ($cancel) {
454 print "$prompt [y/n/C] ";
455 } else {
456 print "$prompt [Y/n] ";
457 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400458 $ans = <STDIN>;
459 chomp $ans;
460 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500461 if ($cancel) {
462 $ans = "c";
463 } else {
464 $ans = "y";
465 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400466 }
467 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500468 if ($cancel) {
469 last if ($ans =~ /^c$/i);
470 print "Please answer either 'y', 'n' or 'c'.\n";
471 } else {
472 print "Please answer either 'y' or 'n'.\n";
473 }
474 }
475 if ($ans =~ /^c/i) {
476 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400477 }
478 if ($ans !~ /^y$/i) {
479 return 0;
480 }
481 return 1;
482}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500483
Steven Rostedtdad98752011-11-22 20:48:57 -0500484sub read_yn {
485 my ($prompt) = @_;
486
487 return read_prompt 0, $prompt;
488}
489
490sub read_ync {
491 my ($prompt) = @_;
492
493 return read_prompt 1, $prompt;
494}
495
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500496sub get_ktest_config {
497 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400498 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500499
500 return if (defined($opt{$config}));
501
502 if (defined($config_help{$config})) {
503 print "\n";
504 print $config_help{$config};
505 }
506
507 for (;;) {
508 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500509 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500510 print "\[$default{$config}\] ";
511 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400512 $ans = <STDIN>;
513 $ans =~ s/^\s*(.*\S)\s*$/$1/;
514 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500515 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400516 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500517 } else {
518 print "Your answer can not be blank\n";
519 next;
520 }
521 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500522 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500523 last;
524 }
525}
526
527sub get_ktest_configs {
528 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500529 get_ktest_config("BUILD_DIR");
530 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500531
Steven Rostedtdbd37832011-11-23 16:00:48 -0500532 if ($newconfig) {
533 get_ktest_config("BUILD_OPTIONS");
534 }
535
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500536 # options required for other than just building a kernel
537 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500538 get_ktest_config("POWER_CYCLE");
539 get_ktest_config("CONSOLE");
540 }
541
542 # options required for install and more
543 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500544 get_ktest_config("SSH_USER");
545 get_ktest_config("BUILD_TARGET");
546 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500547 }
548
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500549 get_ktest_config("LOCALVERSION");
550
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500551 return if ($buildonly);
552
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500553 my $rtype = $opt{"REBOOT_TYPE"};
554
555 if (!defined($rtype)) {
556 if (!defined($opt{"GRUB_MENU"})) {
557 get_ktest_config("REBOOT_TYPE");
558 $rtype = $entered_configs{"REBOOT_TYPE"};
559 } else {
560 $rtype = "grub";
561 }
562 }
563
564 if ($rtype eq "grub") {
565 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500566 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500567
568 if ($rtype eq "grub2") {
569 get_ktest_config("GRUB_MENU");
570 get_ktest_config("GRUB_FILE");
571 }
Steven Rostedt77869542012-12-11 17:37:41 -0500572
573 if ($rtype eq "syslinux") {
574 get_ktest_config("SYSLINUX_LABEL");
575 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500576}
577
Steven Rostedt77d942c2011-05-20 13:36:58 -0400578sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400579 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400580 my $retval = "";
581
582 # We want to check for '\', and it is just easier
583 # to check the previous characet of '$' and not need
584 # to worry if '$' is the first character. By adding
585 # a space to $value, we can just check [^\\]\$ and
586 # it will still work.
587 $value = " $value";
588
589 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
590 my $begin = $1;
591 my $var = $2;
592 my $end = $3;
593 # append beginning of value to retval
594 $retval = "$retval$begin";
595 if (defined($variable{$var})) {
596 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400597 } elsif (defined($remove_undef) && $remove_undef) {
598 # for if statements, any variable that is not defined,
599 # we simple convert to 0
600 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400601 } else {
602 # put back the origin piece.
603 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500604 # This could be an option that is used later, save
605 # it so we don't warn if this option is not one of
606 # ktests options.
607 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400608 }
609 $value = $end;
610 }
611 $retval = "$retval$value";
612
613 # remove the space added in the beginning
614 $retval =~ s/ //;
615
616 return "$retval"
617}
618
Steven Rostedta57419b2010-11-02 15:13:54 -0400619sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400620 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400621
Steven Rostedtcad96662011-12-22 11:32:52 -0500622 my $prvalue = process_variables($rvalue);
623
624 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500625 # Note if a test is something other than build, then we
626 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500627 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500628 # for bisect, we need to check BISECT_TYPE
629 if ($prvalue ne "bisect") {
630 $buildonly = 0;
631 }
632 } else {
633 # install still limits some manditory options.
634 $buildonly = 2;
635 }
636 }
637
638 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
639 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500640 $buildonly = 0;
641 } else {
642 # install still limits some manditory options.
643 $buildonly = 2;
644 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500645 }
646
Steven Rostedta57419b2010-11-02 15:13:54 -0400647 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400648 if (!$override || defined(${$overrides}{$lvalue})) {
649 my $extra = "";
650 if ($override) {
651 $extra = "In the same override section!\n";
652 }
653 die "$name: $.: Option $lvalue defined more than once!\n$extra";
654 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500655 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400656 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500657 if ($rvalue =~ /^\s*$/) {
658 delete $opt{$lvalue};
659 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500660 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500661 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400662}
663
Steven Rostedt77d942c2011-05-20 13:36:58 -0400664sub set_variable {
665 my ($lvalue, $rvalue) = @_;
666
667 if ($rvalue =~ /^\s*$/) {
668 delete $variable{$lvalue};
669 } else {
670 $rvalue = process_variables($rvalue);
671 $variable{$lvalue} = $rvalue;
672 }
673}
674
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400675sub process_compare {
676 my ($lval, $cmp, $rval) = @_;
677
678 # remove whitespace
679
680 $lval =~ s/^\s*//;
681 $lval =~ s/\s*$//;
682
683 $rval =~ s/^\s*//;
684 $rval =~ s/\s*$//;
685
686 if ($cmp eq "==") {
687 return $lval eq $rval;
688 } elsif ($cmp eq "!=") {
689 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400690 } elsif ($cmp eq "=~") {
691 return $lval =~ m/$rval/;
692 } elsif ($cmp eq "!~") {
693 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400694 }
695
696 my $statement = "$lval $cmp $rval";
697 my $ret = eval $statement;
698
699 # $@ stores error of eval
700 if ($@) {
701 return -1;
702 }
703
704 return $ret;
705}
706
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400707sub value_defined {
708 my ($val) = @_;
709
710 return defined($variable{$2}) ||
711 defined($opt{$2});
712}
713
Steven Rostedt8d735212011-10-17 11:36:44 -0400714my $d = 0;
715sub process_expression {
716 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400717
Steven Rostedt8d735212011-10-17 11:36:44 -0400718 my $c = $d++;
719
720 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
721 my $express = $1;
722
723 if (process_expression($name, $express)) {
724 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
725 } else {
726 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
727 }
728 }
729
730 $d--;
731 my $OR = "\\|\\|";
732 my $AND = "\\&\\&";
733
734 while ($val =~ s/^(.*?)($OR|$AND)//) {
735 my $express = $1;
736 my $op = $2;
737
738 if (process_expression($name, $express)) {
739 if ($op eq "||") {
740 return 1;
741 }
742 } else {
743 if ($op eq "&&") {
744 return 0;
745 }
746 }
747 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400748
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400749 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400750 my $ret = process_compare($1, $2, $3);
751 if ($ret < 0) {
752 die "$name: $.: Unable to process comparison\n";
753 }
754 return $ret;
755 }
756
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400757 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
758 if (defined $1) {
759 return !value_defined($2);
760 } else {
761 return value_defined($2);
762 }
763 }
764
Steven Rostedt45d73a52011-09-30 19:44:53 -0400765 if ($val =~ /^\s*0\s*$/) {
766 return 0;
767 } elsif ($val =~ /^\s*\d+\s*$/) {
768 return 1;
769 }
770
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400771 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400772}
773
774sub process_if {
775 my ($name, $value) = @_;
776
777 # Convert variables and replace undefined ones with 0
778 my $val = process_variables($value, 1);
779 my $ret = process_expression $name, $val;
780
781 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400782}
783
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400784sub __read_config {
785 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400786
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400787 my $in;
788 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400789
Steven Rostedta57419b2010-11-02 15:13:54 -0400790 my $name = $config;
791 $name =~ s,.*/(.*),$1,;
792
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400793 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400794 my $default = 1;
795 my $repeat = 1;
796 my $num_tests_set = 0;
797 my $skip = 0;
798 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400799 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400800 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400801 my $if = 0;
802 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400803 my $override = 0;
804
805 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400806
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400807 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400808
809 # ignore blank lines and comments
810 next if (/^\s*$/ || /\s*\#/);
811
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400812 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400813
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400814 my $type = $1;
815 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400816 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400817
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400818 my $old_test_num;
819 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400820 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400821
822 if ($type eq "TEST_START") {
823
824 if ($num_tests_set) {
825 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
826 }
827
828 $old_test_num = $test_num;
829 $old_repeat = $repeat;
830
831 $test_num += $repeat;
832 $default = 0;
833 $repeat = 1;
834 } else {
835 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400836 }
837
Steven Rostedta9f84422011-10-17 11:06:29 -0400838 # If SKIP is anywhere in the line, the command will be skipped
839 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400840 $skip = 1;
841 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400842 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400843 $skip = 0;
844 }
845
Steven Rostedta9f84422011-10-17 11:06:29 -0400846 if ($rest =~ s/\sELSE\b//) {
847 if (!$if) {
848 die "$name: $.: ELSE found with out matching IF section\n$_";
849 }
850 $if = 0;
851
852 if ($if_set) {
853 $skip = 1;
854 } else {
855 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400856 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400857 }
858
Steven Rostedta9f84422011-10-17 11:06:29 -0400859 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400860 if (process_if($name, $1)) {
861 $if_set = 1;
862 } else {
863 $skip = 1;
864 }
865 $if = 1;
866 } else {
867 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400868 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400869 }
870
Steven Rostedta9f84422011-10-17 11:06:29 -0400871 if (!$skip) {
872 if ($type eq "TEST_START") {
873 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
874 $repeat = $1;
875 $repeat_tests{"$test_num"} = $repeat;
876 }
877 } elsif ($rest =~ s/\sOVERRIDE\b//) {
878 # DEFAULT only
879 $override = 1;
880 # Clear previous overrides
881 %overrides = ();
882 }
883 }
884
885 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400886 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400887 }
888
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400889 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400890 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400891 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400892 }
893
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400894 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400895 if (!$if) {
896 die "$name: $.: ELSE found with out matching IF section\n$_";
897 }
898 $rest = $1;
899 if ($if_set) {
900 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400901 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400902 } else {
903 $skip = 0;
904
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400905 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400906 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400907 if (process_if($name, $1)) {
908 $if_set = 1;
909 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400910 $skip = 1;
911 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400912 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400913 } else {
914 $if = 0;
915 }
916 }
917
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400918 if ($rest !~ /^\s*$/) {
919 die "$name: $.: Gargbage found after DEFAULTS\n$_";
920 }
921
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400922 } elsif (/^\s*INCLUDE\s+(\S+)/) {
923
924 next if ($skip);
925
926 if (!$default) {
927 die "$name: $.: INCLUDE can only be done in default sections\n$_";
928 }
929
930 my $file = process_variables($1);
931
932 if ($file !~ m,^/,) {
933 # check the path of the config file first
934 if ($config =~ m,(.*)/,) {
935 if (-f "$1/$file") {
936 $file = "$1/$file";
937 }
938 }
939 }
940
941 if ( ! -r $file ) {
942 die "$name: $.: Can't read file $file\n$_";
943 }
944
945 if (__read_config($file, \$test_num)) {
946 $test_case = 1;
947 }
948
Steven Rostedta57419b2010-11-02 15:13:54 -0400949 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
950
951 next if ($skip);
952
Steven Rostedt2545eb62010-11-02 15:01:32 -0400953 my $lvalue = $1;
954 my $rvalue = $2;
955
Steven Rostedta57419b2010-11-02 15:13:54 -0400956 if (!$default &&
957 ($lvalue eq "NUM_TESTS" ||
958 $lvalue eq "LOG_FILE" ||
959 $lvalue eq "CLEAR_LOG")) {
960 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400961 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400962
963 if ($lvalue eq "NUM_TESTS") {
964 if ($test_num) {
965 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
966 }
967 if (!$default) {
968 die "$name: $.: NUM_TESTS must be set in default section\n";
969 }
970 $num_tests_set = 1;
971 }
972
973 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400974 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400975 } else {
976 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400977 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400978
979 if ($repeat > 1) {
980 $repeats{$val} = $repeat;
981 }
982 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400983 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
984 next if ($skip);
985
986 my $lvalue = $1;
987 my $rvalue = $2;
988
989 # process config variables.
990 # Config variables are only active while reading the
991 # config and can be defined anywhere. They also ignore
992 # TEST_START and DEFAULTS, but are skipped if they are in
993 # on of these sections that have SKIP defined.
994 # The save variable can be
995 # defined multiple times and the new one simply overrides
996 # the prevous one.
997 set_variable($lvalue, $rvalue);
998
Steven Rostedta57419b2010-11-02 15:13:54 -0400999 } else {
1000 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001001 }
1002 }
1003
Steven Rostedta57419b2010-11-02 15:13:54 -04001004 if ($test_num) {
1005 $test_num += $repeat - 1;
1006 $opt{"NUM_TESTS"} = $test_num;
1007 }
1008
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001009 close($in);
1010
1011 $$current_test_num = $test_num;
1012
1013 return $test_case;
1014}
1015
Steven Rostedtc4261d02011-11-23 13:41:18 -05001016sub get_test_case {
1017 print "What test case would you like to run?\n";
1018 print " (build, install or boot)\n";
1019 print " Other tests are available but require editing the config file\n";
1020 my $ans = <STDIN>;
1021 chomp $ans;
1022 $default{"TEST_TYPE"} = $ans;
1023}
1024
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001025sub read_config {
1026 my ($config) = @_;
1027
1028 my $test_case;
1029 my $test_num = 0;
1030
1031 $test_case = __read_config $config, \$test_num;
1032
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001033 # make sure we have all mandatory configs
1034 get_ktest_configs;
1035
Steven Rostedt0df213c2011-06-14 20:51:37 -04001036 # was a test specified?
1037 if (!$test_case) {
1038 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001039 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001040 }
1041
Steven Rostedta75fece2010-11-02 14:58:27 -04001042 # set any defaults
1043
1044 foreach my $default (keys %default) {
1045 if (!defined($opt{$default})) {
1046 $opt{$default} = $default{$default};
1047 }
1048 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001049
1050 if ($opt{"IGNORE_UNUSED"} == 1) {
1051 return;
1052 }
1053
1054 my %not_used;
1055
1056 # check if there are any stragglers (typos?)
1057 foreach my $option (keys %opt) {
1058 my $op = $option;
1059 # remove per test labels.
1060 $op =~ s/\[.*\]//;
1061 if (!exists($option_map{$op}) &&
1062 !exists($default{$op}) &&
1063 !exists($used_options{$op})) {
1064 $not_used{$op} = 1;
1065 }
1066 }
1067
1068 if (%not_used) {
1069 my $s = "s are";
1070 $s = " is" if (keys %not_used == 1);
1071 print "The following option$s not used; could be a typo:\n";
1072 foreach my $option (keys %not_used) {
1073 print "$option\n";
1074 }
1075 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1076 if (!read_yn "Do you want to continue?") {
1077 exit -1;
1078 }
1079 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001080}
1081
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001082sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001083 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001084
1085 # Add space to evaluate the character before $
1086 $option = " $option";
1087 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301088 my $repeated = 0;
1089 my $parent = 0;
1090
1091 foreach my $test (keys %repeat_tests) {
1092 if ($i >= $test &&
1093 $i < $test + $repeat_tests{$test}) {
1094
1095 $repeated = 1;
1096 $parent = $test;
1097 last;
1098 }
1099 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001100
1101 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1102 my $start = $1;
1103 my $var = $2;
1104 my $end = $3;
1105
1106 # Append beginning of line
1107 $retval = "$retval$start";
1108
1109 # If the iteration option OPT[$i] exists, then use that.
1110 # otherwise see if the default OPT (without [$i]) exists.
1111
1112 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301113 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001114
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001115 # If a variable contains itself, use the default var
1116 if (($var eq $name) && defined($opt{$var})) {
1117 $o = $opt{$var};
1118 $retval = "$retval$o";
1119 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001120 $o = $opt{$o};
1121 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301122 } elsif ($repeated && defined($opt{$parento})) {
1123 $o = $opt{$parento};
1124 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001125 } elsif (defined($opt{$var})) {
1126 $o = $opt{$var};
1127 $retval = "$retval$o";
1128 } else {
1129 $retval = "$retval\$\{$var\}";
1130 }
1131
1132 $option = $end;
1133 }
1134
1135 $retval = "$retval$option";
1136
1137 $retval =~ s/^ //;
1138
1139 return $retval;
1140}
1141
1142sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001143 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001144
1145 my $prev = "";
1146
1147 # Since an option can evaluate to another option,
1148 # keep iterating until we do not evaluate any more
1149 # options.
1150 my $r = 0;
1151 while ($prev ne $option) {
1152 # Check for recursive evaluations.
1153 # 100 deep should be more than enough.
1154 if ($r++ > 100) {
1155 die "Over 100 evaluations accurred with $option\n" .
1156 "Check for recursive variables\n";
1157 }
1158 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001159 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001160 }
1161
1162 return $option;
1163}
1164
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001165sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001166 if (defined($opt{"LOG_FILE"})) {
1167 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1168 print OUT @_;
1169 close(OUT);
1170 }
1171}
1172
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001173sub logit {
1174 if (defined($opt{"LOG_FILE"})) {
1175 _logit @_;
1176 } else {
1177 print @_;
1178 }
1179}
1180
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001181sub doprint {
1182 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001183 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001184}
1185
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001186sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001187sub start_monitor;
1188sub end_monitor;
1189sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001190
1191sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001192 my ($time) = @_;
1193
Steven Rostedta4968722012-12-11 14:59:05 -05001194 # Make sure everything has been written to disk
1195 run_ssh("sync");
1196
Steven Rostedt2b803362011-09-30 18:00:23 -04001197 if (defined($time)) {
1198 start_monitor;
1199 # flush out current monitor
1200 # May contain the reboot success line
1201 wait_for_monitor 1;
1202 }
1203
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001204 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001205 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001206 if (defined($powercycle_after_reboot)) {
1207 sleep $powercycle_after_reboot;
1208 run_command "$power_cycle";
1209 }
1210 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001211 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001212 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001213 }
Andrew Jones2728be42011-08-12 15:32:05 +02001214
1215 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001216
1217 # We only want to get to the new kernel, don't fail
1218 # if we stumble over a call trace.
1219 my $save_ignore_errors = $ignore_errors;
1220 $ignore_errors = 1;
1221
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001222 # Look for the good kernel to boot
1223 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001224 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001225 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001226 run_command "$power_cycle";
1227 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001228
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001229 $ignore_errors = $save_ignore_errors;
1230
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001231 # Still need to wait for the reboot to finish
1232 wait_for_monitor($time, $reboot_success_line);
1233
Andrew Jones2728be42011-08-12 15:32:05 +02001234 end_monitor;
1235 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001236}
1237
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001238sub reboot_to_good {
1239 my ($time) = @_;
1240
1241 if (defined($switch_to_good)) {
1242 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001243 }
1244
1245 reboot $time;
1246}
1247
Steven Rostedt576f6272010-11-02 14:58:38 -04001248sub do_not_reboot {
1249 my $i = $iteration;
1250
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001251 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001252 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1253 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1254}
1255
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001256sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001257 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001258
Steven Rostedt576f6272010-11-02 14:58:38 -04001259 my $i = $iteration;
1260
1261 if ($reboot_on_error && !do_not_reboot) {
1262
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001263 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001264 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001265
Steven Rostedta75fece2010-11-02 14:58:27 -04001266 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001267 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001268 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001269 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001270
Steven Rostedtf80802c2011-03-07 13:18:47 -05001271 if (defined($opt{"LOG_FILE"})) {
1272 print " See $opt{LOG_FILE} for more info.\n";
1273 }
1274
Steven Rostedt576f6272010-11-02 14:58:38 -04001275 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001276}
1277
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001278sub open_console {
1279 my ($fp) = @_;
1280
1281 my $flags;
1282
Steven Rostedta75fece2010-11-02 14:58:27 -04001283 my $pid = open($fp, "$console|") or
1284 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001285
1286 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001287 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001288 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001289 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001290
1291 return $pid;
1292}
1293
1294sub close_console {
1295 my ($fp, $pid) = @_;
1296
1297 doprint "kill child process $pid\n";
1298 kill 2, $pid;
1299
1300 print "closing!\n";
1301 close($fp);
1302}
1303
1304sub start_monitor {
1305 if ($monitor_cnt++) {
1306 return;
1307 }
1308 $monitor_fp = \*MONFD;
1309 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001310
1311 return;
1312
1313 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001314}
1315
1316sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001317 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001318 if (--$monitor_cnt) {
1319 return;
1320 }
1321 close_console($monitor_fp, $monitor_pid);
1322}
1323
1324sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001325 my ($time, $stop) = @_;
1326 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001327 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001328 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001329 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001330 my $skip_call_trace = 0;
1331 my $bug = 0;
1332 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001333 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001334
Steven Rostedta75fece2010-11-02 14:58:27 -04001335 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001336
1337 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001338 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001339 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001340 last if (!defined($line));
1341 print "$line";
1342 $full_line .= $line;
1343
1344 if (defined($stop) && $full_line =~ /$stop/) {
1345 doprint "wait for monitor detected $stop\n";
1346 $booted = 1;
1347 }
1348
Steven Rostedt8a80c722012-07-19 16:08:33 -04001349 if ($full_line =~ /\[ backtrace testing \]/) {
1350 $skip_call_trace = 1;
1351 }
1352
1353 if ($full_line =~ /call trace:/i) {
1354 if (!$bug && !$skip_call_trace) {
1355 if ($ignore_errors) {
1356 $bug_ignored = 1;
1357 } else {
1358 $bug = 1;
1359 }
1360 }
1361 }
1362
1363 if ($full_line =~ /\[ end of backtrace testing \]/) {
1364 $skip_call_trace = 0;
1365 }
1366
1367 if ($full_line =~ /Kernel panic -/) {
1368 $bug = 1;
1369 }
1370
Steven Rostedt2b803362011-09-30 18:00:23 -04001371 if ($line =~ /\n/) {
1372 $full_line = "";
1373 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001374 $now = time;
1375 if ($now - $start_time >= $max_monitor_wait) {
1376 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1377 return 1;
1378 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001379 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001380 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001381 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001382}
1383
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301384sub save_logs {
1385 my ($result, $basedir) = @_;
1386 my @t = localtime;
1387 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1388 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1389
1390 my $type = $build_type;
1391 if ($type =~ /useconfig/) {
1392 $type = "useconfig";
1393 }
1394
1395 my $dir = "$machine-$test_type-$type-$result-$date";
1396
1397 $dir = "$basedir/$dir";
1398
1399 if (!-d $dir) {
1400 mkpath($dir) or
1401 die "can't create $dir";
1402 }
1403
1404 my %files = (
1405 "config" => $output_config,
1406 "buildlog" => $buildlog,
1407 "dmesg" => $dmesg,
1408 "testlog" => $testlog,
1409 );
1410
1411 while (my ($name, $source) = each(%files)) {
1412 if (-f "$source") {
1413 cp "$source", "$dir/$name" or
1414 die "failed to copy $source";
1415 }
1416 }
1417
1418 doprint "*** Saved info to $dir ***\n";
1419}
1420
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001421sub fail {
1422
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001423 if (defined($post_test)) {
1424 run_command $post_test;
1425 }
1426
Steven Rostedta75fece2010-11-02 14:58:27 -04001427 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001428 dodie @_;
1429 }
1430
Steven Rostedta75fece2010-11-02 14:58:27 -04001431 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001432
Steven Rostedt576f6272010-11-02 14:58:38 -04001433 my $i = $iteration;
1434
Steven Rostedta75fece2010-11-02 14:58:27 -04001435 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001436 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001437 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001438 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001439 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001440
Steven Rostedt9064af52011-06-13 10:38:48 -04001441 my $name = "";
1442
1443 if (defined($test_name)) {
1444 $name = " ($test_name)";
1445 }
1446
Steven Rostedt576f6272010-11-02 14:58:38 -04001447 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1448 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001449 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001450 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1451 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001452
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301453 if (defined($store_failures)) {
1454 save_logs "fail", $store_failures;
1455 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001456
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001457 return 1;
1458}
1459
Steven Rostedt2545eb62010-11-02 15:01:32 -04001460sub run_command {
1461 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001462 my $dolog = 0;
1463 my $dord = 0;
1464 my $pid;
1465
Steven Rostedte48c5292010-11-02 14:35:37 -04001466 $command =~ s/\$SSH_USER/$ssh_user/g;
1467 $command =~ s/\$MACHINE/$machine/g;
1468
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001469 doprint("$command ... ");
1470
1471 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001472 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001473
1474 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001475 open(LOG, ">>$opt{LOG_FILE}") or
1476 dodie "failed to write to log";
1477 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001478 }
1479
1480 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001481 open (RD, ">$redirect") or
1482 dodie "failed to write to redirect $redirect";
1483 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001484 }
1485
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001486 while (<CMD>) {
1487 print LOG if ($dolog);
1488 print RD if ($dord);
1489 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001490
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001491 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001492 my $failed = $?;
1493
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001494 close(CMD);
1495 close(LOG) if ($dolog);
1496 close(RD) if ($dord);
1497
Steven Rostedt2545eb62010-11-02 15:01:32 -04001498 if ($failed) {
1499 doprint "FAILED!\n";
1500 } else {
1501 doprint "SUCCESS\n";
1502 }
1503
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001504 return !$failed;
1505}
1506
Steven Rostedte48c5292010-11-02 14:35:37 -04001507sub run_ssh {
1508 my ($cmd) = @_;
1509 my $cp_exec = $ssh_exec;
1510
1511 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1512 return run_command "$cp_exec";
1513}
1514
1515sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001516 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001517
1518 $cp_scp =~ s/\$SRC_FILE/$src/g;
1519 $cp_scp =~ s/\$DST_FILE/$dst/g;
1520
1521 return run_command "$cp_scp";
1522}
1523
Steven Rostedt02ad2612012-03-21 08:21:24 -04001524sub run_scp_install {
1525 my ($src, $dst) = @_;
1526
1527 my $cp_scp = $scp_to_target_install;
1528
1529 return run_scp($src, $dst, $cp_scp);
1530}
1531
1532sub run_scp_mod {
1533 my ($src, $dst) = @_;
1534
1535 my $cp_scp = $scp_to_target;
1536
1537 return run_scp($src, $dst, $cp_scp);
1538}
1539
Steven Rostedta15ba912012-11-13 14:30:37 -05001540sub get_grub2_index {
1541
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001542 return if (defined($grub_number) && defined($last_grub_menu) &&
1543 $last_grub_menu eq $grub_menu);
Steven Rostedta15ba912012-11-13 14:30:37 -05001544
1545 doprint "Find grub2 menu ... ";
1546 $grub_number = -1;
1547
1548 my $ssh_grub = $ssh_exec;
1549 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1550
1551 open(IN, "$ssh_grub |")
1552 or die "unable to get $grub_file";
1553
1554 my $found = 0;
1555
1556 while (<IN>) {
1557 if (/^menuentry.*$grub_menu/) {
1558 $grub_number++;
1559 $found = 1;
1560 last;
1561 } elsif (/^menuentry\s/) {
1562 $grub_number++;
1563 }
1564 }
1565 close(IN);
1566
1567 die "Could not find '$grub_menu' in $grub_file on $machine"
1568 if (!$found);
1569 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001570 $last_grub_menu = $grub_menu;
Steven Rostedta15ba912012-11-13 14:30:37 -05001571}
1572
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001573sub get_grub_index {
1574
Steven Rostedta15ba912012-11-13 14:30:37 -05001575 if ($reboot_type eq "grub2") {
1576 get_grub2_index;
1577 return;
1578 }
1579
Steven Rostedta75fece2010-11-02 14:58:27 -04001580 if ($reboot_type ne "grub") {
1581 return;
1582 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001583 return if (defined($grub_number) && defined($last_grub_menu) &&
1584 $last_grub_menu eq $grub_menu);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001585
1586 doprint "Find grub menu ... ";
1587 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001588
1589 my $ssh_grub = $ssh_exec;
1590 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1591
1592 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001593 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001594
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001595 my $found = 0;
1596
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001597 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001598 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001599 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001600 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001601 last;
1602 } elsif (/^\s*title\s/) {
1603 $grub_number++;
1604 }
1605 }
1606 close(IN);
1607
Steven Rostedta75fece2010-11-02 14:58:27 -04001608 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001609 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001610 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001611 $last_grub_menu = $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001612}
1613
Steven Rostedt2545eb62010-11-02 15:01:32 -04001614sub wait_for_input
1615{
1616 my ($fp, $time) = @_;
1617 my $rin;
1618 my $ready;
1619 my $line;
1620 my $ch;
1621
1622 if (!defined($time)) {
1623 $time = $timeout;
1624 }
1625
1626 $rin = '';
1627 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001628 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001629
1630 $line = "";
1631
1632 # try to read one char at a time
1633 while (sysread $fp, $ch, 1) {
1634 $line .= $ch;
1635 last if ($ch eq "\n");
1636 }
1637
1638 if (!length($line)) {
1639 return undef;
1640 }
1641
1642 return $line;
1643}
1644
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001645sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001646 if (defined($switch_to_test)) {
1647 run_command $switch_to_test;
1648 }
1649
Steven Rostedta75fece2010-11-02 14:58:27 -04001650 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001651 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001652 } elsif ($reboot_type eq "grub2") {
1653 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001654 } elsif ($reboot_type eq "syslinux") {
1655 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001656 } elsif (defined $reboot_script) {
1657 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001658 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001659 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001660}
1661
Steven Rostedta57419b2010-11-02 15:13:54 -04001662sub get_sha1 {
1663 my ($commit) = @_;
1664
1665 doprint "git rev-list --max-count=1 $commit ... ";
1666 my $sha1 = `git rev-list --max-count=1 $commit`;
1667 my $ret = $?;
1668
1669 logit $sha1;
1670
1671 if ($ret) {
1672 doprint "FAILED\n";
1673 dodie "Failed to get git $commit";
1674 }
1675
1676 print "SUCCESS\n";
1677
1678 chomp $sha1;
1679
1680 return $sha1;
1681}
1682
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001683sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001684 my $booted = 0;
1685 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001686 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001687 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001688 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001689
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001690 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001691
1692 my $line;
1693 my $full_line = "";
1694
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001695 open(DMESG, "> $dmesg") or
1696 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001697
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001698 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001699
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001700 my $success_start;
1701 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001702 my $monitor_start = time;
1703 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001704 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001705
Steven Rostedt2d01b262011-03-08 09:47:54 -05001706 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001707
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001708 if ($bug && defined($stop_after_failure) &&
1709 $stop_after_failure >= 0) {
1710 my $time = $stop_after_failure - (time - $failure_start);
1711 $line = wait_for_input($monitor_fp, $time);
1712 if (!defined($line)) {
1713 doprint "bug timed out after $booted_timeout seconds\n";
1714 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1715 last;
1716 }
1717 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001718 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001719 if (!defined($line)) {
1720 my $s = $booted_timeout == 1 ? "" : "s";
1721 doprint "Successful boot found: break after $booted_timeout second$s\n";
1722 last;
1723 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001724 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001725 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001726 if (!defined($line)) {
1727 my $s = $timeout == 1 ? "" : "s";
1728 doprint "Timed out after $timeout second$s\n";
1729 last;
1730 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001731 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001732
Steven Rostedt2545eb62010-11-02 15:01:32 -04001733 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001734 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001735
1736 # we are not guaranteed to get a full line
1737 $full_line .= $line;
1738
Steven Rostedta75fece2010-11-02 14:58:27 -04001739 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001740 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001741 $success_start = time;
1742 }
1743
1744 if ($booted && defined($stop_after_success) &&
1745 $stop_after_success >= 0) {
1746 my $now = time;
1747 if ($now - $success_start >= $stop_after_success) {
1748 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1749 last;
1750 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001751 }
1752
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001753 if ($full_line =~ /\[ backtrace testing \]/) {
1754 $skip_call_trace = 1;
1755 }
1756
Steven Rostedt2545eb62010-11-02 15:01:32 -04001757 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001758 if (!$bug && !$skip_call_trace) {
1759 if ($ignore_errors) {
1760 $bug_ignored = 1;
1761 } else {
1762 $bug = 1;
1763 $failure_start = time;
1764 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001765 }
1766 }
1767
1768 if ($bug && defined($stop_after_failure) &&
1769 $stop_after_failure >= 0) {
1770 my $now = time;
1771 if ($now - $failure_start >= $stop_after_failure) {
1772 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1773 last;
1774 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001775 }
1776
1777 if ($full_line =~ /\[ end of backtrace testing \]/) {
1778 $skip_call_trace = 0;
1779 }
1780
1781 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001782 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001783 $bug = 1;
1784 }
1785
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001786 # Detect triple faults by testing the banner
1787 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1788 if ($1 eq $version) {
1789 $version_found = 1;
1790 } elsif ($version_found && $detect_triplefault) {
1791 # We already booted into the kernel we are testing,
1792 # but now we booted into another kernel?
1793 # Consider this a triple fault.
1794 doprint "Aleady booted in Linux kernel $version, but now\n";
1795 doprint "we booted into Linux kernel $1.\n";
1796 doprint "Assuming that this is a triple fault.\n";
1797 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1798 last;
1799 }
1800 }
1801
Steven Rostedt2545eb62010-11-02 15:01:32 -04001802 if ($line =~ /\n/) {
1803 $full_line = "";
1804 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001805
1806 if ($stop_test_after > 0 && !$booted && !$bug) {
1807 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001808 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001809 $done = 1;
1810 }
1811 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001812 }
1813
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001814 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001815
Steven Rostedt2545eb62010-11-02 15:01:32 -04001816 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001817 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001818 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001819 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001820
Steven Rostedta75fece2010-11-02 14:58:27 -04001821 if (!$booted) {
1822 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001823 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001824 }
1825
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001826 if ($bug_ignored) {
1827 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1828 }
1829
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001830 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001831}
1832
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001833sub eval_kernel_version {
1834 my ($option) = @_;
1835
1836 $option =~ s/\$KERNEL_VERSION/$version/g;
1837
1838 return $option;
1839}
1840
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001841sub do_post_install {
1842
1843 return if (!defined($post_install));
1844
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001845 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001846 run_command "$cp_post_install" or
1847 dodie "Failed to run post install";
1848}
1849
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001850# Sometimes the reboot fails, and will hang. We try to ssh to the box
1851# and if we fail, we force another reboot, that should powercycle it.
1852sub test_booted {
1853 if (!run_ssh "echo testing connection") {
1854 reboot $sleep_time;
1855 }
1856}
1857
Steven Rostedt2545eb62010-11-02 15:01:32 -04001858sub install {
1859
Steven Rostedte0a87422011-09-30 17:50:48 -04001860 return if ($no_install);
1861
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001862 if (defined($pre_install)) {
1863 my $cp_pre_install = eval_kernel_version $pre_install;
1864 run_command "$cp_pre_install" or
1865 dodie "Failed to run pre install";
1866 }
1867
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001868 my $cp_target = eval_kernel_version $target_image;
1869
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001870 test_booted;
1871
Steven Rostedt02ad2612012-03-21 08:21:24 -04001872 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001873 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001874
1875 my $install_mods = 0;
1876
1877 # should we process modules?
1878 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001879 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001880 while (<IN>) {
1881 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001882 if (defined($1)) {
1883 $install_mods = 1;
1884 last;
1885 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001886 }
1887 }
1888 close(IN);
1889
1890 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001891 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001892 doprint "No modules needed\n";
1893 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001894 }
1895
Steven Rostedt627977d2012-03-21 08:16:15 -04001896 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001897 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001898
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001899 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001900 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001901
Steven Rostedte48c5292010-11-02 14:35:37 -04001902 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001903 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001904
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001905 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001906 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001907 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001908
Steven Rostedt02ad2612012-03-21 08:21:24 -04001909 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001910 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001911
Steven Rostedta75fece2010-11-02 14:58:27 -04001912 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001913
Steven Rostedte7b13442011-06-14 20:44:36 -04001914 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001915 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001916
Steven Rostedte48c5292010-11-02 14:35:37 -04001917 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001918
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001919 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001920}
1921
Steven Rostedtddf607e2011-06-14 20:49:13 -04001922sub get_version {
1923 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001924 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001925 doprint "$make kernelrelease ... ";
1926 $version = `$make kernelrelease | tail -1`;
1927 chomp($version);
1928 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001929 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001930}
1931
1932sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001933 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001934
1935 # Install bisects, don't need console
1936 if (defined $console) {
1937 start_monitor;
1938 wait_for_monitor 5;
1939 end_monitor;
1940 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001941
Steven Rostedtddf607e2011-06-14 20:49:13 -04001942 get_grub_index;
1943 get_version;
1944 install;
1945
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001946 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001947 return monitor;
1948}
1949
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001950my $check_build_re = ".*:.*(warning|error|Error):.*";
1951my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1952
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05001953sub process_warning_line {
1954 my ($line) = @_;
1955
1956 chomp $line;
1957
1958 # for distcc heterogeneous systems, some compilers
1959 # do things differently causing warning lines
1960 # to be slightly different. This makes an attempt
1961 # to fixe those issues.
1962
1963 # chop off the index into the line
1964 # using distcc, some compilers give different indexes
1965 # depending on white space
1966 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
1967
1968 # Some compilers use UTF-8 extended for quotes and some don't.
1969 $line =~ s/$utf8_quote/'/g;
1970
1971 return $line;
1972}
1973
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001974# Read buildlog and check against warnings file for any
1975# new warnings.
1976#
1977# Returns 1 if OK
1978# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001979sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001980 return 1 if (!defined $warnings_file);
1981
1982 my %warnings_list;
1983
1984 # Failed builds should not reboot the target
1985 my $save_no_reboot = $no_reboot;
1986 $no_reboot = 1;
1987
1988 if (-f $warnings_file) {
1989 open(IN, $warnings_file) or
1990 dodie "Error opening $warnings_file";
1991
1992 while (<IN>) {
1993 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05001994 my $warning = process_warning_line $_;
1995
1996 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001997 }
1998 }
1999 close(IN);
2000 }
2001
2002 # If warnings file didn't exist, and WARNINGS_FILE exist,
2003 # then we fail on any warning!
2004
2005 open(IN, $buildlog) or dodie "Can't open $buildlog";
2006 while (<IN>) {
2007 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002008 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002009
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002010 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002011 fail "New warning found (not in $warnings_file)\n$_\n";
2012 $no_reboot = $save_no_reboot;
2013 return 0;
2014 }
2015 }
2016 }
2017 $no_reboot = $save_no_reboot;
2018 close(IN);
2019}
2020
2021sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002022 my ($patch) = @_;
2023
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002024 my @files = `git show $patch | diffstat -l`;
2025
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002026 foreach my $file (@files) {
2027 chomp $file;
2028 }
2029
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002030 open(IN, "git show $patch |") or
2031 dodie "failed to show $patch";
2032 while (<IN>) {
2033 if (m,^--- a/(.*),) {
2034 chomp $1;
2035 $files[$#files] = $1;
2036 }
2037 }
2038 close(IN);
2039
2040 open(IN, $buildlog) or dodie "Can't open $buildlog";
2041 while (<IN>) {
2042 if (/^\s*(.*?):.*(warning|error)/) {
2043 my $err = $1;
2044 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002045 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002046 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002047 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002048 }
2049 }
2050 }
2051 }
2052 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002053
2054 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002055}
2056
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002057sub apply_min_config {
2058 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002059
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002060 # Read the config file and remove anything that
2061 # is in the force_config hash (from minconfig and others)
2062 # then add the force config back.
2063
2064 doprint "Applying minimum configurations into $output_config.new\n";
2065
2066 open (OUT, ">$outconfig") or
2067 dodie "Can't create $outconfig";
2068
2069 if (-f $output_config) {
2070 open (IN, $output_config) or
2071 dodie "Failed to open $output_config";
2072 while (<IN>) {
2073 if (/^(# )?(CONFIG_[^\s=]*)/) {
2074 next if (defined($force_config{$2}));
2075 }
2076 print OUT;
2077 }
2078 close IN;
2079 }
2080 foreach my $config (keys %force_config) {
2081 print OUT "$force_config{$config}\n";
2082 }
2083 close OUT;
2084
2085 run_command "mv $outconfig $output_config";
2086}
2087
2088sub make_oldconfig {
2089
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002090 my @force_list = keys %force_config;
2091
2092 if ($#force_list >= 0) {
2093 apply_min_config;
2094 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002095
Adam Leefb16d892012-09-01 01:05:17 +08002096 if (!run_command "$make olddefconfig") {
2097 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002098 # try oldnoconfig
2099 doprint "olddefconfig failed, trying make oldnoconfig\n";
2100 if (!run_command "$make oldnoconfig") {
2101 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2102 # try a yes '' | oldconfig
2103 run_command "yes '' | $make oldconfig" or
2104 dodie "failed make config oldconfig";
2105 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002106 }
2107}
2108
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002109# read a config file and use this to force new configs.
2110sub load_force_config {
2111 my ($config) = @_;
2112
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002113 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002114 open(IN, $config) or
2115 dodie "failed to read $config";
2116 while (<IN>) {
2117 chomp;
2118 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2119 $force_config{$1} = $_;
2120 } elsif (/^# (CONFIG_\S*) is not set/) {
2121 $force_config{$1} = $_;
2122 }
2123 }
2124 close IN;
2125}
2126
Steven Rostedt2545eb62010-11-02 15:01:32 -04002127sub build {
2128 my ($type) = @_;
2129
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002130 unlink $buildlog;
2131
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002132 # Failed builds should not reboot the target
2133 my $save_no_reboot = $no_reboot;
2134 $no_reboot = 1;
2135
Steven Rostedt683a3e62012-05-18 13:34:35 -04002136 # Calculate a new version from here.
2137 $have_version = 0;
2138
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002139 if (defined($pre_build)) {
2140 my $ret = run_command $pre_build;
2141 if (!$ret && defined($pre_build_die) &&
2142 $pre_build_die) {
2143 dodie "failed to pre_build\n";
2144 }
2145 }
2146
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002147 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002148 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002149 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002150
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002151 $type = "oldconfig";
2152 }
2153
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002154 # old config can ask questions
2155 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002156 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002157
2158 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002159 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002160
Andrew Jones13488232011-08-12 15:32:04 +02002161 if (!$noclean) {
2162 run_command "mv $output_config $outputdir/config_temp" or
2163 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002164
Andrew Jones13488232011-08-12 15:32:04 +02002165 run_command "$make mrproper" or dodie "make mrproper";
2166
2167 run_command "mv $outputdir/config_temp $output_config" or
2168 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002169 }
2170
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002171 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002172 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002173 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002174 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002175 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002176
2177 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002178 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2179 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002180 close(OUT);
2181
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002182 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002183 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002184 }
2185
Adam Leefb16d892012-09-01 01:05:17 +08002186 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002187 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002188 dodie "failed make config";
2189 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002190 # Run old config regardless, to enforce min configurations
2191 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002192
Steven Rostedta75fece2010-11-02 14:58:27 -04002193 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002194 my $build_ret = run_command "$make $build_options";
2195 undef $redirect;
2196
2197 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002198 # Because a post build may change the kernel version
2199 # do it now.
2200 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002201 my $ret = run_command $post_build;
2202 if (!$ret && defined($post_build_die) &&
2203 $post_build_die) {
2204 dodie "failed to post_build\n";
2205 }
2206 }
2207
2208 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002209 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002210 if ($in_bisect) {
2211 $no_reboot = $save_no_reboot;
2212 return 0;
2213 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002214 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002215 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002216
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002217 $no_reboot = $save_no_reboot;
2218
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002219 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002220}
2221
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002222sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002223 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002224 if (defined($poweroff_after_halt)) {
2225 sleep $poweroff_after_halt;
2226 run_command "$power_off";
2227 }
2228 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002229 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002230 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002231 }
2232}
2233
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002234sub success {
2235 my ($i) = @_;
2236
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002237 if (defined($post_test)) {
2238 run_command $post_test;
2239 }
2240
Steven Rostedte48c5292010-11-02 14:35:37 -04002241 $successes++;
2242
Steven Rostedt9064af52011-06-13 10:38:48 -04002243 my $name = "";
2244
2245 if (defined($test_name)) {
2246 $name = " ($test_name)";
2247 }
2248
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002249 doprint "\n\n*******************************************\n";
2250 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002251 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002252 doprint "*******************************************\n";
2253 doprint "*******************************************\n";
2254
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302255 if (defined($store_successes)) {
2256 save_logs "success", $store_successes;
2257 }
2258
Steven Rostedt576f6272010-11-02 14:58:38 -04002259 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002260 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002261 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002262 }
2263}
2264
Steven Rostedtc960bb92011-03-08 09:22:39 -05002265sub answer_bisect {
2266 for (;;) {
2267 doprint "Pass or fail? [p/f]";
2268 my $ans = <STDIN>;
2269 chomp $ans;
2270 if ($ans eq "p" || $ans eq "P") {
2271 return 1;
2272 } elsif ($ans eq "f" || $ans eq "F") {
2273 return 0;
2274 } else {
2275 print "Please answer 'P' or 'F'\n";
2276 }
2277 }
2278}
2279
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002280sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002281 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002282
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002283 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002284 $reboot_on_error = 0;
2285 $poweroff_on_error = 0;
2286 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002287
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302288 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002289 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302290 undef $redirect;
2291
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002292 exit $failed;
2293}
2294
2295my $child_done;
2296
2297sub child_finished {
2298 $child_done = 1;
2299}
2300
2301sub do_run_test {
2302 my $child_pid;
2303 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002304 my $line;
2305 my $full_line;
2306 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002307 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002308
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002309 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002310
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002311 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002312
2313 $child_done = 0;
2314
2315 $SIG{CHLD} = qw(child_finished);
2316
2317 $child_pid = fork;
2318
2319 child_run_test if (!$child_pid);
2320
2321 $full_line = "";
2322
2323 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002324 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002325 if (defined($line)) {
2326
2327 # we are not guaranteed to get a full line
2328 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002329 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002330
2331 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002332 if ($ignore_errors) {
2333 $bug_ignored = 1;
2334 } else {
2335 $bug = 1;
2336 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002337 }
2338
2339 if ($full_line =~ /Kernel panic -/) {
2340 $bug = 1;
2341 }
2342
2343 if ($line =~ /\n/) {
2344 $full_line = "";
2345 }
2346 }
2347 } while (!$child_done && !$bug);
2348
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002349 if (!$bug && $bug_ignored) {
2350 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2351 }
2352
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002353 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002354 my $failure_start = time;
2355 my $now;
2356 do {
2357 $line = wait_for_input($monitor_fp, 1);
2358 if (defined($line)) {
2359 doprint $line;
2360 }
2361 $now = time;
2362 if ($now - $failure_start >= $stop_after_failure) {
2363 last;
2364 }
2365 } while (defined($line));
2366
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002367 doprint "Detected kernel crash!\n";
2368 # kill the child with extreme prejudice
2369 kill 9, $child_pid;
2370 }
2371
2372 waitpid $child_pid, 0;
2373 $child_exit = $?;
2374
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002375 if (!$bug && $in_bisect) {
2376 if (defined($bisect_ret_good)) {
2377 if ($child_exit == $bisect_ret_good) {
2378 return 1;
2379 }
2380 }
2381 if (defined($bisect_ret_skip)) {
2382 if ($child_exit == $bisect_ret_skip) {
2383 return -1;
2384 }
2385 }
2386 if (defined($bisect_ret_abort)) {
2387 if ($child_exit == $bisect_ret_abort) {
2388 fail "test abort" and return -2;
2389 }
2390 }
2391 if (defined($bisect_ret_bad)) {
2392 if ($child_exit == $bisect_ret_skip) {
2393 return 0;
2394 }
2395 }
2396 if (defined($bisect_ret_default)) {
2397 if ($bisect_ret_default eq "good") {
2398 return 1;
2399 } elsif ($bisect_ret_default eq "bad") {
2400 return 0;
2401 } elsif ($bisect_ret_default eq "skip") {
2402 return -1;
2403 } elsif ($bisect_ret_default eq "abort") {
2404 return -2;
2405 } else {
2406 fail "unknown default action: $bisect_ret_default"
2407 and return -2;
2408 }
2409 }
2410 }
2411
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002412 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002413 return 0 if $in_bisect;
2414 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002415 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002416 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002417}
2418
Steven Rostedta75fece2010-11-02 14:58:27 -04002419sub run_git_bisect {
2420 my ($command) = @_;
2421
2422 doprint "$command ... ";
2423
2424 my $output = `$command 2>&1`;
2425 my $ret = $?;
2426
2427 logit $output;
2428
2429 if ($ret) {
2430 doprint "FAILED\n";
2431 dodie "Failed to git bisect";
2432 }
2433
2434 doprint "SUCCESS\n";
2435 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2436 doprint "$1 [$2]\n";
2437 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002438 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002439 doprint "Found bad commit... $1\n";
2440 return 0;
2441 } else {
2442 # we already logged it, just print it now.
2443 print $output;
2444 }
2445
2446 return 1;
2447}
2448
Steven Rostedtc23dca72011-03-08 09:26:31 -05002449sub bisect_reboot {
2450 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002451 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002452}
2453
2454# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002455sub run_bisect_test {
2456 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002457
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002458 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002459 my $result;
2460 my $output;
2461 my $ret;
2462
Steven Rostedt0a05c762010-11-08 11:14:10 -05002463 $in_bisect = 1;
2464
2465 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002466
2467 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002468 if ($failed && $bisect_skip) {
2469 $in_bisect = 0;
2470 return -1;
2471 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002472 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002473
2474 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002475 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002476
2477 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002478 if ($failed && $bisect_skip) {
2479 end_monitor;
2480 bisect_reboot;
2481 $in_bisect = 0;
2482 return -1;
2483 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002484 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002485
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002486 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002487 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002488 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002489 }
2490
2491 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002492 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002493 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002494 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002495 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002496
2497 # reboot the box to a kernel we can ssh to
2498 if ($type ne "build") {
2499 bisect_reboot;
2500 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002501 $in_bisect = 0;
2502
2503 return $result;
2504}
2505
2506sub run_bisect {
2507 my ($type) = @_;
2508 my $buildtype = "oldconfig";
2509
2510 # We should have a minconfig to use?
2511 if (defined($minconfig)) {
2512 $buildtype = "useconfig:$minconfig";
2513 }
2514
2515 my $ret = run_bisect_test $type, $buildtype;
2516
Steven Rostedtc960bb92011-03-08 09:22:39 -05002517 if ($bisect_manual) {
2518 $ret = answer_bisect;
2519 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002520
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002521 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002522 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002523 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002524 }
2525
Steven Rostedtc23dca72011-03-08 09:26:31 -05002526 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002527 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002528 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002529 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002530 } elsif ($bisect_skip) {
2531 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2532 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002533 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002534}
2535
Steven Rostedtdad98752011-11-22 20:48:57 -05002536sub update_bisect_replay {
2537 my $tmp_log = "$tmpdir/ktest_bisect_log";
2538 run_command "git bisect log > $tmp_log" or
2539 die "can't create bisect log";
2540 return $tmp_log;
2541}
2542
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002543sub bisect {
2544 my ($i) = @_;
2545
2546 my $result;
2547
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002548 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2549 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2550 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002551
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002552 my $good = $bisect_good;
2553 my $bad = $bisect_bad;
2554 my $type = $bisect_type;
2555 my $start = $bisect_start;
2556 my $replay = $bisect_replay;
2557 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002558
2559 if (defined($start_files)) {
2560 $start_files = " -- " . $start_files;
2561 } else {
2562 $start_files = "";
2563 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002564
Steven Rostedta57419b2010-11-02 15:13:54 -04002565 # convert to true sha1's
2566 $good = get_sha1($good);
2567 $bad = get_sha1($bad);
2568
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002569 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002570 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2571 $reverse_bisect = 1;
2572 } else {
2573 $reverse_bisect = 0;
2574 }
2575
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002576 # Can't have a test without having a test to run
2577 if ($type eq "test" && !defined($run_test)) {
2578 $type = "boot";
2579 }
2580
Steven Rostedtdad98752011-11-22 20:48:57 -05002581 # Check if a bisect was running
2582 my $bisect_start_file = "$builddir/.git/BISECT_START";
2583
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002584 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002585 my $do_check = defined($check) && $check ne "0";
2586
2587 if ( -f $bisect_start_file ) {
2588 print "Bisect in progress found\n";
2589 if ($do_check) {
2590 print " If you say yes, then no checks of good or bad will be done\n";
2591 }
2592 if (defined($replay)) {
2593 print "** BISECT_REPLAY is defined in config file **";
2594 print " Ignore config option and perform new git bisect log?\n";
2595 if (read_ync " (yes, no, or cancel) ") {
2596 $replay = update_bisect_replay;
2597 $do_check = 0;
2598 }
2599 } elsif (read_yn "read git log and continue?") {
2600 $replay = update_bisect_replay;
2601 $do_check = 0;
2602 }
2603 }
2604
2605 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002606
2607 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002608 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002609
2610 if ($check ne "good") {
2611 doprint "TESTING BISECT BAD [$bad]\n";
2612 run_command "git checkout $bad" or
2613 die "Failed to checkout $bad";
2614
2615 $result = run_bisect $type;
2616
2617 if ($result ne "bad") {
2618 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2619 }
2620 }
2621
2622 if ($check ne "bad") {
2623 doprint "TESTING BISECT GOOD [$good]\n";
2624 run_command "git checkout $good" or
2625 die "Failed to checkout $good";
2626
2627 $result = run_bisect $type;
2628
2629 if ($result ne "good") {
2630 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2631 }
2632 }
2633
2634 # checkout where we started
2635 run_command "git checkout $head" or
2636 die "Failed to checkout $head";
2637 }
2638
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002639 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002640 dodie "could not start bisect";
2641
2642 run_command "git bisect good $good" or
2643 dodie "could not set bisect good to $good";
2644
2645 run_git_bisect "git bisect bad $bad" or
2646 dodie "could not set bisect bad to $bad";
2647
2648 if (defined($replay)) {
2649 run_command "git bisect replay $replay" or
2650 dodie "failed to run replay";
2651 }
2652
2653 if (defined($start)) {
2654 run_command "git checkout $start" or
2655 dodie "failed to checkout $start";
2656 }
2657
2658 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002659 do {
2660 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002661 $test = run_git_bisect "git bisect $result";
2662 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002663
2664 run_command "git bisect log" or
2665 dodie "could not capture git bisect log";
2666
2667 run_command "git bisect reset" or
2668 dodie "could not reset git bisect";
2669
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002670 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002671
Steven Rostedt0a05c762010-11-08 11:14:10 -05002672 success $i;
2673}
2674
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002675# config_ignore holds the configs that were set (or unset) for
2676# a good config and we will ignore these configs for the rest
2677# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002678my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002679
2680# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002681my %config_set;
2682
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002683# config_off holds the set of configs that the bad config had disabled.
2684# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002685# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002686my %config_off;
2687
2688# config_off_tmp holds a set of configs to turn off for now
2689my @config_off_tmp;
2690
2691# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002692my %config_list;
2693my %null_config;
2694
2695my %dependency;
2696
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002697sub assign_configs {
2698 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002699
2700 open (IN, $config)
2701 or dodie "Failed to read $config";
2702
2703 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002704 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002705 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002706 }
2707 }
2708
2709 close(IN);
2710}
2711
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002712sub process_config_ignore {
2713 my ($config) = @_;
2714
2715 assign_configs \%config_ignore, $config;
2716}
2717
Steven Rostedt0a05c762010-11-08 11:14:10 -05002718sub read_current_config {
2719 my ($config_ref) = @_;
2720
2721 %{$config_ref} = ();
2722 undef %{$config_ref};
2723
2724 my @key = keys %{$config_ref};
2725 if ($#key >= 0) {
2726 print "did not delete!\n";
2727 exit;
2728 }
2729 open (IN, "$output_config");
2730
2731 while (<IN>) {
2732 if (/^(CONFIG\S+)=(.*)/) {
2733 ${$config_ref}{$1} = $2;
2734 }
2735 }
2736 close(IN);
2737}
2738
2739sub get_dependencies {
2740 my ($config) = @_;
2741
2742 my $arr = $dependency{$config};
2743 if (!defined($arr)) {
2744 return ();
2745 }
2746
2747 my @deps = @{$arr};
2748
2749 foreach my $dep (@{$arr}) {
2750 print "ADD DEP $dep\n";
2751 @deps = (@deps, get_dependencies $dep);
2752 }
2753
2754 return @deps;
2755}
2756
2757sub create_config {
2758 my @configs = @_;
2759
2760 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2761
2762 foreach my $config (@configs) {
2763 print OUT "$config_set{$config}\n";
2764 my @deps = get_dependencies $config;
2765 foreach my $dep (@deps) {
2766 print OUT "$config_set{$dep}\n";
2767 }
2768 }
2769
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002770 # turn off configs to keep off
2771 foreach my $config (keys %config_off) {
2772 print OUT "# $config is not set\n";
2773 }
2774
2775 # turn off configs that should be off for now
2776 foreach my $config (@config_off_tmp) {
2777 print OUT "# $config is not set\n";
2778 }
2779
Steven Rostedt0a05c762010-11-08 11:14:10 -05002780 foreach my $config (keys %config_ignore) {
2781 print OUT "$config_ignore{$config}\n";
2782 }
2783 close(OUT);
2784
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002785 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002786}
2787
2788sub compare_configs {
2789 my (%a, %b) = @_;
2790
2791 foreach my $item (keys %a) {
2792 if (!defined($b{$item})) {
2793 print "diff $item\n";
2794 return 1;
2795 }
2796 delete $b{$item};
2797 }
2798
2799 my @keys = keys %b;
2800 if ($#keys) {
2801 print "diff2 $keys[0]\n";
2802 }
2803 return -1 if ($#keys >= 0);
2804
2805 return 0;
2806}
2807
2808sub run_config_bisect_test {
2809 my ($type) = @_;
2810
2811 return run_bisect_test $type, "oldconfig";
2812}
2813
2814sub process_passed {
2815 my (%configs) = @_;
2816
2817 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2818 # Passed! All these configs are part of a good compile.
2819 # Add them to the min options.
2820 foreach my $config (keys %configs) {
2821 if (defined($config_list{$config})) {
2822 doprint " removing $config\n";
2823 $config_ignore{$config} = $config_list{$config};
2824 delete $config_list{$config};
2825 }
2826 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002827 doprint "config copied to $outputdir/config_good\n";
2828 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002829}
2830
2831sub process_failed {
2832 my ($config) = @_;
2833
2834 doprint "\n\n***************************************\n";
2835 doprint "Found bad config: $config\n";
2836 doprint "***************************************\n\n";
2837}
2838
2839sub run_config_bisect {
2840
2841 my @start_list = keys %config_list;
2842
2843 if ($#start_list < 0) {
2844 doprint "No more configs to test!!!\n";
2845 return -1;
2846 }
2847
2848 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002849 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002850 my $ret;
2851 my %current_config;
2852
2853 my $count = $#start_list + 1;
2854 doprint " $count configs to test\n";
2855
2856 my $half = int($#start_list / 2);
2857
2858 do {
2859 my @tophalf = @start_list[0 .. $half];
2860
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002861 # keep the bottom half off
2862 if ($half < $#start_list) {
2863 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2864 } else {
2865 @config_off_tmp = ();
2866 }
2867
Steven Rostedt0a05c762010-11-08 11:14:10 -05002868 create_config @tophalf;
2869 read_current_config \%current_config;
2870
2871 $count = $#tophalf + 1;
2872 doprint "Testing $count configs\n";
2873 my $found = 0;
2874 # make sure we test something
2875 foreach my $config (@tophalf) {
2876 if (defined($current_config{$config})) {
2877 logit " $config\n";
2878 $found = 1;
2879 }
2880 }
2881 if (!$found) {
2882 # try the other half
2883 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002884
2885 # keep the top half off
2886 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002887 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002888
Steven Rostedt0a05c762010-11-08 11:14:10 -05002889 create_config @tophalf;
2890 read_current_config \%current_config;
2891 foreach my $config (@tophalf) {
2892 if (defined($current_config{$config})) {
2893 logit " $config\n";
2894 $found = 1;
2895 }
2896 }
2897 if (!$found) {
2898 doprint "Failed: Can't make new config with current configs\n";
2899 foreach my $config (@start_list) {
2900 doprint " CONFIG: $config\n";
2901 }
2902 return -1;
2903 }
2904 $count = $#tophalf + 1;
2905 doprint "Testing $count configs\n";
2906 }
2907
2908 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002909 if ($bisect_manual) {
2910 $ret = answer_bisect;
2911 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002912 if ($ret) {
2913 process_passed %current_config;
2914 return 0;
2915 }
2916
2917 doprint "This config had a failure.\n";
2918 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002919 doprint "config copied to $outputdir/config_bad\n";
2920 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002921
2922 # A config exists in this group that was bad.
2923 foreach my $config (keys %config_list) {
2924 if (!defined($current_config{$config})) {
2925 doprint " removing $config\n";
2926 delete $config_list{$config};
2927 }
2928 }
2929
2930 @start_list = @tophalf;
2931
2932 if ($#start_list == 0) {
2933 process_failed $start_list[0];
2934 return 1;
2935 }
2936
2937 # remove half the configs we are looking at and see if
2938 # they are good.
2939 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002940 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002941
Steven Rostedtc960bb92011-03-08 09:22:39 -05002942 # we found a single config, try it again unless we are running manually
2943
2944 if ($bisect_manual) {
2945 process_failed $start_list[0];
2946 return 1;
2947 }
2948
Steven Rostedt0a05c762010-11-08 11:14:10 -05002949 my @tophalf = @start_list[0 .. 0];
2950
2951 $ret = run_config_bisect_test $type;
2952 if ($ret) {
2953 process_passed %current_config;
2954 return 0;
2955 }
2956
2957 process_failed $start_list[0];
2958 return 1;
2959}
2960
2961sub config_bisect {
2962 my ($i) = @_;
2963
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002964 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002965
2966 my $tmpconfig = "$tmpdir/use_config";
2967
Steven Rostedt30f75da2011-06-13 10:35:35 -04002968 if (defined($config_bisect_good)) {
2969 process_config_ignore $config_bisect_good;
2970 }
2971
Steven Rostedt0a05c762010-11-08 11:14:10 -05002972 # Make the file with the bad config and the min config
2973 if (defined($minconfig)) {
2974 # read the min config for things to ignore
2975 run_command "cp $minconfig $tmpconfig" or
2976 dodie "failed to copy $minconfig to $tmpconfig";
2977 } else {
2978 unlink $tmpconfig;
2979 }
2980
Steven Rostedt0a05c762010-11-08 11:14:10 -05002981 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002982 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002983 process_config_ignore $tmpconfig;
2984 }
2985
2986 # now process the start config
2987 run_command "cp $start_config $output_config" or
2988 dodie "failed to copy $start_config to $output_config";
2989
2990 # read directly what we want to check
2991 my %config_check;
2992 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002993 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002994
2995 while (<IN>) {
2996 if (/^((CONFIG\S*)=.*)/) {
2997 $config_check{$2} = $1;
2998 }
2999 }
3000 close(IN);
3001
Steven Rostedt250bae82011-07-15 22:05:59 -04003002 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003003 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003004
3005 # check to see what we lost (or gained)
3006 open (IN, $output_config)
3007 or dodie "Failed to read $start_config";
3008
3009 my %removed_configs;
3010 my %added_configs;
3011
3012 while (<IN>) {
3013 if (/^((CONFIG\S*)=.*)/) {
3014 # save off all options
3015 $config_set{$2} = $1;
3016 if (defined($config_check{$2})) {
3017 if (defined($config_ignore{$2})) {
3018 $removed_configs{$2} = $1;
3019 } else {
3020 $config_list{$2} = $1;
3021 }
3022 } elsif (!defined($config_ignore{$2})) {
3023 $added_configs{$2} = $1;
3024 $config_list{$2} = $1;
3025 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003026 } elsif (/^# ((CONFIG\S*).*)/) {
3027 # Keep these configs disabled
3028 $config_set{$2} = $1;
3029 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003030 }
3031 }
3032 close(IN);
3033
3034 my @confs = keys %removed_configs;
3035 if ($#confs >= 0) {
3036 doprint "Configs overridden by default configs and removed from check:\n";
3037 foreach my $config (@confs) {
3038 doprint " $config\n";
3039 }
3040 }
3041 @confs = keys %added_configs;
3042 if ($#confs >= 0) {
3043 doprint "Configs appearing in make oldconfig and added:\n";
3044 foreach my $config (@confs) {
3045 doprint " $config\n";
3046 }
3047 }
3048
3049 my %config_test;
3050 my $once = 0;
3051
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003052 @config_off_tmp = ();
3053
Steven Rostedt0a05c762010-11-08 11:14:10 -05003054 # Sometimes kconfig does weird things. We must make sure
3055 # that the config we autocreate has everything we need
3056 # to test, otherwise we may miss testing configs, or
3057 # may not be able to create a new config.
3058 # Here we create a config with everything set.
3059 create_config (keys %config_list);
3060 read_current_config \%config_test;
3061 foreach my $config (keys %config_list) {
3062 if (!defined($config_test{$config})) {
3063 if (!$once) {
3064 $once = 1;
3065 doprint "Configs not produced by kconfig (will not be checked):\n";
3066 }
3067 doprint " $config\n";
3068 delete $config_list{$config};
3069 }
3070 }
3071 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04003072
3073 if (defined($config_bisect_check) && $config_bisect_check) {
3074 doprint " Checking to make sure bad config with min config fails\n";
3075 create_config keys %config_list;
3076 $ret = run_config_bisect_test $config_bisect_type;
3077 if ($ret) {
3078 doprint " FAILED! Bad config with min config boots fine\n";
3079 return -1;
3080 }
3081 doprint " Bad config with min config fails as expected\n";
3082 }
3083
Steven Rostedt0a05c762010-11-08 11:14:10 -05003084 do {
3085 $ret = run_config_bisect;
3086 } while (!$ret);
3087
3088 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003089
3090 success $i;
3091}
3092
Steven Rostedt27d934b2011-05-20 09:18:18 -04003093sub patchcheck_reboot {
3094 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003095 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003096}
3097
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003098sub patchcheck {
3099 my ($i) = @_;
3100
3101 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003102 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003103 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003104 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003105
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003106 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003107
3108 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003109 if (defined($patchcheck_end)) {
3110 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003111 }
3112
Steven Rostedta57419b2010-11-02 15:13:54 -04003113 # Get the true sha1's since we can use things like HEAD~3
3114 $start = get_sha1($start);
3115 $end = get_sha1($end);
3116
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003117 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003118
3119 # Can't have a test without having a test to run
3120 if ($type eq "test" && !defined($run_test)) {
3121 $type = "boot";
3122 }
3123
3124 open (IN, "git log --pretty=oneline $end|") or
3125 dodie "could not get git list";
3126
3127 my @list;
3128
3129 while (<IN>) {
3130 chomp;
3131 $list[$#list+1] = $_;
3132 last if (/^$start/);
3133 }
3134 close(IN);
3135
3136 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003137 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003138 }
3139
3140 # go backwards in the list
3141 @list = reverse @list;
3142
3143 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003144 my %ignored_warnings;
3145
3146 if (defined($ignore_warnings)) {
3147 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3148 $ignored_warnings{$sha1} = 1;
3149 }
3150 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003151
3152 $in_patchcheck = 1;
3153 foreach my $item (@list) {
3154 my $sha1 = $item;
3155 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3156
3157 doprint "\nProcessing commit $item\n\n";
3158
3159 run_command "git checkout $sha1" or
3160 die "Failed to checkout $sha1";
3161
3162 # only clean on the first and last patch
3163 if ($item eq $list[0] ||
3164 $item eq $list[$#list]) {
3165 $noclean = $save_clean;
3166 } else {
3167 $noclean = 1;
3168 }
3169
3170 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003171 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003172 } else {
3173 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003174 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003175 }
3176
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003177 # No need to do per patch checking if warnings file exists
3178 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3179 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003180 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003181
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003182 check_buildlog or return 0;
3183
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003184 next if ($type eq "build");
3185
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003186 my $failed = 0;
3187
Steven Rostedtddf607e2011-06-14 20:49:13 -04003188 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003189
3190 if (!$failed && $type ne "boot"){
3191 do_run_test or $failed = 1;
3192 }
3193 end_monitor;
3194 return 0 if ($failed);
3195
Steven Rostedt27d934b2011-05-20 09:18:18 -04003196 patchcheck_reboot;
3197
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003198 }
3199 $in_patchcheck = 0;
3200 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003201
3202 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003203}
3204
Steven Rostedtb9066f62011-07-15 21:25:24 -04003205my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003206my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003207my $iflevel = 0;
3208my @ifdeps;
3209
3210# prevent recursion
3211my %read_kconfigs;
3212
Steven Rostedtac6974c2011-10-04 09:40:17 -04003213sub add_dep {
3214 # $config depends on $dep
3215 my ($config, $dep) = @_;
3216
3217 if (defined($depends{$config})) {
3218 $depends{$config} .= " " . $dep;
3219 } else {
3220 $depends{$config} = $dep;
3221 }
3222
3223 # record the number of configs depending on $dep
3224 if (defined $depcount{$dep}) {
3225 $depcount{$dep}++;
3226 } else {
3227 $depcount{$dep} = 1;
3228 }
3229}
3230
Steven Rostedtb9066f62011-07-15 21:25:24 -04003231# taken from streamline_config.pl
3232sub read_kconfig {
3233 my ($kconfig) = @_;
3234
3235 my $state = "NONE";
3236 my $config;
3237 my @kconfigs;
3238
3239 my $cont = 0;
3240 my $line;
3241
3242
3243 if (! -f $kconfig) {
3244 doprint "file $kconfig does not exist, skipping\n";
3245 return;
3246 }
3247
3248 open(KIN, "$kconfig")
3249 or die "Can't open $kconfig";
3250 while (<KIN>) {
3251 chomp;
3252
3253 # Make sure that lines ending with \ continue
3254 if ($cont) {
3255 $_ = $line . " " . $_;
3256 }
3257
3258 if (s/\\$//) {
3259 $cont = 1;
3260 $line = $_;
3261 next;
3262 }
3263
3264 $cont = 0;
3265
3266 # collect any Kconfig sources
3267 if (/^source\s*"(.*)"/) {
3268 $kconfigs[$#kconfigs+1] = $1;
3269 }
3270
3271 # configs found
3272 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3273 $state = "NEW";
3274 $config = $2;
3275
3276 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003277 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003278 }
3279
3280 # collect the depends for the config
3281 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3282
Steven Rostedtac6974c2011-10-04 09:40:17 -04003283 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003284
3285 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003286 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3287
3288 # selected by depends on config
3289 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003290
3291 # Check for if statements
3292 } elsif (/^if\s+(.*\S)\s*$/) {
3293 my $deps = $1;
3294 # remove beginning and ending non text
3295 $deps =~ s/^[^a-zA-Z0-9_]*//;
3296 $deps =~ s/[^a-zA-Z0-9_]*$//;
3297
3298 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3299
3300 $ifdeps[$iflevel++] = join ':', @deps;
3301
3302 } elsif (/^endif/) {
3303
3304 $iflevel-- if ($iflevel);
3305
3306 # stop on "help"
3307 } elsif (/^\s*help\s*$/) {
3308 $state = "NONE";
3309 }
3310 }
3311 close(KIN);
3312
3313 # read in any configs that were found.
3314 foreach $kconfig (@kconfigs) {
3315 if (!defined($read_kconfigs{$kconfig})) {
3316 $read_kconfigs{$kconfig} = 1;
3317 read_kconfig("$builddir/$kconfig");
3318 }
3319 }
3320}
3321
3322sub read_depends {
3323 # find out which arch this is by the kconfig file
3324 open (IN, $output_config)
3325 or dodie "Failed to read $output_config";
3326 my $arch;
3327 while (<IN>) {
3328 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3329 $arch = $1;
3330 last;
3331 }
3332 }
3333 close IN;
3334
3335 if (!defined($arch)) {
3336 doprint "Could not find arch from config file\n";
3337 doprint "no dependencies used\n";
3338 return;
3339 }
3340
3341 # arch is really the subarch, we need to know
3342 # what directory to look at.
3343 if ($arch eq "i386" || $arch eq "x86_64") {
3344 $arch = "x86";
3345 } elsif ($arch =~ /^tile/) {
3346 $arch = "tile";
3347 }
3348
3349 my $kconfig = "$builddir/arch/$arch/Kconfig";
3350
3351 if (! -f $kconfig && $arch =~ /\d$/) {
3352 my $orig = $arch;
3353 # some subarchs have numbers, truncate them
3354 $arch =~ s/\d*$//;
3355 $kconfig = "$builddir/arch/$arch/Kconfig";
3356 if (! -f $kconfig) {
3357 doprint "No idea what arch dir $orig is for\n";
3358 doprint "no dependencies used\n";
3359 return;
3360 }
3361 }
3362
3363 read_kconfig($kconfig);
3364}
3365
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003366sub read_config_list {
3367 my ($config) = @_;
3368
3369 open (IN, $config)
3370 or dodie "Failed to read $config";
3371
3372 while (<IN>) {
3373 if (/^((CONFIG\S*)=.*)/) {
3374 if (!defined($config_ignore{$2})) {
3375 $config_list{$2} = $1;
3376 }
3377 }
3378 }
3379
3380 close(IN);
3381}
3382
3383sub read_output_config {
3384 my ($config) = @_;
3385
3386 assign_configs \%config_ignore, $config;
3387}
3388
3389sub make_new_config {
3390 my @configs = @_;
3391
3392 open (OUT, ">$output_config")
3393 or dodie "Failed to write $output_config";
3394
3395 foreach my $config (@configs) {
3396 print OUT "$config\n";
3397 }
3398 close OUT;
3399}
3400
Steven Rostedtac6974c2011-10-04 09:40:17 -04003401sub chomp_config {
3402 my ($config) = @_;
3403
3404 $config =~ s/CONFIG_//;
3405
3406 return $config;
3407}
3408
Steven Rostedtb9066f62011-07-15 21:25:24 -04003409sub get_depends {
3410 my ($dep) = @_;
3411
Steven Rostedtac6974c2011-10-04 09:40:17 -04003412 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003413
3414 $dep = $depends{"$kconfig"};
3415
3416 # the dep string we have saves the dependencies as they
3417 # were found, including expressions like ! && ||. We
3418 # want to split this out into just an array of configs.
3419
3420 my $valid = "A-Za-z_0-9";
3421
3422 my @configs;
3423
3424 while ($dep =~ /[$valid]/) {
3425
3426 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3427 my $conf = "CONFIG_" . $1;
3428
3429 $configs[$#configs + 1] = $conf;
3430
3431 $dep =~ s/^[^$valid]*[$valid]+//;
3432 } else {
3433 die "this should never happen";
3434 }
3435 }
3436
3437 return @configs;
3438}
3439
3440my %min_configs;
3441my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003442my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003443my %processed_configs;
3444my %nochange_config;
3445
3446sub test_this_config {
3447 my ($config) = @_;
3448
3449 my $found;
3450
3451 # if we already processed this config, skip it
3452 if (defined($processed_configs{$config})) {
3453 return undef;
3454 }
3455 $processed_configs{$config} = 1;
3456
3457 # if this config failed during this round, skip it
3458 if (defined($nochange_config{$config})) {
3459 return undef;
3460 }
3461
Steven Rostedtac6974c2011-10-04 09:40:17 -04003462 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003463
3464 # Test dependencies first
3465 if (defined($depends{"$kconfig"})) {
3466 my @parents = get_depends $config;
3467 foreach my $parent (@parents) {
3468 # if the parent is in the min config, check it first
3469 next if (!defined($min_configs{$parent}));
3470 $found = test_this_config($parent);
3471 if (defined($found)) {
3472 return $found;
3473 }
3474 }
3475 }
3476
3477 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003478 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003479 # .config to make sure it is missing the config that
3480 # we had before
3481 my %configs = %min_configs;
3482 delete $configs{$config};
3483 make_new_config ((values %configs), (values %keep_configs));
3484 make_oldconfig;
3485 undef %configs;
3486 assign_configs \%configs, $output_config;
3487
3488 return $config if (!defined($configs{$config}));
3489
3490 doprint "disabling config $config did not change .config\n";
3491
3492 $nochange_config{$config} = 1;
3493
3494 return undef;
3495}
3496
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003497sub make_min_config {
3498 my ($i) = @_;
3499
Steven Rostedtccc513b2012-05-21 17:13:40 -04003500 my $type = $minconfig_type;
3501 if ($type ne "boot" && $type ne "test") {
3502 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3503 " make_min_config works only with 'boot' and 'test'\n" and return;
3504 }
3505
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003506 if (!defined($output_minconfig)) {
3507 fail "OUTPUT_MIN_CONFIG not defined" and return;
3508 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003509
3510 # If output_minconfig exists, and the start_minconfig
3511 # came from min_config, than ask if we should use
3512 # that instead.
3513 if (-f $output_minconfig && !$start_minconfig_defined) {
3514 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003515 if (!defined($use_output_minconfig)) {
3516 if (read_yn " Use it as minconfig?") {
3517 $start_minconfig = $output_minconfig;
3518 }
3519 } elsif ($use_output_minconfig > 0) {
3520 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003521 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003522 } else {
3523 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003524 }
3525 }
3526
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003527 if (!defined($start_minconfig)) {
3528 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3529 }
3530
Steven Rostedt35ce5952011-07-15 21:57:25 -04003531 my $temp_config = "$tmpdir/temp_config";
3532
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003533 # First things first. We build an allnoconfig to find
3534 # out what the defaults are that we can't touch.
3535 # Some are selections, but we really can't handle selections.
3536
3537 my $save_minconfig = $minconfig;
3538 undef $minconfig;
3539
3540 run_command "$make allnoconfig" or return 0;
3541
Steven Rostedtb9066f62011-07-15 21:25:24 -04003542 read_depends;
3543
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003544 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003545
Steven Rostedt43d1b652011-07-15 22:01:56 -04003546 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003547 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003548
3549 if (defined($ignore_config)) {
3550 # make sure the file exists
3551 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003552 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003553 }
3554
Steven Rostedt43d1b652011-07-15 22:01:56 -04003555 %keep_configs = %save_configs;
3556
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003557 doprint "Load initial configs from $start_minconfig\n";
3558
3559 # Look at the current min configs, and save off all the
3560 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003561 assign_configs \%min_configs, $start_minconfig;
3562
3563 my @config_keys = keys %min_configs;
3564
Steven Rostedtac6974c2011-10-04 09:40:17 -04003565 # All configs need a depcount
3566 foreach my $config (@config_keys) {
3567 my $kconfig = chomp_config $config;
3568 if (!defined $depcount{$kconfig}) {
3569 $depcount{$kconfig} = 0;
3570 }
3571 }
3572
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003573 # Remove anything that was set by the make allnoconfig
3574 # we shouldn't need them as they get set for us anyway.
3575 foreach my $config (@config_keys) {
3576 # Remove anything in the ignore_config
3577 if (defined($keep_configs{$config})) {
3578 my $file = $ignore_config;
3579 $file =~ s,.*/(.*?)$,$1,;
3580 doprint "$config set by $file ... ignored\n";
3581 delete $min_configs{$config};
3582 next;
3583 }
3584 # But make sure the settings are the same. If a min config
3585 # sets a selection, we do not want to get rid of it if
3586 # it is not the same as what we have. Just move it into
3587 # the keep configs.
3588 if (defined($config_ignore{$config})) {
3589 if ($config_ignore{$config} ne $min_configs{$config}) {
3590 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3591 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3592 $keep_configs{$config} = $min_configs{$config};
3593 } else {
3594 doprint "$config set by allnoconfig ... ignored\n";
3595 }
3596 delete $min_configs{$config};
3597 }
3598 }
3599
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003600 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003601 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003602
3603 while (!$done) {
3604
3605 my $config;
3606 my $found;
3607
3608 # Now disable each config one by one and do a make oldconfig
3609 # till we find a config that changes our list.
3610
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003611 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003612
3613 # Sort keys by who is most dependent on
3614 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3615 @test_configs ;
3616
3617 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003618 my $reset = 1;
3619 for (my $i = 0; $i < $#test_configs; $i++) {
3620 if (!defined($nochange_config{$test_configs[0]})) {
3621 $reset = 0;
3622 last;
3623 }
3624 # This config didn't change the .config last time.
3625 # Place it at the end
3626 my $config = shift @test_configs;
3627 push @test_configs, $config;
3628 }
3629
3630 # if every test config has failed to modify the .config file
3631 # in the past, then reset and start over.
3632 if ($reset) {
3633 undef %nochange_config;
3634 }
3635
Steven Rostedtb9066f62011-07-15 21:25:24 -04003636 undef %processed_configs;
3637
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003638 foreach my $config (@test_configs) {
3639
Steven Rostedtb9066f62011-07-15 21:25:24 -04003640 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003641
Steven Rostedtb9066f62011-07-15 21:25:24 -04003642 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003643
3644 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003645 }
3646
3647 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003648 # we could have failed due to the nochange_config hash
3649 # reset and try again
3650 if (!$take_two) {
3651 undef %nochange_config;
3652 $take_two = 1;
3653 next;
3654 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003655 doprint "No more configs found that we can disable\n";
3656 $done = 1;
3657 last;
3658 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003659 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003660
3661 $config = $found;
3662
3663 doprint "Test with $config disabled\n";
3664
3665 # set in_bisect to keep build and monitor from dieing
3666 $in_bisect = 1;
3667
3668 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003669 build "oldconfig" or $failed = 1;
3670 if (!$failed) {
3671 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003672
3673 if ($type eq "test" && !$failed) {
3674 do_run_test or $failed = 1;
3675 }
3676
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003677 end_monitor;
3678 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003679
3680 $in_bisect = 0;
3681
3682 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003683 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003684 # this config is needed, add it to the ignore list.
3685 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003686 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003687 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003688
3689 # update new ignore configs
3690 if (defined($ignore_config)) {
3691 open (OUT, ">$temp_config")
3692 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003693 foreach my $config (keys %save_configs) {
3694 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003695 }
3696 close OUT;
3697 run_command "mv $temp_config $ignore_config" or
3698 dodie "failed to copy update to $ignore_config";
3699 }
3700
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003701 } else {
3702 # We booted without this config, remove it from the minconfigs.
3703 doprint "$config is not needed, disabling\n";
3704
3705 delete $min_configs{$config};
3706
3707 # Also disable anything that is not enabled in this config
3708 my %configs;
3709 assign_configs \%configs, $output_config;
3710 my @config_keys = keys %min_configs;
3711 foreach my $config (@config_keys) {
3712 if (!defined($configs{$config})) {
3713 doprint "$config is not set, disabling\n";
3714 delete $min_configs{$config};
3715 }
3716 }
3717
3718 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003719 open (OUT, ">$temp_config")
3720 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003721 foreach my $config (keys %keep_configs) {
3722 print OUT "$keep_configs{$config}\n";
3723 }
3724 foreach my $config (keys %min_configs) {
3725 print OUT "$min_configs{$config}\n";
3726 }
3727 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003728
3729 run_command "mv $temp_config $output_minconfig" or
3730 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003731 }
3732
3733 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003734 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003735 }
3736
3737 success $i;
3738 return 1;
3739}
3740
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003741sub make_warnings_file {
3742 my ($i) = @_;
3743
3744 if (!defined($warnings_file)) {
3745 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3746 }
3747
3748 if ($build_type eq "nobuild") {
3749 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3750 }
3751
3752 build $build_type or dodie "Failed to build";
3753
3754 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3755
3756 open(IN, $buildlog) or dodie "Can't open $buildlog";
3757 while (<IN>) {
3758
3759 # Some compilers use UTF-8 extended for quotes
3760 # for distcc heterogeneous systems, this causes issues
3761 s/$utf8_quote/'/g;
3762
3763 if (/$check_build_re/) {
3764 print OUT;
3765 }
3766 }
3767 close(IN);
3768
3769 close(OUT);
3770
3771 success $i;
3772}
3773
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003774$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003775
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003776if ($#ARGV == 0) {
3777 $ktest_config = $ARGV[0];
3778 if (! -f $ktest_config) {
3779 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003780 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003781 exit 0;
3782 }
3783 }
3784} else {
3785 $ktest_config = "ktest.conf";
3786}
3787
3788if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003789 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003790 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003791 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3792 print OUT << "EOF"
3793# Generated by ktest.pl
3794#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003795
3796# PWD is a ktest.pl variable that will result in the process working
3797# directory that ktest.pl is executed in.
3798
3799# THIS_DIR is automatically assigned the PWD of the path that generated
3800# the config file. It is best to use this variable when assigning other
3801# directory paths within this directory. This allows you to easily
3802# move the test cases to other locations or to other machines.
3803#
3804THIS_DIR := $variable{"PWD"}
3805
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003806# Define each test with TEST_START
3807# The config options below it will override the defaults
3808TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003809TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003810
3811DEFAULTS
3812EOF
3813;
3814 close(OUT);
3815}
3816read_config $ktest_config;
3817
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003818if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003819 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003820}
3821
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003822# Append any configs entered in manually to the config file.
3823my @new_configs = keys %entered_configs;
3824if ($#new_configs >= 0) {
3825 print "\nAppending entered in configs to $ktest_config\n";
3826 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3827 foreach my $config (@new_configs) {
3828 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003829 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003830 }
3831}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003832
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003833if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3834 unlink $opt{"LOG_FILE"};
3835}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003836
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003837doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3838
Steven Rostedta57419b2010-11-02 15:13:54 -04003839for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3840
3841 if (!$i) {
3842 doprint "DEFAULT OPTIONS:\n";
3843 } else {
3844 doprint "\nTEST $i OPTIONS";
3845 if (defined($repeat_tests{$i})) {
3846 $repeat = $repeat_tests{$i};
3847 doprint " ITERATE $repeat";
3848 }
3849 doprint "\n";
3850 }
3851
3852 foreach my $option (sort keys %opt) {
3853
3854 if ($option =~ /\[(\d+)\]$/) {
3855 next if ($i != $1);
3856 } else {
3857 next if ($i);
3858 }
3859
3860 doprint "$option = $opt{$option}\n";
3861 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003862}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003863
Steven Rostedt2a625122011-05-20 15:48:59 -04003864sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003865 my ($name, $i) = @_;
3866
3867 my $option = "$name\[$i\]";
3868
3869 if (defined($opt{$option})) {
3870 return $opt{$option};
3871 }
3872
Steven Rostedta57419b2010-11-02 15:13:54 -04003873 foreach my $test (keys %repeat_tests) {
3874 if ($i >= $test &&
3875 $i < $test + $repeat_tests{$test}) {
3876 $option = "$name\[$test\]";
3877 if (defined($opt{$option})) {
3878 return $opt{$option};
3879 }
3880 }
3881 }
3882
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003883 if (defined($opt{$name})) {
3884 return $opt{$name};
3885 }
3886
3887 return undef;
3888}
3889
Steven Rostedt2a625122011-05-20 15:48:59 -04003890sub set_test_option {
3891 my ($name, $i) = @_;
3892
3893 my $option = __set_test_option($name, $i);
3894 return $option if (!defined($option));
3895
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003896 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003897}
3898
Steven Rostedt2545eb62010-11-02 15:01:32 -04003899# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003900for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003901
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003902 # Do not reboot on failing test options
3903 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003904 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003905
Steven Rostedt683a3e62012-05-18 13:34:35 -04003906 $have_version = 0;
3907
Steven Rostedt576f6272010-11-02 14:58:38 -04003908 $iteration = $i;
3909
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003910 undef %force_config;
3911
Steven Rostedta75fece2010-11-02 14:58:27 -04003912 my $makecmd = set_test_option("MAKE_CMD", $i);
3913
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003914 # Load all the options into their mapped variable names
3915 foreach my $opt (keys %option_map) {
3916 ${$option_map{$opt}} = set_test_option($opt, $i);
3917 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003918
Steven Rostedt35ce5952011-07-15 21:57:25 -04003919 $start_minconfig_defined = 1;
3920
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003921 # The first test may override the PRE_KTEST option
3922 if (defined($pre_ktest) && $i == 1) {
3923 doprint "\n";
3924 run_command $pre_ktest;
3925 }
3926
3927 # Any test can override the POST_KTEST option
3928 # The last test takes precedence.
3929 if (defined($post_ktest)) {
3930 $final_post_ktest = $post_ktest;
3931 }
3932
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003933 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003934 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003935 $start_minconfig = $minconfig;
3936 }
3937
Steven Rostedta75fece2010-11-02 14:58:27 -04003938 chdir $builddir || die "can't change directory to $builddir";
3939
Andrew Jonesa908a662011-08-12 15:32:03 +02003940 foreach my $dir ($tmpdir, $outputdir) {
3941 if (!-d $dir) {
3942 mkpath($dir) or
3943 die "can't create $dir";
3944 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003945 }
3946
Steven Rostedte48c5292010-11-02 14:35:37 -04003947 $ENV{"SSH_USER"} = $ssh_user;
3948 $ENV{"MACHINE"} = $machine;
3949
Steven Rostedta75fece2010-11-02 14:58:27 -04003950 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303951 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003952 $dmesg = "$tmpdir/dmesg-$machine";
3953 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003954 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003955
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003956 if (!$buildonly) {
3957 $target = "$ssh_user\@$machine";
3958 if ($reboot_type eq "grub") {
3959 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05003960 } elsif ($reboot_type eq "grub2") {
3961 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3962 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05003963 } elsif ($reboot_type eq "syslinux") {
3964 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003965 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003966 }
3967
3968 my $run_type = $build_type;
3969 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003970 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003971 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003972 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003973 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003974 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003975 } elsif ($test_type eq "make_min_config") {
3976 $run_type = "";
3977 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003978 $run_type = "";
3979 }
3980
Steven Rostedta75fece2010-11-02 14:58:27 -04003981 # mistake in config file?
3982 if (!defined($run_type)) {
3983 $run_type = "ERROR";
3984 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003985
Steven Rostedte0a87422011-09-30 17:50:48 -04003986 my $installme = "";
3987 $installme = " no_install" if ($no_install);
3988
Steven Rostedt2545eb62010-11-02 15:01:32 -04003989 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003990 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003991
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003992 if (defined($pre_test)) {
3993 run_command $pre_test;
3994 }
3995
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003996 unlink $dmesg;
3997 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303998 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003999
Steven Rostedt250bae82011-07-15 22:05:59 -04004000 if (defined($addconfig)) {
4001 my $min = $minconfig;
4002 if (!defined($minconfig)) {
4003 $min = "";
4004 }
4005 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004006 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004007 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004008 }
4009
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004010 if (defined($checkout)) {
4011 run_command "git checkout $checkout" or
4012 die "failed to checkout $checkout";
4013 }
4014
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004015 $no_reboot = 0;
4016
Steven Rostedt648a1822012-03-21 11:18:27 -04004017 # A test may opt to not reboot the box
4018 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004019 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004020 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004021
Steven Rostedta75fece2010-11-02 14:58:27 -04004022 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004023 bisect $i;
4024 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004025 } elsif ($test_type eq "config_bisect") {
4026 config_bisect $i;
4027 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004028 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004029 patchcheck $i;
4030 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004031 } elsif ($test_type eq "make_min_config") {
4032 make_min_config $i;
4033 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004034 } elsif ($test_type eq "make_warnings_file") {
4035 $no_reboot = 1;
4036 make_warnings_file $i;
4037 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004038 }
4039
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004040 if ($build_type ne "nobuild") {
4041 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004042 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004043 }
4044
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004045 if ($test_type eq "install") {
4046 get_version;
4047 install;
4048 success $i;
4049 next;
4050 }
4051
Steven Rostedta75fece2010-11-02 14:58:27 -04004052 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004053 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004054 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004055
4056 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4057 do_run_test or $failed = 1;
4058 }
4059 end_monitor;
4060 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004061 }
4062
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004063 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004064}
4065
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004066if (defined($final_post_ktest)) {
4067 run_command $final_post_ktest;
4068}
4069
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004070if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004071 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004072} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004073 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004074} elsif (defined($switch_to_good)) {
4075 # still need to get to the good kernel
4076 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004077}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004078
Steven Rostedt648a1822012-03-21 11:18:27 -04004079
Steven Rostedte48c5292010-11-02 14:35:37 -04004080doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4081
Steven Rostedt2545eb62010-11-02 15:01:32 -04004082exit 0;