blob: 1dae000f79f87ef36ffd507b851ba4e2dc4df0af [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 Poimboeuf98842782015-01-27 12:10:04 -0600181my $stty;
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 Rostedt165708b2011-11-26 20:56:52 -0500201# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500202# which would require more options.
203my $buildonly = 1;
204
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500205# tell build not to worry about warnings, even when WARNINGS_FILE is set
206my $warnings_ok = 0;
207
Steven Rostedtdbd37832011-11-23 16:00:48 -0500208# set when creating a new config
209my $newconfig = 0;
210
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500211my %entered_configs;
212my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400213my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400214
215# force_config is the list of configs that we force enabled (or disabled)
216# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400217my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500218
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400219# do not force reboots on config problems
220my $no_reboot = 1;
221
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400222# reboot on success
223my $reboot_success = 0;
224
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500225my %option_map = (
226 "MACHINE" => \$machine,
227 "SSH_USER" => \$ssh_user,
228 "TMP_DIR" => \$tmpdir,
229 "OUTPUT_DIR" => \$outputdir,
230 "BUILD_DIR" => \$builddir,
231 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400232 "PRE_KTEST" => \$pre_ktest,
233 "POST_KTEST" => \$post_ktest,
234 "PRE_TEST" => \$pre_test,
235 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500236 "BUILD_TYPE" => \$build_type,
237 "BUILD_OPTIONS" => \$build_options,
238 "PRE_BUILD" => \$pre_build,
239 "POST_BUILD" => \$post_build,
240 "PRE_BUILD_DIE" => \$pre_build_die,
241 "POST_BUILD_DIE" => \$post_build_die,
242 "POWER_CYCLE" => \$power_cycle,
243 "REBOOT" => \$reboot,
244 "BUILD_NOCLEAN" => \$noclean,
245 "MIN_CONFIG" => \$minconfig,
246 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
247 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400248 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400249 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500250 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500251 "IGNORE_CONFIG" => \$ignore_config,
252 "TEST" => \$run_test,
253 "ADD_CONFIG" => \$addconfig,
254 "REBOOT_TYPE" => \$reboot_type,
255 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500256 "GRUB_FILE" => \$grub_file,
257 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500258 "SYSLINUX" => \$syslinux,
259 "SYSLINUX_PATH" => \$syslinux_path,
260 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400261 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500262 "POST_INSTALL" => \$post_install,
263 "NO_INSTALL" => \$no_install,
264 "REBOOT_SCRIPT" => \$reboot_script,
265 "REBOOT_ON_ERROR" => \$reboot_on_error,
266 "SWITCH_TO_GOOD" => \$switch_to_good,
267 "SWITCH_TO_TEST" => \$switch_to_test,
268 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400269 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500270 "DIE_ON_FAILURE" => \$die_on_failure,
271 "POWER_OFF" => \$power_off,
272 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
273 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400274 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500275 "SLEEP_TIME" => \$sleep_time,
276 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
277 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
278 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500279 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500280 "BISECT_MANUAL" => \$bisect_manual,
281 "BISECT_SKIP" => \$bisect_skip,
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -0500282 "BISECT_TRIES" => \$bisect_tries,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500283 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
284 "BISECT_RET_GOOD" => \$bisect_ret_good,
285 "BISECT_RET_BAD" => \$bisect_ret_bad,
286 "BISECT_RET_SKIP" => \$bisect_ret_skip,
287 "BISECT_RET_ABORT" => \$bisect_ret_abort,
288 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
289 "STORE_FAILURES" => \$store_failures,
290 "STORE_SUCCESSES" => \$store_successes,
291 "TEST_NAME" => \$test_name,
292 "TIMEOUT" => \$timeout,
293 "BOOTED_TIMEOUT" => \$booted_timeout,
294 "CONSOLE" => \$console,
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900295 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500296 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
297 "SUCCESS_LINE" => \$success_line,
298 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
299 "STOP_AFTER_SUCCESS" => \$stop_after_success,
300 "STOP_AFTER_FAILURE" => \$stop_after_failure,
301 "STOP_TEST_AFTER" => \$stop_test_after,
302 "BUILD_TARGET" => \$build_target,
303 "SSH_EXEC" => \$ssh_exec,
304 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400305 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500306 "CHECKOUT" => \$checkout,
307 "TARGET_IMAGE" => \$target_image,
308 "LOCALVERSION" => \$localversion,
309
310 "BISECT_GOOD" => \$bisect_good,
311 "BISECT_BAD" => \$bisect_bad,
312 "BISECT_TYPE" => \$bisect_type,
313 "BISECT_START" => \$bisect_start,
314 "BISECT_REPLAY" => \$bisect_replay,
315 "BISECT_FILES" => \$bisect_files,
316 "BISECT_REVERSE" => \$bisect_reverse,
317 "BISECT_CHECK" => \$bisect_check,
318
319 "CONFIG_BISECT" => \$config_bisect,
320 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400321 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500322
323 "PATCHCHECK_TYPE" => \$patchcheck_type,
324 "PATCHCHECK_START" => \$patchcheck_start,
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -0400325 "PATCHCHECK_CHERRY" => \$patchcheck_cherry,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500326 "PATCHCHECK_END" => \$patchcheck_end,
327);
328
329# Options may be used by other options, record them.
330my %used_options;
331
Steven Rostedt7bf51072011-10-22 09:07:03 -0400332# default variables that can be used
333chomp ($variable{"PWD"} = `pwd`);
334
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500335$config_help{"MACHINE"} = << "EOF"
336 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500337 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500338EOF
339 ;
340$config_help{"SSH_USER"} = << "EOF"
341 The box is expected to have ssh on normal bootup, provide the user
342 (most likely root, since you need privileged operations)
343EOF
344 ;
345$config_help{"BUILD_DIR"} = << "EOF"
346 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500347 You can use \${PWD} that will be the path where ktest.pl is run, or use
348 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500349EOF
350 ;
351$config_help{"OUTPUT_DIR"} = << "EOF"
352 The directory that the objects will be built (full path).
353 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500354 You can use \${PWD} that will be the path where ktest.pl is run, or use
355 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500356EOF
357 ;
358$config_help{"BUILD_TARGET"} = << "EOF"
359 The location of the compiled file to copy to the target.
360 (relative to OUTPUT_DIR)
361EOF
362 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500363$config_help{"BUILD_OPTIONS"} = << "EOF"
364 Options to add to \"make\" when building.
365 i.e. -j20
366EOF
367 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500368$config_help{"TARGET_IMAGE"} = << "EOF"
369 The place to put your image on the test machine.
370EOF
371 ;
372$config_help{"POWER_CYCLE"} = << "EOF"
373 A script or command to reboot the box.
374
375 Here is a digital loggers power switch example
376 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
377
378 Here is an example to reboot a virtual box on the current host
379 with the name "Guest".
380 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
381EOF
382 ;
383$config_help{"CONSOLE"} = << "EOF"
384 The script or command that reads the console
385
386 If you use ttywatch server, something like the following would work.
387CONSOLE = nc -d localhost 3001
388
389 For a virtual machine with guest name "Guest".
390CONSOLE = virsh console Guest
391EOF
392 ;
393$config_help{"LOCALVERSION"} = << "EOF"
394 Required version ending to differentiate the test
395 from other linux builds on the system.
396EOF
397 ;
398$config_help{"REBOOT_TYPE"} = << "EOF"
399 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500400 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500401
402 If you specify grub, it will assume grub version 1
403 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
404 and select that target to reboot to the kernel. If this is not
405 your setup, then specify "script" and have a command or script
406 specified in REBOOT_SCRIPT to boot to the target.
407
408 The entry in /boot/grub/menu.lst must be entered in manually.
409 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500410
411 If you specify grub2, then you also need to specify both \$GRUB_MENU
412 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500413
414 If you specify syslinux, then you may use SYSLINUX to define the syslinux
415 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
416 the syslinux install (defaults to /boot/extlinux). But you have to specify
417 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500418EOF
419 ;
420$config_help{"GRUB_MENU"} = << "EOF"
421 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500422 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500423
424 Note, ktest.pl will not update the grub menu.lst, you need to
425 manually add an option for the test. ktest.pl will search
426 the grub menu.lst for this option to find what kernel to
427 reboot into.
428
429 For example, if in the /boot/grub/menu.lst the test kernel title has:
430 title Test Kernel
431 kernel vmlinuz-test
432 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500433
434 For grub2, a search of \$GRUB_FILE is performed for the lines
435 that begin with "menuentry". It will not detect submenus. The
436 menu must be a non-nested menu. Add the quotes used in the menu
437 to guarantee your selection, as the first menuentry with the content
438 of \$GRUB_MENU that is found will be used.
439EOF
440 ;
441$config_help{"GRUB_FILE"} = << "EOF"
442 If grub2 is used, the full path for the grub.cfg file is placed
443 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500444EOF
445 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500446$config_help{"SYSLINUX_LABEL"} = << "EOF"
447 If syslinux is used, the label that boots the target kernel must
448 be specified with SYSLINUX_LABEL.
449EOF
450 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500451$config_help{"REBOOT_SCRIPT"} = << "EOF"
452 A script to reboot the target into the test kernel
453 (Only mandatory if REBOOT_TYPE = script)
454EOF
455 ;
456
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500457sub _logit {
458 if (defined($opt{"LOG_FILE"})) {
459 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
460 print OUT @_;
461 close(OUT);
462 }
463}
464
465sub logit {
466 if (defined($opt{"LOG_FILE"})) {
467 _logit @_;
468 } else {
469 print @_;
470 }
471}
472
473sub doprint {
474 print @_;
475 _logit @_;
476}
477
Steven Rostedtdad98752011-11-22 20:48:57 -0500478sub read_prompt {
479 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400480
481 my $ans;
482
483 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500484 if ($cancel) {
485 print "$prompt [y/n/C] ";
486 } else {
487 print "$prompt [Y/n] ";
488 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400489 $ans = <STDIN>;
490 chomp $ans;
491 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500492 if ($cancel) {
493 $ans = "c";
494 } else {
495 $ans = "y";
496 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400497 }
498 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500499 if ($cancel) {
500 last if ($ans =~ /^c$/i);
501 print "Please answer either 'y', 'n' or 'c'.\n";
502 } else {
503 print "Please answer either 'y' or 'n'.\n";
504 }
505 }
506 if ($ans =~ /^c/i) {
507 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400508 }
509 if ($ans !~ /^y$/i) {
510 return 0;
511 }
512 return 1;
513}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500514
Steven Rostedtdad98752011-11-22 20:48:57 -0500515sub read_yn {
516 my ($prompt) = @_;
517
518 return read_prompt 0, $prompt;
519}
520
521sub read_ync {
522 my ($prompt) = @_;
523
524 return read_prompt 1, $prompt;
525}
526
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900527sub get_mandatory_config {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500528 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400529 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500530
531 return if (defined($opt{$config}));
532
533 if (defined($config_help{$config})) {
534 print "\n";
535 print $config_help{$config};
536 }
537
538 for (;;) {
539 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500540 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500541 print "\[$default{$config}\] ";
542 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400543 $ans = <STDIN>;
544 $ans =~ s/^\s*(.*\S)\s*$/$1/;
545 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500546 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400547 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500548 } else {
549 print "Your answer can not be blank\n";
550 next;
551 }
552 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500553 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500554 last;
555 }
556}
557
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900558sub get_mandatory_configs {
559 get_mandatory_config("MACHINE");
560 get_mandatory_config("BUILD_DIR");
561 get_mandatory_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500562
Steven Rostedtdbd37832011-11-23 16:00:48 -0500563 if ($newconfig) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900564 get_mandatory_config("BUILD_OPTIONS");
Steven Rostedtdbd37832011-11-23 16:00:48 -0500565 }
566
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500567 # options required for other than just building a kernel
568 if (!$buildonly) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900569 get_mandatory_config("POWER_CYCLE");
570 get_mandatory_config("CONSOLE");
Steven Rostedt165708b2011-11-26 20:56:52 -0500571 }
572
573 # options required for install and more
574 if ($buildonly != 1) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900575 get_mandatory_config("SSH_USER");
576 get_mandatory_config("BUILD_TARGET");
577 get_mandatory_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500578 }
579
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900580 get_mandatory_config("LOCALVERSION");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500581
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500582 return if ($buildonly);
583
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500584 my $rtype = $opt{"REBOOT_TYPE"};
585
586 if (!defined($rtype)) {
587 if (!defined($opt{"GRUB_MENU"})) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900588 get_mandatory_config("REBOOT_TYPE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500589 $rtype = $entered_configs{"REBOOT_TYPE"};
590 } else {
591 $rtype = "grub";
592 }
593 }
594
595 if ($rtype eq "grub") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900596 get_mandatory_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500597 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500598
599 if ($rtype eq "grub2") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900600 get_mandatory_config("GRUB_MENU");
601 get_mandatory_config("GRUB_FILE");
Steven Rostedta15ba912012-11-13 14:30:37 -0500602 }
Steven Rostedt77869542012-12-11 17:37:41 -0500603
604 if ($rtype eq "syslinux") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900605 get_mandatory_config("SYSLINUX_LABEL");
Steven Rostedt77869542012-12-11 17:37:41 -0500606 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500607}
608
Steven Rostedt77d942c2011-05-20 13:36:58 -0400609sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400610 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400611 my $retval = "";
612
613 # We want to check for '\', and it is just easier
614 # to check the previous characet of '$' and not need
615 # to worry if '$' is the first character. By adding
616 # a space to $value, we can just check [^\\]\$ and
617 # it will still work.
618 $value = " $value";
619
620 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
621 my $begin = $1;
622 my $var = $2;
623 my $end = $3;
624 # append beginning of value to retval
625 $retval = "$retval$begin";
626 if (defined($variable{$var})) {
627 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400628 } elsif (defined($remove_undef) && $remove_undef) {
629 # for if statements, any variable that is not defined,
630 # we simple convert to 0
631 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400632 } else {
633 # put back the origin piece.
634 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500635 # This could be an option that is used later, save
636 # it so we don't warn if this option is not one of
637 # ktests options.
638 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400639 }
640 $value = $end;
641 }
642 $retval = "$retval$value";
643
644 # remove the space added in the beginning
645 $retval =~ s/ //;
646
647 return "$retval"
648}
649
Steven Rostedta57419b2010-11-02 15:13:54 -0400650sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400651 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400652
Steven Rostedtcad96662011-12-22 11:32:52 -0500653 my $prvalue = process_variables($rvalue);
654
655 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500656 # Note if a test is something other than build, then we
657 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500658 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500659 # for bisect, we need to check BISECT_TYPE
660 if ($prvalue ne "bisect") {
661 $buildonly = 0;
662 }
663 } else {
664 # install still limits some manditory options.
665 $buildonly = 2;
666 }
667 }
668
669 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
670 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500671 $buildonly = 0;
672 } else {
673 # install still limits some manditory options.
674 $buildonly = 2;
675 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500676 }
677
Steven Rostedta57419b2010-11-02 15:13:54 -0400678 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400679 if (!$override || defined(${$overrides}{$lvalue})) {
680 my $extra = "";
681 if ($override) {
682 $extra = "In the same override section!\n";
683 }
684 die "$name: $.: Option $lvalue defined more than once!\n$extra";
685 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500686 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400687 }
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -0500688
689 $opt{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400690}
691
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500692sub set_eval {
693 my ($lvalue, $rvalue, $name) = @_;
694
695 my $prvalue = process_variables($rvalue);
696 my $arr;
697
698 if (defined($evals{$lvalue})) {
699 $arr = $evals{$lvalue};
700 } else {
701 $arr = [];
702 $evals{$lvalue} = $arr;
703 }
704
705 push @{$arr}, $rvalue;
706}
707
Steven Rostedt77d942c2011-05-20 13:36:58 -0400708sub set_variable {
709 my ($lvalue, $rvalue) = @_;
710
711 if ($rvalue =~ /^\s*$/) {
712 delete $variable{$lvalue};
713 } else {
714 $rvalue = process_variables($rvalue);
715 $variable{$lvalue} = $rvalue;
716 }
717}
718
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400719sub process_compare {
720 my ($lval, $cmp, $rval) = @_;
721
722 # remove whitespace
723
724 $lval =~ s/^\s*//;
725 $lval =~ s/\s*$//;
726
727 $rval =~ s/^\s*//;
728 $rval =~ s/\s*$//;
729
730 if ($cmp eq "==") {
731 return $lval eq $rval;
732 } elsif ($cmp eq "!=") {
733 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400734 } elsif ($cmp eq "=~") {
735 return $lval =~ m/$rval/;
736 } elsif ($cmp eq "!~") {
737 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400738 }
739
740 my $statement = "$lval $cmp $rval";
741 my $ret = eval $statement;
742
743 # $@ stores error of eval
744 if ($@) {
745 return -1;
746 }
747
748 return $ret;
749}
750
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400751sub value_defined {
752 my ($val) = @_;
753
754 return defined($variable{$2}) ||
755 defined($opt{$2});
756}
757
Steven Rostedt8d735212011-10-17 11:36:44 -0400758my $d = 0;
759sub process_expression {
760 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400761
Steven Rostedt8d735212011-10-17 11:36:44 -0400762 my $c = $d++;
763
764 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
765 my $express = $1;
766
767 if (process_expression($name, $express)) {
768 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
769 } else {
770 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
771 }
772 }
773
774 $d--;
775 my $OR = "\\|\\|";
776 my $AND = "\\&\\&";
777
778 while ($val =~ s/^(.*?)($OR|$AND)//) {
779 my $express = $1;
780 my $op = $2;
781
782 if (process_expression($name, $express)) {
783 if ($op eq "||") {
784 return 1;
785 }
786 } else {
787 if ($op eq "&&") {
788 return 0;
789 }
790 }
791 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400792
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400793 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400794 my $ret = process_compare($1, $2, $3);
795 if ($ret < 0) {
796 die "$name: $.: Unable to process comparison\n";
797 }
798 return $ret;
799 }
800
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400801 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
802 if (defined $1) {
803 return !value_defined($2);
804 } else {
805 return value_defined($2);
806 }
807 }
808
Steven Rostedt45d73a52011-09-30 19:44:53 -0400809 if ($val =~ /^\s*0\s*$/) {
810 return 0;
811 } elsif ($val =~ /^\s*\d+\s*$/) {
812 return 1;
813 }
814
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400815 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400816}
817
818sub process_if {
819 my ($name, $value) = @_;
820
821 # Convert variables and replace undefined ones with 0
822 my $val = process_variables($value, 1);
823 my $ret = process_expression $name, $val;
824
825 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400826}
827
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400828sub __read_config {
829 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400830
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400831 my $in;
832 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400833
Steven Rostedta57419b2010-11-02 15:13:54 -0400834 my $name = $config;
835 $name =~ s,.*/(.*),$1,;
836
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400837 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400838 my $default = 1;
839 my $repeat = 1;
840 my $num_tests_set = 0;
841 my $skip = 0;
842 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400843 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400844 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400845 my $if = 0;
846 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400847 my $override = 0;
848
849 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400850
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400851 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400852
853 # ignore blank lines and comments
854 next if (/^\s*$/ || /\s*\#/);
855
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400856 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400857
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400858 my $type = $1;
859 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400860 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400861
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400862 my $old_test_num;
863 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400864 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400865
866 if ($type eq "TEST_START") {
867
868 if ($num_tests_set) {
869 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
870 }
871
872 $old_test_num = $test_num;
873 $old_repeat = $repeat;
874
875 $test_num += $repeat;
876 $default = 0;
877 $repeat = 1;
878 } else {
879 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400880 }
881
Steven Rostedta9f84422011-10-17 11:06:29 -0400882 # If SKIP is anywhere in the line, the command will be skipped
883 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400884 $skip = 1;
885 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400886 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400887 $skip = 0;
888 }
889
Steven Rostedta9f84422011-10-17 11:06:29 -0400890 if ($rest =~ s/\sELSE\b//) {
891 if (!$if) {
892 die "$name: $.: ELSE found with out matching IF section\n$_";
893 }
894 $if = 0;
895
896 if ($if_set) {
897 $skip = 1;
898 } else {
899 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400900 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400901 }
902
Steven Rostedta9f84422011-10-17 11:06:29 -0400903 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400904 if (process_if($name, $1)) {
905 $if_set = 1;
906 } else {
907 $skip = 1;
908 }
909 $if = 1;
910 } else {
911 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400912 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400913 }
914
Steven Rostedta9f84422011-10-17 11:06:29 -0400915 if (!$skip) {
916 if ($type eq "TEST_START") {
917 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
918 $repeat = $1;
919 $repeat_tests{"$test_num"} = $repeat;
920 }
921 } elsif ($rest =~ s/\sOVERRIDE\b//) {
922 # DEFAULT only
923 $override = 1;
924 # Clear previous overrides
925 %overrides = ();
926 }
927 }
928
929 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400930 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400931 }
932
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400933 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400934 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400935 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400936 }
937
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400938 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400939 if (!$if) {
940 die "$name: $.: ELSE found with out matching IF section\n$_";
941 }
942 $rest = $1;
943 if ($if_set) {
944 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400945 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400946 } else {
947 $skip = 0;
948
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400949 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400950 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400951 if (process_if($name, $1)) {
952 $if_set = 1;
953 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400954 $skip = 1;
955 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400956 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400957 } else {
958 $if = 0;
959 }
960 }
961
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400962 if ($rest !~ /^\s*$/) {
963 die "$name: $.: Gargbage found after DEFAULTS\n$_";
964 }
965
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400966 } elsif (/^\s*INCLUDE\s+(\S+)/) {
967
968 next if ($skip);
969
970 if (!$default) {
971 die "$name: $.: INCLUDE can only be done in default sections\n$_";
972 }
973
974 my $file = process_variables($1);
975
976 if ($file !~ m,^/,) {
977 # check the path of the config file first
978 if ($config =~ m,(.*)/,) {
979 if (-f "$1/$file") {
980 $file = "$1/$file";
981 }
982 }
983 }
984
985 if ( ! -r $file ) {
986 die "$name: $.: Can't read file $file\n$_";
987 }
988
989 if (__read_config($file, \$test_num)) {
990 $test_case = 1;
991 }
992
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500993 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
994
995 next if ($skip);
996
997 my $lvalue = $1;
998 my $rvalue = $2;
999
1000 if ($default || $lvalue =~ /\[\d+\]$/) {
1001 set_eval($lvalue, $rvalue, $name);
1002 } else {
1003 my $val = "$lvalue\[$test_num\]";
1004 set_eval($val, $rvalue, $name);
1005 }
1006
Steven Rostedta57419b2010-11-02 15:13:54 -04001007 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1008
1009 next if ($skip);
1010
Steven Rostedt2545eb62010-11-02 15:01:32 -04001011 my $lvalue = $1;
1012 my $rvalue = $2;
1013
Steven Rostedta57419b2010-11-02 15:13:54 -04001014 if (!$default &&
1015 ($lvalue eq "NUM_TESTS" ||
1016 $lvalue eq "LOG_FILE" ||
1017 $lvalue eq "CLEAR_LOG")) {
1018 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001019 }
Steven Rostedta57419b2010-11-02 15:13:54 -04001020
1021 if ($lvalue eq "NUM_TESTS") {
1022 if ($test_num) {
1023 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1024 }
1025 if (!$default) {
1026 die "$name: $.: NUM_TESTS must be set in default section\n";
1027 }
1028 $num_tests_set = 1;
1029 }
1030
1031 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001032 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001033 } else {
1034 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001035 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001036
1037 if ($repeat > 1) {
1038 $repeats{$val} = $repeat;
1039 }
1040 }
Steven Rostedt77d942c2011-05-20 13:36:58 -04001041 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1042 next if ($skip);
1043
1044 my $lvalue = $1;
1045 my $rvalue = $2;
1046
1047 # process config variables.
1048 # Config variables are only active while reading the
1049 # config and can be defined anywhere. They also ignore
1050 # TEST_START and DEFAULTS, but are skipped if they are in
1051 # on of these sections that have SKIP defined.
1052 # The save variable can be
1053 # defined multiple times and the new one simply overrides
1054 # the prevous one.
1055 set_variable($lvalue, $rvalue);
1056
Steven Rostedta57419b2010-11-02 15:13:54 -04001057 } else {
1058 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001059 }
1060 }
1061
Steven Rostedta57419b2010-11-02 15:13:54 -04001062 if ($test_num) {
1063 $test_num += $repeat - 1;
1064 $opt{"NUM_TESTS"} = $test_num;
1065 }
1066
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001067 close($in);
1068
1069 $$current_test_num = $test_num;
1070
1071 return $test_case;
1072}
1073
Steven Rostedtc4261d02011-11-23 13:41:18 -05001074sub get_test_case {
1075 print "What test case would you like to run?\n";
1076 print " (build, install or boot)\n";
1077 print " Other tests are available but require editing the config file\n";
1078 my $ans = <STDIN>;
1079 chomp $ans;
1080 $default{"TEST_TYPE"} = $ans;
1081}
1082
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001083sub read_config {
1084 my ($config) = @_;
1085
1086 my $test_case;
1087 my $test_num = 0;
1088
1089 $test_case = __read_config $config, \$test_num;
1090
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001091 # make sure we have all mandatory configs
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09001092 get_mandatory_configs;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001093
Steven Rostedt0df213c2011-06-14 20:51:37 -04001094 # was a test specified?
1095 if (!$test_case) {
1096 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001097 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001098 }
1099
Steven Rostedta75fece2010-11-02 14:58:27 -04001100 # set any defaults
1101
1102 foreach my $default (keys %default) {
1103 if (!defined($opt{$default})) {
1104 $opt{$default} = $default{$default};
1105 }
1106 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001107
1108 if ($opt{"IGNORE_UNUSED"} == 1) {
1109 return;
1110 }
1111
1112 my %not_used;
1113
1114 # check if there are any stragglers (typos?)
1115 foreach my $option (keys %opt) {
1116 my $op = $option;
1117 # remove per test labels.
1118 $op =~ s/\[.*\]//;
1119 if (!exists($option_map{$op}) &&
1120 !exists($default{$op}) &&
1121 !exists($used_options{$op})) {
1122 $not_used{$op} = 1;
1123 }
1124 }
1125
1126 if (%not_used) {
1127 my $s = "s are";
1128 $s = " is" if (keys %not_used == 1);
1129 print "The following option$s not used; could be a typo:\n";
1130 foreach my $option (keys %not_used) {
1131 print "$option\n";
1132 }
1133 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1134 if (!read_yn "Do you want to continue?") {
1135 exit -1;
1136 }
1137 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001138}
1139
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001140sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001141 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001142
1143 # Add space to evaluate the character before $
1144 $option = " $option";
1145 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301146 my $repeated = 0;
1147 my $parent = 0;
1148
1149 foreach my $test (keys %repeat_tests) {
1150 if ($i >= $test &&
1151 $i < $test + $repeat_tests{$test}) {
1152
1153 $repeated = 1;
1154 $parent = $test;
1155 last;
1156 }
1157 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001158
1159 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1160 my $start = $1;
1161 my $var = $2;
1162 my $end = $3;
1163
1164 # Append beginning of line
1165 $retval = "$retval$start";
1166
1167 # If the iteration option OPT[$i] exists, then use that.
1168 # otherwise see if the default OPT (without [$i]) exists.
1169
1170 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301171 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001172
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001173 # If a variable contains itself, use the default var
1174 if (($var eq $name) && defined($opt{$var})) {
1175 $o = $opt{$var};
1176 $retval = "$retval$o";
1177 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001178 $o = $opt{$o};
1179 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301180 } elsif ($repeated && defined($opt{$parento})) {
1181 $o = $opt{$parento};
1182 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001183 } elsif (defined($opt{$var})) {
1184 $o = $opt{$var};
1185 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001186 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1187 # special option KERNEL_VERSION uses kernel version
1188 get_version();
1189 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001190 } else {
1191 $retval = "$retval\$\{$var\}";
1192 }
1193
1194 $option = $end;
1195 }
1196
1197 $retval = "$retval$option";
1198
1199 $retval =~ s/^ //;
1200
1201 return $retval;
1202}
1203
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001204sub process_evals {
1205 my ($name, $option, $i) = @_;
1206
1207 my $option_name = "$name\[$i\]";
1208 my $ev;
1209
1210 my $old_option = $option;
1211
1212 if (defined($evals{$option_name})) {
1213 $ev = $evals{$option_name};
1214 } elsif (defined($evals{$name})) {
1215 $ev = $evals{$name};
1216 } else {
1217 return $option;
1218 }
1219
1220 for my $e (@{$ev}) {
1221 eval "\$option =~ $e";
1222 }
1223
1224 if ($option ne $old_option) {
1225 doprint("$name changed from '$old_option' to '$option'\n");
1226 }
1227
1228 return $option;
1229}
1230
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001231sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001232 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001233
1234 my $prev = "";
1235
1236 # Since an option can evaluate to another option,
1237 # keep iterating until we do not evaluate any more
1238 # options.
1239 my $r = 0;
1240 while ($prev ne $option) {
1241 # Check for recursive evaluations.
1242 # 100 deep should be more than enough.
1243 if ($r++ > 100) {
1244 die "Over 100 evaluations accurred with $option\n" .
1245 "Check for recursive variables\n";
1246 }
1247 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001248 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001249 }
1250
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001251 $option = process_evals($name, $option, $i);
1252
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001253 return $option;
1254}
1255
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001256sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001257sub start_monitor;
1258sub end_monitor;
1259sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001260
1261sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001262 my ($time) = @_;
1263
Steven Rostedta4968722012-12-11 14:59:05 -05001264 # Make sure everything has been written to disk
1265 run_ssh("sync");
1266
Steven Rostedt2b803362011-09-30 18:00:23 -04001267 if (defined($time)) {
1268 start_monitor;
1269 # flush out current monitor
1270 # May contain the reboot success line
1271 wait_for_monitor 1;
1272 }
1273
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001274 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001275 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001276 if (defined($powercycle_after_reboot)) {
1277 sleep $powercycle_after_reboot;
1278 run_command "$power_cycle";
1279 }
1280 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001281 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001282 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001283 }
Andrew Jones2728be42011-08-12 15:32:05 +02001284
1285 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001286
1287 # We only want to get to the new kernel, don't fail
1288 # if we stumble over a call trace.
1289 my $save_ignore_errors = $ignore_errors;
1290 $ignore_errors = 1;
1291
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001292 # Look for the good kernel to boot
1293 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001294 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001295 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001296 run_command "$power_cycle";
1297 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001298
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001299 $ignore_errors = $save_ignore_errors;
1300
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001301 # Still need to wait for the reboot to finish
1302 wait_for_monitor($time, $reboot_success_line);
1303
Andrew Jones2728be42011-08-12 15:32:05 +02001304 end_monitor;
1305 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001306}
1307
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001308sub reboot_to_good {
1309 my ($time) = @_;
1310
1311 if (defined($switch_to_good)) {
1312 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001313 }
1314
1315 reboot $time;
1316}
1317
Steven Rostedt576f6272010-11-02 14:58:38 -04001318sub do_not_reboot {
1319 my $i = $iteration;
1320
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001321 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001322 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1323 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1324}
1325
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001326sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001327 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001328
Steven Rostedt576f6272010-11-02 14:58:38 -04001329 my $i = $iteration;
1330
1331 if ($reboot_on_error && !do_not_reboot) {
1332
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001333 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001334 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001335
Steven Rostedta75fece2010-11-02 14:58:27 -04001336 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001337 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001338 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001339 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001340
Steven Rostedtf80802c2011-03-07 13:18:47 -05001341 if (defined($opt{"LOG_FILE"})) {
1342 print " See $opt{LOG_FILE} for more info.\n";
1343 }
1344
Steven Rostedt576f6272010-11-02 14:58:38 -04001345 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001346}
1347
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001348sub open_console {
1349 my ($fp) = @_;
1350
1351 my $flags;
1352
Josh Poimboeuf98842782015-01-27 12:10:04 -06001353 # save terminal settings
1354 $stty = `stty -g`;
1355
Steven Rostedta75fece2010-11-02 14:58:27 -04001356 my $pid = open($fp, "$console|") or
1357 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001358
1359 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001360 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001361 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001362 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001363
1364 return $pid;
1365}
1366
1367sub close_console {
1368 my ($fp, $pid) = @_;
1369
1370 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001371 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001372
1373 print "closing!\n";
1374 close($fp);
Josh Poimboeuf98842782015-01-27 12:10:04 -06001375
1376 # restore terminal settings
1377 system("stty $stty");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001378}
1379
1380sub start_monitor {
1381 if ($monitor_cnt++) {
1382 return;
1383 }
1384 $monitor_fp = \*MONFD;
1385 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001386
1387 return;
1388
1389 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001390}
1391
1392sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001393 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001394 if (--$monitor_cnt) {
1395 return;
1396 }
1397 close_console($monitor_fp, $monitor_pid);
1398}
1399
1400sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001401 my ($time, $stop) = @_;
1402 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001403 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001404 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001405 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001406 my $skip_call_trace = 0;
1407 my $bug = 0;
1408 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001409 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001410
Steven Rostedta75fece2010-11-02 14:58:27 -04001411 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001412
1413 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001414 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001415 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001416 last if (!defined($line));
1417 print "$line";
1418 $full_line .= $line;
1419
1420 if (defined($stop) && $full_line =~ /$stop/) {
1421 doprint "wait for monitor detected $stop\n";
1422 $booted = 1;
1423 }
1424
Steven Rostedt8a80c722012-07-19 16:08:33 -04001425 if ($full_line =~ /\[ backtrace testing \]/) {
1426 $skip_call_trace = 1;
1427 }
1428
1429 if ($full_line =~ /call trace:/i) {
1430 if (!$bug && !$skip_call_trace) {
1431 if ($ignore_errors) {
1432 $bug_ignored = 1;
1433 } else {
1434 $bug = 1;
1435 }
1436 }
1437 }
1438
1439 if ($full_line =~ /\[ end of backtrace testing \]/) {
1440 $skip_call_trace = 0;
1441 }
1442
1443 if ($full_line =~ /Kernel panic -/) {
1444 $bug = 1;
1445 }
1446
Steven Rostedt2b803362011-09-30 18:00:23 -04001447 if ($line =~ /\n/) {
1448 $full_line = "";
1449 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001450 $now = time;
1451 if ($now - $start_time >= $max_monitor_wait) {
1452 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1453 return 1;
1454 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001455 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001456 print "** Monitor flushed **\n";
Steven Rostedt (Red Hat)995bc432014-10-07 16:31:07 -04001457
1458 # if stop is defined but wasn't hit, return error
1459 # used by reboot (which wants to see a reboot)
1460 if (defined($stop) && !$booted) {
1461 $bug = 1;
1462 }
Steven Rostedt8a80c722012-07-19 16:08:33 -04001463 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001464}
1465
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301466sub save_logs {
1467 my ($result, $basedir) = @_;
1468 my @t = localtime;
1469 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1470 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1471
1472 my $type = $build_type;
1473 if ($type =~ /useconfig/) {
1474 $type = "useconfig";
1475 }
1476
1477 my $dir = "$machine-$test_type-$type-$result-$date";
1478
1479 $dir = "$basedir/$dir";
1480
1481 if (!-d $dir) {
1482 mkpath($dir) or
1483 die "can't create $dir";
1484 }
1485
1486 my %files = (
1487 "config" => $output_config,
1488 "buildlog" => $buildlog,
1489 "dmesg" => $dmesg,
1490 "testlog" => $testlog,
1491 );
1492
1493 while (my ($name, $source) = each(%files)) {
1494 if (-f "$source") {
1495 cp "$source", "$dir/$name" or
1496 die "failed to copy $source";
1497 }
1498 }
1499
1500 doprint "*** Saved info to $dir ***\n";
1501}
1502
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001503sub fail {
1504
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001505 if (defined($post_test)) {
1506 run_command $post_test;
1507 }
1508
Steven Rostedta75fece2010-11-02 14:58:27 -04001509 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001510 dodie @_;
1511 }
1512
Steven Rostedta75fece2010-11-02 14:58:27 -04001513 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001514
Steven Rostedt576f6272010-11-02 14:58:38 -04001515 my $i = $iteration;
1516
Steven Rostedta75fece2010-11-02 14:58:27 -04001517 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001518 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001519 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001520 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001521 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001522
Steven Rostedt9064af52011-06-13 10:38:48 -04001523 my $name = "";
1524
1525 if (defined($test_name)) {
1526 $name = " ($test_name)";
1527 }
1528
Steven Rostedt576f6272010-11-02 14:58:38 -04001529 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1530 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001531 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001532 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1533 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001534
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301535 if (defined($store_failures)) {
1536 save_logs "fail", $store_failures;
1537 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001538
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001539 return 1;
1540}
1541
Steven Rostedt2545eb62010-11-02 15:01:32 -04001542sub run_command {
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09001543 my ($command, $redirect) = @_;
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001544 my $start_time;
1545 my $end_time;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001546 my $dolog = 0;
1547 my $dord = 0;
1548 my $pid;
1549
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001550 $start_time = time;
1551
Steven Rostedte48c5292010-11-02 14:35:37 -04001552 $command =~ s/\$SSH_USER/$ssh_user/g;
1553 $command =~ s/\$MACHINE/$machine/g;
1554
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001555 doprint("$command ... ");
1556
1557 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001558 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001559
1560 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001561 open(LOG, ">>$opt{LOG_FILE}") or
1562 dodie "failed to write to log";
1563 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001564 }
1565
1566 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001567 open (RD, ">$redirect") or
1568 dodie "failed to write to redirect $redirect";
1569 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001570 }
1571
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001572 while (<CMD>) {
1573 print LOG if ($dolog);
1574 print RD if ($dord);
1575 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001576
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001577 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001578 my $failed = $?;
1579
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001580 close(CMD);
1581 close(LOG) if ($dolog);
1582 close(RD) if ($dord);
1583
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001584 $end_time = time;
1585 my $delta = $end_time - $start_time;
1586
1587 if ($delta == 1) {
1588 doprint "[1 second] ";
1589 } else {
1590 doprint "[$delta seconds] ";
1591 }
1592
Steven Rostedt2545eb62010-11-02 15:01:32 -04001593 if ($failed) {
1594 doprint "FAILED!\n";
1595 } else {
1596 doprint "SUCCESS\n";
1597 }
1598
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001599 return !$failed;
1600}
1601
Steven Rostedte48c5292010-11-02 14:35:37 -04001602sub run_ssh {
1603 my ($cmd) = @_;
1604 my $cp_exec = $ssh_exec;
1605
1606 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1607 return run_command "$cp_exec";
1608}
1609
1610sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001611 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001612
1613 $cp_scp =~ s/\$SRC_FILE/$src/g;
1614 $cp_scp =~ s/\$DST_FILE/$dst/g;
1615
1616 return run_command "$cp_scp";
1617}
1618
Steven Rostedt02ad2612012-03-21 08:21:24 -04001619sub run_scp_install {
1620 my ($src, $dst) = @_;
1621
1622 my $cp_scp = $scp_to_target_install;
1623
1624 return run_scp($src, $dst, $cp_scp);
1625}
1626
1627sub run_scp_mod {
1628 my ($src, $dst) = @_;
1629
1630 my $cp_scp = $scp_to_target;
1631
1632 return run_scp($src, $dst, $cp_scp);
1633}
1634
Steven Rostedta15ba912012-11-13 14:30:37 -05001635sub get_grub2_index {
1636
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001637 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001638 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1639 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001640
1641 doprint "Find grub2 menu ... ";
1642 $grub_number = -1;
1643
1644 my $ssh_grub = $ssh_exec;
1645 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1646
1647 open(IN, "$ssh_grub |")
1648 or die "unable to get $grub_file";
1649
1650 my $found = 0;
1651
1652 while (<IN>) {
1653 if (/^menuentry.*$grub_menu/) {
1654 $grub_number++;
1655 $found = 1;
1656 last;
1657 } elsif (/^menuentry\s/) {
1658 $grub_number++;
1659 }
1660 }
1661 close(IN);
1662
1663 die "Could not find '$grub_menu' in $grub_file on $machine"
1664 if (!$found);
1665 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001666 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001667 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001668}
1669
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001670sub get_grub_index {
1671
Steven Rostedta15ba912012-11-13 14:30:37 -05001672 if ($reboot_type eq "grub2") {
1673 get_grub2_index;
1674 return;
1675 }
1676
Steven Rostedta75fece2010-11-02 14:58:27 -04001677 if ($reboot_type ne "grub") {
1678 return;
1679 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001680 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001681 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1682 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001683
1684 doprint "Find grub menu ... ";
1685 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001686
1687 my $ssh_grub = $ssh_exec;
1688 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1689
1690 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001691 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001692
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001693 my $found = 0;
1694
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001695 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001696 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001697 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001698 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001699 last;
1700 } elsif (/^\s*title\s/) {
1701 $grub_number++;
1702 }
1703 }
1704 close(IN);
1705
Steven Rostedta75fece2010-11-02 14:58:27 -04001706 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001707 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001708 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001709 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001710 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001711}
1712
Steven Rostedt2545eb62010-11-02 15:01:32 -04001713sub wait_for_input
1714{
1715 my ($fp, $time) = @_;
1716 my $rin;
1717 my $ready;
1718 my $line;
1719 my $ch;
1720
1721 if (!defined($time)) {
1722 $time = $timeout;
1723 }
1724
1725 $rin = '';
1726 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001727 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001728
1729 $line = "";
1730
1731 # try to read one char at a time
1732 while (sysread $fp, $ch, 1) {
1733 $line .= $ch;
1734 last if ($ch eq "\n");
1735 }
1736
1737 if (!length($line)) {
1738 return undef;
1739 }
1740
1741 return $line;
1742}
1743
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001744sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001745 if (defined($switch_to_test)) {
1746 run_command $switch_to_test;
1747 }
1748
Steven Rostedta75fece2010-11-02 14:58:27 -04001749 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001750 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001751 } elsif ($reboot_type eq "grub2") {
1752 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001753 } elsif ($reboot_type eq "syslinux") {
1754 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001755 } elsif (defined $reboot_script) {
1756 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001757 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001758 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001759}
1760
Steven Rostedta57419b2010-11-02 15:13:54 -04001761sub get_sha1 {
1762 my ($commit) = @_;
1763
1764 doprint "git rev-list --max-count=1 $commit ... ";
1765 my $sha1 = `git rev-list --max-count=1 $commit`;
1766 my $ret = $?;
1767
1768 logit $sha1;
1769
1770 if ($ret) {
1771 doprint "FAILED\n";
1772 dodie "Failed to get git $commit";
1773 }
1774
1775 print "SUCCESS\n";
1776
1777 chomp $sha1;
1778
1779 return $sha1;
1780}
1781
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001782sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001783 my $booted = 0;
1784 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001785 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001786 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001787 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001788
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001789 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001790
1791 my $line;
1792 my $full_line = "";
1793
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001794 open(DMESG, "> $dmesg") or
1795 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001796
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001797 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001798
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001799 my $success_start;
1800 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001801 my $monitor_start = time;
1802 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001803 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001804
Steven Rostedt2d01b262011-03-08 09:47:54 -05001805 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001806
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001807 if ($bug && defined($stop_after_failure) &&
1808 $stop_after_failure >= 0) {
1809 my $time = $stop_after_failure - (time - $failure_start);
1810 $line = wait_for_input($monitor_fp, $time);
1811 if (!defined($line)) {
1812 doprint "bug timed out after $booted_timeout seconds\n";
1813 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1814 last;
1815 }
1816 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001817 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001818 if (!defined($line)) {
1819 my $s = $booted_timeout == 1 ? "" : "s";
1820 doprint "Successful boot found: break after $booted_timeout second$s\n";
1821 last;
1822 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001823 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001824 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001825 if (!defined($line)) {
1826 my $s = $timeout == 1 ? "" : "s";
1827 doprint "Timed out after $timeout second$s\n";
1828 last;
1829 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001830 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001831
Steven Rostedt2545eb62010-11-02 15:01:32 -04001832 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001833 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001834
1835 # we are not guaranteed to get a full line
1836 $full_line .= $line;
1837
Steven Rostedta75fece2010-11-02 14:58:27 -04001838 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001839 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001840 $success_start = time;
1841 }
1842
1843 if ($booted && defined($stop_after_success) &&
1844 $stop_after_success >= 0) {
1845 my $now = time;
1846 if ($now - $success_start >= $stop_after_success) {
1847 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1848 last;
1849 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001850 }
1851
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001852 if ($full_line =~ /\[ backtrace testing \]/) {
1853 $skip_call_trace = 1;
1854 }
1855
Steven Rostedt2545eb62010-11-02 15:01:32 -04001856 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001857 if (!$bug && !$skip_call_trace) {
1858 if ($ignore_errors) {
1859 $bug_ignored = 1;
1860 } else {
1861 $bug = 1;
1862 $failure_start = time;
1863 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001864 }
1865 }
1866
1867 if ($bug && defined($stop_after_failure) &&
1868 $stop_after_failure >= 0) {
1869 my $now = time;
1870 if ($now - $failure_start >= $stop_after_failure) {
1871 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1872 last;
1873 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001874 }
1875
1876 if ($full_line =~ /\[ end of backtrace testing \]/) {
1877 $skip_call_trace = 0;
1878 }
1879
1880 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001881 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001882 $bug = 1;
1883 }
1884
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001885 # Detect triple faults by testing the banner
1886 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1887 if ($1 eq $version) {
1888 $version_found = 1;
1889 } elsif ($version_found && $detect_triplefault) {
1890 # We already booted into the kernel we are testing,
1891 # but now we booted into another kernel?
1892 # Consider this a triple fault.
Masanari Iida8b513d02013-05-21 23:13:12 +09001893 doprint "Already booted in Linux kernel $version, but now\n";
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001894 doprint "we booted into Linux kernel $1.\n";
1895 doprint "Assuming that this is a triple fault.\n";
1896 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1897 last;
1898 }
1899 }
1900
Steven Rostedt2545eb62010-11-02 15:01:32 -04001901 if ($line =~ /\n/) {
1902 $full_line = "";
1903 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001904
1905 if ($stop_test_after > 0 && !$booted && !$bug) {
1906 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001907 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001908 $done = 1;
1909 }
1910 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001911 }
1912
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001913 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001914
Steven Rostedt2545eb62010-11-02 15:01:32 -04001915 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001916 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001917 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001918 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001919
Steven Rostedta75fece2010-11-02 14:58:27 -04001920 if (!$booted) {
1921 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001922 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001923 }
1924
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001925 if ($bug_ignored) {
1926 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1927 }
1928
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001929 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001930}
1931
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001932sub eval_kernel_version {
1933 my ($option) = @_;
1934
1935 $option =~ s/\$KERNEL_VERSION/$version/g;
1936
1937 return $option;
1938}
1939
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001940sub do_post_install {
1941
1942 return if (!defined($post_install));
1943
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001944 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001945 run_command "$cp_post_install" or
1946 dodie "Failed to run post install";
1947}
1948
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001949# Sometimes the reboot fails, and will hang. We try to ssh to the box
1950# and if we fail, we force another reboot, that should powercycle it.
1951sub test_booted {
1952 if (!run_ssh "echo testing connection") {
1953 reboot $sleep_time;
1954 }
1955}
1956
Steven Rostedt2545eb62010-11-02 15:01:32 -04001957sub install {
1958
Steven Rostedte0a87422011-09-30 17:50:48 -04001959 return if ($no_install);
1960
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001961 if (defined($pre_install)) {
1962 my $cp_pre_install = eval_kernel_version $pre_install;
1963 run_command "$cp_pre_install" or
1964 dodie "Failed to run pre install";
1965 }
1966
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001967 my $cp_target = eval_kernel_version $target_image;
1968
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001969 test_booted;
1970
Steven Rostedt02ad2612012-03-21 08:21:24 -04001971 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001972 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001973
1974 my $install_mods = 0;
1975
1976 # should we process modules?
1977 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001978 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001979 while (<IN>) {
1980 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001981 if (defined($1)) {
1982 $install_mods = 1;
1983 last;
1984 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001985 }
1986 }
1987 close(IN);
1988
1989 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001990 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001991 doprint "No modules needed\n";
1992 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001993 }
1994
Steven Rostedt627977d2012-03-21 08:16:15 -04001995 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001996 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001997
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001998 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001999 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002000
Steven Rostedte48c5292010-11-02 14:35:37 -04002001 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002002 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002003
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002004 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04002005 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002006 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002007
Steven Rostedt02ad2612012-03-21 08:21:24 -04002008 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002009 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002010
Steven Rostedta75fece2010-11-02 14:58:27 -04002011 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002012
Steven Rostedte7b13442011-06-14 20:44:36 -04002013 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002014 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002015
Steven Rostedte48c5292010-11-02 14:35:37 -04002016 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002017
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002018 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002019}
2020
Steven Rostedtddf607e2011-06-14 20:49:13 -04002021sub get_version {
2022 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04002023 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002024 doprint "$make kernelrelease ... ";
Steven Rostedt (Red Hat)17150fe2014-11-23 15:13:44 -05002025 $version = `$make -s kernelrelease | tail -1`;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002026 chomp($version);
2027 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002028 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002029}
2030
2031sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002032 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002033
2034 # Install bisects, don't need console
2035 if (defined $console) {
2036 start_monitor;
2037 wait_for_monitor 5;
2038 end_monitor;
2039 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002040
Steven Rostedtddf607e2011-06-14 20:49:13 -04002041 get_grub_index;
2042 get_version;
2043 install;
2044
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002045 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002046 return monitor;
2047}
2048
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002049my $check_build_re = ".*:.*(warning|error|Error):.*";
2050my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2051
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002052sub process_warning_line {
2053 my ($line) = @_;
2054
2055 chomp $line;
2056
2057 # for distcc heterogeneous systems, some compilers
2058 # do things differently causing warning lines
2059 # to be slightly different. This makes an attempt
2060 # to fixe those issues.
2061
2062 # chop off the index into the line
2063 # using distcc, some compilers give different indexes
2064 # depending on white space
2065 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2066
2067 # Some compilers use UTF-8 extended for quotes and some don't.
2068 $line =~ s/$utf8_quote/'/g;
2069
2070 return $line;
2071}
2072
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002073# Read buildlog and check against warnings file for any
2074# new warnings.
2075#
2076# Returns 1 if OK
2077# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002078sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002079 return 1 if (!defined $warnings_file);
2080
2081 my %warnings_list;
2082
2083 # Failed builds should not reboot the target
2084 my $save_no_reboot = $no_reboot;
2085 $no_reboot = 1;
2086
2087 if (-f $warnings_file) {
2088 open(IN, $warnings_file) or
2089 dodie "Error opening $warnings_file";
2090
2091 while (<IN>) {
2092 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002093 my $warning = process_warning_line $_;
2094
2095 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002096 }
2097 }
2098 close(IN);
2099 }
2100
2101 # If warnings file didn't exist, and WARNINGS_FILE exist,
2102 # then we fail on any warning!
2103
2104 open(IN, $buildlog) or dodie "Can't open $buildlog";
2105 while (<IN>) {
2106 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002107 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002108
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002109 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002110 fail "New warning found (not in $warnings_file)\n$_\n";
2111 $no_reboot = $save_no_reboot;
2112 return 0;
2113 }
2114 }
2115 }
2116 $no_reboot = $save_no_reboot;
2117 close(IN);
2118}
2119
2120sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002121 my ($patch) = @_;
2122
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002123 my @files = `git show $patch | diffstat -l`;
2124
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002125 foreach my $file (@files) {
2126 chomp $file;
2127 }
2128
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002129 open(IN, "git show $patch |") or
2130 dodie "failed to show $patch";
2131 while (<IN>) {
2132 if (m,^--- a/(.*),) {
2133 chomp $1;
2134 $files[$#files] = $1;
2135 }
2136 }
2137 close(IN);
2138
2139 open(IN, $buildlog) or dodie "Can't open $buildlog";
2140 while (<IN>) {
2141 if (/^\s*(.*?):.*(warning|error)/) {
2142 my $err = $1;
2143 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002144 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002145 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002146 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002147 }
2148 }
2149 }
2150 }
2151 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002152
2153 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002154}
2155
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002156sub apply_min_config {
2157 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002158
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002159 # Read the config file and remove anything that
2160 # is in the force_config hash (from minconfig and others)
2161 # then add the force config back.
2162
2163 doprint "Applying minimum configurations into $output_config.new\n";
2164
2165 open (OUT, ">$outconfig") or
2166 dodie "Can't create $outconfig";
2167
2168 if (-f $output_config) {
2169 open (IN, $output_config) or
2170 dodie "Failed to open $output_config";
2171 while (<IN>) {
2172 if (/^(# )?(CONFIG_[^\s=]*)/) {
2173 next if (defined($force_config{$2}));
2174 }
2175 print OUT;
2176 }
2177 close IN;
2178 }
2179 foreach my $config (keys %force_config) {
2180 print OUT "$force_config{$config}\n";
2181 }
2182 close OUT;
2183
2184 run_command "mv $outconfig $output_config";
2185}
2186
2187sub make_oldconfig {
2188
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002189 my @force_list = keys %force_config;
2190
2191 if ($#force_list >= 0) {
2192 apply_min_config;
2193 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002194
Adam Leefb16d892012-09-01 01:05:17 +08002195 if (!run_command "$make olddefconfig") {
2196 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002197 # try oldnoconfig
2198 doprint "olddefconfig failed, trying make oldnoconfig\n";
2199 if (!run_command "$make oldnoconfig") {
2200 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2201 # try a yes '' | oldconfig
2202 run_command "yes '' | $make oldconfig" or
2203 dodie "failed make config oldconfig";
2204 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002205 }
2206}
2207
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002208# read a config file and use this to force new configs.
2209sub load_force_config {
2210 my ($config) = @_;
2211
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002212 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002213 open(IN, $config) or
2214 dodie "failed to read $config";
2215 while (<IN>) {
2216 chomp;
2217 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2218 $force_config{$1} = $_;
2219 } elsif (/^# (CONFIG_\S*) is not set/) {
2220 $force_config{$1} = $_;
2221 }
2222 }
2223 close IN;
2224}
2225
Steven Rostedt2545eb62010-11-02 15:01:32 -04002226sub build {
2227 my ($type) = @_;
2228
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002229 unlink $buildlog;
2230
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002231 # Failed builds should not reboot the target
2232 my $save_no_reboot = $no_reboot;
2233 $no_reboot = 1;
2234
Steven Rostedt683a3e62012-05-18 13:34:35 -04002235 # Calculate a new version from here.
2236 $have_version = 0;
2237
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002238 if (defined($pre_build)) {
2239 my $ret = run_command $pre_build;
2240 if (!$ret && defined($pre_build_die) &&
2241 $pre_build_die) {
2242 dodie "failed to pre_build\n";
2243 }
2244 }
2245
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002246 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002247 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002248 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002249
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002250 $type = "oldconfig";
2251 }
2252
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002253 # old config can ask questions
2254 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002255 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002256
2257 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002258 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002259
Andrew Jones13488232011-08-12 15:32:04 +02002260 if (!$noclean) {
2261 run_command "mv $output_config $outputdir/config_temp" or
2262 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002263
Andrew Jones13488232011-08-12 15:32:04 +02002264 run_command "$make mrproper" or dodie "make mrproper";
2265
2266 run_command "mv $outputdir/config_temp $output_config" or
2267 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002268 }
2269
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002270 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002271 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002272 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002273 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002274 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002275
2276 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002277 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2278 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002279 close(OUT);
2280
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002281 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002282 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002283 }
2284
Adam Leefb16d892012-09-01 01:05:17 +08002285 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002286 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002287 dodie "failed make config";
2288 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002289 # Run old config regardless, to enforce min configurations
2290 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002291
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002292 my $build_ret = run_command "$make $build_options", $buildlog;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002293
2294 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002295 # Because a post build may change the kernel version
2296 # do it now.
2297 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002298 my $ret = run_command $post_build;
2299 if (!$ret && defined($post_build_die) &&
2300 $post_build_die) {
2301 dodie "failed to post_build\n";
2302 }
2303 }
2304
2305 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002306 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002307 if ($in_bisect) {
2308 $no_reboot = $save_no_reboot;
2309 return 0;
2310 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002311 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002312 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002313
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002314 $no_reboot = $save_no_reboot;
2315
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002316 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002317}
2318
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002319sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002320 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002321 if (defined($poweroff_after_halt)) {
2322 sleep $poweroff_after_halt;
2323 run_command "$power_off";
2324 }
2325 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002326 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002327 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002328 }
2329}
2330
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002331sub success {
2332 my ($i) = @_;
2333
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002334 if (defined($post_test)) {
2335 run_command $post_test;
2336 }
2337
Steven Rostedte48c5292010-11-02 14:35:37 -04002338 $successes++;
2339
Steven Rostedt9064af52011-06-13 10:38:48 -04002340 my $name = "";
2341
2342 if (defined($test_name)) {
2343 $name = " ($test_name)";
2344 }
2345
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002346 doprint "\n\n*******************************************\n";
2347 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002348 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002349 doprint "*******************************************\n";
2350 doprint "*******************************************\n";
2351
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302352 if (defined($store_successes)) {
2353 save_logs "success", $store_successes;
2354 }
2355
Steven Rostedt576f6272010-11-02 14:58:38 -04002356 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002357 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002358 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002359 }
2360}
2361
Steven Rostedtc960bb92011-03-08 09:22:39 -05002362sub answer_bisect {
2363 for (;;) {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002364 doprint "Pass, fail, or skip? [p/f/s]";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002365 my $ans = <STDIN>;
2366 chomp $ans;
2367 if ($ans eq "p" || $ans eq "P") {
2368 return 1;
2369 } elsif ($ans eq "f" || $ans eq "F") {
2370 return 0;
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002371 } elsif ($ans eq "s" || $ans eq "S") {
2372 return -1;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002373 } else {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002374 print "Please answer 'p', 'f', or 's'\n";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002375 }
2376 }
2377}
2378
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002379sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002380 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002381
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002382 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002383 $reboot_on_error = 0;
2384 $poweroff_on_error = 0;
2385 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002386
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002387 run_command $run_test, $testlog or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302388
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002389 exit $failed;
2390}
2391
2392my $child_done;
2393
2394sub child_finished {
2395 $child_done = 1;
2396}
2397
2398sub do_run_test {
2399 my $child_pid;
2400 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002401 my $line;
2402 my $full_line;
2403 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002404 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002405
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002406 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002407
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002408 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002409
2410 $child_done = 0;
2411
2412 $SIG{CHLD} = qw(child_finished);
2413
2414 $child_pid = fork;
2415
2416 child_run_test if (!$child_pid);
2417
2418 $full_line = "";
2419
2420 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002421 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002422 if (defined($line)) {
2423
2424 # we are not guaranteed to get a full line
2425 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002426 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002427
2428 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002429 if ($ignore_errors) {
2430 $bug_ignored = 1;
2431 } else {
2432 $bug = 1;
2433 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002434 }
2435
2436 if ($full_line =~ /Kernel panic -/) {
2437 $bug = 1;
2438 }
2439
2440 if ($line =~ /\n/) {
2441 $full_line = "";
2442 }
2443 }
2444 } while (!$child_done && !$bug);
2445
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002446 if (!$bug && $bug_ignored) {
2447 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2448 }
2449
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002450 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002451 my $failure_start = time;
2452 my $now;
2453 do {
2454 $line = wait_for_input($monitor_fp, 1);
2455 if (defined($line)) {
2456 doprint $line;
2457 }
2458 $now = time;
2459 if ($now - $failure_start >= $stop_after_failure) {
2460 last;
2461 }
2462 } while (defined($line));
2463
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002464 doprint "Detected kernel crash!\n";
2465 # kill the child with extreme prejudice
2466 kill 9, $child_pid;
2467 }
2468
2469 waitpid $child_pid, 0;
2470 $child_exit = $?;
2471
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002472 if (!$bug && $in_bisect) {
2473 if (defined($bisect_ret_good)) {
2474 if ($child_exit == $bisect_ret_good) {
2475 return 1;
2476 }
2477 }
2478 if (defined($bisect_ret_skip)) {
2479 if ($child_exit == $bisect_ret_skip) {
2480 return -1;
2481 }
2482 }
2483 if (defined($bisect_ret_abort)) {
2484 if ($child_exit == $bisect_ret_abort) {
2485 fail "test abort" and return -2;
2486 }
2487 }
2488 if (defined($bisect_ret_bad)) {
2489 if ($child_exit == $bisect_ret_skip) {
2490 return 0;
2491 }
2492 }
2493 if (defined($bisect_ret_default)) {
2494 if ($bisect_ret_default eq "good") {
2495 return 1;
2496 } elsif ($bisect_ret_default eq "bad") {
2497 return 0;
2498 } elsif ($bisect_ret_default eq "skip") {
2499 return -1;
2500 } elsif ($bisect_ret_default eq "abort") {
2501 return -2;
2502 } else {
2503 fail "unknown default action: $bisect_ret_default"
2504 and return -2;
2505 }
2506 }
2507 }
2508
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002509 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002510 return 0 if $in_bisect;
2511 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002512 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002513 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002514}
2515
Steven Rostedta75fece2010-11-02 14:58:27 -04002516sub run_git_bisect {
2517 my ($command) = @_;
2518
2519 doprint "$command ... ";
2520
2521 my $output = `$command 2>&1`;
2522 my $ret = $?;
2523
2524 logit $output;
2525
2526 if ($ret) {
2527 doprint "FAILED\n";
2528 dodie "Failed to git bisect";
2529 }
2530
2531 doprint "SUCCESS\n";
2532 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2533 doprint "$1 [$2]\n";
2534 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002535 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002536 doprint "Found bad commit... $1\n";
2537 return 0;
2538 } else {
2539 # we already logged it, just print it now.
2540 print $output;
2541 }
2542
2543 return 1;
2544}
2545
Steven Rostedtc23dca72011-03-08 09:26:31 -05002546sub bisect_reboot {
2547 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002548 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002549}
2550
2551# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002552sub run_bisect_test {
2553 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002554
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002555 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002556 my $result;
2557 my $output;
2558 my $ret;
2559
Steven Rostedt0a05c762010-11-08 11:14:10 -05002560 $in_bisect = 1;
2561
2562 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002563
2564 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002565 if ($failed && $bisect_skip) {
2566 $in_bisect = 0;
2567 return -1;
2568 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002569 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002570
2571 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002572 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002573
2574 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002575 if ($failed && $bisect_skip) {
2576 end_monitor;
2577 bisect_reboot;
2578 $in_bisect = 0;
2579 return -1;
2580 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002581 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002582
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002583 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002584 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002585 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002586 }
2587
2588 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002589 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002590 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002591 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002592 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002593
2594 # reboot the box to a kernel we can ssh to
2595 if ($type ne "build") {
2596 bisect_reboot;
2597 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002598 $in_bisect = 0;
2599
2600 return $result;
2601}
2602
2603sub run_bisect {
2604 my ($type) = @_;
2605 my $buildtype = "oldconfig";
2606
2607 # We should have a minconfig to use?
2608 if (defined($minconfig)) {
2609 $buildtype = "useconfig:$minconfig";
2610 }
2611
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002612 # If the user sets bisect_tries to less than 1, then no tries
2613 # is a success.
2614 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002615
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002616 # Still let the user manually decide that though.
2617 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002618 $ret = answer_bisect;
2619 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002620
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002621 for (my $i = 0; $i < $bisect_tries; $i++) {
2622 if ($bisect_tries > 1) {
2623 my $t = $i + 1;
2624 doprint("Running bisect trial $t of $bisect_tries:\n");
2625 }
2626 $ret = run_bisect_test $type, $buildtype;
2627
2628 if ($bisect_manual) {
2629 $ret = answer_bisect;
2630 }
2631
2632 last if (!$ret);
2633 }
2634
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002635 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002636 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002637 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002638 }
2639
Steven Rostedtc23dca72011-03-08 09:26:31 -05002640 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002641 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002642 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002643 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002644 } elsif ($bisect_skip) {
2645 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2646 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002647 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002648}
2649
Steven Rostedtdad98752011-11-22 20:48:57 -05002650sub update_bisect_replay {
2651 my $tmp_log = "$tmpdir/ktest_bisect_log";
2652 run_command "git bisect log > $tmp_log" or
2653 die "can't create bisect log";
2654 return $tmp_log;
2655}
2656
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002657sub bisect {
2658 my ($i) = @_;
2659
2660 my $result;
2661
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002662 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2663 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2664 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002665
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002666 my $good = $bisect_good;
2667 my $bad = $bisect_bad;
2668 my $type = $bisect_type;
2669 my $start = $bisect_start;
2670 my $replay = $bisect_replay;
2671 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002672
2673 if (defined($start_files)) {
2674 $start_files = " -- " . $start_files;
2675 } else {
2676 $start_files = "";
2677 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002678
Steven Rostedta57419b2010-11-02 15:13:54 -04002679 # convert to true sha1's
2680 $good = get_sha1($good);
2681 $bad = get_sha1($bad);
2682
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002683 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002684 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2685 $reverse_bisect = 1;
2686 } else {
2687 $reverse_bisect = 0;
2688 }
2689
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002690 # Can't have a test without having a test to run
2691 if ($type eq "test" && !defined($run_test)) {
2692 $type = "boot";
2693 }
2694
Steven Rostedtdad98752011-11-22 20:48:57 -05002695 # Check if a bisect was running
2696 my $bisect_start_file = "$builddir/.git/BISECT_START";
2697
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002698 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002699 my $do_check = defined($check) && $check ne "0";
2700
2701 if ( -f $bisect_start_file ) {
2702 print "Bisect in progress found\n";
2703 if ($do_check) {
2704 print " If you say yes, then no checks of good or bad will be done\n";
2705 }
2706 if (defined($replay)) {
2707 print "** BISECT_REPLAY is defined in config file **";
2708 print " Ignore config option and perform new git bisect log?\n";
2709 if (read_ync " (yes, no, or cancel) ") {
2710 $replay = update_bisect_replay;
2711 $do_check = 0;
2712 }
2713 } elsif (read_yn "read git log and continue?") {
2714 $replay = update_bisect_replay;
2715 $do_check = 0;
2716 }
2717 }
2718
2719 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002720
2721 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002722 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002723
2724 if ($check ne "good") {
2725 doprint "TESTING BISECT BAD [$bad]\n";
2726 run_command "git checkout $bad" or
2727 die "Failed to checkout $bad";
2728
2729 $result = run_bisect $type;
2730
2731 if ($result ne "bad") {
2732 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2733 }
2734 }
2735
2736 if ($check ne "bad") {
2737 doprint "TESTING BISECT GOOD [$good]\n";
2738 run_command "git checkout $good" or
2739 die "Failed to checkout $good";
2740
2741 $result = run_bisect $type;
2742
2743 if ($result ne "good") {
2744 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2745 }
2746 }
2747
2748 # checkout where we started
2749 run_command "git checkout $head" or
2750 die "Failed to checkout $head";
2751 }
2752
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002753 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002754 dodie "could not start bisect";
2755
Steven Rostedta75fece2010-11-02 14:58:27 -04002756 if (defined($replay)) {
2757 run_command "git bisect replay $replay" or
2758 dodie "failed to run replay";
Steven Rostedt (Red Hat)d832d742014-10-07 16:34:25 -04002759 } else {
2760
2761 run_command "git bisect good $good" or
2762 dodie "could not set bisect good to $good";
2763
2764 run_git_bisect "git bisect bad $bad" or
2765 dodie "could not set bisect bad to $bad";
2766
Steven Rostedta75fece2010-11-02 14:58:27 -04002767 }
2768
2769 if (defined($start)) {
2770 run_command "git checkout $start" or
2771 dodie "failed to checkout $start";
2772 }
2773
2774 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002775 do {
2776 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002777 $test = run_git_bisect "git bisect $result";
2778 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002779
2780 run_command "git bisect log" or
2781 dodie "could not capture git bisect log";
2782
2783 run_command "git bisect reset" or
2784 dodie "could not reset git bisect";
2785
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002786 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002787
Steven Rostedt0a05c762010-11-08 11:14:10 -05002788 success $i;
2789}
2790
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002791# config_ignore holds the configs that were set (or unset) for
2792# a good config and we will ignore these configs for the rest
2793# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002794my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002795
2796# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002797my %config_set;
2798
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002799# config_off holds the set of configs that the bad config had disabled.
2800# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002801# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002802my %config_off;
2803
2804# config_off_tmp holds a set of configs to turn off for now
2805my @config_off_tmp;
2806
2807# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002808my %config_list;
2809my %null_config;
2810
2811my %dependency;
2812
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002813sub assign_configs {
2814 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002815
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002816 doprint "Reading configs from $config\n";
2817
Steven Rostedt0a05c762010-11-08 11:14:10 -05002818 open (IN, $config)
2819 or dodie "Failed to read $config";
2820
2821 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002822 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04002823 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002824 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002825 } elsif (/^(# (CONFIG\S*) is not set)/) {
2826 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002827 }
2828 }
2829
2830 close(IN);
2831}
2832
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002833sub process_config_ignore {
2834 my ($config) = @_;
2835
2836 assign_configs \%config_ignore, $config;
2837}
2838
Steven Rostedt0a05c762010-11-08 11:14:10 -05002839sub get_dependencies {
2840 my ($config) = @_;
2841
2842 my $arr = $dependency{$config};
2843 if (!defined($arr)) {
2844 return ();
2845 }
2846
2847 my @deps = @{$arr};
2848
2849 foreach my $dep (@{$arr}) {
2850 print "ADD DEP $dep\n";
2851 @deps = (@deps, get_dependencies $dep);
2852 }
2853
2854 return @deps;
2855}
2856
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002857sub save_config {
2858 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002859
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002860 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002861
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002862 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002863
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002864 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002865
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002866 foreach my $config (keys %configs) {
2867 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002868 }
2869 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002870}
2871
2872sub create_config {
2873 my ($name, $pc) = @_;
2874
2875 doprint "Creating old config from $name configs\n";
2876
2877 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002878
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002879 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002880}
2881
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002882# compare two config hashes, and return configs with different vals.
2883# It returns B's config values, but you can use A to see what A was.
2884sub diff_config_vals {
2885 my ($pa, $pb) = @_;
2886
2887 # crappy Perl way to pass in hashes.
2888 my %a = %{$pa};
2889 my %b = %{$pb};
2890
2891 my %ret;
2892
2893 foreach my $item (keys %a) {
2894 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2895 $ret{$item} = $b{$item};
2896 }
2897 }
2898
2899 return %ret;
2900}
2901
2902# compare two config hashes and return the configs in B but not A
2903sub diff_configs {
2904 my ($pa, $pb) = @_;
2905
2906 my %ret;
2907
2908 # crappy Perl way to pass in hashes.
2909 my %a = %{$pa};
2910 my %b = %{$pb};
2911
2912 foreach my $item (keys %b) {
2913 if (!defined($a{$item})) {
2914 $ret{$item} = $b{$item};
2915 }
2916 }
2917
2918 return %ret;
2919}
2920
2921# return if two configs are equal or not
2922# 0 is equal +1 b has something a does not
2923# +1 if a and b have a different item.
2924# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05002925sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002926 my ($pa, $pb) = @_;
2927
2928 my %ret;
2929
2930 # crappy Perl way to pass in hashes.
2931 my %a = %{$pa};
2932 my %b = %{$pb};
2933
2934 foreach my $item (keys %b) {
2935 if (!defined($a{$item})) {
2936 return 1;
2937 }
2938 if ($a{$item} ne $b{$item}) {
2939 return 1;
2940 }
2941 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002942
2943 foreach my $item (keys %a) {
2944 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002945 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002946 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002947 }
2948
Steven Rostedt0a05c762010-11-08 11:14:10 -05002949 return 0;
2950}
2951
2952sub run_config_bisect_test {
2953 my ($type) = @_;
2954
Steven Rostedt (Red Hat)4cc559b2014-04-23 22:27:27 -04002955 my $ret = run_bisect_test $type, "oldconfig";
2956
2957 if ($bisect_manual) {
2958 $ret = answer_bisect;
2959 }
2960
2961 return $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002962}
2963
Steven Rostedt0a05c762010-11-08 11:14:10 -05002964sub process_failed {
2965 my ($config) = @_;
2966
2967 doprint "\n\n***************************************\n";
2968 doprint "Found bad config: $config\n";
2969 doprint "***************************************\n\n";
2970}
2971
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002972# used for config bisecting
2973my $good_config;
2974my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002975
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002976sub process_new_config {
2977 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002978
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002979 my %tmp_config = %{$tc};
2980 my %good_configs = %{$gc};
2981 my %bad_configs = %{$bc};
2982
2983 my %new_configs;
2984
2985 my $runtest = 1;
2986 my $ret;
2987
2988 create_config "tmp_configs", \%tmp_config;
2989 assign_configs \%new_configs, $output_config;
2990
2991 $ret = compare_configs \%new_configs, \%bad_configs;
2992 if (!$ret) {
2993 doprint "New config equals bad config, try next test\n";
2994 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002995 }
2996
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002997 if ($runtest) {
2998 $ret = compare_configs \%new_configs, \%good_configs;
2999 if (!$ret) {
3000 doprint "New config equals good config, try next test\n";
3001 $runtest = 0;
3002 }
3003 }
3004
3005 %{$nc} = %new_configs;
3006
3007 return $runtest;
3008}
3009
3010sub run_config_bisect {
3011 my ($pgood, $pbad) = @_;
3012
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003013 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003014
3015 my %good_configs = %{$pgood};
3016 my %bad_configs = %{$pbad};
3017
3018 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
3019 my %b_configs = diff_configs \%good_configs, \%bad_configs;
3020 my %g_configs = diff_configs \%bad_configs, \%good_configs;
3021
3022 my @diff_arr = keys %diff_configs;
3023 my $len_diff = $#diff_arr + 1;
3024
3025 my @b_arr = keys %b_configs;
3026 my $len_b = $#b_arr + 1;
3027
3028 my @g_arr = keys %g_configs;
3029 my $len_g = $#g_arr + 1;
3030
3031 my $runtest = 1;
3032 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003033 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003034
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003035 # First, lets get it down to a single subset.
3036 # Is the problem with a difference in values?
3037 # Is the problem with a missing config?
3038 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003039
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003040 # Enable all of one set and see if we get a new bad
3041 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003042
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003043 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003044
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003045 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003046
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003047 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003048
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003049 if ($len_diff > 0) {
3050 if ($len_b > 0 || $len_g > 0) {
3051 my %tmp_config = %bad_configs;
3052
3053 doprint "Set tmp config to be bad config with good config values\n";
3054 foreach my $item (@diff_arr) {
3055 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003056 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003057
3058 $runtest = process_new_config \%tmp_config, \%new_configs,
3059 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003060 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003061 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003062
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003063 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003064
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003065 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003066 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003067 return 1;
3068 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003069 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003070
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003071 my $half = int($#diff_arr / 2);
3072 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003073
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003074 doprint "Settings bisect with top half:\n";
3075 doprint "Set tmp config to be bad config with some good config values\n";
3076 foreach my $item (@tophalf) {
3077 $tmp_config{$item} = $good_configs{$item};
3078 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003079
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003080 $runtest = process_new_config \%tmp_config, \%new_configs,
3081 \%good_configs, \%bad_configs;
3082
3083 if (!$runtest) {
3084 my %tmp_config = %bad_configs;
3085
3086 doprint "Try bottom half\n";
3087
3088 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3089
3090 foreach my $item (@bottomhalf) {
3091 $tmp_config{$item} = $good_configs{$item};
3092 }
3093
3094 $runtest = process_new_config \%tmp_config, \%new_configs,
3095 \%good_configs, \%bad_configs;
3096 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003097 }
3098
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003099 if ($runtest) {
3100 $ret = run_config_bisect_test $type;
3101 if ($ret) {
3102 doprint "NEW GOOD CONFIG\n";
3103 %good_configs = %new_configs;
3104 run_command "mv $good_config ${good_config}.last";
3105 save_config \%good_configs, $good_config;
3106 %{$pgood} = %good_configs;
3107 } else {
3108 doprint "NEW BAD CONFIG\n";
3109 %bad_configs = %new_configs;
3110 run_command "mv $bad_config ${bad_config}.last";
3111 save_config \%bad_configs, $bad_config;
3112 %{$pbad} = %bad_configs;
3113 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003114 return 0;
3115 }
3116
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003117 fail "Hmm, need to do a mix match?\n";
3118 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003119}
3120
3121sub config_bisect {
3122 my ($i) = @_;
3123
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003124 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003125 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003126
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003127 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003128
Steven Rostedt30f75da2011-06-13 10:35:35 -04003129 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003130 $good_config = $config_bisect_good;
3131 } elsif (defined($minconfig)) {
3132 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003133 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003134 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003135 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003136 if (!$ret) {
3137 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3138 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003139 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003140 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003141 }
3142
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003143 # we don't want min configs to cause issues here.
3144 doprint "Disabling 'MIN_CONFIG' for this test\n";
3145 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003146
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003147 my %good_configs;
3148 my %bad_configs;
3149 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003150
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003151 doprint "Run good configs through make oldconfig\n";
3152 assign_configs \%tmp_configs, $good_config;
3153 create_config "$good_config", \%tmp_configs;
3154 assign_configs \%good_configs, $output_config;
3155
3156 doprint "Run bad configs through make oldconfig\n";
3157 assign_configs \%tmp_configs, $bad_config;
3158 create_config "$bad_config", \%tmp_configs;
3159 assign_configs \%bad_configs, $output_config;
3160
3161 $good_config = "$tmpdir/good_config";
3162 $bad_config = "$tmpdir/bad_config";
3163
3164 save_config \%good_configs, $good_config;
3165 save_config \%bad_configs, $bad_config;
3166
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003167
3168 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3169 if ($config_bisect_check ne "good") {
3170 doprint "Testing bad config\n";
3171
3172 $ret = run_bisect_test $type, "useconfig:$bad_config";
3173 if ($ret) {
3174 fail "Bad config succeeded when expected to fail!";
3175 return 0;
3176 }
3177 }
3178 if ($config_bisect_check ne "bad") {
3179 doprint "Testing good config\n";
3180
3181 $ret = run_bisect_test $type, "useconfig:$good_config";
3182 if (!$ret) {
3183 fail "Good config failed when expected to succeed!";
3184 return 0;
3185 }
3186 }
3187 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003188
Steven Rostedt0a05c762010-11-08 11:14:10 -05003189 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003190 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003191 } while (!$ret);
3192
3193 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003194
3195 success $i;
3196}
3197
Steven Rostedt27d934b2011-05-20 09:18:18 -04003198sub patchcheck_reboot {
3199 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003200 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003201}
3202
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003203sub patchcheck {
3204 my ($i) = @_;
3205
3206 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003207 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003208 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003209 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003210
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003211 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003212
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003213 my $cherry = $patchcheck_cherry;
3214 if (!defined($cherry)) {
3215 $cherry = 0;
3216 }
3217
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003218 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003219 if (defined($patchcheck_end)) {
3220 $end = $patchcheck_end;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003221 } elsif ($cherry) {
3222 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003223 }
3224
Steven Rostedta57419b2010-11-02 15:13:54 -04003225 # Get the true sha1's since we can use things like HEAD~3
3226 $start = get_sha1($start);
3227 $end = get_sha1($end);
3228
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003229 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003230
3231 # Can't have a test without having a test to run
3232 if ($type eq "test" && !defined($run_test)) {
3233 $type = "boot";
3234 }
3235
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003236 if ($cherry) {
3237 open (IN, "git cherry -v $start $end|") or
3238 dodie "could not get git list";
3239 } else {
3240 open (IN, "git log --pretty=oneline $end|") or
3241 dodie "could not get git list";
3242 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003243
3244 my @list;
3245
3246 while (<IN>) {
3247 chomp;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003248 # git cherry adds a '+' we want to remove
3249 s/^\+ //;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003250 $list[$#list+1] = $_;
3251 last if (/^$start/);
3252 }
3253 close(IN);
3254
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003255 if (!$cherry) {
3256 if ($list[$#list] !~ /^$start/) {
3257 fail "SHA1 $start not found";
3258 }
3259
3260 # go backwards in the list
3261 @list = reverse @list;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003262 }
3263
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003264 doprint("Going to test the following commits:\n");
3265 foreach my $l (@list) {
3266 doprint "$l\n";
3267 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003268
3269 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003270 my %ignored_warnings;
3271
3272 if (defined($ignore_warnings)) {
3273 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3274 $ignored_warnings{$sha1} = 1;
3275 }
3276 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003277
3278 $in_patchcheck = 1;
3279 foreach my $item (@list) {
3280 my $sha1 = $item;
3281 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3282
3283 doprint "\nProcessing commit $item\n\n";
3284
3285 run_command "git checkout $sha1" or
3286 die "Failed to checkout $sha1";
3287
3288 # only clean on the first and last patch
3289 if ($item eq $list[0] ||
3290 $item eq $list[$#list]) {
3291 $noclean = $save_clean;
3292 } else {
3293 $noclean = 1;
3294 }
3295
3296 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003297 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003298 } else {
3299 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003300 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003301 }
3302
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003303 # No need to do per patch checking if warnings file exists
3304 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3305 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003306 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003307
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003308 check_buildlog or return 0;
3309
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003310 next if ($type eq "build");
3311
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003312 my $failed = 0;
3313
Steven Rostedtddf607e2011-06-14 20:49:13 -04003314 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003315
3316 if (!$failed && $type ne "boot"){
3317 do_run_test or $failed = 1;
3318 }
3319 end_monitor;
3320 return 0 if ($failed);
3321
Steven Rostedt27d934b2011-05-20 09:18:18 -04003322 patchcheck_reboot;
3323
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003324 }
3325 $in_patchcheck = 0;
3326 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003327
3328 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003329}
3330
Steven Rostedtb9066f62011-07-15 21:25:24 -04003331my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003332my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003333my $iflevel = 0;
3334my @ifdeps;
3335
3336# prevent recursion
3337my %read_kconfigs;
3338
Steven Rostedtac6974c2011-10-04 09:40:17 -04003339sub add_dep {
3340 # $config depends on $dep
3341 my ($config, $dep) = @_;
3342
3343 if (defined($depends{$config})) {
3344 $depends{$config} .= " " . $dep;
3345 } else {
3346 $depends{$config} = $dep;
3347 }
3348
3349 # record the number of configs depending on $dep
3350 if (defined $depcount{$dep}) {
3351 $depcount{$dep}++;
3352 } else {
3353 $depcount{$dep} = 1;
3354 }
3355}
3356
Steven Rostedtb9066f62011-07-15 21:25:24 -04003357# taken from streamline_config.pl
3358sub read_kconfig {
3359 my ($kconfig) = @_;
3360
3361 my $state = "NONE";
3362 my $config;
3363 my @kconfigs;
3364
3365 my $cont = 0;
3366 my $line;
3367
3368
3369 if (! -f $kconfig) {
3370 doprint "file $kconfig does not exist, skipping\n";
3371 return;
3372 }
3373
3374 open(KIN, "$kconfig")
3375 or die "Can't open $kconfig";
3376 while (<KIN>) {
3377 chomp;
3378
3379 # Make sure that lines ending with \ continue
3380 if ($cont) {
3381 $_ = $line . " " . $_;
3382 }
3383
3384 if (s/\\$//) {
3385 $cont = 1;
3386 $line = $_;
3387 next;
3388 }
3389
3390 $cont = 0;
3391
3392 # collect any Kconfig sources
3393 if (/^source\s*"(.*)"/) {
3394 $kconfigs[$#kconfigs+1] = $1;
3395 }
3396
3397 # configs found
3398 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3399 $state = "NEW";
3400 $config = $2;
3401
3402 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003403 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003404 }
3405
3406 # collect the depends for the config
3407 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3408
Steven Rostedtac6974c2011-10-04 09:40:17 -04003409 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003410
3411 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003412 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3413
3414 # selected by depends on config
3415 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003416
3417 # Check for if statements
3418 } elsif (/^if\s+(.*\S)\s*$/) {
3419 my $deps = $1;
3420 # remove beginning and ending non text
3421 $deps =~ s/^[^a-zA-Z0-9_]*//;
3422 $deps =~ s/[^a-zA-Z0-9_]*$//;
3423
3424 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3425
3426 $ifdeps[$iflevel++] = join ':', @deps;
3427
3428 } elsif (/^endif/) {
3429
3430 $iflevel-- if ($iflevel);
3431
3432 # stop on "help"
3433 } elsif (/^\s*help\s*$/) {
3434 $state = "NONE";
3435 }
3436 }
3437 close(KIN);
3438
3439 # read in any configs that were found.
3440 foreach $kconfig (@kconfigs) {
3441 if (!defined($read_kconfigs{$kconfig})) {
3442 $read_kconfigs{$kconfig} = 1;
3443 read_kconfig("$builddir/$kconfig");
3444 }
3445 }
3446}
3447
3448sub read_depends {
3449 # find out which arch this is by the kconfig file
3450 open (IN, $output_config)
3451 or dodie "Failed to read $output_config";
3452 my $arch;
3453 while (<IN>) {
3454 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3455 $arch = $1;
3456 last;
3457 }
3458 }
3459 close IN;
3460
3461 if (!defined($arch)) {
3462 doprint "Could not find arch from config file\n";
3463 doprint "no dependencies used\n";
3464 return;
3465 }
3466
3467 # arch is really the subarch, we need to know
3468 # what directory to look at.
3469 if ($arch eq "i386" || $arch eq "x86_64") {
3470 $arch = "x86";
3471 } elsif ($arch =~ /^tile/) {
3472 $arch = "tile";
3473 }
3474
3475 my $kconfig = "$builddir/arch/$arch/Kconfig";
3476
3477 if (! -f $kconfig && $arch =~ /\d$/) {
3478 my $orig = $arch;
3479 # some subarchs have numbers, truncate them
3480 $arch =~ s/\d*$//;
3481 $kconfig = "$builddir/arch/$arch/Kconfig";
3482 if (! -f $kconfig) {
3483 doprint "No idea what arch dir $orig is for\n";
3484 doprint "no dependencies used\n";
3485 return;
3486 }
3487 }
3488
3489 read_kconfig($kconfig);
3490}
3491
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003492sub make_new_config {
3493 my @configs = @_;
3494
3495 open (OUT, ">$output_config")
3496 or dodie "Failed to write $output_config";
3497
3498 foreach my $config (@configs) {
3499 print OUT "$config\n";
3500 }
3501 close OUT;
3502}
3503
Steven Rostedtac6974c2011-10-04 09:40:17 -04003504sub chomp_config {
3505 my ($config) = @_;
3506
3507 $config =~ s/CONFIG_//;
3508
3509 return $config;
3510}
3511
Steven Rostedtb9066f62011-07-15 21:25:24 -04003512sub get_depends {
3513 my ($dep) = @_;
3514
Steven Rostedtac6974c2011-10-04 09:40:17 -04003515 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003516
3517 $dep = $depends{"$kconfig"};
3518
3519 # the dep string we have saves the dependencies as they
3520 # were found, including expressions like ! && ||. We
3521 # want to split this out into just an array of configs.
3522
3523 my $valid = "A-Za-z_0-9";
3524
3525 my @configs;
3526
3527 while ($dep =~ /[$valid]/) {
3528
3529 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3530 my $conf = "CONFIG_" . $1;
3531
3532 $configs[$#configs + 1] = $conf;
3533
3534 $dep =~ s/^[^$valid]*[$valid]+//;
3535 } else {
3536 die "this should never happen";
3537 }
3538 }
3539
3540 return @configs;
3541}
3542
3543my %min_configs;
3544my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003545my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003546my %processed_configs;
3547my %nochange_config;
3548
3549sub test_this_config {
3550 my ($config) = @_;
3551
3552 my $found;
3553
3554 # if we already processed this config, skip it
3555 if (defined($processed_configs{$config})) {
3556 return undef;
3557 }
3558 $processed_configs{$config} = 1;
3559
3560 # if this config failed during this round, skip it
3561 if (defined($nochange_config{$config})) {
3562 return undef;
3563 }
3564
Steven Rostedtac6974c2011-10-04 09:40:17 -04003565 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003566
3567 # Test dependencies first
3568 if (defined($depends{"$kconfig"})) {
3569 my @parents = get_depends $config;
3570 foreach my $parent (@parents) {
3571 # if the parent is in the min config, check it first
3572 next if (!defined($min_configs{$parent}));
3573 $found = test_this_config($parent);
3574 if (defined($found)) {
3575 return $found;
3576 }
3577 }
3578 }
3579
3580 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003581 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003582 # .config to make sure it is missing the config that
3583 # we had before
3584 my %configs = %min_configs;
3585 delete $configs{$config};
3586 make_new_config ((values %configs), (values %keep_configs));
3587 make_oldconfig;
3588 undef %configs;
3589 assign_configs \%configs, $output_config;
3590
Steven Rostedt (Red Hat)9972fc02014-10-22 10:11:47 -04003591 if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
3592 return $config;
3593 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003594
3595 doprint "disabling config $config did not change .config\n";
3596
3597 $nochange_config{$config} = 1;
3598
3599 return undef;
3600}
3601
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003602sub make_min_config {
3603 my ($i) = @_;
3604
Steven Rostedtccc513b2012-05-21 17:13:40 -04003605 my $type = $minconfig_type;
3606 if ($type ne "boot" && $type ne "test") {
3607 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3608 " make_min_config works only with 'boot' and 'test'\n" and return;
3609 }
3610
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003611 if (!defined($output_minconfig)) {
3612 fail "OUTPUT_MIN_CONFIG not defined" and return;
3613 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003614
3615 # If output_minconfig exists, and the start_minconfig
3616 # came from min_config, than ask if we should use
3617 # that instead.
3618 if (-f $output_minconfig && !$start_minconfig_defined) {
3619 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003620 if (!defined($use_output_minconfig)) {
3621 if (read_yn " Use it as minconfig?") {
3622 $start_minconfig = $output_minconfig;
3623 }
3624 } elsif ($use_output_minconfig > 0) {
3625 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003626 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003627 } else {
3628 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003629 }
3630 }
3631
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003632 if (!defined($start_minconfig)) {
3633 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3634 }
3635
Steven Rostedt35ce5952011-07-15 21:57:25 -04003636 my $temp_config = "$tmpdir/temp_config";
3637
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003638 # First things first. We build an allnoconfig to find
3639 # out what the defaults are that we can't touch.
3640 # Some are selections, but we really can't handle selections.
3641
3642 my $save_minconfig = $minconfig;
3643 undef $minconfig;
3644
3645 run_command "$make allnoconfig" or return 0;
3646
Steven Rostedtb9066f62011-07-15 21:25:24 -04003647 read_depends;
3648
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003649 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003650
Steven Rostedt43d1b652011-07-15 22:01:56 -04003651 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003652 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003653
3654 if (defined($ignore_config)) {
3655 # make sure the file exists
3656 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003657 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003658 }
3659
Steven Rostedt43d1b652011-07-15 22:01:56 -04003660 %keep_configs = %save_configs;
3661
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003662 doprint "Load initial configs from $start_minconfig\n";
3663
3664 # Look at the current min configs, and save off all the
3665 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003666 assign_configs \%min_configs, $start_minconfig;
3667
3668 my @config_keys = keys %min_configs;
3669
Steven Rostedtac6974c2011-10-04 09:40:17 -04003670 # All configs need a depcount
3671 foreach my $config (@config_keys) {
3672 my $kconfig = chomp_config $config;
3673 if (!defined $depcount{$kconfig}) {
3674 $depcount{$kconfig} = 0;
3675 }
3676 }
3677
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003678 # Remove anything that was set by the make allnoconfig
3679 # we shouldn't need them as they get set for us anyway.
3680 foreach my $config (@config_keys) {
3681 # Remove anything in the ignore_config
3682 if (defined($keep_configs{$config})) {
3683 my $file = $ignore_config;
3684 $file =~ s,.*/(.*?)$,$1,;
3685 doprint "$config set by $file ... ignored\n";
3686 delete $min_configs{$config};
3687 next;
3688 }
3689 # But make sure the settings are the same. If a min config
3690 # sets a selection, we do not want to get rid of it if
3691 # it is not the same as what we have. Just move it into
3692 # the keep configs.
3693 if (defined($config_ignore{$config})) {
3694 if ($config_ignore{$config} ne $min_configs{$config}) {
3695 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3696 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3697 $keep_configs{$config} = $min_configs{$config};
3698 } else {
3699 doprint "$config set by allnoconfig ... ignored\n";
3700 }
3701 delete $min_configs{$config};
3702 }
3703 }
3704
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003705 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003706 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003707
3708 while (!$done) {
3709
3710 my $config;
3711 my $found;
3712
3713 # Now disable each config one by one and do a make oldconfig
3714 # till we find a config that changes our list.
3715
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003716 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003717
3718 # Sort keys by who is most dependent on
3719 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3720 @test_configs ;
3721
3722 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003723 my $reset = 1;
3724 for (my $i = 0; $i < $#test_configs; $i++) {
3725 if (!defined($nochange_config{$test_configs[0]})) {
3726 $reset = 0;
3727 last;
3728 }
3729 # This config didn't change the .config last time.
3730 # Place it at the end
3731 my $config = shift @test_configs;
3732 push @test_configs, $config;
3733 }
3734
3735 # if every test config has failed to modify the .config file
3736 # in the past, then reset and start over.
3737 if ($reset) {
3738 undef %nochange_config;
3739 }
3740
Steven Rostedtb9066f62011-07-15 21:25:24 -04003741 undef %processed_configs;
3742
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003743 foreach my $config (@test_configs) {
3744
Steven Rostedtb9066f62011-07-15 21:25:24 -04003745 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003746
Steven Rostedtb9066f62011-07-15 21:25:24 -04003747 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003748
3749 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003750 }
3751
3752 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003753 # we could have failed due to the nochange_config hash
3754 # reset and try again
3755 if (!$take_two) {
3756 undef %nochange_config;
3757 $take_two = 1;
3758 next;
3759 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003760 doprint "No more configs found that we can disable\n";
3761 $done = 1;
3762 last;
3763 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003764 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003765
3766 $config = $found;
3767
3768 doprint "Test with $config disabled\n";
3769
3770 # set in_bisect to keep build and monitor from dieing
3771 $in_bisect = 1;
3772
3773 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003774 build "oldconfig" or $failed = 1;
3775 if (!$failed) {
3776 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003777
3778 if ($type eq "test" && !$failed) {
3779 do_run_test or $failed = 1;
3780 }
3781
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003782 end_monitor;
3783 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003784
3785 $in_bisect = 0;
3786
3787 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003788 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003789 # this config is needed, add it to the ignore list.
3790 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003791 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003792 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003793
3794 # update new ignore configs
3795 if (defined($ignore_config)) {
3796 open (OUT, ">$temp_config")
3797 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003798 foreach my $config (keys %save_configs) {
3799 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003800 }
3801 close OUT;
3802 run_command "mv $temp_config $ignore_config" or
3803 dodie "failed to copy update to $ignore_config";
3804 }
3805
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003806 } else {
3807 # We booted without this config, remove it from the minconfigs.
3808 doprint "$config is not needed, disabling\n";
3809
3810 delete $min_configs{$config};
3811
3812 # Also disable anything that is not enabled in this config
3813 my %configs;
3814 assign_configs \%configs, $output_config;
3815 my @config_keys = keys %min_configs;
3816 foreach my $config (@config_keys) {
3817 if (!defined($configs{$config})) {
3818 doprint "$config is not set, disabling\n";
3819 delete $min_configs{$config};
3820 }
3821 }
3822
3823 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003824 open (OUT, ">$temp_config")
3825 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003826 foreach my $config (keys %keep_configs) {
3827 print OUT "$keep_configs{$config}\n";
3828 }
3829 foreach my $config (keys %min_configs) {
3830 print OUT "$min_configs{$config}\n";
3831 }
3832 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003833
3834 run_command "mv $temp_config $output_minconfig" or
3835 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003836 }
3837
3838 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003839 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003840 }
3841
3842 success $i;
3843 return 1;
3844}
3845
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003846sub make_warnings_file {
3847 my ($i) = @_;
3848
3849 if (!defined($warnings_file)) {
3850 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3851 }
3852
3853 if ($build_type eq "nobuild") {
3854 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3855 }
3856
3857 build $build_type or dodie "Failed to build";
3858
3859 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3860
3861 open(IN, $buildlog) or dodie "Can't open $buildlog";
3862 while (<IN>) {
3863
3864 # Some compilers use UTF-8 extended for quotes
3865 # for distcc heterogeneous systems, this causes issues
3866 s/$utf8_quote/'/g;
3867
3868 if (/$check_build_re/) {
3869 print OUT;
3870 }
3871 }
3872 close(IN);
3873
3874 close(OUT);
3875
3876 success $i;
3877}
3878
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09003879$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003880
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003881if ($#ARGV == 0) {
3882 $ktest_config = $ARGV[0];
3883 if (! -f $ktest_config) {
3884 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003885 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003886 exit 0;
3887 }
3888 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003889}
3890
3891if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003892 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003893 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003894 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3895 print OUT << "EOF"
3896# Generated by ktest.pl
3897#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003898
3899# PWD is a ktest.pl variable that will result in the process working
3900# directory that ktest.pl is executed in.
3901
3902# THIS_DIR is automatically assigned the PWD of the path that generated
3903# the config file. It is best to use this variable when assigning other
3904# directory paths within this directory. This allows you to easily
3905# move the test cases to other locations or to other machines.
3906#
3907THIS_DIR := $variable{"PWD"}
3908
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003909# Define each test with TEST_START
3910# The config options below it will override the defaults
3911TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003912TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003913
3914DEFAULTS
3915EOF
3916;
3917 close(OUT);
3918}
3919read_config $ktest_config;
3920
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003921if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003922 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003923}
3924
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003925# Append any configs entered in manually to the config file.
3926my @new_configs = keys %entered_configs;
3927if ($#new_configs >= 0) {
3928 print "\nAppending entered in configs to $ktest_config\n";
3929 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3930 foreach my $config (@new_configs) {
3931 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003932 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003933 }
3934}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003935
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003936if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3937 unlink $opt{"LOG_FILE"};
3938}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003939
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003940doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3941
Steven Rostedta57419b2010-11-02 15:13:54 -04003942for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3943
3944 if (!$i) {
3945 doprint "DEFAULT OPTIONS:\n";
3946 } else {
3947 doprint "\nTEST $i OPTIONS";
3948 if (defined($repeat_tests{$i})) {
3949 $repeat = $repeat_tests{$i};
3950 doprint " ITERATE $repeat";
3951 }
3952 doprint "\n";
3953 }
3954
3955 foreach my $option (sort keys %opt) {
3956
3957 if ($option =~ /\[(\d+)\]$/) {
3958 next if ($i != $1);
3959 } else {
3960 next if ($i);
3961 }
3962
3963 doprint "$option = $opt{$option}\n";
3964 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003965}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003966
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003967sub option_defined {
3968 my ($option) = @_;
3969
3970 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
3971 return 1;
3972 }
3973
3974 return 0;
3975}
3976
Steven Rostedt2a625122011-05-20 15:48:59 -04003977sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003978 my ($name, $i) = @_;
3979
3980 my $option = "$name\[$i\]";
3981
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003982 if (option_defined($option)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003983 return $opt{$option};
3984 }
3985
Steven Rostedta57419b2010-11-02 15:13:54 -04003986 foreach my $test (keys %repeat_tests) {
3987 if ($i >= $test &&
3988 $i < $test + $repeat_tests{$test}) {
3989 $option = "$name\[$test\]";
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003990 if (option_defined($option)) {
Steven Rostedta57419b2010-11-02 15:13:54 -04003991 return $opt{$option};
3992 }
3993 }
3994 }
3995
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003996 if (option_defined($name)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003997 return $opt{$name};
3998 }
3999
4000 return undef;
4001}
4002
Steven Rostedt2a625122011-05-20 15:48:59 -04004003sub set_test_option {
4004 my ($name, $i) = @_;
4005
4006 my $option = __set_test_option($name, $i);
4007 return $option if (!defined($option));
4008
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05004009 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04004010}
4011
Steven Rostedt2545eb62010-11-02 15:01:32 -04004012# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04004013for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04004014
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004015 # Do not reboot on failing test options
4016 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004017 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004018
Steven Rostedt683a3e62012-05-18 13:34:35 -04004019 $have_version = 0;
4020
Steven Rostedt576f6272010-11-02 14:58:38 -04004021 $iteration = $i;
4022
Steven Rostedtc1434dc2012-07-20 22:39:16 -04004023 undef %force_config;
4024
Steven Rostedta75fece2010-11-02 14:58:27 -04004025 my $makecmd = set_test_option("MAKE_CMD", $i);
4026
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004027 $outputdir = set_test_option("OUTPUT_DIR", $i);
4028 $builddir = set_test_option("BUILD_DIR", $i);
4029
4030 chdir $builddir || die "can't change directory to $builddir";
4031
4032 if (!-d $outputdir) {
4033 mkpath($outputdir) or
4034 die "can't create $outputdir";
4035 }
4036
4037 $make = "$makecmd O=$outputdir";
4038
Steven Rostedt9cc9e092011-12-22 21:37:22 -05004039 # Load all the options into their mapped variable names
4040 foreach my $opt (keys %option_map) {
4041 ${$option_map{$opt}} = set_test_option($opt, $i);
4042 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004043
Steven Rostedt35ce5952011-07-15 21:57:25 -04004044 $start_minconfig_defined = 1;
4045
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004046 # The first test may override the PRE_KTEST option
4047 if (defined($pre_ktest) && $i == 1) {
4048 doprint "\n";
4049 run_command $pre_ktest;
4050 }
4051
4052 # Any test can override the POST_KTEST option
4053 # The last test takes precedence.
4054 if (defined($post_ktest)) {
4055 $final_post_ktest = $post_ktest;
4056 }
4057
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004058 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004059 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004060 $start_minconfig = $minconfig;
4061 }
4062
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004063 if (!-d $tmpdir) {
4064 mkpath($tmpdir) or
4065 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004066 }
4067
Steven Rostedte48c5292010-11-02 14:35:37 -04004068 $ENV{"SSH_USER"} = $ssh_user;
4069 $ENV{"MACHINE"} = $machine;
4070
Steven Rostedta75fece2010-11-02 14:58:27 -04004071 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304072 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004073 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004074 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004075
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004076 if (!$buildonly) {
4077 $target = "$ssh_user\@$machine";
4078 if ($reboot_type eq "grub") {
4079 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004080 } elsif ($reboot_type eq "grub2") {
4081 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4082 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004083 } elsif ($reboot_type eq "syslinux") {
4084 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004085 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004086 }
4087
4088 my $run_type = $build_type;
4089 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004090 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004091 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004092 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004093 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004094 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004095 } elsif ($test_type eq "make_min_config") {
4096 $run_type = "";
4097 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004098 $run_type = "";
4099 }
4100
Steven Rostedta75fece2010-11-02 14:58:27 -04004101 # mistake in config file?
4102 if (!defined($run_type)) {
4103 $run_type = "ERROR";
4104 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004105
Steven Rostedte0a87422011-09-30 17:50:48 -04004106 my $installme = "";
4107 $installme = " no_install" if ($no_install);
4108
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004109 my $name = "";
4110
4111 if (defined($test_name)) {
4112 $name = " ($test_name)";
4113 }
4114
Steven Rostedt2545eb62010-11-02 15:01:32 -04004115 doprint "\n\n";
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004116 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 -04004117
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004118 if (defined($pre_test)) {
4119 run_command $pre_test;
4120 }
4121
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004122 unlink $dmesg;
4123 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304124 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004125
Steven Rostedt250bae82011-07-15 22:05:59 -04004126 if (defined($addconfig)) {
4127 my $min = $minconfig;
4128 if (!defined($minconfig)) {
4129 $min = "";
4130 }
4131 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004132 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004133 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004134 }
4135
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004136 if (defined($checkout)) {
4137 run_command "git checkout $checkout" or
4138 die "failed to checkout $checkout";
4139 }
4140
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004141 $no_reboot = 0;
4142
Steven Rostedt648a1822012-03-21 11:18:27 -04004143 # A test may opt to not reboot the box
4144 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004145 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004146 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004147
Steven Rostedta75fece2010-11-02 14:58:27 -04004148 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004149 bisect $i;
4150 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004151 } elsif ($test_type eq "config_bisect") {
4152 config_bisect $i;
4153 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004154 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004155 patchcheck $i;
4156 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004157 } elsif ($test_type eq "make_min_config") {
4158 make_min_config $i;
4159 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004160 } elsif ($test_type eq "make_warnings_file") {
4161 $no_reboot = 1;
4162 make_warnings_file $i;
4163 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004164 }
4165
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004166 if ($build_type ne "nobuild") {
4167 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004168 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004169 }
4170
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004171 if ($test_type eq "install") {
4172 get_version;
4173 install;
4174 success $i;
4175 next;
4176 }
4177
Steven Rostedta75fece2010-11-02 14:58:27 -04004178 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004179 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004180 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004181
4182 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4183 do_run_test or $failed = 1;
4184 }
4185 end_monitor;
4186 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004187 }
4188
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004189 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004190}
4191
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004192if (defined($final_post_ktest)) {
4193 run_command $final_post_ktest;
4194}
4195
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004196if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004197 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004198} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004199 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004200} elsif (defined($switch_to_good)) {
4201 # still need to get to the good kernel
4202 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004203}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004204
Steven Rostedt648a1822012-03-21 11:18:27 -04004205
Steven Rostedte48c5292010-11-02 14:35:37 -04004206doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4207
Steven Rostedt2545eb62010-11-02 15:01:32 -04004208exit 0;