blob: 0c8b61f8398edace8b4d7be42e50b8638679520d [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 Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -050021my %evals;
Steven Rostedt2545eb62010-11-02 15:01:32 -040022
23#default opts
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050024my %default = (
25 "NUM_TESTS" => 1,
26 "TEST_TYPE" => "build",
27 "BUILD_TYPE" => "randconfig",
28 "MAKE_CMD" => "make",
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +090029 "CLOSE_CONSOLE_SIGNAL" => "INT",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050030 "TIMEOUT" => 120,
31 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
32 "SLEEP_TIME" => 60, # sleep time between tests
33 "BUILD_NOCLEAN" => 0,
34 "REBOOT_ON_ERROR" => 0,
35 "POWEROFF_ON_ERROR" => 0,
36 "REBOOT_ON_SUCCESS" => 1,
37 "POWEROFF_ON_SUCCESS" => 0,
38 "BUILD_OPTIONS" => "",
39 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
40 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
41 "CLEAR_LOG" => 0,
42 "BISECT_MANUAL" => 0,
43 "BISECT_SKIP" => 1,
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -050044 "BISECT_TRIES" => 1,
Steven Rostedtccc513b2012-05-21 17:13:40 -040045 "MIN_CONFIG_TYPE" => "boot",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050046 "SUCCESS_LINE" => "login:",
47 "DETECT_TRIPLE_FAULT" => 1,
48 "NO_INSTALL" => 0,
49 "BOOTED_TIMEOUT" => 1,
50 "DIE_ON_FAILURE" => 1,
51 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
52 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
Steven Rostedt02ad2612012-03-21 08:21:24 -040053 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050054 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
55 "STOP_AFTER_SUCCESS" => 10,
56 "STOP_AFTER_FAILURE" => 60,
57 "STOP_TEST_AFTER" => 600,
Steven Rostedt407b95b2012-07-19 16:05:42 -040058 "MAX_MONITOR_WAIT" => 1800,
Steven Rostedta15ba912012-11-13 14:30:37 -050059 "GRUB_REBOOT" => "grub2-reboot",
Steven Rostedt77869542012-12-11 17:37:41 -050060 "SYSLINUX" => "extlinux",
61 "SYSLINUX_PATH" => "/boot/extlinux",
Steven Rostedt600bbf02011-11-21 20:12:04 -050062
63# required, and we will ask users if they don't have them but we keep the default
64# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050065 "REBOOT_TYPE" => "grub",
66 "LOCALVERSION" => "-test",
67 "SSH_USER" => "root",
68 "BUILD_TARGET" => "arch/x86/boot/bzImage",
69 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050070
71 "LOG_FILE" => undef,
72 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050073);
Steven Rostedt2545eb62010-11-02 15:01:32 -040074
Satoru Takeuchi5269faa2014-03-09 23:32:04 +090075my $ktest_config = "ktest.conf";
Steven Rostedt2545eb62010-11-02 15:01:32 -040076my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040077my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040078my $machine;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -040079my $last_machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040080my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040081my $tmpdir;
82my $builddir;
83my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050084my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040085my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040086my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040087my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040088my $final_post_ktest;
89my $pre_ktest;
90my $post_ktest;
91my $pre_test;
92my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040093my $pre_build;
94my $post_build;
95my $pre_build_die;
96my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040097my $reboot_type;
98my $reboot_script;
99my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -0400100my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -0400101my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -0500102my $switch_to_good;
103my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -0400104my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -0400105my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -0400106my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -0400107my $powercycle_after_reboot;
108my $poweroff_after_halt;
Steven Rostedt407b95b2012-07-19 16:05:42 -0400109my $max_monitor_wait;
Steven Rostedte48c5292010-11-02 14:35:37 -0400110my $ssh_exec;
111my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400112my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400113my $power_off;
114my $grub_menu;
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -0500115my $last_grub_menu;
Steven Rostedta15ba912012-11-13 14:30:37 -0500116my $grub_file;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400117my $grub_number;
Steven Rostedta15ba912012-11-13 14:30:37 -0500118my $grub_reboot;
Steven Rostedt77869542012-12-11 17:37:41 -0500119my $syslinux;
120my $syslinux_path;
121my $syslinux_label;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400122my $target;
123my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400124my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400125my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400126my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400127my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400128my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400129my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400130my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400131my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400132my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400133my $use_output_minconfig;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500134my $warnings_file;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400135my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500136my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400137my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400138my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500139my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400140my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500141my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500142my $bisect_skip;
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -0500143my $bisect_tries;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400144my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500145my $bisect_ret_good;
146my $bisect_ret_bad;
147my $bisect_ret_skip;
148my $bisect_ret_abort;
149my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400150my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400151my $run_test;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400152my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530153my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400154my $dmesg;
155my $monitor_fp;
156my $monitor_pid;
157my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400158my $sleep_time;
159my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400160my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400161my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400162my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530163my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400164my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400165my $timeout;
166my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400167my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400168my $console;
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900169my $close_console_signal;
Steven Rostedt2b803362011-09-30 18:00:23 -0400170my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400171my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500172my $stop_after_success;
173my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500174my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400175my $build_target;
176my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500177my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400178my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400179my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400180my $successes = 0;
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -0600181my $stty_orig;
Steven Rostedt (VMware)57394382017-02-07 14:50:03 -0500182my $run_command_status = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400183
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500184my $bisect_good;
185my $bisect_bad;
186my $bisect_type;
187my $bisect_start;
188my $bisect_replay;
189my $bisect_files;
190my $bisect_reverse;
191my $bisect_check;
192
193my $config_bisect;
194my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400195my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500196
197my $patchcheck_type;
198my $patchcheck_start;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -0400199my $patchcheck_cherry;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500200my $patchcheck_end;
201
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -0500202my $build_time;
203my $install_time;
204my $reboot_time;
205my $test_time;
206
Steven Rostedt165708b2011-11-26 20:56:52 -0500207# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500208# which would require more options.
209my $buildonly = 1;
210
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500211# tell build not to worry about warnings, even when WARNINGS_FILE is set
212my $warnings_ok = 0;
213
Steven Rostedtdbd37832011-11-23 16:00:48 -0500214# set when creating a new config
215my $newconfig = 0;
216
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500217my %entered_configs;
218my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400219my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400220
221# force_config is the list of configs that we force enabled (or disabled)
222# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400223my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500224
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400225# do not force reboots on config problems
226my $no_reboot = 1;
227
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400228# reboot on success
229my $reboot_success = 0;
230
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500231my %option_map = (
232 "MACHINE" => \$machine,
233 "SSH_USER" => \$ssh_user,
234 "TMP_DIR" => \$tmpdir,
235 "OUTPUT_DIR" => \$outputdir,
236 "BUILD_DIR" => \$builddir,
237 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400238 "PRE_KTEST" => \$pre_ktest,
239 "POST_KTEST" => \$post_ktest,
240 "PRE_TEST" => \$pre_test,
241 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500242 "BUILD_TYPE" => \$build_type,
243 "BUILD_OPTIONS" => \$build_options,
244 "PRE_BUILD" => \$pre_build,
245 "POST_BUILD" => \$post_build,
246 "PRE_BUILD_DIE" => \$pre_build_die,
247 "POST_BUILD_DIE" => \$post_build_die,
248 "POWER_CYCLE" => \$power_cycle,
249 "REBOOT" => \$reboot,
250 "BUILD_NOCLEAN" => \$noclean,
251 "MIN_CONFIG" => \$minconfig,
252 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
253 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400254 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400255 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500256 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500257 "IGNORE_CONFIG" => \$ignore_config,
258 "TEST" => \$run_test,
259 "ADD_CONFIG" => \$addconfig,
260 "REBOOT_TYPE" => \$reboot_type,
261 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500262 "GRUB_FILE" => \$grub_file,
263 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500264 "SYSLINUX" => \$syslinux,
265 "SYSLINUX_PATH" => \$syslinux_path,
266 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400267 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500268 "POST_INSTALL" => \$post_install,
269 "NO_INSTALL" => \$no_install,
270 "REBOOT_SCRIPT" => \$reboot_script,
271 "REBOOT_ON_ERROR" => \$reboot_on_error,
272 "SWITCH_TO_GOOD" => \$switch_to_good,
273 "SWITCH_TO_TEST" => \$switch_to_test,
274 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400275 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500276 "DIE_ON_FAILURE" => \$die_on_failure,
277 "POWER_OFF" => \$power_off,
278 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
279 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400280 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500281 "SLEEP_TIME" => \$sleep_time,
282 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
283 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
284 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500285 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500286 "BISECT_MANUAL" => \$bisect_manual,
287 "BISECT_SKIP" => \$bisect_skip,
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -0500288 "BISECT_TRIES" => \$bisect_tries,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500289 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
290 "BISECT_RET_GOOD" => \$bisect_ret_good,
291 "BISECT_RET_BAD" => \$bisect_ret_bad,
292 "BISECT_RET_SKIP" => \$bisect_ret_skip,
293 "BISECT_RET_ABORT" => \$bisect_ret_abort,
294 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
295 "STORE_FAILURES" => \$store_failures,
296 "STORE_SUCCESSES" => \$store_successes,
297 "TEST_NAME" => \$test_name,
298 "TIMEOUT" => \$timeout,
299 "BOOTED_TIMEOUT" => \$booted_timeout,
300 "CONSOLE" => \$console,
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900301 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500302 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
303 "SUCCESS_LINE" => \$success_line,
304 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
305 "STOP_AFTER_SUCCESS" => \$stop_after_success,
306 "STOP_AFTER_FAILURE" => \$stop_after_failure,
307 "STOP_TEST_AFTER" => \$stop_test_after,
308 "BUILD_TARGET" => \$build_target,
309 "SSH_EXEC" => \$ssh_exec,
310 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400311 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500312 "CHECKOUT" => \$checkout,
313 "TARGET_IMAGE" => \$target_image,
314 "LOCALVERSION" => \$localversion,
315
316 "BISECT_GOOD" => \$bisect_good,
317 "BISECT_BAD" => \$bisect_bad,
318 "BISECT_TYPE" => \$bisect_type,
319 "BISECT_START" => \$bisect_start,
320 "BISECT_REPLAY" => \$bisect_replay,
321 "BISECT_FILES" => \$bisect_files,
322 "BISECT_REVERSE" => \$bisect_reverse,
323 "BISECT_CHECK" => \$bisect_check,
324
325 "CONFIG_BISECT" => \$config_bisect,
326 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400327 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500328
329 "PATCHCHECK_TYPE" => \$patchcheck_type,
330 "PATCHCHECK_START" => \$patchcheck_start,
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -0400331 "PATCHCHECK_CHERRY" => \$patchcheck_cherry,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500332 "PATCHCHECK_END" => \$patchcheck_end,
333);
334
335# Options may be used by other options, record them.
336my %used_options;
337
Steven Rostedt7bf51072011-10-22 09:07:03 -0400338# default variables that can be used
339chomp ($variable{"PWD"} = `pwd`);
340
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500341$config_help{"MACHINE"} = << "EOF"
342 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500343 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500344EOF
345 ;
346$config_help{"SSH_USER"} = << "EOF"
347 The box is expected to have ssh on normal bootup, provide the user
348 (most likely root, since you need privileged operations)
349EOF
350 ;
351$config_help{"BUILD_DIR"} = << "EOF"
352 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500353 You can use \${PWD} that will be the path where ktest.pl is run, or use
354 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500355EOF
356 ;
357$config_help{"OUTPUT_DIR"} = << "EOF"
358 The directory that the objects will be built (full path).
359 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500360 You can use \${PWD} that will be the path where ktest.pl is run, or use
361 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500362EOF
363 ;
364$config_help{"BUILD_TARGET"} = << "EOF"
365 The location of the compiled file to copy to the target.
366 (relative to OUTPUT_DIR)
367EOF
368 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500369$config_help{"BUILD_OPTIONS"} = << "EOF"
370 Options to add to \"make\" when building.
371 i.e. -j20
372EOF
373 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500374$config_help{"TARGET_IMAGE"} = << "EOF"
375 The place to put your image on the test machine.
376EOF
377 ;
378$config_help{"POWER_CYCLE"} = << "EOF"
379 A script or command to reboot the box.
380
381 Here is a digital loggers power switch example
382 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
383
384 Here is an example to reboot a virtual box on the current host
385 with the name "Guest".
386 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
387EOF
388 ;
389$config_help{"CONSOLE"} = << "EOF"
390 The script or command that reads the console
391
392 If you use ttywatch server, something like the following would work.
393CONSOLE = nc -d localhost 3001
394
395 For a virtual machine with guest name "Guest".
396CONSOLE = virsh console Guest
397EOF
398 ;
399$config_help{"LOCALVERSION"} = << "EOF"
400 Required version ending to differentiate the test
401 from other linux builds on the system.
402EOF
403 ;
404$config_help{"REBOOT_TYPE"} = << "EOF"
405 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500406 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500407
408 If you specify grub, it will assume grub version 1
409 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
410 and select that target to reboot to the kernel. If this is not
411 your setup, then specify "script" and have a command or script
412 specified in REBOOT_SCRIPT to boot to the target.
413
414 The entry in /boot/grub/menu.lst must be entered in manually.
415 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500416
417 If you specify grub2, then you also need to specify both \$GRUB_MENU
418 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500419
420 If you specify syslinux, then you may use SYSLINUX to define the syslinux
421 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
422 the syslinux install (defaults to /boot/extlinux). But you have to specify
423 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500424EOF
425 ;
426$config_help{"GRUB_MENU"} = << "EOF"
427 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500428 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500429
430 Note, ktest.pl will not update the grub menu.lst, you need to
431 manually add an option for the test. ktest.pl will search
432 the grub menu.lst for this option to find what kernel to
433 reboot into.
434
435 For example, if in the /boot/grub/menu.lst the test kernel title has:
436 title Test Kernel
437 kernel vmlinuz-test
438 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500439
440 For grub2, a search of \$GRUB_FILE is performed for the lines
441 that begin with "menuentry". It will not detect submenus. The
442 menu must be a non-nested menu. Add the quotes used in the menu
443 to guarantee your selection, as the first menuentry with the content
444 of \$GRUB_MENU that is found will be used.
445EOF
446 ;
447$config_help{"GRUB_FILE"} = << "EOF"
448 If grub2 is used, the full path for the grub.cfg file is placed
449 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500450EOF
451 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500452$config_help{"SYSLINUX_LABEL"} = << "EOF"
453 If syslinux is used, the label that boots the target kernel must
454 be specified with SYSLINUX_LABEL.
455EOF
456 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500457$config_help{"REBOOT_SCRIPT"} = << "EOF"
458 A script to reboot the target into the test kernel
459 (Only mandatory if REBOOT_TYPE = script)
460EOF
461 ;
462
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500463sub _logit {
464 if (defined($opt{"LOG_FILE"})) {
465 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
466 print OUT @_;
467 close(OUT);
468 }
469}
470
471sub logit {
472 if (defined($opt{"LOG_FILE"})) {
473 _logit @_;
474 } else {
475 print @_;
476 }
477}
478
479sub doprint {
480 print @_;
481 _logit @_;
482}
483
Steven Rostedtdad98752011-11-22 20:48:57 -0500484sub read_prompt {
485 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400486
487 my $ans;
488
489 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500490 if ($cancel) {
491 print "$prompt [y/n/C] ";
492 } else {
493 print "$prompt [Y/n] ";
494 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400495 $ans = <STDIN>;
496 chomp $ans;
497 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500498 if ($cancel) {
499 $ans = "c";
500 } else {
501 $ans = "y";
502 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400503 }
504 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500505 if ($cancel) {
506 last if ($ans =~ /^c$/i);
507 print "Please answer either 'y', 'n' or 'c'.\n";
508 } else {
509 print "Please answer either 'y' or 'n'.\n";
510 }
511 }
512 if ($ans =~ /^c/i) {
513 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400514 }
515 if ($ans !~ /^y$/i) {
516 return 0;
517 }
518 return 1;
519}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500520
Steven Rostedtdad98752011-11-22 20:48:57 -0500521sub read_yn {
522 my ($prompt) = @_;
523
524 return read_prompt 0, $prompt;
525}
526
527sub read_ync {
528 my ($prompt) = @_;
529
530 return read_prompt 1, $prompt;
531}
532
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900533sub get_mandatory_config {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500534 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400535 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500536
537 return if (defined($opt{$config}));
538
539 if (defined($config_help{$config})) {
540 print "\n";
541 print $config_help{$config};
542 }
543
544 for (;;) {
545 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500546 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500547 print "\[$default{$config}\] ";
548 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400549 $ans = <STDIN>;
550 $ans =~ s/^\s*(.*\S)\s*$/$1/;
551 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500552 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400553 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500554 } else {
555 print "Your answer can not be blank\n";
556 next;
557 }
558 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500559 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500560 last;
561 }
562}
563
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -0500564sub show_time {
565 my ($time) = @_;
566
567 my $hours = 0;
568 my $minutes = 0;
569
570 if ($time > 3600) {
571 $hours = int($time / 3600);
572 $time -= $hours * 3600;
573 }
574 if ($time > 60) {
575 $minutes = int($time / 60);
576 $time -= $minutes * 60;
577 }
578
579 if ($hours > 0) {
580 doprint "$hours hour";
581 doprint "s" if ($hours > 1);
582 doprint " ";
583 }
584
585 if ($minutes > 0) {
586 doprint "$minutes minute";
587 doprint "s" if ($minutes > 1);
588 doprint " ";
589 }
590
591 doprint "$time second";
592 doprint "s" if ($time != 1);
593}
594
595sub print_times {
596 doprint "\n";
597 if ($build_time) {
598 doprint "Build time: ";
599 show_time($build_time);
600 doprint "\n";
601 }
602 if ($install_time) {
603 doprint "Install time: ";
604 show_time($install_time);
605 doprint "\n";
606 }
607 if ($reboot_time) {
608 doprint "Reboot time: ";
609 show_time($reboot_time);
610 doprint "\n";
611 }
612 if ($test_time) {
613 doprint "Test time: ";
614 show_time($test_time);
615 doprint "\n";
616 }
617 # reset for iterations like bisect
618 $build_time = 0;
619 $install_time = 0;
620 $reboot_time = 0;
621 $test_time = 0;
622}
623
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900624sub get_mandatory_configs {
625 get_mandatory_config("MACHINE");
626 get_mandatory_config("BUILD_DIR");
627 get_mandatory_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500628
Steven Rostedtdbd37832011-11-23 16:00:48 -0500629 if ($newconfig) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900630 get_mandatory_config("BUILD_OPTIONS");
Steven Rostedtdbd37832011-11-23 16:00:48 -0500631 }
632
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500633 # options required for other than just building a kernel
634 if (!$buildonly) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900635 get_mandatory_config("POWER_CYCLE");
636 get_mandatory_config("CONSOLE");
Steven Rostedt165708b2011-11-26 20:56:52 -0500637 }
638
639 # options required for install and more
640 if ($buildonly != 1) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900641 get_mandatory_config("SSH_USER");
642 get_mandatory_config("BUILD_TARGET");
643 get_mandatory_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500644 }
645
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900646 get_mandatory_config("LOCALVERSION");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500647
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500648 return if ($buildonly);
649
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500650 my $rtype = $opt{"REBOOT_TYPE"};
651
652 if (!defined($rtype)) {
653 if (!defined($opt{"GRUB_MENU"})) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900654 get_mandatory_config("REBOOT_TYPE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500655 $rtype = $entered_configs{"REBOOT_TYPE"};
656 } else {
657 $rtype = "grub";
658 }
659 }
660
661 if ($rtype eq "grub") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900662 get_mandatory_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500663 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500664
665 if ($rtype eq "grub2") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900666 get_mandatory_config("GRUB_MENU");
667 get_mandatory_config("GRUB_FILE");
Steven Rostedta15ba912012-11-13 14:30:37 -0500668 }
Steven Rostedt77869542012-12-11 17:37:41 -0500669
670 if ($rtype eq "syslinux") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900671 get_mandatory_config("SYSLINUX_LABEL");
Steven Rostedt77869542012-12-11 17:37:41 -0500672 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500673}
674
Steven Rostedt77d942c2011-05-20 13:36:58 -0400675sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400676 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400677 my $retval = "";
678
679 # We want to check for '\', and it is just easier
680 # to check the previous characet of '$' and not need
681 # to worry if '$' is the first character. By adding
682 # a space to $value, we can just check [^\\]\$ and
683 # it will still work.
684 $value = " $value";
685
686 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
687 my $begin = $1;
688 my $var = $2;
689 my $end = $3;
690 # append beginning of value to retval
691 $retval = "$retval$begin";
692 if (defined($variable{$var})) {
693 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400694 } elsif (defined($remove_undef) && $remove_undef) {
695 # for if statements, any variable that is not defined,
696 # we simple convert to 0
697 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400698 } else {
699 # put back the origin piece.
700 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500701 # This could be an option that is used later, save
702 # it so we don't warn if this option is not one of
703 # ktests options.
704 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400705 }
706 $value = $end;
707 }
708 $retval = "$retval$value";
709
710 # remove the space added in the beginning
711 $retval =~ s/ //;
712
713 return "$retval"
714}
715
Steven Rostedta57419b2010-11-02 15:13:54 -0400716sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400717 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400718
Steven Rostedtcad96662011-12-22 11:32:52 -0500719 my $prvalue = process_variables($rvalue);
720
721 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500722 # Note if a test is something other than build, then we
Pavel Machek22722792016-12-14 15:06:18 -0800723 # will need other mandatory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500724 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500725 # for bisect, we need to check BISECT_TYPE
726 if ($prvalue ne "bisect") {
727 $buildonly = 0;
728 }
729 } else {
Pavel Machek22722792016-12-14 15:06:18 -0800730 # install still limits some mandatory options.
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500731 $buildonly = 2;
732 }
733 }
734
735 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
736 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500737 $buildonly = 0;
738 } else {
Pavel Machek22722792016-12-14 15:06:18 -0800739 # install still limits some mandatory options.
Steven Rostedt165708b2011-11-26 20:56:52 -0500740 $buildonly = 2;
741 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500742 }
743
Steven Rostedta57419b2010-11-02 15:13:54 -0400744 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400745 if (!$override || defined(${$overrides}{$lvalue})) {
746 my $extra = "";
747 if ($override) {
748 $extra = "In the same override section!\n";
749 }
750 die "$name: $.: Option $lvalue defined more than once!\n$extra";
751 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500752 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400753 }
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -0500754
755 $opt{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400756}
757
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500758sub set_eval {
759 my ($lvalue, $rvalue, $name) = @_;
760
761 my $prvalue = process_variables($rvalue);
762 my $arr;
763
764 if (defined($evals{$lvalue})) {
765 $arr = $evals{$lvalue};
766 } else {
767 $arr = [];
768 $evals{$lvalue} = $arr;
769 }
770
771 push @{$arr}, $rvalue;
772}
773
Steven Rostedt77d942c2011-05-20 13:36:58 -0400774sub set_variable {
775 my ($lvalue, $rvalue) = @_;
776
777 if ($rvalue =~ /^\s*$/) {
778 delete $variable{$lvalue};
779 } else {
780 $rvalue = process_variables($rvalue);
781 $variable{$lvalue} = $rvalue;
782 }
783}
784
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400785sub process_compare {
786 my ($lval, $cmp, $rval) = @_;
787
788 # remove whitespace
789
790 $lval =~ s/^\s*//;
791 $lval =~ s/\s*$//;
792
793 $rval =~ s/^\s*//;
794 $rval =~ s/\s*$//;
795
796 if ($cmp eq "==") {
797 return $lval eq $rval;
798 } elsif ($cmp eq "!=") {
799 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400800 } elsif ($cmp eq "=~") {
801 return $lval =~ m/$rval/;
802 } elsif ($cmp eq "!~") {
803 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400804 }
805
806 my $statement = "$lval $cmp $rval";
807 my $ret = eval $statement;
808
809 # $@ stores error of eval
810 if ($@) {
811 return -1;
812 }
813
814 return $ret;
815}
816
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400817sub value_defined {
818 my ($val) = @_;
819
820 return defined($variable{$2}) ||
821 defined($opt{$2});
822}
823
Steven Rostedt8d735212011-10-17 11:36:44 -0400824my $d = 0;
825sub process_expression {
826 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400827
Steven Rostedt8d735212011-10-17 11:36:44 -0400828 my $c = $d++;
829
830 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
831 my $express = $1;
832
833 if (process_expression($name, $express)) {
834 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
835 } else {
836 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
837 }
838 }
839
840 $d--;
841 my $OR = "\\|\\|";
842 my $AND = "\\&\\&";
843
844 while ($val =~ s/^(.*?)($OR|$AND)//) {
845 my $express = $1;
846 my $op = $2;
847
848 if (process_expression($name, $express)) {
849 if ($op eq "||") {
850 return 1;
851 }
852 } else {
853 if ($op eq "&&") {
854 return 0;
855 }
856 }
857 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400858
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400859 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400860 my $ret = process_compare($1, $2, $3);
861 if ($ret < 0) {
862 die "$name: $.: Unable to process comparison\n";
863 }
864 return $ret;
865 }
866
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400867 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
868 if (defined $1) {
869 return !value_defined($2);
870 } else {
871 return value_defined($2);
872 }
873 }
874
Steven Rostedt45d73a52011-09-30 19:44:53 -0400875 if ($val =~ /^\s*0\s*$/) {
876 return 0;
877 } elsif ($val =~ /^\s*\d+\s*$/) {
878 return 1;
879 }
880
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400881 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400882}
883
884sub process_if {
885 my ($name, $value) = @_;
886
887 # Convert variables and replace undefined ones with 0
888 my $val = process_variables($value, 1);
889 my $ret = process_expression $name, $val;
890
891 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400892}
893
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400894sub __read_config {
895 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400896
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400897 my $in;
898 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400899
Steven Rostedta57419b2010-11-02 15:13:54 -0400900 my $name = $config;
901 $name =~ s,.*/(.*),$1,;
902
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400903 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400904 my $default = 1;
905 my $repeat = 1;
906 my $num_tests_set = 0;
907 my $skip = 0;
908 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400909 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400910 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400911 my $if = 0;
912 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400913 my $override = 0;
914
915 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400916
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400917 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400918
919 # ignore blank lines and comments
920 next if (/^\s*$/ || /\s*\#/);
921
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400922 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400923
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400924 my $type = $1;
925 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400926 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400927
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400928 my $old_test_num;
929 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400930 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400931
932 if ($type eq "TEST_START") {
933
934 if ($num_tests_set) {
935 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
936 }
937
938 $old_test_num = $test_num;
939 $old_repeat = $repeat;
940
941 $test_num += $repeat;
942 $default = 0;
943 $repeat = 1;
944 } else {
945 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400946 }
947
Steven Rostedta9f84422011-10-17 11:06:29 -0400948 # If SKIP is anywhere in the line, the command will be skipped
949 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400950 $skip = 1;
951 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400952 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400953 $skip = 0;
954 }
955
Steven Rostedta9f84422011-10-17 11:06:29 -0400956 if ($rest =~ s/\sELSE\b//) {
957 if (!$if) {
958 die "$name: $.: ELSE found with out matching IF section\n$_";
959 }
960 $if = 0;
961
962 if ($if_set) {
963 $skip = 1;
964 } else {
965 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400966 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400967 }
968
Steven Rostedta9f84422011-10-17 11:06:29 -0400969 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400970 if (process_if($name, $1)) {
971 $if_set = 1;
972 } else {
973 $skip = 1;
974 }
975 $if = 1;
976 } else {
977 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400978 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400979 }
980
Steven Rostedta9f84422011-10-17 11:06:29 -0400981 if (!$skip) {
982 if ($type eq "TEST_START") {
983 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
984 $repeat = $1;
985 $repeat_tests{"$test_num"} = $repeat;
986 }
987 } elsif ($rest =~ s/\sOVERRIDE\b//) {
988 # DEFAULT only
989 $override = 1;
990 # Clear previous overrides
991 %overrides = ();
992 }
993 }
994
995 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400996 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400997 }
998
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400999 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -04001000 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -04001001 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -04001002 }
1003
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001004 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -04001005 if (!$if) {
1006 die "$name: $.: ELSE found with out matching IF section\n$_";
1007 }
1008 $rest = $1;
1009 if ($if_set) {
1010 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001011 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -04001012 } else {
1013 $skip = 0;
1014
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001015 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -04001016 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -04001017 if (process_if($name, $1)) {
1018 $if_set = 1;
1019 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -04001020 $skip = 1;
1021 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001022 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -04001023 } else {
1024 $if = 0;
1025 }
1026 }
1027
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001028 if ($rest !~ /^\s*$/) {
1029 die "$name: $.: Gargbage found after DEFAULTS\n$_";
1030 }
1031
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001032 } elsif (/^\s*INCLUDE\s+(\S+)/) {
1033
1034 next if ($skip);
1035
1036 if (!$default) {
1037 die "$name: $.: INCLUDE can only be done in default sections\n$_";
1038 }
1039
1040 my $file = process_variables($1);
1041
1042 if ($file !~ m,^/,) {
1043 # check the path of the config file first
1044 if ($config =~ m,(.*)/,) {
1045 if (-f "$1/$file") {
1046 $file = "$1/$file";
1047 }
1048 }
1049 }
1050
1051 if ( ! -r $file ) {
1052 die "$name: $.: Can't read file $file\n$_";
1053 }
1054
1055 if (__read_config($file, \$test_num)) {
1056 $test_case = 1;
1057 }
1058
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001059 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1060
1061 next if ($skip);
1062
1063 my $lvalue = $1;
1064 my $rvalue = $2;
1065
1066 if ($default || $lvalue =~ /\[\d+\]$/) {
1067 set_eval($lvalue, $rvalue, $name);
1068 } else {
1069 my $val = "$lvalue\[$test_num\]";
1070 set_eval($val, $rvalue, $name);
1071 }
1072
Steven Rostedta57419b2010-11-02 15:13:54 -04001073 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1074
1075 next if ($skip);
1076
Steven Rostedt2545eb62010-11-02 15:01:32 -04001077 my $lvalue = $1;
1078 my $rvalue = $2;
1079
Steven Rostedta57419b2010-11-02 15:13:54 -04001080 if (!$default &&
1081 ($lvalue eq "NUM_TESTS" ||
1082 $lvalue eq "LOG_FILE" ||
1083 $lvalue eq "CLEAR_LOG")) {
1084 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001085 }
Steven Rostedta57419b2010-11-02 15:13:54 -04001086
1087 if ($lvalue eq "NUM_TESTS") {
1088 if ($test_num) {
1089 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1090 }
1091 if (!$default) {
1092 die "$name: $.: NUM_TESTS must be set in default section\n";
1093 }
1094 $num_tests_set = 1;
1095 }
1096
1097 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001098 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001099 } else {
1100 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001101 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001102
1103 if ($repeat > 1) {
1104 $repeats{$val} = $repeat;
1105 }
1106 }
Steven Rostedt77d942c2011-05-20 13:36:58 -04001107 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1108 next if ($skip);
1109
1110 my $lvalue = $1;
1111 my $rvalue = $2;
1112
1113 # process config variables.
1114 # Config variables are only active while reading the
1115 # config and can be defined anywhere. They also ignore
1116 # TEST_START and DEFAULTS, but are skipped if they are in
1117 # on of these sections that have SKIP defined.
1118 # The save variable can be
1119 # defined multiple times and the new one simply overrides
1120 # the prevous one.
1121 set_variable($lvalue, $rvalue);
1122
Steven Rostedta57419b2010-11-02 15:13:54 -04001123 } else {
1124 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001125 }
1126 }
1127
Steven Rostedta57419b2010-11-02 15:13:54 -04001128 if ($test_num) {
1129 $test_num += $repeat - 1;
1130 $opt{"NUM_TESTS"} = $test_num;
1131 }
1132
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001133 close($in);
1134
1135 $$current_test_num = $test_num;
1136
1137 return $test_case;
1138}
1139
Steven Rostedtc4261d02011-11-23 13:41:18 -05001140sub get_test_case {
1141 print "What test case would you like to run?\n";
1142 print " (build, install or boot)\n";
1143 print " Other tests are available but require editing the config file\n";
1144 my $ans = <STDIN>;
1145 chomp $ans;
1146 $default{"TEST_TYPE"} = $ans;
1147}
1148
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001149sub read_config {
1150 my ($config) = @_;
1151
1152 my $test_case;
1153 my $test_num = 0;
1154
1155 $test_case = __read_config $config, \$test_num;
1156
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001157 # make sure we have all mandatory configs
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09001158 get_mandatory_configs;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001159
Steven Rostedt0df213c2011-06-14 20:51:37 -04001160 # was a test specified?
1161 if (!$test_case) {
1162 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001163 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001164 }
1165
Steven Rostedta75fece2010-11-02 14:58:27 -04001166 # set any defaults
1167
1168 foreach my $default (keys %default) {
1169 if (!defined($opt{$default})) {
1170 $opt{$default} = $default{$default};
1171 }
1172 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001173
1174 if ($opt{"IGNORE_UNUSED"} == 1) {
1175 return;
1176 }
1177
1178 my %not_used;
1179
1180 # check if there are any stragglers (typos?)
1181 foreach my $option (keys %opt) {
1182 my $op = $option;
1183 # remove per test labels.
1184 $op =~ s/\[.*\]//;
1185 if (!exists($option_map{$op}) &&
1186 !exists($default{$op}) &&
1187 !exists($used_options{$op})) {
1188 $not_used{$op} = 1;
1189 }
1190 }
1191
1192 if (%not_used) {
1193 my $s = "s are";
1194 $s = " is" if (keys %not_used == 1);
1195 print "The following option$s not used; could be a typo:\n";
1196 foreach my $option (keys %not_used) {
1197 print "$option\n";
1198 }
1199 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1200 if (!read_yn "Do you want to continue?") {
1201 exit -1;
1202 }
1203 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001204}
1205
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001206sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001207 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001208
1209 # Add space to evaluate the character before $
1210 $option = " $option";
1211 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301212 my $repeated = 0;
1213 my $parent = 0;
1214
1215 foreach my $test (keys %repeat_tests) {
1216 if ($i >= $test &&
1217 $i < $test + $repeat_tests{$test}) {
1218
1219 $repeated = 1;
1220 $parent = $test;
1221 last;
1222 }
1223 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001224
1225 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1226 my $start = $1;
1227 my $var = $2;
1228 my $end = $3;
1229
1230 # Append beginning of line
1231 $retval = "$retval$start";
1232
1233 # If the iteration option OPT[$i] exists, then use that.
1234 # otherwise see if the default OPT (without [$i]) exists.
1235
1236 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301237 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001238
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001239 # If a variable contains itself, use the default var
1240 if (($var eq $name) && defined($opt{$var})) {
1241 $o = $opt{$var};
1242 $retval = "$retval$o";
1243 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001244 $o = $opt{$o};
1245 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301246 } elsif ($repeated && defined($opt{$parento})) {
1247 $o = $opt{$parento};
1248 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001249 } elsif (defined($opt{$var})) {
1250 $o = $opt{$var};
1251 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001252 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1253 # special option KERNEL_VERSION uses kernel version
1254 get_version();
1255 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001256 } else {
1257 $retval = "$retval\$\{$var\}";
1258 }
1259
1260 $option = $end;
1261 }
1262
1263 $retval = "$retval$option";
1264
1265 $retval =~ s/^ //;
1266
1267 return $retval;
1268}
1269
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001270sub process_evals {
1271 my ($name, $option, $i) = @_;
1272
1273 my $option_name = "$name\[$i\]";
1274 my $ev;
1275
1276 my $old_option = $option;
1277
1278 if (defined($evals{$option_name})) {
1279 $ev = $evals{$option_name};
1280 } elsif (defined($evals{$name})) {
1281 $ev = $evals{$name};
1282 } else {
1283 return $option;
1284 }
1285
1286 for my $e (@{$ev}) {
1287 eval "\$option =~ $e";
1288 }
1289
1290 if ($option ne $old_option) {
1291 doprint("$name changed from '$old_option' to '$option'\n");
1292 }
1293
1294 return $option;
1295}
1296
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001297sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001298 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001299
1300 my $prev = "";
1301
1302 # Since an option can evaluate to another option,
1303 # keep iterating until we do not evaluate any more
1304 # options.
1305 my $r = 0;
1306 while ($prev ne $option) {
1307 # Check for recursive evaluations.
1308 # 100 deep should be more than enough.
1309 if ($r++ > 100) {
1310 die "Over 100 evaluations accurred with $option\n" .
1311 "Check for recursive variables\n";
1312 }
1313 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001314 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001315 }
1316
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001317 $option = process_evals($name, $option, $i);
1318
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001319 return $option;
1320}
1321
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001322sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001323sub start_monitor;
1324sub end_monitor;
1325sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001326
1327sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001328 my ($time) = @_;
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001329 my $powercycle = 0;
Andrew Jones2728be42011-08-12 15:32:05 +02001330
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001331 # test if the machine can be connected to within 5 seconds
1332 my $stat = run_ssh("echo check machine status", 5);
1333 if (!$stat) {
1334 doprint("power cycle\n");
1335 $powercycle = 1;
1336 }
Steven Rostedta4968722012-12-11 14:59:05 -05001337
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001338 if ($powercycle) {
1339 run_command "$power_cycle";
1340
Steven Rostedt2b803362011-09-30 18:00:23 -04001341 start_monitor;
1342 # flush out current monitor
1343 # May contain the reboot success line
1344 wait_for_monitor 1;
Steven Rostedt2b803362011-09-30 18:00:23 -04001345
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001346 } else {
1347 # Make sure everything has been written to disk
1348 run_ssh("sync");
1349
1350 if (defined($time)) {
1351 start_monitor;
1352 # flush out current monitor
1353 # May contain the reboot success line
1354 wait_for_monitor 1;
1355 }
1356
1357 # try to reboot normally
1358 if (run_command $reboot) {
1359 if (defined($powercycle_after_reboot)) {
1360 sleep $powercycle_after_reboot;
1361 run_command "$power_cycle";
1362 }
1363 } else {
1364 # nope? power cycle it.
Steven Rostedt576f6272010-11-02 14:58:38 -04001365 run_command "$power_cycle";
1366 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001367 }
Andrew Jones2728be42011-08-12 15:32:05 +02001368
1369 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001370
1371 # We only want to get to the new kernel, don't fail
1372 # if we stumble over a call trace.
1373 my $save_ignore_errors = $ignore_errors;
1374 $ignore_errors = 1;
1375
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001376 # Look for the good kernel to boot
1377 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001378 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001379 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001380 run_command "$power_cycle";
1381 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001382
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001383 $ignore_errors = $save_ignore_errors;
1384
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001385 # Still need to wait for the reboot to finish
1386 wait_for_monitor($time, $reboot_success_line);
1387
Andrew Jones2728be42011-08-12 15:32:05 +02001388 end_monitor;
1389 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001390}
1391
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001392sub reboot_to_good {
1393 my ($time) = @_;
1394
1395 if (defined($switch_to_good)) {
1396 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001397 }
1398
1399 reboot $time;
1400}
1401
Steven Rostedt576f6272010-11-02 14:58:38 -04001402sub do_not_reboot {
1403 my $i = $iteration;
1404
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001405 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001406 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1407 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1408}
1409
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001410sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001411 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001412
Steven Rostedt576f6272010-11-02 14:58:38 -04001413 my $i = $iteration;
1414
1415 if ($reboot_on_error && !do_not_reboot) {
1416
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001417 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001418 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001419
Steven Rostedta75fece2010-11-02 14:58:27 -04001420 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001421 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001422 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001423 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001424
Steven Rostedtf80802c2011-03-07 13:18:47 -05001425 if (defined($opt{"LOG_FILE"})) {
1426 print " See $opt{LOG_FILE} for more info.\n";
1427 }
1428
Josh Poimboeuf1cb9e642015-01-29 20:54:53 -06001429 if ($monitor_cnt) {
1430 # restore terminal settings
1431 system("stty $stty_orig");
1432 }
1433
Steven Rostedt (VMware)2e07c9f2017-02-07 11:49:21 -05001434 if (defined($post_test)) {
1435 run_command $post_test;
1436 }
1437
Steven Rostedt576f6272010-11-02 14:58:38 -04001438 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001439}
1440
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001441sub create_pty {
1442 my ($ptm, $pts) = @_;
1443 my $tmp;
1444 my $TIOCSPTLCK = 0x40045431;
1445 my $TIOCGPTN = 0x80045430;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001446
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001447 sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
1448 dodie "Cant open /dev/ptmx";
1449
1450 # unlockpt()
1451 $tmp = pack("i", 0);
1452 ioctl($ptm, $TIOCSPTLCK, $tmp) or
1453 dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
1454
1455 # ptsname()
1456 ioctl($ptm, $TIOCGPTN, $tmp) or
1457 dodie "ioctl TIOCGPTN for /dev/ptmx failed";
1458 $tmp = unpack("i", $tmp);
1459
1460 sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
1461 dodie "Can't open /dev/pts/$tmp";
1462}
1463
1464sub exec_console {
1465 my ($ptm, $pts) = @_;
1466
1467 close($ptm);
1468
1469 close(\*STDIN);
1470 close(\*STDOUT);
1471 close(\*STDERR);
1472
1473 open(\*STDIN, '<&', $pts);
1474 open(\*STDOUT, '>&', $pts);
1475 open(\*STDERR, '>&', $pts);
1476
1477 close($pts);
1478
1479 exec $console or
Josh Poimboeuf1cb9e642015-01-29 20:54:53 -06001480 die "Can't open console $console";
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001481}
1482
1483sub open_console {
1484 my ($ptm) = @_;
1485 my $pts = \*PTSFD;
1486 my $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001487
Josh Poimboeuf98842782015-01-27 12:10:04 -06001488 # save terminal settings
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001489 $stty_orig = `stty -g`;
1490
1491 # place terminal in cbreak mode so that stdin can be read one character at
1492 # a time without having to wait for a newline
1493 system("stty -icanon -echo -icrnl");
Josh Poimboeuf98842782015-01-27 12:10:04 -06001494
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001495 create_pty($ptm, $pts);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001496
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001497 $pid = fork;
1498
1499 if (!$pid) {
1500 # child
1501 exec_console($ptm, $pts)
1502 }
1503
1504 # parent
1505 close($pts);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001506
1507 return $pid;
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001508
1509 open(PTSFD, "Stop perl from warning about single use of PTSFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001510}
1511
1512sub close_console {
1513 my ($fp, $pid) = @_;
1514
1515 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001516 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001517
1518 print "closing!\n";
1519 close($fp);
Josh Poimboeuf98842782015-01-27 12:10:04 -06001520
1521 # restore terminal settings
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001522 system("stty $stty_orig");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001523}
1524
1525sub start_monitor {
1526 if ($monitor_cnt++) {
1527 return;
1528 }
1529 $monitor_fp = \*MONFD;
1530 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001531
1532 return;
1533
1534 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001535}
1536
1537sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001538 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001539 if (--$monitor_cnt) {
1540 return;
1541 }
1542 close_console($monitor_fp, $monitor_pid);
1543}
1544
1545sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001546 my ($time, $stop) = @_;
1547 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001548 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001549 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001550 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001551 my $skip_call_trace = 0;
1552 my $bug = 0;
1553 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001554 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001555
Steven Rostedta75fece2010-11-02 14:58:27 -04001556 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001557
1558 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001559 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001560 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001561 last if (!defined($line));
1562 print "$line";
1563 $full_line .= $line;
1564
1565 if (defined($stop) && $full_line =~ /$stop/) {
1566 doprint "wait for monitor detected $stop\n";
1567 $booted = 1;
1568 }
1569
Steven Rostedt8a80c722012-07-19 16:08:33 -04001570 if ($full_line =~ /\[ backtrace testing \]/) {
1571 $skip_call_trace = 1;
1572 }
1573
1574 if ($full_line =~ /call trace:/i) {
1575 if (!$bug && !$skip_call_trace) {
1576 if ($ignore_errors) {
1577 $bug_ignored = 1;
1578 } else {
1579 $bug = 1;
1580 }
1581 }
1582 }
1583
1584 if ($full_line =~ /\[ end of backtrace testing \]/) {
1585 $skip_call_trace = 0;
1586 }
1587
1588 if ($full_line =~ /Kernel panic -/) {
1589 $bug = 1;
1590 }
1591
Steven Rostedt2b803362011-09-30 18:00:23 -04001592 if ($line =~ /\n/) {
1593 $full_line = "";
1594 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001595 $now = time;
1596 if ($now - $start_time >= $max_monitor_wait) {
1597 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1598 return 1;
1599 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001600 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001601 print "** Monitor flushed **\n";
Steven Rostedt (Red Hat)995bc432014-10-07 16:31:07 -04001602
1603 # if stop is defined but wasn't hit, return error
1604 # used by reboot (which wants to see a reboot)
1605 if (defined($stop) && !$booted) {
1606 $bug = 1;
1607 }
Steven Rostedt8a80c722012-07-19 16:08:33 -04001608 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001609}
1610
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301611sub save_logs {
1612 my ($result, $basedir) = @_;
1613 my @t = localtime;
1614 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1615 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1616
1617 my $type = $build_type;
1618 if ($type =~ /useconfig/) {
1619 $type = "useconfig";
1620 }
1621
1622 my $dir = "$machine-$test_type-$type-$result-$date";
1623
1624 $dir = "$basedir/$dir";
1625
1626 if (!-d $dir) {
1627 mkpath($dir) or
1628 die "can't create $dir";
1629 }
1630
1631 my %files = (
1632 "config" => $output_config,
1633 "buildlog" => $buildlog,
1634 "dmesg" => $dmesg,
1635 "testlog" => $testlog,
1636 );
1637
1638 while (my ($name, $source) = each(%files)) {
1639 if (-f "$source") {
1640 cp "$source", "$dir/$name" or
1641 die "failed to copy $source";
1642 }
1643 }
1644
1645 doprint "*** Saved info to $dir ***\n";
1646}
1647
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001648sub fail {
1649
Steven Rostedta75fece2010-11-02 14:58:27 -04001650 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001651 dodie @_;
1652 }
1653
Steven Rostedta75fece2010-11-02 14:58:27 -04001654 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001655
Steven Rostedt576f6272010-11-02 14:58:38 -04001656 my $i = $iteration;
1657
Steven Rostedta75fece2010-11-02 14:58:27 -04001658 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001659 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001660 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001661 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001662 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001663
Steven Rostedt9064af52011-06-13 10:38:48 -04001664 my $name = "";
1665
1666 if (defined($test_name)) {
1667 $name = " ($test_name)";
1668 }
1669
Steven Rostedt (Red Hat)4bf6e1f2015-01-29 10:06:07 -05001670 print_times;
1671
Steven Rostedt576f6272010-11-02 14:58:38 -04001672 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1673 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001674 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001675 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1676 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001677
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301678 if (defined($store_failures)) {
1679 save_logs "fail", $store_failures;
1680 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001681
Steven Rostedt (VMware)2e07c9f2017-02-07 11:49:21 -05001682 if (defined($post_test)) {
1683 run_command $post_test;
1684 }
1685
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001686 return 1;
1687}
1688
Steven Rostedt2545eb62010-11-02 15:01:32 -04001689sub run_command {
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001690 my ($command, $redirect, $timeout) = @_;
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001691 my $start_time;
1692 my $end_time;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001693 my $dolog = 0;
1694 my $dord = 0;
1695 my $pid;
1696
Steven Rostedte48c5292010-11-02 14:35:37 -04001697 $command =~ s/\$SSH_USER/$ssh_user/g;
1698 $command =~ s/\$MACHINE/$machine/g;
1699
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001700 doprint("$command ... ");
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001701 $start_time = time;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001702
1703 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001704 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001705
1706 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001707 open(LOG, ">>$opt{LOG_FILE}") or
1708 dodie "failed to write to log";
1709 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001710 }
1711
1712 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001713 open (RD, ">$redirect") or
1714 dodie "failed to write to redirect $redirect";
1715 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001716 }
1717
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001718 my $hit_timeout = 0;
1719
1720 while (1) {
1721 my $fp = \*CMD;
1722 if (defined($timeout)) {
1723 doprint "timeout = $timeout\n";
1724 }
1725 my $line = wait_for_input($fp, $timeout);
1726 if (!defined($line)) {
1727 my $now = time;
1728 if (defined($timeout) && (($now - $start_time) >= $timeout)) {
1729 doprint "Hit timeout of $timeout, killing process\n";
1730 $hit_timeout = 1;
1731 kill 9, $pid;
1732 }
1733 last;
1734 }
1735 print LOG $line if ($dolog);
1736 print RD $line if ($dord);
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001737 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001738
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001739 waitpid($pid, 0);
Steven Rostedt (VMware)57394382017-02-07 14:50:03 -05001740 # shift 8 for real exit status
1741 $run_command_status = $? >> 8;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001742
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001743 close(CMD);
1744 close(LOG) if ($dolog);
1745 close(RD) if ($dord);
1746
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001747 $end_time = time;
1748 my $delta = $end_time - $start_time;
1749
1750 if ($delta == 1) {
1751 doprint "[1 second] ";
1752 } else {
1753 doprint "[$delta seconds] ";
1754 }
1755
Steven Rostedt (VMware)57394382017-02-07 14:50:03 -05001756 if ($hit_timeout) {
1757 $run_command_status = 1;
1758 }
1759
1760 if ($run_command_status) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001761 doprint "FAILED!\n";
1762 } else {
1763 doprint "SUCCESS\n";
1764 }
1765
Steven Rostedt (VMware)57394382017-02-07 14:50:03 -05001766 return !$run_command_status;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001767}
1768
Steven Rostedte48c5292010-11-02 14:35:37 -04001769sub run_ssh {
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001770 my ($cmd, $timeout) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001771 my $cp_exec = $ssh_exec;
1772
1773 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001774 return run_command "$cp_exec", undef , $timeout;
Steven Rostedte48c5292010-11-02 14:35:37 -04001775}
1776
1777sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001778 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001779
1780 $cp_scp =~ s/\$SRC_FILE/$src/g;
1781 $cp_scp =~ s/\$DST_FILE/$dst/g;
1782
1783 return run_command "$cp_scp";
1784}
1785
Steven Rostedt02ad2612012-03-21 08:21:24 -04001786sub run_scp_install {
1787 my ($src, $dst) = @_;
1788
1789 my $cp_scp = $scp_to_target_install;
1790
1791 return run_scp($src, $dst, $cp_scp);
1792}
1793
1794sub run_scp_mod {
1795 my ($src, $dst) = @_;
1796
1797 my $cp_scp = $scp_to_target;
1798
1799 return run_scp($src, $dst, $cp_scp);
1800}
1801
Steven Rostedta15ba912012-11-13 14:30:37 -05001802sub get_grub2_index {
1803
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001804 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001805 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1806 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001807
1808 doprint "Find grub2 menu ... ";
1809 $grub_number = -1;
1810
1811 my $ssh_grub = $ssh_exec;
1812 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1813
1814 open(IN, "$ssh_grub |")
1815 or die "unable to get $grub_file";
1816
1817 my $found = 0;
1818
1819 while (<IN>) {
1820 if (/^menuentry.*$grub_menu/) {
1821 $grub_number++;
1822 $found = 1;
1823 last;
1824 } elsif (/^menuentry\s/) {
1825 $grub_number++;
1826 }
1827 }
1828 close(IN);
1829
1830 die "Could not find '$grub_menu' in $grub_file on $machine"
1831 if (!$found);
1832 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001833 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001834 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001835}
1836
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001837sub get_grub_index {
1838
Steven Rostedta15ba912012-11-13 14:30:37 -05001839 if ($reboot_type eq "grub2") {
1840 get_grub2_index;
1841 return;
1842 }
1843
Steven Rostedta75fece2010-11-02 14:58:27 -04001844 if ($reboot_type ne "grub") {
1845 return;
1846 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001847 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001848 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1849 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001850
1851 doprint "Find grub menu ... ";
1852 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001853
1854 my $ssh_grub = $ssh_exec;
1855 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1856
1857 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001858 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001859
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001860 my $found = 0;
1861
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001862 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001863 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001864 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001865 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001866 last;
1867 } elsif (/^\s*title\s/) {
1868 $grub_number++;
1869 }
1870 }
1871 close(IN);
1872
Steven Rostedta75fece2010-11-02 14:58:27 -04001873 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001874 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001875 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001876 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001877 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001878}
1879
Steven Rostedt2545eb62010-11-02 15:01:32 -04001880sub wait_for_input
1881{
1882 my ($fp, $time) = @_;
Steven Rostedt (VMware)f7c64012017-03-08 10:36:59 -05001883 my $start_time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001884 my $rin;
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001885 my $rout;
1886 my $nr;
1887 my $buf;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001888 my $line;
1889 my $ch;
1890
1891 if (!defined($time)) {
1892 $time = $timeout;
1893 }
1894
1895 $rin = '';
1896 vec($rin, fileno($fp), 1) = 1;
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001897 vec($rin, fileno(\*STDIN), 1) = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001898
Steven Rostedt (VMware)f7c64012017-03-08 10:36:59 -05001899 $start_time = time;
1900
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001901 while (1) {
1902 $nr = select($rout=$rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001903
Steven Rostedt (VMware)f7c64012017-03-08 10:36:59 -05001904 last if ($nr <= 0);
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001905
1906 # copy data from stdin to the console
1907 if (vec($rout, fileno(\*STDIN), 1) == 1) {
Steven Rostedt (VMware)99c014a2017-03-08 10:16:17 -05001908 $nr = sysread(\*STDIN, $buf, 1000);
1909 syswrite($fp, $buf, $nr) if ($nr > 0);
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001910 }
1911
Steven Rostedt (VMware)f7c64012017-03-08 10:36:59 -05001912 # The timeout is based on time waiting for the fp data
1913 if (vec($rout, fileno($fp), 1) != 1) {
1914 last if (defined($time) && (time - $start_time > $time));
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001915 next;
1916 }
1917
1918 $line = "";
1919
1920 # try to read one char at a time
1921 while (sysread $fp, $ch, 1) {
1922 $line .= $ch;
1923 last if ($ch eq "\n");
1924 }
1925
Steven Rostedt (VMware)f7c64012017-03-08 10:36:59 -05001926 last if (!length($line));
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001927
1928 return $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001929 }
Steven Rostedt (VMware)f7c64012017-03-08 10:36:59 -05001930 return undef;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001931}
1932
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001933sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001934 if (defined($switch_to_test)) {
1935 run_command $switch_to_test;
1936 }
1937
Steven Rostedta75fece2010-11-02 14:58:27 -04001938 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001939 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001940 } elsif ($reboot_type eq "grub2") {
1941 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001942 } elsif ($reboot_type eq "syslinux") {
1943 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001944 } elsif (defined $reboot_script) {
1945 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001946 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001947 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001948}
1949
Steven Rostedta57419b2010-11-02 15:13:54 -04001950sub get_sha1 {
1951 my ($commit) = @_;
1952
1953 doprint "git rev-list --max-count=1 $commit ... ";
1954 my $sha1 = `git rev-list --max-count=1 $commit`;
1955 my $ret = $?;
1956
1957 logit $sha1;
1958
1959 if ($ret) {
1960 doprint "FAILED\n";
1961 dodie "Failed to get git $commit";
1962 }
1963
1964 print "SUCCESS\n";
1965
1966 chomp $sha1;
1967
1968 return $sha1;
1969}
1970
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001971sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001972 my $booted = 0;
1973 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001974 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001975 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001976 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001977
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05001978 my $start_time = time;
1979
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001980 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001981
1982 my $line;
1983 my $full_line = "";
1984
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001985 open(DMESG, "> $dmesg") or
1986 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001987
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001988 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001989
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001990 my $success_start;
1991 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001992 my $monitor_start = time;
1993 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001994 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001995
Steven Rostedt2d01b262011-03-08 09:47:54 -05001996 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001997
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001998 if ($bug && defined($stop_after_failure) &&
1999 $stop_after_failure >= 0) {
2000 my $time = $stop_after_failure - (time - $failure_start);
2001 $line = wait_for_input($monitor_fp, $time);
2002 if (!defined($line)) {
2003 doprint "bug timed out after $booted_timeout seconds\n";
2004 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
2005 last;
2006 }
2007 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002008 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04002009 if (!defined($line)) {
2010 my $s = $booted_timeout == 1 ? "" : "s";
2011 doprint "Successful boot found: break after $booted_timeout second$s\n";
2012 last;
2013 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002014 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002015 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04002016 if (!defined($line)) {
2017 my $s = $timeout == 1 ? "" : "s";
2018 doprint "Timed out after $timeout second$s\n";
2019 last;
2020 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002021 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002022
Steven Rostedt2545eb62010-11-02 15:01:32 -04002023 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002024 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002025
2026 # we are not guaranteed to get a full line
2027 $full_line .= $line;
2028
Steven Rostedta75fece2010-11-02 14:58:27 -04002029 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04002030 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002031 $success_start = time;
2032 }
2033
2034 if ($booted && defined($stop_after_success) &&
2035 $stop_after_success >= 0) {
2036 my $now = time;
2037 if ($now - $success_start >= $stop_after_success) {
2038 doprint "Test forced to stop after $stop_after_success seconds after success\n";
2039 last;
2040 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002041 }
2042
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002043 if ($full_line =~ /\[ backtrace testing \]/) {
2044 $skip_call_trace = 1;
2045 }
2046
Steven Rostedt2545eb62010-11-02 15:01:32 -04002047 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04002048 if (!$bug && !$skip_call_trace) {
2049 if ($ignore_errors) {
2050 $bug_ignored = 1;
2051 } else {
2052 $bug = 1;
2053 $failure_start = time;
2054 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002055 }
2056 }
2057
2058 if ($bug && defined($stop_after_failure) &&
2059 $stop_after_failure >= 0) {
2060 my $now = time;
2061 if ($now - $failure_start >= $stop_after_failure) {
2062 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
2063 last;
2064 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002065 }
2066
2067 if ($full_line =~ /\[ end of backtrace testing \]/) {
2068 $skip_call_trace = 0;
2069 }
2070
2071 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05002072 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002073 $bug = 1;
2074 }
2075
Steven Rostedtf1a5b962011-06-13 10:30:00 -04002076 # Detect triple faults by testing the banner
2077 if ($full_line =~ /\bLinux version (\S+).*\n/) {
2078 if ($1 eq $version) {
2079 $version_found = 1;
2080 } elsif ($version_found && $detect_triplefault) {
2081 # We already booted into the kernel we are testing,
2082 # but now we booted into another kernel?
2083 # Consider this a triple fault.
Masanari Iida8b513d02013-05-21 23:13:12 +09002084 doprint "Already booted in Linux kernel $version, but now\n";
Steven Rostedtf1a5b962011-06-13 10:30:00 -04002085 doprint "we booted into Linux kernel $1.\n";
2086 doprint "Assuming that this is a triple fault.\n";
2087 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
2088 last;
2089 }
2090 }
2091
Steven Rostedt2545eb62010-11-02 15:01:32 -04002092 if ($line =~ /\n/) {
2093 $full_line = "";
2094 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05002095
2096 if ($stop_test_after > 0 && !$booted && !$bug) {
2097 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04002098 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05002099 $done = 1;
2100 }
2101 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002102 }
2103
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002104 my $end_time = time;
2105 $reboot_time = $end_time - $start_time;
2106
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002107 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002108
Steven Rostedt2545eb62010-11-02 15:01:32 -04002109 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002110 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04002111 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002112 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002113
Steven Rostedta75fece2010-11-02 14:58:27 -04002114 if (!$booted) {
2115 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04002116 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04002117 }
2118
Steven Rostedt6ca996c2012-03-21 08:18:35 -04002119 if ($bug_ignored) {
2120 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2121 }
2122
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002123 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002124}
2125
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05002126sub eval_kernel_version {
2127 my ($option) = @_;
2128
2129 $option =~ s/\$KERNEL_VERSION/$version/g;
2130
2131 return $option;
2132}
2133
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002134sub do_post_install {
2135
2136 return if (!defined($post_install));
2137
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05002138 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002139 run_command "$cp_post_install" or
2140 dodie "Failed to run post install";
2141}
2142
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05002143# Sometimes the reboot fails, and will hang. We try to ssh to the box
2144# and if we fail, we force another reboot, that should powercycle it.
2145sub test_booted {
2146 if (!run_ssh "echo testing connection") {
2147 reboot $sleep_time;
2148 }
2149}
2150
Steven Rostedt2545eb62010-11-02 15:01:32 -04002151sub install {
2152
Steven Rostedte0a87422011-09-30 17:50:48 -04002153 return if ($no_install);
2154
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002155 my $start_time = time;
2156
Steven Rostedte5c2ec12012-07-19 15:22:05 -04002157 if (defined($pre_install)) {
2158 my $cp_pre_install = eval_kernel_version $pre_install;
2159 run_command "$cp_pre_install" or
2160 dodie "Failed to run pre install";
2161 }
2162
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05002163 my $cp_target = eval_kernel_version $target_image;
2164
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05002165 test_booted;
2166
Steven Rostedt02ad2612012-03-21 08:21:24 -04002167 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002168 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002169
2170 my $install_mods = 0;
2171
2172 # should we process modules?
2173 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002174 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002175 while (<IN>) {
2176 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04002177 if (defined($1)) {
2178 $install_mods = 1;
2179 last;
2180 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002181 }
2182 }
2183 close(IN);
2184
2185 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002186 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002187 doprint "No modules needed\n";
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002188 my $end_time = time;
2189 $install_time = $end_time - $start_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002190 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002191 }
2192
Steven Rostedt627977d2012-03-21 08:16:15 -04002193 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002194 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002195
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002196 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04002197 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002198
Steven Rostedte48c5292010-11-02 14:35:37 -04002199 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002200 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002201
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002202 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04002203 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002204 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002205
Steven Rostedt02ad2612012-03-21 08:21:24 -04002206 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002207 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002208
Steven Rostedta75fece2010-11-02 14:58:27 -04002209 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002210
Steven Rostedte7b13442011-06-14 20:44:36 -04002211 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002212 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002213
Steven Rostedte48c5292010-11-02 14:35:37 -04002214 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002215
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002216 do_post_install;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002217
2218 my $end_time = time;
2219 $install_time = $end_time - $start_time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002220}
2221
Steven Rostedtddf607e2011-06-14 20:49:13 -04002222sub get_version {
2223 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04002224 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002225 doprint "$make kernelrelease ... ";
Steven Rostedt (Red Hat)17150fe2014-11-23 15:13:44 -05002226 $version = `$make -s kernelrelease | tail -1`;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002227 chomp($version);
2228 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002229 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002230}
2231
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05002232sub start_monitor_and_install {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002233 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002234
2235 # Install bisects, don't need console
2236 if (defined $console) {
2237 start_monitor;
2238 wait_for_monitor 5;
2239 end_monitor;
2240 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002241
Steven Rostedtddf607e2011-06-14 20:49:13 -04002242 get_grub_index;
2243 get_version;
2244 install;
2245
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002246 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002247 return monitor;
2248}
2249
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002250my $check_build_re = ".*:.*(warning|error|Error):.*";
2251my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2252
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002253sub process_warning_line {
2254 my ($line) = @_;
2255
2256 chomp $line;
2257
2258 # for distcc heterogeneous systems, some compilers
2259 # do things differently causing warning lines
2260 # to be slightly different. This makes an attempt
2261 # to fixe those issues.
2262
2263 # chop off the index into the line
2264 # using distcc, some compilers give different indexes
2265 # depending on white space
2266 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2267
2268 # Some compilers use UTF-8 extended for quotes and some don't.
2269 $line =~ s/$utf8_quote/'/g;
2270
2271 return $line;
2272}
2273
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002274# Read buildlog and check against warnings file for any
2275# new warnings.
2276#
2277# Returns 1 if OK
2278# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002279sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002280 return 1 if (!defined $warnings_file);
2281
2282 my %warnings_list;
2283
2284 # Failed builds should not reboot the target
2285 my $save_no_reboot = $no_reboot;
2286 $no_reboot = 1;
2287
2288 if (-f $warnings_file) {
2289 open(IN, $warnings_file) or
2290 dodie "Error opening $warnings_file";
2291
2292 while (<IN>) {
2293 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002294 my $warning = process_warning_line $_;
2295
2296 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002297 }
2298 }
2299 close(IN);
2300 }
2301
2302 # If warnings file didn't exist, and WARNINGS_FILE exist,
2303 # then we fail on any warning!
2304
2305 open(IN, $buildlog) or dodie "Can't open $buildlog";
2306 while (<IN>) {
2307 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002308 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002309
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002310 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002311 fail "New warning found (not in $warnings_file)\n$_\n";
2312 $no_reboot = $save_no_reboot;
2313 return 0;
2314 }
2315 }
2316 }
2317 $no_reboot = $save_no_reboot;
2318 close(IN);
2319}
2320
2321sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002322 my ($patch) = @_;
2323
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002324 my @files = `git show $patch | diffstat -l`;
2325
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002326 foreach my $file (@files) {
2327 chomp $file;
2328 }
2329
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002330 open(IN, "git show $patch |") or
2331 dodie "failed to show $patch";
2332 while (<IN>) {
2333 if (m,^--- a/(.*),) {
2334 chomp $1;
2335 $files[$#files] = $1;
2336 }
2337 }
2338 close(IN);
2339
2340 open(IN, $buildlog) or dodie "Can't open $buildlog";
2341 while (<IN>) {
2342 if (/^\s*(.*?):.*(warning|error)/) {
2343 my $err = $1;
2344 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002345 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002346 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002347 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002348 }
2349 }
2350 }
2351 }
2352 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002353
2354 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002355}
2356
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002357sub apply_min_config {
2358 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002359
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002360 # Read the config file and remove anything that
2361 # is in the force_config hash (from minconfig and others)
2362 # then add the force config back.
2363
2364 doprint "Applying minimum configurations into $output_config.new\n";
2365
2366 open (OUT, ">$outconfig") or
2367 dodie "Can't create $outconfig";
2368
2369 if (-f $output_config) {
2370 open (IN, $output_config) or
2371 dodie "Failed to open $output_config";
2372 while (<IN>) {
2373 if (/^(# )?(CONFIG_[^\s=]*)/) {
2374 next if (defined($force_config{$2}));
2375 }
2376 print OUT;
2377 }
2378 close IN;
2379 }
2380 foreach my $config (keys %force_config) {
2381 print OUT "$force_config{$config}\n";
2382 }
2383 close OUT;
2384
2385 run_command "mv $outconfig $output_config";
2386}
2387
2388sub make_oldconfig {
2389
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002390 my @force_list = keys %force_config;
2391
2392 if ($#force_list >= 0) {
2393 apply_min_config;
2394 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002395
Adam Leefb16d892012-09-01 01:05:17 +08002396 if (!run_command "$make olddefconfig") {
2397 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002398 # try oldnoconfig
2399 doprint "olddefconfig failed, trying make oldnoconfig\n";
2400 if (!run_command "$make oldnoconfig") {
2401 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2402 # try a yes '' | oldconfig
2403 run_command "yes '' | $make oldconfig" or
2404 dodie "failed make config oldconfig";
2405 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002406 }
2407}
2408
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002409# read a config file and use this to force new configs.
2410sub load_force_config {
2411 my ($config) = @_;
2412
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002413 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002414 open(IN, $config) or
2415 dodie "failed to read $config";
2416 while (<IN>) {
2417 chomp;
2418 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2419 $force_config{$1} = $_;
2420 } elsif (/^# (CONFIG_\S*) is not set/) {
2421 $force_config{$1} = $_;
2422 }
2423 }
2424 close IN;
2425}
2426
Steven Rostedt2545eb62010-11-02 15:01:32 -04002427sub build {
2428 my ($type) = @_;
2429
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002430 unlink $buildlog;
2431
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002432 my $start_time = time;
2433
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002434 # Failed builds should not reboot the target
2435 my $save_no_reboot = $no_reboot;
2436 $no_reboot = 1;
2437
Steven Rostedt683a3e62012-05-18 13:34:35 -04002438 # Calculate a new version from here.
2439 $have_version = 0;
2440
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002441 if (defined($pre_build)) {
2442 my $ret = run_command $pre_build;
2443 if (!$ret && defined($pre_build_die) &&
2444 $pre_build_die) {
2445 dodie "failed to pre_build\n";
2446 }
2447 }
2448
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002449 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002450 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002451 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002452
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002453 $type = "oldconfig";
2454 }
2455
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002456 # old config can ask questions
2457 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002458 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002459
2460 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002461 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002462
Andrew Jones13488232011-08-12 15:32:04 +02002463 if (!$noclean) {
2464 run_command "mv $output_config $outputdir/config_temp" or
2465 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002466
Andrew Jones13488232011-08-12 15:32:04 +02002467 run_command "$make mrproper" or dodie "make mrproper";
2468
2469 run_command "mv $outputdir/config_temp $output_config" or
2470 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002471 }
2472
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002473 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002474 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002475 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002476 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002477 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002478
2479 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002480 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2481 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002482 close(OUT);
2483
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002484 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002485 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002486 }
2487
Adam Leefb16d892012-09-01 01:05:17 +08002488 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002489 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002490 dodie "failed make config";
2491 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002492 # Run old config regardless, to enforce min configurations
2493 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002494
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002495 my $build_ret = run_command "$make $build_options", $buildlog;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002496
2497 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002498 # Because a post build may change the kernel version
2499 # do it now.
2500 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002501 my $ret = run_command $post_build;
2502 if (!$ret && defined($post_build_die) &&
2503 $post_build_die) {
2504 dodie "failed to post_build\n";
2505 }
2506 }
2507
2508 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002509 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002510 if ($in_bisect) {
2511 $no_reboot = $save_no_reboot;
2512 return 0;
2513 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002514 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002515 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002516
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002517 $no_reboot = $save_no_reboot;
2518
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002519 my $end_time = time;
2520 $build_time = $end_time - $start_time;
2521
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002522 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002523}
2524
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002525sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002526 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002527 if (defined($poweroff_after_halt)) {
2528 sleep $poweroff_after_halt;
2529 run_command "$power_off";
2530 }
2531 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002532 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002533 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002534 }
2535}
2536
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002537sub success {
2538 my ($i) = @_;
2539
Steven Rostedte48c5292010-11-02 14:35:37 -04002540 $successes++;
2541
Steven Rostedt9064af52011-06-13 10:38:48 -04002542 my $name = "";
2543
2544 if (defined($test_name)) {
2545 $name = " ($test_name)";
2546 }
2547
Steven Rostedt (Red Hat)4bf6e1f2015-01-29 10:06:07 -05002548 print_times;
2549
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002550 doprint "\n\n*******************************************\n";
2551 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002552 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002553 doprint "*******************************************\n";
2554 doprint "*******************************************\n";
2555
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302556 if (defined($store_successes)) {
2557 save_logs "success", $store_successes;
2558 }
2559
Steven Rostedt576f6272010-11-02 14:58:38 -04002560 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002561 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002562 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002563 }
Steven Rostedt (VMware)2e07c9f2017-02-07 11:49:21 -05002564
2565 if (defined($post_test)) {
2566 run_command $post_test;
2567 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002568}
2569
Steven Rostedtc960bb92011-03-08 09:22:39 -05002570sub answer_bisect {
2571 for (;;) {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002572 doprint "Pass, fail, or skip? [p/f/s]";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002573 my $ans = <STDIN>;
2574 chomp $ans;
2575 if ($ans eq "p" || $ans eq "P") {
2576 return 1;
2577 } elsif ($ans eq "f" || $ans eq "F") {
2578 return 0;
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002579 } elsif ($ans eq "s" || $ans eq "S") {
2580 return -1;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002581 } else {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002582 print "Please answer 'p', 'f', or 's'\n";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002583 }
2584 }
2585}
2586
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002587sub child_run_test {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002588
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002589 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002590 $reboot_on_error = 0;
2591 $poweroff_on_error = 0;
2592 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002593
Steven Rostedt (VMware)57394382017-02-07 14:50:03 -05002594 run_command $run_test, $testlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302595
Steven Rostedt (VMware)57394382017-02-07 14:50:03 -05002596 exit $run_command_status;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002597}
2598
2599my $child_done;
2600
2601sub child_finished {
2602 $child_done = 1;
2603}
2604
2605sub do_run_test {
2606 my $child_pid;
2607 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002608 my $line;
2609 my $full_line;
2610 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002611 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002612
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002613 my $start_time = time;
2614
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002615 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002616
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002617 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002618
2619 $child_done = 0;
2620
2621 $SIG{CHLD} = qw(child_finished);
2622
2623 $child_pid = fork;
2624
2625 child_run_test if (!$child_pid);
2626
2627 $full_line = "";
2628
2629 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002630 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002631 if (defined($line)) {
2632
2633 # we are not guaranteed to get a full line
2634 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002635 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002636
2637 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002638 if ($ignore_errors) {
2639 $bug_ignored = 1;
2640 } else {
2641 $bug = 1;
2642 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002643 }
2644
2645 if ($full_line =~ /Kernel panic -/) {
2646 $bug = 1;
2647 }
2648
2649 if ($line =~ /\n/) {
2650 $full_line = "";
2651 }
2652 }
2653 } while (!$child_done && !$bug);
2654
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002655 if (!$bug && $bug_ignored) {
2656 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2657 }
2658
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002659 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002660 my $failure_start = time;
2661 my $now;
2662 do {
2663 $line = wait_for_input($monitor_fp, 1);
2664 if (defined($line)) {
2665 doprint $line;
2666 }
2667 $now = time;
2668 if ($now - $failure_start >= $stop_after_failure) {
2669 last;
2670 }
2671 } while (defined($line));
2672
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002673 doprint "Detected kernel crash!\n";
2674 # kill the child with extreme prejudice
2675 kill 9, $child_pid;
2676 }
2677
2678 waitpid $child_pid, 0;
Steven Rostedt (VMware)32677202017-02-07 12:05:25 -05002679 $child_exit = $? >> 8;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002680
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002681 my $end_time = time;
2682 $test_time = $end_time - $start_time;
2683
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002684 if (!$bug && $in_bisect) {
2685 if (defined($bisect_ret_good)) {
2686 if ($child_exit == $bisect_ret_good) {
2687 return 1;
2688 }
2689 }
2690 if (defined($bisect_ret_skip)) {
2691 if ($child_exit == $bisect_ret_skip) {
2692 return -1;
2693 }
2694 }
2695 if (defined($bisect_ret_abort)) {
2696 if ($child_exit == $bisect_ret_abort) {
2697 fail "test abort" and return -2;
2698 }
2699 }
2700 if (defined($bisect_ret_bad)) {
2701 if ($child_exit == $bisect_ret_skip) {
2702 return 0;
2703 }
2704 }
2705 if (defined($bisect_ret_default)) {
2706 if ($bisect_ret_default eq "good") {
2707 return 1;
2708 } elsif ($bisect_ret_default eq "bad") {
2709 return 0;
2710 } elsif ($bisect_ret_default eq "skip") {
2711 return -1;
2712 } elsif ($bisect_ret_default eq "abort") {
2713 return -2;
2714 } else {
2715 fail "unknown default action: $bisect_ret_default"
2716 and return -2;
2717 }
2718 }
2719 }
2720
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002721 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002722 return 0 if $in_bisect;
2723 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002724 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002725 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002726}
2727
Steven Rostedta75fece2010-11-02 14:58:27 -04002728sub run_git_bisect {
2729 my ($command) = @_;
2730
2731 doprint "$command ... ";
2732
2733 my $output = `$command 2>&1`;
2734 my $ret = $?;
2735
2736 logit $output;
2737
2738 if ($ret) {
2739 doprint "FAILED\n";
2740 dodie "Failed to git bisect";
2741 }
2742
2743 doprint "SUCCESS\n";
2744 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2745 doprint "$1 [$2]\n";
2746 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002747 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002748 doprint "Found bad commit... $1\n";
2749 return 0;
2750 } else {
2751 # we already logged it, just print it now.
2752 print $output;
2753 }
2754
2755 return 1;
2756}
2757
Steven Rostedtc23dca72011-03-08 09:26:31 -05002758sub bisect_reboot {
2759 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002760 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002761}
2762
2763# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002764sub run_bisect_test {
2765 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002766
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002767 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002768 my $result;
2769 my $output;
2770 my $ret;
2771
Steven Rostedt0a05c762010-11-08 11:14:10 -05002772 $in_bisect = 1;
2773
2774 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002775
2776 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002777 if ($failed && $bisect_skip) {
2778 $in_bisect = 0;
2779 return -1;
2780 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002781 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002782
2783 # Now boot the box
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05002784 start_monitor_and_install or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002785
2786 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002787 if ($failed && $bisect_skip) {
2788 end_monitor;
2789 bisect_reboot;
2790 $in_bisect = 0;
2791 return -1;
2792 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002793 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002794
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002795 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002796 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002797 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002798 }
2799
2800 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002801 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002802 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002803 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002804 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002805
2806 # reboot the box to a kernel we can ssh to
2807 if ($type ne "build") {
2808 bisect_reboot;
2809 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002810 $in_bisect = 0;
2811
2812 return $result;
2813}
2814
2815sub run_bisect {
2816 my ($type) = @_;
2817 my $buildtype = "oldconfig";
2818
2819 # We should have a minconfig to use?
2820 if (defined($minconfig)) {
2821 $buildtype = "useconfig:$minconfig";
2822 }
2823
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002824 # If the user sets bisect_tries to less than 1, then no tries
2825 # is a success.
2826 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002827
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002828 # Still let the user manually decide that though.
2829 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002830 $ret = answer_bisect;
2831 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002832
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002833 for (my $i = 0; $i < $bisect_tries; $i++) {
2834 if ($bisect_tries > 1) {
2835 my $t = $i + 1;
2836 doprint("Running bisect trial $t of $bisect_tries:\n");
2837 }
2838 $ret = run_bisect_test $type, $buildtype;
2839
2840 if ($bisect_manual) {
2841 $ret = answer_bisect;
2842 }
2843
2844 last if (!$ret);
2845 }
2846
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002847 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002848 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002849 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002850 }
2851
Steven Rostedtc23dca72011-03-08 09:26:31 -05002852 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002853 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002854 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002855 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002856 } elsif ($bisect_skip) {
2857 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2858 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002859 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002860}
2861
Steven Rostedtdad98752011-11-22 20:48:57 -05002862sub update_bisect_replay {
2863 my $tmp_log = "$tmpdir/ktest_bisect_log";
2864 run_command "git bisect log > $tmp_log" or
2865 die "can't create bisect log";
2866 return $tmp_log;
2867}
2868
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002869sub bisect {
2870 my ($i) = @_;
2871
2872 my $result;
2873
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002874 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2875 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2876 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002877
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002878 my $good = $bisect_good;
2879 my $bad = $bisect_bad;
2880 my $type = $bisect_type;
2881 my $start = $bisect_start;
2882 my $replay = $bisect_replay;
2883 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002884
2885 if (defined($start_files)) {
2886 $start_files = " -- " . $start_files;
2887 } else {
2888 $start_files = "";
2889 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002890
Steven Rostedta57419b2010-11-02 15:13:54 -04002891 # convert to true sha1's
2892 $good = get_sha1($good);
2893 $bad = get_sha1($bad);
2894
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002895 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002896 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2897 $reverse_bisect = 1;
2898 } else {
2899 $reverse_bisect = 0;
2900 }
2901
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002902 # Can't have a test without having a test to run
2903 if ($type eq "test" && !defined($run_test)) {
2904 $type = "boot";
2905 }
2906
Steven Rostedtdad98752011-11-22 20:48:57 -05002907 # Check if a bisect was running
2908 my $bisect_start_file = "$builddir/.git/BISECT_START";
2909
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002910 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002911 my $do_check = defined($check) && $check ne "0";
2912
2913 if ( -f $bisect_start_file ) {
2914 print "Bisect in progress found\n";
2915 if ($do_check) {
2916 print " If you say yes, then no checks of good or bad will be done\n";
2917 }
2918 if (defined($replay)) {
2919 print "** BISECT_REPLAY is defined in config file **";
2920 print " Ignore config option and perform new git bisect log?\n";
2921 if (read_ync " (yes, no, or cancel) ") {
2922 $replay = update_bisect_replay;
2923 $do_check = 0;
2924 }
2925 } elsif (read_yn "read git log and continue?") {
2926 $replay = update_bisect_replay;
2927 $do_check = 0;
2928 }
2929 }
2930
2931 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002932
2933 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002934 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002935
2936 if ($check ne "good") {
2937 doprint "TESTING BISECT BAD [$bad]\n";
2938 run_command "git checkout $bad" or
2939 die "Failed to checkout $bad";
2940
2941 $result = run_bisect $type;
2942
2943 if ($result ne "bad") {
2944 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2945 }
2946 }
2947
2948 if ($check ne "bad") {
2949 doprint "TESTING BISECT GOOD [$good]\n";
2950 run_command "git checkout $good" or
2951 die "Failed to checkout $good";
2952
2953 $result = run_bisect $type;
2954
2955 if ($result ne "good") {
2956 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2957 }
2958 }
2959
2960 # checkout where we started
2961 run_command "git checkout $head" or
2962 die "Failed to checkout $head";
2963 }
2964
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002965 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002966 dodie "could not start bisect";
2967
Steven Rostedta75fece2010-11-02 14:58:27 -04002968 if (defined($replay)) {
2969 run_command "git bisect replay $replay" or
2970 dodie "failed to run replay";
Steven Rostedt (Red Hat)d832d742014-10-07 16:34:25 -04002971 } else {
2972
2973 run_command "git bisect good $good" or
2974 dodie "could not set bisect good to $good";
2975
2976 run_git_bisect "git bisect bad $bad" or
2977 dodie "could not set bisect bad to $bad";
2978
Steven Rostedta75fece2010-11-02 14:58:27 -04002979 }
2980
2981 if (defined($start)) {
2982 run_command "git checkout $start" or
2983 dodie "failed to checkout $start";
2984 }
2985
2986 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002987 do {
2988 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002989 $test = run_git_bisect "git bisect $result";
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002990 print_times;
Steven Rostedta75fece2010-11-02 14:58:27 -04002991 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002992
2993 run_command "git bisect log" or
2994 dodie "could not capture git bisect log";
2995
2996 run_command "git bisect reset" or
2997 dodie "could not reset git bisect";
2998
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002999 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003000
Steven Rostedt0a05c762010-11-08 11:14:10 -05003001 success $i;
3002}
3003
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003004# config_ignore holds the configs that were set (or unset) for
3005# a good config and we will ignore these configs for the rest
3006# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003007my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003008
3009# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003010my %config_set;
3011
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003012# config_off holds the set of configs that the bad config had disabled.
3013# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08003014# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003015my %config_off;
3016
3017# config_off_tmp holds a set of configs to turn off for now
3018my @config_off_tmp;
3019
3020# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05003021my %config_list;
3022my %null_config;
3023
3024my %dependency;
3025
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003026sub assign_configs {
3027 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003028
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003029 doprint "Reading configs from $config\n";
3030
Steven Rostedt0a05c762010-11-08 11:14:10 -05003031 open (IN, $config)
3032 or dodie "Failed to read $config";
3033
3034 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003035 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04003036 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003037 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003038 } elsif (/^(# (CONFIG\S*) is not set)/) {
3039 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003040 }
3041 }
3042
3043 close(IN);
3044}
3045
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003046sub process_config_ignore {
3047 my ($config) = @_;
3048
3049 assign_configs \%config_ignore, $config;
3050}
3051
Steven Rostedt0a05c762010-11-08 11:14:10 -05003052sub get_dependencies {
3053 my ($config) = @_;
3054
3055 my $arr = $dependency{$config};
3056 if (!defined($arr)) {
3057 return ();
3058 }
3059
3060 my @deps = @{$arr};
3061
3062 foreach my $dep (@{$arr}) {
3063 print "ADD DEP $dep\n";
3064 @deps = (@deps, get_dependencies $dep);
3065 }
3066
3067 return @deps;
3068}
3069
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003070sub save_config {
3071 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003072
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003073 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003074
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003075 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05003076
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003077 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003078
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003079 foreach my $config (keys %configs) {
3080 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05003081 }
3082 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003083}
3084
3085sub create_config {
3086 my ($name, $pc) = @_;
3087
3088 doprint "Creating old config from $name configs\n";
3089
3090 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003091
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003092 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003093}
3094
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003095# compare two config hashes, and return configs with different vals.
3096# It returns B's config values, but you can use A to see what A was.
3097sub diff_config_vals {
3098 my ($pa, $pb) = @_;
3099
3100 # crappy Perl way to pass in hashes.
3101 my %a = %{$pa};
3102 my %b = %{$pb};
3103
3104 my %ret;
3105
3106 foreach my $item (keys %a) {
3107 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
3108 $ret{$item} = $b{$item};
3109 }
3110 }
3111
3112 return %ret;
3113}
3114
3115# compare two config hashes and return the configs in B but not A
3116sub diff_configs {
3117 my ($pa, $pb) = @_;
3118
3119 my %ret;
3120
3121 # crappy Perl way to pass in hashes.
3122 my %a = %{$pa};
3123 my %b = %{$pb};
3124
3125 foreach my $item (keys %b) {
3126 if (!defined($a{$item})) {
3127 $ret{$item} = $b{$item};
3128 }
3129 }
3130
3131 return %ret;
3132}
3133
3134# return if two configs are equal or not
3135# 0 is equal +1 b has something a does not
3136# +1 if a and b have a different item.
3137# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05003138sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003139 my ($pa, $pb) = @_;
3140
3141 my %ret;
3142
3143 # crappy Perl way to pass in hashes.
3144 my %a = %{$pa};
3145 my %b = %{$pb};
3146
3147 foreach my $item (keys %b) {
3148 if (!defined($a{$item})) {
3149 return 1;
3150 }
3151 if ($a{$item} ne $b{$item}) {
3152 return 1;
3153 }
3154 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003155
3156 foreach my $item (keys %a) {
3157 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003158 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003159 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003160 }
3161
Steven Rostedt0a05c762010-11-08 11:14:10 -05003162 return 0;
3163}
3164
3165sub run_config_bisect_test {
3166 my ($type) = @_;
3167
Steven Rostedt (Red Hat)4cc559b2014-04-23 22:27:27 -04003168 my $ret = run_bisect_test $type, "oldconfig";
3169
3170 if ($bisect_manual) {
3171 $ret = answer_bisect;
3172 }
3173
3174 return $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003175}
3176
Steven Rostedt0a05c762010-11-08 11:14:10 -05003177sub process_failed {
3178 my ($config) = @_;
3179
3180 doprint "\n\n***************************************\n";
3181 doprint "Found bad config: $config\n";
3182 doprint "***************************************\n\n";
3183}
3184
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003185# used for config bisecting
3186my $good_config;
3187my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003188
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003189sub process_new_config {
3190 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003191
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003192 my %tmp_config = %{$tc};
3193 my %good_configs = %{$gc};
3194 my %bad_configs = %{$bc};
3195
3196 my %new_configs;
3197
3198 my $runtest = 1;
3199 my $ret;
3200
3201 create_config "tmp_configs", \%tmp_config;
3202 assign_configs \%new_configs, $output_config;
3203
3204 $ret = compare_configs \%new_configs, \%bad_configs;
3205 if (!$ret) {
3206 doprint "New config equals bad config, try next test\n";
3207 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003208 }
3209
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003210 if ($runtest) {
3211 $ret = compare_configs \%new_configs, \%good_configs;
3212 if (!$ret) {
3213 doprint "New config equals good config, try next test\n";
3214 $runtest = 0;
3215 }
3216 }
3217
3218 %{$nc} = %new_configs;
3219
3220 return $runtest;
3221}
3222
3223sub run_config_bisect {
3224 my ($pgood, $pbad) = @_;
3225
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003226 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003227
3228 my %good_configs = %{$pgood};
3229 my %bad_configs = %{$pbad};
3230
3231 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
3232 my %b_configs = diff_configs \%good_configs, \%bad_configs;
3233 my %g_configs = diff_configs \%bad_configs, \%good_configs;
3234
3235 my @diff_arr = keys %diff_configs;
3236 my $len_diff = $#diff_arr + 1;
3237
3238 my @b_arr = keys %b_configs;
3239 my $len_b = $#b_arr + 1;
3240
3241 my @g_arr = keys %g_configs;
3242 my $len_g = $#g_arr + 1;
3243
3244 my $runtest = 1;
3245 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003246 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003247
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003248 # First, lets get it down to a single subset.
3249 # Is the problem with a difference in values?
3250 # Is the problem with a missing config?
3251 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003252
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003253 # Enable all of one set and see if we get a new bad
3254 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003255
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003256 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003257
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003258 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003259
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003260 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003261
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003262 if ($len_diff > 0) {
3263 if ($len_b > 0 || $len_g > 0) {
3264 my %tmp_config = %bad_configs;
3265
3266 doprint "Set tmp config to be bad config with good config values\n";
3267 foreach my $item (@diff_arr) {
3268 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003269 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003270
3271 $runtest = process_new_config \%tmp_config, \%new_configs,
3272 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003273 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003274 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003275
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003276 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003277
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003278 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003279 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003280 return 1;
3281 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003282 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003283
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003284 my $half = int($#diff_arr / 2);
3285 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003286
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003287 doprint "Settings bisect with top half:\n";
3288 doprint "Set tmp config to be bad config with some good config values\n";
3289 foreach my $item (@tophalf) {
3290 $tmp_config{$item} = $good_configs{$item};
3291 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003292
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003293 $runtest = process_new_config \%tmp_config, \%new_configs,
3294 \%good_configs, \%bad_configs;
3295
3296 if (!$runtest) {
3297 my %tmp_config = %bad_configs;
3298
3299 doprint "Try bottom half\n";
3300
3301 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3302
3303 foreach my $item (@bottomhalf) {
3304 $tmp_config{$item} = $good_configs{$item};
3305 }
3306
3307 $runtest = process_new_config \%tmp_config, \%new_configs,
3308 \%good_configs, \%bad_configs;
3309 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003310 }
3311
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003312 if ($runtest) {
3313 $ret = run_config_bisect_test $type;
3314 if ($ret) {
3315 doprint "NEW GOOD CONFIG\n";
3316 %good_configs = %new_configs;
3317 run_command "mv $good_config ${good_config}.last";
3318 save_config \%good_configs, $good_config;
3319 %{$pgood} = %good_configs;
3320 } else {
3321 doprint "NEW BAD CONFIG\n";
3322 %bad_configs = %new_configs;
3323 run_command "mv $bad_config ${bad_config}.last";
3324 save_config \%bad_configs, $bad_config;
3325 %{$pbad} = %bad_configs;
3326 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003327 return 0;
3328 }
3329
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003330 fail "Hmm, need to do a mix match?\n";
3331 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003332}
3333
3334sub config_bisect {
3335 my ($i) = @_;
3336
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003337 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003338 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003339
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003340 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003341
Steven Rostedt30f75da2011-06-13 10:35:35 -04003342 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003343 $good_config = $config_bisect_good;
3344 } elsif (defined($minconfig)) {
3345 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003346 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003347 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003348 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003349 if (!$ret) {
3350 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3351 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003352 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003353 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003354 }
3355
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003356 # we don't want min configs to cause issues here.
3357 doprint "Disabling 'MIN_CONFIG' for this test\n";
3358 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003359
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003360 my %good_configs;
3361 my %bad_configs;
3362 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003363
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003364 doprint "Run good configs through make oldconfig\n";
3365 assign_configs \%tmp_configs, $good_config;
3366 create_config "$good_config", \%tmp_configs;
3367 assign_configs \%good_configs, $output_config;
3368
3369 doprint "Run bad configs through make oldconfig\n";
3370 assign_configs \%tmp_configs, $bad_config;
3371 create_config "$bad_config", \%tmp_configs;
3372 assign_configs \%bad_configs, $output_config;
3373
3374 $good_config = "$tmpdir/good_config";
3375 $bad_config = "$tmpdir/bad_config";
3376
3377 save_config \%good_configs, $good_config;
3378 save_config \%bad_configs, $bad_config;
3379
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003380 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3381 if ($config_bisect_check ne "good") {
3382 doprint "Testing bad config\n";
3383
3384 $ret = run_bisect_test $type, "useconfig:$bad_config";
3385 if ($ret) {
3386 fail "Bad config succeeded when expected to fail!";
3387 return 0;
3388 }
3389 }
3390 if ($config_bisect_check ne "bad") {
3391 doprint "Testing good config\n";
3392
3393 $ret = run_bisect_test $type, "useconfig:$good_config";
3394 if (!$ret) {
3395 fail "Good config failed when expected to succeed!";
3396 return 0;
3397 }
3398 }
3399 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003400
Steven Rostedt0a05c762010-11-08 11:14:10 -05003401 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003402 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05003403 print_times;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003404 } while (!$ret);
3405
3406 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003407
3408 success $i;
3409}
3410
Steven Rostedt27d934b2011-05-20 09:18:18 -04003411sub patchcheck_reboot {
3412 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003413 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003414}
3415
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003416sub patchcheck {
3417 my ($i) = @_;
3418
3419 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003420 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003421 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003422 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003423
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003424 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003425
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003426 my $cherry = $patchcheck_cherry;
3427 if (!defined($cherry)) {
3428 $cherry = 0;
3429 }
3430
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003431 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003432 if (defined($patchcheck_end)) {
3433 $end = $patchcheck_end;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003434 } elsif ($cherry) {
3435 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003436 }
3437
Steven Rostedta57419b2010-11-02 15:13:54 -04003438 # Get the true sha1's since we can use things like HEAD~3
3439 $start = get_sha1($start);
3440 $end = get_sha1($end);
3441
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003442 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003443
3444 # Can't have a test without having a test to run
3445 if ($type eq "test" && !defined($run_test)) {
3446 $type = "boot";
3447 }
3448
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003449 if ($cherry) {
3450 open (IN, "git cherry -v $start $end|") or
3451 dodie "could not get git list";
3452 } else {
3453 open (IN, "git log --pretty=oneline $end|") or
3454 dodie "could not get git list";
3455 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003456
3457 my @list;
3458
3459 while (<IN>) {
3460 chomp;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003461 # git cherry adds a '+' we want to remove
3462 s/^\+ //;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003463 $list[$#list+1] = $_;
3464 last if (/^$start/);
3465 }
3466 close(IN);
3467
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003468 if (!$cherry) {
3469 if ($list[$#list] !~ /^$start/) {
3470 fail "SHA1 $start not found";
3471 }
3472
3473 # go backwards in the list
3474 @list = reverse @list;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003475 }
3476
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003477 doprint("Going to test the following commits:\n");
3478 foreach my $l (@list) {
3479 doprint "$l\n";
3480 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003481
3482 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003483 my %ignored_warnings;
3484
3485 if (defined($ignore_warnings)) {
3486 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3487 $ignored_warnings{$sha1} = 1;
3488 }
3489 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003490
3491 $in_patchcheck = 1;
3492 foreach my $item (@list) {
3493 my $sha1 = $item;
3494 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3495
Steven Rostedt (Red Hat)7c2c49e2015-02-03 15:45:13 -05003496 doprint "\nProcessing commit \"$item\"\n\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003497
3498 run_command "git checkout $sha1" or
3499 die "Failed to checkout $sha1";
3500
3501 # only clean on the first and last patch
3502 if ($item eq $list[0] ||
3503 $item eq $list[$#list]) {
3504 $noclean = $save_clean;
3505 } else {
3506 $noclean = 1;
3507 }
3508
3509 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003510 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003511 } else {
3512 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003513 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003514 }
3515
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003516 # No need to do per patch checking if warnings file exists
3517 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3518 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003519 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003520
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003521 check_buildlog or return 0;
3522
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003523 next if ($type eq "build");
3524
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003525 my $failed = 0;
3526
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05003527 start_monitor_and_install or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003528
3529 if (!$failed && $type ne "boot"){
3530 do_run_test or $failed = 1;
3531 }
3532 end_monitor;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05003533 if ($failed) {
3534 print_times;
3535 return 0;
3536 }
Steven Rostedt27d934b2011-05-20 09:18:18 -04003537 patchcheck_reboot;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05003538 print_times;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003539 }
3540 $in_patchcheck = 0;
3541 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003542
3543 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003544}
3545
Steven Rostedtb9066f62011-07-15 21:25:24 -04003546my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003547my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003548my $iflevel = 0;
3549my @ifdeps;
3550
3551# prevent recursion
3552my %read_kconfigs;
3553
Steven Rostedtac6974c2011-10-04 09:40:17 -04003554sub add_dep {
3555 # $config depends on $dep
3556 my ($config, $dep) = @_;
3557
3558 if (defined($depends{$config})) {
3559 $depends{$config} .= " " . $dep;
3560 } else {
3561 $depends{$config} = $dep;
3562 }
3563
3564 # record the number of configs depending on $dep
3565 if (defined $depcount{$dep}) {
3566 $depcount{$dep}++;
3567 } else {
3568 $depcount{$dep} = 1;
3569 }
3570}
3571
Steven Rostedtb9066f62011-07-15 21:25:24 -04003572# taken from streamline_config.pl
3573sub read_kconfig {
3574 my ($kconfig) = @_;
3575
3576 my $state = "NONE";
3577 my $config;
3578 my @kconfigs;
3579
3580 my $cont = 0;
3581 my $line;
3582
3583
3584 if (! -f $kconfig) {
3585 doprint "file $kconfig does not exist, skipping\n";
3586 return;
3587 }
3588
3589 open(KIN, "$kconfig")
3590 or die "Can't open $kconfig";
3591 while (<KIN>) {
3592 chomp;
3593
3594 # Make sure that lines ending with \ continue
3595 if ($cont) {
3596 $_ = $line . " " . $_;
3597 }
3598
3599 if (s/\\$//) {
3600 $cont = 1;
3601 $line = $_;
3602 next;
3603 }
3604
3605 $cont = 0;
3606
3607 # collect any Kconfig sources
3608 if (/^source\s*"(.*)"/) {
3609 $kconfigs[$#kconfigs+1] = $1;
3610 }
3611
3612 # configs found
3613 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3614 $state = "NEW";
3615 $config = $2;
3616
3617 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003618 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003619 }
3620
3621 # collect the depends for the config
3622 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3623
Steven Rostedtac6974c2011-10-04 09:40:17 -04003624 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003625
3626 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003627 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3628
3629 # selected by depends on config
3630 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003631
3632 # Check for if statements
3633 } elsif (/^if\s+(.*\S)\s*$/) {
3634 my $deps = $1;
3635 # remove beginning and ending non text
3636 $deps =~ s/^[^a-zA-Z0-9_]*//;
3637 $deps =~ s/[^a-zA-Z0-9_]*$//;
3638
3639 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3640
3641 $ifdeps[$iflevel++] = join ':', @deps;
3642
3643 } elsif (/^endif/) {
3644
3645 $iflevel-- if ($iflevel);
3646
3647 # stop on "help"
3648 } elsif (/^\s*help\s*$/) {
3649 $state = "NONE";
3650 }
3651 }
3652 close(KIN);
3653
3654 # read in any configs that were found.
3655 foreach $kconfig (@kconfigs) {
3656 if (!defined($read_kconfigs{$kconfig})) {
3657 $read_kconfigs{$kconfig} = 1;
3658 read_kconfig("$builddir/$kconfig");
3659 }
3660 }
3661}
3662
3663sub read_depends {
3664 # find out which arch this is by the kconfig file
3665 open (IN, $output_config)
3666 or dodie "Failed to read $output_config";
3667 my $arch;
3668 while (<IN>) {
3669 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3670 $arch = $1;
3671 last;
3672 }
3673 }
3674 close IN;
3675
3676 if (!defined($arch)) {
3677 doprint "Could not find arch from config file\n";
3678 doprint "no dependencies used\n";
3679 return;
3680 }
3681
3682 # arch is really the subarch, we need to know
3683 # what directory to look at.
3684 if ($arch eq "i386" || $arch eq "x86_64") {
3685 $arch = "x86";
3686 } elsif ($arch =~ /^tile/) {
3687 $arch = "tile";
3688 }
3689
3690 my $kconfig = "$builddir/arch/$arch/Kconfig";
3691
3692 if (! -f $kconfig && $arch =~ /\d$/) {
3693 my $orig = $arch;
3694 # some subarchs have numbers, truncate them
3695 $arch =~ s/\d*$//;
3696 $kconfig = "$builddir/arch/$arch/Kconfig";
3697 if (! -f $kconfig) {
3698 doprint "No idea what arch dir $orig is for\n";
3699 doprint "no dependencies used\n";
3700 return;
3701 }
3702 }
3703
3704 read_kconfig($kconfig);
3705}
3706
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003707sub make_new_config {
3708 my @configs = @_;
3709
3710 open (OUT, ">$output_config")
3711 or dodie "Failed to write $output_config";
3712
3713 foreach my $config (@configs) {
3714 print OUT "$config\n";
3715 }
3716 close OUT;
3717}
3718
Steven Rostedtac6974c2011-10-04 09:40:17 -04003719sub chomp_config {
3720 my ($config) = @_;
3721
3722 $config =~ s/CONFIG_//;
3723
3724 return $config;
3725}
3726
Steven Rostedtb9066f62011-07-15 21:25:24 -04003727sub get_depends {
3728 my ($dep) = @_;
3729
Steven Rostedtac6974c2011-10-04 09:40:17 -04003730 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003731
3732 $dep = $depends{"$kconfig"};
3733
3734 # the dep string we have saves the dependencies as they
3735 # were found, including expressions like ! && ||. We
3736 # want to split this out into just an array of configs.
3737
3738 my $valid = "A-Za-z_0-9";
3739
3740 my @configs;
3741
3742 while ($dep =~ /[$valid]/) {
3743
3744 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3745 my $conf = "CONFIG_" . $1;
3746
3747 $configs[$#configs + 1] = $conf;
3748
3749 $dep =~ s/^[^$valid]*[$valid]+//;
3750 } else {
3751 die "this should never happen";
3752 }
3753 }
3754
3755 return @configs;
3756}
3757
3758my %min_configs;
3759my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003760my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003761my %processed_configs;
3762my %nochange_config;
3763
3764sub test_this_config {
3765 my ($config) = @_;
3766
3767 my $found;
3768
3769 # if we already processed this config, skip it
3770 if (defined($processed_configs{$config})) {
3771 return undef;
3772 }
3773 $processed_configs{$config} = 1;
3774
3775 # if this config failed during this round, skip it
3776 if (defined($nochange_config{$config})) {
3777 return undef;
3778 }
3779
Steven Rostedtac6974c2011-10-04 09:40:17 -04003780 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003781
3782 # Test dependencies first
3783 if (defined($depends{"$kconfig"})) {
3784 my @parents = get_depends $config;
3785 foreach my $parent (@parents) {
3786 # if the parent is in the min config, check it first
3787 next if (!defined($min_configs{$parent}));
3788 $found = test_this_config($parent);
3789 if (defined($found)) {
3790 return $found;
3791 }
3792 }
3793 }
3794
3795 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003796 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003797 # .config to make sure it is missing the config that
3798 # we had before
3799 my %configs = %min_configs;
3800 delete $configs{$config};
3801 make_new_config ((values %configs), (values %keep_configs));
3802 make_oldconfig;
3803 undef %configs;
3804 assign_configs \%configs, $output_config;
3805
Steven Rostedt (Red Hat)9972fc02014-10-22 10:11:47 -04003806 if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
3807 return $config;
3808 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003809
3810 doprint "disabling config $config did not change .config\n";
3811
3812 $nochange_config{$config} = 1;
3813
3814 return undef;
3815}
3816
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003817sub make_min_config {
3818 my ($i) = @_;
3819
Steven Rostedtccc513b2012-05-21 17:13:40 -04003820 my $type = $minconfig_type;
3821 if ($type ne "boot" && $type ne "test") {
3822 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3823 " make_min_config works only with 'boot' and 'test'\n" and return;
3824 }
3825
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003826 if (!defined($output_minconfig)) {
3827 fail "OUTPUT_MIN_CONFIG not defined" and return;
3828 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003829
3830 # If output_minconfig exists, and the start_minconfig
3831 # came from min_config, than ask if we should use
3832 # that instead.
3833 if (-f $output_minconfig && !$start_minconfig_defined) {
3834 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003835 if (!defined($use_output_minconfig)) {
3836 if (read_yn " Use it as minconfig?") {
3837 $start_minconfig = $output_minconfig;
3838 }
3839 } elsif ($use_output_minconfig > 0) {
3840 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003841 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003842 } else {
3843 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003844 }
3845 }
3846
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003847 if (!defined($start_minconfig)) {
3848 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3849 }
3850
Steven Rostedt35ce5952011-07-15 21:57:25 -04003851 my $temp_config = "$tmpdir/temp_config";
3852
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003853 # First things first. We build an allnoconfig to find
3854 # out what the defaults are that we can't touch.
3855 # Some are selections, but we really can't handle selections.
3856
3857 my $save_minconfig = $minconfig;
3858 undef $minconfig;
3859
3860 run_command "$make allnoconfig" or return 0;
3861
Steven Rostedtb9066f62011-07-15 21:25:24 -04003862 read_depends;
3863
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003864 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003865
Steven Rostedt43d1b652011-07-15 22:01:56 -04003866 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003867 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003868
3869 if (defined($ignore_config)) {
3870 # make sure the file exists
3871 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003872 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003873 }
3874
Steven Rostedt43d1b652011-07-15 22:01:56 -04003875 %keep_configs = %save_configs;
3876
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003877 doprint "Load initial configs from $start_minconfig\n";
3878
3879 # Look at the current min configs, and save off all the
3880 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003881 assign_configs \%min_configs, $start_minconfig;
3882
3883 my @config_keys = keys %min_configs;
3884
Steven Rostedtac6974c2011-10-04 09:40:17 -04003885 # All configs need a depcount
3886 foreach my $config (@config_keys) {
3887 my $kconfig = chomp_config $config;
3888 if (!defined $depcount{$kconfig}) {
3889 $depcount{$kconfig} = 0;
3890 }
3891 }
3892
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003893 # Remove anything that was set by the make allnoconfig
3894 # we shouldn't need them as they get set for us anyway.
3895 foreach my $config (@config_keys) {
3896 # Remove anything in the ignore_config
3897 if (defined($keep_configs{$config})) {
3898 my $file = $ignore_config;
3899 $file =~ s,.*/(.*?)$,$1,;
3900 doprint "$config set by $file ... ignored\n";
3901 delete $min_configs{$config};
3902 next;
3903 }
3904 # But make sure the settings are the same. If a min config
3905 # sets a selection, we do not want to get rid of it if
3906 # it is not the same as what we have. Just move it into
3907 # the keep configs.
3908 if (defined($config_ignore{$config})) {
3909 if ($config_ignore{$config} ne $min_configs{$config}) {
3910 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3911 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3912 $keep_configs{$config} = $min_configs{$config};
3913 } else {
3914 doprint "$config set by allnoconfig ... ignored\n";
3915 }
3916 delete $min_configs{$config};
3917 }
3918 }
3919
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003920 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003921 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003922
3923 while (!$done) {
3924
3925 my $config;
3926 my $found;
3927
3928 # Now disable each config one by one and do a make oldconfig
3929 # till we find a config that changes our list.
3930
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003931 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003932
3933 # Sort keys by who is most dependent on
3934 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3935 @test_configs ;
3936
3937 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003938 my $reset = 1;
3939 for (my $i = 0; $i < $#test_configs; $i++) {
3940 if (!defined($nochange_config{$test_configs[0]})) {
3941 $reset = 0;
3942 last;
3943 }
3944 # This config didn't change the .config last time.
3945 # Place it at the end
3946 my $config = shift @test_configs;
3947 push @test_configs, $config;
3948 }
3949
3950 # if every test config has failed to modify the .config file
3951 # in the past, then reset and start over.
3952 if ($reset) {
3953 undef %nochange_config;
3954 }
3955
Steven Rostedtb9066f62011-07-15 21:25:24 -04003956 undef %processed_configs;
3957
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003958 foreach my $config (@test_configs) {
3959
Steven Rostedtb9066f62011-07-15 21:25:24 -04003960 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003961
Steven Rostedtb9066f62011-07-15 21:25:24 -04003962 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003963
3964 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003965 }
3966
3967 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003968 # we could have failed due to the nochange_config hash
3969 # reset and try again
3970 if (!$take_two) {
3971 undef %nochange_config;
3972 $take_two = 1;
3973 next;
3974 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003975 doprint "No more configs found that we can disable\n";
3976 $done = 1;
3977 last;
3978 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003979 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003980
3981 $config = $found;
3982
3983 doprint "Test with $config disabled\n";
3984
3985 # set in_bisect to keep build and monitor from dieing
3986 $in_bisect = 1;
3987
3988 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003989 build "oldconfig" or $failed = 1;
3990 if (!$failed) {
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05003991 start_monitor_and_install or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003992
3993 if ($type eq "test" && !$failed) {
3994 do_run_test or $failed = 1;
3995 }
3996
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003997 end_monitor;
3998 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003999
4000 $in_bisect = 0;
4001
4002 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04004003 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004004 # this config is needed, add it to the ignore list.
4005 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04004006 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004007 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04004008
4009 # update new ignore configs
4010 if (defined($ignore_config)) {
4011 open (OUT, ">$temp_config")
4012 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04004013 foreach my $config (keys %save_configs) {
4014 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04004015 }
4016 close OUT;
4017 run_command "mv $temp_config $ignore_config" or
4018 dodie "failed to copy update to $ignore_config";
4019 }
4020
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004021 } else {
4022 # We booted without this config, remove it from the minconfigs.
4023 doprint "$config is not needed, disabling\n";
4024
4025 delete $min_configs{$config};
4026
4027 # Also disable anything that is not enabled in this config
4028 my %configs;
4029 assign_configs \%configs, $output_config;
4030 my @config_keys = keys %min_configs;
4031 foreach my $config (@config_keys) {
4032 if (!defined($configs{$config})) {
4033 doprint "$config is not set, disabling\n";
4034 delete $min_configs{$config};
4035 }
4036 }
4037
Pavel Machek22722792016-12-14 15:06:18 -08004038 # Save off all the current mandatory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04004039 open (OUT, ">$temp_config")
4040 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004041 foreach my $config (keys %keep_configs) {
4042 print OUT "$keep_configs{$config}\n";
4043 }
4044 foreach my $config (keys %min_configs) {
4045 print OUT "$min_configs{$config}\n";
4046 }
4047 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04004048
4049 run_command "mv $temp_config $output_minconfig" or
4050 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004051 }
4052
4053 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004054 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004055 }
4056
4057 success $i;
4058 return 1;
4059}
4060
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004061sub make_warnings_file {
4062 my ($i) = @_;
4063
4064 if (!defined($warnings_file)) {
4065 dodie "Must define WARNINGS_FILE for make_warnings_file test";
4066 }
4067
4068 if ($build_type eq "nobuild") {
4069 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
4070 }
4071
4072 build $build_type or dodie "Failed to build";
4073
4074 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
4075
4076 open(IN, $buildlog) or dodie "Can't open $buildlog";
4077 while (<IN>) {
4078
4079 # Some compilers use UTF-8 extended for quotes
4080 # for distcc heterogeneous systems, this causes issues
4081 s/$utf8_quote/'/g;
4082
4083 if (/$check_build_re/) {
4084 print OUT;
4085 }
4086 }
4087 close(IN);
4088
4089 close(OUT);
4090
4091 success $i;
4092}
4093
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09004094$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04004095
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004096if ($#ARGV == 0) {
4097 $ktest_config = $ARGV[0];
4098 if (! -f $ktest_config) {
4099 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04004100 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004101 exit 0;
4102 }
4103 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004104}
4105
4106if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05004107 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05004108 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004109 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
4110 print OUT << "EOF"
4111# Generated by ktest.pl
4112#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05004113
4114# PWD is a ktest.pl variable that will result in the process working
4115# directory that ktest.pl is executed in.
4116
4117# THIS_DIR is automatically assigned the PWD of the path that generated
4118# the config file. It is best to use this variable when assigning other
4119# directory paths within this directory. This allows you to easily
4120# move the test cases to other locations or to other machines.
4121#
4122THIS_DIR := $variable{"PWD"}
4123
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004124# Define each test with TEST_START
4125# The config options below it will override the defaults
4126TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05004127TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004128
4129DEFAULTS
4130EOF
4131;
4132 close(OUT);
4133}
4134read_config $ktest_config;
4135
Steven Rostedt23715c3c2011-06-13 11:03:34 -04004136if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05004137 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04004138}
4139
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004140# Append any configs entered in manually to the config file.
4141my @new_configs = keys %entered_configs;
4142if ($#new_configs >= 0) {
4143 print "\nAppending entered in configs to $ktest_config\n";
4144 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
4145 foreach my $config (@new_configs) {
4146 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05004147 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004148 }
4149}
Steven Rostedt2545eb62010-11-02 15:01:32 -04004150
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004151if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
4152 unlink $opt{"LOG_FILE"};
4153}
Steven Rostedt2545eb62010-11-02 15:01:32 -04004154
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004155doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
4156
Steven Rostedta57419b2010-11-02 15:13:54 -04004157for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4158
4159 if (!$i) {
4160 doprint "DEFAULT OPTIONS:\n";
4161 } else {
4162 doprint "\nTEST $i OPTIONS";
4163 if (defined($repeat_tests{$i})) {
4164 $repeat = $repeat_tests{$i};
4165 doprint " ITERATE $repeat";
4166 }
4167 doprint "\n";
4168 }
4169
4170 foreach my $option (sort keys %opt) {
4171
4172 if ($option =~ /\[(\d+)\]$/) {
4173 next if ($i != $1);
4174 } else {
4175 next if ($i);
4176 }
4177
4178 doprint "$option = $opt{$option}\n";
4179 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004180}
Steven Rostedt2545eb62010-11-02 15:01:32 -04004181
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004182sub option_defined {
4183 my ($option) = @_;
4184
4185 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
4186 return 1;
4187 }
4188
4189 return 0;
4190}
4191
Steven Rostedt2a625122011-05-20 15:48:59 -04004192sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004193 my ($name, $i) = @_;
4194
4195 my $option = "$name\[$i\]";
4196
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004197 if (option_defined($option)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004198 return $opt{$option};
4199 }
4200
Steven Rostedta57419b2010-11-02 15:13:54 -04004201 foreach my $test (keys %repeat_tests) {
4202 if ($i >= $test &&
4203 $i < $test + $repeat_tests{$test}) {
4204 $option = "$name\[$test\]";
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004205 if (option_defined($option)) {
Steven Rostedta57419b2010-11-02 15:13:54 -04004206 return $opt{$option};
4207 }
4208 }
4209 }
4210
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004211 if (option_defined($name)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004212 return $opt{$name};
4213 }
4214
4215 return undef;
4216}
4217
Steven Rostedt2a625122011-05-20 15:48:59 -04004218sub set_test_option {
4219 my ($name, $i) = @_;
4220
4221 my $option = __set_test_option($name, $i);
4222 return $option if (!defined($option));
4223
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05004224 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04004225}
4226
Steven Rostedt2545eb62010-11-02 15:01:32 -04004227# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04004228for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04004229
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004230 # Do not reboot on failing test options
4231 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004232 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004233
Steven Rostedt683a3e62012-05-18 13:34:35 -04004234 $have_version = 0;
4235
Steven Rostedt576f6272010-11-02 14:58:38 -04004236 $iteration = $i;
4237
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05004238 $build_time = 0;
4239 $install_time = 0;
4240 $reboot_time = 0;
4241 $test_time = 0;
4242
Steven Rostedtc1434dc2012-07-20 22:39:16 -04004243 undef %force_config;
4244
Steven Rostedta75fece2010-11-02 14:58:27 -04004245 my $makecmd = set_test_option("MAKE_CMD", $i);
4246
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004247 $outputdir = set_test_option("OUTPUT_DIR", $i);
4248 $builddir = set_test_option("BUILD_DIR", $i);
4249
4250 chdir $builddir || die "can't change directory to $builddir";
4251
4252 if (!-d $outputdir) {
4253 mkpath($outputdir) or
4254 die "can't create $outputdir";
4255 }
4256
4257 $make = "$makecmd O=$outputdir";
4258
Steven Rostedt9cc9e092011-12-22 21:37:22 -05004259 # Load all the options into their mapped variable names
4260 foreach my $opt (keys %option_map) {
4261 ${$option_map{$opt}} = set_test_option($opt, $i);
4262 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004263
Steven Rostedt35ce5952011-07-15 21:57:25 -04004264 $start_minconfig_defined = 1;
4265
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004266 # The first test may override the PRE_KTEST option
4267 if (defined($pre_ktest) && $i == 1) {
4268 doprint "\n";
4269 run_command $pre_ktest;
4270 }
4271
4272 # Any test can override the POST_KTEST option
4273 # The last test takes precedence.
4274 if (defined($post_ktest)) {
4275 $final_post_ktest = $post_ktest;
4276 }
4277
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004278 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004279 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004280 $start_minconfig = $minconfig;
4281 }
4282
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004283 if (!-d $tmpdir) {
4284 mkpath($tmpdir) or
4285 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004286 }
4287
Steven Rostedte48c5292010-11-02 14:35:37 -04004288 $ENV{"SSH_USER"} = $ssh_user;
4289 $ENV{"MACHINE"} = $machine;
4290
Steven Rostedta75fece2010-11-02 14:58:27 -04004291 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304292 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004293 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004294 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004295
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004296 if (!$buildonly) {
4297 $target = "$ssh_user\@$machine";
4298 if ($reboot_type eq "grub") {
4299 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004300 } elsif ($reboot_type eq "grub2") {
4301 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4302 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004303 } elsif ($reboot_type eq "syslinux") {
4304 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004305 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004306 }
4307
4308 my $run_type = $build_type;
4309 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004310 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004311 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004312 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004313 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004314 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004315 } elsif ($test_type eq "make_min_config") {
4316 $run_type = "";
4317 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004318 $run_type = "";
4319 }
4320
Steven Rostedta75fece2010-11-02 14:58:27 -04004321 # mistake in config file?
4322 if (!defined($run_type)) {
4323 $run_type = "ERROR";
4324 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004325
Steven Rostedte0a87422011-09-30 17:50:48 -04004326 my $installme = "";
4327 $installme = " no_install" if ($no_install);
4328
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004329 my $name = "";
4330
4331 if (defined($test_name)) {
4332 $name = " ($test_name)";
4333 }
4334
Steven Rostedt2545eb62010-11-02 15:01:32 -04004335 doprint "\n\n";
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004336 doprint "RUNNING TEST $i of $opt{NUM_TESTS}$name with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004337
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004338 if (defined($pre_test)) {
4339 run_command $pre_test;
4340 }
4341
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004342 unlink $dmesg;
4343 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304344 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004345
Steven Rostedt250bae82011-07-15 22:05:59 -04004346 if (defined($addconfig)) {
4347 my $min = $minconfig;
4348 if (!defined($minconfig)) {
4349 $min = "";
4350 }
4351 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004352 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004353 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004354 }
4355
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004356 if (defined($checkout)) {
4357 run_command "git checkout $checkout" or
4358 die "failed to checkout $checkout";
4359 }
4360
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004361 $no_reboot = 0;
4362
Steven Rostedt648a1822012-03-21 11:18:27 -04004363 # A test may opt to not reboot the box
4364 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004365 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004366 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004367
Steven Rostedta75fece2010-11-02 14:58:27 -04004368 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004369 bisect $i;
4370 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004371 } elsif ($test_type eq "config_bisect") {
4372 config_bisect $i;
4373 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004374 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004375 patchcheck $i;
4376 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004377 } elsif ($test_type eq "make_min_config") {
4378 make_min_config $i;
4379 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004380 } elsif ($test_type eq "make_warnings_file") {
4381 $no_reboot = 1;
4382 make_warnings_file $i;
4383 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004384 }
4385
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004386 if ($build_type ne "nobuild") {
4387 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004388 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004389 }
4390
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004391 if ($test_type eq "install") {
4392 get_version;
4393 install;
4394 success $i;
4395 next;
4396 }
4397
Steven Rostedta75fece2010-11-02 14:58:27 -04004398 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004399 my $failed = 0;
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05004400 start_monitor_and_install or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004401
4402 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4403 do_run_test or $failed = 1;
4404 }
4405 end_monitor;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05004406 if ($failed) {
4407 print_times;
4408 next;
4409 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004410 }
4411
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05004412 print_times;
4413
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004414 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004415}
4416
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004417if (defined($final_post_ktest)) {
4418 run_command $final_post_ktest;
4419}
4420
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004421if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004422 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004423} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004424 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004425} elsif (defined($switch_to_good)) {
4426 # still need to get to the good kernel
4427 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004428}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004429
Steven Rostedt648a1822012-03-21 11:18:27 -04004430
Steven Rostedte48c5292010-11-02 14:35:37 -04004431doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4432
Steven Rostedt2545eb62010-11-02 15:01:32 -04004433exit 0;