blob: 6a1484cc4436627c7edb425dc36be0149d6a7946 [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 Rostedt2545eb62010-11-02 15:01:32 -0400182
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500183my $bisect_good;
184my $bisect_bad;
185my $bisect_type;
186my $bisect_start;
187my $bisect_replay;
188my $bisect_files;
189my $bisect_reverse;
190my $bisect_check;
191
192my $config_bisect;
193my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400194my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500195
196my $patchcheck_type;
197my $patchcheck_start;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -0400198my $patchcheck_cherry;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500199my $patchcheck_end;
200
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -0500201my $build_time;
202my $install_time;
203my $reboot_time;
204my $test_time;
205
Steven Rostedt165708b2011-11-26 20:56:52 -0500206# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500207# which would require more options.
208my $buildonly = 1;
209
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500210# tell build not to worry about warnings, even when WARNINGS_FILE is set
211my $warnings_ok = 0;
212
Steven Rostedtdbd37832011-11-23 16:00:48 -0500213# set when creating a new config
214my $newconfig = 0;
215
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500216my %entered_configs;
217my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400218my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400219
220# force_config is the list of configs that we force enabled (or disabled)
221# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400222my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500223
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400224# do not force reboots on config problems
225my $no_reboot = 1;
226
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400227# reboot on success
228my $reboot_success = 0;
229
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500230my %option_map = (
231 "MACHINE" => \$machine,
232 "SSH_USER" => \$ssh_user,
233 "TMP_DIR" => \$tmpdir,
234 "OUTPUT_DIR" => \$outputdir,
235 "BUILD_DIR" => \$builddir,
236 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400237 "PRE_KTEST" => \$pre_ktest,
238 "POST_KTEST" => \$post_ktest,
239 "PRE_TEST" => \$pre_test,
240 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500241 "BUILD_TYPE" => \$build_type,
242 "BUILD_OPTIONS" => \$build_options,
243 "PRE_BUILD" => \$pre_build,
244 "POST_BUILD" => \$post_build,
245 "PRE_BUILD_DIE" => \$pre_build_die,
246 "POST_BUILD_DIE" => \$post_build_die,
247 "POWER_CYCLE" => \$power_cycle,
248 "REBOOT" => \$reboot,
249 "BUILD_NOCLEAN" => \$noclean,
250 "MIN_CONFIG" => \$minconfig,
251 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
252 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400253 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400254 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500255 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500256 "IGNORE_CONFIG" => \$ignore_config,
257 "TEST" => \$run_test,
258 "ADD_CONFIG" => \$addconfig,
259 "REBOOT_TYPE" => \$reboot_type,
260 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500261 "GRUB_FILE" => \$grub_file,
262 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500263 "SYSLINUX" => \$syslinux,
264 "SYSLINUX_PATH" => \$syslinux_path,
265 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400266 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500267 "POST_INSTALL" => \$post_install,
268 "NO_INSTALL" => \$no_install,
269 "REBOOT_SCRIPT" => \$reboot_script,
270 "REBOOT_ON_ERROR" => \$reboot_on_error,
271 "SWITCH_TO_GOOD" => \$switch_to_good,
272 "SWITCH_TO_TEST" => \$switch_to_test,
273 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400274 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500275 "DIE_ON_FAILURE" => \$die_on_failure,
276 "POWER_OFF" => \$power_off,
277 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
278 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400279 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500280 "SLEEP_TIME" => \$sleep_time,
281 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
282 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
283 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500284 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500285 "BISECT_MANUAL" => \$bisect_manual,
286 "BISECT_SKIP" => \$bisect_skip,
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -0500287 "BISECT_TRIES" => \$bisect_tries,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500288 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
289 "BISECT_RET_GOOD" => \$bisect_ret_good,
290 "BISECT_RET_BAD" => \$bisect_ret_bad,
291 "BISECT_RET_SKIP" => \$bisect_ret_skip,
292 "BISECT_RET_ABORT" => \$bisect_ret_abort,
293 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
294 "STORE_FAILURES" => \$store_failures,
295 "STORE_SUCCESSES" => \$store_successes,
296 "TEST_NAME" => \$test_name,
297 "TIMEOUT" => \$timeout,
298 "BOOTED_TIMEOUT" => \$booted_timeout,
299 "CONSOLE" => \$console,
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900300 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500301 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
302 "SUCCESS_LINE" => \$success_line,
303 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
304 "STOP_AFTER_SUCCESS" => \$stop_after_success,
305 "STOP_AFTER_FAILURE" => \$stop_after_failure,
306 "STOP_TEST_AFTER" => \$stop_test_after,
307 "BUILD_TARGET" => \$build_target,
308 "SSH_EXEC" => \$ssh_exec,
309 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400310 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500311 "CHECKOUT" => \$checkout,
312 "TARGET_IMAGE" => \$target_image,
313 "LOCALVERSION" => \$localversion,
314
315 "BISECT_GOOD" => \$bisect_good,
316 "BISECT_BAD" => \$bisect_bad,
317 "BISECT_TYPE" => \$bisect_type,
318 "BISECT_START" => \$bisect_start,
319 "BISECT_REPLAY" => \$bisect_replay,
320 "BISECT_FILES" => \$bisect_files,
321 "BISECT_REVERSE" => \$bisect_reverse,
322 "BISECT_CHECK" => \$bisect_check,
323
324 "CONFIG_BISECT" => \$config_bisect,
325 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400326 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500327
328 "PATCHCHECK_TYPE" => \$patchcheck_type,
329 "PATCHCHECK_START" => \$patchcheck_start,
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -0400330 "PATCHCHECK_CHERRY" => \$patchcheck_cherry,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500331 "PATCHCHECK_END" => \$patchcheck_end,
332);
333
334# Options may be used by other options, record them.
335my %used_options;
336
Steven Rostedt7bf51072011-10-22 09:07:03 -0400337# default variables that can be used
338chomp ($variable{"PWD"} = `pwd`);
339
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500340$config_help{"MACHINE"} = << "EOF"
341 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500342 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500343EOF
344 ;
345$config_help{"SSH_USER"} = << "EOF"
346 The box is expected to have ssh on normal bootup, provide the user
347 (most likely root, since you need privileged operations)
348EOF
349 ;
350$config_help{"BUILD_DIR"} = << "EOF"
351 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500352 You can use \${PWD} that will be the path where ktest.pl is run, or use
353 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500354EOF
355 ;
356$config_help{"OUTPUT_DIR"} = << "EOF"
357 The directory that the objects will be built (full path).
358 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500359 You can use \${PWD} that will be the path where ktest.pl is run, or use
360 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500361EOF
362 ;
363$config_help{"BUILD_TARGET"} = << "EOF"
364 The location of the compiled file to copy to the target.
365 (relative to OUTPUT_DIR)
366EOF
367 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500368$config_help{"BUILD_OPTIONS"} = << "EOF"
369 Options to add to \"make\" when building.
370 i.e. -j20
371EOF
372 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500373$config_help{"TARGET_IMAGE"} = << "EOF"
374 The place to put your image on the test machine.
375EOF
376 ;
377$config_help{"POWER_CYCLE"} = << "EOF"
378 A script or command to reboot the box.
379
380 Here is a digital loggers power switch example
381 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
382
383 Here is an example to reboot a virtual box on the current host
384 with the name "Guest".
385 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
386EOF
387 ;
388$config_help{"CONSOLE"} = << "EOF"
389 The script or command that reads the console
390
391 If you use ttywatch server, something like the following would work.
392CONSOLE = nc -d localhost 3001
393
394 For a virtual machine with guest name "Guest".
395CONSOLE = virsh console Guest
396EOF
397 ;
398$config_help{"LOCALVERSION"} = << "EOF"
399 Required version ending to differentiate the test
400 from other linux builds on the system.
401EOF
402 ;
403$config_help{"REBOOT_TYPE"} = << "EOF"
404 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500405 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500406
407 If you specify grub, it will assume grub version 1
408 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
409 and select that target to reboot to the kernel. If this is not
410 your setup, then specify "script" and have a command or script
411 specified in REBOOT_SCRIPT to boot to the target.
412
413 The entry in /boot/grub/menu.lst must be entered in manually.
414 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500415
416 If you specify grub2, then you also need to specify both \$GRUB_MENU
417 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500418
419 If you specify syslinux, then you may use SYSLINUX to define the syslinux
420 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
421 the syslinux install (defaults to /boot/extlinux). But you have to specify
422 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500423EOF
424 ;
425$config_help{"GRUB_MENU"} = << "EOF"
426 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500427 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500428
429 Note, ktest.pl will not update the grub menu.lst, you need to
430 manually add an option for the test. ktest.pl will search
431 the grub menu.lst for this option to find what kernel to
432 reboot into.
433
434 For example, if in the /boot/grub/menu.lst the test kernel title has:
435 title Test Kernel
436 kernel vmlinuz-test
437 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500438
439 For grub2, a search of \$GRUB_FILE is performed for the lines
440 that begin with "menuentry". It will not detect submenus. The
441 menu must be a non-nested menu. Add the quotes used in the menu
442 to guarantee your selection, as the first menuentry with the content
443 of \$GRUB_MENU that is found will be used.
444EOF
445 ;
446$config_help{"GRUB_FILE"} = << "EOF"
447 If grub2 is used, the full path for the grub.cfg file is placed
448 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500449EOF
450 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500451$config_help{"SYSLINUX_LABEL"} = << "EOF"
452 If syslinux is used, the label that boots the target kernel must
453 be specified with SYSLINUX_LABEL.
454EOF
455 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500456$config_help{"REBOOT_SCRIPT"} = << "EOF"
457 A script to reboot the target into the test kernel
458 (Only mandatory if REBOOT_TYPE = script)
459EOF
460 ;
461
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500462sub _logit {
463 if (defined($opt{"LOG_FILE"})) {
464 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
465 print OUT @_;
466 close(OUT);
467 }
468}
469
470sub logit {
471 if (defined($opt{"LOG_FILE"})) {
472 _logit @_;
473 } else {
474 print @_;
475 }
476}
477
478sub doprint {
479 print @_;
480 _logit @_;
481}
482
Steven Rostedtdad98752011-11-22 20:48:57 -0500483sub read_prompt {
484 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400485
486 my $ans;
487
488 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500489 if ($cancel) {
490 print "$prompt [y/n/C] ";
491 } else {
492 print "$prompt [Y/n] ";
493 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400494 $ans = <STDIN>;
495 chomp $ans;
496 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500497 if ($cancel) {
498 $ans = "c";
499 } else {
500 $ans = "y";
501 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400502 }
503 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500504 if ($cancel) {
505 last if ($ans =~ /^c$/i);
506 print "Please answer either 'y', 'n' or 'c'.\n";
507 } else {
508 print "Please answer either 'y' or 'n'.\n";
509 }
510 }
511 if ($ans =~ /^c/i) {
512 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400513 }
514 if ($ans !~ /^y$/i) {
515 return 0;
516 }
517 return 1;
518}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500519
Steven Rostedtdad98752011-11-22 20:48:57 -0500520sub read_yn {
521 my ($prompt) = @_;
522
523 return read_prompt 0, $prompt;
524}
525
526sub read_ync {
527 my ($prompt) = @_;
528
529 return read_prompt 1, $prompt;
530}
531
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900532sub get_mandatory_config {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500533 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400534 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500535
536 return if (defined($opt{$config}));
537
538 if (defined($config_help{$config})) {
539 print "\n";
540 print $config_help{$config};
541 }
542
543 for (;;) {
544 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500545 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500546 print "\[$default{$config}\] ";
547 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400548 $ans = <STDIN>;
549 $ans =~ s/^\s*(.*\S)\s*$/$1/;
550 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500551 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400552 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500553 } else {
554 print "Your answer can not be blank\n";
555 next;
556 }
557 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500558 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500559 last;
560 }
561}
562
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -0500563sub show_time {
564 my ($time) = @_;
565
566 my $hours = 0;
567 my $minutes = 0;
568
569 if ($time > 3600) {
570 $hours = int($time / 3600);
571 $time -= $hours * 3600;
572 }
573 if ($time > 60) {
574 $minutes = int($time / 60);
575 $time -= $minutes * 60;
576 }
577
578 if ($hours > 0) {
579 doprint "$hours hour";
580 doprint "s" if ($hours > 1);
581 doprint " ";
582 }
583
584 if ($minutes > 0) {
585 doprint "$minutes minute";
586 doprint "s" if ($minutes > 1);
587 doprint " ";
588 }
589
590 doprint "$time second";
591 doprint "s" if ($time != 1);
592}
593
594sub print_times {
595 doprint "\n";
596 if ($build_time) {
597 doprint "Build time: ";
598 show_time($build_time);
599 doprint "\n";
600 }
601 if ($install_time) {
602 doprint "Install time: ";
603 show_time($install_time);
604 doprint "\n";
605 }
606 if ($reboot_time) {
607 doprint "Reboot time: ";
608 show_time($reboot_time);
609 doprint "\n";
610 }
611 if ($test_time) {
612 doprint "Test time: ";
613 show_time($test_time);
614 doprint "\n";
615 }
616 # reset for iterations like bisect
617 $build_time = 0;
618 $install_time = 0;
619 $reboot_time = 0;
620 $test_time = 0;
621}
622
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900623sub get_mandatory_configs {
624 get_mandatory_config("MACHINE");
625 get_mandatory_config("BUILD_DIR");
626 get_mandatory_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500627
Steven Rostedtdbd37832011-11-23 16:00:48 -0500628 if ($newconfig) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900629 get_mandatory_config("BUILD_OPTIONS");
Steven Rostedtdbd37832011-11-23 16:00:48 -0500630 }
631
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500632 # options required for other than just building a kernel
633 if (!$buildonly) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900634 get_mandatory_config("POWER_CYCLE");
635 get_mandatory_config("CONSOLE");
Steven Rostedt165708b2011-11-26 20:56:52 -0500636 }
637
638 # options required for install and more
639 if ($buildonly != 1) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900640 get_mandatory_config("SSH_USER");
641 get_mandatory_config("BUILD_TARGET");
642 get_mandatory_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500643 }
644
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900645 get_mandatory_config("LOCALVERSION");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500646
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500647 return if ($buildonly);
648
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500649 my $rtype = $opt{"REBOOT_TYPE"};
650
651 if (!defined($rtype)) {
652 if (!defined($opt{"GRUB_MENU"})) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900653 get_mandatory_config("REBOOT_TYPE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500654 $rtype = $entered_configs{"REBOOT_TYPE"};
655 } else {
656 $rtype = "grub";
657 }
658 }
659
660 if ($rtype eq "grub") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900661 get_mandatory_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500662 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500663
664 if ($rtype eq "grub2") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900665 get_mandatory_config("GRUB_MENU");
666 get_mandatory_config("GRUB_FILE");
Steven Rostedta15ba912012-11-13 14:30:37 -0500667 }
Steven Rostedt77869542012-12-11 17:37:41 -0500668
669 if ($rtype eq "syslinux") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900670 get_mandatory_config("SYSLINUX_LABEL");
Steven Rostedt77869542012-12-11 17:37:41 -0500671 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500672}
673
Steven Rostedt77d942c2011-05-20 13:36:58 -0400674sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400675 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400676 my $retval = "";
677
678 # We want to check for '\', and it is just easier
679 # to check the previous characet of '$' and not need
680 # to worry if '$' is the first character. By adding
681 # a space to $value, we can just check [^\\]\$ and
682 # it will still work.
683 $value = " $value";
684
685 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
686 my $begin = $1;
687 my $var = $2;
688 my $end = $3;
689 # append beginning of value to retval
690 $retval = "$retval$begin";
691 if (defined($variable{$var})) {
692 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400693 } elsif (defined($remove_undef) && $remove_undef) {
694 # for if statements, any variable that is not defined,
695 # we simple convert to 0
696 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400697 } else {
698 # put back the origin piece.
699 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500700 # This could be an option that is used later, save
701 # it so we don't warn if this option is not one of
702 # ktests options.
703 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400704 }
705 $value = $end;
706 }
707 $retval = "$retval$value";
708
709 # remove the space added in the beginning
710 $retval =~ s/ //;
711
712 return "$retval"
713}
714
Steven Rostedta57419b2010-11-02 15:13:54 -0400715sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400716 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400717
Steven Rostedtcad96662011-12-22 11:32:52 -0500718 my $prvalue = process_variables($rvalue);
719
720 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500721 # Note if a test is something other than build, then we
722 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500723 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500724 # for bisect, we need to check BISECT_TYPE
725 if ($prvalue ne "bisect") {
726 $buildonly = 0;
727 }
728 } else {
729 # install still limits some manditory options.
730 $buildonly = 2;
731 }
732 }
733
734 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
735 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500736 $buildonly = 0;
737 } else {
738 # install still limits some manditory options.
739 $buildonly = 2;
740 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500741 }
742
Steven Rostedta57419b2010-11-02 15:13:54 -0400743 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400744 if (!$override || defined(${$overrides}{$lvalue})) {
745 my $extra = "";
746 if ($override) {
747 $extra = "In the same override section!\n";
748 }
749 die "$name: $.: Option $lvalue defined more than once!\n$extra";
750 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500751 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400752 }
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -0500753
754 $opt{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400755}
756
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500757sub set_eval {
758 my ($lvalue, $rvalue, $name) = @_;
759
760 my $prvalue = process_variables($rvalue);
761 my $arr;
762
763 if (defined($evals{$lvalue})) {
764 $arr = $evals{$lvalue};
765 } else {
766 $arr = [];
767 $evals{$lvalue} = $arr;
768 }
769
770 push @{$arr}, $rvalue;
771}
772
Steven Rostedt77d942c2011-05-20 13:36:58 -0400773sub set_variable {
774 my ($lvalue, $rvalue) = @_;
775
776 if ($rvalue =~ /^\s*$/) {
777 delete $variable{$lvalue};
778 } else {
779 $rvalue = process_variables($rvalue);
780 $variable{$lvalue} = $rvalue;
781 }
782}
783
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400784sub process_compare {
785 my ($lval, $cmp, $rval) = @_;
786
787 # remove whitespace
788
789 $lval =~ s/^\s*//;
790 $lval =~ s/\s*$//;
791
792 $rval =~ s/^\s*//;
793 $rval =~ s/\s*$//;
794
795 if ($cmp eq "==") {
796 return $lval eq $rval;
797 } elsif ($cmp eq "!=") {
798 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400799 } elsif ($cmp eq "=~") {
800 return $lval =~ m/$rval/;
801 } elsif ($cmp eq "!~") {
802 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400803 }
804
805 my $statement = "$lval $cmp $rval";
806 my $ret = eval $statement;
807
808 # $@ stores error of eval
809 if ($@) {
810 return -1;
811 }
812
813 return $ret;
814}
815
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400816sub value_defined {
817 my ($val) = @_;
818
819 return defined($variable{$2}) ||
820 defined($opt{$2});
821}
822
Steven Rostedt8d735212011-10-17 11:36:44 -0400823my $d = 0;
824sub process_expression {
825 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400826
Steven Rostedt8d735212011-10-17 11:36:44 -0400827 my $c = $d++;
828
829 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
830 my $express = $1;
831
832 if (process_expression($name, $express)) {
833 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
834 } else {
835 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
836 }
837 }
838
839 $d--;
840 my $OR = "\\|\\|";
841 my $AND = "\\&\\&";
842
843 while ($val =~ s/^(.*?)($OR|$AND)//) {
844 my $express = $1;
845 my $op = $2;
846
847 if (process_expression($name, $express)) {
848 if ($op eq "||") {
849 return 1;
850 }
851 } else {
852 if ($op eq "&&") {
853 return 0;
854 }
855 }
856 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400857
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400858 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400859 my $ret = process_compare($1, $2, $3);
860 if ($ret < 0) {
861 die "$name: $.: Unable to process comparison\n";
862 }
863 return $ret;
864 }
865
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400866 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
867 if (defined $1) {
868 return !value_defined($2);
869 } else {
870 return value_defined($2);
871 }
872 }
873
Steven Rostedt45d73a52011-09-30 19:44:53 -0400874 if ($val =~ /^\s*0\s*$/) {
875 return 0;
876 } elsif ($val =~ /^\s*\d+\s*$/) {
877 return 1;
878 }
879
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400880 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400881}
882
883sub process_if {
884 my ($name, $value) = @_;
885
886 # Convert variables and replace undefined ones with 0
887 my $val = process_variables($value, 1);
888 my $ret = process_expression $name, $val;
889
890 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400891}
892
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400893sub __read_config {
894 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400895
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400896 my $in;
897 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400898
Steven Rostedta57419b2010-11-02 15:13:54 -0400899 my $name = $config;
900 $name =~ s,.*/(.*),$1,;
901
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400902 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400903 my $default = 1;
904 my $repeat = 1;
905 my $num_tests_set = 0;
906 my $skip = 0;
907 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400908 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400909 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400910 my $if = 0;
911 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400912 my $override = 0;
913
914 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400915
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400916 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400917
918 # ignore blank lines and comments
919 next if (/^\s*$/ || /\s*\#/);
920
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400921 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400922
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400923 my $type = $1;
924 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400925 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400926
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400927 my $old_test_num;
928 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400929 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400930
931 if ($type eq "TEST_START") {
932
933 if ($num_tests_set) {
934 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
935 }
936
937 $old_test_num = $test_num;
938 $old_repeat = $repeat;
939
940 $test_num += $repeat;
941 $default = 0;
942 $repeat = 1;
943 } else {
944 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400945 }
946
Steven Rostedta9f84422011-10-17 11:06:29 -0400947 # If SKIP is anywhere in the line, the command will be skipped
948 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400949 $skip = 1;
950 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400951 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400952 $skip = 0;
953 }
954
Steven Rostedta9f84422011-10-17 11:06:29 -0400955 if ($rest =~ s/\sELSE\b//) {
956 if (!$if) {
957 die "$name: $.: ELSE found with out matching IF section\n$_";
958 }
959 $if = 0;
960
961 if ($if_set) {
962 $skip = 1;
963 } else {
964 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400965 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400966 }
967
Steven Rostedta9f84422011-10-17 11:06:29 -0400968 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400969 if (process_if($name, $1)) {
970 $if_set = 1;
971 } else {
972 $skip = 1;
973 }
974 $if = 1;
975 } else {
976 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400977 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400978 }
979
Steven Rostedta9f84422011-10-17 11:06:29 -0400980 if (!$skip) {
981 if ($type eq "TEST_START") {
982 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
983 $repeat = $1;
984 $repeat_tests{"$test_num"} = $repeat;
985 }
986 } elsif ($rest =~ s/\sOVERRIDE\b//) {
987 # DEFAULT only
988 $override = 1;
989 # Clear previous overrides
990 %overrides = ();
991 }
992 }
993
994 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400995 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400996 }
997
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400998 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400999 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -04001000 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -04001001 }
1002
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001003 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -04001004 if (!$if) {
1005 die "$name: $.: ELSE found with out matching IF section\n$_";
1006 }
1007 $rest = $1;
1008 if ($if_set) {
1009 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001010 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -04001011 } else {
1012 $skip = 0;
1013
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001014 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -04001015 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -04001016 if (process_if($name, $1)) {
1017 $if_set = 1;
1018 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -04001019 $skip = 1;
1020 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001021 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -04001022 } else {
1023 $if = 0;
1024 }
1025 }
1026
Steven Rostedtab7a3f52011-09-30 20:24:07 -04001027 if ($rest !~ /^\s*$/) {
1028 die "$name: $.: Gargbage found after DEFAULTS\n$_";
1029 }
1030
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001031 } elsif (/^\s*INCLUDE\s+(\S+)/) {
1032
1033 next if ($skip);
1034
1035 if (!$default) {
1036 die "$name: $.: INCLUDE can only be done in default sections\n$_";
1037 }
1038
1039 my $file = process_variables($1);
1040
1041 if ($file !~ m,^/,) {
1042 # check the path of the config file first
1043 if ($config =~ m,(.*)/,) {
1044 if (-f "$1/$file") {
1045 $file = "$1/$file";
1046 }
1047 }
1048 }
1049
1050 if ( ! -r $file ) {
1051 die "$name: $.: Can't read file $file\n$_";
1052 }
1053
1054 if (__read_config($file, \$test_num)) {
1055 $test_case = 1;
1056 }
1057
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001058 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
1059
1060 next if ($skip);
1061
1062 my $lvalue = $1;
1063 my $rvalue = $2;
1064
1065 if ($default || $lvalue =~ /\[\d+\]$/) {
1066 set_eval($lvalue, $rvalue, $name);
1067 } else {
1068 my $val = "$lvalue\[$test_num\]";
1069 set_eval($val, $rvalue, $name);
1070 }
1071
Steven Rostedta57419b2010-11-02 15:13:54 -04001072 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1073
1074 next if ($skip);
1075
Steven Rostedt2545eb62010-11-02 15:01:32 -04001076 my $lvalue = $1;
1077 my $rvalue = $2;
1078
Steven Rostedta57419b2010-11-02 15:13:54 -04001079 if (!$default &&
1080 ($lvalue eq "NUM_TESTS" ||
1081 $lvalue eq "LOG_FILE" ||
1082 $lvalue eq "CLEAR_LOG")) {
1083 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001084 }
Steven Rostedta57419b2010-11-02 15:13:54 -04001085
1086 if ($lvalue eq "NUM_TESTS") {
1087 if ($test_num) {
1088 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1089 }
1090 if (!$default) {
1091 die "$name: $.: NUM_TESTS must be set in default section\n";
1092 }
1093 $num_tests_set = 1;
1094 }
1095
1096 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001097 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001098 } else {
1099 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001100 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001101
1102 if ($repeat > 1) {
1103 $repeats{$val} = $repeat;
1104 }
1105 }
Steven Rostedt77d942c2011-05-20 13:36:58 -04001106 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1107 next if ($skip);
1108
1109 my $lvalue = $1;
1110 my $rvalue = $2;
1111
1112 # process config variables.
1113 # Config variables are only active while reading the
1114 # config and can be defined anywhere. They also ignore
1115 # TEST_START and DEFAULTS, but are skipped if they are in
1116 # on of these sections that have SKIP defined.
1117 # The save variable can be
1118 # defined multiple times and the new one simply overrides
1119 # the prevous one.
1120 set_variable($lvalue, $rvalue);
1121
Steven Rostedta57419b2010-11-02 15:13:54 -04001122 } else {
1123 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001124 }
1125 }
1126
Steven Rostedta57419b2010-11-02 15:13:54 -04001127 if ($test_num) {
1128 $test_num += $repeat - 1;
1129 $opt{"NUM_TESTS"} = $test_num;
1130 }
1131
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001132 close($in);
1133
1134 $$current_test_num = $test_num;
1135
1136 return $test_case;
1137}
1138
Steven Rostedtc4261d02011-11-23 13:41:18 -05001139sub get_test_case {
1140 print "What test case would you like to run?\n";
1141 print " (build, install or boot)\n";
1142 print " Other tests are available but require editing the config file\n";
1143 my $ans = <STDIN>;
1144 chomp $ans;
1145 $default{"TEST_TYPE"} = $ans;
1146}
1147
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001148sub read_config {
1149 my ($config) = @_;
1150
1151 my $test_case;
1152 my $test_num = 0;
1153
1154 $test_case = __read_config $config, \$test_num;
1155
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001156 # make sure we have all mandatory configs
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09001157 get_mandatory_configs;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001158
Steven Rostedt0df213c2011-06-14 20:51:37 -04001159 # was a test specified?
1160 if (!$test_case) {
1161 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001162 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001163 }
1164
Steven Rostedta75fece2010-11-02 14:58:27 -04001165 # set any defaults
1166
1167 foreach my $default (keys %default) {
1168 if (!defined($opt{$default})) {
1169 $opt{$default} = $default{$default};
1170 }
1171 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001172
1173 if ($opt{"IGNORE_UNUSED"} == 1) {
1174 return;
1175 }
1176
1177 my %not_used;
1178
1179 # check if there are any stragglers (typos?)
1180 foreach my $option (keys %opt) {
1181 my $op = $option;
1182 # remove per test labels.
1183 $op =~ s/\[.*\]//;
1184 if (!exists($option_map{$op}) &&
1185 !exists($default{$op}) &&
1186 !exists($used_options{$op})) {
1187 $not_used{$op} = 1;
1188 }
1189 }
1190
1191 if (%not_used) {
1192 my $s = "s are";
1193 $s = " is" if (keys %not_used == 1);
1194 print "The following option$s not used; could be a typo:\n";
1195 foreach my $option (keys %not_used) {
1196 print "$option\n";
1197 }
1198 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1199 if (!read_yn "Do you want to continue?") {
1200 exit -1;
1201 }
1202 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001203}
1204
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001205sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001206 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001207
1208 # Add space to evaluate the character before $
1209 $option = " $option";
1210 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301211 my $repeated = 0;
1212 my $parent = 0;
1213
1214 foreach my $test (keys %repeat_tests) {
1215 if ($i >= $test &&
1216 $i < $test + $repeat_tests{$test}) {
1217
1218 $repeated = 1;
1219 $parent = $test;
1220 last;
1221 }
1222 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001223
1224 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1225 my $start = $1;
1226 my $var = $2;
1227 my $end = $3;
1228
1229 # Append beginning of line
1230 $retval = "$retval$start";
1231
1232 # If the iteration option OPT[$i] exists, then use that.
1233 # otherwise see if the default OPT (without [$i]) exists.
1234
1235 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301236 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001237
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001238 # If a variable contains itself, use the default var
1239 if (($var eq $name) && defined($opt{$var})) {
1240 $o = $opt{$var};
1241 $retval = "$retval$o";
1242 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001243 $o = $opt{$o};
1244 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301245 } elsif ($repeated && defined($opt{$parento})) {
1246 $o = $opt{$parento};
1247 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001248 } elsif (defined($opt{$var})) {
1249 $o = $opt{$var};
1250 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001251 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1252 # special option KERNEL_VERSION uses kernel version
1253 get_version();
1254 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001255 } else {
1256 $retval = "$retval\$\{$var\}";
1257 }
1258
1259 $option = $end;
1260 }
1261
1262 $retval = "$retval$option";
1263
1264 $retval =~ s/^ //;
1265
1266 return $retval;
1267}
1268
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001269sub process_evals {
1270 my ($name, $option, $i) = @_;
1271
1272 my $option_name = "$name\[$i\]";
1273 my $ev;
1274
1275 my $old_option = $option;
1276
1277 if (defined($evals{$option_name})) {
1278 $ev = $evals{$option_name};
1279 } elsif (defined($evals{$name})) {
1280 $ev = $evals{$name};
1281 } else {
1282 return $option;
1283 }
1284
1285 for my $e (@{$ev}) {
1286 eval "\$option =~ $e";
1287 }
1288
1289 if ($option ne $old_option) {
1290 doprint("$name changed from '$old_option' to '$option'\n");
1291 }
1292
1293 return $option;
1294}
1295
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001296sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001297 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001298
1299 my $prev = "";
1300
1301 # Since an option can evaluate to another option,
1302 # keep iterating until we do not evaluate any more
1303 # options.
1304 my $r = 0;
1305 while ($prev ne $option) {
1306 # Check for recursive evaluations.
1307 # 100 deep should be more than enough.
1308 if ($r++ > 100) {
1309 die "Over 100 evaluations accurred with $option\n" .
1310 "Check for recursive variables\n";
1311 }
1312 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001313 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001314 }
1315
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001316 $option = process_evals($name, $option, $i);
1317
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001318 return $option;
1319}
1320
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001321sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001322sub start_monitor;
1323sub end_monitor;
1324sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001325
1326sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001327 my ($time) = @_;
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001328 my $powercycle = 0;
Andrew Jones2728be42011-08-12 15:32:05 +02001329
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001330 # test if the machine can be connected to within 5 seconds
1331 my $stat = run_ssh("echo check machine status", 5);
1332 if (!$stat) {
1333 doprint("power cycle\n");
1334 $powercycle = 1;
1335 }
Steven Rostedta4968722012-12-11 14:59:05 -05001336
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001337 if ($powercycle) {
1338 run_command "$power_cycle";
1339
Steven Rostedt2b803362011-09-30 18:00:23 -04001340 start_monitor;
1341 # flush out current monitor
1342 # May contain the reboot success line
1343 wait_for_monitor 1;
Steven Rostedt2b803362011-09-30 18:00:23 -04001344
Steven Rostedt (VMware)6474ace2017-02-07 12:13:08 -05001345 } else {
1346 # Make sure everything has been written to disk
1347 run_ssh("sync");
1348
1349 if (defined($time)) {
1350 start_monitor;
1351 # flush out current monitor
1352 # May contain the reboot success line
1353 wait_for_monitor 1;
1354 }
1355
1356 # try to reboot normally
1357 if (run_command $reboot) {
1358 if (defined($powercycle_after_reboot)) {
1359 sleep $powercycle_after_reboot;
1360 run_command "$power_cycle";
1361 }
1362 } else {
1363 # nope? power cycle it.
Steven Rostedt576f6272010-11-02 14:58:38 -04001364 run_command "$power_cycle";
1365 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001366 }
Andrew Jones2728be42011-08-12 15:32:05 +02001367
1368 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001369
1370 # We only want to get to the new kernel, don't fail
1371 # if we stumble over a call trace.
1372 my $save_ignore_errors = $ignore_errors;
1373 $ignore_errors = 1;
1374
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001375 # Look for the good kernel to boot
1376 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001377 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001378 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001379 run_command "$power_cycle";
1380 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001381
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001382 $ignore_errors = $save_ignore_errors;
1383
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001384 # Still need to wait for the reboot to finish
1385 wait_for_monitor($time, $reboot_success_line);
1386
Andrew Jones2728be42011-08-12 15:32:05 +02001387 end_monitor;
1388 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001389}
1390
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001391sub reboot_to_good {
1392 my ($time) = @_;
1393
1394 if (defined($switch_to_good)) {
1395 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001396 }
1397
1398 reboot $time;
1399}
1400
Steven Rostedt576f6272010-11-02 14:58:38 -04001401sub do_not_reboot {
1402 my $i = $iteration;
1403
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001404 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001405 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1406 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1407}
1408
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001409sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001410 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001411
Steven Rostedt576f6272010-11-02 14:58:38 -04001412 my $i = $iteration;
1413
1414 if ($reboot_on_error && !do_not_reboot) {
1415
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001416 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001417 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001418
Steven Rostedta75fece2010-11-02 14:58:27 -04001419 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001420 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001421 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001422 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001423
Steven Rostedtf80802c2011-03-07 13:18:47 -05001424 if (defined($opt{"LOG_FILE"})) {
1425 print " See $opt{LOG_FILE} for more info.\n";
1426 }
1427
Josh Poimboeuf1cb9e642015-01-29 20:54:53 -06001428 if ($monitor_cnt) {
1429 # restore terminal settings
1430 system("stty $stty_orig");
1431 }
1432
Steven Rostedt (VMware)2e07c9f2017-02-07 11:49:21 -05001433 if (defined($post_test)) {
1434 run_command $post_test;
1435 }
1436
Steven Rostedt576f6272010-11-02 14:58:38 -04001437 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001438}
1439
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001440sub create_pty {
1441 my ($ptm, $pts) = @_;
1442 my $tmp;
1443 my $TIOCSPTLCK = 0x40045431;
1444 my $TIOCGPTN = 0x80045430;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001445
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001446 sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
1447 dodie "Cant open /dev/ptmx";
1448
1449 # unlockpt()
1450 $tmp = pack("i", 0);
1451 ioctl($ptm, $TIOCSPTLCK, $tmp) or
1452 dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
1453
1454 # ptsname()
1455 ioctl($ptm, $TIOCGPTN, $tmp) or
1456 dodie "ioctl TIOCGPTN for /dev/ptmx failed";
1457 $tmp = unpack("i", $tmp);
1458
1459 sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
1460 dodie "Can't open /dev/pts/$tmp";
1461}
1462
1463sub exec_console {
1464 my ($ptm, $pts) = @_;
1465
1466 close($ptm);
1467
1468 close(\*STDIN);
1469 close(\*STDOUT);
1470 close(\*STDERR);
1471
1472 open(\*STDIN, '<&', $pts);
1473 open(\*STDOUT, '>&', $pts);
1474 open(\*STDERR, '>&', $pts);
1475
1476 close($pts);
1477
1478 exec $console or
Josh Poimboeuf1cb9e642015-01-29 20:54:53 -06001479 die "Can't open console $console";
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001480}
1481
1482sub open_console {
1483 my ($ptm) = @_;
1484 my $pts = \*PTSFD;
1485 my $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001486
Josh Poimboeuf98842782015-01-27 12:10:04 -06001487 # save terminal settings
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001488 $stty_orig = `stty -g`;
1489
1490 # place terminal in cbreak mode so that stdin can be read one character at
1491 # a time without having to wait for a newline
1492 system("stty -icanon -echo -icrnl");
Josh Poimboeuf98842782015-01-27 12:10:04 -06001493
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001494 create_pty($ptm, $pts);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001495
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001496 $pid = fork;
1497
1498 if (!$pid) {
1499 # child
1500 exec_console($ptm, $pts)
1501 }
1502
1503 # parent
1504 close($pts);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001505
1506 return $pid;
Josh Poimboeuf9f2cdcb2015-01-28 13:38:38 -06001507
1508 open(PTSFD, "Stop perl from warning about single use of PTSFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001509}
1510
1511sub close_console {
1512 my ($fp, $pid) = @_;
1513
1514 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001515 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001516
1517 print "closing!\n";
1518 close($fp);
Josh Poimboeuf98842782015-01-27 12:10:04 -06001519
1520 # restore terminal settings
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001521 system("stty $stty_orig");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001522}
1523
1524sub start_monitor {
1525 if ($monitor_cnt++) {
1526 return;
1527 }
1528 $monitor_fp = \*MONFD;
1529 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001530
1531 return;
1532
1533 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001534}
1535
1536sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001537 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001538 if (--$monitor_cnt) {
1539 return;
1540 }
1541 close_console($monitor_fp, $monitor_pid);
1542}
1543
1544sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001545 my ($time, $stop) = @_;
1546 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001547 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001548 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001549 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001550 my $skip_call_trace = 0;
1551 my $bug = 0;
1552 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001553 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001554
Steven Rostedta75fece2010-11-02 14:58:27 -04001555 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001556
1557 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001558 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001559 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001560 last if (!defined($line));
1561 print "$line";
1562 $full_line .= $line;
1563
1564 if (defined($stop) && $full_line =~ /$stop/) {
1565 doprint "wait for monitor detected $stop\n";
1566 $booted = 1;
1567 }
1568
Steven Rostedt8a80c722012-07-19 16:08:33 -04001569 if ($full_line =~ /\[ backtrace testing \]/) {
1570 $skip_call_trace = 1;
1571 }
1572
1573 if ($full_line =~ /call trace:/i) {
1574 if (!$bug && !$skip_call_trace) {
1575 if ($ignore_errors) {
1576 $bug_ignored = 1;
1577 } else {
1578 $bug = 1;
1579 }
1580 }
1581 }
1582
1583 if ($full_line =~ /\[ end of backtrace testing \]/) {
1584 $skip_call_trace = 0;
1585 }
1586
1587 if ($full_line =~ /Kernel panic -/) {
1588 $bug = 1;
1589 }
1590
Steven Rostedt2b803362011-09-30 18:00:23 -04001591 if ($line =~ /\n/) {
1592 $full_line = "";
1593 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001594 $now = time;
1595 if ($now - $start_time >= $max_monitor_wait) {
1596 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1597 return 1;
1598 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001599 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001600 print "** Monitor flushed **\n";
Steven Rostedt (Red Hat)995bc432014-10-07 16:31:07 -04001601
1602 # if stop is defined but wasn't hit, return error
1603 # used by reboot (which wants to see a reboot)
1604 if (defined($stop) && !$booted) {
1605 $bug = 1;
1606 }
Steven Rostedt8a80c722012-07-19 16:08:33 -04001607 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001608}
1609
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301610sub save_logs {
1611 my ($result, $basedir) = @_;
1612 my @t = localtime;
1613 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1614 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1615
1616 my $type = $build_type;
1617 if ($type =~ /useconfig/) {
1618 $type = "useconfig";
1619 }
1620
1621 my $dir = "$machine-$test_type-$type-$result-$date";
1622
1623 $dir = "$basedir/$dir";
1624
1625 if (!-d $dir) {
1626 mkpath($dir) or
1627 die "can't create $dir";
1628 }
1629
1630 my %files = (
1631 "config" => $output_config,
1632 "buildlog" => $buildlog,
1633 "dmesg" => $dmesg,
1634 "testlog" => $testlog,
1635 );
1636
1637 while (my ($name, $source) = each(%files)) {
1638 if (-f "$source") {
1639 cp "$source", "$dir/$name" or
1640 die "failed to copy $source";
1641 }
1642 }
1643
1644 doprint "*** Saved info to $dir ***\n";
1645}
1646
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001647sub fail {
1648
Steven Rostedta75fece2010-11-02 14:58:27 -04001649 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001650 dodie @_;
1651 }
1652
Steven Rostedta75fece2010-11-02 14:58:27 -04001653 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001654
Steven Rostedt576f6272010-11-02 14:58:38 -04001655 my $i = $iteration;
1656
Steven Rostedta75fece2010-11-02 14:58:27 -04001657 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001658 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001659 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001660 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001661 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001662
Steven Rostedt9064af52011-06-13 10:38:48 -04001663 my $name = "";
1664
1665 if (defined($test_name)) {
1666 $name = " ($test_name)";
1667 }
1668
Steven Rostedt (Red Hat)4bf6e1f2015-01-29 10:06:07 -05001669 print_times;
1670
Steven Rostedt576f6272010-11-02 14:58:38 -04001671 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1672 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001673 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001674 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1675 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001676
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301677 if (defined($store_failures)) {
1678 save_logs "fail", $store_failures;
1679 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001680
Steven Rostedt (VMware)2e07c9f2017-02-07 11:49:21 -05001681 if (defined($post_test)) {
1682 run_command $post_test;
1683 }
1684
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001685 return 1;
1686}
1687
Steven Rostedt2545eb62010-11-02 15:01:32 -04001688sub run_command {
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001689 my ($command, $redirect, $timeout) = @_;
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001690 my $start_time;
1691 my $end_time;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001692 my $dolog = 0;
1693 my $dord = 0;
1694 my $pid;
1695
Steven Rostedte48c5292010-11-02 14:35:37 -04001696 $command =~ s/\$SSH_USER/$ssh_user/g;
1697 $command =~ s/\$MACHINE/$machine/g;
1698
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001699 doprint("$command ... ");
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001700 $start_time = time;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001701
1702 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001703 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001704
1705 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001706 open(LOG, ">>$opt{LOG_FILE}") or
1707 dodie "failed to write to log";
1708 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001709 }
1710
1711 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001712 open (RD, ">$redirect") or
1713 dodie "failed to write to redirect $redirect";
1714 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001715 }
1716
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001717 my $hit_timeout = 0;
1718
1719 while (1) {
1720 my $fp = \*CMD;
1721 if (defined($timeout)) {
1722 doprint "timeout = $timeout\n";
1723 }
1724 my $line = wait_for_input($fp, $timeout);
1725 if (!defined($line)) {
1726 my $now = time;
1727 if (defined($timeout) && (($now - $start_time) >= $timeout)) {
1728 doprint "Hit timeout of $timeout, killing process\n";
1729 $hit_timeout = 1;
1730 kill 9, $pid;
1731 }
1732 last;
1733 }
1734 print LOG $line if ($dolog);
1735 print RD $line if ($dord);
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001736 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001737
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001738 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001739 my $failed = $?;
1740
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001741 if ($hit_timeout) {
1742 $failed = 1;
1743 }
1744
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001745 close(CMD);
1746 close(LOG) if ($dolog);
1747 close(RD) if ($dord);
1748
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001749 $end_time = time;
1750 my $delta = $end_time - $start_time;
1751
1752 if ($delta == 1) {
1753 doprint "[1 second] ";
1754 } else {
1755 doprint "[$delta seconds] ";
1756 }
1757
Steven Rostedt2545eb62010-11-02 15:01:32 -04001758 if ($failed) {
1759 doprint "FAILED!\n";
1760 } else {
1761 doprint "SUCCESS\n";
1762 }
1763
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001764 return !$failed;
1765}
1766
Steven Rostedte48c5292010-11-02 14:35:37 -04001767sub run_ssh {
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001768 my ($cmd, $timeout) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001769 my $cp_exec = $ssh_exec;
1770
1771 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
Steven Rostedt (VMware)6e98d1b2017-02-07 12:22:03 -05001772 return run_command "$cp_exec", undef , $timeout;
Steven Rostedte48c5292010-11-02 14:35:37 -04001773}
1774
1775sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001776 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001777
1778 $cp_scp =~ s/\$SRC_FILE/$src/g;
1779 $cp_scp =~ s/\$DST_FILE/$dst/g;
1780
1781 return run_command "$cp_scp";
1782}
1783
Steven Rostedt02ad2612012-03-21 08:21:24 -04001784sub run_scp_install {
1785 my ($src, $dst) = @_;
1786
1787 my $cp_scp = $scp_to_target_install;
1788
1789 return run_scp($src, $dst, $cp_scp);
1790}
1791
1792sub run_scp_mod {
1793 my ($src, $dst) = @_;
1794
1795 my $cp_scp = $scp_to_target;
1796
1797 return run_scp($src, $dst, $cp_scp);
1798}
1799
Steven Rostedta15ba912012-11-13 14:30:37 -05001800sub get_grub2_index {
1801
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001802 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001803 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1804 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001805
1806 doprint "Find grub2 menu ... ";
1807 $grub_number = -1;
1808
1809 my $ssh_grub = $ssh_exec;
1810 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1811
1812 open(IN, "$ssh_grub |")
1813 or die "unable to get $grub_file";
1814
1815 my $found = 0;
1816
1817 while (<IN>) {
1818 if (/^menuentry.*$grub_menu/) {
1819 $grub_number++;
1820 $found = 1;
1821 last;
1822 } elsif (/^menuentry\s/) {
1823 $grub_number++;
1824 }
1825 }
1826 close(IN);
1827
1828 die "Could not find '$grub_menu' in $grub_file on $machine"
1829 if (!$found);
1830 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001831 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001832 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001833}
1834
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001835sub get_grub_index {
1836
Steven Rostedta15ba912012-11-13 14:30:37 -05001837 if ($reboot_type eq "grub2") {
1838 get_grub2_index;
1839 return;
1840 }
1841
Steven Rostedta75fece2010-11-02 14:58:27 -04001842 if ($reboot_type ne "grub") {
1843 return;
1844 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001845 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001846 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1847 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001848
1849 doprint "Find grub menu ... ";
1850 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001851
1852 my $ssh_grub = $ssh_exec;
1853 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1854
1855 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001856 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001857
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001858 my $found = 0;
1859
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001860 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001861 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001862 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001863 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001864 last;
1865 } elsif (/^\s*title\s/) {
1866 $grub_number++;
1867 }
1868 }
1869 close(IN);
1870
Steven Rostedta75fece2010-11-02 14:58:27 -04001871 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001872 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001873 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001874 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001875 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001876}
1877
Steven Rostedt2545eb62010-11-02 15:01:32 -04001878sub wait_for_input
1879{
1880 my ($fp, $time) = @_;
1881 my $rin;
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001882 my $rout;
1883 my $nr;
1884 my $buf;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001885 my $line;
1886 my $ch;
1887
1888 if (!defined($time)) {
1889 $time = $timeout;
1890 }
1891
1892 $rin = '';
1893 vec($rin, fileno($fp), 1) = 1;
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001894 vec($rin, fileno(\*STDIN), 1) = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001895
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001896 while (1) {
1897 $nr = select($rout=$rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001898
Josh Poimboeuf9d2f7f02015-01-28 13:38:39 -06001899 if ($nr <= 0) {
1900 return undef;
1901 }
1902
1903 # copy data from stdin to the console
1904 if (vec($rout, fileno(\*STDIN), 1) == 1) {
1905 sysread(\*STDIN, $buf, 1000);
1906 syswrite($fp, $buf, 1000);
1907 next;
1908 }
1909
1910 $line = "";
1911
1912 # try to read one char at a time
1913 while (sysread $fp, $ch, 1) {
1914 $line .= $ch;
1915 last if ($ch eq "\n");
1916 }
1917
1918 if (!length($line)) {
1919 return undef;
1920 }
1921
1922 return $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001923 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001924}
1925
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001926sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001927 if (defined($switch_to_test)) {
1928 run_command $switch_to_test;
1929 }
1930
Steven Rostedta75fece2010-11-02 14:58:27 -04001931 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001932 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001933 } elsif ($reboot_type eq "grub2") {
1934 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001935 } elsif ($reboot_type eq "syslinux") {
1936 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001937 } elsif (defined $reboot_script) {
1938 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001939 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001940 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001941}
1942
Steven Rostedta57419b2010-11-02 15:13:54 -04001943sub get_sha1 {
1944 my ($commit) = @_;
1945
1946 doprint "git rev-list --max-count=1 $commit ... ";
1947 my $sha1 = `git rev-list --max-count=1 $commit`;
1948 my $ret = $?;
1949
1950 logit $sha1;
1951
1952 if ($ret) {
1953 doprint "FAILED\n";
1954 dodie "Failed to get git $commit";
1955 }
1956
1957 print "SUCCESS\n";
1958
1959 chomp $sha1;
1960
1961 return $sha1;
1962}
1963
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001964sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001965 my $booted = 0;
1966 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001967 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001968 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001969 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001970
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05001971 my $start_time = time;
1972
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001973 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001974
1975 my $line;
1976 my $full_line = "";
1977
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001978 open(DMESG, "> $dmesg") or
1979 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001980
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001981 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001982
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001983 my $success_start;
1984 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001985 my $monitor_start = time;
1986 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001987 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001988
Steven Rostedt2d01b262011-03-08 09:47:54 -05001989 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001990
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001991 if ($bug && defined($stop_after_failure) &&
1992 $stop_after_failure >= 0) {
1993 my $time = $stop_after_failure - (time - $failure_start);
1994 $line = wait_for_input($monitor_fp, $time);
1995 if (!defined($line)) {
1996 doprint "bug timed out after $booted_timeout seconds\n";
1997 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1998 last;
1999 }
2000 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002001 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04002002 if (!defined($line)) {
2003 my $s = $booted_timeout == 1 ? "" : "s";
2004 doprint "Successful boot found: break after $booted_timeout second$s\n";
2005 last;
2006 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002007 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002008 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04002009 if (!defined($line)) {
2010 my $s = $timeout == 1 ? "" : "s";
2011 doprint "Timed out after $timeout second$s\n";
2012 last;
2013 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002014 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002015
Steven Rostedt2545eb62010-11-02 15:01:32 -04002016 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002017 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002018
2019 # we are not guaranteed to get a full line
2020 $full_line .= $line;
2021
Steven Rostedta75fece2010-11-02 14:58:27 -04002022 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04002023 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002024 $success_start = time;
2025 }
2026
2027 if ($booted && defined($stop_after_success) &&
2028 $stop_after_success >= 0) {
2029 my $now = time;
2030 if ($now - $success_start >= $stop_after_success) {
2031 doprint "Test forced to stop after $stop_after_success seconds after success\n";
2032 last;
2033 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002034 }
2035
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002036 if ($full_line =~ /\[ backtrace testing \]/) {
2037 $skip_call_trace = 1;
2038 }
2039
Steven Rostedt2545eb62010-11-02 15:01:32 -04002040 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04002041 if (!$bug && !$skip_call_trace) {
2042 if ($ignore_errors) {
2043 $bug_ignored = 1;
2044 } else {
2045 $bug = 1;
2046 $failure_start = time;
2047 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05002048 }
2049 }
2050
2051 if ($bug && defined($stop_after_failure) &&
2052 $stop_after_failure >= 0) {
2053 my $now = time;
2054 if ($now - $failure_start >= $stop_after_failure) {
2055 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
2056 last;
2057 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002058 }
2059
2060 if ($full_line =~ /\[ end of backtrace testing \]/) {
2061 $skip_call_trace = 0;
2062 }
2063
2064 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05002065 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002066 $bug = 1;
2067 }
2068
Steven Rostedtf1a5b962011-06-13 10:30:00 -04002069 # Detect triple faults by testing the banner
2070 if ($full_line =~ /\bLinux version (\S+).*\n/) {
2071 if ($1 eq $version) {
2072 $version_found = 1;
2073 } elsif ($version_found && $detect_triplefault) {
2074 # We already booted into the kernel we are testing,
2075 # but now we booted into another kernel?
2076 # Consider this a triple fault.
Masanari Iida8b513d02013-05-21 23:13:12 +09002077 doprint "Already booted in Linux kernel $version, but now\n";
Steven Rostedtf1a5b962011-06-13 10:30:00 -04002078 doprint "we booted into Linux kernel $1.\n";
2079 doprint "Assuming that this is a triple fault.\n";
2080 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
2081 last;
2082 }
2083 }
2084
Steven Rostedt2545eb62010-11-02 15:01:32 -04002085 if ($line =~ /\n/) {
2086 $full_line = "";
2087 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05002088
2089 if ($stop_test_after > 0 && !$booted && !$bug) {
2090 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04002091 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05002092 $done = 1;
2093 }
2094 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002095 }
2096
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002097 my $end_time = time;
2098 $reboot_time = $end_time - $start_time;
2099
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002100 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002101
Steven Rostedt2545eb62010-11-02 15:01:32 -04002102 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002103 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04002104 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002105 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002106
Steven Rostedta75fece2010-11-02 14:58:27 -04002107 if (!$booted) {
2108 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04002109 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04002110 }
2111
Steven Rostedt6ca996c2012-03-21 08:18:35 -04002112 if ($bug_ignored) {
2113 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2114 }
2115
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002116 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002117}
2118
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05002119sub eval_kernel_version {
2120 my ($option) = @_;
2121
2122 $option =~ s/\$KERNEL_VERSION/$version/g;
2123
2124 return $option;
2125}
2126
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002127sub do_post_install {
2128
2129 return if (!defined($post_install));
2130
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05002131 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002132 run_command "$cp_post_install" or
2133 dodie "Failed to run post install";
2134}
2135
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05002136# Sometimes the reboot fails, and will hang. We try to ssh to the box
2137# and if we fail, we force another reboot, that should powercycle it.
2138sub test_booted {
2139 if (!run_ssh "echo testing connection") {
2140 reboot $sleep_time;
2141 }
2142}
2143
Steven Rostedt2545eb62010-11-02 15:01:32 -04002144sub install {
2145
Steven Rostedte0a87422011-09-30 17:50:48 -04002146 return if ($no_install);
2147
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002148 my $start_time = time;
2149
Steven Rostedte5c2ec12012-07-19 15:22:05 -04002150 if (defined($pre_install)) {
2151 my $cp_pre_install = eval_kernel_version $pre_install;
2152 run_command "$cp_pre_install" or
2153 dodie "Failed to run pre install";
2154 }
2155
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05002156 my $cp_target = eval_kernel_version $target_image;
2157
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05002158 test_booted;
2159
Steven Rostedt02ad2612012-03-21 08:21:24 -04002160 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002161 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002162
2163 my $install_mods = 0;
2164
2165 # should we process modules?
2166 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002167 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002168 while (<IN>) {
2169 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04002170 if (defined($1)) {
2171 $install_mods = 1;
2172 last;
2173 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002174 }
2175 }
2176 close(IN);
2177
2178 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002179 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002180 doprint "No modules needed\n";
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002181 my $end_time = time;
2182 $install_time = $end_time - $start_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002183 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002184 }
2185
Steven Rostedt627977d2012-03-21 08:16:15 -04002186 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002187 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002188
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002189 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04002190 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002191
Steven Rostedte48c5292010-11-02 14:35:37 -04002192 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002193 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002194
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002195 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04002196 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002197 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002198
Steven Rostedt02ad2612012-03-21 08:21:24 -04002199 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002200 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002201
Steven Rostedta75fece2010-11-02 14:58:27 -04002202 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002203
Steven Rostedte7b13442011-06-14 20:44:36 -04002204 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002205 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002206
Steven Rostedte48c5292010-11-02 14:35:37 -04002207 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002208
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002209 do_post_install;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002210
2211 my $end_time = time;
2212 $install_time = $end_time - $start_time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002213}
2214
Steven Rostedtddf607e2011-06-14 20:49:13 -04002215sub get_version {
2216 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04002217 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002218 doprint "$make kernelrelease ... ";
Steven Rostedt (Red Hat)17150fe2014-11-23 15:13:44 -05002219 $version = `$make -s kernelrelease | tail -1`;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002220 chomp($version);
2221 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002222 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002223}
2224
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05002225sub start_monitor_and_install {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002226 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002227
2228 # Install bisects, don't need console
2229 if (defined $console) {
2230 start_monitor;
2231 wait_for_monitor 5;
2232 end_monitor;
2233 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002234
Steven Rostedtddf607e2011-06-14 20:49:13 -04002235 get_grub_index;
2236 get_version;
2237 install;
2238
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002239 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002240 return monitor;
2241}
2242
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002243my $check_build_re = ".*:.*(warning|error|Error):.*";
2244my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2245
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002246sub process_warning_line {
2247 my ($line) = @_;
2248
2249 chomp $line;
2250
2251 # for distcc heterogeneous systems, some compilers
2252 # do things differently causing warning lines
2253 # to be slightly different. This makes an attempt
2254 # to fixe those issues.
2255
2256 # chop off the index into the line
2257 # using distcc, some compilers give different indexes
2258 # depending on white space
2259 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2260
2261 # Some compilers use UTF-8 extended for quotes and some don't.
2262 $line =~ s/$utf8_quote/'/g;
2263
2264 return $line;
2265}
2266
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002267# Read buildlog and check against warnings file for any
2268# new warnings.
2269#
2270# Returns 1 if OK
2271# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002272sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002273 return 1 if (!defined $warnings_file);
2274
2275 my %warnings_list;
2276
2277 # Failed builds should not reboot the target
2278 my $save_no_reboot = $no_reboot;
2279 $no_reboot = 1;
2280
2281 if (-f $warnings_file) {
2282 open(IN, $warnings_file) or
2283 dodie "Error opening $warnings_file";
2284
2285 while (<IN>) {
2286 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002287 my $warning = process_warning_line $_;
2288
2289 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002290 }
2291 }
2292 close(IN);
2293 }
2294
2295 # If warnings file didn't exist, and WARNINGS_FILE exist,
2296 # then we fail on any warning!
2297
2298 open(IN, $buildlog) or dodie "Can't open $buildlog";
2299 while (<IN>) {
2300 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002301 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002302
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002303 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002304 fail "New warning found (not in $warnings_file)\n$_\n";
2305 $no_reboot = $save_no_reboot;
2306 return 0;
2307 }
2308 }
2309 }
2310 $no_reboot = $save_no_reboot;
2311 close(IN);
2312}
2313
2314sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002315 my ($patch) = @_;
2316
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002317 my @files = `git show $patch | diffstat -l`;
2318
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002319 foreach my $file (@files) {
2320 chomp $file;
2321 }
2322
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002323 open(IN, "git show $patch |") or
2324 dodie "failed to show $patch";
2325 while (<IN>) {
2326 if (m,^--- a/(.*),) {
2327 chomp $1;
2328 $files[$#files] = $1;
2329 }
2330 }
2331 close(IN);
2332
2333 open(IN, $buildlog) or dodie "Can't open $buildlog";
2334 while (<IN>) {
2335 if (/^\s*(.*?):.*(warning|error)/) {
2336 my $err = $1;
2337 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002338 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002339 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002340 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002341 }
2342 }
2343 }
2344 }
2345 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002346
2347 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002348}
2349
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002350sub apply_min_config {
2351 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002352
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002353 # Read the config file and remove anything that
2354 # is in the force_config hash (from minconfig and others)
2355 # then add the force config back.
2356
2357 doprint "Applying minimum configurations into $output_config.new\n";
2358
2359 open (OUT, ">$outconfig") or
2360 dodie "Can't create $outconfig";
2361
2362 if (-f $output_config) {
2363 open (IN, $output_config) or
2364 dodie "Failed to open $output_config";
2365 while (<IN>) {
2366 if (/^(# )?(CONFIG_[^\s=]*)/) {
2367 next if (defined($force_config{$2}));
2368 }
2369 print OUT;
2370 }
2371 close IN;
2372 }
2373 foreach my $config (keys %force_config) {
2374 print OUT "$force_config{$config}\n";
2375 }
2376 close OUT;
2377
2378 run_command "mv $outconfig $output_config";
2379}
2380
2381sub make_oldconfig {
2382
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002383 my @force_list = keys %force_config;
2384
2385 if ($#force_list >= 0) {
2386 apply_min_config;
2387 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002388
Adam Leefb16d892012-09-01 01:05:17 +08002389 if (!run_command "$make olddefconfig") {
2390 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002391 # try oldnoconfig
2392 doprint "olddefconfig failed, trying make oldnoconfig\n";
2393 if (!run_command "$make oldnoconfig") {
2394 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2395 # try a yes '' | oldconfig
2396 run_command "yes '' | $make oldconfig" or
2397 dodie "failed make config oldconfig";
2398 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002399 }
2400}
2401
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002402# read a config file and use this to force new configs.
2403sub load_force_config {
2404 my ($config) = @_;
2405
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002406 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002407 open(IN, $config) or
2408 dodie "failed to read $config";
2409 while (<IN>) {
2410 chomp;
2411 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2412 $force_config{$1} = $_;
2413 } elsif (/^# (CONFIG_\S*) is not set/) {
2414 $force_config{$1} = $_;
2415 }
2416 }
2417 close IN;
2418}
2419
Steven Rostedt2545eb62010-11-02 15:01:32 -04002420sub build {
2421 my ($type) = @_;
2422
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002423 unlink $buildlog;
2424
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002425 my $start_time = time;
2426
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002427 # Failed builds should not reboot the target
2428 my $save_no_reboot = $no_reboot;
2429 $no_reboot = 1;
2430
Steven Rostedt683a3e62012-05-18 13:34:35 -04002431 # Calculate a new version from here.
2432 $have_version = 0;
2433
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002434 if (defined($pre_build)) {
2435 my $ret = run_command $pre_build;
2436 if (!$ret && defined($pre_build_die) &&
2437 $pre_build_die) {
2438 dodie "failed to pre_build\n";
2439 }
2440 }
2441
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002442 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002443 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002444 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002445
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002446 $type = "oldconfig";
2447 }
2448
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002449 # old config can ask questions
2450 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002451 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002452
2453 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002454 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002455
Andrew Jones13488232011-08-12 15:32:04 +02002456 if (!$noclean) {
2457 run_command "mv $output_config $outputdir/config_temp" or
2458 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002459
Andrew Jones13488232011-08-12 15:32:04 +02002460 run_command "$make mrproper" or dodie "make mrproper";
2461
2462 run_command "mv $outputdir/config_temp $output_config" or
2463 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002464 }
2465
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002466 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002467 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002468 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002469 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002470 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002471
2472 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002473 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2474 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002475 close(OUT);
2476
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002477 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002478 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002479 }
2480
Adam Leefb16d892012-09-01 01:05:17 +08002481 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002482 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002483 dodie "failed make config";
2484 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002485 # Run old config regardless, to enforce min configurations
2486 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002487
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002488 my $build_ret = run_command "$make $build_options", $buildlog;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002489
2490 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002491 # Because a post build may change the kernel version
2492 # do it now.
2493 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002494 my $ret = run_command $post_build;
2495 if (!$ret && defined($post_build_die) &&
2496 $post_build_die) {
2497 dodie "failed to post_build\n";
2498 }
2499 }
2500
2501 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002502 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002503 if ($in_bisect) {
2504 $no_reboot = $save_no_reboot;
2505 return 0;
2506 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002507 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002508 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002509
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002510 $no_reboot = $save_no_reboot;
2511
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002512 my $end_time = time;
2513 $build_time = $end_time - $start_time;
2514
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002515 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002516}
2517
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002518sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002519 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002520 if (defined($poweroff_after_halt)) {
2521 sleep $poweroff_after_halt;
2522 run_command "$power_off";
2523 }
2524 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002525 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002526 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002527 }
2528}
2529
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002530sub success {
2531 my ($i) = @_;
2532
Steven Rostedte48c5292010-11-02 14:35:37 -04002533 $successes++;
2534
Steven Rostedt9064af52011-06-13 10:38:48 -04002535 my $name = "";
2536
2537 if (defined($test_name)) {
2538 $name = " ($test_name)";
2539 }
2540
Steven Rostedt (Red Hat)4bf6e1f2015-01-29 10:06:07 -05002541 print_times;
2542
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002543 doprint "\n\n*******************************************\n";
2544 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002545 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002546 doprint "*******************************************\n";
2547 doprint "*******************************************\n";
2548
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302549 if (defined($store_successes)) {
2550 save_logs "success", $store_successes;
2551 }
2552
Steven Rostedt576f6272010-11-02 14:58:38 -04002553 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002554 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002555 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002556 }
Steven Rostedt (VMware)2e07c9f2017-02-07 11:49:21 -05002557
2558 if (defined($post_test)) {
2559 run_command $post_test;
2560 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002561}
2562
Steven Rostedtc960bb92011-03-08 09:22:39 -05002563sub answer_bisect {
2564 for (;;) {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002565 doprint "Pass, fail, or skip? [p/f/s]";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002566 my $ans = <STDIN>;
2567 chomp $ans;
2568 if ($ans eq "p" || $ans eq "P") {
2569 return 1;
2570 } elsif ($ans eq "f" || $ans eq "F") {
2571 return 0;
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002572 } elsif ($ans eq "s" || $ans eq "S") {
2573 return -1;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002574 } else {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002575 print "Please answer 'p', 'f', or 's'\n";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002576 }
2577 }
2578}
2579
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002580sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002581 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002582
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002583 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002584 $reboot_on_error = 0;
2585 $poweroff_on_error = 0;
2586 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002587
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002588 run_command $run_test, $testlog or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302589
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002590 exit $failed;
2591}
2592
2593my $child_done;
2594
2595sub child_finished {
2596 $child_done = 1;
2597}
2598
2599sub do_run_test {
2600 my $child_pid;
2601 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002602 my $line;
2603 my $full_line;
2604 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002605 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002606
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002607 my $start_time = time;
2608
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002609 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002610
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002611 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002612
2613 $child_done = 0;
2614
2615 $SIG{CHLD} = qw(child_finished);
2616
2617 $child_pid = fork;
2618
2619 child_run_test if (!$child_pid);
2620
2621 $full_line = "";
2622
2623 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002624 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002625 if (defined($line)) {
2626
2627 # we are not guaranteed to get a full line
2628 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002629 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002630
2631 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002632 if ($ignore_errors) {
2633 $bug_ignored = 1;
2634 } else {
2635 $bug = 1;
2636 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002637 }
2638
2639 if ($full_line =~ /Kernel panic -/) {
2640 $bug = 1;
2641 }
2642
2643 if ($line =~ /\n/) {
2644 $full_line = "";
2645 }
2646 }
2647 } while (!$child_done && !$bug);
2648
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002649 if (!$bug && $bug_ignored) {
2650 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2651 }
2652
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002653 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002654 my $failure_start = time;
2655 my $now;
2656 do {
2657 $line = wait_for_input($monitor_fp, 1);
2658 if (defined($line)) {
2659 doprint $line;
2660 }
2661 $now = time;
2662 if ($now - $failure_start >= $stop_after_failure) {
2663 last;
2664 }
2665 } while (defined($line));
2666
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002667 doprint "Detected kernel crash!\n";
2668 # kill the child with extreme prejudice
2669 kill 9, $child_pid;
2670 }
2671
2672 waitpid $child_pid, 0;
Steven Rostedt (VMware)32677202017-02-07 12:05:25 -05002673 $child_exit = $? >> 8;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002674
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002675 my $end_time = time;
2676 $test_time = $end_time - $start_time;
2677
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002678 if (!$bug && $in_bisect) {
2679 if (defined($bisect_ret_good)) {
2680 if ($child_exit == $bisect_ret_good) {
2681 return 1;
2682 }
2683 }
2684 if (defined($bisect_ret_skip)) {
2685 if ($child_exit == $bisect_ret_skip) {
2686 return -1;
2687 }
2688 }
2689 if (defined($bisect_ret_abort)) {
2690 if ($child_exit == $bisect_ret_abort) {
2691 fail "test abort" and return -2;
2692 }
2693 }
2694 if (defined($bisect_ret_bad)) {
2695 if ($child_exit == $bisect_ret_skip) {
2696 return 0;
2697 }
2698 }
2699 if (defined($bisect_ret_default)) {
2700 if ($bisect_ret_default eq "good") {
2701 return 1;
2702 } elsif ($bisect_ret_default eq "bad") {
2703 return 0;
2704 } elsif ($bisect_ret_default eq "skip") {
2705 return -1;
2706 } elsif ($bisect_ret_default eq "abort") {
2707 return -2;
2708 } else {
2709 fail "unknown default action: $bisect_ret_default"
2710 and return -2;
2711 }
2712 }
2713 }
2714
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002715 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002716 return 0 if $in_bisect;
2717 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002718 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002719 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002720}
2721
Steven Rostedta75fece2010-11-02 14:58:27 -04002722sub run_git_bisect {
2723 my ($command) = @_;
2724
2725 doprint "$command ... ";
2726
2727 my $output = `$command 2>&1`;
2728 my $ret = $?;
2729
2730 logit $output;
2731
2732 if ($ret) {
2733 doprint "FAILED\n";
2734 dodie "Failed to git bisect";
2735 }
2736
2737 doprint "SUCCESS\n";
2738 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2739 doprint "$1 [$2]\n";
2740 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002741 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002742 doprint "Found bad commit... $1\n";
2743 return 0;
2744 } else {
2745 # we already logged it, just print it now.
2746 print $output;
2747 }
2748
2749 return 1;
2750}
2751
Steven Rostedtc23dca72011-03-08 09:26:31 -05002752sub bisect_reboot {
2753 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002754 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002755}
2756
2757# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002758sub run_bisect_test {
2759 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002760
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002761 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002762 my $result;
2763 my $output;
2764 my $ret;
2765
Steven Rostedt0a05c762010-11-08 11:14:10 -05002766 $in_bisect = 1;
2767
2768 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002769
2770 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002771 if ($failed && $bisect_skip) {
2772 $in_bisect = 0;
2773 return -1;
2774 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002775 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002776
2777 # Now boot the box
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05002778 start_monitor_and_install or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002779
2780 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002781 if ($failed && $bisect_skip) {
2782 end_monitor;
2783 bisect_reboot;
2784 $in_bisect = 0;
2785 return -1;
2786 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002787 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002788
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002789 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002790 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002791 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002792 }
2793
2794 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002795 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002796 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002797 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002798 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002799
2800 # reboot the box to a kernel we can ssh to
2801 if ($type ne "build") {
2802 bisect_reboot;
2803 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002804 $in_bisect = 0;
2805
2806 return $result;
2807}
2808
2809sub run_bisect {
2810 my ($type) = @_;
2811 my $buildtype = "oldconfig";
2812
2813 # We should have a minconfig to use?
2814 if (defined($minconfig)) {
2815 $buildtype = "useconfig:$minconfig";
2816 }
2817
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002818 # If the user sets bisect_tries to less than 1, then no tries
2819 # is a success.
2820 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002821
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002822 # Still let the user manually decide that though.
2823 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002824 $ret = answer_bisect;
2825 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002826
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002827 for (my $i = 0; $i < $bisect_tries; $i++) {
2828 if ($bisect_tries > 1) {
2829 my $t = $i + 1;
2830 doprint("Running bisect trial $t of $bisect_tries:\n");
2831 }
2832 $ret = run_bisect_test $type, $buildtype;
2833
2834 if ($bisect_manual) {
2835 $ret = answer_bisect;
2836 }
2837
2838 last if (!$ret);
2839 }
2840
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002841 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002842 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002843 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002844 }
2845
Steven Rostedtc23dca72011-03-08 09:26:31 -05002846 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002847 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002848 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002849 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002850 } elsif ($bisect_skip) {
2851 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2852 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002853 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002854}
2855
Steven Rostedtdad98752011-11-22 20:48:57 -05002856sub update_bisect_replay {
2857 my $tmp_log = "$tmpdir/ktest_bisect_log";
2858 run_command "git bisect log > $tmp_log" or
2859 die "can't create bisect log";
2860 return $tmp_log;
2861}
2862
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002863sub bisect {
2864 my ($i) = @_;
2865
2866 my $result;
2867
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002868 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2869 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2870 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002871
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002872 my $good = $bisect_good;
2873 my $bad = $bisect_bad;
2874 my $type = $bisect_type;
2875 my $start = $bisect_start;
2876 my $replay = $bisect_replay;
2877 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002878
2879 if (defined($start_files)) {
2880 $start_files = " -- " . $start_files;
2881 } else {
2882 $start_files = "";
2883 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002884
Steven Rostedta57419b2010-11-02 15:13:54 -04002885 # convert to true sha1's
2886 $good = get_sha1($good);
2887 $bad = get_sha1($bad);
2888
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002889 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002890 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2891 $reverse_bisect = 1;
2892 } else {
2893 $reverse_bisect = 0;
2894 }
2895
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002896 # Can't have a test without having a test to run
2897 if ($type eq "test" && !defined($run_test)) {
2898 $type = "boot";
2899 }
2900
Steven Rostedtdad98752011-11-22 20:48:57 -05002901 # Check if a bisect was running
2902 my $bisect_start_file = "$builddir/.git/BISECT_START";
2903
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002904 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002905 my $do_check = defined($check) && $check ne "0";
2906
2907 if ( -f $bisect_start_file ) {
2908 print "Bisect in progress found\n";
2909 if ($do_check) {
2910 print " If you say yes, then no checks of good or bad will be done\n";
2911 }
2912 if (defined($replay)) {
2913 print "** BISECT_REPLAY is defined in config file **";
2914 print " Ignore config option and perform new git bisect log?\n";
2915 if (read_ync " (yes, no, or cancel) ") {
2916 $replay = update_bisect_replay;
2917 $do_check = 0;
2918 }
2919 } elsif (read_yn "read git log and continue?") {
2920 $replay = update_bisect_replay;
2921 $do_check = 0;
2922 }
2923 }
2924
2925 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002926
2927 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002928 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002929
2930 if ($check ne "good") {
2931 doprint "TESTING BISECT BAD [$bad]\n";
2932 run_command "git checkout $bad" or
2933 die "Failed to checkout $bad";
2934
2935 $result = run_bisect $type;
2936
2937 if ($result ne "bad") {
2938 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2939 }
2940 }
2941
2942 if ($check ne "bad") {
2943 doprint "TESTING BISECT GOOD [$good]\n";
2944 run_command "git checkout $good" or
2945 die "Failed to checkout $good";
2946
2947 $result = run_bisect $type;
2948
2949 if ($result ne "good") {
2950 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2951 }
2952 }
2953
2954 # checkout where we started
2955 run_command "git checkout $head" or
2956 die "Failed to checkout $head";
2957 }
2958
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002959 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002960 dodie "could not start bisect";
2961
Steven Rostedta75fece2010-11-02 14:58:27 -04002962 if (defined($replay)) {
2963 run_command "git bisect replay $replay" or
2964 dodie "failed to run replay";
Steven Rostedt (Red Hat)d832d742014-10-07 16:34:25 -04002965 } else {
2966
2967 run_command "git bisect good $good" or
2968 dodie "could not set bisect good to $good";
2969
2970 run_git_bisect "git bisect bad $bad" or
2971 dodie "could not set bisect bad to $bad";
2972
Steven Rostedta75fece2010-11-02 14:58:27 -04002973 }
2974
2975 if (defined($start)) {
2976 run_command "git checkout $start" or
2977 dodie "failed to checkout $start";
2978 }
2979
2980 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002981 do {
2982 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002983 $test = run_git_bisect "git bisect $result";
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05002984 print_times;
Steven Rostedta75fece2010-11-02 14:58:27 -04002985 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002986
2987 run_command "git bisect log" or
2988 dodie "could not capture git bisect log";
2989
2990 run_command "git bisect reset" or
2991 dodie "could not reset git bisect";
2992
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002993 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002994
Steven Rostedt0a05c762010-11-08 11:14:10 -05002995 success $i;
2996}
2997
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002998# config_ignore holds the configs that were set (or unset) for
2999# a good config and we will ignore these configs for the rest
3000# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003001my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003002
3003# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003004my %config_set;
3005
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003006# config_off holds the set of configs that the bad config had disabled.
3007# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08003008# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003009my %config_off;
3010
3011# config_off_tmp holds a set of configs to turn off for now
3012my @config_off_tmp;
3013
3014# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05003015my %config_list;
3016my %null_config;
3017
3018my %dependency;
3019
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003020sub assign_configs {
3021 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003022
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003023 doprint "Reading configs from $config\n";
3024
Steven Rostedt0a05c762010-11-08 11:14:10 -05003025 open (IN, $config)
3026 or dodie "Failed to read $config";
3027
3028 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003029 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04003030 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003031 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003032 } elsif (/^(# (CONFIG\S*) is not set)/) {
3033 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003034 }
3035 }
3036
3037 close(IN);
3038}
3039
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003040sub process_config_ignore {
3041 my ($config) = @_;
3042
3043 assign_configs \%config_ignore, $config;
3044}
3045
Steven Rostedt0a05c762010-11-08 11:14:10 -05003046sub get_dependencies {
3047 my ($config) = @_;
3048
3049 my $arr = $dependency{$config};
3050 if (!defined($arr)) {
3051 return ();
3052 }
3053
3054 my @deps = @{$arr};
3055
3056 foreach my $dep (@{$arr}) {
3057 print "ADD DEP $dep\n";
3058 @deps = (@deps, get_dependencies $dep);
3059 }
3060
3061 return @deps;
3062}
3063
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003064sub save_config {
3065 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003066
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003067 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003068
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003069 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05003070
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003071 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003072
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003073 foreach my $config (keys %configs) {
3074 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05003075 }
3076 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003077}
3078
3079sub create_config {
3080 my ($name, $pc) = @_;
3081
3082 doprint "Creating old config from $name configs\n";
3083
3084 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003085
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003086 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003087}
3088
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003089# compare two config hashes, and return configs with different vals.
3090# It returns B's config values, but you can use A to see what A was.
3091sub diff_config_vals {
3092 my ($pa, $pb) = @_;
3093
3094 # crappy Perl way to pass in hashes.
3095 my %a = %{$pa};
3096 my %b = %{$pb};
3097
3098 my %ret;
3099
3100 foreach my $item (keys %a) {
3101 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
3102 $ret{$item} = $b{$item};
3103 }
3104 }
3105
3106 return %ret;
3107}
3108
3109# compare two config hashes and return the configs in B but not A
3110sub diff_configs {
3111 my ($pa, $pb) = @_;
3112
3113 my %ret;
3114
3115 # crappy Perl way to pass in hashes.
3116 my %a = %{$pa};
3117 my %b = %{$pb};
3118
3119 foreach my $item (keys %b) {
3120 if (!defined($a{$item})) {
3121 $ret{$item} = $b{$item};
3122 }
3123 }
3124
3125 return %ret;
3126}
3127
3128# return if two configs are equal or not
3129# 0 is equal +1 b has something a does not
3130# +1 if a and b have a different item.
3131# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05003132sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003133 my ($pa, $pb) = @_;
3134
3135 my %ret;
3136
3137 # crappy Perl way to pass in hashes.
3138 my %a = %{$pa};
3139 my %b = %{$pb};
3140
3141 foreach my $item (keys %b) {
3142 if (!defined($a{$item})) {
3143 return 1;
3144 }
3145 if ($a{$item} ne $b{$item}) {
3146 return 1;
3147 }
3148 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003149
3150 foreach my $item (keys %a) {
3151 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003152 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003153 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003154 }
3155
Steven Rostedt0a05c762010-11-08 11:14:10 -05003156 return 0;
3157}
3158
3159sub run_config_bisect_test {
3160 my ($type) = @_;
3161
Steven Rostedt (Red Hat)4cc559b2014-04-23 22:27:27 -04003162 my $ret = run_bisect_test $type, "oldconfig";
3163
3164 if ($bisect_manual) {
3165 $ret = answer_bisect;
3166 }
3167
3168 return $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003169}
3170
Steven Rostedt0a05c762010-11-08 11:14:10 -05003171sub process_failed {
3172 my ($config) = @_;
3173
3174 doprint "\n\n***************************************\n";
3175 doprint "Found bad config: $config\n";
3176 doprint "***************************************\n\n";
3177}
3178
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003179# used for config bisecting
3180my $good_config;
3181my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003182
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003183sub process_new_config {
3184 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003185
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003186 my %tmp_config = %{$tc};
3187 my %good_configs = %{$gc};
3188 my %bad_configs = %{$bc};
3189
3190 my %new_configs;
3191
3192 my $runtest = 1;
3193 my $ret;
3194
3195 create_config "tmp_configs", \%tmp_config;
3196 assign_configs \%new_configs, $output_config;
3197
3198 $ret = compare_configs \%new_configs, \%bad_configs;
3199 if (!$ret) {
3200 doprint "New config equals bad config, try next test\n";
3201 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003202 }
3203
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003204 if ($runtest) {
3205 $ret = compare_configs \%new_configs, \%good_configs;
3206 if (!$ret) {
3207 doprint "New config equals good config, try next test\n";
3208 $runtest = 0;
3209 }
3210 }
3211
3212 %{$nc} = %new_configs;
3213
3214 return $runtest;
3215}
3216
3217sub run_config_bisect {
3218 my ($pgood, $pbad) = @_;
3219
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003220 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003221
3222 my %good_configs = %{$pgood};
3223 my %bad_configs = %{$pbad};
3224
3225 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
3226 my %b_configs = diff_configs \%good_configs, \%bad_configs;
3227 my %g_configs = diff_configs \%bad_configs, \%good_configs;
3228
3229 my @diff_arr = keys %diff_configs;
3230 my $len_diff = $#diff_arr + 1;
3231
3232 my @b_arr = keys %b_configs;
3233 my $len_b = $#b_arr + 1;
3234
3235 my @g_arr = keys %g_configs;
3236 my $len_g = $#g_arr + 1;
3237
3238 my $runtest = 1;
3239 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003240 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003241
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003242 # First, lets get it down to a single subset.
3243 # Is the problem with a difference in values?
3244 # Is the problem with a missing config?
3245 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003246
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003247 # Enable all of one set and see if we get a new bad
3248 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003249
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003250 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003251
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003252 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003253
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003254 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003255
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003256 if ($len_diff > 0) {
3257 if ($len_b > 0 || $len_g > 0) {
3258 my %tmp_config = %bad_configs;
3259
3260 doprint "Set tmp config to be bad config with good config values\n";
3261 foreach my $item (@diff_arr) {
3262 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003263 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003264
3265 $runtest = process_new_config \%tmp_config, \%new_configs,
3266 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003267 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003268 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003269
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003270 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003271
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003272 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003273 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003274 return 1;
3275 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003276 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003277
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003278 my $half = int($#diff_arr / 2);
3279 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003280
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003281 doprint "Settings bisect with top half:\n";
3282 doprint "Set tmp config to be bad config with some good config values\n";
3283 foreach my $item (@tophalf) {
3284 $tmp_config{$item} = $good_configs{$item};
3285 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003286
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003287 $runtest = process_new_config \%tmp_config, \%new_configs,
3288 \%good_configs, \%bad_configs;
3289
3290 if (!$runtest) {
3291 my %tmp_config = %bad_configs;
3292
3293 doprint "Try bottom half\n";
3294
3295 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3296
3297 foreach my $item (@bottomhalf) {
3298 $tmp_config{$item} = $good_configs{$item};
3299 }
3300
3301 $runtest = process_new_config \%tmp_config, \%new_configs,
3302 \%good_configs, \%bad_configs;
3303 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003304 }
3305
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003306 if ($runtest) {
3307 $ret = run_config_bisect_test $type;
3308 if ($ret) {
3309 doprint "NEW GOOD CONFIG\n";
3310 %good_configs = %new_configs;
3311 run_command "mv $good_config ${good_config}.last";
3312 save_config \%good_configs, $good_config;
3313 %{$pgood} = %good_configs;
3314 } else {
3315 doprint "NEW BAD CONFIG\n";
3316 %bad_configs = %new_configs;
3317 run_command "mv $bad_config ${bad_config}.last";
3318 save_config \%bad_configs, $bad_config;
3319 %{$pbad} = %bad_configs;
3320 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003321 return 0;
3322 }
3323
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003324 fail "Hmm, need to do a mix match?\n";
3325 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003326}
3327
3328sub config_bisect {
3329 my ($i) = @_;
3330
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003331 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003332 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003333
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003334 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003335
Steven Rostedt30f75da2011-06-13 10:35:35 -04003336 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003337 $good_config = $config_bisect_good;
3338 } elsif (defined($minconfig)) {
3339 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003340 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003341 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003342 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003343 if (!$ret) {
3344 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3345 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003346 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003347 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003348 }
3349
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003350 # we don't want min configs to cause issues here.
3351 doprint "Disabling 'MIN_CONFIG' for this test\n";
3352 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003353
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003354 my %good_configs;
3355 my %bad_configs;
3356 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003357
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003358 doprint "Run good configs through make oldconfig\n";
3359 assign_configs \%tmp_configs, $good_config;
3360 create_config "$good_config", \%tmp_configs;
3361 assign_configs \%good_configs, $output_config;
3362
3363 doprint "Run bad configs through make oldconfig\n";
3364 assign_configs \%tmp_configs, $bad_config;
3365 create_config "$bad_config", \%tmp_configs;
3366 assign_configs \%bad_configs, $output_config;
3367
3368 $good_config = "$tmpdir/good_config";
3369 $bad_config = "$tmpdir/bad_config";
3370
3371 save_config \%good_configs, $good_config;
3372 save_config \%bad_configs, $bad_config;
3373
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003374
3375 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3376 if ($config_bisect_check ne "good") {
3377 doprint "Testing bad config\n";
3378
3379 $ret = run_bisect_test $type, "useconfig:$bad_config";
3380 if ($ret) {
3381 fail "Bad config succeeded when expected to fail!";
3382 return 0;
3383 }
3384 }
3385 if ($config_bisect_check ne "bad") {
3386 doprint "Testing good config\n";
3387
3388 $ret = run_bisect_test $type, "useconfig:$good_config";
3389 if (!$ret) {
3390 fail "Good config failed when expected to succeed!";
3391 return 0;
3392 }
3393 }
3394 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003395
Steven Rostedt0a05c762010-11-08 11:14:10 -05003396 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003397 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05003398 print_times;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003399 } while (!$ret);
3400
3401 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003402
3403 success $i;
3404}
3405
Steven Rostedt27d934b2011-05-20 09:18:18 -04003406sub patchcheck_reboot {
3407 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003408 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003409}
3410
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003411sub patchcheck {
3412 my ($i) = @_;
3413
3414 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003415 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003416 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003417 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003418
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003419 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003420
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003421 my $cherry = $patchcheck_cherry;
3422 if (!defined($cherry)) {
3423 $cherry = 0;
3424 }
3425
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003426 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003427 if (defined($patchcheck_end)) {
3428 $end = $patchcheck_end;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003429 } elsif ($cherry) {
3430 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003431 }
3432
Steven Rostedta57419b2010-11-02 15:13:54 -04003433 # Get the true sha1's since we can use things like HEAD~3
3434 $start = get_sha1($start);
3435 $end = get_sha1($end);
3436
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003437 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003438
3439 # Can't have a test without having a test to run
3440 if ($type eq "test" && !defined($run_test)) {
3441 $type = "boot";
3442 }
3443
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003444 if ($cherry) {
3445 open (IN, "git cherry -v $start $end|") or
3446 dodie "could not get git list";
3447 } else {
3448 open (IN, "git log --pretty=oneline $end|") or
3449 dodie "could not get git list";
3450 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003451
3452 my @list;
3453
3454 while (<IN>) {
3455 chomp;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003456 # git cherry adds a '+' we want to remove
3457 s/^\+ //;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003458 $list[$#list+1] = $_;
3459 last if (/^$start/);
3460 }
3461 close(IN);
3462
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003463 if (!$cherry) {
3464 if ($list[$#list] !~ /^$start/) {
3465 fail "SHA1 $start not found";
3466 }
3467
3468 # go backwards in the list
3469 @list = reverse @list;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003470 }
3471
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003472 doprint("Going to test the following commits:\n");
3473 foreach my $l (@list) {
3474 doprint "$l\n";
3475 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003476
3477 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003478 my %ignored_warnings;
3479
3480 if (defined($ignore_warnings)) {
3481 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3482 $ignored_warnings{$sha1} = 1;
3483 }
3484 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003485
3486 $in_patchcheck = 1;
3487 foreach my $item (@list) {
3488 my $sha1 = $item;
3489 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3490
Steven Rostedt (Red Hat)7c2c49e2015-02-03 15:45:13 -05003491 doprint "\nProcessing commit \"$item\"\n\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003492
3493 run_command "git checkout $sha1" or
3494 die "Failed to checkout $sha1";
3495
3496 # only clean on the first and last patch
3497 if ($item eq $list[0] ||
3498 $item eq $list[$#list]) {
3499 $noclean = $save_clean;
3500 } else {
3501 $noclean = 1;
3502 }
3503
3504 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003505 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003506 } else {
3507 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003508 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003509 }
3510
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003511 # No need to do per patch checking if warnings file exists
3512 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3513 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003514 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003515
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003516 check_buildlog or return 0;
3517
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003518 next if ($type eq "build");
3519
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003520 my $failed = 0;
3521
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05003522 start_monitor_and_install or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003523
3524 if (!$failed && $type ne "boot"){
3525 do_run_test or $failed = 1;
3526 }
3527 end_monitor;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05003528 if ($failed) {
3529 print_times;
3530 return 0;
3531 }
Steven Rostedt27d934b2011-05-20 09:18:18 -04003532 patchcheck_reboot;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05003533 print_times;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003534 }
3535 $in_patchcheck = 0;
3536 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003537
3538 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003539}
3540
Steven Rostedtb9066f62011-07-15 21:25:24 -04003541my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003542my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003543my $iflevel = 0;
3544my @ifdeps;
3545
3546# prevent recursion
3547my %read_kconfigs;
3548
Steven Rostedtac6974c2011-10-04 09:40:17 -04003549sub add_dep {
3550 # $config depends on $dep
3551 my ($config, $dep) = @_;
3552
3553 if (defined($depends{$config})) {
3554 $depends{$config} .= " " . $dep;
3555 } else {
3556 $depends{$config} = $dep;
3557 }
3558
3559 # record the number of configs depending on $dep
3560 if (defined $depcount{$dep}) {
3561 $depcount{$dep}++;
3562 } else {
3563 $depcount{$dep} = 1;
3564 }
3565}
3566
Steven Rostedtb9066f62011-07-15 21:25:24 -04003567# taken from streamline_config.pl
3568sub read_kconfig {
3569 my ($kconfig) = @_;
3570
3571 my $state = "NONE";
3572 my $config;
3573 my @kconfigs;
3574
3575 my $cont = 0;
3576 my $line;
3577
3578
3579 if (! -f $kconfig) {
3580 doprint "file $kconfig does not exist, skipping\n";
3581 return;
3582 }
3583
3584 open(KIN, "$kconfig")
3585 or die "Can't open $kconfig";
3586 while (<KIN>) {
3587 chomp;
3588
3589 # Make sure that lines ending with \ continue
3590 if ($cont) {
3591 $_ = $line . " " . $_;
3592 }
3593
3594 if (s/\\$//) {
3595 $cont = 1;
3596 $line = $_;
3597 next;
3598 }
3599
3600 $cont = 0;
3601
3602 # collect any Kconfig sources
3603 if (/^source\s*"(.*)"/) {
3604 $kconfigs[$#kconfigs+1] = $1;
3605 }
3606
3607 # configs found
3608 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3609 $state = "NEW";
3610 $config = $2;
3611
3612 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003613 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003614 }
3615
3616 # collect the depends for the config
3617 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3618
Steven Rostedtac6974c2011-10-04 09:40:17 -04003619 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003620
3621 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003622 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3623
3624 # selected by depends on config
3625 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003626
3627 # Check for if statements
3628 } elsif (/^if\s+(.*\S)\s*$/) {
3629 my $deps = $1;
3630 # remove beginning and ending non text
3631 $deps =~ s/^[^a-zA-Z0-9_]*//;
3632 $deps =~ s/[^a-zA-Z0-9_]*$//;
3633
3634 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3635
3636 $ifdeps[$iflevel++] = join ':', @deps;
3637
3638 } elsif (/^endif/) {
3639
3640 $iflevel-- if ($iflevel);
3641
3642 # stop on "help"
3643 } elsif (/^\s*help\s*$/) {
3644 $state = "NONE";
3645 }
3646 }
3647 close(KIN);
3648
3649 # read in any configs that were found.
3650 foreach $kconfig (@kconfigs) {
3651 if (!defined($read_kconfigs{$kconfig})) {
3652 $read_kconfigs{$kconfig} = 1;
3653 read_kconfig("$builddir/$kconfig");
3654 }
3655 }
3656}
3657
3658sub read_depends {
3659 # find out which arch this is by the kconfig file
3660 open (IN, $output_config)
3661 or dodie "Failed to read $output_config";
3662 my $arch;
3663 while (<IN>) {
3664 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3665 $arch = $1;
3666 last;
3667 }
3668 }
3669 close IN;
3670
3671 if (!defined($arch)) {
3672 doprint "Could not find arch from config file\n";
3673 doprint "no dependencies used\n";
3674 return;
3675 }
3676
3677 # arch is really the subarch, we need to know
3678 # what directory to look at.
3679 if ($arch eq "i386" || $arch eq "x86_64") {
3680 $arch = "x86";
3681 } elsif ($arch =~ /^tile/) {
3682 $arch = "tile";
3683 }
3684
3685 my $kconfig = "$builddir/arch/$arch/Kconfig";
3686
3687 if (! -f $kconfig && $arch =~ /\d$/) {
3688 my $orig = $arch;
3689 # some subarchs have numbers, truncate them
3690 $arch =~ s/\d*$//;
3691 $kconfig = "$builddir/arch/$arch/Kconfig";
3692 if (! -f $kconfig) {
3693 doprint "No idea what arch dir $orig is for\n";
3694 doprint "no dependencies used\n";
3695 return;
3696 }
3697 }
3698
3699 read_kconfig($kconfig);
3700}
3701
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003702sub make_new_config {
3703 my @configs = @_;
3704
3705 open (OUT, ">$output_config")
3706 or dodie "Failed to write $output_config";
3707
3708 foreach my $config (@configs) {
3709 print OUT "$config\n";
3710 }
3711 close OUT;
3712}
3713
Steven Rostedtac6974c2011-10-04 09:40:17 -04003714sub chomp_config {
3715 my ($config) = @_;
3716
3717 $config =~ s/CONFIG_//;
3718
3719 return $config;
3720}
3721
Steven Rostedtb9066f62011-07-15 21:25:24 -04003722sub get_depends {
3723 my ($dep) = @_;
3724
Steven Rostedtac6974c2011-10-04 09:40:17 -04003725 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003726
3727 $dep = $depends{"$kconfig"};
3728
3729 # the dep string we have saves the dependencies as they
3730 # were found, including expressions like ! && ||. We
3731 # want to split this out into just an array of configs.
3732
3733 my $valid = "A-Za-z_0-9";
3734
3735 my @configs;
3736
3737 while ($dep =~ /[$valid]/) {
3738
3739 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3740 my $conf = "CONFIG_" . $1;
3741
3742 $configs[$#configs + 1] = $conf;
3743
3744 $dep =~ s/^[^$valid]*[$valid]+//;
3745 } else {
3746 die "this should never happen";
3747 }
3748 }
3749
3750 return @configs;
3751}
3752
3753my %min_configs;
3754my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003755my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003756my %processed_configs;
3757my %nochange_config;
3758
3759sub test_this_config {
3760 my ($config) = @_;
3761
3762 my $found;
3763
3764 # if we already processed this config, skip it
3765 if (defined($processed_configs{$config})) {
3766 return undef;
3767 }
3768 $processed_configs{$config} = 1;
3769
3770 # if this config failed during this round, skip it
3771 if (defined($nochange_config{$config})) {
3772 return undef;
3773 }
3774
Steven Rostedtac6974c2011-10-04 09:40:17 -04003775 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003776
3777 # Test dependencies first
3778 if (defined($depends{"$kconfig"})) {
3779 my @parents = get_depends $config;
3780 foreach my $parent (@parents) {
3781 # if the parent is in the min config, check it first
3782 next if (!defined($min_configs{$parent}));
3783 $found = test_this_config($parent);
3784 if (defined($found)) {
3785 return $found;
3786 }
3787 }
3788 }
3789
3790 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003791 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003792 # .config to make sure it is missing the config that
3793 # we had before
3794 my %configs = %min_configs;
3795 delete $configs{$config};
3796 make_new_config ((values %configs), (values %keep_configs));
3797 make_oldconfig;
3798 undef %configs;
3799 assign_configs \%configs, $output_config;
3800
Steven Rostedt (Red Hat)9972fc02014-10-22 10:11:47 -04003801 if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
3802 return $config;
3803 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003804
3805 doprint "disabling config $config did not change .config\n";
3806
3807 $nochange_config{$config} = 1;
3808
3809 return undef;
3810}
3811
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003812sub make_min_config {
3813 my ($i) = @_;
3814
Steven Rostedtccc513b2012-05-21 17:13:40 -04003815 my $type = $minconfig_type;
3816 if ($type ne "boot" && $type ne "test") {
3817 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3818 " make_min_config works only with 'boot' and 'test'\n" and return;
3819 }
3820
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003821 if (!defined($output_minconfig)) {
3822 fail "OUTPUT_MIN_CONFIG not defined" and return;
3823 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003824
3825 # If output_minconfig exists, and the start_minconfig
3826 # came from min_config, than ask if we should use
3827 # that instead.
3828 if (-f $output_minconfig && !$start_minconfig_defined) {
3829 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003830 if (!defined($use_output_minconfig)) {
3831 if (read_yn " Use it as minconfig?") {
3832 $start_minconfig = $output_minconfig;
3833 }
3834 } elsif ($use_output_minconfig > 0) {
3835 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003836 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003837 } else {
3838 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003839 }
3840 }
3841
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003842 if (!defined($start_minconfig)) {
3843 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3844 }
3845
Steven Rostedt35ce5952011-07-15 21:57:25 -04003846 my $temp_config = "$tmpdir/temp_config";
3847
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003848 # First things first. We build an allnoconfig to find
3849 # out what the defaults are that we can't touch.
3850 # Some are selections, but we really can't handle selections.
3851
3852 my $save_minconfig = $minconfig;
3853 undef $minconfig;
3854
3855 run_command "$make allnoconfig" or return 0;
3856
Steven Rostedtb9066f62011-07-15 21:25:24 -04003857 read_depends;
3858
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003859 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003860
Steven Rostedt43d1b652011-07-15 22:01:56 -04003861 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003862 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003863
3864 if (defined($ignore_config)) {
3865 # make sure the file exists
3866 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003867 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003868 }
3869
Steven Rostedt43d1b652011-07-15 22:01:56 -04003870 %keep_configs = %save_configs;
3871
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003872 doprint "Load initial configs from $start_minconfig\n";
3873
3874 # Look at the current min configs, and save off all the
3875 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003876 assign_configs \%min_configs, $start_minconfig;
3877
3878 my @config_keys = keys %min_configs;
3879
Steven Rostedtac6974c2011-10-04 09:40:17 -04003880 # All configs need a depcount
3881 foreach my $config (@config_keys) {
3882 my $kconfig = chomp_config $config;
3883 if (!defined $depcount{$kconfig}) {
3884 $depcount{$kconfig} = 0;
3885 }
3886 }
3887
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003888 # Remove anything that was set by the make allnoconfig
3889 # we shouldn't need them as they get set for us anyway.
3890 foreach my $config (@config_keys) {
3891 # Remove anything in the ignore_config
3892 if (defined($keep_configs{$config})) {
3893 my $file = $ignore_config;
3894 $file =~ s,.*/(.*?)$,$1,;
3895 doprint "$config set by $file ... ignored\n";
3896 delete $min_configs{$config};
3897 next;
3898 }
3899 # But make sure the settings are the same. If a min config
3900 # sets a selection, we do not want to get rid of it if
3901 # it is not the same as what we have. Just move it into
3902 # the keep configs.
3903 if (defined($config_ignore{$config})) {
3904 if ($config_ignore{$config} ne $min_configs{$config}) {
3905 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3906 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3907 $keep_configs{$config} = $min_configs{$config};
3908 } else {
3909 doprint "$config set by allnoconfig ... ignored\n";
3910 }
3911 delete $min_configs{$config};
3912 }
3913 }
3914
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003915 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003916 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003917
3918 while (!$done) {
3919
3920 my $config;
3921 my $found;
3922
3923 # Now disable each config one by one and do a make oldconfig
3924 # till we find a config that changes our list.
3925
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003926 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003927
3928 # Sort keys by who is most dependent on
3929 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3930 @test_configs ;
3931
3932 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003933 my $reset = 1;
3934 for (my $i = 0; $i < $#test_configs; $i++) {
3935 if (!defined($nochange_config{$test_configs[0]})) {
3936 $reset = 0;
3937 last;
3938 }
3939 # This config didn't change the .config last time.
3940 # Place it at the end
3941 my $config = shift @test_configs;
3942 push @test_configs, $config;
3943 }
3944
3945 # if every test config has failed to modify the .config file
3946 # in the past, then reset and start over.
3947 if ($reset) {
3948 undef %nochange_config;
3949 }
3950
Steven Rostedtb9066f62011-07-15 21:25:24 -04003951 undef %processed_configs;
3952
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003953 foreach my $config (@test_configs) {
3954
Steven Rostedtb9066f62011-07-15 21:25:24 -04003955 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003956
Steven Rostedtb9066f62011-07-15 21:25:24 -04003957 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003958
3959 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003960 }
3961
3962 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003963 # we could have failed due to the nochange_config hash
3964 # reset and try again
3965 if (!$take_two) {
3966 undef %nochange_config;
3967 $take_two = 1;
3968 next;
3969 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003970 doprint "No more configs found that we can disable\n";
3971 $done = 1;
3972 last;
3973 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003974 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003975
3976 $config = $found;
3977
3978 doprint "Test with $config disabled\n";
3979
3980 # set in_bisect to keep build and monitor from dieing
3981 $in_bisect = 1;
3982
3983 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003984 build "oldconfig" or $failed = 1;
3985 if (!$failed) {
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05003986 start_monitor_and_install or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003987
3988 if ($type eq "test" && !$failed) {
3989 do_run_test or $failed = 1;
3990 }
3991
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003992 end_monitor;
3993 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003994
3995 $in_bisect = 0;
3996
3997 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003998 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003999 # this config is needed, add it to the ignore list.
4000 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04004001 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004002 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04004003
4004 # update new ignore configs
4005 if (defined($ignore_config)) {
4006 open (OUT, ">$temp_config")
4007 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04004008 foreach my $config (keys %save_configs) {
4009 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04004010 }
4011 close OUT;
4012 run_command "mv $temp_config $ignore_config" or
4013 dodie "failed to copy update to $ignore_config";
4014 }
4015
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004016 } else {
4017 # We booted without this config, remove it from the minconfigs.
4018 doprint "$config is not needed, disabling\n";
4019
4020 delete $min_configs{$config};
4021
4022 # Also disable anything that is not enabled in this config
4023 my %configs;
4024 assign_configs \%configs, $output_config;
4025 my @config_keys = keys %min_configs;
4026 foreach my $config (@config_keys) {
4027 if (!defined($configs{$config})) {
4028 doprint "$config is not set, disabling\n";
4029 delete $min_configs{$config};
4030 }
4031 }
4032
4033 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04004034 open (OUT, ">$temp_config")
4035 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004036 foreach my $config (keys %keep_configs) {
4037 print OUT "$keep_configs{$config}\n";
4038 }
4039 foreach my $config (keys %min_configs) {
4040 print OUT "$min_configs{$config}\n";
4041 }
4042 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04004043
4044 run_command "mv $temp_config $output_minconfig" or
4045 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004046 }
4047
4048 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004049 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004050 }
4051
4052 success $i;
4053 return 1;
4054}
4055
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004056sub make_warnings_file {
4057 my ($i) = @_;
4058
4059 if (!defined($warnings_file)) {
4060 dodie "Must define WARNINGS_FILE for make_warnings_file test";
4061 }
4062
4063 if ($build_type eq "nobuild") {
4064 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
4065 }
4066
4067 build $build_type or dodie "Failed to build";
4068
4069 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
4070
4071 open(IN, $buildlog) or dodie "Can't open $buildlog";
4072 while (<IN>) {
4073
4074 # Some compilers use UTF-8 extended for quotes
4075 # for distcc heterogeneous systems, this causes issues
4076 s/$utf8_quote/'/g;
4077
4078 if (/$check_build_re/) {
4079 print OUT;
4080 }
4081 }
4082 close(IN);
4083
4084 close(OUT);
4085
4086 success $i;
4087}
4088
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09004089$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04004090
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004091if ($#ARGV == 0) {
4092 $ktest_config = $ARGV[0];
4093 if (! -f $ktest_config) {
4094 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04004095 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004096 exit 0;
4097 }
4098 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004099}
4100
4101if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05004102 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05004103 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004104 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
4105 print OUT << "EOF"
4106# Generated by ktest.pl
4107#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05004108
4109# PWD is a ktest.pl variable that will result in the process working
4110# directory that ktest.pl is executed in.
4111
4112# THIS_DIR is automatically assigned the PWD of the path that generated
4113# the config file. It is best to use this variable when assigning other
4114# directory paths within this directory. This allows you to easily
4115# move the test cases to other locations or to other machines.
4116#
4117THIS_DIR := $variable{"PWD"}
4118
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004119# Define each test with TEST_START
4120# The config options below it will override the defaults
4121TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05004122TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004123
4124DEFAULTS
4125EOF
4126;
4127 close(OUT);
4128}
4129read_config $ktest_config;
4130
Steven Rostedt23715c3c2011-06-13 11:03:34 -04004131if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05004132 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04004133}
4134
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004135# Append any configs entered in manually to the config file.
4136my @new_configs = keys %entered_configs;
4137if ($#new_configs >= 0) {
4138 print "\nAppending entered in configs to $ktest_config\n";
4139 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
4140 foreach my $config (@new_configs) {
4141 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05004142 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05004143 }
4144}
Steven Rostedt2545eb62010-11-02 15:01:32 -04004145
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004146if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
4147 unlink $opt{"LOG_FILE"};
4148}
Steven Rostedt2545eb62010-11-02 15:01:32 -04004149
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004150doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
4151
Steven Rostedta57419b2010-11-02 15:13:54 -04004152for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
4153
4154 if (!$i) {
4155 doprint "DEFAULT OPTIONS:\n";
4156 } else {
4157 doprint "\nTEST $i OPTIONS";
4158 if (defined($repeat_tests{$i})) {
4159 $repeat = $repeat_tests{$i};
4160 doprint " ITERATE $repeat";
4161 }
4162 doprint "\n";
4163 }
4164
4165 foreach my $option (sort keys %opt) {
4166
4167 if ($option =~ /\[(\d+)\]$/) {
4168 next if ($i != $1);
4169 } else {
4170 next if ($i);
4171 }
4172
4173 doprint "$option = $opt{$option}\n";
4174 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004175}
Steven Rostedt2545eb62010-11-02 15:01:32 -04004176
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004177sub option_defined {
4178 my ($option) = @_;
4179
4180 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
4181 return 1;
4182 }
4183
4184 return 0;
4185}
4186
Steven Rostedt2a625122011-05-20 15:48:59 -04004187sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004188 my ($name, $i) = @_;
4189
4190 my $option = "$name\[$i\]";
4191
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004192 if (option_defined($option)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004193 return $opt{$option};
4194 }
4195
Steven Rostedta57419b2010-11-02 15:13:54 -04004196 foreach my $test (keys %repeat_tests) {
4197 if ($i >= $test &&
4198 $i < $test + $repeat_tests{$test}) {
4199 $option = "$name\[$test\]";
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004200 if (option_defined($option)) {
Steven Rostedta57419b2010-11-02 15:13:54 -04004201 return $opt{$option};
4202 }
4203 }
4204 }
4205
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05004206 if (option_defined($name)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004207 return $opt{$name};
4208 }
4209
4210 return undef;
4211}
4212
Steven Rostedt2a625122011-05-20 15:48:59 -04004213sub set_test_option {
4214 my ($name, $i) = @_;
4215
4216 my $option = __set_test_option($name, $i);
4217 return $option if (!defined($option));
4218
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05004219 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04004220}
4221
Steven Rostedt2545eb62010-11-02 15:01:32 -04004222# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04004223for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04004224
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004225 # Do not reboot on failing test options
4226 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004227 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004228
Steven Rostedt683a3e62012-05-18 13:34:35 -04004229 $have_version = 0;
4230
Steven Rostedt576f6272010-11-02 14:58:38 -04004231 $iteration = $i;
4232
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05004233 $build_time = 0;
4234 $install_time = 0;
4235 $reboot_time = 0;
4236 $test_time = 0;
4237
Steven Rostedtc1434dc2012-07-20 22:39:16 -04004238 undef %force_config;
4239
Steven Rostedta75fece2010-11-02 14:58:27 -04004240 my $makecmd = set_test_option("MAKE_CMD", $i);
4241
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004242 $outputdir = set_test_option("OUTPUT_DIR", $i);
4243 $builddir = set_test_option("BUILD_DIR", $i);
4244
4245 chdir $builddir || die "can't change directory to $builddir";
4246
4247 if (!-d $outputdir) {
4248 mkpath($outputdir) or
4249 die "can't create $outputdir";
4250 }
4251
4252 $make = "$makecmd O=$outputdir";
4253
Steven Rostedt9cc9e092011-12-22 21:37:22 -05004254 # Load all the options into their mapped variable names
4255 foreach my $opt (keys %option_map) {
4256 ${$option_map{$opt}} = set_test_option($opt, $i);
4257 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004258
Steven Rostedt35ce5952011-07-15 21:57:25 -04004259 $start_minconfig_defined = 1;
4260
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004261 # The first test may override the PRE_KTEST option
4262 if (defined($pre_ktest) && $i == 1) {
4263 doprint "\n";
4264 run_command $pre_ktest;
4265 }
4266
4267 # Any test can override the POST_KTEST option
4268 # The last test takes precedence.
4269 if (defined($post_ktest)) {
4270 $final_post_ktest = $post_ktest;
4271 }
4272
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004273 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004274 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004275 $start_minconfig = $minconfig;
4276 }
4277
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004278 if (!-d $tmpdir) {
4279 mkpath($tmpdir) or
4280 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004281 }
4282
Steven Rostedte48c5292010-11-02 14:35:37 -04004283 $ENV{"SSH_USER"} = $ssh_user;
4284 $ENV{"MACHINE"} = $machine;
4285
Steven Rostedta75fece2010-11-02 14:58:27 -04004286 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304287 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004288 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004289 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004290
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004291 if (!$buildonly) {
4292 $target = "$ssh_user\@$machine";
4293 if ($reboot_type eq "grub") {
4294 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004295 } elsif ($reboot_type eq "grub2") {
4296 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4297 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004298 } elsif ($reboot_type eq "syslinux") {
4299 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004300 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004301 }
4302
4303 my $run_type = $build_type;
4304 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004305 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004306 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004307 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004308 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004309 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004310 } elsif ($test_type eq "make_min_config") {
4311 $run_type = "";
4312 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004313 $run_type = "";
4314 }
4315
Steven Rostedta75fece2010-11-02 14:58:27 -04004316 # mistake in config file?
4317 if (!defined($run_type)) {
4318 $run_type = "ERROR";
4319 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004320
Steven Rostedte0a87422011-09-30 17:50:48 -04004321 my $installme = "";
4322 $installme = " no_install" if ($no_install);
4323
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004324 my $name = "";
4325
4326 if (defined($test_name)) {
4327 $name = " ($test_name)";
4328 }
4329
Steven Rostedt2545eb62010-11-02 15:01:32 -04004330 doprint "\n\n";
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004331 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 -04004332
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004333 if (defined($pre_test)) {
4334 run_command $pre_test;
4335 }
4336
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004337 unlink $dmesg;
4338 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304339 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004340
Steven Rostedt250bae82011-07-15 22:05:59 -04004341 if (defined($addconfig)) {
4342 my $min = $minconfig;
4343 if (!defined($minconfig)) {
4344 $min = "";
4345 }
4346 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004347 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004348 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004349 }
4350
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004351 if (defined($checkout)) {
4352 run_command "git checkout $checkout" or
4353 die "failed to checkout $checkout";
4354 }
4355
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004356 $no_reboot = 0;
4357
Steven Rostedt648a1822012-03-21 11:18:27 -04004358 # A test may opt to not reboot the box
4359 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004360 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004361 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004362
Steven Rostedta75fece2010-11-02 14:58:27 -04004363 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004364 bisect $i;
4365 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004366 } elsif ($test_type eq "config_bisect") {
4367 config_bisect $i;
4368 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004369 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004370 patchcheck $i;
4371 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004372 } elsif ($test_type eq "make_min_config") {
4373 make_min_config $i;
4374 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004375 } elsif ($test_type eq "make_warnings_file") {
4376 $no_reboot = 1;
4377 make_warnings_file $i;
4378 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004379 }
4380
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004381 if ($build_type ne "nobuild") {
4382 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004383 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004384 }
4385
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004386 if ($test_type eq "install") {
4387 get_version;
4388 install;
4389 success $i;
4390 next;
4391 }
4392
Steven Rostedta75fece2010-11-02 14:58:27 -04004393 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004394 my $failed = 0;
Steven Rostedt (Red Hat)64d98282015-01-28 15:17:35 -05004395 start_monitor_and_install or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004396
4397 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4398 do_run_test or $failed = 1;
4399 }
4400 end_monitor;
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05004401 if ($failed) {
4402 print_times;
4403 next;
4404 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004405 }
4406
Steven Rostedt (Red Hat)38fa3dc2015-01-28 09:43:01 -05004407 print_times;
4408
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004409 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004410}
4411
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004412if (defined($final_post_ktest)) {
4413 run_command $final_post_ktest;
4414}
4415
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004416if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004417 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004418} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004419 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004420} elsif (defined($switch_to_good)) {
4421 # still need to get to the good kernel
4422 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004423}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004424
Steven Rostedt648a1822012-03-21 11:18:27 -04004425
Steven Rostedte48c5292010-11-02 14:35:37 -04004426doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4427
Steven Rostedt2545eb62010-11-02 15:01:32 -04004428exit 0;