blob: 27273c228d92a723256fef6addc64ff1a066a1e5 [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;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400181
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500182my $bisect_good;
183my $bisect_bad;
184my $bisect_type;
185my $bisect_start;
186my $bisect_replay;
187my $bisect_files;
188my $bisect_reverse;
189my $bisect_check;
190
191my $config_bisect;
192my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400193my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500194
195my $patchcheck_type;
196my $patchcheck_start;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -0400197my $patchcheck_cherry;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500198my $patchcheck_end;
199
Steven Rostedt165708b2011-11-26 20:56:52 -0500200# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500201# which would require more options.
202my $buildonly = 1;
203
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500204# tell build not to worry about warnings, even when WARNINGS_FILE is set
205my $warnings_ok = 0;
206
Steven Rostedtdbd37832011-11-23 16:00:48 -0500207# set when creating a new config
208my $newconfig = 0;
209
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500210my %entered_configs;
211my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400212my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400213
214# force_config is the list of configs that we force enabled (or disabled)
215# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400216my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500217
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400218# do not force reboots on config problems
219my $no_reboot = 1;
220
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400221# reboot on success
222my $reboot_success = 0;
223
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500224my %option_map = (
225 "MACHINE" => \$machine,
226 "SSH_USER" => \$ssh_user,
227 "TMP_DIR" => \$tmpdir,
228 "OUTPUT_DIR" => \$outputdir,
229 "BUILD_DIR" => \$builddir,
230 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400231 "PRE_KTEST" => \$pre_ktest,
232 "POST_KTEST" => \$post_ktest,
233 "PRE_TEST" => \$pre_test,
234 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500235 "BUILD_TYPE" => \$build_type,
236 "BUILD_OPTIONS" => \$build_options,
237 "PRE_BUILD" => \$pre_build,
238 "POST_BUILD" => \$post_build,
239 "PRE_BUILD_DIE" => \$pre_build_die,
240 "POST_BUILD_DIE" => \$post_build_die,
241 "POWER_CYCLE" => \$power_cycle,
242 "REBOOT" => \$reboot,
243 "BUILD_NOCLEAN" => \$noclean,
244 "MIN_CONFIG" => \$minconfig,
245 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
246 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400247 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400248 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500249 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500250 "IGNORE_CONFIG" => \$ignore_config,
251 "TEST" => \$run_test,
252 "ADD_CONFIG" => \$addconfig,
253 "REBOOT_TYPE" => \$reboot_type,
254 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500255 "GRUB_FILE" => \$grub_file,
256 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500257 "SYSLINUX" => \$syslinux,
258 "SYSLINUX_PATH" => \$syslinux_path,
259 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400260 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500261 "POST_INSTALL" => \$post_install,
262 "NO_INSTALL" => \$no_install,
263 "REBOOT_SCRIPT" => \$reboot_script,
264 "REBOOT_ON_ERROR" => \$reboot_on_error,
265 "SWITCH_TO_GOOD" => \$switch_to_good,
266 "SWITCH_TO_TEST" => \$switch_to_test,
267 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400268 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500269 "DIE_ON_FAILURE" => \$die_on_failure,
270 "POWER_OFF" => \$power_off,
271 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
272 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400273 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500274 "SLEEP_TIME" => \$sleep_time,
275 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
276 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
277 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500278 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500279 "BISECT_MANUAL" => \$bisect_manual,
280 "BISECT_SKIP" => \$bisect_skip,
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -0500281 "BISECT_TRIES" => \$bisect_tries,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500282 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
283 "BISECT_RET_GOOD" => \$bisect_ret_good,
284 "BISECT_RET_BAD" => \$bisect_ret_bad,
285 "BISECT_RET_SKIP" => \$bisect_ret_skip,
286 "BISECT_RET_ABORT" => \$bisect_ret_abort,
287 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
288 "STORE_FAILURES" => \$store_failures,
289 "STORE_SUCCESSES" => \$store_successes,
290 "TEST_NAME" => \$test_name,
291 "TIMEOUT" => \$timeout,
292 "BOOTED_TIMEOUT" => \$booted_timeout,
293 "CONSOLE" => \$console,
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900294 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500295 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
296 "SUCCESS_LINE" => \$success_line,
297 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
298 "STOP_AFTER_SUCCESS" => \$stop_after_success,
299 "STOP_AFTER_FAILURE" => \$stop_after_failure,
300 "STOP_TEST_AFTER" => \$stop_test_after,
301 "BUILD_TARGET" => \$build_target,
302 "SSH_EXEC" => \$ssh_exec,
303 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400304 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500305 "CHECKOUT" => \$checkout,
306 "TARGET_IMAGE" => \$target_image,
307 "LOCALVERSION" => \$localversion,
308
309 "BISECT_GOOD" => \$bisect_good,
310 "BISECT_BAD" => \$bisect_bad,
311 "BISECT_TYPE" => \$bisect_type,
312 "BISECT_START" => \$bisect_start,
313 "BISECT_REPLAY" => \$bisect_replay,
314 "BISECT_FILES" => \$bisect_files,
315 "BISECT_REVERSE" => \$bisect_reverse,
316 "BISECT_CHECK" => \$bisect_check,
317
318 "CONFIG_BISECT" => \$config_bisect,
319 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400320 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500321
322 "PATCHCHECK_TYPE" => \$patchcheck_type,
323 "PATCHCHECK_START" => \$patchcheck_start,
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -0400324 "PATCHCHECK_CHERRY" => \$patchcheck_cherry,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500325 "PATCHCHECK_END" => \$patchcheck_end,
326);
327
328# Options may be used by other options, record them.
329my %used_options;
330
Steven Rostedt7bf51072011-10-22 09:07:03 -0400331# default variables that can be used
332chomp ($variable{"PWD"} = `pwd`);
333
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500334$config_help{"MACHINE"} = << "EOF"
335 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500336 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500337EOF
338 ;
339$config_help{"SSH_USER"} = << "EOF"
340 The box is expected to have ssh on normal bootup, provide the user
341 (most likely root, since you need privileged operations)
342EOF
343 ;
344$config_help{"BUILD_DIR"} = << "EOF"
345 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500346 You can use \${PWD} that will be the path where ktest.pl is run, or use
347 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500348EOF
349 ;
350$config_help{"OUTPUT_DIR"} = << "EOF"
351 The directory that the objects will be built (full path).
352 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500353 You can use \${PWD} that will be the path where ktest.pl is run, or use
354 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500355EOF
356 ;
357$config_help{"BUILD_TARGET"} = << "EOF"
358 The location of the compiled file to copy to the target.
359 (relative to OUTPUT_DIR)
360EOF
361 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500362$config_help{"BUILD_OPTIONS"} = << "EOF"
363 Options to add to \"make\" when building.
364 i.e. -j20
365EOF
366 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500367$config_help{"TARGET_IMAGE"} = << "EOF"
368 The place to put your image on the test machine.
369EOF
370 ;
371$config_help{"POWER_CYCLE"} = << "EOF"
372 A script or command to reboot the box.
373
374 Here is a digital loggers power switch example
375 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
376
377 Here is an example to reboot a virtual box on the current host
378 with the name "Guest".
379 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
380EOF
381 ;
382$config_help{"CONSOLE"} = << "EOF"
383 The script or command that reads the console
384
385 If you use ttywatch server, something like the following would work.
386CONSOLE = nc -d localhost 3001
387
388 For a virtual machine with guest name "Guest".
389CONSOLE = virsh console Guest
390EOF
391 ;
392$config_help{"LOCALVERSION"} = << "EOF"
393 Required version ending to differentiate the test
394 from other linux builds on the system.
395EOF
396 ;
397$config_help{"REBOOT_TYPE"} = << "EOF"
398 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500399 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500400
401 If you specify grub, it will assume grub version 1
402 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
403 and select that target to reboot to the kernel. If this is not
404 your setup, then specify "script" and have a command or script
405 specified in REBOOT_SCRIPT to boot to the target.
406
407 The entry in /boot/grub/menu.lst must be entered in manually.
408 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500409
410 If you specify grub2, then you also need to specify both \$GRUB_MENU
411 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500412
413 If you specify syslinux, then you may use SYSLINUX to define the syslinux
414 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
415 the syslinux install (defaults to /boot/extlinux). But you have to specify
416 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500417EOF
418 ;
419$config_help{"GRUB_MENU"} = << "EOF"
420 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500421 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500422
423 Note, ktest.pl will not update the grub menu.lst, you need to
424 manually add an option for the test. ktest.pl will search
425 the grub menu.lst for this option to find what kernel to
426 reboot into.
427
428 For example, if in the /boot/grub/menu.lst the test kernel title has:
429 title Test Kernel
430 kernel vmlinuz-test
431 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500432
433 For grub2, a search of \$GRUB_FILE is performed for the lines
434 that begin with "menuentry". It will not detect submenus. The
435 menu must be a non-nested menu. Add the quotes used in the menu
436 to guarantee your selection, as the first menuentry with the content
437 of \$GRUB_MENU that is found will be used.
438EOF
439 ;
440$config_help{"GRUB_FILE"} = << "EOF"
441 If grub2 is used, the full path for the grub.cfg file is placed
442 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500443EOF
444 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500445$config_help{"SYSLINUX_LABEL"} = << "EOF"
446 If syslinux is used, the label that boots the target kernel must
447 be specified with SYSLINUX_LABEL.
448EOF
449 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500450$config_help{"REBOOT_SCRIPT"} = << "EOF"
451 A script to reboot the target into the test kernel
452 (Only mandatory if REBOOT_TYPE = script)
453EOF
454 ;
455
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500456sub _logit {
457 if (defined($opt{"LOG_FILE"})) {
458 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
459 print OUT @_;
460 close(OUT);
461 }
462}
463
464sub logit {
465 if (defined($opt{"LOG_FILE"})) {
466 _logit @_;
467 } else {
468 print @_;
469 }
470}
471
472sub doprint {
473 print @_;
474 _logit @_;
475}
476
Steven Rostedtdad98752011-11-22 20:48:57 -0500477sub read_prompt {
478 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400479
480 my $ans;
481
482 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500483 if ($cancel) {
484 print "$prompt [y/n/C] ";
485 } else {
486 print "$prompt [Y/n] ";
487 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400488 $ans = <STDIN>;
489 chomp $ans;
490 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500491 if ($cancel) {
492 $ans = "c";
493 } else {
494 $ans = "y";
495 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400496 }
497 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500498 if ($cancel) {
499 last if ($ans =~ /^c$/i);
500 print "Please answer either 'y', 'n' or 'c'.\n";
501 } else {
502 print "Please answer either 'y' or 'n'.\n";
503 }
504 }
505 if ($ans =~ /^c/i) {
506 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400507 }
508 if ($ans !~ /^y$/i) {
509 return 0;
510 }
511 return 1;
512}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500513
Steven Rostedtdad98752011-11-22 20:48:57 -0500514sub read_yn {
515 my ($prompt) = @_;
516
517 return read_prompt 0, $prompt;
518}
519
520sub read_ync {
521 my ($prompt) = @_;
522
523 return read_prompt 1, $prompt;
524}
525
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900526sub get_mandatory_config {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500527 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400528 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500529
530 return if (defined($opt{$config}));
531
532 if (defined($config_help{$config})) {
533 print "\n";
534 print $config_help{$config};
535 }
536
537 for (;;) {
538 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500539 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500540 print "\[$default{$config}\] ";
541 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400542 $ans = <STDIN>;
543 $ans =~ s/^\s*(.*\S)\s*$/$1/;
544 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500545 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400546 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500547 } else {
548 print "Your answer can not be blank\n";
549 next;
550 }
551 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500552 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500553 last;
554 }
555}
556
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900557sub get_mandatory_configs {
558 get_mandatory_config("MACHINE");
559 get_mandatory_config("BUILD_DIR");
560 get_mandatory_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500561
Steven Rostedtdbd37832011-11-23 16:00:48 -0500562 if ($newconfig) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900563 get_mandatory_config("BUILD_OPTIONS");
Steven Rostedtdbd37832011-11-23 16:00:48 -0500564 }
565
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500566 # options required for other than just building a kernel
567 if (!$buildonly) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900568 get_mandatory_config("POWER_CYCLE");
569 get_mandatory_config("CONSOLE");
Steven Rostedt165708b2011-11-26 20:56:52 -0500570 }
571
572 # options required for install and more
573 if ($buildonly != 1) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900574 get_mandatory_config("SSH_USER");
575 get_mandatory_config("BUILD_TARGET");
576 get_mandatory_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500577 }
578
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900579 get_mandatory_config("LOCALVERSION");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500580
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500581 return if ($buildonly);
582
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500583 my $rtype = $opt{"REBOOT_TYPE"};
584
585 if (!defined($rtype)) {
586 if (!defined($opt{"GRUB_MENU"})) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900587 get_mandatory_config("REBOOT_TYPE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500588 $rtype = $entered_configs{"REBOOT_TYPE"};
589 } else {
590 $rtype = "grub";
591 }
592 }
593
594 if ($rtype eq "grub") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900595 get_mandatory_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500596 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500597
598 if ($rtype eq "grub2") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900599 get_mandatory_config("GRUB_MENU");
600 get_mandatory_config("GRUB_FILE");
Steven Rostedta15ba912012-11-13 14:30:37 -0500601 }
Steven Rostedt77869542012-12-11 17:37:41 -0500602
603 if ($rtype eq "syslinux") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900604 get_mandatory_config("SYSLINUX_LABEL");
Steven Rostedt77869542012-12-11 17:37:41 -0500605 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500606}
607
Steven Rostedt77d942c2011-05-20 13:36:58 -0400608sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400609 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400610 my $retval = "";
611
612 # We want to check for '\', and it is just easier
613 # to check the previous characet of '$' and not need
614 # to worry if '$' is the first character. By adding
615 # a space to $value, we can just check [^\\]\$ and
616 # it will still work.
617 $value = " $value";
618
619 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
620 my $begin = $1;
621 my $var = $2;
622 my $end = $3;
623 # append beginning of value to retval
624 $retval = "$retval$begin";
625 if (defined($variable{$var})) {
626 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400627 } elsif (defined($remove_undef) && $remove_undef) {
628 # for if statements, any variable that is not defined,
629 # we simple convert to 0
630 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400631 } else {
632 # put back the origin piece.
633 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500634 # This could be an option that is used later, save
635 # it so we don't warn if this option is not one of
636 # ktests options.
637 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400638 }
639 $value = $end;
640 }
641 $retval = "$retval$value";
642
643 # remove the space added in the beginning
644 $retval =~ s/ //;
645
646 return "$retval"
647}
648
Steven Rostedta57419b2010-11-02 15:13:54 -0400649sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400650 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400651
Steven Rostedtcad96662011-12-22 11:32:52 -0500652 my $prvalue = process_variables($rvalue);
653
654 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500655 # Note if a test is something other than build, then we
656 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500657 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500658 # for bisect, we need to check BISECT_TYPE
659 if ($prvalue ne "bisect") {
660 $buildonly = 0;
661 }
662 } else {
663 # install still limits some manditory options.
664 $buildonly = 2;
665 }
666 }
667
668 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
669 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500670 $buildonly = 0;
671 } else {
672 # install still limits some manditory options.
673 $buildonly = 2;
674 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500675 }
676
Steven Rostedta57419b2010-11-02 15:13:54 -0400677 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400678 if (!$override || defined(${$overrides}{$lvalue})) {
679 my $extra = "";
680 if ($override) {
681 $extra = "In the same override section!\n";
682 }
683 die "$name: $.: Option $lvalue defined more than once!\n$extra";
684 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500685 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400686 }
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -0500687
688 $opt{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400689}
690
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500691sub set_eval {
692 my ($lvalue, $rvalue, $name) = @_;
693
694 my $prvalue = process_variables($rvalue);
695 my $arr;
696
697 if (defined($evals{$lvalue})) {
698 $arr = $evals{$lvalue};
699 } else {
700 $arr = [];
701 $evals{$lvalue} = $arr;
702 }
703
704 push @{$arr}, $rvalue;
705}
706
Steven Rostedt77d942c2011-05-20 13:36:58 -0400707sub set_variable {
708 my ($lvalue, $rvalue) = @_;
709
710 if ($rvalue =~ /^\s*$/) {
711 delete $variable{$lvalue};
712 } else {
713 $rvalue = process_variables($rvalue);
714 $variable{$lvalue} = $rvalue;
715 }
716}
717
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400718sub process_compare {
719 my ($lval, $cmp, $rval) = @_;
720
721 # remove whitespace
722
723 $lval =~ s/^\s*//;
724 $lval =~ s/\s*$//;
725
726 $rval =~ s/^\s*//;
727 $rval =~ s/\s*$//;
728
729 if ($cmp eq "==") {
730 return $lval eq $rval;
731 } elsif ($cmp eq "!=") {
732 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400733 } elsif ($cmp eq "=~") {
734 return $lval =~ m/$rval/;
735 } elsif ($cmp eq "!~") {
736 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400737 }
738
739 my $statement = "$lval $cmp $rval";
740 my $ret = eval $statement;
741
742 # $@ stores error of eval
743 if ($@) {
744 return -1;
745 }
746
747 return $ret;
748}
749
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400750sub value_defined {
751 my ($val) = @_;
752
753 return defined($variable{$2}) ||
754 defined($opt{$2});
755}
756
Steven Rostedt8d735212011-10-17 11:36:44 -0400757my $d = 0;
758sub process_expression {
759 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400760
Steven Rostedt8d735212011-10-17 11:36:44 -0400761 my $c = $d++;
762
763 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
764 my $express = $1;
765
766 if (process_expression($name, $express)) {
767 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
768 } else {
769 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
770 }
771 }
772
773 $d--;
774 my $OR = "\\|\\|";
775 my $AND = "\\&\\&";
776
777 while ($val =~ s/^(.*?)($OR|$AND)//) {
778 my $express = $1;
779 my $op = $2;
780
781 if (process_expression($name, $express)) {
782 if ($op eq "||") {
783 return 1;
784 }
785 } else {
786 if ($op eq "&&") {
787 return 0;
788 }
789 }
790 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400791
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400792 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400793 my $ret = process_compare($1, $2, $3);
794 if ($ret < 0) {
795 die "$name: $.: Unable to process comparison\n";
796 }
797 return $ret;
798 }
799
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400800 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
801 if (defined $1) {
802 return !value_defined($2);
803 } else {
804 return value_defined($2);
805 }
806 }
807
Steven Rostedt45d73a52011-09-30 19:44:53 -0400808 if ($val =~ /^\s*0\s*$/) {
809 return 0;
810 } elsif ($val =~ /^\s*\d+\s*$/) {
811 return 1;
812 }
813
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400814 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400815}
816
817sub process_if {
818 my ($name, $value) = @_;
819
820 # Convert variables and replace undefined ones with 0
821 my $val = process_variables($value, 1);
822 my $ret = process_expression $name, $val;
823
824 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400825}
826
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400827sub __read_config {
828 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400829
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400830 my $in;
831 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400832
Steven Rostedta57419b2010-11-02 15:13:54 -0400833 my $name = $config;
834 $name =~ s,.*/(.*),$1,;
835
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400836 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400837 my $default = 1;
838 my $repeat = 1;
839 my $num_tests_set = 0;
840 my $skip = 0;
841 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400842 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400843 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400844 my $if = 0;
845 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400846 my $override = 0;
847
848 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400849
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400850 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400851
852 # ignore blank lines and comments
853 next if (/^\s*$/ || /\s*\#/);
854
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400855 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400856
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400857 my $type = $1;
858 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400859 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400860
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400861 my $old_test_num;
862 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400863 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400864
865 if ($type eq "TEST_START") {
866
867 if ($num_tests_set) {
868 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
869 }
870
871 $old_test_num = $test_num;
872 $old_repeat = $repeat;
873
874 $test_num += $repeat;
875 $default = 0;
876 $repeat = 1;
877 } else {
878 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400879 }
880
Steven Rostedta9f84422011-10-17 11:06:29 -0400881 # If SKIP is anywhere in the line, the command will be skipped
882 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400883 $skip = 1;
884 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400885 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400886 $skip = 0;
887 }
888
Steven Rostedta9f84422011-10-17 11:06:29 -0400889 if ($rest =~ s/\sELSE\b//) {
890 if (!$if) {
891 die "$name: $.: ELSE found with out matching IF section\n$_";
892 }
893 $if = 0;
894
895 if ($if_set) {
896 $skip = 1;
897 } else {
898 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400899 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400900 }
901
Steven Rostedta9f84422011-10-17 11:06:29 -0400902 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400903 if (process_if($name, $1)) {
904 $if_set = 1;
905 } else {
906 $skip = 1;
907 }
908 $if = 1;
909 } else {
910 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400911 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400912 }
913
Steven Rostedta9f84422011-10-17 11:06:29 -0400914 if (!$skip) {
915 if ($type eq "TEST_START") {
916 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
917 $repeat = $1;
918 $repeat_tests{"$test_num"} = $repeat;
919 }
920 } elsif ($rest =~ s/\sOVERRIDE\b//) {
921 # DEFAULT only
922 $override = 1;
923 # Clear previous overrides
924 %overrides = ();
925 }
926 }
927
928 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400929 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400930 }
931
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400932 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400933 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400934 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400935 }
936
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400937 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400938 if (!$if) {
939 die "$name: $.: ELSE found with out matching IF section\n$_";
940 }
941 $rest = $1;
942 if ($if_set) {
943 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400944 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400945 } else {
946 $skip = 0;
947
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400948 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400949 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400950 if (process_if($name, $1)) {
951 $if_set = 1;
952 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400953 $skip = 1;
954 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400955 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400956 } else {
957 $if = 0;
958 }
959 }
960
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400961 if ($rest !~ /^\s*$/) {
962 die "$name: $.: Gargbage found after DEFAULTS\n$_";
963 }
964
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400965 } elsif (/^\s*INCLUDE\s+(\S+)/) {
966
967 next if ($skip);
968
969 if (!$default) {
970 die "$name: $.: INCLUDE can only be done in default sections\n$_";
971 }
972
973 my $file = process_variables($1);
974
975 if ($file !~ m,^/,) {
976 # check the path of the config file first
977 if ($config =~ m,(.*)/,) {
978 if (-f "$1/$file") {
979 $file = "$1/$file";
980 }
981 }
982 }
983
984 if ( ! -r $file ) {
985 die "$name: $.: Can't read file $file\n$_";
986 }
987
988 if (__read_config($file, \$test_num)) {
989 $test_case = 1;
990 }
991
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500992 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
993
994 next if ($skip);
995
996 my $lvalue = $1;
997 my $rvalue = $2;
998
999 if ($default || $lvalue =~ /\[\d+\]$/) {
1000 set_eval($lvalue, $rvalue, $name);
1001 } else {
1002 my $val = "$lvalue\[$test_num\]";
1003 set_eval($val, $rvalue, $name);
1004 }
1005
Steven Rostedta57419b2010-11-02 15:13:54 -04001006 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1007
1008 next if ($skip);
1009
Steven Rostedt2545eb62010-11-02 15:01:32 -04001010 my $lvalue = $1;
1011 my $rvalue = $2;
1012
Steven Rostedta57419b2010-11-02 15:13:54 -04001013 if (!$default &&
1014 ($lvalue eq "NUM_TESTS" ||
1015 $lvalue eq "LOG_FILE" ||
1016 $lvalue eq "CLEAR_LOG")) {
1017 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001018 }
Steven Rostedta57419b2010-11-02 15:13:54 -04001019
1020 if ($lvalue eq "NUM_TESTS") {
1021 if ($test_num) {
1022 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1023 }
1024 if (!$default) {
1025 die "$name: $.: NUM_TESTS must be set in default section\n";
1026 }
1027 $num_tests_set = 1;
1028 }
1029
1030 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001031 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001032 } else {
1033 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001034 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001035
1036 if ($repeat > 1) {
1037 $repeats{$val} = $repeat;
1038 }
1039 }
Steven Rostedt77d942c2011-05-20 13:36:58 -04001040 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1041 next if ($skip);
1042
1043 my $lvalue = $1;
1044 my $rvalue = $2;
1045
1046 # process config variables.
1047 # Config variables are only active while reading the
1048 # config and can be defined anywhere. They also ignore
1049 # TEST_START and DEFAULTS, but are skipped if they are in
1050 # on of these sections that have SKIP defined.
1051 # The save variable can be
1052 # defined multiple times and the new one simply overrides
1053 # the prevous one.
1054 set_variable($lvalue, $rvalue);
1055
Steven Rostedta57419b2010-11-02 15:13:54 -04001056 } else {
1057 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001058 }
1059 }
1060
Steven Rostedta57419b2010-11-02 15:13:54 -04001061 if ($test_num) {
1062 $test_num += $repeat - 1;
1063 $opt{"NUM_TESTS"} = $test_num;
1064 }
1065
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001066 close($in);
1067
1068 $$current_test_num = $test_num;
1069
1070 return $test_case;
1071}
1072
Steven Rostedtc4261d02011-11-23 13:41:18 -05001073sub get_test_case {
1074 print "What test case would you like to run?\n";
1075 print " (build, install or boot)\n";
1076 print " Other tests are available but require editing the config file\n";
1077 my $ans = <STDIN>;
1078 chomp $ans;
1079 $default{"TEST_TYPE"} = $ans;
1080}
1081
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001082sub read_config {
1083 my ($config) = @_;
1084
1085 my $test_case;
1086 my $test_num = 0;
1087
1088 $test_case = __read_config $config, \$test_num;
1089
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001090 # make sure we have all mandatory configs
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09001091 get_mandatory_configs;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001092
Steven Rostedt0df213c2011-06-14 20:51:37 -04001093 # was a test specified?
1094 if (!$test_case) {
1095 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001096 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001097 }
1098
Steven Rostedta75fece2010-11-02 14:58:27 -04001099 # set any defaults
1100
1101 foreach my $default (keys %default) {
1102 if (!defined($opt{$default})) {
1103 $opt{$default} = $default{$default};
1104 }
1105 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001106
1107 if ($opt{"IGNORE_UNUSED"} == 1) {
1108 return;
1109 }
1110
1111 my %not_used;
1112
1113 # check if there are any stragglers (typos?)
1114 foreach my $option (keys %opt) {
1115 my $op = $option;
1116 # remove per test labels.
1117 $op =~ s/\[.*\]//;
1118 if (!exists($option_map{$op}) &&
1119 !exists($default{$op}) &&
1120 !exists($used_options{$op})) {
1121 $not_used{$op} = 1;
1122 }
1123 }
1124
1125 if (%not_used) {
1126 my $s = "s are";
1127 $s = " is" if (keys %not_used == 1);
1128 print "The following option$s not used; could be a typo:\n";
1129 foreach my $option (keys %not_used) {
1130 print "$option\n";
1131 }
1132 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1133 if (!read_yn "Do you want to continue?") {
1134 exit -1;
1135 }
1136 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001137}
1138
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001139sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001140 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001141
1142 # Add space to evaluate the character before $
1143 $option = " $option";
1144 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301145 my $repeated = 0;
1146 my $parent = 0;
1147
1148 foreach my $test (keys %repeat_tests) {
1149 if ($i >= $test &&
1150 $i < $test + $repeat_tests{$test}) {
1151
1152 $repeated = 1;
1153 $parent = $test;
1154 last;
1155 }
1156 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001157
1158 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1159 my $start = $1;
1160 my $var = $2;
1161 my $end = $3;
1162
1163 # Append beginning of line
1164 $retval = "$retval$start";
1165
1166 # If the iteration option OPT[$i] exists, then use that.
1167 # otherwise see if the default OPT (without [$i]) exists.
1168
1169 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301170 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001171
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001172 # If a variable contains itself, use the default var
1173 if (($var eq $name) && defined($opt{$var})) {
1174 $o = $opt{$var};
1175 $retval = "$retval$o";
1176 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001177 $o = $opt{$o};
1178 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301179 } elsif ($repeated && defined($opt{$parento})) {
1180 $o = $opt{$parento};
1181 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001182 } elsif (defined($opt{$var})) {
1183 $o = $opt{$var};
1184 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001185 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1186 # special option KERNEL_VERSION uses kernel version
1187 get_version();
1188 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001189 } else {
1190 $retval = "$retval\$\{$var\}";
1191 }
1192
1193 $option = $end;
1194 }
1195
1196 $retval = "$retval$option";
1197
1198 $retval =~ s/^ //;
1199
1200 return $retval;
1201}
1202
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001203sub process_evals {
1204 my ($name, $option, $i) = @_;
1205
1206 my $option_name = "$name\[$i\]";
1207 my $ev;
1208
1209 my $old_option = $option;
1210
1211 if (defined($evals{$option_name})) {
1212 $ev = $evals{$option_name};
1213 } elsif (defined($evals{$name})) {
1214 $ev = $evals{$name};
1215 } else {
1216 return $option;
1217 }
1218
1219 for my $e (@{$ev}) {
1220 eval "\$option =~ $e";
1221 }
1222
1223 if ($option ne $old_option) {
1224 doprint("$name changed from '$old_option' to '$option'\n");
1225 }
1226
1227 return $option;
1228}
1229
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001230sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001231 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001232
1233 my $prev = "";
1234
1235 # Since an option can evaluate to another option,
1236 # keep iterating until we do not evaluate any more
1237 # options.
1238 my $r = 0;
1239 while ($prev ne $option) {
1240 # Check for recursive evaluations.
1241 # 100 deep should be more than enough.
1242 if ($r++ > 100) {
1243 die "Over 100 evaluations accurred with $option\n" .
1244 "Check for recursive variables\n";
1245 }
1246 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001247 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001248 }
1249
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001250 $option = process_evals($name, $option, $i);
1251
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001252 return $option;
1253}
1254
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001255sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001256sub start_monitor;
1257sub end_monitor;
1258sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001259
1260sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001261 my ($time) = @_;
1262
Steven Rostedta4968722012-12-11 14:59:05 -05001263 # Make sure everything has been written to disk
1264 run_ssh("sync");
1265
Steven Rostedt2b803362011-09-30 18:00:23 -04001266 if (defined($time)) {
1267 start_monitor;
1268 # flush out current monitor
1269 # May contain the reboot success line
1270 wait_for_monitor 1;
1271 }
1272
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001273 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001274 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001275 if (defined($powercycle_after_reboot)) {
1276 sleep $powercycle_after_reboot;
1277 run_command "$power_cycle";
1278 }
1279 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001280 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001281 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001282 }
Andrew Jones2728be42011-08-12 15:32:05 +02001283
1284 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001285
1286 # We only want to get to the new kernel, don't fail
1287 # if we stumble over a call trace.
1288 my $save_ignore_errors = $ignore_errors;
1289 $ignore_errors = 1;
1290
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001291 # Look for the good kernel to boot
1292 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001293 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001294 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001295 run_command "$power_cycle";
1296 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001297
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001298 $ignore_errors = $save_ignore_errors;
1299
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001300 # Still need to wait for the reboot to finish
1301 wait_for_monitor($time, $reboot_success_line);
1302
Andrew Jones2728be42011-08-12 15:32:05 +02001303 end_monitor;
1304 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001305}
1306
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001307sub reboot_to_good {
1308 my ($time) = @_;
1309
1310 if (defined($switch_to_good)) {
1311 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001312 }
1313
1314 reboot $time;
1315}
1316
Steven Rostedt576f6272010-11-02 14:58:38 -04001317sub do_not_reboot {
1318 my $i = $iteration;
1319
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001320 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001321 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1322 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1323}
1324
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001325sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001326 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001327
Steven Rostedt576f6272010-11-02 14:58:38 -04001328 my $i = $iteration;
1329
1330 if ($reboot_on_error && !do_not_reboot) {
1331
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001332 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001333 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001334
Steven Rostedta75fece2010-11-02 14:58:27 -04001335 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001336 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001337 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001338 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001339
Steven Rostedtf80802c2011-03-07 13:18:47 -05001340 if (defined($opt{"LOG_FILE"})) {
1341 print " See $opt{LOG_FILE} for more info.\n";
1342 }
1343
Steven Rostedt576f6272010-11-02 14:58:38 -04001344 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001345}
1346
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001347sub open_console {
1348 my ($fp) = @_;
1349
1350 my $flags;
1351
Steven Rostedta75fece2010-11-02 14:58:27 -04001352 my $pid = open($fp, "$console|") or
1353 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001354
1355 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001356 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001357 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001358 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001359
1360 return $pid;
1361}
1362
1363sub close_console {
1364 my ($fp, $pid) = @_;
1365
1366 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001367 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001368
1369 print "closing!\n";
1370 close($fp);
1371}
1372
1373sub start_monitor {
1374 if ($monitor_cnt++) {
1375 return;
1376 }
1377 $monitor_fp = \*MONFD;
1378 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001379
1380 return;
1381
1382 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001383}
1384
1385sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001386 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001387 if (--$monitor_cnt) {
1388 return;
1389 }
1390 close_console($monitor_fp, $monitor_pid);
1391}
1392
1393sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001394 my ($time, $stop) = @_;
1395 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001396 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001397 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001398 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001399 my $skip_call_trace = 0;
1400 my $bug = 0;
1401 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001402 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001403
Steven Rostedta75fece2010-11-02 14:58:27 -04001404 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001405
1406 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001407 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001408 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001409 last if (!defined($line));
1410 print "$line";
1411 $full_line .= $line;
1412
1413 if (defined($stop) && $full_line =~ /$stop/) {
1414 doprint "wait for monitor detected $stop\n";
1415 $booted = 1;
1416 }
1417
Steven Rostedt8a80c722012-07-19 16:08:33 -04001418 if ($full_line =~ /\[ backtrace testing \]/) {
1419 $skip_call_trace = 1;
1420 }
1421
1422 if ($full_line =~ /call trace:/i) {
1423 if (!$bug && !$skip_call_trace) {
1424 if ($ignore_errors) {
1425 $bug_ignored = 1;
1426 } else {
1427 $bug = 1;
1428 }
1429 }
1430 }
1431
1432 if ($full_line =~ /\[ end of backtrace testing \]/) {
1433 $skip_call_trace = 0;
1434 }
1435
1436 if ($full_line =~ /Kernel panic -/) {
1437 $bug = 1;
1438 }
1439
Steven Rostedt2b803362011-09-30 18:00:23 -04001440 if ($line =~ /\n/) {
1441 $full_line = "";
1442 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001443 $now = time;
1444 if ($now - $start_time >= $max_monitor_wait) {
1445 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1446 return 1;
1447 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001448 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001449 print "** Monitor flushed **\n";
Steven Rostedt (Red Hat)995bc432014-10-07 16:31:07 -04001450
1451 # if stop is defined but wasn't hit, return error
1452 # used by reboot (which wants to see a reboot)
1453 if (defined($stop) && !$booted) {
1454 $bug = 1;
1455 }
Steven Rostedt8a80c722012-07-19 16:08:33 -04001456 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001457}
1458
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301459sub save_logs {
1460 my ($result, $basedir) = @_;
1461 my @t = localtime;
1462 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1463 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1464
1465 my $type = $build_type;
1466 if ($type =~ /useconfig/) {
1467 $type = "useconfig";
1468 }
1469
1470 my $dir = "$machine-$test_type-$type-$result-$date";
1471
1472 $dir = "$basedir/$dir";
1473
1474 if (!-d $dir) {
1475 mkpath($dir) or
1476 die "can't create $dir";
1477 }
1478
1479 my %files = (
1480 "config" => $output_config,
1481 "buildlog" => $buildlog,
1482 "dmesg" => $dmesg,
1483 "testlog" => $testlog,
1484 );
1485
1486 while (my ($name, $source) = each(%files)) {
1487 if (-f "$source") {
1488 cp "$source", "$dir/$name" or
1489 die "failed to copy $source";
1490 }
1491 }
1492
1493 doprint "*** Saved info to $dir ***\n";
1494}
1495
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001496sub fail {
1497
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001498 if (defined($post_test)) {
1499 run_command $post_test;
1500 }
1501
Steven Rostedta75fece2010-11-02 14:58:27 -04001502 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001503 dodie @_;
1504 }
1505
Steven Rostedta75fece2010-11-02 14:58:27 -04001506 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001507
Steven Rostedt576f6272010-11-02 14:58:38 -04001508 my $i = $iteration;
1509
Steven Rostedta75fece2010-11-02 14:58:27 -04001510 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001511 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001512 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001513 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001514 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001515
Steven Rostedt9064af52011-06-13 10:38:48 -04001516 my $name = "";
1517
1518 if (defined($test_name)) {
1519 $name = " ($test_name)";
1520 }
1521
Steven Rostedt576f6272010-11-02 14:58:38 -04001522 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1523 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001524 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001525 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1526 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001527
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301528 if (defined($store_failures)) {
1529 save_logs "fail", $store_failures;
1530 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001531
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001532 return 1;
1533}
1534
Steven Rostedt2545eb62010-11-02 15:01:32 -04001535sub run_command {
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09001536 my ($command, $redirect) = @_;
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001537 my $start_time;
1538 my $end_time;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001539 my $dolog = 0;
1540 my $dord = 0;
1541 my $pid;
1542
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001543 $start_time = time;
1544
Steven Rostedte48c5292010-11-02 14:35:37 -04001545 $command =~ s/\$SSH_USER/$ssh_user/g;
1546 $command =~ s/\$MACHINE/$machine/g;
1547
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001548 doprint("$command ... ");
1549
1550 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001551 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001552
1553 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001554 open(LOG, ">>$opt{LOG_FILE}") or
1555 dodie "failed to write to log";
1556 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001557 }
1558
1559 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001560 open (RD, ">$redirect") or
1561 dodie "failed to write to redirect $redirect";
1562 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001563 }
1564
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001565 while (<CMD>) {
1566 print LOG if ($dolog);
1567 print RD if ($dord);
1568 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001569
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001570 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001571 my $failed = $?;
1572
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001573 close(CMD);
1574 close(LOG) if ($dolog);
1575 close(RD) if ($dord);
1576
Steven Rostedt (Red Hat)b53486e2015-01-27 17:02:02 -05001577 $end_time = time;
1578 my $delta = $end_time - $start_time;
1579
1580 if ($delta == 1) {
1581 doprint "[1 second] ";
1582 } else {
1583 doprint "[$delta seconds] ";
1584 }
1585
Steven Rostedt2545eb62010-11-02 15:01:32 -04001586 if ($failed) {
1587 doprint "FAILED!\n";
1588 } else {
1589 doprint "SUCCESS\n";
1590 }
1591
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001592 return !$failed;
1593}
1594
Steven Rostedte48c5292010-11-02 14:35:37 -04001595sub run_ssh {
1596 my ($cmd) = @_;
1597 my $cp_exec = $ssh_exec;
1598
1599 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1600 return run_command "$cp_exec";
1601}
1602
1603sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001604 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001605
1606 $cp_scp =~ s/\$SRC_FILE/$src/g;
1607 $cp_scp =~ s/\$DST_FILE/$dst/g;
1608
1609 return run_command "$cp_scp";
1610}
1611
Steven Rostedt02ad2612012-03-21 08:21:24 -04001612sub run_scp_install {
1613 my ($src, $dst) = @_;
1614
1615 my $cp_scp = $scp_to_target_install;
1616
1617 return run_scp($src, $dst, $cp_scp);
1618}
1619
1620sub run_scp_mod {
1621 my ($src, $dst) = @_;
1622
1623 my $cp_scp = $scp_to_target;
1624
1625 return run_scp($src, $dst, $cp_scp);
1626}
1627
Steven Rostedta15ba912012-11-13 14:30:37 -05001628sub get_grub2_index {
1629
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001630 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001631 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1632 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001633
1634 doprint "Find grub2 menu ... ";
1635 $grub_number = -1;
1636
1637 my $ssh_grub = $ssh_exec;
1638 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1639
1640 open(IN, "$ssh_grub |")
1641 or die "unable to get $grub_file";
1642
1643 my $found = 0;
1644
1645 while (<IN>) {
1646 if (/^menuentry.*$grub_menu/) {
1647 $grub_number++;
1648 $found = 1;
1649 last;
1650 } elsif (/^menuentry\s/) {
1651 $grub_number++;
1652 }
1653 }
1654 close(IN);
1655
1656 die "Could not find '$grub_menu' in $grub_file on $machine"
1657 if (!$found);
1658 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001659 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001660 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001661}
1662
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001663sub get_grub_index {
1664
Steven Rostedta15ba912012-11-13 14:30:37 -05001665 if ($reboot_type eq "grub2") {
1666 get_grub2_index;
1667 return;
1668 }
1669
Steven Rostedta75fece2010-11-02 14:58:27 -04001670 if ($reboot_type ne "grub") {
1671 return;
1672 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001673 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001674 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1675 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001676
1677 doprint "Find grub menu ... ";
1678 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001679
1680 my $ssh_grub = $ssh_exec;
1681 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1682
1683 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001684 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001685
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001686 my $found = 0;
1687
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001688 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001689 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001690 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001691 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001692 last;
1693 } elsif (/^\s*title\s/) {
1694 $grub_number++;
1695 }
1696 }
1697 close(IN);
1698
Steven Rostedta75fece2010-11-02 14:58:27 -04001699 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001700 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001701 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001702 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001703 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001704}
1705
Steven Rostedt2545eb62010-11-02 15:01:32 -04001706sub wait_for_input
1707{
1708 my ($fp, $time) = @_;
1709 my $rin;
1710 my $ready;
1711 my $line;
1712 my $ch;
1713
1714 if (!defined($time)) {
1715 $time = $timeout;
1716 }
1717
1718 $rin = '';
1719 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001720 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001721
1722 $line = "";
1723
1724 # try to read one char at a time
1725 while (sysread $fp, $ch, 1) {
1726 $line .= $ch;
1727 last if ($ch eq "\n");
1728 }
1729
1730 if (!length($line)) {
1731 return undef;
1732 }
1733
1734 return $line;
1735}
1736
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001737sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001738 if (defined($switch_to_test)) {
1739 run_command $switch_to_test;
1740 }
1741
Steven Rostedta75fece2010-11-02 14:58:27 -04001742 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001743 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001744 } elsif ($reboot_type eq "grub2") {
1745 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001746 } elsif ($reboot_type eq "syslinux") {
1747 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001748 } elsif (defined $reboot_script) {
1749 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001750 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001751 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001752}
1753
Steven Rostedta57419b2010-11-02 15:13:54 -04001754sub get_sha1 {
1755 my ($commit) = @_;
1756
1757 doprint "git rev-list --max-count=1 $commit ... ";
1758 my $sha1 = `git rev-list --max-count=1 $commit`;
1759 my $ret = $?;
1760
1761 logit $sha1;
1762
1763 if ($ret) {
1764 doprint "FAILED\n";
1765 dodie "Failed to get git $commit";
1766 }
1767
1768 print "SUCCESS\n";
1769
1770 chomp $sha1;
1771
1772 return $sha1;
1773}
1774
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001775sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001776 my $booted = 0;
1777 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001778 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001779 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001780 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001781
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001782 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001783
1784 my $line;
1785 my $full_line = "";
1786
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001787 open(DMESG, "> $dmesg") or
1788 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001789
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001790 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001791
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001792 my $success_start;
1793 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001794 my $monitor_start = time;
1795 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001796 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001797
Steven Rostedt2d01b262011-03-08 09:47:54 -05001798 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001799
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001800 if ($bug && defined($stop_after_failure) &&
1801 $stop_after_failure >= 0) {
1802 my $time = $stop_after_failure - (time - $failure_start);
1803 $line = wait_for_input($monitor_fp, $time);
1804 if (!defined($line)) {
1805 doprint "bug timed out after $booted_timeout seconds\n";
1806 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1807 last;
1808 }
1809 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001810 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001811 if (!defined($line)) {
1812 my $s = $booted_timeout == 1 ? "" : "s";
1813 doprint "Successful boot found: break after $booted_timeout second$s\n";
1814 last;
1815 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001816 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001817 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001818 if (!defined($line)) {
1819 my $s = $timeout == 1 ? "" : "s";
1820 doprint "Timed out after $timeout second$s\n";
1821 last;
1822 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001823 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001824
Steven Rostedt2545eb62010-11-02 15:01:32 -04001825 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001826 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001827
1828 # we are not guaranteed to get a full line
1829 $full_line .= $line;
1830
Steven Rostedta75fece2010-11-02 14:58:27 -04001831 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001832 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001833 $success_start = time;
1834 }
1835
1836 if ($booted && defined($stop_after_success) &&
1837 $stop_after_success >= 0) {
1838 my $now = time;
1839 if ($now - $success_start >= $stop_after_success) {
1840 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1841 last;
1842 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001843 }
1844
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001845 if ($full_line =~ /\[ backtrace testing \]/) {
1846 $skip_call_trace = 1;
1847 }
1848
Steven Rostedt2545eb62010-11-02 15:01:32 -04001849 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001850 if (!$bug && !$skip_call_trace) {
1851 if ($ignore_errors) {
1852 $bug_ignored = 1;
1853 } else {
1854 $bug = 1;
1855 $failure_start = time;
1856 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001857 }
1858 }
1859
1860 if ($bug && defined($stop_after_failure) &&
1861 $stop_after_failure >= 0) {
1862 my $now = time;
1863 if ($now - $failure_start >= $stop_after_failure) {
1864 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1865 last;
1866 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001867 }
1868
1869 if ($full_line =~ /\[ end of backtrace testing \]/) {
1870 $skip_call_trace = 0;
1871 }
1872
1873 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001874 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001875 $bug = 1;
1876 }
1877
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001878 # Detect triple faults by testing the banner
1879 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1880 if ($1 eq $version) {
1881 $version_found = 1;
1882 } elsif ($version_found && $detect_triplefault) {
1883 # We already booted into the kernel we are testing,
1884 # but now we booted into another kernel?
1885 # Consider this a triple fault.
Masanari Iida8b513d02013-05-21 23:13:12 +09001886 doprint "Already booted in Linux kernel $version, but now\n";
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001887 doprint "we booted into Linux kernel $1.\n";
1888 doprint "Assuming that this is a triple fault.\n";
1889 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1890 last;
1891 }
1892 }
1893
Steven Rostedt2545eb62010-11-02 15:01:32 -04001894 if ($line =~ /\n/) {
1895 $full_line = "";
1896 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001897
1898 if ($stop_test_after > 0 && !$booted && !$bug) {
1899 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001900 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001901 $done = 1;
1902 }
1903 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001904 }
1905
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001906 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001907
Steven Rostedt2545eb62010-11-02 15:01:32 -04001908 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001909 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001910 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001911 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001912
Steven Rostedta75fece2010-11-02 14:58:27 -04001913 if (!$booted) {
1914 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001915 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001916 }
1917
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001918 if ($bug_ignored) {
1919 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1920 }
1921
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001922 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001923}
1924
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001925sub eval_kernel_version {
1926 my ($option) = @_;
1927
1928 $option =~ s/\$KERNEL_VERSION/$version/g;
1929
1930 return $option;
1931}
1932
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001933sub do_post_install {
1934
1935 return if (!defined($post_install));
1936
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001937 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001938 run_command "$cp_post_install" or
1939 dodie "Failed to run post install";
1940}
1941
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001942# Sometimes the reboot fails, and will hang. We try to ssh to the box
1943# and if we fail, we force another reboot, that should powercycle it.
1944sub test_booted {
1945 if (!run_ssh "echo testing connection") {
1946 reboot $sleep_time;
1947 }
1948}
1949
Steven Rostedt2545eb62010-11-02 15:01:32 -04001950sub install {
1951
Steven Rostedte0a87422011-09-30 17:50:48 -04001952 return if ($no_install);
1953
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001954 if (defined($pre_install)) {
1955 my $cp_pre_install = eval_kernel_version $pre_install;
1956 run_command "$cp_pre_install" or
1957 dodie "Failed to run pre install";
1958 }
1959
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001960 my $cp_target = eval_kernel_version $target_image;
1961
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001962 test_booted;
1963
Steven Rostedt02ad2612012-03-21 08:21:24 -04001964 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001965 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001966
1967 my $install_mods = 0;
1968
1969 # should we process modules?
1970 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001971 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001972 while (<IN>) {
1973 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001974 if (defined($1)) {
1975 $install_mods = 1;
1976 last;
1977 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001978 }
1979 }
1980 close(IN);
1981
1982 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001983 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001984 doprint "No modules needed\n";
1985 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001986 }
1987
Steven Rostedt627977d2012-03-21 08:16:15 -04001988 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001989 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001990
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001991 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001992 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001993
Steven Rostedte48c5292010-11-02 14:35:37 -04001994 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001995 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001996
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001997 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001998 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001999 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002000
Steven Rostedt02ad2612012-03-21 08:21:24 -04002001 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002002 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002003
Steven Rostedta75fece2010-11-02 14:58:27 -04002004 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002005
Steven Rostedte7b13442011-06-14 20:44:36 -04002006 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002007 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002008
Steven Rostedte48c5292010-11-02 14:35:37 -04002009 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002010
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002011 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002012}
2013
Steven Rostedtddf607e2011-06-14 20:49:13 -04002014sub get_version {
2015 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04002016 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002017 doprint "$make kernelrelease ... ";
Steven Rostedt (Red Hat)17150fe2014-11-23 15:13:44 -05002018 $version = `$make -s kernelrelease | tail -1`;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002019 chomp($version);
2020 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002021 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002022}
2023
2024sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002025 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002026
2027 # Install bisects, don't need console
2028 if (defined $console) {
2029 start_monitor;
2030 wait_for_monitor 5;
2031 end_monitor;
2032 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002033
Steven Rostedtddf607e2011-06-14 20:49:13 -04002034 get_grub_index;
2035 get_version;
2036 install;
2037
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002038 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002039 return monitor;
2040}
2041
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002042my $check_build_re = ".*:.*(warning|error|Error):.*";
2043my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2044
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002045sub process_warning_line {
2046 my ($line) = @_;
2047
2048 chomp $line;
2049
2050 # for distcc heterogeneous systems, some compilers
2051 # do things differently causing warning lines
2052 # to be slightly different. This makes an attempt
2053 # to fixe those issues.
2054
2055 # chop off the index into the line
2056 # using distcc, some compilers give different indexes
2057 # depending on white space
2058 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2059
2060 # Some compilers use UTF-8 extended for quotes and some don't.
2061 $line =~ s/$utf8_quote/'/g;
2062
2063 return $line;
2064}
2065
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002066# Read buildlog and check against warnings file for any
2067# new warnings.
2068#
2069# Returns 1 if OK
2070# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002071sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002072 return 1 if (!defined $warnings_file);
2073
2074 my %warnings_list;
2075
2076 # Failed builds should not reboot the target
2077 my $save_no_reboot = $no_reboot;
2078 $no_reboot = 1;
2079
2080 if (-f $warnings_file) {
2081 open(IN, $warnings_file) or
2082 dodie "Error opening $warnings_file";
2083
2084 while (<IN>) {
2085 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002086 my $warning = process_warning_line $_;
2087
2088 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002089 }
2090 }
2091 close(IN);
2092 }
2093
2094 # If warnings file didn't exist, and WARNINGS_FILE exist,
2095 # then we fail on any warning!
2096
2097 open(IN, $buildlog) or dodie "Can't open $buildlog";
2098 while (<IN>) {
2099 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002100 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002101
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002102 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002103 fail "New warning found (not in $warnings_file)\n$_\n";
2104 $no_reboot = $save_no_reboot;
2105 return 0;
2106 }
2107 }
2108 }
2109 $no_reboot = $save_no_reboot;
2110 close(IN);
2111}
2112
2113sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002114 my ($patch) = @_;
2115
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002116 my @files = `git show $patch | diffstat -l`;
2117
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002118 foreach my $file (@files) {
2119 chomp $file;
2120 }
2121
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002122 open(IN, "git show $patch |") or
2123 dodie "failed to show $patch";
2124 while (<IN>) {
2125 if (m,^--- a/(.*),) {
2126 chomp $1;
2127 $files[$#files] = $1;
2128 }
2129 }
2130 close(IN);
2131
2132 open(IN, $buildlog) or dodie "Can't open $buildlog";
2133 while (<IN>) {
2134 if (/^\s*(.*?):.*(warning|error)/) {
2135 my $err = $1;
2136 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002137 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002138 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002139 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002140 }
2141 }
2142 }
2143 }
2144 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002145
2146 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002147}
2148
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002149sub apply_min_config {
2150 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002151
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002152 # Read the config file and remove anything that
2153 # is in the force_config hash (from minconfig and others)
2154 # then add the force config back.
2155
2156 doprint "Applying minimum configurations into $output_config.new\n";
2157
2158 open (OUT, ">$outconfig") or
2159 dodie "Can't create $outconfig";
2160
2161 if (-f $output_config) {
2162 open (IN, $output_config) or
2163 dodie "Failed to open $output_config";
2164 while (<IN>) {
2165 if (/^(# )?(CONFIG_[^\s=]*)/) {
2166 next if (defined($force_config{$2}));
2167 }
2168 print OUT;
2169 }
2170 close IN;
2171 }
2172 foreach my $config (keys %force_config) {
2173 print OUT "$force_config{$config}\n";
2174 }
2175 close OUT;
2176
2177 run_command "mv $outconfig $output_config";
2178}
2179
2180sub make_oldconfig {
2181
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002182 my @force_list = keys %force_config;
2183
2184 if ($#force_list >= 0) {
2185 apply_min_config;
2186 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002187
Adam Leefb16d892012-09-01 01:05:17 +08002188 if (!run_command "$make olddefconfig") {
2189 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002190 # try oldnoconfig
2191 doprint "olddefconfig failed, trying make oldnoconfig\n";
2192 if (!run_command "$make oldnoconfig") {
2193 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2194 # try a yes '' | oldconfig
2195 run_command "yes '' | $make oldconfig" or
2196 dodie "failed make config oldconfig";
2197 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002198 }
2199}
2200
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002201# read a config file and use this to force new configs.
2202sub load_force_config {
2203 my ($config) = @_;
2204
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002205 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002206 open(IN, $config) or
2207 dodie "failed to read $config";
2208 while (<IN>) {
2209 chomp;
2210 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2211 $force_config{$1} = $_;
2212 } elsif (/^# (CONFIG_\S*) is not set/) {
2213 $force_config{$1} = $_;
2214 }
2215 }
2216 close IN;
2217}
2218
Steven Rostedt2545eb62010-11-02 15:01:32 -04002219sub build {
2220 my ($type) = @_;
2221
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002222 unlink $buildlog;
2223
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002224 # Failed builds should not reboot the target
2225 my $save_no_reboot = $no_reboot;
2226 $no_reboot = 1;
2227
Steven Rostedt683a3e62012-05-18 13:34:35 -04002228 # Calculate a new version from here.
2229 $have_version = 0;
2230
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002231 if (defined($pre_build)) {
2232 my $ret = run_command $pre_build;
2233 if (!$ret && defined($pre_build_die) &&
2234 $pre_build_die) {
2235 dodie "failed to pre_build\n";
2236 }
2237 }
2238
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002239 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002240 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002241 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002242
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002243 $type = "oldconfig";
2244 }
2245
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002246 # old config can ask questions
2247 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002248 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002249
2250 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002251 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002252
Andrew Jones13488232011-08-12 15:32:04 +02002253 if (!$noclean) {
2254 run_command "mv $output_config $outputdir/config_temp" or
2255 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002256
Andrew Jones13488232011-08-12 15:32:04 +02002257 run_command "$make mrproper" or dodie "make mrproper";
2258
2259 run_command "mv $outputdir/config_temp $output_config" or
2260 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002261 }
2262
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002263 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002264 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002265 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002266 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002267 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002268
2269 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002270 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2271 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002272 close(OUT);
2273
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002274 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002275 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002276 }
2277
Adam Leefb16d892012-09-01 01:05:17 +08002278 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002279 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002280 dodie "failed make config";
2281 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002282 # Run old config regardless, to enforce min configurations
2283 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002284
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002285 my $build_ret = run_command "$make $build_options", $buildlog;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002286
2287 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002288 # Because a post build may change the kernel version
2289 # do it now.
2290 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002291 my $ret = run_command $post_build;
2292 if (!$ret && defined($post_build_die) &&
2293 $post_build_die) {
2294 dodie "failed to post_build\n";
2295 }
2296 }
2297
2298 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002299 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002300 if ($in_bisect) {
2301 $no_reboot = $save_no_reboot;
2302 return 0;
2303 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002304 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002305 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002306
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002307 $no_reboot = $save_no_reboot;
2308
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002309 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002310}
2311
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002312sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002313 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002314 if (defined($poweroff_after_halt)) {
2315 sleep $poweroff_after_halt;
2316 run_command "$power_off";
2317 }
2318 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002319 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002320 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002321 }
2322}
2323
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002324sub success {
2325 my ($i) = @_;
2326
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002327 if (defined($post_test)) {
2328 run_command $post_test;
2329 }
2330
Steven Rostedte48c5292010-11-02 14:35:37 -04002331 $successes++;
2332
Steven Rostedt9064af52011-06-13 10:38:48 -04002333 my $name = "";
2334
2335 if (defined($test_name)) {
2336 $name = " ($test_name)";
2337 }
2338
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002339 doprint "\n\n*******************************************\n";
2340 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002341 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002342 doprint "*******************************************\n";
2343 doprint "*******************************************\n";
2344
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302345 if (defined($store_successes)) {
2346 save_logs "success", $store_successes;
2347 }
2348
Steven Rostedt576f6272010-11-02 14:58:38 -04002349 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002350 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002351 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002352 }
2353}
2354
Steven Rostedtc960bb92011-03-08 09:22:39 -05002355sub answer_bisect {
2356 for (;;) {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002357 doprint "Pass, fail, or skip? [p/f/s]";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002358 my $ans = <STDIN>;
2359 chomp $ans;
2360 if ($ans eq "p" || $ans eq "P") {
2361 return 1;
2362 } elsif ($ans eq "f" || $ans eq "F") {
2363 return 0;
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002364 } elsif ($ans eq "s" || $ans eq "S") {
2365 return -1;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002366 } else {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002367 print "Please answer 'p', 'f', or 's'\n";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002368 }
2369 }
2370}
2371
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002372sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002373 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002374
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002375 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002376 $reboot_on_error = 0;
2377 $poweroff_on_error = 0;
2378 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002379
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002380 run_command $run_test, $testlog or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302381
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002382 exit $failed;
2383}
2384
2385my $child_done;
2386
2387sub child_finished {
2388 $child_done = 1;
2389}
2390
2391sub do_run_test {
2392 my $child_pid;
2393 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002394 my $line;
2395 my $full_line;
2396 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002397 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002398
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002399 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002400
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002401 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002402
2403 $child_done = 0;
2404
2405 $SIG{CHLD} = qw(child_finished);
2406
2407 $child_pid = fork;
2408
2409 child_run_test if (!$child_pid);
2410
2411 $full_line = "";
2412
2413 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002414 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002415 if (defined($line)) {
2416
2417 # we are not guaranteed to get a full line
2418 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002419 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002420
2421 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002422 if ($ignore_errors) {
2423 $bug_ignored = 1;
2424 } else {
2425 $bug = 1;
2426 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002427 }
2428
2429 if ($full_line =~ /Kernel panic -/) {
2430 $bug = 1;
2431 }
2432
2433 if ($line =~ /\n/) {
2434 $full_line = "";
2435 }
2436 }
2437 } while (!$child_done && !$bug);
2438
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002439 if (!$bug && $bug_ignored) {
2440 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2441 }
2442
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002443 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002444 my $failure_start = time;
2445 my $now;
2446 do {
2447 $line = wait_for_input($monitor_fp, 1);
2448 if (defined($line)) {
2449 doprint $line;
2450 }
2451 $now = time;
2452 if ($now - $failure_start >= $stop_after_failure) {
2453 last;
2454 }
2455 } while (defined($line));
2456
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002457 doprint "Detected kernel crash!\n";
2458 # kill the child with extreme prejudice
2459 kill 9, $child_pid;
2460 }
2461
2462 waitpid $child_pid, 0;
2463 $child_exit = $?;
2464
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002465 if (!$bug && $in_bisect) {
2466 if (defined($bisect_ret_good)) {
2467 if ($child_exit == $bisect_ret_good) {
2468 return 1;
2469 }
2470 }
2471 if (defined($bisect_ret_skip)) {
2472 if ($child_exit == $bisect_ret_skip) {
2473 return -1;
2474 }
2475 }
2476 if (defined($bisect_ret_abort)) {
2477 if ($child_exit == $bisect_ret_abort) {
2478 fail "test abort" and return -2;
2479 }
2480 }
2481 if (defined($bisect_ret_bad)) {
2482 if ($child_exit == $bisect_ret_skip) {
2483 return 0;
2484 }
2485 }
2486 if (defined($bisect_ret_default)) {
2487 if ($bisect_ret_default eq "good") {
2488 return 1;
2489 } elsif ($bisect_ret_default eq "bad") {
2490 return 0;
2491 } elsif ($bisect_ret_default eq "skip") {
2492 return -1;
2493 } elsif ($bisect_ret_default eq "abort") {
2494 return -2;
2495 } else {
2496 fail "unknown default action: $bisect_ret_default"
2497 and return -2;
2498 }
2499 }
2500 }
2501
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002502 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002503 return 0 if $in_bisect;
2504 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002505 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002506 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002507}
2508
Steven Rostedta75fece2010-11-02 14:58:27 -04002509sub run_git_bisect {
2510 my ($command) = @_;
2511
2512 doprint "$command ... ";
2513
2514 my $output = `$command 2>&1`;
2515 my $ret = $?;
2516
2517 logit $output;
2518
2519 if ($ret) {
2520 doprint "FAILED\n";
2521 dodie "Failed to git bisect";
2522 }
2523
2524 doprint "SUCCESS\n";
2525 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2526 doprint "$1 [$2]\n";
2527 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002528 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002529 doprint "Found bad commit... $1\n";
2530 return 0;
2531 } else {
2532 # we already logged it, just print it now.
2533 print $output;
2534 }
2535
2536 return 1;
2537}
2538
Steven Rostedtc23dca72011-03-08 09:26:31 -05002539sub bisect_reboot {
2540 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002541 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002542}
2543
2544# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002545sub run_bisect_test {
2546 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002547
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002548 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002549 my $result;
2550 my $output;
2551 my $ret;
2552
Steven Rostedt0a05c762010-11-08 11:14:10 -05002553 $in_bisect = 1;
2554
2555 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002556
2557 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002558 if ($failed && $bisect_skip) {
2559 $in_bisect = 0;
2560 return -1;
2561 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002562 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002563
2564 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002565 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002566
2567 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002568 if ($failed && $bisect_skip) {
2569 end_monitor;
2570 bisect_reboot;
2571 $in_bisect = 0;
2572 return -1;
2573 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002574 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002575
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002576 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002577 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002578 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002579 }
2580
2581 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002582 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002583 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002584 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002585 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002586
2587 # reboot the box to a kernel we can ssh to
2588 if ($type ne "build") {
2589 bisect_reboot;
2590 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002591 $in_bisect = 0;
2592
2593 return $result;
2594}
2595
2596sub run_bisect {
2597 my ($type) = @_;
2598 my $buildtype = "oldconfig";
2599
2600 # We should have a minconfig to use?
2601 if (defined($minconfig)) {
2602 $buildtype = "useconfig:$minconfig";
2603 }
2604
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002605 # If the user sets bisect_tries to less than 1, then no tries
2606 # is a success.
2607 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002608
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002609 # Still let the user manually decide that though.
2610 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002611 $ret = answer_bisect;
2612 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002613
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002614 for (my $i = 0; $i < $bisect_tries; $i++) {
2615 if ($bisect_tries > 1) {
2616 my $t = $i + 1;
2617 doprint("Running bisect trial $t of $bisect_tries:\n");
2618 }
2619 $ret = run_bisect_test $type, $buildtype;
2620
2621 if ($bisect_manual) {
2622 $ret = answer_bisect;
2623 }
2624
2625 last if (!$ret);
2626 }
2627
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002628 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002629 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002630 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002631 }
2632
Steven Rostedtc23dca72011-03-08 09:26:31 -05002633 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002634 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002635 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002636 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002637 } elsif ($bisect_skip) {
2638 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2639 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002640 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002641}
2642
Steven Rostedtdad98752011-11-22 20:48:57 -05002643sub update_bisect_replay {
2644 my $tmp_log = "$tmpdir/ktest_bisect_log";
2645 run_command "git bisect log > $tmp_log" or
2646 die "can't create bisect log";
2647 return $tmp_log;
2648}
2649
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002650sub bisect {
2651 my ($i) = @_;
2652
2653 my $result;
2654
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002655 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2656 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2657 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002658
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002659 my $good = $bisect_good;
2660 my $bad = $bisect_bad;
2661 my $type = $bisect_type;
2662 my $start = $bisect_start;
2663 my $replay = $bisect_replay;
2664 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002665
2666 if (defined($start_files)) {
2667 $start_files = " -- " . $start_files;
2668 } else {
2669 $start_files = "";
2670 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002671
Steven Rostedta57419b2010-11-02 15:13:54 -04002672 # convert to true sha1's
2673 $good = get_sha1($good);
2674 $bad = get_sha1($bad);
2675
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002676 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002677 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2678 $reverse_bisect = 1;
2679 } else {
2680 $reverse_bisect = 0;
2681 }
2682
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002683 # Can't have a test without having a test to run
2684 if ($type eq "test" && !defined($run_test)) {
2685 $type = "boot";
2686 }
2687
Steven Rostedtdad98752011-11-22 20:48:57 -05002688 # Check if a bisect was running
2689 my $bisect_start_file = "$builddir/.git/BISECT_START";
2690
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002691 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002692 my $do_check = defined($check) && $check ne "0";
2693
2694 if ( -f $bisect_start_file ) {
2695 print "Bisect in progress found\n";
2696 if ($do_check) {
2697 print " If you say yes, then no checks of good or bad will be done\n";
2698 }
2699 if (defined($replay)) {
2700 print "** BISECT_REPLAY is defined in config file **";
2701 print " Ignore config option and perform new git bisect log?\n";
2702 if (read_ync " (yes, no, or cancel) ") {
2703 $replay = update_bisect_replay;
2704 $do_check = 0;
2705 }
2706 } elsif (read_yn "read git log and continue?") {
2707 $replay = update_bisect_replay;
2708 $do_check = 0;
2709 }
2710 }
2711
2712 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002713
2714 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002715 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002716
2717 if ($check ne "good") {
2718 doprint "TESTING BISECT BAD [$bad]\n";
2719 run_command "git checkout $bad" or
2720 die "Failed to checkout $bad";
2721
2722 $result = run_bisect $type;
2723
2724 if ($result ne "bad") {
2725 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2726 }
2727 }
2728
2729 if ($check ne "bad") {
2730 doprint "TESTING BISECT GOOD [$good]\n";
2731 run_command "git checkout $good" or
2732 die "Failed to checkout $good";
2733
2734 $result = run_bisect $type;
2735
2736 if ($result ne "good") {
2737 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2738 }
2739 }
2740
2741 # checkout where we started
2742 run_command "git checkout $head" or
2743 die "Failed to checkout $head";
2744 }
2745
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002746 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002747 dodie "could not start bisect";
2748
Steven Rostedta75fece2010-11-02 14:58:27 -04002749 if (defined($replay)) {
2750 run_command "git bisect replay $replay" or
2751 dodie "failed to run replay";
Steven Rostedt (Red Hat)d832d742014-10-07 16:34:25 -04002752 } else {
2753
2754 run_command "git bisect good $good" or
2755 dodie "could not set bisect good to $good";
2756
2757 run_git_bisect "git bisect bad $bad" or
2758 dodie "could not set bisect bad to $bad";
2759
Steven Rostedta75fece2010-11-02 14:58:27 -04002760 }
2761
2762 if (defined($start)) {
2763 run_command "git checkout $start" or
2764 dodie "failed to checkout $start";
2765 }
2766
2767 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002768 do {
2769 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002770 $test = run_git_bisect "git bisect $result";
2771 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002772
2773 run_command "git bisect log" or
2774 dodie "could not capture git bisect log";
2775
2776 run_command "git bisect reset" or
2777 dodie "could not reset git bisect";
2778
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002779 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002780
Steven Rostedt0a05c762010-11-08 11:14:10 -05002781 success $i;
2782}
2783
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002784# config_ignore holds the configs that were set (or unset) for
2785# a good config and we will ignore these configs for the rest
2786# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002787my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002788
2789# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002790my %config_set;
2791
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002792# config_off holds the set of configs that the bad config had disabled.
2793# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002794# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002795my %config_off;
2796
2797# config_off_tmp holds a set of configs to turn off for now
2798my @config_off_tmp;
2799
2800# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002801my %config_list;
2802my %null_config;
2803
2804my %dependency;
2805
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002806sub assign_configs {
2807 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002808
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002809 doprint "Reading configs from $config\n";
2810
Steven Rostedt0a05c762010-11-08 11:14:10 -05002811 open (IN, $config)
2812 or dodie "Failed to read $config";
2813
2814 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002815 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04002816 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002817 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002818 } elsif (/^(# (CONFIG\S*) is not set)/) {
2819 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002820 }
2821 }
2822
2823 close(IN);
2824}
2825
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002826sub process_config_ignore {
2827 my ($config) = @_;
2828
2829 assign_configs \%config_ignore, $config;
2830}
2831
Steven Rostedt0a05c762010-11-08 11:14:10 -05002832sub get_dependencies {
2833 my ($config) = @_;
2834
2835 my $arr = $dependency{$config};
2836 if (!defined($arr)) {
2837 return ();
2838 }
2839
2840 my @deps = @{$arr};
2841
2842 foreach my $dep (@{$arr}) {
2843 print "ADD DEP $dep\n";
2844 @deps = (@deps, get_dependencies $dep);
2845 }
2846
2847 return @deps;
2848}
2849
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002850sub save_config {
2851 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002852
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002853 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002854
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002855 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002856
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002857 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002858
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002859 foreach my $config (keys %configs) {
2860 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002861 }
2862 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002863}
2864
2865sub create_config {
2866 my ($name, $pc) = @_;
2867
2868 doprint "Creating old config from $name configs\n";
2869
2870 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002871
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002872 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002873}
2874
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002875# compare two config hashes, and return configs with different vals.
2876# It returns B's config values, but you can use A to see what A was.
2877sub diff_config_vals {
2878 my ($pa, $pb) = @_;
2879
2880 # crappy Perl way to pass in hashes.
2881 my %a = %{$pa};
2882 my %b = %{$pb};
2883
2884 my %ret;
2885
2886 foreach my $item (keys %a) {
2887 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2888 $ret{$item} = $b{$item};
2889 }
2890 }
2891
2892 return %ret;
2893}
2894
2895# compare two config hashes and return the configs in B but not A
2896sub diff_configs {
2897 my ($pa, $pb) = @_;
2898
2899 my %ret;
2900
2901 # crappy Perl way to pass in hashes.
2902 my %a = %{$pa};
2903 my %b = %{$pb};
2904
2905 foreach my $item (keys %b) {
2906 if (!defined($a{$item})) {
2907 $ret{$item} = $b{$item};
2908 }
2909 }
2910
2911 return %ret;
2912}
2913
2914# return if two configs are equal or not
2915# 0 is equal +1 b has something a does not
2916# +1 if a and b have a different item.
2917# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05002918sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002919 my ($pa, $pb) = @_;
2920
2921 my %ret;
2922
2923 # crappy Perl way to pass in hashes.
2924 my %a = %{$pa};
2925 my %b = %{$pb};
2926
2927 foreach my $item (keys %b) {
2928 if (!defined($a{$item})) {
2929 return 1;
2930 }
2931 if ($a{$item} ne $b{$item}) {
2932 return 1;
2933 }
2934 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002935
2936 foreach my $item (keys %a) {
2937 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002938 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002939 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002940 }
2941
Steven Rostedt0a05c762010-11-08 11:14:10 -05002942 return 0;
2943}
2944
2945sub run_config_bisect_test {
2946 my ($type) = @_;
2947
Steven Rostedt (Red Hat)4cc559b2014-04-23 22:27:27 -04002948 my $ret = run_bisect_test $type, "oldconfig";
2949
2950 if ($bisect_manual) {
2951 $ret = answer_bisect;
2952 }
2953
2954 return $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002955}
2956
Steven Rostedt0a05c762010-11-08 11:14:10 -05002957sub process_failed {
2958 my ($config) = @_;
2959
2960 doprint "\n\n***************************************\n";
2961 doprint "Found bad config: $config\n";
2962 doprint "***************************************\n\n";
2963}
2964
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002965# used for config bisecting
2966my $good_config;
2967my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002968
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002969sub process_new_config {
2970 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002971
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002972 my %tmp_config = %{$tc};
2973 my %good_configs = %{$gc};
2974 my %bad_configs = %{$bc};
2975
2976 my %new_configs;
2977
2978 my $runtest = 1;
2979 my $ret;
2980
2981 create_config "tmp_configs", \%tmp_config;
2982 assign_configs \%new_configs, $output_config;
2983
2984 $ret = compare_configs \%new_configs, \%bad_configs;
2985 if (!$ret) {
2986 doprint "New config equals bad config, try next test\n";
2987 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002988 }
2989
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002990 if ($runtest) {
2991 $ret = compare_configs \%new_configs, \%good_configs;
2992 if (!$ret) {
2993 doprint "New config equals good config, try next test\n";
2994 $runtest = 0;
2995 }
2996 }
2997
2998 %{$nc} = %new_configs;
2999
3000 return $runtest;
3001}
3002
3003sub run_config_bisect {
3004 my ($pgood, $pbad) = @_;
3005
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003006 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003007
3008 my %good_configs = %{$pgood};
3009 my %bad_configs = %{$pbad};
3010
3011 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
3012 my %b_configs = diff_configs \%good_configs, \%bad_configs;
3013 my %g_configs = diff_configs \%bad_configs, \%good_configs;
3014
3015 my @diff_arr = keys %diff_configs;
3016 my $len_diff = $#diff_arr + 1;
3017
3018 my @b_arr = keys %b_configs;
3019 my $len_b = $#b_arr + 1;
3020
3021 my @g_arr = keys %g_configs;
3022 my $len_g = $#g_arr + 1;
3023
3024 my $runtest = 1;
3025 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003026 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003027
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003028 # First, lets get it down to a single subset.
3029 # Is the problem with a difference in values?
3030 # Is the problem with a missing config?
3031 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003032
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003033 # Enable all of one set and see if we get a new bad
3034 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003035
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003036 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003037
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003038 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003039
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003040 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003041
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003042 if ($len_diff > 0) {
3043 if ($len_b > 0 || $len_g > 0) {
3044 my %tmp_config = %bad_configs;
3045
3046 doprint "Set tmp config to be bad config with good config values\n";
3047 foreach my $item (@diff_arr) {
3048 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003049 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003050
3051 $runtest = process_new_config \%tmp_config, \%new_configs,
3052 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003053 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003054 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003055
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003056 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003057
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003058 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003059 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003060 return 1;
3061 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003062 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003063
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003064 my $half = int($#diff_arr / 2);
3065 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003066
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003067 doprint "Settings bisect with top half:\n";
3068 doprint "Set tmp config to be bad config with some good config values\n";
3069 foreach my $item (@tophalf) {
3070 $tmp_config{$item} = $good_configs{$item};
3071 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003072
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003073 $runtest = process_new_config \%tmp_config, \%new_configs,
3074 \%good_configs, \%bad_configs;
3075
3076 if (!$runtest) {
3077 my %tmp_config = %bad_configs;
3078
3079 doprint "Try bottom half\n";
3080
3081 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3082
3083 foreach my $item (@bottomhalf) {
3084 $tmp_config{$item} = $good_configs{$item};
3085 }
3086
3087 $runtest = process_new_config \%tmp_config, \%new_configs,
3088 \%good_configs, \%bad_configs;
3089 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003090 }
3091
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003092 if ($runtest) {
3093 $ret = run_config_bisect_test $type;
3094 if ($ret) {
3095 doprint "NEW GOOD CONFIG\n";
3096 %good_configs = %new_configs;
3097 run_command "mv $good_config ${good_config}.last";
3098 save_config \%good_configs, $good_config;
3099 %{$pgood} = %good_configs;
3100 } else {
3101 doprint "NEW BAD CONFIG\n";
3102 %bad_configs = %new_configs;
3103 run_command "mv $bad_config ${bad_config}.last";
3104 save_config \%bad_configs, $bad_config;
3105 %{$pbad} = %bad_configs;
3106 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003107 return 0;
3108 }
3109
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003110 fail "Hmm, need to do a mix match?\n";
3111 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003112}
3113
3114sub config_bisect {
3115 my ($i) = @_;
3116
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003117 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003118 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003119
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003120 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003121
Steven Rostedt30f75da2011-06-13 10:35:35 -04003122 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003123 $good_config = $config_bisect_good;
3124 } elsif (defined($minconfig)) {
3125 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003126 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003127 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003128 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003129 if (!$ret) {
3130 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3131 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003132 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003133 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003134 }
3135
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003136 # we don't want min configs to cause issues here.
3137 doprint "Disabling 'MIN_CONFIG' for this test\n";
3138 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003139
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003140 my %good_configs;
3141 my %bad_configs;
3142 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003143
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003144 doprint "Run good configs through make oldconfig\n";
3145 assign_configs \%tmp_configs, $good_config;
3146 create_config "$good_config", \%tmp_configs;
3147 assign_configs \%good_configs, $output_config;
3148
3149 doprint "Run bad configs through make oldconfig\n";
3150 assign_configs \%tmp_configs, $bad_config;
3151 create_config "$bad_config", \%tmp_configs;
3152 assign_configs \%bad_configs, $output_config;
3153
3154 $good_config = "$tmpdir/good_config";
3155 $bad_config = "$tmpdir/bad_config";
3156
3157 save_config \%good_configs, $good_config;
3158 save_config \%bad_configs, $bad_config;
3159
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003160
3161 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3162 if ($config_bisect_check ne "good") {
3163 doprint "Testing bad config\n";
3164
3165 $ret = run_bisect_test $type, "useconfig:$bad_config";
3166 if ($ret) {
3167 fail "Bad config succeeded when expected to fail!";
3168 return 0;
3169 }
3170 }
3171 if ($config_bisect_check ne "bad") {
3172 doprint "Testing good config\n";
3173
3174 $ret = run_bisect_test $type, "useconfig:$good_config";
3175 if (!$ret) {
3176 fail "Good config failed when expected to succeed!";
3177 return 0;
3178 }
3179 }
3180 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003181
Steven Rostedt0a05c762010-11-08 11:14:10 -05003182 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003183 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003184 } while (!$ret);
3185
3186 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003187
3188 success $i;
3189}
3190
Steven Rostedt27d934b2011-05-20 09:18:18 -04003191sub patchcheck_reboot {
3192 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003193 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003194}
3195
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003196sub patchcheck {
3197 my ($i) = @_;
3198
3199 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003200 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003201 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003202 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003203
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003204 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003205
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003206 my $cherry = $patchcheck_cherry;
3207 if (!defined($cherry)) {
3208 $cherry = 0;
3209 }
3210
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003211 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003212 if (defined($patchcheck_end)) {
3213 $end = $patchcheck_end;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003214 } elsif ($cherry) {
3215 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003216 }
3217
Steven Rostedta57419b2010-11-02 15:13:54 -04003218 # Get the true sha1's since we can use things like HEAD~3
3219 $start = get_sha1($start);
3220 $end = get_sha1($end);
3221
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003222 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003223
3224 # Can't have a test without having a test to run
3225 if ($type eq "test" && !defined($run_test)) {
3226 $type = "boot";
3227 }
3228
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003229 if ($cherry) {
3230 open (IN, "git cherry -v $start $end|") or
3231 dodie "could not get git list";
3232 } else {
3233 open (IN, "git log --pretty=oneline $end|") or
3234 dodie "could not get git list";
3235 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003236
3237 my @list;
3238
3239 while (<IN>) {
3240 chomp;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003241 # git cherry adds a '+' we want to remove
3242 s/^\+ //;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003243 $list[$#list+1] = $_;
3244 last if (/^$start/);
3245 }
3246 close(IN);
3247
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003248 if (!$cherry) {
3249 if ($list[$#list] !~ /^$start/) {
3250 fail "SHA1 $start not found";
3251 }
3252
3253 # go backwards in the list
3254 @list = reverse @list;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003255 }
3256
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003257 doprint("Going to test the following commits:\n");
3258 foreach my $l (@list) {
3259 doprint "$l\n";
3260 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003261
3262 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003263 my %ignored_warnings;
3264
3265 if (defined($ignore_warnings)) {
3266 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3267 $ignored_warnings{$sha1} = 1;
3268 }
3269 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003270
3271 $in_patchcheck = 1;
3272 foreach my $item (@list) {
3273 my $sha1 = $item;
3274 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3275
3276 doprint "\nProcessing commit $item\n\n";
3277
3278 run_command "git checkout $sha1" or
3279 die "Failed to checkout $sha1";
3280
3281 # only clean on the first and last patch
3282 if ($item eq $list[0] ||
3283 $item eq $list[$#list]) {
3284 $noclean = $save_clean;
3285 } else {
3286 $noclean = 1;
3287 }
3288
3289 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003290 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003291 } else {
3292 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003293 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003294 }
3295
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003296 # No need to do per patch checking if warnings file exists
3297 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3298 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003299 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003300
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003301 check_buildlog or return 0;
3302
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003303 next if ($type eq "build");
3304
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003305 my $failed = 0;
3306
Steven Rostedtddf607e2011-06-14 20:49:13 -04003307 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003308
3309 if (!$failed && $type ne "boot"){
3310 do_run_test or $failed = 1;
3311 }
3312 end_monitor;
3313 return 0 if ($failed);
3314
Steven Rostedt27d934b2011-05-20 09:18:18 -04003315 patchcheck_reboot;
3316
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003317 }
3318 $in_patchcheck = 0;
3319 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003320
3321 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003322}
3323
Steven Rostedtb9066f62011-07-15 21:25:24 -04003324my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003325my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003326my $iflevel = 0;
3327my @ifdeps;
3328
3329# prevent recursion
3330my %read_kconfigs;
3331
Steven Rostedtac6974c2011-10-04 09:40:17 -04003332sub add_dep {
3333 # $config depends on $dep
3334 my ($config, $dep) = @_;
3335
3336 if (defined($depends{$config})) {
3337 $depends{$config} .= " " . $dep;
3338 } else {
3339 $depends{$config} = $dep;
3340 }
3341
3342 # record the number of configs depending on $dep
3343 if (defined $depcount{$dep}) {
3344 $depcount{$dep}++;
3345 } else {
3346 $depcount{$dep} = 1;
3347 }
3348}
3349
Steven Rostedtb9066f62011-07-15 21:25:24 -04003350# taken from streamline_config.pl
3351sub read_kconfig {
3352 my ($kconfig) = @_;
3353
3354 my $state = "NONE";
3355 my $config;
3356 my @kconfigs;
3357
3358 my $cont = 0;
3359 my $line;
3360
3361
3362 if (! -f $kconfig) {
3363 doprint "file $kconfig does not exist, skipping\n";
3364 return;
3365 }
3366
3367 open(KIN, "$kconfig")
3368 or die "Can't open $kconfig";
3369 while (<KIN>) {
3370 chomp;
3371
3372 # Make sure that lines ending with \ continue
3373 if ($cont) {
3374 $_ = $line . " " . $_;
3375 }
3376
3377 if (s/\\$//) {
3378 $cont = 1;
3379 $line = $_;
3380 next;
3381 }
3382
3383 $cont = 0;
3384
3385 # collect any Kconfig sources
3386 if (/^source\s*"(.*)"/) {
3387 $kconfigs[$#kconfigs+1] = $1;
3388 }
3389
3390 # configs found
3391 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3392 $state = "NEW";
3393 $config = $2;
3394
3395 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003396 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003397 }
3398
3399 # collect the depends for the config
3400 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3401
Steven Rostedtac6974c2011-10-04 09:40:17 -04003402 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003403
3404 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003405 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3406
3407 # selected by depends on config
3408 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003409
3410 # Check for if statements
3411 } elsif (/^if\s+(.*\S)\s*$/) {
3412 my $deps = $1;
3413 # remove beginning and ending non text
3414 $deps =~ s/^[^a-zA-Z0-9_]*//;
3415 $deps =~ s/[^a-zA-Z0-9_]*$//;
3416
3417 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3418
3419 $ifdeps[$iflevel++] = join ':', @deps;
3420
3421 } elsif (/^endif/) {
3422
3423 $iflevel-- if ($iflevel);
3424
3425 # stop on "help"
3426 } elsif (/^\s*help\s*$/) {
3427 $state = "NONE";
3428 }
3429 }
3430 close(KIN);
3431
3432 # read in any configs that were found.
3433 foreach $kconfig (@kconfigs) {
3434 if (!defined($read_kconfigs{$kconfig})) {
3435 $read_kconfigs{$kconfig} = 1;
3436 read_kconfig("$builddir/$kconfig");
3437 }
3438 }
3439}
3440
3441sub read_depends {
3442 # find out which arch this is by the kconfig file
3443 open (IN, $output_config)
3444 or dodie "Failed to read $output_config";
3445 my $arch;
3446 while (<IN>) {
3447 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3448 $arch = $1;
3449 last;
3450 }
3451 }
3452 close IN;
3453
3454 if (!defined($arch)) {
3455 doprint "Could not find arch from config file\n";
3456 doprint "no dependencies used\n";
3457 return;
3458 }
3459
3460 # arch is really the subarch, we need to know
3461 # what directory to look at.
3462 if ($arch eq "i386" || $arch eq "x86_64") {
3463 $arch = "x86";
3464 } elsif ($arch =~ /^tile/) {
3465 $arch = "tile";
3466 }
3467
3468 my $kconfig = "$builddir/arch/$arch/Kconfig";
3469
3470 if (! -f $kconfig && $arch =~ /\d$/) {
3471 my $orig = $arch;
3472 # some subarchs have numbers, truncate them
3473 $arch =~ s/\d*$//;
3474 $kconfig = "$builddir/arch/$arch/Kconfig";
3475 if (! -f $kconfig) {
3476 doprint "No idea what arch dir $orig is for\n";
3477 doprint "no dependencies used\n";
3478 return;
3479 }
3480 }
3481
3482 read_kconfig($kconfig);
3483}
3484
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003485sub make_new_config {
3486 my @configs = @_;
3487
3488 open (OUT, ">$output_config")
3489 or dodie "Failed to write $output_config";
3490
3491 foreach my $config (@configs) {
3492 print OUT "$config\n";
3493 }
3494 close OUT;
3495}
3496
Steven Rostedtac6974c2011-10-04 09:40:17 -04003497sub chomp_config {
3498 my ($config) = @_;
3499
3500 $config =~ s/CONFIG_//;
3501
3502 return $config;
3503}
3504
Steven Rostedtb9066f62011-07-15 21:25:24 -04003505sub get_depends {
3506 my ($dep) = @_;
3507
Steven Rostedtac6974c2011-10-04 09:40:17 -04003508 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003509
3510 $dep = $depends{"$kconfig"};
3511
3512 # the dep string we have saves the dependencies as they
3513 # were found, including expressions like ! && ||. We
3514 # want to split this out into just an array of configs.
3515
3516 my $valid = "A-Za-z_0-9";
3517
3518 my @configs;
3519
3520 while ($dep =~ /[$valid]/) {
3521
3522 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3523 my $conf = "CONFIG_" . $1;
3524
3525 $configs[$#configs + 1] = $conf;
3526
3527 $dep =~ s/^[^$valid]*[$valid]+//;
3528 } else {
3529 die "this should never happen";
3530 }
3531 }
3532
3533 return @configs;
3534}
3535
3536my %min_configs;
3537my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003538my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003539my %processed_configs;
3540my %nochange_config;
3541
3542sub test_this_config {
3543 my ($config) = @_;
3544
3545 my $found;
3546
3547 # if we already processed this config, skip it
3548 if (defined($processed_configs{$config})) {
3549 return undef;
3550 }
3551 $processed_configs{$config} = 1;
3552
3553 # if this config failed during this round, skip it
3554 if (defined($nochange_config{$config})) {
3555 return undef;
3556 }
3557
Steven Rostedtac6974c2011-10-04 09:40:17 -04003558 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003559
3560 # Test dependencies first
3561 if (defined($depends{"$kconfig"})) {
3562 my @parents = get_depends $config;
3563 foreach my $parent (@parents) {
3564 # if the parent is in the min config, check it first
3565 next if (!defined($min_configs{$parent}));
3566 $found = test_this_config($parent);
3567 if (defined($found)) {
3568 return $found;
3569 }
3570 }
3571 }
3572
3573 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003574 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003575 # .config to make sure it is missing the config that
3576 # we had before
3577 my %configs = %min_configs;
3578 delete $configs{$config};
3579 make_new_config ((values %configs), (values %keep_configs));
3580 make_oldconfig;
3581 undef %configs;
3582 assign_configs \%configs, $output_config;
3583
Steven Rostedt (Red Hat)9972fc02014-10-22 10:11:47 -04003584 if (!defined($configs{$config}) || $configs{$config} =~ /^#/) {
3585 return $config;
3586 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003587
3588 doprint "disabling config $config did not change .config\n";
3589
3590 $nochange_config{$config} = 1;
3591
3592 return undef;
3593}
3594
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003595sub make_min_config {
3596 my ($i) = @_;
3597
Steven Rostedtccc513b2012-05-21 17:13:40 -04003598 my $type = $minconfig_type;
3599 if ($type ne "boot" && $type ne "test") {
3600 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3601 " make_min_config works only with 'boot' and 'test'\n" and return;
3602 }
3603
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003604 if (!defined($output_minconfig)) {
3605 fail "OUTPUT_MIN_CONFIG not defined" and return;
3606 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003607
3608 # If output_minconfig exists, and the start_minconfig
3609 # came from min_config, than ask if we should use
3610 # that instead.
3611 if (-f $output_minconfig && !$start_minconfig_defined) {
3612 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003613 if (!defined($use_output_minconfig)) {
3614 if (read_yn " Use it as minconfig?") {
3615 $start_minconfig = $output_minconfig;
3616 }
3617 } elsif ($use_output_minconfig > 0) {
3618 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003619 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003620 } else {
3621 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003622 }
3623 }
3624
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003625 if (!defined($start_minconfig)) {
3626 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3627 }
3628
Steven Rostedt35ce5952011-07-15 21:57:25 -04003629 my $temp_config = "$tmpdir/temp_config";
3630
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003631 # First things first. We build an allnoconfig to find
3632 # out what the defaults are that we can't touch.
3633 # Some are selections, but we really can't handle selections.
3634
3635 my $save_minconfig = $minconfig;
3636 undef $minconfig;
3637
3638 run_command "$make allnoconfig" or return 0;
3639
Steven Rostedtb9066f62011-07-15 21:25:24 -04003640 read_depends;
3641
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003642 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003643
Steven Rostedt43d1b652011-07-15 22:01:56 -04003644 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003645 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003646
3647 if (defined($ignore_config)) {
3648 # make sure the file exists
3649 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003650 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003651 }
3652
Steven Rostedt43d1b652011-07-15 22:01:56 -04003653 %keep_configs = %save_configs;
3654
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003655 doprint "Load initial configs from $start_minconfig\n";
3656
3657 # Look at the current min configs, and save off all the
3658 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003659 assign_configs \%min_configs, $start_minconfig;
3660
3661 my @config_keys = keys %min_configs;
3662
Steven Rostedtac6974c2011-10-04 09:40:17 -04003663 # All configs need a depcount
3664 foreach my $config (@config_keys) {
3665 my $kconfig = chomp_config $config;
3666 if (!defined $depcount{$kconfig}) {
3667 $depcount{$kconfig} = 0;
3668 }
3669 }
3670
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003671 # Remove anything that was set by the make allnoconfig
3672 # we shouldn't need them as they get set for us anyway.
3673 foreach my $config (@config_keys) {
3674 # Remove anything in the ignore_config
3675 if (defined($keep_configs{$config})) {
3676 my $file = $ignore_config;
3677 $file =~ s,.*/(.*?)$,$1,;
3678 doprint "$config set by $file ... ignored\n";
3679 delete $min_configs{$config};
3680 next;
3681 }
3682 # But make sure the settings are the same. If a min config
3683 # sets a selection, we do not want to get rid of it if
3684 # it is not the same as what we have. Just move it into
3685 # the keep configs.
3686 if (defined($config_ignore{$config})) {
3687 if ($config_ignore{$config} ne $min_configs{$config}) {
3688 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3689 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3690 $keep_configs{$config} = $min_configs{$config};
3691 } else {
3692 doprint "$config set by allnoconfig ... ignored\n";
3693 }
3694 delete $min_configs{$config};
3695 }
3696 }
3697
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003698 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003699 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003700
3701 while (!$done) {
3702
3703 my $config;
3704 my $found;
3705
3706 # Now disable each config one by one and do a make oldconfig
3707 # till we find a config that changes our list.
3708
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003709 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003710
3711 # Sort keys by who is most dependent on
3712 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3713 @test_configs ;
3714
3715 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003716 my $reset = 1;
3717 for (my $i = 0; $i < $#test_configs; $i++) {
3718 if (!defined($nochange_config{$test_configs[0]})) {
3719 $reset = 0;
3720 last;
3721 }
3722 # This config didn't change the .config last time.
3723 # Place it at the end
3724 my $config = shift @test_configs;
3725 push @test_configs, $config;
3726 }
3727
3728 # if every test config has failed to modify the .config file
3729 # in the past, then reset and start over.
3730 if ($reset) {
3731 undef %nochange_config;
3732 }
3733
Steven Rostedtb9066f62011-07-15 21:25:24 -04003734 undef %processed_configs;
3735
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003736 foreach my $config (@test_configs) {
3737
Steven Rostedtb9066f62011-07-15 21:25:24 -04003738 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003739
Steven Rostedtb9066f62011-07-15 21:25:24 -04003740 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003741
3742 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003743 }
3744
3745 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003746 # we could have failed due to the nochange_config hash
3747 # reset and try again
3748 if (!$take_two) {
3749 undef %nochange_config;
3750 $take_two = 1;
3751 next;
3752 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003753 doprint "No more configs found that we can disable\n";
3754 $done = 1;
3755 last;
3756 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003757 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003758
3759 $config = $found;
3760
3761 doprint "Test with $config disabled\n";
3762
3763 # set in_bisect to keep build and monitor from dieing
3764 $in_bisect = 1;
3765
3766 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003767 build "oldconfig" or $failed = 1;
3768 if (!$failed) {
3769 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003770
3771 if ($type eq "test" && !$failed) {
3772 do_run_test or $failed = 1;
3773 }
3774
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003775 end_monitor;
3776 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003777
3778 $in_bisect = 0;
3779
3780 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003781 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003782 # this config is needed, add it to the ignore list.
3783 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003784 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003785 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003786
3787 # update new ignore configs
3788 if (defined($ignore_config)) {
3789 open (OUT, ">$temp_config")
3790 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003791 foreach my $config (keys %save_configs) {
3792 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003793 }
3794 close OUT;
3795 run_command "mv $temp_config $ignore_config" or
3796 dodie "failed to copy update to $ignore_config";
3797 }
3798
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003799 } else {
3800 # We booted without this config, remove it from the minconfigs.
3801 doprint "$config is not needed, disabling\n";
3802
3803 delete $min_configs{$config};
3804
3805 # Also disable anything that is not enabled in this config
3806 my %configs;
3807 assign_configs \%configs, $output_config;
3808 my @config_keys = keys %min_configs;
3809 foreach my $config (@config_keys) {
3810 if (!defined($configs{$config})) {
3811 doprint "$config is not set, disabling\n";
3812 delete $min_configs{$config};
3813 }
3814 }
3815
3816 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003817 open (OUT, ">$temp_config")
3818 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003819 foreach my $config (keys %keep_configs) {
3820 print OUT "$keep_configs{$config}\n";
3821 }
3822 foreach my $config (keys %min_configs) {
3823 print OUT "$min_configs{$config}\n";
3824 }
3825 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003826
3827 run_command "mv $temp_config $output_minconfig" or
3828 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003829 }
3830
3831 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003832 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003833 }
3834
3835 success $i;
3836 return 1;
3837}
3838
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003839sub make_warnings_file {
3840 my ($i) = @_;
3841
3842 if (!defined($warnings_file)) {
3843 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3844 }
3845
3846 if ($build_type eq "nobuild") {
3847 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3848 }
3849
3850 build $build_type or dodie "Failed to build";
3851
3852 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3853
3854 open(IN, $buildlog) or dodie "Can't open $buildlog";
3855 while (<IN>) {
3856
3857 # Some compilers use UTF-8 extended for quotes
3858 # for distcc heterogeneous systems, this causes issues
3859 s/$utf8_quote/'/g;
3860
3861 if (/$check_build_re/) {
3862 print OUT;
3863 }
3864 }
3865 close(IN);
3866
3867 close(OUT);
3868
3869 success $i;
3870}
3871
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09003872$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003873
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003874if ($#ARGV == 0) {
3875 $ktest_config = $ARGV[0];
3876 if (! -f $ktest_config) {
3877 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003878 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003879 exit 0;
3880 }
3881 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003882}
3883
3884if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003885 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003886 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003887 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3888 print OUT << "EOF"
3889# Generated by ktest.pl
3890#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003891
3892# PWD is a ktest.pl variable that will result in the process working
3893# directory that ktest.pl is executed in.
3894
3895# THIS_DIR is automatically assigned the PWD of the path that generated
3896# the config file. It is best to use this variable when assigning other
3897# directory paths within this directory. This allows you to easily
3898# move the test cases to other locations or to other machines.
3899#
3900THIS_DIR := $variable{"PWD"}
3901
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003902# Define each test with TEST_START
3903# The config options below it will override the defaults
3904TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003905TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003906
3907DEFAULTS
3908EOF
3909;
3910 close(OUT);
3911}
3912read_config $ktest_config;
3913
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003914if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003915 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003916}
3917
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003918# Append any configs entered in manually to the config file.
3919my @new_configs = keys %entered_configs;
3920if ($#new_configs >= 0) {
3921 print "\nAppending entered in configs to $ktest_config\n";
3922 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3923 foreach my $config (@new_configs) {
3924 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003925 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003926 }
3927}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003928
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003929if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3930 unlink $opt{"LOG_FILE"};
3931}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003932
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003933doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3934
Steven Rostedta57419b2010-11-02 15:13:54 -04003935for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3936
3937 if (!$i) {
3938 doprint "DEFAULT OPTIONS:\n";
3939 } else {
3940 doprint "\nTEST $i OPTIONS";
3941 if (defined($repeat_tests{$i})) {
3942 $repeat = $repeat_tests{$i};
3943 doprint " ITERATE $repeat";
3944 }
3945 doprint "\n";
3946 }
3947
3948 foreach my $option (sort keys %opt) {
3949
3950 if ($option =~ /\[(\d+)\]$/) {
3951 next if ($i != $1);
3952 } else {
3953 next if ($i);
3954 }
3955
3956 doprint "$option = $opt{$option}\n";
3957 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003958}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003959
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003960sub option_defined {
3961 my ($option) = @_;
3962
3963 if (defined($opt{$option}) && $opt{$option} !~ /^\s*$/) {
3964 return 1;
3965 }
3966
3967 return 0;
3968}
3969
Steven Rostedt2a625122011-05-20 15:48:59 -04003970sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003971 my ($name, $i) = @_;
3972
3973 my $option = "$name\[$i\]";
3974
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003975 if (option_defined($option)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003976 return $opt{$option};
3977 }
3978
Steven Rostedta57419b2010-11-02 15:13:54 -04003979 foreach my $test (keys %repeat_tests) {
3980 if ($i >= $test &&
3981 $i < $test + $repeat_tests{$test}) {
3982 $option = "$name\[$test\]";
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003983 if (option_defined($option)) {
Steven Rostedta57419b2010-11-02 15:13:54 -04003984 return $opt{$option};
3985 }
3986 }
3987 }
3988
Steven Rostedt (Red Hat)22c37a92014-11-21 16:21:25 -05003989 if (option_defined($name)) {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003990 return $opt{$name};
3991 }
3992
3993 return undef;
3994}
3995
Steven Rostedt2a625122011-05-20 15:48:59 -04003996sub set_test_option {
3997 my ($name, $i) = @_;
3998
3999 my $option = __set_test_option($name, $i);
4000 return $option if (!defined($option));
4001
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05004002 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04004003}
4004
Steven Rostedt2545eb62010-11-02 15:01:32 -04004005# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04004006for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04004007
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004008 # Do not reboot on failing test options
4009 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004010 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004011
Steven Rostedt683a3e62012-05-18 13:34:35 -04004012 $have_version = 0;
4013
Steven Rostedt576f6272010-11-02 14:58:38 -04004014 $iteration = $i;
4015
Steven Rostedtc1434dc2012-07-20 22:39:16 -04004016 undef %force_config;
4017
Steven Rostedta75fece2010-11-02 14:58:27 -04004018 my $makecmd = set_test_option("MAKE_CMD", $i);
4019
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004020 $outputdir = set_test_option("OUTPUT_DIR", $i);
4021 $builddir = set_test_option("BUILD_DIR", $i);
4022
4023 chdir $builddir || die "can't change directory to $builddir";
4024
4025 if (!-d $outputdir) {
4026 mkpath($outputdir) or
4027 die "can't create $outputdir";
4028 }
4029
4030 $make = "$makecmd O=$outputdir";
4031
Steven Rostedt9cc9e092011-12-22 21:37:22 -05004032 # Load all the options into their mapped variable names
4033 foreach my $opt (keys %option_map) {
4034 ${$option_map{$opt}} = set_test_option($opt, $i);
4035 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004036
Steven Rostedt35ce5952011-07-15 21:57:25 -04004037 $start_minconfig_defined = 1;
4038
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004039 # The first test may override the PRE_KTEST option
4040 if (defined($pre_ktest) && $i == 1) {
4041 doprint "\n";
4042 run_command $pre_ktest;
4043 }
4044
4045 # Any test can override the POST_KTEST option
4046 # The last test takes precedence.
4047 if (defined($post_ktest)) {
4048 $final_post_ktest = $post_ktest;
4049 }
4050
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004051 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004052 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004053 $start_minconfig = $minconfig;
4054 }
4055
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004056 if (!-d $tmpdir) {
4057 mkpath($tmpdir) or
4058 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004059 }
4060
Steven Rostedte48c5292010-11-02 14:35:37 -04004061 $ENV{"SSH_USER"} = $ssh_user;
4062 $ENV{"MACHINE"} = $machine;
4063
Steven Rostedta75fece2010-11-02 14:58:27 -04004064 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304065 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004066 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004067 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004068
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004069 if (!$buildonly) {
4070 $target = "$ssh_user\@$machine";
4071 if ($reboot_type eq "grub") {
4072 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004073 } elsif ($reboot_type eq "grub2") {
4074 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4075 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004076 } elsif ($reboot_type eq "syslinux") {
4077 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004078 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004079 }
4080
4081 my $run_type = $build_type;
4082 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004083 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004084 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004085 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004086 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004087 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004088 } elsif ($test_type eq "make_min_config") {
4089 $run_type = "";
4090 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004091 $run_type = "";
4092 }
4093
Steven Rostedta75fece2010-11-02 14:58:27 -04004094 # mistake in config file?
4095 if (!defined($run_type)) {
4096 $run_type = "ERROR";
4097 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004098
Steven Rostedte0a87422011-09-30 17:50:48 -04004099 my $installme = "";
4100 $installme = " no_install" if ($no_install);
4101
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004102 my $name = "";
4103
4104 if (defined($test_name)) {
4105 $name = " ($test_name)";
4106 }
4107
Steven Rostedt2545eb62010-11-02 15:01:32 -04004108 doprint "\n\n";
Steven Rostedt (Red Hat)18656c72014-11-21 19:28:24 -05004109 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 -04004110
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004111 if (defined($pre_test)) {
4112 run_command $pre_test;
4113 }
4114
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004115 unlink $dmesg;
4116 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304117 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004118
Steven Rostedt250bae82011-07-15 22:05:59 -04004119 if (defined($addconfig)) {
4120 my $min = $minconfig;
4121 if (!defined($minconfig)) {
4122 $min = "";
4123 }
4124 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004125 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004126 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004127 }
4128
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004129 if (defined($checkout)) {
4130 run_command "git checkout $checkout" or
4131 die "failed to checkout $checkout";
4132 }
4133
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004134 $no_reboot = 0;
4135
Steven Rostedt648a1822012-03-21 11:18:27 -04004136 # A test may opt to not reboot the box
4137 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004138 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004139 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004140
Steven Rostedta75fece2010-11-02 14:58:27 -04004141 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004142 bisect $i;
4143 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004144 } elsif ($test_type eq "config_bisect") {
4145 config_bisect $i;
4146 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004147 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004148 patchcheck $i;
4149 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004150 } elsif ($test_type eq "make_min_config") {
4151 make_min_config $i;
4152 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004153 } elsif ($test_type eq "make_warnings_file") {
4154 $no_reboot = 1;
4155 make_warnings_file $i;
4156 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004157 }
4158
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004159 if ($build_type ne "nobuild") {
4160 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004161 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004162 }
4163
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004164 if ($test_type eq "install") {
4165 get_version;
4166 install;
4167 success $i;
4168 next;
4169 }
4170
Steven Rostedta75fece2010-11-02 14:58:27 -04004171 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004172 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004173 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004174
4175 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4176 do_run_test or $failed = 1;
4177 }
4178 end_monitor;
4179 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004180 }
4181
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004182 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004183}
4184
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004185if (defined($final_post_ktest)) {
4186 run_command $final_post_ktest;
4187}
4188
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004189if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004190 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004191} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004192 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004193} elsif (defined($switch_to_good)) {
4194 # still need to get to the good kernel
4195 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004196}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004197
Steven Rostedt648a1822012-03-21 11:18:27 -04004198
Steven Rostedte48c5292010-11-02 14:35:37 -04004199doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4200
Steven Rostedt2545eb62010-11-02 15:01:32 -04004201exit 0;