blob: 5dc5704d868076d514ca63d1351bc20b54e2bb84 [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";
1132 } else {
1133 $retval = "$retval\$\{$var\}";
1134 }
1135
1136 $option = $end;
1137 }
1138
1139 $retval = "$retval$option";
1140
1141 $retval =~ s/^ //;
1142
1143 return $retval;
1144}
1145
1146sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001147 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001148
1149 my $prev = "";
1150
1151 # Since an option can evaluate to another option,
1152 # keep iterating until we do not evaluate any more
1153 # options.
1154 my $r = 0;
1155 while ($prev ne $option) {
1156 # Check for recursive evaluations.
1157 # 100 deep should be more than enough.
1158 if ($r++ > 100) {
1159 die "Over 100 evaluations accurred with $option\n" .
1160 "Check for recursive variables\n";
1161 }
1162 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001163 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001164 }
1165
1166 return $option;
1167}
1168
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001169sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001170 if (defined($opt{"LOG_FILE"})) {
1171 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1172 print OUT @_;
1173 close(OUT);
1174 }
1175}
1176
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001177sub logit {
1178 if (defined($opt{"LOG_FILE"})) {
1179 _logit @_;
1180 } else {
1181 print @_;
1182 }
1183}
1184
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001185sub doprint {
1186 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001187 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001188}
1189
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001190sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001191sub start_monitor;
1192sub end_monitor;
1193sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001194
1195sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001196 my ($time) = @_;
1197
Steven Rostedta4968722012-12-11 14:59:05 -05001198 # Make sure everything has been written to disk
1199 run_ssh("sync");
1200
Steven Rostedt2b803362011-09-30 18:00:23 -04001201 if (defined($time)) {
1202 start_monitor;
1203 # flush out current monitor
1204 # May contain the reboot success line
1205 wait_for_monitor 1;
1206 }
1207
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001208 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001209 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001210 if (defined($powercycle_after_reboot)) {
1211 sleep $powercycle_after_reboot;
1212 run_command "$power_cycle";
1213 }
1214 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001215 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001216 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001217 }
Andrew Jones2728be42011-08-12 15:32:05 +02001218
1219 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001220
1221 # We only want to get to the new kernel, don't fail
1222 # if we stumble over a call trace.
1223 my $save_ignore_errors = $ignore_errors;
1224 $ignore_errors = 1;
1225
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001226 # Look for the good kernel to boot
1227 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001228 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001229 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001230 run_command "$power_cycle";
1231 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001232
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001233 $ignore_errors = $save_ignore_errors;
1234
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001235 # Still need to wait for the reboot to finish
1236 wait_for_monitor($time, $reboot_success_line);
1237
Andrew Jones2728be42011-08-12 15:32:05 +02001238 end_monitor;
1239 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001240}
1241
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001242sub reboot_to_good {
1243 my ($time) = @_;
1244
1245 if (defined($switch_to_good)) {
1246 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001247 }
1248
1249 reboot $time;
1250}
1251
Steven Rostedt576f6272010-11-02 14:58:38 -04001252sub do_not_reboot {
1253 my $i = $iteration;
1254
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001255 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001256 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1257 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1258}
1259
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001260sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001261 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001262
Steven Rostedt576f6272010-11-02 14:58:38 -04001263 my $i = $iteration;
1264
1265 if ($reboot_on_error && !do_not_reboot) {
1266
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001267 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001268 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001269
Steven Rostedta75fece2010-11-02 14:58:27 -04001270 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001271 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001272 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001273 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001274
Steven Rostedtf80802c2011-03-07 13:18:47 -05001275 if (defined($opt{"LOG_FILE"})) {
1276 print " See $opt{LOG_FILE} for more info.\n";
1277 }
1278
Steven Rostedt576f6272010-11-02 14:58:38 -04001279 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001280}
1281
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001282sub open_console {
1283 my ($fp) = @_;
1284
1285 my $flags;
1286
Steven Rostedta75fece2010-11-02 14:58:27 -04001287 my $pid = open($fp, "$console|") or
1288 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001289
1290 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001291 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001292 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001293 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001294
1295 return $pid;
1296}
1297
1298sub close_console {
1299 my ($fp, $pid) = @_;
1300
1301 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001302 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001303
1304 print "closing!\n";
1305 close($fp);
1306}
1307
1308sub start_monitor {
1309 if ($monitor_cnt++) {
1310 return;
1311 }
1312 $monitor_fp = \*MONFD;
1313 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001314
1315 return;
1316
1317 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001318}
1319
1320sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001321 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001322 if (--$monitor_cnt) {
1323 return;
1324 }
1325 close_console($monitor_fp, $monitor_pid);
1326}
1327
1328sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001329 my ($time, $stop) = @_;
1330 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001331 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001332 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001333 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001334 my $skip_call_trace = 0;
1335 my $bug = 0;
1336 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001337 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001338
Steven Rostedta75fece2010-11-02 14:58:27 -04001339 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001340
1341 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001342 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001343 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001344 last if (!defined($line));
1345 print "$line";
1346 $full_line .= $line;
1347
1348 if (defined($stop) && $full_line =~ /$stop/) {
1349 doprint "wait for monitor detected $stop\n";
1350 $booted = 1;
1351 }
1352
Steven Rostedt8a80c722012-07-19 16:08:33 -04001353 if ($full_line =~ /\[ backtrace testing \]/) {
1354 $skip_call_trace = 1;
1355 }
1356
1357 if ($full_line =~ /call trace:/i) {
1358 if (!$bug && !$skip_call_trace) {
1359 if ($ignore_errors) {
1360 $bug_ignored = 1;
1361 } else {
1362 $bug = 1;
1363 }
1364 }
1365 }
1366
1367 if ($full_line =~ /\[ end of backtrace testing \]/) {
1368 $skip_call_trace = 0;
1369 }
1370
1371 if ($full_line =~ /Kernel panic -/) {
1372 $bug = 1;
1373 }
1374
Steven Rostedt2b803362011-09-30 18:00:23 -04001375 if ($line =~ /\n/) {
1376 $full_line = "";
1377 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001378 $now = time;
1379 if ($now - $start_time >= $max_monitor_wait) {
1380 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1381 return 1;
1382 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001383 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001384 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001385 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001386}
1387
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301388sub save_logs {
1389 my ($result, $basedir) = @_;
1390 my @t = localtime;
1391 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1392 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1393
1394 my $type = $build_type;
1395 if ($type =~ /useconfig/) {
1396 $type = "useconfig";
1397 }
1398
1399 my $dir = "$machine-$test_type-$type-$result-$date";
1400
1401 $dir = "$basedir/$dir";
1402
1403 if (!-d $dir) {
1404 mkpath($dir) or
1405 die "can't create $dir";
1406 }
1407
1408 my %files = (
1409 "config" => $output_config,
1410 "buildlog" => $buildlog,
1411 "dmesg" => $dmesg,
1412 "testlog" => $testlog,
1413 );
1414
1415 while (my ($name, $source) = each(%files)) {
1416 if (-f "$source") {
1417 cp "$source", "$dir/$name" or
1418 die "failed to copy $source";
1419 }
1420 }
1421
1422 doprint "*** Saved info to $dir ***\n";
1423}
1424
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001425sub fail {
1426
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001427 if (defined($post_test)) {
1428 run_command $post_test;
1429 }
1430
Steven Rostedta75fece2010-11-02 14:58:27 -04001431 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001432 dodie @_;
1433 }
1434
Steven Rostedta75fece2010-11-02 14:58:27 -04001435 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001436
Steven Rostedt576f6272010-11-02 14:58:38 -04001437 my $i = $iteration;
1438
Steven Rostedta75fece2010-11-02 14:58:27 -04001439 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001440 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001441 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001442 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001443 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001444
Steven Rostedt9064af52011-06-13 10:38:48 -04001445 my $name = "";
1446
1447 if (defined($test_name)) {
1448 $name = " ($test_name)";
1449 }
1450
Steven Rostedt576f6272010-11-02 14:58:38 -04001451 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1452 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001453 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001454 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1455 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001456
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301457 if (defined($store_failures)) {
1458 save_logs "fail", $store_failures;
1459 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001460
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001461 return 1;
1462}
1463
Steven Rostedt2545eb62010-11-02 15:01:32 -04001464sub run_command {
1465 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001466 my $dolog = 0;
1467 my $dord = 0;
1468 my $pid;
1469
Steven Rostedte48c5292010-11-02 14:35:37 -04001470 $command =~ s/\$SSH_USER/$ssh_user/g;
1471 $command =~ s/\$MACHINE/$machine/g;
1472
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001473 doprint("$command ... ");
1474
1475 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001476 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001477
1478 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001479 open(LOG, ">>$opt{LOG_FILE}") or
1480 dodie "failed to write to log";
1481 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001482 }
1483
1484 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001485 open (RD, ">$redirect") or
1486 dodie "failed to write to redirect $redirect";
1487 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001488 }
1489
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001490 while (<CMD>) {
1491 print LOG if ($dolog);
1492 print RD if ($dord);
1493 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001494
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001495 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001496 my $failed = $?;
1497
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001498 close(CMD);
1499 close(LOG) if ($dolog);
1500 close(RD) if ($dord);
1501
Steven Rostedt2545eb62010-11-02 15:01:32 -04001502 if ($failed) {
1503 doprint "FAILED!\n";
1504 } else {
1505 doprint "SUCCESS\n";
1506 }
1507
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001508 return !$failed;
1509}
1510
Steven Rostedte48c5292010-11-02 14:35:37 -04001511sub run_ssh {
1512 my ($cmd) = @_;
1513 my $cp_exec = $ssh_exec;
1514
1515 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1516 return run_command "$cp_exec";
1517}
1518
1519sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001520 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001521
1522 $cp_scp =~ s/\$SRC_FILE/$src/g;
1523 $cp_scp =~ s/\$DST_FILE/$dst/g;
1524
1525 return run_command "$cp_scp";
1526}
1527
Steven Rostedt02ad2612012-03-21 08:21:24 -04001528sub run_scp_install {
1529 my ($src, $dst) = @_;
1530
1531 my $cp_scp = $scp_to_target_install;
1532
1533 return run_scp($src, $dst, $cp_scp);
1534}
1535
1536sub run_scp_mod {
1537 my ($src, $dst) = @_;
1538
1539 my $cp_scp = $scp_to_target;
1540
1541 return run_scp($src, $dst, $cp_scp);
1542}
1543
Steven Rostedta15ba912012-11-13 14:30:37 -05001544sub get_grub2_index {
1545
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001546 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001547 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1548 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001549
1550 doprint "Find grub2 menu ... ";
1551 $grub_number = -1;
1552
1553 my $ssh_grub = $ssh_exec;
1554 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1555
1556 open(IN, "$ssh_grub |")
1557 or die "unable to get $grub_file";
1558
1559 my $found = 0;
1560
1561 while (<IN>) {
1562 if (/^menuentry.*$grub_menu/) {
1563 $grub_number++;
1564 $found = 1;
1565 last;
1566 } elsif (/^menuentry\s/) {
1567 $grub_number++;
1568 }
1569 }
1570 close(IN);
1571
1572 die "Could not find '$grub_menu' in $grub_file on $machine"
1573 if (!$found);
1574 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001575 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001576 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001577}
1578
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001579sub get_grub_index {
1580
Steven Rostedta15ba912012-11-13 14:30:37 -05001581 if ($reboot_type eq "grub2") {
1582 get_grub2_index;
1583 return;
1584 }
1585
Steven Rostedta75fece2010-11-02 14:58:27 -04001586 if ($reboot_type ne "grub") {
1587 return;
1588 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001589 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001590 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1591 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001592
1593 doprint "Find grub menu ... ";
1594 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001595
1596 my $ssh_grub = $ssh_exec;
1597 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1598
1599 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001600 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001601
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001602 my $found = 0;
1603
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001604 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001605 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001606 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001607 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001608 last;
1609 } elsif (/^\s*title\s/) {
1610 $grub_number++;
1611 }
1612 }
1613 close(IN);
1614
Steven Rostedta75fece2010-11-02 14:58:27 -04001615 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001616 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001617 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001618 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001619 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001620}
1621
Steven Rostedt2545eb62010-11-02 15:01:32 -04001622sub wait_for_input
1623{
1624 my ($fp, $time) = @_;
1625 my $rin;
1626 my $ready;
1627 my $line;
1628 my $ch;
1629
1630 if (!defined($time)) {
1631 $time = $timeout;
1632 }
1633
1634 $rin = '';
1635 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001636 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001637
1638 $line = "";
1639
1640 # try to read one char at a time
1641 while (sysread $fp, $ch, 1) {
1642 $line .= $ch;
1643 last if ($ch eq "\n");
1644 }
1645
1646 if (!length($line)) {
1647 return undef;
1648 }
1649
1650 return $line;
1651}
1652
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001653sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001654 if (defined($switch_to_test)) {
1655 run_command $switch_to_test;
1656 }
1657
Steven Rostedta75fece2010-11-02 14:58:27 -04001658 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001659 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001660 } elsif ($reboot_type eq "grub2") {
1661 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001662 } elsif ($reboot_type eq "syslinux") {
1663 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001664 } elsif (defined $reboot_script) {
1665 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001666 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001667 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001668}
1669
Steven Rostedta57419b2010-11-02 15:13:54 -04001670sub get_sha1 {
1671 my ($commit) = @_;
1672
1673 doprint "git rev-list --max-count=1 $commit ... ";
1674 my $sha1 = `git rev-list --max-count=1 $commit`;
1675 my $ret = $?;
1676
1677 logit $sha1;
1678
1679 if ($ret) {
1680 doprint "FAILED\n";
1681 dodie "Failed to get git $commit";
1682 }
1683
1684 print "SUCCESS\n";
1685
1686 chomp $sha1;
1687
1688 return $sha1;
1689}
1690
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001691sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001692 my $booted = 0;
1693 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001694 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001695 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001696 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001697
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001698 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001699
1700 my $line;
1701 my $full_line = "";
1702
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001703 open(DMESG, "> $dmesg") or
1704 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001705
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001706 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001707
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001708 my $success_start;
1709 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001710 my $monitor_start = time;
1711 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001712 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001713
Steven Rostedt2d01b262011-03-08 09:47:54 -05001714 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001715
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001716 if ($bug && defined($stop_after_failure) &&
1717 $stop_after_failure >= 0) {
1718 my $time = $stop_after_failure - (time - $failure_start);
1719 $line = wait_for_input($monitor_fp, $time);
1720 if (!defined($line)) {
1721 doprint "bug timed out after $booted_timeout seconds\n";
1722 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1723 last;
1724 }
1725 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001726 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001727 if (!defined($line)) {
1728 my $s = $booted_timeout == 1 ? "" : "s";
1729 doprint "Successful boot found: break after $booted_timeout second$s\n";
1730 last;
1731 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001732 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001733 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001734 if (!defined($line)) {
1735 my $s = $timeout == 1 ? "" : "s";
1736 doprint "Timed out after $timeout second$s\n";
1737 last;
1738 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001739 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001740
Steven Rostedt2545eb62010-11-02 15:01:32 -04001741 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001742 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001743
1744 # we are not guaranteed to get a full line
1745 $full_line .= $line;
1746
Steven Rostedta75fece2010-11-02 14:58:27 -04001747 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001748 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001749 $success_start = time;
1750 }
1751
1752 if ($booted && defined($stop_after_success) &&
1753 $stop_after_success >= 0) {
1754 my $now = time;
1755 if ($now - $success_start >= $stop_after_success) {
1756 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1757 last;
1758 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001759 }
1760
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001761 if ($full_line =~ /\[ backtrace testing \]/) {
1762 $skip_call_trace = 1;
1763 }
1764
Steven Rostedt2545eb62010-11-02 15:01:32 -04001765 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001766 if (!$bug && !$skip_call_trace) {
1767 if ($ignore_errors) {
1768 $bug_ignored = 1;
1769 } else {
1770 $bug = 1;
1771 $failure_start = time;
1772 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001773 }
1774 }
1775
1776 if ($bug && defined($stop_after_failure) &&
1777 $stop_after_failure >= 0) {
1778 my $now = time;
1779 if ($now - $failure_start >= $stop_after_failure) {
1780 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1781 last;
1782 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001783 }
1784
1785 if ($full_line =~ /\[ end of backtrace testing \]/) {
1786 $skip_call_trace = 0;
1787 }
1788
1789 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001790 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001791 $bug = 1;
1792 }
1793
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001794 # Detect triple faults by testing the banner
1795 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1796 if ($1 eq $version) {
1797 $version_found = 1;
1798 } elsif ($version_found && $detect_triplefault) {
1799 # We already booted into the kernel we are testing,
1800 # but now we booted into another kernel?
1801 # Consider this a triple fault.
1802 doprint "Aleady booted in Linux kernel $version, but now\n";
1803 doprint "we booted into Linux kernel $1.\n";
1804 doprint "Assuming that this is a triple fault.\n";
1805 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1806 last;
1807 }
1808 }
1809
Steven Rostedt2545eb62010-11-02 15:01:32 -04001810 if ($line =~ /\n/) {
1811 $full_line = "";
1812 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001813
1814 if ($stop_test_after > 0 && !$booted && !$bug) {
1815 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001816 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001817 $done = 1;
1818 }
1819 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001820 }
1821
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001822 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001823
Steven Rostedt2545eb62010-11-02 15:01:32 -04001824 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001825 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001826 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001827 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001828
Steven Rostedta75fece2010-11-02 14:58:27 -04001829 if (!$booted) {
1830 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001831 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001832 }
1833
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001834 if ($bug_ignored) {
1835 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1836 }
1837
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001838 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001839}
1840
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001841sub eval_kernel_version {
1842 my ($option) = @_;
1843
1844 $option =~ s/\$KERNEL_VERSION/$version/g;
1845
1846 return $option;
1847}
1848
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001849sub do_post_install {
1850
1851 return if (!defined($post_install));
1852
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001853 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001854 run_command "$cp_post_install" or
1855 dodie "Failed to run post install";
1856}
1857
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001858# Sometimes the reboot fails, and will hang. We try to ssh to the box
1859# and if we fail, we force another reboot, that should powercycle it.
1860sub test_booted {
1861 if (!run_ssh "echo testing connection") {
1862 reboot $sleep_time;
1863 }
1864}
1865
Steven Rostedt2545eb62010-11-02 15:01:32 -04001866sub install {
1867
Steven Rostedte0a87422011-09-30 17:50:48 -04001868 return if ($no_install);
1869
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001870 if (defined($pre_install)) {
1871 my $cp_pre_install = eval_kernel_version $pre_install;
1872 run_command "$cp_pre_install" or
1873 dodie "Failed to run pre install";
1874 }
1875
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001876 my $cp_target = eval_kernel_version $target_image;
1877
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001878 test_booted;
1879
Steven Rostedt02ad2612012-03-21 08:21:24 -04001880 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001881 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001882
1883 my $install_mods = 0;
1884
1885 # should we process modules?
1886 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001887 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001888 while (<IN>) {
1889 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001890 if (defined($1)) {
1891 $install_mods = 1;
1892 last;
1893 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001894 }
1895 }
1896 close(IN);
1897
1898 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001899 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001900 doprint "No modules needed\n";
1901 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001902 }
1903
Steven Rostedt627977d2012-03-21 08:16:15 -04001904 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001905 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001906
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001907 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001908 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001909
Steven Rostedte48c5292010-11-02 14:35:37 -04001910 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001911 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001912
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001913 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001914 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001915 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001916
Steven Rostedt02ad2612012-03-21 08:21:24 -04001917 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001918 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001919
Steven Rostedta75fece2010-11-02 14:58:27 -04001920 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001921
Steven Rostedte7b13442011-06-14 20:44:36 -04001922 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001923 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001924
Steven Rostedte48c5292010-11-02 14:35:37 -04001925 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001926
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001927 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001928}
1929
Steven Rostedtddf607e2011-06-14 20:49:13 -04001930sub get_version {
1931 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001932 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001933 doprint "$make kernelrelease ... ";
1934 $version = `$make kernelrelease | tail -1`;
1935 chomp($version);
1936 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001937 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001938}
1939
1940sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001941 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001942
1943 # Install bisects, don't need console
1944 if (defined $console) {
1945 start_monitor;
1946 wait_for_monitor 5;
1947 end_monitor;
1948 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001949
Steven Rostedtddf607e2011-06-14 20:49:13 -04001950 get_grub_index;
1951 get_version;
1952 install;
1953
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001954 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001955 return monitor;
1956}
1957
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001958my $check_build_re = ".*:.*(warning|error|Error):.*";
1959my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1960
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05001961sub process_warning_line {
1962 my ($line) = @_;
1963
1964 chomp $line;
1965
1966 # for distcc heterogeneous systems, some compilers
1967 # do things differently causing warning lines
1968 # to be slightly different. This makes an attempt
1969 # to fixe those issues.
1970
1971 # chop off the index into the line
1972 # using distcc, some compilers give different indexes
1973 # depending on white space
1974 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
1975
1976 # Some compilers use UTF-8 extended for quotes and some don't.
1977 $line =~ s/$utf8_quote/'/g;
1978
1979 return $line;
1980}
1981
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001982# Read buildlog and check against warnings file for any
1983# new warnings.
1984#
1985# Returns 1 if OK
1986# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001987sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001988 return 1 if (!defined $warnings_file);
1989
1990 my %warnings_list;
1991
1992 # Failed builds should not reboot the target
1993 my $save_no_reboot = $no_reboot;
1994 $no_reboot = 1;
1995
1996 if (-f $warnings_file) {
1997 open(IN, $warnings_file) or
1998 dodie "Error opening $warnings_file";
1999
2000 while (<IN>) {
2001 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002002 my $warning = process_warning_line $_;
2003
2004 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002005 }
2006 }
2007 close(IN);
2008 }
2009
2010 # If warnings file didn't exist, and WARNINGS_FILE exist,
2011 # then we fail on any warning!
2012
2013 open(IN, $buildlog) or dodie "Can't open $buildlog";
2014 while (<IN>) {
2015 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002016 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002017
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002018 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002019 fail "New warning found (not in $warnings_file)\n$_\n";
2020 $no_reboot = $save_no_reboot;
2021 return 0;
2022 }
2023 }
2024 }
2025 $no_reboot = $save_no_reboot;
2026 close(IN);
2027}
2028
2029sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002030 my ($patch) = @_;
2031
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002032 my @files = `git show $patch | diffstat -l`;
2033
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002034 foreach my $file (@files) {
2035 chomp $file;
2036 }
2037
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002038 open(IN, "git show $patch |") or
2039 dodie "failed to show $patch";
2040 while (<IN>) {
2041 if (m,^--- a/(.*),) {
2042 chomp $1;
2043 $files[$#files] = $1;
2044 }
2045 }
2046 close(IN);
2047
2048 open(IN, $buildlog) or dodie "Can't open $buildlog";
2049 while (<IN>) {
2050 if (/^\s*(.*?):.*(warning|error)/) {
2051 my $err = $1;
2052 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002053 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002054 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002055 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002056 }
2057 }
2058 }
2059 }
2060 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002061
2062 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002063}
2064
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002065sub apply_min_config {
2066 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002067
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002068 # Read the config file and remove anything that
2069 # is in the force_config hash (from minconfig and others)
2070 # then add the force config back.
2071
2072 doprint "Applying minimum configurations into $output_config.new\n";
2073
2074 open (OUT, ">$outconfig") or
2075 dodie "Can't create $outconfig";
2076
2077 if (-f $output_config) {
2078 open (IN, $output_config) or
2079 dodie "Failed to open $output_config";
2080 while (<IN>) {
2081 if (/^(# )?(CONFIG_[^\s=]*)/) {
2082 next if (defined($force_config{$2}));
2083 }
2084 print OUT;
2085 }
2086 close IN;
2087 }
2088 foreach my $config (keys %force_config) {
2089 print OUT "$force_config{$config}\n";
2090 }
2091 close OUT;
2092
2093 run_command "mv $outconfig $output_config";
2094}
2095
2096sub make_oldconfig {
2097
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002098 my @force_list = keys %force_config;
2099
2100 if ($#force_list >= 0) {
2101 apply_min_config;
2102 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002103
Adam Leefb16d892012-09-01 01:05:17 +08002104 if (!run_command "$make olddefconfig") {
2105 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002106 # try oldnoconfig
2107 doprint "olddefconfig failed, trying make oldnoconfig\n";
2108 if (!run_command "$make oldnoconfig") {
2109 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2110 # try a yes '' | oldconfig
2111 run_command "yes '' | $make oldconfig" or
2112 dodie "failed make config oldconfig";
2113 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002114 }
2115}
2116
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002117# read a config file and use this to force new configs.
2118sub load_force_config {
2119 my ($config) = @_;
2120
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002121 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002122 open(IN, $config) or
2123 dodie "failed to read $config";
2124 while (<IN>) {
2125 chomp;
2126 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2127 $force_config{$1} = $_;
2128 } elsif (/^# (CONFIG_\S*) is not set/) {
2129 $force_config{$1} = $_;
2130 }
2131 }
2132 close IN;
2133}
2134
Steven Rostedt2545eb62010-11-02 15:01:32 -04002135sub build {
2136 my ($type) = @_;
2137
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002138 unlink $buildlog;
2139
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002140 # Failed builds should not reboot the target
2141 my $save_no_reboot = $no_reboot;
2142 $no_reboot = 1;
2143
Steven Rostedt683a3e62012-05-18 13:34:35 -04002144 # Calculate a new version from here.
2145 $have_version = 0;
2146
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002147 if (defined($pre_build)) {
2148 my $ret = run_command $pre_build;
2149 if (!$ret && defined($pre_build_die) &&
2150 $pre_build_die) {
2151 dodie "failed to pre_build\n";
2152 }
2153 }
2154
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002155 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002156 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002157 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002158
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002159 $type = "oldconfig";
2160 }
2161
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002162 # old config can ask questions
2163 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002164 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002165
2166 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002167 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002168
Andrew Jones13488232011-08-12 15:32:04 +02002169 if (!$noclean) {
2170 run_command "mv $output_config $outputdir/config_temp" or
2171 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002172
Andrew Jones13488232011-08-12 15:32:04 +02002173 run_command "$make mrproper" or dodie "make mrproper";
2174
2175 run_command "mv $outputdir/config_temp $output_config" or
2176 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002177 }
2178
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002179 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002180 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002181 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002182 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002183 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002184
2185 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002186 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2187 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002188 close(OUT);
2189
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002190 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002191 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002192 }
2193
Adam Leefb16d892012-09-01 01:05:17 +08002194 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002195 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002196 dodie "failed make config";
2197 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002198 # Run old config regardless, to enforce min configurations
2199 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002200
Steven Rostedta75fece2010-11-02 14:58:27 -04002201 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002202 my $build_ret = run_command "$make $build_options";
2203 undef $redirect;
2204
2205 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002206 # Because a post build may change the kernel version
2207 # do it now.
2208 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002209 my $ret = run_command $post_build;
2210 if (!$ret && defined($post_build_die) &&
2211 $post_build_die) {
2212 dodie "failed to post_build\n";
2213 }
2214 }
2215
2216 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002217 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002218 if ($in_bisect) {
2219 $no_reboot = $save_no_reboot;
2220 return 0;
2221 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002222 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002223 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002224
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002225 $no_reboot = $save_no_reboot;
2226
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002227 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002228}
2229
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002230sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002231 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002232 if (defined($poweroff_after_halt)) {
2233 sleep $poweroff_after_halt;
2234 run_command "$power_off";
2235 }
2236 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002237 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002238 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002239 }
2240}
2241
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002242sub success {
2243 my ($i) = @_;
2244
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002245 if (defined($post_test)) {
2246 run_command $post_test;
2247 }
2248
Steven Rostedte48c5292010-11-02 14:35:37 -04002249 $successes++;
2250
Steven Rostedt9064af52011-06-13 10:38:48 -04002251 my $name = "";
2252
2253 if (defined($test_name)) {
2254 $name = " ($test_name)";
2255 }
2256
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002257 doprint "\n\n*******************************************\n";
2258 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002259 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002260 doprint "*******************************************\n";
2261 doprint "*******************************************\n";
2262
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302263 if (defined($store_successes)) {
2264 save_logs "success", $store_successes;
2265 }
2266
Steven Rostedt576f6272010-11-02 14:58:38 -04002267 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002268 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002269 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002270 }
2271}
2272
Steven Rostedtc960bb92011-03-08 09:22:39 -05002273sub answer_bisect {
2274 for (;;) {
2275 doprint "Pass or fail? [p/f]";
2276 my $ans = <STDIN>;
2277 chomp $ans;
2278 if ($ans eq "p" || $ans eq "P") {
2279 return 1;
2280 } elsif ($ans eq "f" || $ans eq "F") {
2281 return 0;
2282 } else {
2283 print "Please answer 'P' or 'F'\n";
2284 }
2285 }
2286}
2287
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002288sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002289 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002290
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002291 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002292 $reboot_on_error = 0;
2293 $poweroff_on_error = 0;
2294 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002295
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302296 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002297 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302298 undef $redirect;
2299
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002300 exit $failed;
2301}
2302
2303my $child_done;
2304
2305sub child_finished {
2306 $child_done = 1;
2307}
2308
2309sub do_run_test {
2310 my $child_pid;
2311 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002312 my $line;
2313 my $full_line;
2314 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002315 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002316
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002317 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002318
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002319 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002320
2321 $child_done = 0;
2322
2323 $SIG{CHLD} = qw(child_finished);
2324
2325 $child_pid = fork;
2326
2327 child_run_test if (!$child_pid);
2328
2329 $full_line = "";
2330
2331 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002332 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002333 if (defined($line)) {
2334
2335 # we are not guaranteed to get a full line
2336 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002337 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002338
2339 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002340 if ($ignore_errors) {
2341 $bug_ignored = 1;
2342 } else {
2343 $bug = 1;
2344 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002345 }
2346
2347 if ($full_line =~ /Kernel panic -/) {
2348 $bug = 1;
2349 }
2350
2351 if ($line =~ /\n/) {
2352 $full_line = "";
2353 }
2354 }
2355 } while (!$child_done && !$bug);
2356
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002357 if (!$bug && $bug_ignored) {
2358 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2359 }
2360
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002361 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002362 my $failure_start = time;
2363 my $now;
2364 do {
2365 $line = wait_for_input($monitor_fp, 1);
2366 if (defined($line)) {
2367 doprint $line;
2368 }
2369 $now = time;
2370 if ($now - $failure_start >= $stop_after_failure) {
2371 last;
2372 }
2373 } while (defined($line));
2374
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002375 doprint "Detected kernel crash!\n";
2376 # kill the child with extreme prejudice
2377 kill 9, $child_pid;
2378 }
2379
2380 waitpid $child_pid, 0;
2381 $child_exit = $?;
2382
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002383 if (!$bug && $in_bisect) {
2384 if (defined($bisect_ret_good)) {
2385 if ($child_exit == $bisect_ret_good) {
2386 return 1;
2387 }
2388 }
2389 if (defined($bisect_ret_skip)) {
2390 if ($child_exit == $bisect_ret_skip) {
2391 return -1;
2392 }
2393 }
2394 if (defined($bisect_ret_abort)) {
2395 if ($child_exit == $bisect_ret_abort) {
2396 fail "test abort" and return -2;
2397 }
2398 }
2399 if (defined($bisect_ret_bad)) {
2400 if ($child_exit == $bisect_ret_skip) {
2401 return 0;
2402 }
2403 }
2404 if (defined($bisect_ret_default)) {
2405 if ($bisect_ret_default eq "good") {
2406 return 1;
2407 } elsif ($bisect_ret_default eq "bad") {
2408 return 0;
2409 } elsif ($bisect_ret_default eq "skip") {
2410 return -1;
2411 } elsif ($bisect_ret_default eq "abort") {
2412 return -2;
2413 } else {
2414 fail "unknown default action: $bisect_ret_default"
2415 and return -2;
2416 }
2417 }
2418 }
2419
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002420 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002421 return 0 if $in_bisect;
2422 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002423 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002424 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002425}
2426
Steven Rostedta75fece2010-11-02 14:58:27 -04002427sub run_git_bisect {
2428 my ($command) = @_;
2429
2430 doprint "$command ... ";
2431
2432 my $output = `$command 2>&1`;
2433 my $ret = $?;
2434
2435 logit $output;
2436
2437 if ($ret) {
2438 doprint "FAILED\n";
2439 dodie "Failed to git bisect";
2440 }
2441
2442 doprint "SUCCESS\n";
2443 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2444 doprint "$1 [$2]\n";
2445 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002446 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002447 doprint "Found bad commit... $1\n";
2448 return 0;
2449 } else {
2450 # we already logged it, just print it now.
2451 print $output;
2452 }
2453
2454 return 1;
2455}
2456
Steven Rostedtc23dca72011-03-08 09:26:31 -05002457sub bisect_reboot {
2458 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002459 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002460}
2461
2462# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002463sub run_bisect_test {
2464 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002465
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002466 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002467 my $result;
2468 my $output;
2469 my $ret;
2470
Steven Rostedt0a05c762010-11-08 11:14:10 -05002471 $in_bisect = 1;
2472
2473 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002474
2475 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002476 if ($failed && $bisect_skip) {
2477 $in_bisect = 0;
2478 return -1;
2479 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002480 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002481
2482 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002483 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002484
2485 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002486 if ($failed && $bisect_skip) {
2487 end_monitor;
2488 bisect_reboot;
2489 $in_bisect = 0;
2490 return -1;
2491 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002492 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002493
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002494 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002495 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002496 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002497 }
2498
2499 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002500 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002501 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002502 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002503 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002504
2505 # reboot the box to a kernel we can ssh to
2506 if ($type ne "build") {
2507 bisect_reboot;
2508 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002509 $in_bisect = 0;
2510
2511 return $result;
2512}
2513
2514sub run_bisect {
2515 my ($type) = @_;
2516 my $buildtype = "oldconfig";
2517
2518 # We should have a minconfig to use?
2519 if (defined($minconfig)) {
2520 $buildtype = "useconfig:$minconfig";
2521 }
2522
2523 my $ret = run_bisect_test $type, $buildtype;
2524
Steven Rostedtc960bb92011-03-08 09:22:39 -05002525 if ($bisect_manual) {
2526 $ret = answer_bisect;
2527 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002528
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002529 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002530 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002531 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002532 }
2533
Steven Rostedtc23dca72011-03-08 09:26:31 -05002534 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002535 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002536 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002537 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002538 } elsif ($bisect_skip) {
2539 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2540 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002541 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002542}
2543
Steven Rostedtdad98752011-11-22 20:48:57 -05002544sub update_bisect_replay {
2545 my $tmp_log = "$tmpdir/ktest_bisect_log";
2546 run_command "git bisect log > $tmp_log" or
2547 die "can't create bisect log";
2548 return $tmp_log;
2549}
2550
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002551sub bisect {
2552 my ($i) = @_;
2553
2554 my $result;
2555
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002556 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2557 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2558 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002559
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002560 my $good = $bisect_good;
2561 my $bad = $bisect_bad;
2562 my $type = $bisect_type;
2563 my $start = $bisect_start;
2564 my $replay = $bisect_replay;
2565 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002566
2567 if (defined($start_files)) {
2568 $start_files = " -- " . $start_files;
2569 } else {
2570 $start_files = "";
2571 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002572
Steven Rostedta57419b2010-11-02 15:13:54 -04002573 # convert to true sha1's
2574 $good = get_sha1($good);
2575 $bad = get_sha1($bad);
2576
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002577 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002578 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2579 $reverse_bisect = 1;
2580 } else {
2581 $reverse_bisect = 0;
2582 }
2583
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002584 # Can't have a test without having a test to run
2585 if ($type eq "test" && !defined($run_test)) {
2586 $type = "boot";
2587 }
2588
Steven Rostedtdad98752011-11-22 20:48:57 -05002589 # Check if a bisect was running
2590 my $bisect_start_file = "$builddir/.git/BISECT_START";
2591
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002592 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002593 my $do_check = defined($check) && $check ne "0";
2594
2595 if ( -f $bisect_start_file ) {
2596 print "Bisect in progress found\n";
2597 if ($do_check) {
2598 print " If you say yes, then no checks of good or bad will be done\n";
2599 }
2600 if (defined($replay)) {
2601 print "** BISECT_REPLAY is defined in config file **";
2602 print " Ignore config option and perform new git bisect log?\n";
2603 if (read_ync " (yes, no, or cancel) ") {
2604 $replay = update_bisect_replay;
2605 $do_check = 0;
2606 }
2607 } elsif (read_yn "read git log and continue?") {
2608 $replay = update_bisect_replay;
2609 $do_check = 0;
2610 }
2611 }
2612
2613 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002614
2615 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002616 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002617
2618 if ($check ne "good") {
2619 doprint "TESTING BISECT BAD [$bad]\n";
2620 run_command "git checkout $bad" or
2621 die "Failed to checkout $bad";
2622
2623 $result = run_bisect $type;
2624
2625 if ($result ne "bad") {
2626 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2627 }
2628 }
2629
2630 if ($check ne "bad") {
2631 doprint "TESTING BISECT GOOD [$good]\n";
2632 run_command "git checkout $good" or
2633 die "Failed to checkout $good";
2634
2635 $result = run_bisect $type;
2636
2637 if ($result ne "good") {
2638 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2639 }
2640 }
2641
2642 # checkout where we started
2643 run_command "git checkout $head" or
2644 die "Failed to checkout $head";
2645 }
2646
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002647 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002648 dodie "could not start bisect";
2649
2650 run_command "git bisect good $good" or
2651 dodie "could not set bisect good to $good";
2652
2653 run_git_bisect "git bisect bad $bad" or
2654 dodie "could not set bisect bad to $bad";
2655
2656 if (defined($replay)) {
2657 run_command "git bisect replay $replay" or
2658 dodie "failed to run replay";
2659 }
2660
2661 if (defined($start)) {
2662 run_command "git checkout $start" or
2663 dodie "failed to checkout $start";
2664 }
2665
2666 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002667 do {
2668 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002669 $test = run_git_bisect "git bisect $result";
2670 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002671
2672 run_command "git bisect log" or
2673 dodie "could not capture git bisect log";
2674
2675 run_command "git bisect reset" or
2676 dodie "could not reset git bisect";
2677
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002678 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002679
Steven Rostedt0a05c762010-11-08 11:14:10 -05002680 success $i;
2681}
2682
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002683# config_ignore holds the configs that were set (or unset) for
2684# a good config and we will ignore these configs for the rest
2685# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002686my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002687
2688# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002689my %config_set;
2690
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002691# config_off holds the set of configs that the bad config had disabled.
2692# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002693# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002694my %config_off;
2695
2696# config_off_tmp holds a set of configs to turn off for now
2697my @config_off_tmp;
2698
2699# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002700my %config_list;
2701my %null_config;
2702
2703my %dependency;
2704
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002705sub assign_configs {
2706 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002707
2708 open (IN, $config)
2709 or dodie "Failed to read $config";
2710
2711 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002712 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002713 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002714 }
2715 }
2716
2717 close(IN);
2718}
2719
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002720sub process_config_ignore {
2721 my ($config) = @_;
2722
2723 assign_configs \%config_ignore, $config;
2724}
2725
Steven Rostedt0a05c762010-11-08 11:14:10 -05002726sub read_current_config {
2727 my ($config_ref) = @_;
2728
2729 %{$config_ref} = ();
2730 undef %{$config_ref};
2731
2732 my @key = keys %{$config_ref};
2733 if ($#key >= 0) {
2734 print "did not delete!\n";
2735 exit;
2736 }
2737 open (IN, "$output_config");
2738
2739 while (<IN>) {
2740 if (/^(CONFIG\S+)=(.*)/) {
2741 ${$config_ref}{$1} = $2;
2742 }
2743 }
2744 close(IN);
2745}
2746
2747sub get_dependencies {
2748 my ($config) = @_;
2749
2750 my $arr = $dependency{$config};
2751 if (!defined($arr)) {
2752 return ();
2753 }
2754
2755 my @deps = @{$arr};
2756
2757 foreach my $dep (@{$arr}) {
2758 print "ADD DEP $dep\n";
2759 @deps = (@deps, get_dependencies $dep);
2760 }
2761
2762 return @deps;
2763}
2764
2765sub create_config {
2766 my @configs = @_;
2767
2768 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2769
2770 foreach my $config (@configs) {
2771 print OUT "$config_set{$config}\n";
2772 my @deps = get_dependencies $config;
2773 foreach my $dep (@deps) {
2774 print OUT "$config_set{$dep}\n";
2775 }
2776 }
2777
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002778 # turn off configs to keep off
2779 foreach my $config (keys %config_off) {
2780 print OUT "# $config is not set\n";
2781 }
2782
2783 # turn off configs that should be off for now
2784 foreach my $config (@config_off_tmp) {
2785 print OUT "# $config is not set\n";
2786 }
2787
Steven Rostedt0a05c762010-11-08 11:14:10 -05002788 foreach my $config (keys %config_ignore) {
2789 print OUT "$config_ignore{$config}\n";
2790 }
2791 close(OUT);
2792
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002793 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002794}
2795
2796sub compare_configs {
2797 my (%a, %b) = @_;
2798
2799 foreach my $item (keys %a) {
2800 if (!defined($b{$item})) {
2801 print "diff $item\n";
2802 return 1;
2803 }
2804 delete $b{$item};
2805 }
2806
2807 my @keys = keys %b;
2808 if ($#keys) {
2809 print "diff2 $keys[0]\n";
2810 }
2811 return -1 if ($#keys >= 0);
2812
2813 return 0;
2814}
2815
2816sub run_config_bisect_test {
2817 my ($type) = @_;
2818
2819 return run_bisect_test $type, "oldconfig";
2820}
2821
2822sub process_passed {
2823 my (%configs) = @_;
2824
2825 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2826 # Passed! All these configs are part of a good compile.
2827 # Add them to the min options.
2828 foreach my $config (keys %configs) {
2829 if (defined($config_list{$config})) {
2830 doprint " removing $config\n";
2831 $config_ignore{$config} = $config_list{$config};
2832 delete $config_list{$config};
2833 }
2834 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002835 doprint "config copied to $outputdir/config_good\n";
2836 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002837}
2838
2839sub process_failed {
2840 my ($config) = @_;
2841
2842 doprint "\n\n***************************************\n";
2843 doprint "Found bad config: $config\n";
2844 doprint "***************************************\n\n";
2845}
2846
2847sub run_config_bisect {
2848
2849 my @start_list = keys %config_list;
2850
2851 if ($#start_list < 0) {
2852 doprint "No more configs to test!!!\n";
2853 return -1;
2854 }
2855
2856 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002857 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002858 my $ret;
2859 my %current_config;
2860
2861 my $count = $#start_list + 1;
2862 doprint " $count configs to test\n";
2863
2864 my $half = int($#start_list / 2);
2865
2866 do {
2867 my @tophalf = @start_list[0 .. $half];
2868
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002869 # keep the bottom half off
2870 if ($half < $#start_list) {
2871 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2872 } else {
2873 @config_off_tmp = ();
2874 }
2875
Steven Rostedt0a05c762010-11-08 11:14:10 -05002876 create_config @tophalf;
2877 read_current_config \%current_config;
2878
2879 $count = $#tophalf + 1;
2880 doprint "Testing $count configs\n";
2881 my $found = 0;
2882 # make sure we test something
2883 foreach my $config (@tophalf) {
2884 if (defined($current_config{$config})) {
2885 logit " $config\n";
2886 $found = 1;
2887 }
2888 }
2889 if (!$found) {
2890 # try the other half
2891 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002892
2893 # keep the top half off
2894 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002895 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002896
Steven Rostedt0a05c762010-11-08 11:14:10 -05002897 create_config @tophalf;
2898 read_current_config \%current_config;
2899 foreach my $config (@tophalf) {
2900 if (defined($current_config{$config})) {
2901 logit " $config\n";
2902 $found = 1;
2903 }
2904 }
2905 if (!$found) {
2906 doprint "Failed: Can't make new config with current configs\n";
2907 foreach my $config (@start_list) {
2908 doprint " CONFIG: $config\n";
2909 }
2910 return -1;
2911 }
2912 $count = $#tophalf + 1;
2913 doprint "Testing $count configs\n";
2914 }
2915
2916 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002917 if ($bisect_manual) {
2918 $ret = answer_bisect;
2919 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002920 if ($ret) {
2921 process_passed %current_config;
2922 return 0;
2923 }
2924
2925 doprint "This config had a failure.\n";
2926 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002927 doprint "config copied to $outputdir/config_bad\n";
2928 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002929
2930 # A config exists in this group that was bad.
2931 foreach my $config (keys %config_list) {
2932 if (!defined($current_config{$config})) {
2933 doprint " removing $config\n";
2934 delete $config_list{$config};
2935 }
2936 }
2937
2938 @start_list = @tophalf;
2939
2940 if ($#start_list == 0) {
2941 process_failed $start_list[0];
2942 return 1;
2943 }
2944
2945 # remove half the configs we are looking at and see if
2946 # they are good.
2947 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002948 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002949
Steven Rostedtc960bb92011-03-08 09:22:39 -05002950 # we found a single config, try it again unless we are running manually
2951
2952 if ($bisect_manual) {
2953 process_failed $start_list[0];
2954 return 1;
2955 }
2956
Steven Rostedt0a05c762010-11-08 11:14:10 -05002957 my @tophalf = @start_list[0 .. 0];
2958
2959 $ret = run_config_bisect_test $type;
2960 if ($ret) {
2961 process_passed %current_config;
2962 return 0;
2963 }
2964
2965 process_failed $start_list[0];
2966 return 1;
2967}
2968
2969sub config_bisect {
2970 my ($i) = @_;
2971
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002972 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002973
2974 my $tmpconfig = "$tmpdir/use_config";
2975
Steven Rostedt30f75da2011-06-13 10:35:35 -04002976 if (defined($config_bisect_good)) {
2977 process_config_ignore $config_bisect_good;
2978 }
2979
Steven Rostedt0a05c762010-11-08 11:14:10 -05002980 # Make the file with the bad config and the min config
2981 if (defined($minconfig)) {
2982 # read the min config for things to ignore
2983 run_command "cp $minconfig $tmpconfig" or
2984 dodie "failed to copy $minconfig to $tmpconfig";
2985 } else {
2986 unlink $tmpconfig;
2987 }
2988
Steven Rostedt0a05c762010-11-08 11:14:10 -05002989 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002990 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002991 process_config_ignore $tmpconfig;
2992 }
2993
2994 # now process the start config
2995 run_command "cp $start_config $output_config" or
2996 dodie "failed to copy $start_config to $output_config";
2997
2998 # read directly what we want to check
2999 my %config_check;
3000 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09003001 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05003002
3003 while (<IN>) {
3004 if (/^((CONFIG\S*)=.*)/) {
3005 $config_check{$2} = $1;
3006 }
3007 }
3008 close(IN);
3009
Steven Rostedt250bae82011-07-15 22:05:59 -04003010 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003011 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003012
3013 # check to see what we lost (or gained)
3014 open (IN, $output_config)
3015 or dodie "Failed to read $start_config";
3016
3017 my %removed_configs;
3018 my %added_configs;
3019
3020 while (<IN>) {
3021 if (/^((CONFIG\S*)=.*)/) {
3022 # save off all options
3023 $config_set{$2} = $1;
3024 if (defined($config_check{$2})) {
3025 if (defined($config_ignore{$2})) {
3026 $removed_configs{$2} = $1;
3027 } else {
3028 $config_list{$2} = $1;
3029 }
3030 } elsif (!defined($config_ignore{$2})) {
3031 $added_configs{$2} = $1;
3032 $config_list{$2} = $1;
3033 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003034 } elsif (/^# ((CONFIG\S*).*)/) {
3035 # Keep these configs disabled
3036 $config_set{$2} = $1;
3037 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003038 }
3039 }
3040 close(IN);
3041
3042 my @confs = keys %removed_configs;
3043 if ($#confs >= 0) {
3044 doprint "Configs overridden by default configs and removed from check:\n";
3045 foreach my $config (@confs) {
3046 doprint " $config\n";
3047 }
3048 }
3049 @confs = keys %added_configs;
3050 if ($#confs >= 0) {
3051 doprint "Configs appearing in make oldconfig and added:\n";
3052 foreach my $config (@confs) {
3053 doprint " $config\n";
3054 }
3055 }
3056
3057 my %config_test;
3058 my $once = 0;
3059
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003060 @config_off_tmp = ();
3061
Steven Rostedt0a05c762010-11-08 11:14:10 -05003062 # Sometimes kconfig does weird things. We must make sure
3063 # that the config we autocreate has everything we need
3064 # to test, otherwise we may miss testing configs, or
3065 # may not be able to create a new config.
3066 # Here we create a config with everything set.
3067 create_config (keys %config_list);
3068 read_current_config \%config_test;
3069 foreach my $config (keys %config_list) {
3070 if (!defined($config_test{$config})) {
3071 if (!$once) {
3072 $once = 1;
3073 doprint "Configs not produced by kconfig (will not be checked):\n";
3074 }
3075 doprint " $config\n";
3076 delete $config_list{$config};
3077 }
3078 }
3079 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04003080
3081 if (defined($config_bisect_check) && $config_bisect_check) {
3082 doprint " Checking to make sure bad config with min config fails\n";
3083 create_config keys %config_list;
3084 $ret = run_config_bisect_test $config_bisect_type;
3085 if ($ret) {
3086 doprint " FAILED! Bad config with min config boots fine\n";
3087 return -1;
3088 }
3089 doprint " Bad config with min config fails as expected\n";
3090 }
3091
Steven Rostedt0a05c762010-11-08 11:14:10 -05003092 do {
3093 $ret = run_config_bisect;
3094 } while (!$ret);
3095
3096 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003097
3098 success $i;
3099}
3100
Steven Rostedt27d934b2011-05-20 09:18:18 -04003101sub patchcheck_reboot {
3102 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003103 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003104}
3105
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003106sub patchcheck {
3107 my ($i) = @_;
3108
3109 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003110 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003111 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003112 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003113
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003114 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003115
3116 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003117 if (defined($patchcheck_end)) {
3118 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003119 }
3120
Steven Rostedta57419b2010-11-02 15:13:54 -04003121 # Get the true sha1's since we can use things like HEAD~3
3122 $start = get_sha1($start);
3123 $end = get_sha1($end);
3124
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003125 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003126
3127 # Can't have a test without having a test to run
3128 if ($type eq "test" && !defined($run_test)) {
3129 $type = "boot";
3130 }
3131
3132 open (IN, "git log --pretty=oneline $end|") or
3133 dodie "could not get git list";
3134
3135 my @list;
3136
3137 while (<IN>) {
3138 chomp;
3139 $list[$#list+1] = $_;
3140 last if (/^$start/);
3141 }
3142 close(IN);
3143
3144 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003145 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003146 }
3147
3148 # go backwards in the list
3149 @list = reverse @list;
3150
3151 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003152 my %ignored_warnings;
3153
3154 if (defined($ignore_warnings)) {
3155 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3156 $ignored_warnings{$sha1} = 1;
3157 }
3158 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003159
3160 $in_patchcheck = 1;
3161 foreach my $item (@list) {
3162 my $sha1 = $item;
3163 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3164
3165 doprint "\nProcessing commit $item\n\n";
3166
3167 run_command "git checkout $sha1" or
3168 die "Failed to checkout $sha1";
3169
3170 # only clean on the first and last patch
3171 if ($item eq $list[0] ||
3172 $item eq $list[$#list]) {
3173 $noclean = $save_clean;
3174 } else {
3175 $noclean = 1;
3176 }
3177
3178 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003179 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003180 } else {
3181 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003182 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003183 }
3184
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003185 # No need to do per patch checking if warnings file exists
3186 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3187 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003188 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003189
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003190 check_buildlog or return 0;
3191
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003192 next if ($type eq "build");
3193
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003194 my $failed = 0;
3195
Steven Rostedtddf607e2011-06-14 20:49:13 -04003196 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003197
3198 if (!$failed && $type ne "boot"){
3199 do_run_test or $failed = 1;
3200 }
3201 end_monitor;
3202 return 0 if ($failed);
3203
Steven Rostedt27d934b2011-05-20 09:18:18 -04003204 patchcheck_reboot;
3205
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003206 }
3207 $in_patchcheck = 0;
3208 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003209
3210 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003211}
3212
Steven Rostedtb9066f62011-07-15 21:25:24 -04003213my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003214my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003215my $iflevel = 0;
3216my @ifdeps;
3217
3218# prevent recursion
3219my %read_kconfigs;
3220
Steven Rostedtac6974c2011-10-04 09:40:17 -04003221sub add_dep {
3222 # $config depends on $dep
3223 my ($config, $dep) = @_;
3224
3225 if (defined($depends{$config})) {
3226 $depends{$config} .= " " . $dep;
3227 } else {
3228 $depends{$config} = $dep;
3229 }
3230
3231 # record the number of configs depending on $dep
3232 if (defined $depcount{$dep}) {
3233 $depcount{$dep}++;
3234 } else {
3235 $depcount{$dep} = 1;
3236 }
3237}
3238
Steven Rostedtb9066f62011-07-15 21:25:24 -04003239# taken from streamline_config.pl
3240sub read_kconfig {
3241 my ($kconfig) = @_;
3242
3243 my $state = "NONE";
3244 my $config;
3245 my @kconfigs;
3246
3247 my $cont = 0;
3248 my $line;
3249
3250
3251 if (! -f $kconfig) {
3252 doprint "file $kconfig does not exist, skipping\n";
3253 return;
3254 }
3255
3256 open(KIN, "$kconfig")
3257 or die "Can't open $kconfig";
3258 while (<KIN>) {
3259 chomp;
3260
3261 # Make sure that lines ending with \ continue
3262 if ($cont) {
3263 $_ = $line . " " . $_;
3264 }
3265
3266 if (s/\\$//) {
3267 $cont = 1;
3268 $line = $_;
3269 next;
3270 }
3271
3272 $cont = 0;
3273
3274 # collect any Kconfig sources
3275 if (/^source\s*"(.*)"/) {
3276 $kconfigs[$#kconfigs+1] = $1;
3277 }
3278
3279 # configs found
3280 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3281 $state = "NEW";
3282 $config = $2;
3283
3284 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003285 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003286 }
3287
3288 # collect the depends for the config
3289 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3290
Steven Rostedtac6974c2011-10-04 09:40:17 -04003291 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003292
3293 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003294 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3295
3296 # selected by depends on config
3297 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003298
3299 # Check for if statements
3300 } elsif (/^if\s+(.*\S)\s*$/) {
3301 my $deps = $1;
3302 # remove beginning and ending non text
3303 $deps =~ s/^[^a-zA-Z0-9_]*//;
3304 $deps =~ s/[^a-zA-Z0-9_]*$//;
3305
3306 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3307
3308 $ifdeps[$iflevel++] = join ':', @deps;
3309
3310 } elsif (/^endif/) {
3311
3312 $iflevel-- if ($iflevel);
3313
3314 # stop on "help"
3315 } elsif (/^\s*help\s*$/) {
3316 $state = "NONE";
3317 }
3318 }
3319 close(KIN);
3320
3321 # read in any configs that were found.
3322 foreach $kconfig (@kconfigs) {
3323 if (!defined($read_kconfigs{$kconfig})) {
3324 $read_kconfigs{$kconfig} = 1;
3325 read_kconfig("$builddir/$kconfig");
3326 }
3327 }
3328}
3329
3330sub read_depends {
3331 # find out which arch this is by the kconfig file
3332 open (IN, $output_config)
3333 or dodie "Failed to read $output_config";
3334 my $arch;
3335 while (<IN>) {
3336 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3337 $arch = $1;
3338 last;
3339 }
3340 }
3341 close IN;
3342
3343 if (!defined($arch)) {
3344 doprint "Could not find arch from config file\n";
3345 doprint "no dependencies used\n";
3346 return;
3347 }
3348
3349 # arch is really the subarch, we need to know
3350 # what directory to look at.
3351 if ($arch eq "i386" || $arch eq "x86_64") {
3352 $arch = "x86";
3353 } elsif ($arch =~ /^tile/) {
3354 $arch = "tile";
3355 }
3356
3357 my $kconfig = "$builddir/arch/$arch/Kconfig";
3358
3359 if (! -f $kconfig && $arch =~ /\d$/) {
3360 my $orig = $arch;
3361 # some subarchs have numbers, truncate them
3362 $arch =~ s/\d*$//;
3363 $kconfig = "$builddir/arch/$arch/Kconfig";
3364 if (! -f $kconfig) {
3365 doprint "No idea what arch dir $orig is for\n";
3366 doprint "no dependencies used\n";
3367 return;
3368 }
3369 }
3370
3371 read_kconfig($kconfig);
3372}
3373
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003374sub read_config_list {
3375 my ($config) = @_;
3376
3377 open (IN, $config)
3378 or dodie "Failed to read $config";
3379
3380 while (<IN>) {
3381 if (/^((CONFIG\S*)=.*)/) {
3382 if (!defined($config_ignore{$2})) {
3383 $config_list{$2} = $1;
3384 }
3385 }
3386 }
3387
3388 close(IN);
3389}
3390
3391sub read_output_config {
3392 my ($config) = @_;
3393
3394 assign_configs \%config_ignore, $config;
3395}
3396
3397sub make_new_config {
3398 my @configs = @_;
3399
3400 open (OUT, ">$output_config")
3401 or dodie "Failed to write $output_config";
3402
3403 foreach my $config (@configs) {
3404 print OUT "$config\n";
3405 }
3406 close OUT;
3407}
3408
Steven Rostedtac6974c2011-10-04 09:40:17 -04003409sub chomp_config {
3410 my ($config) = @_;
3411
3412 $config =~ s/CONFIG_//;
3413
3414 return $config;
3415}
3416
Steven Rostedtb9066f62011-07-15 21:25:24 -04003417sub get_depends {
3418 my ($dep) = @_;
3419
Steven Rostedtac6974c2011-10-04 09:40:17 -04003420 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003421
3422 $dep = $depends{"$kconfig"};
3423
3424 # the dep string we have saves the dependencies as they
3425 # were found, including expressions like ! && ||. We
3426 # want to split this out into just an array of configs.
3427
3428 my $valid = "A-Za-z_0-9";
3429
3430 my @configs;
3431
3432 while ($dep =~ /[$valid]/) {
3433
3434 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3435 my $conf = "CONFIG_" . $1;
3436
3437 $configs[$#configs + 1] = $conf;
3438
3439 $dep =~ s/^[^$valid]*[$valid]+//;
3440 } else {
3441 die "this should never happen";
3442 }
3443 }
3444
3445 return @configs;
3446}
3447
3448my %min_configs;
3449my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003450my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003451my %processed_configs;
3452my %nochange_config;
3453
3454sub test_this_config {
3455 my ($config) = @_;
3456
3457 my $found;
3458
3459 # if we already processed this config, skip it
3460 if (defined($processed_configs{$config})) {
3461 return undef;
3462 }
3463 $processed_configs{$config} = 1;
3464
3465 # if this config failed during this round, skip it
3466 if (defined($nochange_config{$config})) {
3467 return undef;
3468 }
3469
Steven Rostedtac6974c2011-10-04 09:40:17 -04003470 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003471
3472 # Test dependencies first
3473 if (defined($depends{"$kconfig"})) {
3474 my @parents = get_depends $config;
3475 foreach my $parent (@parents) {
3476 # if the parent is in the min config, check it first
3477 next if (!defined($min_configs{$parent}));
3478 $found = test_this_config($parent);
3479 if (defined($found)) {
3480 return $found;
3481 }
3482 }
3483 }
3484
3485 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003486 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003487 # .config to make sure it is missing the config that
3488 # we had before
3489 my %configs = %min_configs;
3490 delete $configs{$config};
3491 make_new_config ((values %configs), (values %keep_configs));
3492 make_oldconfig;
3493 undef %configs;
3494 assign_configs \%configs, $output_config;
3495
3496 return $config if (!defined($configs{$config}));
3497
3498 doprint "disabling config $config did not change .config\n";
3499
3500 $nochange_config{$config} = 1;
3501
3502 return undef;
3503}
3504
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003505sub make_min_config {
3506 my ($i) = @_;
3507
Steven Rostedtccc513b2012-05-21 17:13:40 -04003508 my $type = $minconfig_type;
3509 if ($type ne "boot" && $type ne "test") {
3510 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3511 " make_min_config works only with 'boot' and 'test'\n" and return;
3512 }
3513
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003514 if (!defined($output_minconfig)) {
3515 fail "OUTPUT_MIN_CONFIG not defined" and return;
3516 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003517
3518 # If output_minconfig exists, and the start_minconfig
3519 # came from min_config, than ask if we should use
3520 # that instead.
3521 if (-f $output_minconfig && !$start_minconfig_defined) {
3522 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003523 if (!defined($use_output_minconfig)) {
3524 if (read_yn " Use it as minconfig?") {
3525 $start_minconfig = $output_minconfig;
3526 }
3527 } elsif ($use_output_minconfig > 0) {
3528 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003529 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003530 } else {
3531 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003532 }
3533 }
3534
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003535 if (!defined($start_minconfig)) {
3536 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3537 }
3538
Steven Rostedt35ce5952011-07-15 21:57:25 -04003539 my $temp_config = "$tmpdir/temp_config";
3540
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003541 # First things first. We build an allnoconfig to find
3542 # out what the defaults are that we can't touch.
3543 # Some are selections, but we really can't handle selections.
3544
3545 my $save_minconfig = $minconfig;
3546 undef $minconfig;
3547
3548 run_command "$make allnoconfig" or return 0;
3549
Steven Rostedtb9066f62011-07-15 21:25:24 -04003550 read_depends;
3551
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003552 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003553
Steven Rostedt43d1b652011-07-15 22:01:56 -04003554 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003555 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003556
3557 if (defined($ignore_config)) {
3558 # make sure the file exists
3559 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003560 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003561 }
3562
Steven Rostedt43d1b652011-07-15 22:01:56 -04003563 %keep_configs = %save_configs;
3564
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003565 doprint "Load initial configs from $start_minconfig\n";
3566
3567 # Look at the current min configs, and save off all the
3568 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003569 assign_configs \%min_configs, $start_minconfig;
3570
3571 my @config_keys = keys %min_configs;
3572
Steven Rostedtac6974c2011-10-04 09:40:17 -04003573 # All configs need a depcount
3574 foreach my $config (@config_keys) {
3575 my $kconfig = chomp_config $config;
3576 if (!defined $depcount{$kconfig}) {
3577 $depcount{$kconfig} = 0;
3578 }
3579 }
3580
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003581 # Remove anything that was set by the make allnoconfig
3582 # we shouldn't need them as they get set for us anyway.
3583 foreach my $config (@config_keys) {
3584 # Remove anything in the ignore_config
3585 if (defined($keep_configs{$config})) {
3586 my $file = $ignore_config;
3587 $file =~ s,.*/(.*?)$,$1,;
3588 doprint "$config set by $file ... ignored\n";
3589 delete $min_configs{$config};
3590 next;
3591 }
3592 # But make sure the settings are the same. If a min config
3593 # sets a selection, we do not want to get rid of it if
3594 # it is not the same as what we have. Just move it into
3595 # the keep configs.
3596 if (defined($config_ignore{$config})) {
3597 if ($config_ignore{$config} ne $min_configs{$config}) {
3598 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3599 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3600 $keep_configs{$config} = $min_configs{$config};
3601 } else {
3602 doprint "$config set by allnoconfig ... ignored\n";
3603 }
3604 delete $min_configs{$config};
3605 }
3606 }
3607
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003608 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003609 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003610
3611 while (!$done) {
3612
3613 my $config;
3614 my $found;
3615
3616 # Now disable each config one by one and do a make oldconfig
3617 # till we find a config that changes our list.
3618
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003619 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003620
3621 # Sort keys by who is most dependent on
3622 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3623 @test_configs ;
3624
3625 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003626 my $reset = 1;
3627 for (my $i = 0; $i < $#test_configs; $i++) {
3628 if (!defined($nochange_config{$test_configs[0]})) {
3629 $reset = 0;
3630 last;
3631 }
3632 # This config didn't change the .config last time.
3633 # Place it at the end
3634 my $config = shift @test_configs;
3635 push @test_configs, $config;
3636 }
3637
3638 # if every test config has failed to modify the .config file
3639 # in the past, then reset and start over.
3640 if ($reset) {
3641 undef %nochange_config;
3642 }
3643
Steven Rostedtb9066f62011-07-15 21:25:24 -04003644 undef %processed_configs;
3645
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003646 foreach my $config (@test_configs) {
3647
Steven Rostedtb9066f62011-07-15 21:25:24 -04003648 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003649
Steven Rostedtb9066f62011-07-15 21:25:24 -04003650 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003651
3652 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003653 }
3654
3655 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003656 # we could have failed due to the nochange_config hash
3657 # reset and try again
3658 if (!$take_two) {
3659 undef %nochange_config;
3660 $take_two = 1;
3661 next;
3662 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003663 doprint "No more configs found that we can disable\n";
3664 $done = 1;
3665 last;
3666 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003667 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003668
3669 $config = $found;
3670
3671 doprint "Test with $config disabled\n";
3672
3673 # set in_bisect to keep build and monitor from dieing
3674 $in_bisect = 1;
3675
3676 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003677 build "oldconfig" or $failed = 1;
3678 if (!$failed) {
3679 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003680
3681 if ($type eq "test" && !$failed) {
3682 do_run_test or $failed = 1;
3683 }
3684
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003685 end_monitor;
3686 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003687
3688 $in_bisect = 0;
3689
3690 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003691 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003692 # this config is needed, add it to the ignore list.
3693 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003694 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003695 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003696
3697 # update new ignore configs
3698 if (defined($ignore_config)) {
3699 open (OUT, ">$temp_config")
3700 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003701 foreach my $config (keys %save_configs) {
3702 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003703 }
3704 close OUT;
3705 run_command "mv $temp_config $ignore_config" or
3706 dodie "failed to copy update to $ignore_config";
3707 }
3708
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003709 } else {
3710 # We booted without this config, remove it from the minconfigs.
3711 doprint "$config is not needed, disabling\n";
3712
3713 delete $min_configs{$config};
3714
3715 # Also disable anything that is not enabled in this config
3716 my %configs;
3717 assign_configs \%configs, $output_config;
3718 my @config_keys = keys %min_configs;
3719 foreach my $config (@config_keys) {
3720 if (!defined($configs{$config})) {
3721 doprint "$config is not set, disabling\n";
3722 delete $min_configs{$config};
3723 }
3724 }
3725
3726 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003727 open (OUT, ">$temp_config")
3728 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003729 foreach my $config (keys %keep_configs) {
3730 print OUT "$keep_configs{$config}\n";
3731 }
3732 foreach my $config (keys %min_configs) {
3733 print OUT "$min_configs{$config}\n";
3734 }
3735 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003736
3737 run_command "mv $temp_config $output_minconfig" or
3738 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003739 }
3740
3741 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003742 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003743 }
3744
3745 success $i;
3746 return 1;
3747}
3748
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003749sub make_warnings_file {
3750 my ($i) = @_;
3751
3752 if (!defined($warnings_file)) {
3753 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3754 }
3755
3756 if ($build_type eq "nobuild") {
3757 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3758 }
3759
3760 build $build_type or dodie "Failed to build";
3761
3762 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3763
3764 open(IN, $buildlog) or dodie "Can't open $buildlog";
3765 while (<IN>) {
3766
3767 # Some compilers use UTF-8 extended for quotes
3768 # for distcc heterogeneous systems, this causes issues
3769 s/$utf8_quote/'/g;
3770
3771 if (/$check_build_re/) {
3772 print OUT;
3773 }
3774 }
3775 close(IN);
3776
3777 close(OUT);
3778
3779 success $i;
3780}
3781
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003782$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003783
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003784if ($#ARGV == 0) {
3785 $ktest_config = $ARGV[0];
3786 if (! -f $ktest_config) {
3787 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003788 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003789 exit 0;
3790 }
3791 }
3792} else {
3793 $ktest_config = "ktest.conf";
3794}
3795
3796if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003797 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003798 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003799 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3800 print OUT << "EOF"
3801# Generated by ktest.pl
3802#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003803
3804# PWD is a ktest.pl variable that will result in the process working
3805# directory that ktest.pl is executed in.
3806
3807# THIS_DIR is automatically assigned the PWD of the path that generated
3808# the config file. It is best to use this variable when assigning other
3809# directory paths within this directory. This allows you to easily
3810# move the test cases to other locations or to other machines.
3811#
3812THIS_DIR := $variable{"PWD"}
3813
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003814# Define each test with TEST_START
3815# The config options below it will override the defaults
3816TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003817TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003818
3819DEFAULTS
3820EOF
3821;
3822 close(OUT);
3823}
3824read_config $ktest_config;
3825
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003826if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003827 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003828}
3829
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003830# Append any configs entered in manually to the config file.
3831my @new_configs = keys %entered_configs;
3832if ($#new_configs >= 0) {
3833 print "\nAppending entered in configs to $ktest_config\n";
3834 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3835 foreach my $config (@new_configs) {
3836 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003837 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003838 }
3839}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003840
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003841if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3842 unlink $opt{"LOG_FILE"};
3843}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003844
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003845doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3846
Steven Rostedta57419b2010-11-02 15:13:54 -04003847for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3848
3849 if (!$i) {
3850 doprint "DEFAULT OPTIONS:\n";
3851 } else {
3852 doprint "\nTEST $i OPTIONS";
3853 if (defined($repeat_tests{$i})) {
3854 $repeat = $repeat_tests{$i};
3855 doprint " ITERATE $repeat";
3856 }
3857 doprint "\n";
3858 }
3859
3860 foreach my $option (sort keys %opt) {
3861
3862 if ($option =~ /\[(\d+)\]$/) {
3863 next if ($i != $1);
3864 } else {
3865 next if ($i);
3866 }
3867
3868 doprint "$option = $opt{$option}\n";
3869 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003870}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003871
Steven Rostedt2a625122011-05-20 15:48:59 -04003872sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003873 my ($name, $i) = @_;
3874
3875 my $option = "$name\[$i\]";
3876
3877 if (defined($opt{$option})) {
3878 return $opt{$option};
3879 }
3880
Steven Rostedta57419b2010-11-02 15:13:54 -04003881 foreach my $test (keys %repeat_tests) {
3882 if ($i >= $test &&
3883 $i < $test + $repeat_tests{$test}) {
3884 $option = "$name\[$test\]";
3885 if (defined($opt{$option})) {
3886 return $opt{$option};
3887 }
3888 }
3889 }
3890
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003891 if (defined($opt{$name})) {
3892 return $opt{$name};
3893 }
3894
3895 return undef;
3896}
3897
Steven Rostedt2a625122011-05-20 15:48:59 -04003898sub set_test_option {
3899 my ($name, $i) = @_;
3900
3901 my $option = __set_test_option($name, $i);
3902 return $option if (!defined($option));
3903
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003904 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003905}
3906
Steven Rostedt2545eb62010-11-02 15:01:32 -04003907# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003908for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003909
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003910 # Do not reboot on failing test options
3911 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003912 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003913
Steven Rostedt683a3e62012-05-18 13:34:35 -04003914 $have_version = 0;
3915
Steven Rostedt576f6272010-11-02 14:58:38 -04003916 $iteration = $i;
3917
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003918 undef %force_config;
3919
Steven Rostedta75fece2010-11-02 14:58:27 -04003920 my $makecmd = set_test_option("MAKE_CMD", $i);
3921
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003922 # Load all the options into their mapped variable names
3923 foreach my $opt (keys %option_map) {
3924 ${$option_map{$opt}} = set_test_option($opt, $i);
3925 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003926
Steven Rostedt35ce5952011-07-15 21:57:25 -04003927 $start_minconfig_defined = 1;
3928
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003929 # The first test may override the PRE_KTEST option
3930 if (defined($pre_ktest) && $i == 1) {
3931 doprint "\n";
3932 run_command $pre_ktest;
3933 }
3934
3935 # Any test can override the POST_KTEST option
3936 # The last test takes precedence.
3937 if (defined($post_ktest)) {
3938 $final_post_ktest = $post_ktest;
3939 }
3940
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003941 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003942 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003943 $start_minconfig = $minconfig;
3944 }
3945
Steven Rostedta75fece2010-11-02 14:58:27 -04003946 chdir $builddir || die "can't change directory to $builddir";
3947
Andrew Jonesa908a662011-08-12 15:32:03 +02003948 foreach my $dir ($tmpdir, $outputdir) {
3949 if (!-d $dir) {
3950 mkpath($dir) or
3951 die "can't create $dir";
3952 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003953 }
3954
Steven Rostedte48c5292010-11-02 14:35:37 -04003955 $ENV{"SSH_USER"} = $ssh_user;
3956 $ENV{"MACHINE"} = $machine;
3957
Steven Rostedta75fece2010-11-02 14:58:27 -04003958 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303959 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003960 $dmesg = "$tmpdir/dmesg-$machine";
3961 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003962 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003963
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003964 if (!$buildonly) {
3965 $target = "$ssh_user\@$machine";
3966 if ($reboot_type eq "grub") {
3967 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05003968 } elsif ($reboot_type eq "grub2") {
3969 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3970 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05003971 } elsif ($reboot_type eq "syslinux") {
3972 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003973 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003974 }
3975
3976 my $run_type = $build_type;
3977 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003978 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003979 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003980 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003981 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003982 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003983 } elsif ($test_type eq "make_min_config") {
3984 $run_type = "";
3985 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003986 $run_type = "";
3987 }
3988
Steven Rostedta75fece2010-11-02 14:58:27 -04003989 # mistake in config file?
3990 if (!defined($run_type)) {
3991 $run_type = "ERROR";
3992 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003993
Steven Rostedte0a87422011-09-30 17:50:48 -04003994 my $installme = "";
3995 $installme = " no_install" if ($no_install);
3996
Steven Rostedt2545eb62010-11-02 15:01:32 -04003997 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003998 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003999
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004000 if (defined($pre_test)) {
4001 run_command $pre_test;
4002 }
4003
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004004 unlink $dmesg;
4005 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304006 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004007
Steven Rostedt250bae82011-07-15 22:05:59 -04004008 if (defined($addconfig)) {
4009 my $min = $minconfig;
4010 if (!defined($minconfig)) {
4011 $min = "";
4012 }
4013 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004014 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004015 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004016 }
4017
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004018 if (defined($checkout)) {
4019 run_command "git checkout $checkout" or
4020 die "failed to checkout $checkout";
4021 }
4022
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004023 $no_reboot = 0;
4024
Steven Rostedt648a1822012-03-21 11:18:27 -04004025 # A test may opt to not reboot the box
4026 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004027 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004028 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004029
Steven Rostedta75fece2010-11-02 14:58:27 -04004030 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004031 bisect $i;
4032 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004033 } elsif ($test_type eq "config_bisect") {
4034 config_bisect $i;
4035 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004036 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004037 patchcheck $i;
4038 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004039 } elsif ($test_type eq "make_min_config") {
4040 make_min_config $i;
4041 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004042 } elsif ($test_type eq "make_warnings_file") {
4043 $no_reboot = 1;
4044 make_warnings_file $i;
4045 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004046 }
4047
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004048 if ($build_type ne "nobuild") {
4049 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004050 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004051 }
4052
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004053 if ($test_type eq "install") {
4054 get_version;
4055 install;
4056 success $i;
4057 next;
4058 }
4059
Steven Rostedta75fece2010-11-02 14:58:27 -04004060 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004061 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004062 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004063
4064 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4065 do_run_test or $failed = 1;
4066 }
4067 end_monitor;
4068 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004069 }
4070
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004071 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004072}
4073
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004074if (defined($final_post_ktest)) {
4075 run_command $final_post_ktest;
4076}
4077
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004078if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004079 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004080} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004081 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004082} elsif (defined($switch_to_good)) {
4083 # still need to get to the good kernel
4084 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004085}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004086
Steven Rostedt648a1822012-03-21 11:18:27 -04004087
Steven Rostedte48c5292010-11-02 14:35:37 -04004088doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4089
Steven Rostedt2545eb62010-11-02 15:01:32 -04004090exit 0;