blob: b285933873c79ac26702c99bde6aec2c926dd350 [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",
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +090028 "CLOSE_CONSOLE_SIGNAL" => "INT",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050029 "TIMEOUT" => 120,
30 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
31 "SLEEP_TIME" => 60, # sleep time between tests
32 "BUILD_NOCLEAN" => 0,
33 "REBOOT_ON_ERROR" => 0,
34 "POWEROFF_ON_ERROR" => 0,
35 "REBOOT_ON_SUCCESS" => 1,
36 "POWEROFF_ON_SUCCESS" => 0,
37 "BUILD_OPTIONS" => "",
38 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
39 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
40 "CLEAR_LOG" => 0,
41 "BISECT_MANUAL" => 0,
42 "BISECT_SKIP" => 1,
Steven Rostedtccc513b2012-05-21 17:13:40 -040043 "MIN_CONFIG_TYPE" => "boot",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050044 "SUCCESS_LINE" => "login:",
45 "DETECT_TRIPLE_FAULT" => 1,
46 "NO_INSTALL" => 0,
47 "BOOTED_TIMEOUT" => 1,
48 "DIE_ON_FAILURE" => 1,
49 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
50 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
Steven Rostedt02ad2612012-03-21 08:21:24 -040051 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050052 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
53 "STOP_AFTER_SUCCESS" => 10,
54 "STOP_AFTER_FAILURE" => 60,
55 "STOP_TEST_AFTER" => 600,
Steven Rostedt407b95b2012-07-19 16:05:42 -040056 "MAX_MONITOR_WAIT" => 1800,
Steven Rostedta15ba912012-11-13 14:30:37 -050057 "GRUB_REBOOT" => "grub2-reboot",
Steven Rostedt77869542012-12-11 17:37:41 -050058 "SYSLINUX" => "extlinux",
59 "SYSLINUX_PATH" => "/boot/extlinux",
Steven Rostedt600bbf02011-11-21 20:12:04 -050060
61# required, and we will ask users if they don't have them but we keep the default
62# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050063 "REBOOT_TYPE" => "grub",
64 "LOCALVERSION" => "-test",
65 "SSH_USER" => "root",
66 "BUILD_TARGET" => "arch/x86/boot/bzImage",
67 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050068
69 "LOG_FILE" => undef,
70 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050071);
Steven Rostedt2545eb62010-11-02 15:01:32 -040072
Steven Rostedt8d1491b2010-11-18 15:39:48 -050073my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040074my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040075my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040076my $machine;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -040077my $last_machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040078my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040079my $tmpdir;
80my $builddir;
81my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050082my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040083my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040084my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040085my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040086my $final_post_ktest;
87my $pre_ktest;
88my $post_ktest;
89my $pre_test;
90my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040091my $pre_build;
92my $post_build;
93my $pre_build_die;
94my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040095my $reboot_type;
96my $reboot_script;
97my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040098my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040099my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -0500100my $switch_to_good;
101my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -0400102my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -0400103my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -0400104my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -0400105my $powercycle_after_reboot;
106my $poweroff_after_halt;
Steven Rostedt407b95b2012-07-19 16:05:42 -0400107my $max_monitor_wait;
Steven Rostedte48c5292010-11-02 14:35:37 -0400108my $ssh_exec;
109my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400110my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400111my $power_off;
112my $grub_menu;
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -0500113my $last_grub_menu;
Steven Rostedta15ba912012-11-13 14:30:37 -0500114my $grub_file;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400115my $grub_number;
Steven Rostedta15ba912012-11-13 14:30:37 -0500116my $grub_reboot;
Steven Rostedt77869542012-12-11 17:37:41 -0500117my $syslinux;
118my $syslinux_path;
119my $syslinux_label;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400120my $target;
121my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400122my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400123my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400124my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400125my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400126my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400127my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400128my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400129my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400130my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400131my $use_output_minconfig;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500132my $warnings_file;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400133my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500134my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400135my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400136my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500137my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400138my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500139my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500140my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400141my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500142my $bisect_ret_good;
143my $bisect_ret_bad;
144my $bisect_ret_skip;
145my $bisect_ret_abort;
146my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400147my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400148my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400149my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400150my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530151my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400152my $dmesg;
153my $monitor_fp;
154my $monitor_pid;
155my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400156my $sleep_time;
157my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400158my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400159my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400160my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530161my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400162my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400163my $timeout;
164my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400165my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400166my $console;
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900167my $close_console_signal;
Steven Rostedt2b803362011-09-30 18:00:23 -0400168my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400169my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500170my $stop_after_success;
171my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500172my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400173my $build_target;
174my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500175my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400176my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400177my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400178my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400179
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500180my $bisect_good;
181my $bisect_bad;
182my $bisect_type;
183my $bisect_start;
184my $bisect_replay;
185my $bisect_files;
186my $bisect_reverse;
187my $bisect_check;
188
189my $config_bisect;
190my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400191my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500192
193my $patchcheck_type;
194my $patchcheck_start;
195my $patchcheck_end;
196
Steven Rostedt165708b2011-11-26 20:56:52 -0500197# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500198# which would require more options.
199my $buildonly = 1;
200
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500201# tell build not to worry about warnings, even when WARNINGS_FILE is set
202my $warnings_ok = 0;
203
Steven Rostedtdbd37832011-11-23 16:00:48 -0500204# set when creating a new config
205my $newconfig = 0;
206
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500207my %entered_configs;
208my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400209my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400210
211# force_config is the list of configs that we force enabled (or disabled)
212# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400213my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500214
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400215# do not force reboots on config problems
216my $no_reboot = 1;
217
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400218# reboot on success
219my $reboot_success = 0;
220
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500221my %option_map = (
222 "MACHINE" => \$machine,
223 "SSH_USER" => \$ssh_user,
224 "TMP_DIR" => \$tmpdir,
225 "OUTPUT_DIR" => \$outputdir,
226 "BUILD_DIR" => \$builddir,
227 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400228 "PRE_KTEST" => \$pre_ktest,
229 "POST_KTEST" => \$post_ktest,
230 "PRE_TEST" => \$pre_test,
231 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500232 "BUILD_TYPE" => \$build_type,
233 "BUILD_OPTIONS" => \$build_options,
234 "PRE_BUILD" => \$pre_build,
235 "POST_BUILD" => \$post_build,
236 "PRE_BUILD_DIE" => \$pre_build_die,
237 "POST_BUILD_DIE" => \$post_build_die,
238 "POWER_CYCLE" => \$power_cycle,
239 "REBOOT" => \$reboot,
240 "BUILD_NOCLEAN" => \$noclean,
241 "MIN_CONFIG" => \$minconfig,
242 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
243 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400244 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400245 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500246 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500247 "IGNORE_CONFIG" => \$ignore_config,
248 "TEST" => \$run_test,
249 "ADD_CONFIG" => \$addconfig,
250 "REBOOT_TYPE" => \$reboot_type,
251 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500252 "GRUB_FILE" => \$grub_file,
253 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500254 "SYSLINUX" => \$syslinux,
255 "SYSLINUX_PATH" => \$syslinux_path,
256 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400257 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500258 "POST_INSTALL" => \$post_install,
259 "NO_INSTALL" => \$no_install,
260 "REBOOT_SCRIPT" => \$reboot_script,
261 "REBOOT_ON_ERROR" => \$reboot_on_error,
262 "SWITCH_TO_GOOD" => \$switch_to_good,
263 "SWITCH_TO_TEST" => \$switch_to_test,
264 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400265 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500266 "DIE_ON_FAILURE" => \$die_on_failure,
267 "POWER_OFF" => \$power_off,
268 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
269 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400270 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500271 "SLEEP_TIME" => \$sleep_time,
272 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
273 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
274 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500275 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500276 "BISECT_MANUAL" => \$bisect_manual,
277 "BISECT_SKIP" => \$bisect_skip,
278 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
279 "BISECT_RET_GOOD" => \$bisect_ret_good,
280 "BISECT_RET_BAD" => \$bisect_ret_bad,
281 "BISECT_RET_SKIP" => \$bisect_ret_skip,
282 "BISECT_RET_ABORT" => \$bisect_ret_abort,
283 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
284 "STORE_FAILURES" => \$store_failures,
285 "STORE_SUCCESSES" => \$store_successes,
286 "TEST_NAME" => \$test_name,
287 "TIMEOUT" => \$timeout,
288 "BOOTED_TIMEOUT" => \$booted_timeout,
289 "CONSOLE" => \$console,
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900290 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500291 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
292 "SUCCESS_LINE" => \$success_line,
293 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
294 "STOP_AFTER_SUCCESS" => \$stop_after_success,
295 "STOP_AFTER_FAILURE" => \$stop_after_failure,
296 "STOP_TEST_AFTER" => \$stop_test_after,
297 "BUILD_TARGET" => \$build_target,
298 "SSH_EXEC" => \$ssh_exec,
299 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400300 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500301 "CHECKOUT" => \$checkout,
302 "TARGET_IMAGE" => \$target_image,
303 "LOCALVERSION" => \$localversion,
304
305 "BISECT_GOOD" => \$bisect_good,
306 "BISECT_BAD" => \$bisect_bad,
307 "BISECT_TYPE" => \$bisect_type,
308 "BISECT_START" => \$bisect_start,
309 "BISECT_REPLAY" => \$bisect_replay,
310 "BISECT_FILES" => \$bisect_files,
311 "BISECT_REVERSE" => \$bisect_reverse,
312 "BISECT_CHECK" => \$bisect_check,
313
314 "CONFIG_BISECT" => \$config_bisect,
315 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400316 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500317
318 "PATCHCHECK_TYPE" => \$patchcheck_type,
319 "PATCHCHECK_START" => \$patchcheck_start,
320 "PATCHCHECK_END" => \$patchcheck_end,
321);
322
323# Options may be used by other options, record them.
324my %used_options;
325
Steven Rostedt7bf51072011-10-22 09:07:03 -0400326# default variables that can be used
327chomp ($variable{"PWD"} = `pwd`);
328
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500329$config_help{"MACHINE"} = << "EOF"
330 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500331 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500332EOF
333 ;
334$config_help{"SSH_USER"} = << "EOF"
335 The box is expected to have ssh on normal bootup, provide the user
336 (most likely root, since you need privileged operations)
337EOF
338 ;
339$config_help{"BUILD_DIR"} = << "EOF"
340 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500341 You can use \${PWD} that will be the path where ktest.pl is run, or use
342 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500343EOF
344 ;
345$config_help{"OUTPUT_DIR"} = << "EOF"
346 The directory that the objects will be built (full path).
347 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500348 You can use \${PWD} that will be the path where ktest.pl is run, or use
349 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500350EOF
351 ;
352$config_help{"BUILD_TARGET"} = << "EOF"
353 The location of the compiled file to copy to the target.
354 (relative to OUTPUT_DIR)
355EOF
356 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500357$config_help{"BUILD_OPTIONS"} = << "EOF"
358 Options to add to \"make\" when building.
359 i.e. -j20
360EOF
361 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500362$config_help{"TARGET_IMAGE"} = << "EOF"
363 The place to put your image on the test machine.
364EOF
365 ;
366$config_help{"POWER_CYCLE"} = << "EOF"
367 A script or command to reboot the box.
368
369 Here is a digital loggers power switch example
370 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
371
372 Here is an example to reboot a virtual box on the current host
373 with the name "Guest".
374 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
375EOF
376 ;
377$config_help{"CONSOLE"} = << "EOF"
378 The script or command that reads the console
379
380 If you use ttywatch server, something like the following would work.
381CONSOLE = nc -d localhost 3001
382
383 For a virtual machine with guest name "Guest".
384CONSOLE = virsh console Guest
385EOF
386 ;
387$config_help{"LOCALVERSION"} = << "EOF"
388 Required version ending to differentiate the test
389 from other linux builds on the system.
390EOF
391 ;
392$config_help{"REBOOT_TYPE"} = << "EOF"
393 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500394 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500395
396 If you specify grub, it will assume grub version 1
397 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
398 and select that target to reboot to the kernel. If this is not
399 your setup, then specify "script" and have a command or script
400 specified in REBOOT_SCRIPT to boot to the target.
401
402 The entry in /boot/grub/menu.lst must be entered in manually.
403 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500404
405 If you specify grub2, then you also need to specify both \$GRUB_MENU
406 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500407
408 If you specify syslinux, then you may use SYSLINUX to define the syslinux
409 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
410 the syslinux install (defaults to /boot/extlinux). But you have to specify
411 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500412EOF
413 ;
414$config_help{"GRUB_MENU"} = << "EOF"
415 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500416 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500417
418 Note, ktest.pl will not update the grub menu.lst, you need to
419 manually add an option for the test. ktest.pl will search
420 the grub menu.lst for this option to find what kernel to
421 reboot into.
422
423 For example, if in the /boot/grub/menu.lst the test kernel title has:
424 title Test Kernel
425 kernel vmlinuz-test
426 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500427
428 For grub2, a search of \$GRUB_FILE is performed for the lines
429 that begin with "menuentry". It will not detect submenus. The
430 menu must be a non-nested menu. Add the quotes used in the menu
431 to guarantee your selection, as the first menuentry with the content
432 of \$GRUB_MENU that is found will be used.
433EOF
434 ;
435$config_help{"GRUB_FILE"} = << "EOF"
436 If grub2 is used, the full path for the grub.cfg file is placed
437 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500438EOF
439 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500440$config_help{"SYSLINUX_LABEL"} = << "EOF"
441 If syslinux is used, the label that boots the target kernel must
442 be specified with SYSLINUX_LABEL.
443EOF
444 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500445$config_help{"REBOOT_SCRIPT"} = << "EOF"
446 A script to reboot the target into the test kernel
447 (Only mandatory if REBOOT_TYPE = script)
448EOF
449 ;
450
Steven Rostedtdad98752011-11-22 20:48:57 -0500451sub read_prompt {
452 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400453
454 my $ans;
455
456 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500457 if ($cancel) {
458 print "$prompt [y/n/C] ";
459 } else {
460 print "$prompt [Y/n] ";
461 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400462 $ans = <STDIN>;
463 chomp $ans;
464 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500465 if ($cancel) {
466 $ans = "c";
467 } else {
468 $ans = "y";
469 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400470 }
471 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500472 if ($cancel) {
473 last if ($ans =~ /^c$/i);
474 print "Please answer either 'y', 'n' or 'c'.\n";
475 } else {
476 print "Please answer either 'y' or 'n'.\n";
477 }
478 }
479 if ($ans =~ /^c/i) {
480 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400481 }
482 if ($ans !~ /^y$/i) {
483 return 0;
484 }
485 return 1;
486}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500487
Steven Rostedtdad98752011-11-22 20:48:57 -0500488sub read_yn {
489 my ($prompt) = @_;
490
491 return read_prompt 0, $prompt;
492}
493
494sub read_ync {
495 my ($prompt) = @_;
496
497 return read_prompt 1, $prompt;
498}
499
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500500sub get_ktest_config {
501 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400502 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500503
504 return if (defined($opt{$config}));
505
506 if (defined($config_help{$config})) {
507 print "\n";
508 print $config_help{$config};
509 }
510
511 for (;;) {
512 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500513 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500514 print "\[$default{$config}\] ";
515 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400516 $ans = <STDIN>;
517 $ans =~ s/^\s*(.*\S)\s*$/$1/;
518 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500519 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400520 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500521 } else {
522 print "Your answer can not be blank\n";
523 next;
524 }
525 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500526 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500527 last;
528 }
529}
530
531sub get_ktest_configs {
532 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500533 get_ktest_config("BUILD_DIR");
534 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500535
Steven Rostedtdbd37832011-11-23 16:00:48 -0500536 if ($newconfig) {
537 get_ktest_config("BUILD_OPTIONS");
538 }
539
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500540 # options required for other than just building a kernel
541 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500542 get_ktest_config("POWER_CYCLE");
543 get_ktest_config("CONSOLE");
544 }
545
546 # options required for install and more
547 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500548 get_ktest_config("SSH_USER");
549 get_ktest_config("BUILD_TARGET");
550 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500551 }
552
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500553 get_ktest_config("LOCALVERSION");
554
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500555 return if ($buildonly);
556
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500557 my $rtype = $opt{"REBOOT_TYPE"};
558
559 if (!defined($rtype)) {
560 if (!defined($opt{"GRUB_MENU"})) {
561 get_ktest_config("REBOOT_TYPE");
562 $rtype = $entered_configs{"REBOOT_TYPE"};
563 } else {
564 $rtype = "grub";
565 }
566 }
567
568 if ($rtype eq "grub") {
569 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500570 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500571
572 if ($rtype eq "grub2") {
573 get_ktest_config("GRUB_MENU");
574 get_ktest_config("GRUB_FILE");
575 }
Steven Rostedt77869542012-12-11 17:37:41 -0500576
577 if ($rtype eq "syslinux") {
578 get_ktest_config("SYSLINUX_LABEL");
579 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500580}
581
Steven Rostedt77d942c2011-05-20 13:36:58 -0400582sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400583 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400584 my $retval = "";
585
586 # We want to check for '\', and it is just easier
587 # to check the previous characet of '$' and not need
588 # to worry if '$' is the first character. By adding
589 # a space to $value, we can just check [^\\]\$ and
590 # it will still work.
591 $value = " $value";
592
593 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
594 my $begin = $1;
595 my $var = $2;
596 my $end = $3;
597 # append beginning of value to retval
598 $retval = "$retval$begin";
599 if (defined($variable{$var})) {
600 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400601 } elsif (defined($remove_undef) && $remove_undef) {
602 # for if statements, any variable that is not defined,
603 # we simple convert to 0
604 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400605 } else {
606 # put back the origin piece.
607 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500608 # This could be an option that is used later, save
609 # it so we don't warn if this option is not one of
610 # ktests options.
611 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400612 }
613 $value = $end;
614 }
615 $retval = "$retval$value";
616
617 # remove the space added in the beginning
618 $retval =~ s/ //;
619
620 return "$retval"
621}
622
Steven Rostedta57419b2010-11-02 15:13:54 -0400623sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400624 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400625
Steven Rostedtcad96662011-12-22 11:32:52 -0500626 my $prvalue = process_variables($rvalue);
627
628 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500629 # Note if a test is something other than build, then we
630 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500631 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500632 # for bisect, we need to check BISECT_TYPE
633 if ($prvalue ne "bisect") {
634 $buildonly = 0;
635 }
636 } else {
637 # install still limits some manditory options.
638 $buildonly = 2;
639 }
640 }
641
642 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
643 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500644 $buildonly = 0;
645 } else {
646 # install still limits some manditory options.
647 $buildonly = 2;
648 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500649 }
650
Steven Rostedta57419b2010-11-02 15:13:54 -0400651 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400652 if (!$override || defined(${$overrides}{$lvalue})) {
653 my $extra = "";
654 if ($override) {
655 $extra = "In the same override section!\n";
656 }
657 die "$name: $.: Option $lvalue defined more than once!\n$extra";
658 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500659 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400660 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500661 if ($rvalue =~ /^\s*$/) {
662 delete $opt{$lvalue};
663 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500664 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500665 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400666}
667
Steven Rostedt77d942c2011-05-20 13:36:58 -0400668sub set_variable {
669 my ($lvalue, $rvalue) = @_;
670
671 if ($rvalue =~ /^\s*$/) {
672 delete $variable{$lvalue};
673 } else {
674 $rvalue = process_variables($rvalue);
675 $variable{$lvalue} = $rvalue;
676 }
677}
678
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400679sub process_compare {
680 my ($lval, $cmp, $rval) = @_;
681
682 # remove whitespace
683
684 $lval =~ s/^\s*//;
685 $lval =~ s/\s*$//;
686
687 $rval =~ s/^\s*//;
688 $rval =~ s/\s*$//;
689
690 if ($cmp eq "==") {
691 return $lval eq $rval;
692 } elsif ($cmp eq "!=") {
693 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400694 } elsif ($cmp eq "=~") {
695 return $lval =~ m/$rval/;
696 } elsif ($cmp eq "!~") {
697 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400698 }
699
700 my $statement = "$lval $cmp $rval";
701 my $ret = eval $statement;
702
703 # $@ stores error of eval
704 if ($@) {
705 return -1;
706 }
707
708 return $ret;
709}
710
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400711sub value_defined {
712 my ($val) = @_;
713
714 return defined($variable{$2}) ||
715 defined($opt{$2});
716}
717
Steven Rostedt8d735212011-10-17 11:36:44 -0400718my $d = 0;
719sub process_expression {
720 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400721
Steven Rostedt8d735212011-10-17 11:36:44 -0400722 my $c = $d++;
723
724 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
725 my $express = $1;
726
727 if (process_expression($name, $express)) {
728 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
729 } else {
730 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
731 }
732 }
733
734 $d--;
735 my $OR = "\\|\\|";
736 my $AND = "\\&\\&";
737
738 while ($val =~ s/^(.*?)($OR|$AND)//) {
739 my $express = $1;
740 my $op = $2;
741
742 if (process_expression($name, $express)) {
743 if ($op eq "||") {
744 return 1;
745 }
746 } else {
747 if ($op eq "&&") {
748 return 0;
749 }
750 }
751 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400752
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400753 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400754 my $ret = process_compare($1, $2, $3);
755 if ($ret < 0) {
756 die "$name: $.: Unable to process comparison\n";
757 }
758 return $ret;
759 }
760
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400761 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
762 if (defined $1) {
763 return !value_defined($2);
764 } else {
765 return value_defined($2);
766 }
767 }
768
Steven Rostedt45d73a52011-09-30 19:44:53 -0400769 if ($val =~ /^\s*0\s*$/) {
770 return 0;
771 } elsif ($val =~ /^\s*\d+\s*$/) {
772 return 1;
773 }
774
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400775 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400776}
777
778sub process_if {
779 my ($name, $value) = @_;
780
781 # Convert variables and replace undefined ones with 0
782 my $val = process_variables($value, 1);
783 my $ret = process_expression $name, $val;
784
785 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400786}
787
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400788sub __read_config {
789 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400790
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400791 my $in;
792 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400793
Steven Rostedta57419b2010-11-02 15:13:54 -0400794 my $name = $config;
795 $name =~ s,.*/(.*),$1,;
796
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400797 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400798 my $default = 1;
799 my $repeat = 1;
800 my $num_tests_set = 0;
801 my $skip = 0;
802 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400803 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400804 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400805 my $if = 0;
806 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400807 my $override = 0;
808
809 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400810
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400811 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400812
813 # ignore blank lines and comments
814 next if (/^\s*$/ || /\s*\#/);
815
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400816 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400817
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400818 my $type = $1;
819 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400820 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400821
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400822 my $old_test_num;
823 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400824 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400825
826 if ($type eq "TEST_START") {
827
828 if ($num_tests_set) {
829 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
830 }
831
832 $old_test_num = $test_num;
833 $old_repeat = $repeat;
834
835 $test_num += $repeat;
836 $default = 0;
837 $repeat = 1;
838 } else {
839 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400840 }
841
Steven Rostedta9f84422011-10-17 11:06:29 -0400842 # If SKIP is anywhere in the line, the command will be skipped
843 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400844 $skip = 1;
845 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400846 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400847 $skip = 0;
848 }
849
Steven Rostedta9f84422011-10-17 11:06:29 -0400850 if ($rest =~ s/\sELSE\b//) {
851 if (!$if) {
852 die "$name: $.: ELSE found with out matching IF section\n$_";
853 }
854 $if = 0;
855
856 if ($if_set) {
857 $skip = 1;
858 } else {
859 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400860 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400861 }
862
Steven Rostedta9f84422011-10-17 11:06:29 -0400863 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400864 if (process_if($name, $1)) {
865 $if_set = 1;
866 } else {
867 $skip = 1;
868 }
869 $if = 1;
870 } else {
871 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400872 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400873 }
874
Steven Rostedta9f84422011-10-17 11:06:29 -0400875 if (!$skip) {
876 if ($type eq "TEST_START") {
877 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
878 $repeat = $1;
879 $repeat_tests{"$test_num"} = $repeat;
880 }
881 } elsif ($rest =~ s/\sOVERRIDE\b//) {
882 # DEFAULT only
883 $override = 1;
884 # Clear previous overrides
885 %overrides = ();
886 }
887 }
888
889 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400890 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400891 }
892
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400893 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400894 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400895 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400896 }
897
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400898 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400899 if (!$if) {
900 die "$name: $.: ELSE found with out matching IF section\n$_";
901 }
902 $rest = $1;
903 if ($if_set) {
904 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400905 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400906 } else {
907 $skip = 0;
908
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400909 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400910 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400911 if (process_if($name, $1)) {
912 $if_set = 1;
913 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400914 $skip = 1;
915 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400916 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400917 } else {
918 $if = 0;
919 }
920 }
921
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400922 if ($rest !~ /^\s*$/) {
923 die "$name: $.: Gargbage found after DEFAULTS\n$_";
924 }
925
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400926 } elsif (/^\s*INCLUDE\s+(\S+)/) {
927
928 next if ($skip);
929
930 if (!$default) {
931 die "$name: $.: INCLUDE can only be done in default sections\n$_";
932 }
933
934 my $file = process_variables($1);
935
936 if ($file !~ m,^/,) {
937 # check the path of the config file first
938 if ($config =~ m,(.*)/,) {
939 if (-f "$1/$file") {
940 $file = "$1/$file";
941 }
942 }
943 }
944
945 if ( ! -r $file ) {
946 die "$name: $.: Can't read file $file\n$_";
947 }
948
949 if (__read_config($file, \$test_num)) {
950 $test_case = 1;
951 }
952
Steven Rostedta57419b2010-11-02 15:13:54 -0400953 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
954
955 next if ($skip);
956
Steven Rostedt2545eb62010-11-02 15:01:32 -0400957 my $lvalue = $1;
958 my $rvalue = $2;
959
Steven Rostedta57419b2010-11-02 15:13:54 -0400960 if (!$default &&
961 ($lvalue eq "NUM_TESTS" ||
962 $lvalue eq "LOG_FILE" ||
963 $lvalue eq "CLEAR_LOG")) {
964 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400965 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400966
967 if ($lvalue eq "NUM_TESTS") {
968 if ($test_num) {
969 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
970 }
971 if (!$default) {
972 die "$name: $.: NUM_TESTS must be set in default section\n";
973 }
974 $num_tests_set = 1;
975 }
976
977 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400978 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400979 } else {
980 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400981 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400982
983 if ($repeat > 1) {
984 $repeats{$val} = $repeat;
985 }
986 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400987 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
988 next if ($skip);
989
990 my $lvalue = $1;
991 my $rvalue = $2;
992
993 # process config variables.
994 # Config variables are only active while reading the
995 # config and can be defined anywhere. They also ignore
996 # TEST_START and DEFAULTS, but are skipped if they are in
997 # on of these sections that have SKIP defined.
998 # The save variable can be
999 # defined multiple times and the new one simply overrides
1000 # the prevous one.
1001 set_variable($lvalue, $rvalue);
1002
Steven Rostedta57419b2010-11-02 15:13:54 -04001003 } else {
1004 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001005 }
1006 }
1007
Steven Rostedta57419b2010-11-02 15:13:54 -04001008 if ($test_num) {
1009 $test_num += $repeat - 1;
1010 $opt{"NUM_TESTS"} = $test_num;
1011 }
1012
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001013 close($in);
1014
1015 $$current_test_num = $test_num;
1016
1017 return $test_case;
1018}
1019
Steven Rostedtc4261d02011-11-23 13:41:18 -05001020sub get_test_case {
1021 print "What test case would you like to run?\n";
1022 print " (build, install or boot)\n";
1023 print " Other tests are available but require editing the config file\n";
1024 my $ans = <STDIN>;
1025 chomp $ans;
1026 $default{"TEST_TYPE"} = $ans;
1027}
1028
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001029sub read_config {
1030 my ($config) = @_;
1031
1032 my $test_case;
1033 my $test_num = 0;
1034
1035 $test_case = __read_config $config, \$test_num;
1036
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001037 # make sure we have all mandatory configs
1038 get_ktest_configs;
1039
Steven Rostedt0df213c2011-06-14 20:51:37 -04001040 # was a test specified?
1041 if (!$test_case) {
1042 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001043 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001044 }
1045
Steven Rostedta75fece2010-11-02 14:58:27 -04001046 # set any defaults
1047
1048 foreach my $default (keys %default) {
1049 if (!defined($opt{$default})) {
1050 $opt{$default} = $default{$default};
1051 }
1052 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001053
1054 if ($opt{"IGNORE_UNUSED"} == 1) {
1055 return;
1056 }
1057
1058 my %not_used;
1059
1060 # check if there are any stragglers (typos?)
1061 foreach my $option (keys %opt) {
1062 my $op = $option;
1063 # remove per test labels.
1064 $op =~ s/\[.*\]//;
1065 if (!exists($option_map{$op}) &&
1066 !exists($default{$op}) &&
1067 !exists($used_options{$op})) {
1068 $not_used{$op} = 1;
1069 }
1070 }
1071
1072 if (%not_used) {
1073 my $s = "s are";
1074 $s = " is" if (keys %not_used == 1);
1075 print "The following option$s not used; could be a typo:\n";
1076 foreach my $option (keys %not_used) {
1077 print "$option\n";
1078 }
1079 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1080 if (!read_yn "Do you want to continue?") {
1081 exit -1;
1082 }
1083 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001084}
1085
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001086sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001087 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001088
1089 # Add space to evaluate the character before $
1090 $option = " $option";
1091 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301092 my $repeated = 0;
1093 my $parent = 0;
1094
1095 foreach my $test (keys %repeat_tests) {
1096 if ($i >= $test &&
1097 $i < $test + $repeat_tests{$test}) {
1098
1099 $repeated = 1;
1100 $parent = $test;
1101 last;
1102 }
1103 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001104
1105 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1106 my $start = $1;
1107 my $var = $2;
1108 my $end = $3;
1109
1110 # Append beginning of line
1111 $retval = "$retval$start";
1112
1113 # If the iteration option OPT[$i] exists, then use that.
1114 # otherwise see if the default OPT (without [$i]) exists.
1115
1116 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301117 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001118
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001119 # If a variable contains itself, use the default var
1120 if (($var eq $name) && defined($opt{$var})) {
1121 $o = $opt{$var};
1122 $retval = "$retval$o";
1123 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001124 $o = $opt{$o};
1125 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301126 } elsif ($repeated && defined($opt{$parento})) {
1127 $o = $opt{$parento};
1128 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001129 } elsif (defined($opt{$var})) {
1130 $o = $opt{$var};
1131 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001132 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1133 # special option KERNEL_VERSION uses kernel version
1134 get_version();
1135 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001136 } else {
1137 $retval = "$retval\$\{$var\}";
1138 }
1139
1140 $option = $end;
1141 }
1142
1143 $retval = "$retval$option";
1144
1145 $retval =~ s/^ //;
1146
1147 return $retval;
1148}
1149
1150sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001151 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001152
1153 my $prev = "";
1154
1155 # Since an option can evaluate to another option,
1156 # keep iterating until we do not evaluate any more
1157 # options.
1158 my $r = 0;
1159 while ($prev ne $option) {
1160 # Check for recursive evaluations.
1161 # 100 deep should be more than enough.
1162 if ($r++ > 100) {
1163 die "Over 100 evaluations accurred with $option\n" .
1164 "Check for recursive variables\n";
1165 }
1166 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001167 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001168 }
1169
1170 return $option;
1171}
1172
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001173sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001174 if (defined($opt{"LOG_FILE"})) {
1175 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1176 print OUT @_;
1177 close(OUT);
1178 }
1179}
1180
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001181sub logit {
1182 if (defined($opt{"LOG_FILE"})) {
1183 _logit @_;
1184 } else {
1185 print @_;
1186 }
1187}
1188
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001189sub doprint {
1190 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001191 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001192}
1193
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001194sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001195sub start_monitor;
1196sub end_monitor;
1197sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001198
1199sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001200 my ($time) = @_;
1201
Steven Rostedta4968722012-12-11 14:59:05 -05001202 # Make sure everything has been written to disk
1203 run_ssh("sync");
1204
Steven Rostedt2b803362011-09-30 18:00:23 -04001205 if (defined($time)) {
1206 start_monitor;
1207 # flush out current monitor
1208 # May contain the reboot success line
1209 wait_for_monitor 1;
1210 }
1211
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001212 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001213 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001214 if (defined($powercycle_after_reboot)) {
1215 sleep $powercycle_after_reboot;
1216 run_command "$power_cycle";
1217 }
1218 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001219 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001220 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001221 }
Andrew Jones2728be42011-08-12 15:32:05 +02001222
1223 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001224
1225 # We only want to get to the new kernel, don't fail
1226 # if we stumble over a call trace.
1227 my $save_ignore_errors = $ignore_errors;
1228 $ignore_errors = 1;
1229
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001230 # Look for the good kernel to boot
1231 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001232 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001233 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001234 run_command "$power_cycle";
1235 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001236
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001237 $ignore_errors = $save_ignore_errors;
1238
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001239 # Still need to wait for the reboot to finish
1240 wait_for_monitor($time, $reboot_success_line);
1241
Andrew Jones2728be42011-08-12 15:32:05 +02001242 end_monitor;
1243 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001244}
1245
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001246sub reboot_to_good {
1247 my ($time) = @_;
1248
1249 if (defined($switch_to_good)) {
1250 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001251 }
1252
1253 reboot $time;
1254}
1255
Steven Rostedt576f6272010-11-02 14:58:38 -04001256sub do_not_reboot {
1257 my $i = $iteration;
1258
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001259 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001260 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1261 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1262}
1263
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001264sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001265 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001266
Steven Rostedt576f6272010-11-02 14:58:38 -04001267 my $i = $iteration;
1268
1269 if ($reboot_on_error && !do_not_reboot) {
1270
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001271 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001272 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001273
Steven Rostedta75fece2010-11-02 14:58:27 -04001274 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001275 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001276 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001277 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001278
Steven Rostedtf80802c2011-03-07 13:18:47 -05001279 if (defined($opt{"LOG_FILE"})) {
1280 print " See $opt{LOG_FILE} for more info.\n";
1281 }
1282
Steven Rostedt576f6272010-11-02 14:58:38 -04001283 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001284}
1285
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001286sub open_console {
1287 my ($fp) = @_;
1288
1289 my $flags;
1290
Steven Rostedta75fece2010-11-02 14:58:27 -04001291 my $pid = open($fp, "$console|") or
1292 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001293
1294 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001295 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001296 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001297 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001298
1299 return $pid;
1300}
1301
1302sub close_console {
1303 my ($fp, $pid) = @_;
1304
1305 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001306 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001307
1308 print "closing!\n";
1309 close($fp);
1310}
1311
1312sub start_monitor {
1313 if ($monitor_cnt++) {
1314 return;
1315 }
1316 $monitor_fp = \*MONFD;
1317 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001318
1319 return;
1320
1321 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001322}
1323
1324sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001325 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001326 if (--$monitor_cnt) {
1327 return;
1328 }
1329 close_console($monitor_fp, $monitor_pid);
1330}
1331
1332sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001333 my ($time, $stop) = @_;
1334 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001335 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001336 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001337 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001338 my $skip_call_trace = 0;
1339 my $bug = 0;
1340 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001341 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001342
Steven Rostedta75fece2010-11-02 14:58:27 -04001343 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001344
1345 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001346 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001347 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001348 last if (!defined($line));
1349 print "$line";
1350 $full_line .= $line;
1351
1352 if (defined($stop) && $full_line =~ /$stop/) {
1353 doprint "wait for monitor detected $stop\n";
1354 $booted = 1;
1355 }
1356
Steven Rostedt8a80c722012-07-19 16:08:33 -04001357 if ($full_line =~ /\[ backtrace testing \]/) {
1358 $skip_call_trace = 1;
1359 }
1360
1361 if ($full_line =~ /call trace:/i) {
1362 if (!$bug && !$skip_call_trace) {
1363 if ($ignore_errors) {
1364 $bug_ignored = 1;
1365 } else {
1366 $bug = 1;
1367 }
1368 }
1369 }
1370
1371 if ($full_line =~ /\[ end of backtrace testing \]/) {
1372 $skip_call_trace = 0;
1373 }
1374
1375 if ($full_line =~ /Kernel panic -/) {
1376 $bug = 1;
1377 }
1378
Steven Rostedt2b803362011-09-30 18:00:23 -04001379 if ($line =~ /\n/) {
1380 $full_line = "";
1381 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001382 $now = time;
1383 if ($now - $start_time >= $max_monitor_wait) {
1384 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1385 return 1;
1386 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001387 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001388 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001389 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001390}
1391
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301392sub save_logs {
1393 my ($result, $basedir) = @_;
1394 my @t = localtime;
1395 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1396 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1397
1398 my $type = $build_type;
1399 if ($type =~ /useconfig/) {
1400 $type = "useconfig";
1401 }
1402
1403 my $dir = "$machine-$test_type-$type-$result-$date";
1404
1405 $dir = "$basedir/$dir";
1406
1407 if (!-d $dir) {
1408 mkpath($dir) or
1409 die "can't create $dir";
1410 }
1411
1412 my %files = (
1413 "config" => $output_config,
1414 "buildlog" => $buildlog,
1415 "dmesg" => $dmesg,
1416 "testlog" => $testlog,
1417 );
1418
1419 while (my ($name, $source) = each(%files)) {
1420 if (-f "$source") {
1421 cp "$source", "$dir/$name" or
1422 die "failed to copy $source";
1423 }
1424 }
1425
1426 doprint "*** Saved info to $dir ***\n";
1427}
1428
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001429sub fail {
1430
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001431 if (defined($post_test)) {
1432 run_command $post_test;
1433 }
1434
Steven Rostedta75fece2010-11-02 14:58:27 -04001435 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001436 dodie @_;
1437 }
1438
Steven Rostedta75fece2010-11-02 14:58:27 -04001439 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001440
Steven Rostedt576f6272010-11-02 14:58:38 -04001441 my $i = $iteration;
1442
Steven Rostedta75fece2010-11-02 14:58:27 -04001443 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001444 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001445 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001446 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001447 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001448
Steven Rostedt9064af52011-06-13 10:38:48 -04001449 my $name = "";
1450
1451 if (defined($test_name)) {
1452 $name = " ($test_name)";
1453 }
1454
Steven Rostedt576f6272010-11-02 14:58:38 -04001455 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1456 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001457 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001458 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1459 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001460
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301461 if (defined($store_failures)) {
1462 save_logs "fail", $store_failures;
1463 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001464
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001465 return 1;
1466}
1467
Steven Rostedt2545eb62010-11-02 15:01:32 -04001468sub run_command {
1469 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001470 my $dolog = 0;
1471 my $dord = 0;
1472 my $pid;
1473
Steven Rostedte48c5292010-11-02 14:35:37 -04001474 $command =~ s/\$SSH_USER/$ssh_user/g;
1475 $command =~ s/\$MACHINE/$machine/g;
1476
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001477 doprint("$command ... ");
1478
1479 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001480 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001481
1482 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001483 open(LOG, ">>$opt{LOG_FILE}") or
1484 dodie "failed to write to log";
1485 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001486 }
1487
1488 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001489 open (RD, ">$redirect") or
1490 dodie "failed to write to redirect $redirect";
1491 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001492 }
1493
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001494 while (<CMD>) {
1495 print LOG if ($dolog);
1496 print RD if ($dord);
1497 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001498
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001499 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001500 my $failed = $?;
1501
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001502 close(CMD);
1503 close(LOG) if ($dolog);
1504 close(RD) if ($dord);
1505
Steven Rostedt2545eb62010-11-02 15:01:32 -04001506 if ($failed) {
1507 doprint "FAILED!\n";
1508 } else {
1509 doprint "SUCCESS\n";
1510 }
1511
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001512 return !$failed;
1513}
1514
Steven Rostedte48c5292010-11-02 14:35:37 -04001515sub run_ssh {
1516 my ($cmd) = @_;
1517 my $cp_exec = $ssh_exec;
1518
1519 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1520 return run_command "$cp_exec";
1521}
1522
1523sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001524 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001525
1526 $cp_scp =~ s/\$SRC_FILE/$src/g;
1527 $cp_scp =~ s/\$DST_FILE/$dst/g;
1528
1529 return run_command "$cp_scp";
1530}
1531
Steven Rostedt02ad2612012-03-21 08:21:24 -04001532sub run_scp_install {
1533 my ($src, $dst) = @_;
1534
1535 my $cp_scp = $scp_to_target_install;
1536
1537 return run_scp($src, $dst, $cp_scp);
1538}
1539
1540sub run_scp_mod {
1541 my ($src, $dst) = @_;
1542
1543 my $cp_scp = $scp_to_target;
1544
1545 return run_scp($src, $dst, $cp_scp);
1546}
1547
Steven Rostedta15ba912012-11-13 14:30:37 -05001548sub get_grub2_index {
1549
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001550 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001551 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1552 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001553
1554 doprint "Find grub2 menu ... ";
1555 $grub_number = -1;
1556
1557 my $ssh_grub = $ssh_exec;
1558 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1559
1560 open(IN, "$ssh_grub |")
1561 or die "unable to get $grub_file";
1562
1563 my $found = 0;
1564
1565 while (<IN>) {
1566 if (/^menuentry.*$grub_menu/) {
1567 $grub_number++;
1568 $found = 1;
1569 last;
1570 } elsif (/^menuentry\s/) {
1571 $grub_number++;
1572 }
1573 }
1574 close(IN);
1575
1576 die "Could not find '$grub_menu' in $grub_file on $machine"
1577 if (!$found);
1578 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001579 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001580 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001581}
1582
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001583sub get_grub_index {
1584
Steven Rostedta15ba912012-11-13 14:30:37 -05001585 if ($reboot_type eq "grub2") {
1586 get_grub2_index;
1587 return;
1588 }
1589
Steven Rostedta75fece2010-11-02 14:58:27 -04001590 if ($reboot_type ne "grub") {
1591 return;
1592 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001593 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001594 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1595 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001596
1597 doprint "Find grub menu ... ";
1598 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001599
1600 my $ssh_grub = $ssh_exec;
1601 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1602
1603 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001604 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001605
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001606 my $found = 0;
1607
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001608 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001609 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001610 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001611 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001612 last;
1613 } elsif (/^\s*title\s/) {
1614 $grub_number++;
1615 }
1616 }
1617 close(IN);
1618
Steven Rostedta75fece2010-11-02 14:58:27 -04001619 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001620 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001621 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001622 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001623 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001624}
1625
Steven Rostedt2545eb62010-11-02 15:01:32 -04001626sub wait_for_input
1627{
1628 my ($fp, $time) = @_;
1629 my $rin;
1630 my $ready;
1631 my $line;
1632 my $ch;
1633
1634 if (!defined($time)) {
1635 $time = $timeout;
1636 }
1637
1638 $rin = '';
1639 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001640 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001641
1642 $line = "";
1643
1644 # try to read one char at a time
1645 while (sysread $fp, $ch, 1) {
1646 $line .= $ch;
1647 last if ($ch eq "\n");
1648 }
1649
1650 if (!length($line)) {
1651 return undef;
1652 }
1653
1654 return $line;
1655}
1656
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001657sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001658 if (defined($switch_to_test)) {
1659 run_command $switch_to_test;
1660 }
1661
Steven Rostedta75fece2010-11-02 14:58:27 -04001662 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001663 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001664 } elsif ($reboot_type eq "grub2") {
1665 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001666 } elsif ($reboot_type eq "syslinux") {
1667 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001668 } elsif (defined $reboot_script) {
1669 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001670 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001671 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001672}
1673
Steven Rostedta57419b2010-11-02 15:13:54 -04001674sub get_sha1 {
1675 my ($commit) = @_;
1676
1677 doprint "git rev-list --max-count=1 $commit ... ";
1678 my $sha1 = `git rev-list --max-count=1 $commit`;
1679 my $ret = $?;
1680
1681 logit $sha1;
1682
1683 if ($ret) {
1684 doprint "FAILED\n";
1685 dodie "Failed to get git $commit";
1686 }
1687
1688 print "SUCCESS\n";
1689
1690 chomp $sha1;
1691
1692 return $sha1;
1693}
1694
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001695sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001696 my $booted = 0;
1697 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001698 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001699 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001700 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001701
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001702 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001703
1704 my $line;
1705 my $full_line = "";
1706
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001707 open(DMESG, "> $dmesg") or
1708 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001709
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001710 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001711
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001712 my $success_start;
1713 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001714 my $monitor_start = time;
1715 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001716 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001717
Steven Rostedt2d01b262011-03-08 09:47:54 -05001718 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001719
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001720 if ($bug && defined($stop_after_failure) &&
1721 $stop_after_failure >= 0) {
1722 my $time = $stop_after_failure - (time - $failure_start);
1723 $line = wait_for_input($monitor_fp, $time);
1724 if (!defined($line)) {
1725 doprint "bug timed out after $booted_timeout seconds\n";
1726 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1727 last;
1728 }
1729 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001730 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001731 if (!defined($line)) {
1732 my $s = $booted_timeout == 1 ? "" : "s";
1733 doprint "Successful boot found: break after $booted_timeout second$s\n";
1734 last;
1735 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001736 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001737 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001738 if (!defined($line)) {
1739 my $s = $timeout == 1 ? "" : "s";
1740 doprint "Timed out after $timeout second$s\n";
1741 last;
1742 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001743 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001744
Steven Rostedt2545eb62010-11-02 15:01:32 -04001745 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001746 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001747
1748 # we are not guaranteed to get a full line
1749 $full_line .= $line;
1750
Steven Rostedta75fece2010-11-02 14:58:27 -04001751 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001752 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001753 $success_start = time;
1754 }
1755
1756 if ($booted && defined($stop_after_success) &&
1757 $stop_after_success >= 0) {
1758 my $now = time;
1759 if ($now - $success_start >= $stop_after_success) {
1760 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1761 last;
1762 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001763 }
1764
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001765 if ($full_line =~ /\[ backtrace testing \]/) {
1766 $skip_call_trace = 1;
1767 }
1768
Steven Rostedt2545eb62010-11-02 15:01:32 -04001769 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001770 if (!$bug && !$skip_call_trace) {
1771 if ($ignore_errors) {
1772 $bug_ignored = 1;
1773 } else {
1774 $bug = 1;
1775 $failure_start = time;
1776 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001777 }
1778 }
1779
1780 if ($bug && defined($stop_after_failure) &&
1781 $stop_after_failure >= 0) {
1782 my $now = time;
1783 if ($now - $failure_start >= $stop_after_failure) {
1784 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1785 last;
1786 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001787 }
1788
1789 if ($full_line =~ /\[ end of backtrace testing \]/) {
1790 $skip_call_trace = 0;
1791 }
1792
1793 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001794 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001795 $bug = 1;
1796 }
1797
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001798 # Detect triple faults by testing the banner
1799 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1800 if ($1 eq $version) {
1801 $version_found = 1;
1802 } elsif ($version_found && $detect_triplefault) {
1803 # We already booted into the kernel we are testing,
1804 # but now we booted into another kernel?
1805 # Consider this a triple fault.
1806 doprint "Aleady booted in Linux kernel $version, but now\n";
1807 doprint "we booted into Linux kernel $1.\n";
1808 doprint "Assuming that this is a triple fault.\n";
1809 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1810 last;
1811 }
1812 }
1813
Steven Rostedt2545eb62010-11-02 15:01:32 -04001814 if ($line =~ /\n/) {
1815 $full_line = "";
1816 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001817
1818 if ($stop_test_after > 0 && !$booted && !$bug) {
1819 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001820 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001821 $done = 1;
1822 }
1823 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001824 }
1825
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001826 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001827
Steven Rostedt2545eb62010-11-02 15:01:32 -04001828 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001829 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001830 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001831 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001832
Steven Rostedta75fece2010-11-02 14:58:27 -04001833 if (!$booted) {
1834 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001835 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001836 }
1837
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001838 if ($bug_ignored) {
1839 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1840 }
1841
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001842 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001843}
1844
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001845sub eval_kernel_version {
1846 my ($option) = @_;
1847
1848 $option =~ s/\$KERNEL_VERSION/$version/g;
1849
1850 return $option;
1851}
1852
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001853sub do_post_install {
1854
1855 return if (!defined($post_install));
1856
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001857 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001858 run_command "$cp_post_install" or
1859 dodie "Failed to run post install";
1860}
1861
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001862# Sometimes the reboot fails, and will hang. We try to ssh to the box
1863# and if we fail, we force another reboot, that should powercycle it.
1864sub test_booted {
1865 if (!run_ssh "echo testing connection") {
1866 reboot $sleep_time;
1867 }
1868}
1869
Steven Rostedt2545eb62010-11-02 15:01:32 -04001870sub install {
1871
Steven Rostedte0a87422011-09-30 17:50:48 -04001872 return if ($no_install);
1873
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001874 if (defined($pre_install)) {
1875 my $cp_pre_install = eval_kernel_version $pre_install;
1876 run_command "$cp_pre_install" or
1877 dodie "Failed to run pre install";
1878 }
1879
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001880 my $cp_target = eval_kernel_version $target_image;
1881
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001882 test_booted;
1883
Steven Rostedt02ad2612012-03-21 08:21:24 -04001884 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001885 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001886
1887 my $install_mods = 0;
1888
1889 # should we process modules?
1890 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001891 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001892 while (<IN>) {
1893 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001894 if (defined($1)) {
1895 $install_mods = 1;
1896 last;
1897 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001898 }
1899 }
1900 close(IN);
1901
1902 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001903 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001904 doprint "No modules needed\n";
1905 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001906 }
1907
Steven Rostedt627977d2012-03-21 08:16:15 -04001908 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001909 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001910
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001911 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001912 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001913
Steven Rostedte48c5292010-11-02 14:35:37 -04001914 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001915 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001916
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001917 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001918 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001919 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001920
Steven Rostedt02ad2612012-03-21 08:21:24 -04001921 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001922 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001923
Steven Rostedta75fece2010-11-02 14:58:27 -04001924 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001925
Steven Rostedte7b13442011-06-14 20:44:36 -04001926 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001927 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001928
Steven Rostedte48c5292010-11-02 14:35:37 -04001929 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001930
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001931 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001932}
1933
Steven Rostedtddf607e2011-06-14 20:49:13 -04001934sub get_version {
1935 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001936 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001937 doprint "$make kernelrelease ... ";
1938 $version = `$make kernelrelease | tail -1`;
1939 chomp($version);
1940 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001941 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001942}
1943
1944sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001945 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001946
1947 # Install bisects, don't need console
1948 if (defined $console) {
1949 start_monitor;
1950 wait_for_monitor 5;
1951 end_monitor;
1952 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001953
Steven Rostedtddf607e2011-06-14 20:49:13 -04001954 get_grub_index;
1955 get_version;
1956 install;
1957
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001958 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001959 return monitor;
1960}
1961
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001962my $check_build_re = ".*:.*(warning|error|Error):.*";
1963my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1964
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05001965sub process_warning_line {
1966 my ($line) = @_;
1967
1968 chomp $line;
1969
1970 # for distcc heterogeneous systems, some compilers
1971 # do things differently causing warning lines
1972 # to be slightly different. This makes an attempt
1973 # to fixe those issues.
1974
1975 # chop off the index into the line
1976 # using distcc, some compilers give different indexes
1977 # depending on white space
1978 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
1979
1980 # Some compilers use UTF-8 extended for quotes and some don't.
1981 $line =~ s/$utf8_quote/'/g;
1982
1983 return $line;
1984}
1985
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001986# Read buildlog and check against warnings file for any
1987# new warnings.
1988#
1989# Returns 1 if OK
1990# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001991sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001992 return 1 if (!defined $warnings_file);
1993
1994 my %warnings_list;
1995
1996 # Failed builds should not reboot the target
1997 my $save_no_reboot = $no_reboot;
1998 $no_reboot = 1;
1999
2000 if (-f $warnings_file) {
2001 open(IN, $warnings_file) or
2002 dodie "Error opening $warnings_file";
2003
2004 while (<IN>) {
2005 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002006 my $warning = process_warning_line $_;
2007
2008 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002009 }
2010 }
2011 close(IN);
2012 }
2013
2014 # If warnings file didn't exist, and WARNINGS_FILE exist,
2015 # then we fail on any warning!
2016
2017 open(IN, $buildlog) or dodie "Can't open $buildlog";
2018 while (<IN>) {
2019 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002020 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002021
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002022 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002023 fail "New warning found (not in $warnings_file)\n$_\n";
2024 $no_reboot = $save_no_reboot;
2025 return 0;
2026 }
2027 }
2028 }
2029 $no_reboot = $save_no_reboot;
2030 close(IN);
2031}
2032
2033sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002034 my ($patch) = @_;
2035
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002036 my @files = `git show $patch | diffstat -l`;
2037
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002038 foreach my $file (@files) {
2039 chomp $file;
2040 }
2041
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002042 open(IN, "git show $patch |") or
2043 dodie "failed to show $patch";
2044 while (<IN>) {
2045 if (m,^--- a/(.*),) {
2046 chomp $1;
2047 $files[$#files] = $1;
2048 }
2049 }
2050 close(IN);
2051
2052 open(IN, $buildlog) or dodie "Can't open $buildlog";
2053 while (<IN>) {
2054 if (/^\s*(.*?):.*(warning|error)/) {
2055 my $err = $1;
2056 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002057 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002058 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002059 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002060 }
2061 }
2062 }
2063 }
2064 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002065
2066 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002067}
2068
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002069sub apply_min_config {
2070 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002071
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002072 # Read the config file and remove anything that
2073 # is in the force_config hash (from minconfig and others)
2074 # then add the force config back.
2075
2076 doprint "Applying minimum configurations into $output_config.new\n";
2077
2078 open (OUT, ">$outconfig") or
2079 dodie "Can't create $outconfig";
2080
2081 if (-f $output_config) {
2082 open (IN, $output_config) or
2083 dodie "Failed to open $output_config";
2084 while (<IN>) {
2085 if (/^(# )?(CONFIG_[^\s=]*)/) {
2086 next if (defined($force_config{$2}));
2087 }
2088 print OUT;
2089 }
2090 close IN;
2091 }
2092 foreach my $config (keys %force_config) {
2093 print OUT "$force_config{$config}\n";
2094 }
2095 close OUT;
2096
2097 run_command "mv $outconfig $output_config";
2098}
2099
2100sub make_oldconfig {
2101
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002102 my @force_list = keys %force_config;
2103
2104 if ($#force_list >= 0) {
2105 apply_min_config;
2106 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002107
Adam Leefb16d892012-09-01 01:05:17 +08002108 if (!run_command "$make olddefconfig") {
2109 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002110 # try oldnoconfig
2111 doprint "olddefconfig failed, trying make oldnoconfig\n";
2112 if (!run_command "$make oldnoconfig") {
2113 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2114 # try a yes '' | oldconfig
2115 run_command "yes '' | $make oldconfig" or
2116 dodie "failed make config oldconfig";
2117 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002118 }
2119}
2120
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002121# read a config file and use this to force new configs.
2122sub load_force_config {
2123 my ($config) = @_;
2124
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002125 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002126 open(IN, $config) or
2127 dodie "failed to read $config";
2128 while (<IN>) {
2129 chomp;
2130 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2131 $force_config{$1} = $_;
2132 } elsif (/^# (CONFIG_\S*) is not set/) {
2133 $force_config{$1} = $_;
2134 }
2135 }
2136 close IN;
2137}
2138
Steven Rostedt2545eb62010-11-02 15:01:32 -04002139sub build {
2140 my ($type) = @_;
2141
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002142 unlink $buildlog;
2143
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002144 # Failed builds should not reboot the target
2145 my $save_no_reboot = $no_reboot;
2146 $no_reboot = 1;
2147
Steven Rostedt683a3e62012-05-18 13:34:35 -04002148 # Calculate a new version from here.
2149 $have_version = 0;
2150
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002151 if (defined($pre_build)) {
2152 my $ret = run_command $pre_build;
2153 if (!$ret && defined($pre_build_die) &&
2154 $pre_build_die) {
2155 dodie "failed to pre_build\n";
2156 }
2157 }
2158
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002159 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002160 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002161 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002162
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002163 $type = "oldconfig";
2164 }
2165
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002166 # old config can ask questions
2167 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002168 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002169
2170 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002171 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002172
Andrew Jones13488232011-08-12 15:32:04 +02002173 if (!$noclean) {
2174 run_command "mv $output_config $outputdir/config_temp" or
2175 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002176
Andrew Jones13488232011-08-12 15:32:04 +02002177 run_command "$make mrproper" or dodie "make mrproper";
2178
2179 run_command "mv $outputdir/config_temp $output_config" or
2180 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002181 }
2182
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002183 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002184 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002185 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002186 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002187 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002188
2189 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002190 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2191 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002192 close(OUT);
2193
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002194 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002195 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002196 }
2197
Adam Leefb16d892012-09-01 01:05:17 +08002198 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002199 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002200 dodie "failed make config";
2201 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002202 # Run old config regardless, to enforce min configurations
2203 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002204
Steven Rostedta75fece2010-11-02 14:58:27 -04002205 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002206 my $build_ret = run_command "$make $build_options";
2207 undef $redirect;
2208
2209 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002210 # Because a post build may change the kernel version
2211 # do it now.
2212 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002213 my $ret = run_command $post_build;
2214 if (!$ret && defined($post_build_die) &&
2215 $post_build_die) {
2216 dodie "failed to post_build\n";
2217 }
2218 }
2219
2220 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002221 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002222 if ($in_bisect) {
2223 $no_reboot = $save_no_reboot;
2224 return 0;
2225 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002226 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002227 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002228
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002229 $no_reboot = $save_no_reboot;
2230
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002231 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002232}
2233
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002234sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002235 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002236 if (defined($poweroff_after_halt)) {
2237 sleep $poweroff_after_halt;
2238 run_command "$power_off";
2239 }
2240 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002241 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002242 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002243 }
2244}
2245
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002246sub success {
2247 my ($i) = @_;
2248
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002249 if (defined($post_test)) {
2250 run_command $post_test;
2251 }
2252
Steven Rostedte48c5292010-11-02 14:35:37 -04002253 $successes++;
2254
Steven Rostedt9064af52011-06-13 10:38:48 -04002255 my $name = "";
2256
2257 if (defined($test_name)) {
2258 $name = " ($test_name)";
2259 }
2260
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002261 doprint "\n\n*******************************************\n";
2262 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002263 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002264 doprint "*******************************************\n";
2265 doprint "*******************************************\n";
2266
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302267 if (defined($store_successes)) {
2268 save_logs "success", $store_successes;
2269 }
2270
Steven Rostedt576f6272010-11-02 14:58:38 -04002271 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002272 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002273 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002274 }
2275}
2276
Steven Rostedtc960bb92011-03-08 09:22:39 -05002277sub answer_bisect {
2278 for (;;) {
2279 doprint "Pass or fail? [p/f]";
2280 my $ans = <STDIN>;
2281 chomp $ans;
2282 if ($ans eq "p" || $ans eq "P") {
2283 return 1;
2284 } elsif ($ans eq "f" || $ans eq "F") {
2285 return 0;
2286 } else {
2287 print "Please answer 'P' or 'F'\n";
2288 }
2289 }
2290}
2291
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002292sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002293 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002294
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002295 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002296 $reboot_on_error = 0;
2297 $poweroff_on_error = 0;
2298 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002299
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302300 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002301 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302302 undef $redirect;
2303
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002304 exit $failed;
2305}
2306
2307my $child_done;
2308
2309sub child_finished {
2310 $child_done = 1;
2311}
2312
2313sub do_run_test {
2314 my $child_pid;
2315 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002316 my $line;
2317 my $full_line;
2318 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002319 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002320
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002321 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002322
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002323 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002324
2325 $child_done = 0;
2326
2327 $SIG{CHLD} = qw(child_finished);
2328
2329 $child_pid = fork;
2330
2331 child_run_test if (!$child_pid);
2332
2333 $full_line = "";
2334
2335 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002336 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002337 if (defined($line)) {
2338
2339 # we are not guaranteed to get a full line
2340 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002341 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002342
2343 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002344 if ($ignore_errors) {
2345 $bug_ignored = 1;
2346 } else {
2347 $bug = 1;
2348 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002349 }
2350
2351 if ($full_line =~ /Kernel panic -/) {
2352 $bug = 1;
2353 }
2354
2355 if ($line =~ /\n/) {
2356 $full_line = "";
2357 }
2358 }
2359 } while (!$child_done && !$bug);
2360
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002361 if (!$bug && $bug_ignored) {
2362 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2363 }
2364
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002365 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002366 my $failure_start = time;
2367 my $now;
2368 do {
2369 $line = wait_for_input($monitor_fp, 1);
2370 if (defined($line)) {
2371 doprint $line;
2372 }
2373 $now = time;
2374 if ($now - $failure_start >= $stop_after_failure) {
2375 last;
2376 }
2377 } while (defined($line));
2378
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002379 doprint "Detected kernel crash!\n";
2380 # kill the child with extreme prejudice
2381 kill 9, $child_pid;
2382 }
2383
2384 waitpid $child_pid, 0;
2385 $child_exit = $?;
2386
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002387 if (!$bug && $in_bisect) {
2388 if (defined($bisect_ret_good)) {
2389 if ($child_exit == $bisect_ret_good) {
2390 return 1;
2391 }
2392 }
2393 if (defined($bisect_ret_skip)) {
2394 if ($child_exit == $bisect_ret_skip) {
2395 return -1;
2396 }
2397 }
2398 if (defined($bisect_ret_abort)) {
2399 if ($child_exit == $bisect_ret_abort) {
2400 fail "test abort" and return -2;
2401 }
2402 }
2403 if (defined($bisect_ret_bad)) {
2404 if ($child_exit == $bisect_ret_skip) {
2405 return 0;
2406 }
2407 }
2408 if (defined($bisect_ret_default)) {
2409 if ($bisect_ret_default eq "good") {
2410 return 1;
2411 } elsif ($bisect_ret_default eq "bad") {
2412 return 0;
2413 } elsif ($bisect_ret_default eq "skip") {
2414 return -1;
2415 } elsif ($bisect_ret_default eq "abort") {
2416 return -2;
2417 } else {
2418 fail "unknown default action: $bisect_ret_default"
2419 and return -2;
2420 }
2421 }
2422 }
2423
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002424 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002425 return 0 if $in_bisect;
2426 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002427 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002428 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002429}
2430
Steven Rostedta75fece2010-11-02 14:58:27 -04002431sub run_git_bisect {
2432 my ($command) = @_;
2433
2434 doprint "$command ... ";
2435
2436 my $output = `$command 2>&1`;
2437 my $ret = $?;
2438
2439 logit $output;
2440
2441 if ($ret) {
2442 doprint "FAILED\n";
2443 dodie "Failed to git bisect";
2444 }
2445
2446 doprint "SUCCESS\n";
2447 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2448 doprint "$1 [$2]\n";
2449 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002450 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002451 doprint "Found bad commit... $1\n";
2452 return 0;
2453 } else {
2454 # we already logged it, just print it now.
2455 print $output;
2456 }
2457
2458 return 1;
2459}
2460
Steven Rostedtc23dca72011-03-08 09:26:31 -05002461sub bisect_reboot {
2462 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002463 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002464}
2465
2466# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002467sub run_bisect_test {
2468 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002469
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002470 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002471 my $result;
2472 my $output;
2473 my $ret;
2474
Steven Rostedt0a05c762010-11-08 11:14:10 -05002475 $in_bisect = 1;
2476
2477 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002478
2479 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002480 if ($failed && $bisect_skip) {
2481 $in_bisect = 0;
2482 return -1;
2483 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002484 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002485
2486 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002487 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002488
2489 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002490 if ($failed && $bisect_skip) {
2491 end_monitor;
2492 bisect_reboot;
2493 $in_bisect = 0;
2494 return -1;
2495 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002496 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002497
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002498 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002499 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002500 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002501 }
2502
2503 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002504 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002505 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002506 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002507 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002508
2509 # reboot the box to a kernel we can ssh to
2510 if ($type ne "build") {
2511 bisect_reboot;
2512 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002513 $in_bisect = 0;
2514
2515 return $result;
2516}
2517
2518sub run_bisect {
2519 my ($type) = @_;
2520 my $buildtype = "oldconfig";
2521
2522 # We should have a minconfig to use?
2523 if (defined($minconfig)) {
2524 $buildtype = "useconfig:$minconfig";
2525 }
2526
2527 my $ret = run_bisect_test $type, $buildtype;
2528
Steven Rostedtc960bb92011-03-08 09:22:39 -05002529 if ($bisect_manual) {
2530 $ret = answer_bisect;
2531 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002532
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002533 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002534 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002535 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002536 }
2537
Steven Rostedtc23dca72011-03-08 09:26:31 -05002538 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002539 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002540 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002541 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002542 } elsif ($bisect_skip) {
2543 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2544 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002545 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002546}
2547
Steven Rostedtdad98752011-11-22 20:48:57 -05002548sub update_bisect_replay {
2549 my $tmp_log = "$tmpdir/ktest_bisect_log";
2550 run_command "git bisect log > $tmp_log" or
2551 die "can't create bisect log";
2552 return $tmp_log;
2553}
2554
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002555sub bisect {
2556 my ($i) = @_;
2557
2558 my $result;
2559
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002560 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2561 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2562 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002563
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002564 my $good = $bisect_good;
2565 my $bad = $bisect_bad;
2566 my $type = $bisect_type;
2567 my $start = $bisect_start;
2568 my $replay = $bisect_replay;
2569 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002570
2571 if (defined($start_files)) {
2572 $start_files = " -- " . $start_files;
2573 } else {
2574 $start_files = "";
2575 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002576
Steven Rostedta57419b2010-11-02 15:13:54 -04002577 # convert to true sha1's
2578 $good = get_sha1($good);
2579 $bad = get_sha1($bad);
2580
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002581 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002582 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2583 $reverse_bisect = 1;
2584 } else {
2585 $reverse_bisect = 0;
2586 }
2587
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002588 # Can't have a test without having a test to run
2589 if ($type eq "test" && !defined($run_test)) {
2590 $type = "boot";
2591 }
2592
Steven Rostedtdad98752011-11-22 20:48:57 -05002593 # Check if a bisect was running
2594 my $bisect_start_file = "$builddir/.git/BISECT_START";
2595
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002596 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002597 my $do_check = defined($check) && $check ne "0";
2598
2599 if ( -f $bisect_start_file ) {
2600 print "Bisect in progress found\n";
2601 if ($do_check) {
2602 print " If you say yes, then no checks of good or bad will be done\n";
2603 }
2604 if (defined($replay)) {
2605 print "** BISECT_REPLAY is defined in config file **";
2606 print " Ignore config option and perform new git bisect log?\n";
2607 if (read_ync " (yes, no, or cancel) ") {
2608 $replay = update_bisect_replay;
2609 $do_check = 0;
2610 }
2611 } elsif (read_yn "read git log and continue?") {
2612 $replay = update_bisect_replay;
2613 $do_check = 0;
2614 }
2615 }
2616
2617 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002618
2619 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002620 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002621
2622 if ($check ne "good") {
2623 doprint "TESTING BISECT BAD [$bad]\n";
2624 run_command "git checkout $bad" or
2625 die "Failed to checkout $bad";
2626
2627 $result = run_bisect $type;
2628
2629 if ($result ne "bad") {
2630 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2631 }
2632 }
2633
2634 if ($check ne "bad") {
2635 doprint "TESTING BISECT GOOD [$good]\n";
2636 run_command "git checkout $good" or
2637 die "Failed to checkout $good";
2638
2639 $result = run_bisect $type;
2640
2641 if ($result ne "good") {
2642 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2643 }
2644 }
2645
2646 # checkout where we started
2647 run_command "git checkout $head" or
2648 die "Failed to checkout $head";
2649 }
2650
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002651 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002652 dodie "could not start bisect";
2653
2654 run_command "git bisect good $good" or
2655 dodie "could not set bisect good to $good";
2656
2657 run_git_bisect "git bisect bad $bad" or
2658 dodie "could not set bisect bad to $bad";
2659
2660 if (defined($replay)) {
2661 run_command "git bisect replay $replay" or
2662 dodie "failed to run replay";
2663 }
2664
2665 if (defined($start)) {
2666 run_command "git checkout $start" or
2667 dodie "failed to checkout $start";
2668 }
2669
2670 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002671 do {
2672 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002673 $test = run_git_bisect "git bisect $result";
2674 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002675
2676 run_command "git bisect log" or
2677 dodie "could not capture git bisect log";
2678
2679 run_command "git bisect reset" or
2680 dodie "could not reset git bisect";
2681
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002682 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002683
Steven Rostedt0a05c762010-11-08 11:14:10 -05002684 success $i;
2685}
2686
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002687# config_ignore holds the configs that were set (or unset) for
2688# a good config and we will ignore these configs for the rest
2689# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002690my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002691
2692# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002693my %config_set;
2694
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002695# config_off holds the set of configs that the bad config had disabled.
2696# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002697# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002698my %config_off;
2699
2700# config_off_tmp holds a set of configs to turn off for now
2701my @config_off_tmp;
2702
2703# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002704my %config_list;
2705my %null_config;
2706
2707my %dependency;
2708
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002709sub assign_configs {
2710 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002711
2712 open (IN, $config)
2713 or dodie "Failed to read $config";
2714
2715 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002716 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002717 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002718 }
2719 }
2720
2721 close(IN);
2722}
2723
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002724sub process_config_ignore {
2725 my ($config) = @_;
2726
2727 assign_configs \%config_ignore, $config;
2728}
2729
Steven Rostedt0a05c762010-11-08 11:14:10 -05002730sub read_current_config {
2731 my ($config_ref) = @_;
2732
2733 %{$config_ref} = ();
2734 undef %{$config_ref};
2735
2736 my @key = keys %{$config_ref};
2737 if ($#key >= 0) {
2738 print "did not delete!\n";
2739 exit;
2740 }
2741 open (IN, "$output_config");
2742
2743 while (<IN>) {
2744 if (/^(CONFIG\S+)=(.*)/) {
2745 ${$config_ref}{$1} = $2;
2746 }
2747 }
2748 close(IN);
2749}
2750
2751sub get_dependencies {
2752 my ($config) = @_;
2753
2754 my $arr = $dependency{$config};
2755 if (!defined($arr)) {
2756 return ();
2757 }
2758
2759 my @deps = @{$arr};
2760
2761 foreach my $dep (@{$arr}) {
2762 print "ADD DEP $dep\n";
2763 @deps = (@deps, get_dependencies $dep);
2764 }
2765
2766 return @deps;
2767}
2768
2769sub create_config {
2770 my @configs = @_;
2771
2772 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2773
2774 foreach my $config (@configs) {
2775 print OUT "$config_set{$config}\n";
2776 my @deps = get_dependencies $config;
2777 foreach my $dep (@deps) {
2778 print OUT "$config_set{$dep}\n";
2779 }
2780 }
2781
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002782 # turn off configs to keep off
2783 foreach my $config (keys %config_off) {
2784 print OUT "# $config is not set\n";
2785 }
2786
2787 # turn off configs that should be off for now
2788 foreach my $config (@config_off_tmp) {
2789 print OUT "# $config is not set\n";
2790 }
2791
Steven Rostedt0a05c762010-11-08 11:14:10 -05002792 foreach my $config (keys %config_ignore) {
2793 print OUT "$config_ignore{$config}\n";
2794 }
2795 close(OUT);
2796
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002797 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002798}
2799
2800sub compare_configs {
2801 my (%a, %b) = @_;
2802
2803 foreach my $item (keys %a) {
2804 if (!defined($b{$item})) {
2805 print "diff $item\n";
2806 return 1;
2807 }
2808 delete $b{$item};
2809 }
2810
2811 my @keys = keys %b;
2812 if ($#keys) {
2813 print "diff2 $keys[0]\n";
2814 }
2815 return -1 if ($#keys >= 0);
2816
2817 return 0;
2818}
2819
2820sub run_config_bisect_test {
2821 my ($type) = @_;
2822
2823 return run_bisect_test $type, "oldconfig";
2824}
2825
2826sub process_passed {
2827 my (%configs) = @_;
2828
2829 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2830 # Passed! All these configs are part of a good compile.
2831 # Add them to the min options.
2832 foreach my $config (keys %configs) {
2833 if (defined($config_list{$config})) {
2834 doprint " removing $config\n";
2835 $config_ignore{$config} = $config_list{$config};
2836 delete $config_list{$config};
2837 }
2838 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002839 doprint "config copied to $outputdir/config_good\n";
2840 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002841}
2842
2843sub process_failed {
2844 my ($config) = @_;
2845
2846 doprint "\n\n***************************************\n";
2847 doprint "Found bad config: $config\n";
2848 doprint "***************************************\n\n";
2849}
2850
2851sub run_config_bisect {
2852
2853 my @start_list = keys %config_list;
2854
2855 if ($#start_list < 0) {
2856 doprint "No more configs to test!!!\n";
2857 return -1;
2858 }
2859
2860 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002861 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002862 my $ret;
2863 my %current_config;
2864
2865 my $count = $#start_list + 1;
2866 doprint " $count configs to test\n";
2867
2868 my $half = int($#start_list / 2);
2869
2870 do {
2871 my @tophalf = @start_list[0 .. $half];
2872
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002873 # keep the bottom half off
2874 if ($half < $#start_list) {
2875 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2876 } else {
2877 @config_off_tmp = ();
2878 }
2879
Steven Rostedt0a05c762010-11-08 11:14:10 -05002880 create_config @tophalf;
2881 read_current_config \%current_config;
2882
2883 $count = $#tophalf + 1;
2884 doprint "Testing $count configs\n";
2885 my $found = 0;
2886 # make sure we test something
2887 foreach my $config (@tophalf) {
2888 if (defined($current_config{$config})) {
2889 logit " $config\n";
2890 $found = 1;
2891 }
2892 }
2893 if (!$found) {
2894 # try the other half
2895 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002896
2897 # keep the top half off
2898 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002899 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002900
Steven Rostedt0a05c762010-11-08 11:14:10 -05002901 create_config @tophalf;
2902 read_current_config \%current_config;
2903 foreach my $config (@tophalf) {
2904 if (defined($current_config{$config})) {
2905 logit " $config\n";
2906 $found = 1;
2907 }
2908 }
2909 if (!$found) {
2910 doprint "Failed: Can't make new config with current configs\n";
2911 foreach my $config (@start_list) {
2912 doprint " CONFIG: $config\n";
2913 }
2914 return -1;
2915 }
2916 $count = $#tophalf + 1;
2917 doprint "Testing $count configs\n";
2918 }
2919
2920 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002921 if ($bisect_manual) {
2922 $ret = answer_bisect;
2923 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002924 if ($ret) {
2925 process_passed %current_config;
2926 return 0;
2927 }
2928
2929 doprint "This config had a failure.\n";
2930 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002931 doprint "config copied to $outputdir/config_bad\n";
2932 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002933
2934 # A config exists in this group that was bad.
2935 foreach my $config (keys %config_list) {
2936 if (!defined($current_config{$config})) {
2937 doprint " removing $config\n";
2938 delete $config_list{$config};
2939 }
2940 }
2941
2942 @start_list = @tophalf;
2943
2944 if ($#start_list == 0) {
2945 process_failed $start_list[0];
2946 return 1;
2947 }
2948
2949 # remove half the configs we are looking at and see if
2950 # they are good.
2951 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002952 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002953
Steven Rostedtc960bb92011-03-08 09:22:39 -05002954 # we found a single config, try it again unless we are running manually
2955
2956 if ($bisect_manual) {
2957 process_failed $start_list[0];
2958 return 1;
2959 }
2960
Steven Rostedt0a05c762010-11-08 11:14:10 -05002961 my @tophalf = @start_list[0 .. 0];
2962
2963 $ret = run_config_bisect_test $type;
2964 if ($ret) {
2965 process_passed %current_config;
2966 return 0;
2967 }
2968
2969 process_failed $start_list[0];
2970 return 1;
2971}
2972
2973sub config_bisect {
2974 my ($i) = @_;
2975
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002976 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002977
2978 my $tmpconfig = "$tmpdir/use_config";
2979
Steven Rostedt30f75da2011-06-13 10:35:35 -04002980 if (defined($config_bisect_good)) {
2981 process_config_ignore $config_bisect_good;
2982 }
2983
Steven Rostedt0a05c762010-11-08 11:14:10 -05002984 # Make the file with the bad config and the min config
2985 if (defined($minconfig)) {
2986 # read the min config for things to ignore
2987 run_command "cp $minconfig $tmpconfig" or
2988 dodie "failed to copy $minconfig to $tmpconfig";
2989 } else {
2990 unlink $tmpconfig;
2991 }
2992
Steven Rostedt0a05c762010-11-08 11:14:10 -05002993 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002994 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002995 process_config_ignore $tmpconfig;
2996 }
2997
2998 # now process the start config
2999 run_command "cp $start_config $output_config" or
3000 dodie "failed to copy $start_config to $output_config";
3001
3002 # read directly what we want to check
3003 my %config_check;
3004 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09003005 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05003006
3007 while (<IN>) {
3008 if (/^((CONFIG\S*)=.*)/) {
3009 $config_check{$2} = $1;
3010 }
3011 }
3012 close(IN);
3013
Steven Rostedt250bae82011-07-15 22:05:59 -04003014 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003015 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003016
3017 # check to see what we lost (or gained)
3018 open (IN, $output_config)
3019 or dodie "Failed to read $start_config";
3020
3021 my %removed_configs;
3022 my %added_configs;
3023
3024 while (<IN>) {
3025 if (/^((CONFIG\S*)=.*)/) {
3026 # save off all options
3027 $config_set{$2} = $1;
3028 if (defined($config_check{$2})) {
3029 if (defined($config_ignore{$2})) {
3030 $removed_configs{$2} = $1;
3031 } else {
3032 $config_list{$2} = $1;
3033 }
3034 } elsif (!defined($config_ignore{$2})) {
3035 $added_configs{$2} = $1;
3036 $config_list{$2} = $1;
3037 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003038 } elsif (/^# ((CONFIG\S*).*)/) {
3039 # Keep these configs disabled
3040 $config_set{$2} = $1;
3041 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003042 }
3043 }
3044 close(IN);
3045
3046 my @confs = keys %removed_configs;
3047 if ($#confs >= 0) {
3048 doprint "Configs overridden by default configs and removed from check:\n";
3049 foreach my $config (@confs) {
3050 doprint " $config\n";
3051 }
3052 }
3053 @confs = keys %added_configs;
3054 if ($#confs >= 0) {
3055 doprint "Configs appearing in make oldconfig and added:\n";
3056 foreach my $config (@confs) {
3057 doprint " $config\n";
3058 }
3059 }
3060
3061 my %config_test;
3062 my $once = 0;
3063
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003064 @config_off_tmp = ();
3065
Steven Rostedt0a05c762010-11-08 11:14:10 -05003066 # Sometimes kconfig does weird things. We must make sure
3067 # that the config we autocreate has everything we need
3068 # to test, otherwise we may miss testing configs, or
3069 # may not be able to create a new config.
3070 # Here we create a config with everything set.
3071 create_config (keys %config_list);
3072 read_current_config \%config_test;
3073 foreach my $config (keys %config_list) {
3074 if (!defined($config_test{$config})) {
3075 if (!$once) {
3076 $once = 1;
3077 doprint "Configs not produced by kconfig (will not be checked):\n";
3078 }
3079 doprint " $config\n";
3080 delete $config_list{$config};
3081 }
3082 }
3083 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04003084
3085 if (defined($config_bisect_check) && $config_bisect_check) {
3086 doprint " Checking to make sure bad config with min config fails\n";
3087 create_config keys %config_list;
3088 $ret = run_config_bisect_test $config_bisect_type;
3089 if ($ret) {
3090 doprint " FAILED! Bad config with min config boots fine\n";
3091 return -1;
3092 }
3093 doprint " Bad config with min config fails as expected\n";
3094 }
3095
Steven Rostedt0a05c762010-11-08 11:14:10 -05003096 do {
3097 $ret = run_config_bisect;
3098 } while (!$ret);
3099
3100 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003101
3102 success $i;
3103}
3104
Steven Rostedt27d934b2011-05-20 09:18:18 -04003105sub patchcheck_reboot {
3106 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003107 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003108}
3109
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003110sub patchcheck {
3111 my ($i) = @_;
3112
3113 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003114 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003115 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003116 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003117
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003118 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003119
3120 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003121 if (defined($patchcheck_end)) {
3122 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003123 }
3124
Steven Rostedta57419b2010-11-02 15:13:54 -04003125 # Get the true sha1's since we can use things like HEAD~3
3126 $start = get_sha1($start);
3127 $end = get_sha1($end);
3128
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003129 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003130
3131 # Can't have a test without having a test to run
3132 if ($type eq "test" && !defined($run_test)) {
3133 $type = "boot";
3134 }
3135
3136 open (IN, "git log --pretty=oneline $end|") or
3137 dodie "could not get git list";
3138
3139 my @list;
3140
3141 while (<IN>) {
3142 chomp;
3143 $list[$#list+1] = $_;
3144 last if (/^$start/);
3145 }
3146 close(IN);
3147
3148 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003149 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003150 }
3151
3152 # go backwards in the list
3153 @list = reverse @list;
3154
3155 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003156 my %ignored_warnings;
3157
3158 if (defined($ignore_warnings)) {
3159 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3160 $ignored_warnings{$sha1} = 1;
3161 }
3162 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003163
3164 $in_patchcheck = 1;
3165 foreach my $item (@list) {
3166 my $sha1 = $item;
3167 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3168
3169 doprint "\nProcessing commit $item\n\n";
3170
3171 run_command "git checkout $sha1" or
3172 die "Failed to checkout $sha1";
3173
3174 # only clean on the first and last patch
3175 if ($item eq $list[0] ||
3176 $item eq $list[$#list]) {
3177 $noclean = $save_clean;
3178 } else {
3179 $noclean = 1;
3180 }
3181
3182 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003183 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003184 } else {
3185 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003186 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003187 }
3188
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003189 # No need to do per patch checking if warnings file exists
3190 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3191 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003192 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003193
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003194 check_buildlog or return 0;
3195
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003196 next if ($type eq "build");
3197
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003198 my $failed = 0;
3199
Steven Rostedtddf607e2011-06-14 20:49:13 -04003200 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003201
3202 if (!$failed && $type ne "boot"){
3203 do_run_test or $failed = 1;
3204 }
3205 end_monitor;
3206 return 0 if ($failed);
3207
Steven Rostedt27d934b2011-05-20 09:18:18 -04003208 patchcheck_reboot;
3209
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003210 }
3211 $in_patchcheck = 0;
3212 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003213
3214 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003215}
3216
Steven Rostedtb9066f62011-07-15 21:25:24 -04003217my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003218my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003219my $iflevel = 0;
3220my @ifdeps;
3221
3222# prevent recursion
3223my %read_kconfigs;
3224
Steven Rostedtac6974c2011-10-04 09:40:17 -04003225sub add_dep {
3226 # $config depends on $dep
3227 my ($config, $dep) = @_;
3228
3229 if (defined($depends{$config})) {
3230 $depends{$config} .= " " . $dep;
3231 } else {
3232 $depends{$config} = $dep;
3233 }
3234
3235 # record the number of configs depending on $dep
3236 if (defined $depcount{$dep}) {
3237 $depcount{$dep}++;
3238 } else {
3239 $depcount{$dep} = 1;
3240 }
3241}
3242
Steven Rostedtb9066f62011-07-15 21:25:24 -04003243# taken from streamline_config.pl
3244sub read_kconfig {
3245 my ($kconfig) = @_;
3246
3247 my $state = "NONE";
3248 my $config;
3249 my @kconfigs;
3250
3251 my $cont = 0;
3252 my $line;
3253
3254
3255 if (! -f $kconfig) {
3256 doprint "file $kconfig does not exist, skipping\n";
3257 return;
3258 }
3259
3260 open(KIN, "$kconfig")
3261 or die "Can't open $kconfig";
3262 while (<KIN>) {
3263 chomp;
3264
3265 # Make sure that lines ending with \ continue
3266 if ($cont) {
3267 $_ = $line . " " . $_;
3268 }
3269
3270 if (s/\\$//) {
3271 $cont = 1;
3272 $line = $_;
3273 next;
3274 }
3275
3276 $cont = 0;
3277
3278 # collect any Kconfig sources
3279 if (/^source\s*"(.*)"/) {
3280 $kconfigs[$#kconfigs+1] = $1;
3281 }
3282
3283 # configs found
3284 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3285 $state = "NEW";
3286 $config = $2;
3287
3288 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003289 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003290 }
3291
3292 # collect the depends for the config
3293 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3294
Steven Rostedtac6974c2011-10-04 09:40:17 -04003295 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003296
3297 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003298 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3299
3300 # selected by depends on config
3301 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003302
3303 # Check for if statements
3304 } elsif (/^if\s+(.*\S)\s*$/) {
3305 my $deps = $1;
3306 # remove beginning and ending non text
3307 $deps =~ s/^[^a-zA-Z0-9_]*//;
3308 $deps =~ s/[^a-zA-Z0-9_]*$//;
3309
3310 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3311
3312 $ifdeps[$iflevel++] = join ':', @deps;
3313
3314 } elsif (/^endif/) {
3315
3316 $iflevel-- if ($iflevel);
3317
3318 # stop on "help"
3319 } elsif (/^\s*help\s*$/) {
3320 $state = "NONE";
3321 }
3322 }
3323 close(KIN);
3324
3325 # read in any configs that were found.
3326 foreach $kconfig (@kconfigs) {
3327 if (!defined($read_kconfigs{$kconfig})) {
3328 $read_kconfigs{$kconfig} = 1;
3329 read_kconfig("$builddir/$kconfig");
3330 }
3331 }
3332}
3333
3334sub read_depends {
3335 # find out which arch this is by the kconfig file
3336 open (IN, $output_config)
3337 or dodie "Failed to read $output_config";
3338 my $arch;
3339 while (<IN>) {
3340 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3341 $arch = $1;
3342 last;
3343 }
3344 }
3345 close IN;
3346
3347 if (!defined($arch)) {
3348 doprint "Could not find arch from config file\n";
3349 doprint "no dependencies used\n";
3350 return;
3351 }
3352
3353 # arch is really the subarch, we need to know
3354 # what directory to look at.
3355 if ($arch eq "i386" || $arch eq "x86_64") {
3356 $arch = "x86";
3357 } elsif ($arch =~ /^tile/) {
3358 $arch = "tile";
3359 }
3360
3361 my $kconfig = "$builddir/arch/$arch/Kconfig";
3362
3363 if (! -f $kconfig && $arch =~ /\d$/) {
3364 my $orig = $arch;
3365 # some subarchs have numbers, truncate them
3366 $arch =~ s/\d*$//;
3367 $kconfig = "$builddir/arch/$arch/Kconfig";
3368 if (! -f $kconfig) {
3369 doprint "No idea what arch dir $orig is for\n";
3370 doprint "no dependencies used\n";
3371 return;
3372 }
3373 }
3374
3375 read_kconfig($kconfig);
3376}
3377
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003378sub read_config_list {
3379 my ($config) = @_;
3380
3381 open (IN, $config)
3382 or dodie "Failed to read $config";
3383
3384 while (<IN>) {
3385 if (/^((CONFIG\S*)=.*)/) {
3386 if (!defined($config_ignore{$2})) {
3387 $config_list{$2} = $1;
3388 }
3389 }
3390 }
3391
3392 close(IN);
3393}
3394
3395sub read_output_config {
3396 my ($config) = @_;
3397
3398 assign_configs \%config_ignore, $config;
3399}
3400
3401sub make_new_config {
3402 my @configs = @_;
3403
3404 open (OUT, ">$output_config")
3405 or dodie "Failed to write $output_config";
3406
3407 foreach my $config (@configs) {
3408 print OUT "$config\n";
3409 }
3410 close OUT;
3411}
3412
Steven Rostedtac6974c2011-10-04 09:40:17 -04003413sub chomp_config {
3414 my ($config) = @_;
3415
3416 $config =~ s/CONFIG_//;
3417
3418 return $config;
3419}
3420
Steven Rostedtb9066f62011-07-15 21:25:24 -04003421sub get_depends {
3422 my ($dep) = @_;
3423
Steven Rostedtac6974c2011-10-04 09:40:17 -04003424 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003425
3426 $dep = $depends{"$kconfig"};
3427
3428 # the dep string we have saves the dependencies as they
3429 # were found, including expressions like ! && ||. We
3430 # want to split this out into just an array of configs.
3431
3432 my $valid = "A-Za-z_0-9";
3433
3434 my @configs;
3435
3436 while ($dep =~ /[$valid]/) {
3437
3438 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3439 my $conf = "CONFIG_" . $1;
3440
3441 $configs[$#configs + 1] = $conf;
3442
3443 $dep =~ s/^[^$valid]*[$valid]+//;
3444 } else {
3445 die "this should never happen";
3446 }
3447 }
3448
3449 return @configs;
3450}
3451
3452my %min_configs;
3453my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003454my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003455my %processed_configs;
3456my %nochange_config;
3457
3458sub test_this_config {
3459 my ($config) = @_;
3460
3461 my $found;
3462
3463 # if we already processed this config, skip it
3464 if (defined($processed_configs{$config})) {
3465 return undef;
3466 }
3467 $processed_configs{$config} = 1;
3468
3469 # if this config failed during this round, skip it
3470 if (defined($nochange_config{$config})) {
3471 return undef;
3472 }
3473
Steven Rostedtac6974c2011-10-04 09:40:17 -04003474 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003475
3476 # Test dependencies first
3477 if (defined($depends{"$kconfig"})) {
3478 my @parents = get_depends $config;
3479 foreach my $parent (@parents) {
3480 # if the parent is in the min config, check it first
3481 next if (!defined($min_configs{$parent}));
3482 $found = test_this_config($parent);
3483 if (defined($found)) {
3484 return $found;
3485 }
3486 }
3487 }
3488
3489 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003490 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003491 # .config to make sure it is missing the config that
3492 # we had before
3493 my %configs = %min_configs;
3494 delete $configs{$config};
3495 make_new_config ((values %configs), (values %keep_configs));
3496 make_oldconfig;
3497 undef %configs;
3498 assign_configs \%configs, $output_config;
3499
3500 return $config if (!defined($configs{$config}));
3501
3502 doprint "disabling config $config did not change .config\n";
3503
3504 $nochange_config{$config} = 1;
3505
3506 return undef;
3507}
3508
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003509sub make_min_config {
3510 my ($i) = @_;
3511
Steven Rostedtccc513b2012-05-21 17:13:40 -04003512 my $type = $minconfig_type;
3513 if ($type ne "boot" && $type ne "test") {
3514 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3515 " make_min_config works only with 'boot' and 'test'\n" and return;
3516 }
3517
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003518 if (!defined($output_minconfig)) {
3519 fail "OUTPUT_MIN_CONFIG not defined" and return;
3520 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003521
3522 # If output_minconfig exists, and the start_minconfig
3523 # came from min_config, than ask if we should use
3524 # that instead.
3525 if (-f $output_minconfig && !$start_minconfig_defined) {
3526 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003527 if (!defined($use_output_minconfig)) {
3528 if (read_yn " Use it as minconfig?") {
3529 $start_minconfig = $output_minconfig;
3530 }
3531 } elsif ($use_output_minconfig > 0) {
3532 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003533 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003534 } else {
3535 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003536 }
3537 }
3538
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003539 if (!defined($start_minconfig)) {
3540 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3541 }
3542
Steven Rostedt35ce5952011-07-15 21:57:25 -04003543 my $temp_config = "$tmpdir/temp_config";
3544
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003545 # First things first. We build an allnoconfig to find
3546 # out what the defaults are that we can't touch.
3547 # Some are selections, but we really can't handle selections.
3548
3549 my $save_minconfig = $minconfig;
3550 undef $minconfig;
3551
3552 run_command "$make allnoconfig" or return 0;
3553
Steven Rostedtb9066f62011-07-15 21:25:24 -04003554 read_depends;
3555
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003556 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003557
Steven Rostedt43d1b652011-07-15 22:01:56 -04003558 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003559 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003560
3561 if (defined($ignore_config)) {
3562 # make sure the file exists
3563 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003564 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003565 }
3566
Steven Rostedt43d1b652011-07-15 22:01:56 -04003567 %keep_configs = %save_configs;
3568
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003569 doprint "Load initial configs from $start_minconfig\n";
3570
3571 # Look at the current min configs, and save off all the
3572 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003573 assign_configs \%min_configs, $start_minconfig;
3574
3575 my @config_keys = keys %min_configs;
3576
Steven Rostedtac6974c2011-10-04 09:40:17 -04003577 # All configs need a depcount
3578 foreach my $config (@config_keys) {
3579 my $kconfig = chomp_config $config;
3580 if (!defined $depcount{$kconfig}) {
3581 $depcount{$kconfig} = 0;
3582 }
3583 }
3584
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003585 # Remove anything that was set by the make allnoconfig
3586 # we shouldn't need them as they get set for us anyway.
3587 foreach my $config (@config_keys) {
3588 # Remove anything in the ignore_config
3589 if (defined($keep_configs{$config})) {
3590 my $file = $ignore_config;
3591 $file =~ s,.*/(.*?)$,$1,;
3592 doprint "$config set by $file ... ignored\n";
3593 delete $min_configs{$config};
3594 next;
3595 }
3596 # But make sure the settings are the same. If a min config
3597 # sets a selection, we do not want to get rid of it if
3598 # it is not the same as what we have. Just move it into
3599 # the keep configs.
3600 if (defined($config_ignore{$config})) {
3601 if ($config_ignore{$config} ne $min_configs{$config}) {
3602 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3603 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3604 $keep_configs{$config} = $min_configs{$config};
3605 } else {
3606 doprint "$config set by allnoconfig ... ignored\n";
3607 }
3608 delete $min_configs{$config};
3609 }
3610 }
3611
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003612 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003613 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003614
3615 while (!$done) {
3616
3617 my $config;
3618 my $found;
3619
3620 # Now disable each config one by one and do a make oldconfig
3621 # till we find a config that changes our list.
3622
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003623 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003624
3625 # Sort keys by who is most dependent on
3626 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3627 @test_configs ;
3628
3629 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003630 my $reset = 1;
3631 for (my $i = 0; $i < $#test_configs; $i++) {
3632 if (!defined($nochange_config{$test_configs[0]})) {
3633 $reset = 0;
3634 last;
3635 }
3636 # This config didn't change the .config last time.
3637 # Place it at the end
3638 my $config = shift @test_configs;
3639 push @test_configs, $config;
3640 }
3641
3642 # if every test config has failed to modify the .config file
3643 # in the past, then reset and start over.
3644 if ($reset) {
3645 undef %nochange_config;
3646 }
3647
Steven Rostedtb9066f62011-07-15 21:25:24 -04003648 undef %processed_configs;
3649
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003650 foreach my $config (@test_configs) {
3651
Steven Rostedtb9066f62011-07-15 21:25:24 -04003652 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003653
Steven Rostedtb9066f62011-07-15 21:25:24 -04003654 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003655
3656 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003657 }
3658
3659 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003660 # we could have failed due to the nochange_config hash
3661 # reset and try again
3662 if (!$take_two) {
3663 undef %nochange_config;
3664 $take_two = 1;
3665 next;
3666 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003667 doprint "No more configs found that we can disable\n";
3668 $done = 1;
3669 last;
3670 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003671 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003672
3673 $config = $found;
3674
3675 doprint "Test with $config disabled\n";
3676
3677 # set in_bisect to keep build and monitor from dieing
3678 $in_bisect = 1;
3679
3680 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003681 build "oldconfig" or $failed = 1;
3682 if (!$failed) {
3683 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003684
3685 if ($type eq "test" && !$failed) {
3686 do_run_test or $failed = 1;
3687 }
3688
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003689 end_monitor;
3690 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003691
3692 $in_bisect = 0;
3693
3694 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003695 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003696 # this config is needed, add it to the ignore list.
3697 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003698 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003699 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003700
3701 # update new ignore configs
3702 if (defined($ignore_config)) {
3703 open (OUT, ">$temp_config")
3704 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003705 foreach my $config (keys %save_configs) {
3706 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003707 }
3708 close OUT;
3709 run_command "mv $temp_config $ignore_config" or
3710 dodie "failed to copy update to $ignore_config";
3711 }
3712
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003713 } else {
3714 # We booted without this config, remove it from the minconfigs.
3715 doprint "$config is not needed, disabling\n";
3716
3717 delete $min_configs{$config};
3718
3719 # Also disable anything that is not enabled in this config
3720 my %configs;
3721 assign_configs \%configs, $output_config;
3722 my @config_keys = keys %min_configs;
3723 foreach my $config (@config_keys) {
3724 if (!defined($configs{$config})) {
3725 doprint "$config is not set, disabling\n";
3726 delete $min_configs{$config};
3727 }
3728 }
3729
3730 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003731 open (OUT, ">$temp_config")
3732 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003733 foreach my $config (keys %keep_configs) {
3734 print OUT "$keep_configs{$config}\n";
3735 }
3736 foreach my $config (keys %min_configs) {
3737 print OUT "$min_configs{$config}\n";
3738 }
3739 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003740
3741 run_command "mv $temp_config $output_minconfig" or
3742 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003743 }
3744
3745 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003746 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003747 }
3748
3749 success $i;
3750 return 1;
3751}
3752
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003753sub make_warnings_file {
3754 my ($i) = @_;
3755
3756 if (!defined($warnings_file)) {
3757 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3758 }
3759
3760 if ($build_type eq "nobuild") {
3761 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3762 }
3763
3764 build $build_type or dodie "Failed to build";
3765
3766 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3767
3768 open(IN, $buildlog) or dodie "Can't open $buildlog";
3769 while (<IN>) {
3770
3771 # Some compilers use UTF-8 extended for quotes
3772 # for distcc heterogeneous systems, this causes issues
3773 s/$utf8_quote/'/g;
3774
3775 if (/$check_build_re/) {
3776 print OUT;
3777 }
3778 }
3779 close(IN);
3780
3781 close(OUT);
3782
3783 success $i;
3784}
3785
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003786$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003787
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003788if ($#ARGV == 0) {
3789 $ktest_config = $ARGV[0];
3790 if (! -f $ktest_config) {
3791 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003792 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003793 exit 0;
3794 }
3795 }
3796} else {
3797 $ktest_config = "ktest.conf";
3798}
3799
3800if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003801 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003802 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003803 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3804 print OUT << "EOF"
3805# Generated by ktest.pl
3806#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003807
3808# PWD is a ktest.pl variable that will result in the process working
3809# directory that ktest.pl is executed in.
3810
3811# THIS_DIR is automatically assigned the PWD of the path that generated
3812# the config file. It is best to use this variable when assigning other
3813# directory paths within this directory. This allows you to easily
3814# move the test cases to other locations or to other machines.
3815#
3816THIS_DIR := $variable{"PWD"}
3817
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003818# Define each test with TEST_START
3819# The config options below it will override the defaults
3820TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003821TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003822
3823DEFAULTS
3824EOF
3825;
3826 close(OUT);
3827}
3828read_config $ktest_config;
3829
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003830if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003831 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003832}
3833
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003834# Append any configs entered in manually to the config file.
3835my @new_configs = keys %entered_configs;
3836if ($#new_configs >= 0) {
3837 print "\nAppending entered in configs to $ktest_config\n";
3838 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3839 foreach my $config (@new_configs) {
3840 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003841 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003842 }
3843}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003844
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003845if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3846 unlink $opt{"LOG_FILE"};
3847}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003848
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003849doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3850
Steven Rostedta57419b2010-11-02 15:13:54 -04003851for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3852
3853 if (!$i) {
3854 doprint "DEFAULT OPTIONS:\n";
3855 } else {
3856 doprint "\nTEST $i OPTIONS";
3857 if (defined($repeat_tests{$i})) {
3858 $repeat = $repeat_tests{$i};
3859 doprint " ITERATE $repeat";
3860 }
3861 doprint "\n";
3862 }
3863
3864 foreach my $option (sort keys %opt) {
3865
3866 if ($option =~ /\[(\d+)\]$/) {
3867 next if ($i != $1);
3868 } else {
3869 next if ($i);
3870 }
3871
3872 doprint "$option = $opt{$option}\n";
3873 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003874}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003875
Steven Rostedt2a625122011-05-20 15:48:59 -04003876sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003877 my ($name, $i) = @_;
3878
3879 my $option = "$name\[$i\]";
3880
3881 if (defined($opt{$option})) {
3882 return $opt{$option};
3883 }
3884
Steven Rostedta57419b2010-11-02 15:13:54 -04003885 foreach my $test (keys %repeat_tests) {
3886 if ($i >= $test &&
3887 $i < $test + $repeat_tests{$test}) {
3888 $option = "$name\[$test\]";
3889 if (defined($opt{$option})) {
3890 return $opt{$option};
3891 }
3892 }
3893 }
3894
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003895 if (defined($opt{$name})) {
3896 return $opt{$name};
3897 }
3898
3899 return undef;
3900}
3901
Steven Rostedt2a625122011-05-20 15:48:59 -04003902sub set_test_option {
3903 my ($name, $i) = @_;
3904
3905 my $option = __set_test_option($name, $i);
3906 return $option if (!defined($option));
3907
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003908 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003909}
3910
Steven Rostedt2545eb62010-11-02 15:01:32 -04003911# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003912for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003913
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003914 # Do not reboot on failing test options
3915 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003916 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003917
Steven Rostedt683a3e62012-05-18 13:34:35 -04003918 $have_version = 0;
3919
Steven Rostedt576f6272010-11-02 14:58:38 -04003920 $iteration = $i;
3921
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003922 undef %force_config;
3923
Steven Rostedta75fece2010-11-02 14:58:27 -04003924 my $makecmd = set_test_option("MAKE_CMD", $i);
3925
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003926 $outputdir = set_test_option("OUTPUT_DIR", $i);
3927 $builddir = set_test_option("BUILD_DIR", $i);
3928
3929 chdir $builddir || die "can't change directory to $builddir";
3930
3931 if (!-d $outputdir) {
3932 mkpath($outputdir) or
3933 die "can't create $outputdir";
3934 }
3935
3936 $make = "$makecmd O=$outputdir";
3937
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003938 # Load all the options into their mapped variable names
3939 foreach my $opt (keys %option_map) {
3940 ${$option_map{$opt}} = set_test_option($opt, $i);
3941 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003942
Steven Rostedt35ce5952011-07-15 21:57:25 -04003943 $start_minconfig_defined = 1;
3944
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003945 # The first test may override the PRE_KTEST option
3946 if (defined($pre_ktest) && $i == 1) {
3947 doprint "\n";
3948 run_command $pre_ktest;
3949 }
3950
3951 # Any test can override the POST_KTEST option
3952 # The last test takes precedence.
3953 if (defined($post_ktest)) {
3954 $final_post_ktest = $post_ktest;
3955 }
3956
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003957 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003958 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003959 $start_minconfig = $minconfig;
3960 }
3961
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003962 if (!-d $tmpdir) {
3963 mkpath($tmpdir) or
3964 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04003965 }
3966
Steven Rostedte48c5292010-11-02 14:35:37 -04003967 $ENV{"SSH_USER"} = $ssh_user;
3968 $ENV{"MACHINE"} = $machine;
3969
Steven Rostedta75fece2010-11-02 14:58:27 -04003970 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303971 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003972 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003973 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003974
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003975 if (!$buildonly) {
3976 $target = "$ssh_user\@$machine";
3977 if ($reboot_type eq "grub") {
3978 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05003979 } elsif ($reboot_type eq "grub2") {
3980 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3981 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05003982 } elsif ($reboot_type eq "syslinux") {
3983 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003984 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003985 }
3986
3987 my $run_type = $build_type;
3988 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003989 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003990 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003991 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003992 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003993 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003994 } elsif ($test_type eq "make_min_config") {
3995 $run_type = "";
3996 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003997 $run_type = "";
3998 }
3999
Steven Rostedta75fece2010-11-02 14:58:27 -04004000 # mistake in config file?
4001 if (!defined($run_type)) {
4002 $run_type = "ERROR";
4003 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004004
Steven Rostedte0a87422011-09-30 17:50:48 -04004005 my $installme = "";
4006 $installme = " no_install" if ($no_install);
4007
Steven Rostedt2545eb62010-11-02 15:01:32 -04004008 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04004009 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004010
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004011 if (defined($pre_test)) {
4012 run_command $pre_test;
4013 }
4014
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004015 unlink $dmesg;
4016 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304017 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004018
Steven Rostedt250bae82011-07-15 22:05:59 -04004019 if (defined($addconfig)) {
4020 my $min = $minconfig;
4021 if (!defined($minconfig)) {
4022 $min = "";
4023 }
4024 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004025 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004026 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004027 }
4028
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004029 if (defined($checkout)) {
4030 run_command "git checkout $checkout" or
4031 die "failed to checkout $checkout";
4032 }
4033
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004034 $no_reboot = 0;
4035
Steven Rostedt648a1822012-03-21 11:18:27 -04004036 # A test may opt to not reboot the box
4037 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004038 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004039 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004040
Steven Rostedta75fece2010-11-02 14:58:27 -04004041 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004042 bisect $i;
4043 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004044 } elsif ($test_type eq "config_bisect") {
4045 config_bisect $i;
4046 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004047 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004048 patchcheck $i;
4049 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004050 } elsif ($test_type eq "make_min_config") {
4051 make_min_config $i;
4052 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004053 } elsif ($test_type eq "make_warnings_file") {
4054 $no_reboot = 1;
4055 make_warnings_file $i;
4056 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004057 }
4058
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004059 if ($build_type ne "nobuild") {
4060 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004061 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004062 }
4063
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004064 if ($test_type eq "install") {
4065 get_version;
4066 install;
4067 success $i;
4068 next;
4069 }
4070
Steven Rostedta75fece2010-11-02 14:58:27 -04004071 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004072 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004073 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004074
4075 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4076 do_run_test or $failed = 1;
4077 }
4078 end_monitor;
4079 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004080 }
4081
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004082 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004083}
4084
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004085if (defined($final_post_ktest)) {
4086 run_command $final_post_ktest;
4087}
4088
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004089if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004090 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004091} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004092 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004093} elsif (defined($switch_to_good)) {
4094 # still need to get to the good kernel
4095 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004096}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004097
Steven Rostedt648a1822012-03-21 11:18:27 -04004098
Steven Rostedte48c5292010-11-02 14:35:37 -04004099doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4100
Steven Rostedt2545eb62010-11-02 15:01:32 -04004101exit 0;