blob: c518b0fb6d0190e655acca3807409d270875a0f0 [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 Rostedt21a96792010-11-08 16:45:50 -0500687 if ($rvalue =~ /^\s*$/) {
688 delete $opt{$lvalue};
689 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500690 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500691 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400692}
693
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500694sub set_eval {
695 my ($lvalue, $rvalue, $name) = @_;
696
697 my $prvalue = process_variables($rvalue);
698 my $arr;
699
700 if (defined($evals{$lvalue})) {
701 $arr = $evals{$lvalue};
702 } else {
703 $arr = [];
704 $evals{$lvalue} = $arr;
705 }
706
707 push @{$arr}, $rvalue;
708}
709
Steven Rostedt77d942c2011-05-20 13:36:58 -0400710sub set_variable {
711 my ($lvalue, $rvalue) = @_;
712
713 if ($rvalue =~ /^\s*$/) {
714 delete $variable{$lvalue};
715 } else {
716 $rvalue = process_variables($rvalue);
717 $variable{$lvalue} = $rvalue;
718 }
719}
720
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400721sub process_compare {
722 my ($lval, $cmp, $rval) = @_;
723
724 # remove whitespace
725
726 $lval =~ s/^\s*//;
727 $lval =~ s/\s*$//;
728
729 $rval =~ s/^\s*//;
730 $rval =~ s/\s*$//;
731
732 if ($cmp eq "==") {
733 return $lval eq $rval;
734 } elsif ($cmp eq "!=") {
735 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400736 } elsif ($cmp eq "=~") {
737 return $lval =~ m/$rval/;
738 } elsif ($cmp eq "!~") {
739 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400740 }
741
742 my $statement = "$lval $cmp $rval";
743 my $ret = eval $statement;
744
745 # $@ stores error of eval
746 if ($@) {
747 return -1;
748 }
749
750 return $ret;
751}
752
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400753sub value_defined {
754 my ($val) = @_;
755
756 return defined($variable{$2}) ||
757 defined($opt{$2});
758}
759
Steven Rostedt8d735212011-10-17 11:36:44 -0400760my $d = 0;
761sub process_expression {
762 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400763
Steven Rostedt8d735212011-10-17 11:36:44 -0400764 my $c = $d++;
765
766 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
767 my $express = $1;
768
769 if (process_expression($name, $express)) {
770 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
771 } else {
772 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
773 }
774 }
775
776 $d--;
777 my $OR = "\\|\\|";
778 my $AND = "\\&\\&";
779
780 while ($val =~ s/^(.*?)($OR|$AND)//) {
781 my $express = $1;
782 my $op = $2;
783
784 if (process_expression($name, $express)) {
785 if ($op eq "||") {
786 return 1;
787 }
788 } else {
789 if ($op eq "&&") {
790 return 0;
791 }
792 }
793 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400794
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400795 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400796 my $ret = process_compare($1, $2, $3);
797 if ($ret < 0) {
798 die "$name: $.: Unable to process comparison\n";
799 }
800 return $ret;
801 }
802
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400803 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
804 if (defined $1) {
805 return !value_defined($2);
806 } else {
807 return value_defined($2);
808 }
809 }
810
Steven Rostedt45d73a52011-09-30 19:44:53 -0400811 if ($val =~ /^\s*0\s*$/) {
812 return 0;
813 } elsif ($val =~ /^\s*\d+\s*$/) {
814 return 1;
815 }
816
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400817 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400818}
819
820sub process_if {
821 my ($name, $value) = @_;
822
823 # Convert variables and replace undefined ones with 0
824 my $val = process_variables($value, 1);
825 my $ret = process_expression $name, $val;
826
827 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400828}
829
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400830sub __read_config {
831 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400832
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400833 my $in;
834 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400835
Steven Rostedta57419b2010-11-02 15:13:54 -0400836 my $name = $config;
837 $name =~ s,.*/(.*),$1,;
838
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400839 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400840 my $default = 1;
841 my $repeat = 1;
842 my $num_tests_set = 0;
843 my $skip = 0;
844 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400845 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400846 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400847 my $if = 0;
848 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400849 my $override = 0;
850
851 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400852
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400853 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400854
855 # ignore blank lines and comments
856 next if (/^\s*$/ || /\s*\#/);
857
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400858 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400859
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400860 my $type = $1;
861 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400862 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400863
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400864 my $old_test_num;
865 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400866 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400867
868 if ($type eq "TEST_START") {
869
870 if ($num_tests_set) {
871 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
872 }
873
874 $old_test_num = $test_num;
875 $old_repeat = $repeat;
876
877 $test_num += $repeat;
878 $default = 0;
879 $repeat = 1;
880 } else {
881 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400882 }
883
Steven Rostedta9f84422011-10-17 11:06:29 -0400884 # If SKIP is anywhere in the line, the command will be skipped
885 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400886 $skip = 1;
887 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400888 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400889 $skip = 0;
890 }
891
Steven Rostedta9f84422011-10-17 11:06:29 -0400892 if ($rest =~ s/\sELSE\b//) {
893 if (!$if) {
894 die "$name: $.: ELSE found with out matching IF section\n$_";
895 }
896 $if = 0;
897
898 if ($if_set) {
899 $skip = 1;
900 } else {
901 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400902 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400903 }
904
Steven Rostedta9f84422011-10-17 11:06:29 -0400905 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400906 if (process_if($name, $1)) {
907 $if_set = 1;
908 } else {
909 $skip = 1;
910 }
911 $if = 1;
912 } else {
913 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400914 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400915 }
916
Steven Rostedta9f84422011-10-17 11:06:29 -0400917 if (!$skip) {
918 if ($type eq "TEST_START") {
919 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
920 $repeat = $1;
921 $repeat_tests{"$test_num"} = $repeat;
922 }
923 } elsif ($rest =~ s/\sOVERRIDE\b//) {
924 # DEFAULT only
925 $override = 1;
926 # Clear previous overrides
927 %overrides = ();
928 }
929 }
930
931 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400932 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400933 }
934
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400935 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400936 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400937 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400938 }
939
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400940 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400941 if (!$if) {
942 die "$name: $.: ELSE found with out matching IF section\n$_";
943 }
944 $rest = $1;
945 if ($if_set) {
946 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400947 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400948 } else {
949 $skip = 0;
950
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400951 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400952 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400953 if (process_if($name, $1)) {
954 $if_set = 1;
955 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400956 $skip = 1;
957 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400958 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400959 } else {
960 $if = 0;
961 }
962 }
963
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400964 if ($rest !~ /^\s*$/) {
965 die "$name: $.: Gargbage found after DEFAULTS\n$_";
966 }
967
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400968 } elsif (/^\s*INCLUDE\s+(\S+)/) {
969
970 next if ($skip);
971
972 if (!$default) {
973 die "$name: $.: INCLUDE can only be done in default sections\n$_";
974 }
975
976 my $file = process_variables($1);
977
978 if ($file !~ m,^/,) {
979 # check the path of the config file first
980 if ($config =~ m,(.*)/,) {
981 if (-f "$1/$file") {
982 $file = "$1/$file";
983 }
984 }
985 }
986
987 if ( ! -r $file ) {
988 die "$name: $.: Can't read file $file\n$_";
989 }
990
991 if (__read_config($file, \$test_num)) {
992 $test_case = 1;
993 }
994
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500995 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
996
997 next if ($skip);
998
999 my $lvalue = $1;
1000 my $rvalue = $2;
1001
1002 if ($default || $lvalue =~ /\[\d+\]$/) {
1003 set_eval($lvalue, $rvalue, $name);
1004 } else {
1005 my $val = "$lvalue\[$test_num\]";
1006 set_eval($val, $rvalue, $name);
1007 }
1008
Steven Rostedta57419b2010-11-02 15:13:54 -04001009 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1010
1011 next if ($skip);
1012
Steven Rostedt2545eb62010-11-02 15:01:32 -04001013 my $lvalue = $1;
1014 my $rvalue = $2;
1015
Steven Rostedta57419b2010-11-02 15:13:54 -04001016 if (!$default &&
1017 ($lvalue eq "NUM_TESTS" ||
1018 $lvalue eq "LOG_FILE" ||
1019 $lvalue eq "CLEAR_LOG")) {
1020 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001021 }
Steven Rostedta57419b2010-11-02 15:13:54 -04001022
1023 if ($lvalue eq "NUM_TESTS") {
1024 if ($test_num) {
1025 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1026 }
1027 if (!$default) {
1028 die "$name: $.: NUM_TESTS must be set in default section\n";
1029 }
1030 $num_tests_set = 1;
1031 }
1032
1033 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001034 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001035 } else {
1036 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001037 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001038
1039 if ($repeat > 1) {
1040 $repeats{$val} = $repeat;
1041 }
1042 }
Steven Rostedt77d942c2011-05-20 13:36:58 -04001043 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1044 next if ($skip);
1045
1046 my $lvalue = $1;
1047 my $rvalue = $2;
1048
1049 # process config variables.
1050 # Config variables are only active while reading the
1051 # config and can be defined anywhere. They also ignore
1052 # TEST_START and DEFAULTS, but are skipped if they are in
1053 # on of these sections that have SKIP defined.
1054 # The save variable can be
1055 # defined multiple times and the new one simply overrides
1056 # the prevous one.
1057 set_variable($lvalue, $rvalue);
1058
Steven Rostedta57419b2010-11-02 15:13:54 -04001059 } else {
1060 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001061 }
1062 }
1063
Steven Rostedta57419b2010-11-02 15:13:54 -04001064 if ($test_num) {
1065 $test_num += $repeat - 1;
1066 $opt{"NUM_TESTS"} = $test_num;
1067 }
1068
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001069 close($in);
1070
1071 $$current_test_num = $test_num;
1072
1073 return $test_case;
1074}
1075
Steven Rostedtc4261d02011-11-23 13:41:18 -05001076sub get_test_case {
1077 print "What test case would you like to run?\n";
1078 print " (build, install or boot)\n";
1079 print " Other tests are available but require editing the config file\n";
1080 my $ans = <STDIN>;
1081 chomp $ans;
1082 $default{"TEST_TYPE"} = $ans;
1083}
1084
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001085sub read_config {
1086 my ($config) = @_;
1087
1088 my $test_case;
1089 my $test_num = 0;
1090
1091 $test_case = __read_config $config, \$test_num;
1092
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001093 # make sure we have all mandatory configs
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09001094 get_mandatory_configs;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001095
Steven Rostedt0df213c2011-06-14 20:51:37 -04001096 # was a test specified?
1097 if (!$test_case) {
1098 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001099 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001100 }
1101
Steven Rostedta75fece2010-11-02 14:58:27 -04001102 # set any defaults
1103
1104 foreach my $default (keys %default) {
1105 if (!defined($opt{$default})) {
1106 $opt{$default} = $default{$default};
1107 }
1108 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001109
1110 if ($opt{"IGNORE_UNUSED"} == 1) {
1111 return;
1112 }
1113
1114 my %not_used;
1115
1116 # check if there are any stragglers (typos?)
1117 foreach my $option (keys %opt) {
1118 my $op = $option;
1119 # remove per test labels.
1120 $op =~ s/\[.*\]//;
1121 if (!exists($option_map{$op}) &&
1122 !exists($default{$op}) &&
1123 !exists($used_options{$op})) {
1124 $not_used{$op} = 1;
1125 }
1126 }
1127
1128 if (%not_used) {
1129 my $s = "s are";
1130 $s = " is" if (keys %not_used == 1);
1131 print "The following option$s not used; could be a typo:\n";
1132 foreach my $option (keys %not_used) {
1133 print "$option\n";
1134 }
1135 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1136 if (!read_yn "Do you want to continue?") {
1137 exit -1;
1138 }
1139 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001140}
1141
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001142sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001143 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001144
1145 # Add space to evaluate the character before $
1146 $option = " $option";
1147 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301148 my $repeated = 0;
1149 my $parent = 0;
1150
1151 foreach my $test (keys %repeat_tests) {
1152 if ($i >= $test &&
1153 $i < $test + $repeat_tests{$test}) {
1154
1155 $repeated = 1;
1156 $parent = $test;
1157 last;
1158 }
1159 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001160
1161 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1162 my $start = $1;
1163 my $var = $2;
1164 my $end = $3;
1165
1166 # Append beginning of line
1167 $retval = "$retval$start";
1168
1169 # If the iteration option OPT[$i] exists, then use that.
1170 # otherwise see if the default OPT (without [$i]) exists.
1171
1172 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301173 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001174
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001175 # If a variable contains itself, use the default var
1176 if (($var eq $name) && defined($opt{$var})) {
1177 $o = $opt{$var};
1178 $retval = "$retval$o";
1179 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001180 $o = $opt{$o};
1181 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301182 } elsif ($repeated && defined($opt{$parento})) {
1183 $o = $opt{$parento};
1184 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001185 } elsif (defined($opt{$var})) {
1186 $o = $opt{$var};
1187 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001188 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1189 # special option KERNEL_VERSION uses kernel version
1190 get_version();
1191 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001192 } else {
1193 $retval = "$retval\$\{$var\}";
1194 }
1195
1196 $option = $end;
1197 }
1198
1199 $retval = "$retval$option";
1200
1201 $retval =~ s/^ //;
1202
1203 return $retval;
1204}
1205
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001206sub process_evals {
1207 my ($name, $option, $i) = @_;
1208
1209 my $option_name = "$name\[$i\]";
1210 my $ev;
1211
1212 my $old_option = $option;
1213
1214 if (defined($evals{$option_name})) {
1215 $ev = $evals{$option_name};
1216 } elsif (defined($evals{$name})) {
1217 $ev = $evals{$name};
1218 } else {
1219 return $option;
1220 }
1221
1222 for my $e (@{$ev}) {
1223 eval "\$option =~ $e";
1224 }
1225
1226 if ($option ne $old_option) {
1227 doprint("$name changed from '$old_option' to '$option'\n");
1228 }
1229
1230 return $option;
1231}
1232
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001233sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001234 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001235
1236 my $prev = "";
1237
1238 # Since an option can evaluate to another option,
1239 # keep iterating until we do not evaluate any more
1240 # options.
1241 my $r = 0;
1242 while ($prev ne $option) {
1243 # Check for recursive evaluations.
1244 # 100 deep should be more than enough.
1245 if ($r++ > 100) {
1246 die "Over 100 evaluations accurred with $option\n" .
1247 "Check for recursive variables\n";
1248 }
1249 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001250 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001251 }
1252
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001253 $option = process_evals($name, $option, $i);
1254
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001255 return $option;
1256}
1257
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001258sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001259sub start_monitor;
1260sub end_monitor;
1261sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001262
1263sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001264 my ($time) = @_;
1265
Steven Rostedta4968722012-12-11 14:59:05 -05001266 # Make sure everything has been written to disk
1267 run_ssh("sync");
1268
Steven Rostedt2b803362011-09-30 18:00:23 -04001269 if (defined($time)) {
1270 start_monitor;
1271 # flush out current monitor
1272 # May contain the reboot success line
1273 wait_for_monitor 1;
1274 }
1275
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001276 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001277 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001278 if (defined($powercycle_after_reboot)) {
1279 sleep $powercycle_after_reboot;
1280 run_command "$power_cycle";
1281 }
1282 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001283 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001284 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001285 }
Andrew Jones2728be42011-08-12 15:32:05 +02001286
1287 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001288
1289 # We only want to get to the new kernel, don't fail
1290 # if we stumble over a call trace.
1291 my $save_ignore_errors = $ignore_errors;
1292 $ignore_errors = 1;
1293
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001294 # Look for the good kernel to boot
1295 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001296 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001297 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001298 run_command "$power_cycle";
1299 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001300
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001301 $ignore_errors = $save_ignore_errors;
1302
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001303 # Still need to wait for the reboot to finish
1304 wait_for_monitor($time, $reboot_success_line);
1305
Andrew Jones2728be42011-08-12 15:32:05 +02001306 end_monitor;
1307 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001308}
1309
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001310sub reboot_to_good {
1311 my ($time) = @_;
1312
1313 if (defined($switch_to_good)) {
1314 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001315 }
1316
1317 reboot $time;
1318}
1319
Steven Rostedt576f6272010-11-02 14:58:38 -04001320sub do_not_reboot {
1321 my $i = $iteration;
1322
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001323 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001324 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1325 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1326}
1327
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001328sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001329 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001330
Steven Rostedt576f6272010-11-02 14:58:38 -04001331 my $i = $iteration;
1332
1333 if ($reboot_on_error && !do_not_reboot) {
1334
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001335 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001336 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001337
Steven Rostedta75fece2010-11-02 14:58:27 -04001338 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001339 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001340 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001341 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001342
Steven Rostedtf80802c2011-03-07 13:18:47 -05001343 if (defined($opt{"LOG_FILE"})) {
1344 print " See $opt{LOG_FILE} for more info.\n";
1345 }
1346
Steven Rostedt576f6272010-11-02 14:58:38 -04001347 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001348}
1349
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001350sub open_console {
1351 my ($fp) = @_;
1352
1353 my $flags;
1354
Steven Rostedta75fece2010-11-02 14:58:27 -04001355 my $pid = open($fp, "$console|") or
1356 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001357
1358 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001359 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001360 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001361 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001362
1363 return $pid;
1364}
1365
1366sub close_console {
1367 my ($fp, $pid) = @_;
1368
1369 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001370 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001371
1372 print "closing!\n";
1373 close($fp);
1374}
1375
1376sub start_monitor {
1377 if ($monitor_cnt++) {
1378 return;
1379 }
1380 $monitor_fp = \*MONFD;
1381 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001382
1383 return;
1384
1385 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001386}
1387
1388sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001389 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001390 if (--$monitor_cnt) {
1391 return;
1392 }
1393 close_console($monitor_fp, $monitor_pid);
1394}
1395
1396sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001397 my ($time, $stop) = @_;
1398 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001399 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001400 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001401 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001402 my $skip_call_trace = 0;
1403 my $bug = 0;
1404 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001405 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001406
Steven Rostedta75fece2010-11-02 14:58:27 -04001407 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001408
1409 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001410 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001411 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001412 last if (!defined($line));
1413 print "$line";
1414 $full_line .= $line;
1415
1416 if (defined($stop) && $full_line =~ /$stop/) {
1417 doprint "wait for monitor detected $stop\n";
1418 $booted = 1;
1419 }
1420
Steven Rostedt8a80c722012-07-19 16:08:33 -04001421 if ($full_line =~ /\[ backtrace testing \]/) {
1422 $skip_call_trace = 1;
1423 }
1424
1425 if ($full_line =~ /call trace:/i) {
1426 if (!$bug && !$skip_call_trace) {
1427 if ($ignore_errors) {
1428 $bug_ignored = 1;
1429 } else {
1430 $bug = 1;
1431 }
1432 }
1433 }
1434
1435 if ($full_line =~ /\[ end of backtrace testing \]/) {
1436 $skip_call_trace = 0;
1437 }
1438
1439 if ($full_line =~ /Kernel panic -/) {
1440 $bug = 1;
1441 }
1442
Steven Rostedt2b803362011-09-30 18:00:23 -04001443 if ($line =~ /\n/) {
1444 $full_line = "";
1445 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001446 $now = time;
1447 if ($now - $start_time >= $max_monitor_wait) {
1448 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1449 return 1;
1450 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001451 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001452 print "** Monitor flushed **\n";
Steven Rostedt (Red Hat)995bc432014-10-07 16:31:07 -04001453
1454 # if stop is defined but wasn't hit, return error
1455 # used by reboot (which wants to see a reboot)
1456 if (defined($stop) && !$booted) {
1457 $bug = 1;
1458 }
Steven Rostedt8a80c722012-07-19 16:08:33 -04001459 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001460}
1461
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301462sub save_logs {
1463 my ($result, $basedir) = @_;
1464 my @t = localtime;
1465 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1466 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1467
1468 my $type = $build_type;
1469 if ($type =~ /useconfig/) {
1470 $type = "useconfig";
1471 }
1472
1473 my $dir = "$machine-$test_type-$type-$result-$date";
1474
1475 $dir = "$basedir/$dir";
1476
1477 if (!-d $dir) {
1478 mkpath($dir) or
1479 die "can't create $dir";
1480 }
1481
1482 my %files = (
1483 "config" => $output_config,
1484 "buildlog" => $buildlog,
1485 "dmesg" => $dmesg,
1486 "testlog" => $testlog,
1487 );
1488
1489 while (my ($name, $source) = each(%files)) {
1490 if (-f "$source") {
1491 cp "$source", "$dir/$name" or
1492 die "failed to copy $source";
1493 }
1494 }
1495
1496 doprint "*** Saved info to $dir ***\n";
1497}
1498
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001499sub fail {
1500
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001501 if (defined($post_test)) {
1502 run_command $post_test;
1503 }
1504
Steven Rostedta75fece2010-11-02 14:58:27 -04001505 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001506 dodie @_;
1507 }
1508
Steven Rostedta75fece2010-11-02 14:58:27 -04001509 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001510
Steven Rostedt576f6272010-11-02 14:58:38 -04001511 my $i = $iteration;
1512
Steven Rostedta75fece2010-11-02 14:58:27 -04001513 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001514 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001515 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001516 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001517 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001518
Steven Rostedt9064af52011-06-13 10:38:48 -04001519 my $name = "";
1520
1521 if (defined($test_name)) {
1522 $name = " ($test_name)";
1523 }
1524
Steven Rostedt576f6272010-11-02 14:58:38 -04001525 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1526 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001527 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001528 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1529 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001530
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301531 if (defined($store_failures)) {
1532 save_logs "fail", $store_failures;
1533 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001534
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001535 return 1;
1536}
1537
Steven Rostedt2545eb62010-11-02 15:01:32 -04001538sub run_command {
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09001539 my ($command, $redirect) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001540 my $dolog = 0;
1541 my $dord = 0;
1542 my $pid;
1543
Steven Rostedte48c5292010-11-02 14:35:37 -04001544 $command =~ s/\$SSH_USER/$ssh_user/g;
1545 $command =~ s/\$MACHINE/$machine/g;
1546
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001547 doprint("$command ... ");
1548
1549 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001550 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001551
1552 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001553 open(LOG, ">>$opt{LOG_FILE}") or
1554 dodie "failed to write to log";
1555 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001556 }
1557
1558 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001559 open (RD, ">$redirect") or
1560 dodie "failed to write to redirect $redirect";
1561 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001562 }
1563
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001564 while (<CMD>) {
1565 print LOG if ($dolog);
1566 print RD if ($dord);
1567 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001568
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001569 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001570 my $failed = $?;
1571
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001572 close(CMD);
1573 close(LOG) if ($dolog);
1574 close(RD) if ($dord);
1575
Steven Rostedt2545eb62010-11-02 15:01:32 -04001576 if ($failed) {
1577 doprint "FAILED!\n";
1578 } else {
1579 doprint "SUCCESS\n";
1580 }
1581
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001582 return !$failed;
1583}
1584
Steven Rostedte48c5292010-11-02 14:35:37 -04001585sub run_ssh {
1586 my ($cmd) = @_;
1587 my $cp_exec = $ssh_exec;
1588
1589 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1590 return run_command "$cp_exec";
1591}
1592
1593sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001594 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001595
1596 $cp_scp =~ s/\$SRC_FILE/$src/g;
1597 $cp_scp =~ s/\$DST_FILE/$dst/g;
1598
1599 return run_command "$cp_scp";
1600}
1601
Steven Rostedt02ad2612012-03-21 08:21:24 -04001602sub run_scp_install {
1603 my ($src, $dst) = @_;
1604
1605 my $cp_scp = $scp_to_target_install;
1606
1607 return run_scp($src, $dst, $cp_scp);
1608}
1609
1610sub run_scp_mod {
1611 my ($src, $dst) = @_;
1612
1613 my $cp_scp = $scp_to_target;
1614
1615 return run_scp($src, $dst, $cp_scp);
1616}
1617
Steven Rostedta15ba912012-11-13 14:30:37 -05001618sub get_grub2_index {
1619
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001620 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001621 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1622 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001623
1624 doprint "Find grub2 menu ... ";
1625 $grub_number = -1;
1626
1627 my $ssh_grub = $ssh_exec;
1628 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1629
1630 open(IN, "$ssh_grub |")
1631 or die "unable to get $grub_file";
1632
1633 my $found = 0;
1634
1635 while (<IN>) {
1636 if (/^menuentry.*$grub_menu/) {
1637 $grub_number++;
1638 $found = 1;
1639 last;
1640 } elsif (/^menuentry\s/) {
1641 $grub_number++;
1642 }
1643 }
1644 close(IN);
1645
1646 die "Could not find '$grub_menu' in $grub_file on $machine"
1647 if (!$found);
1648 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001649 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001650 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001651}
1652
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001653sub get_grub_index {
1654
Steven Rostedta15ba912012-11-13 14:30:37 -05001655 if ($reboot_type eq "grub2") {
1656 get_grub2_index;
1657 return;
1658 }
1659
Steven Rostedta75fece2010-11-02 14:58:27 -04001660 if ($reboot_type ne "grub") {
1661 return;
1662 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001663 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001664 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1665 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001666
1667 doprint "Find grub menu ... ";
1668 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001669
1670 my $ssh_grub = $ssh_exec;
1671 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1672
1673 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001674 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001675
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001676 my $found = 0;
1677
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001678 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001679 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001680 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001681 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001682 last;
1683 } elsif (/^\s*title\s/) {
1684 $grub_number++;
1685 }
1686 }
1687 close(IN);
1688
Steven Rostedta75fece2010-11-02 14:58:27 -04001689 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001690 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001691 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001692 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001693 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001694}
1695
Steven Rostedt2545eb62010-11-02 15:01:32 -04001696sub wait_for_input
1697{
1698 my ($fp, $time) = @_;
1699 my $rin;
1700 my $ready;
1701 my $line;
1702 my $ch;
1703
1704 if (!defined($time)) {
1705 $time = $timeout;
1706 }
1707
1708 $rin = '';
1709 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001710 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001711
1712 $line = "";
1713
1714 # try to read one char at a time
1715 while (sysread $fp, $ch, 1) {
1716 $line .= $ch;
1717 last if ($ch eq "\n");
1718 }
1719
1720 if (!length($line)) {
1721 return undef;
1722 }
1723
1724 return $line;
1725}
1726
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001727sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001728 if (defined($switch_to_test)) {
1729 run_command $switch_to_test;
1730 }
1731
Steven Rostedta75fece2010-11-02 14:58:27 -04001732 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001733 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001734 } elsif ($reboot_type eq "grub2") {
1735 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001736 } elsif ($reboot_type eq "syslinux") {
1737 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001738 } elsif (defined $reboot_script) {
1739 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001740 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001741 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001742}
1743
Steven Rostedta57419b2010-11-02 15:13:54 -04001744sub get_sha1 {
1745 my ($commit) = @_;
1746
1747 doprint "git rev-list --max-count=1 $commit ... ";
1748 my $sha1 = `git rev-list --max-count=1 $commit`;
1749 my $ret = $?;
1750
1751 logit $sha1;
1752
1753 if ($ret) {
1754 doprint "FAILED\n";
1755 dodie "Failed to get git $commit";
1756 }
1757
1758 print "SUCCESS\n";
1759
1760 chomp $sha1;
1761
1762 return $sha1;
1763}
1764
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001765sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001766 my $booted = 0;
1767 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001768 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001769 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001770 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001771
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001772 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001773
1774 my $line;
1775 my $full_line = "";
1776
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001777 open(DMESG, "> $dmesg") or
1778 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001779
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001780 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001781
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001782 my $success_start;
1783 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001784 my $monitor_start = time;
1785 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001786 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001787
Steven Rostedt2d01b262011-03-08 09:47:54 -05001788 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001789
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001790 if ($bug && defined($stop_after_failure) &&
1791 $stop_after_failure >= 0) {
1792 my $time = $stop_after_failure - (time - $failure_start);
1793 $line = wait_for_input($monitor_fp, $time);
1794 if (!defined($line)) {
1795 doprint "bug timed out after $booted_timeout seconds\n";
1796 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1797 last;
1798 }
1799 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001800 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001801 if (!defined($line)) {
1802 my $s = $booted_timeout == 1 ? "" : "s";
1803 doprint "Successful boot found: break after $booted_timeout second$s\n";
1804 last;
1805 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001806 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001807 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001808 if (!defined($line)) {
1809 my $s = $timeout == 1 ? "" : "s";
1810 doprint "Timed out after $timeout second$s\n";
1811 last;
1812 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001813 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001814
Steven Rostedt2545eb62010-11-02 15:01:32 -04001815 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001816 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001817
1818 # we are not guaranteed to get a full line
1819 $full_line .= $line;
1820
Steven Rostedta75fece2010-11-02 14:58:27 -04001821 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001822 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001823 $success_start = time;
1824 }
1825
1826 if ($booted && defined($stop_after_success) &&
1827 $stop_after_success >= 0) {
1828 my $now = time;
1829 if ($now - $success_start >= $stop_after_success) {
1830 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1831 last;
1832 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001833 }
1834
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001835 if ($full_line =~ /\[ backtrace testing \]/) {
1836 $skip_call_trace = 1;
1837 }
1838
Steven Rostedt2545eb62010-11-02 15:01:32 -04001839 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001840 if (!$bug && !$skip_call_trace) {
1841 if ($ignore_errors) {
1842 $bug_ignored = 1;
1843 } else {
1844 $bug = 1;
1845 $failure_start = time;
1846 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001847 }
1848 }
1849
1850 if ($bug && defined($stop_after_failure) &&
1851 $stop_after_failure >= 0) {
1852 my $now = time;
1853 if ($now - $failure_start >= $stop_after_failure) {
1854 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1855 last;
1856 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001857 }
1858
1859 if ($full_line =~ /\[ end of backtrace testing \]/) {
1860 $skip_call_trace = 0;
1861 }
1862
1863 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001864 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001865 $bug = 1;
1866 }
1867
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001868 # Detect triple faults by testing the banner
1869 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1870 if ($1 eq $version) {
1871 $version_found = 1;
1872 } elsif ($version_found && $detect_triplefault) {
1873 # We already booted into the kernel we are testing,
1874 # but now we booted into another kernel?
1875 # Consider this a triple fault.
Masanari Iida8b513d02013-05-21 23:13:12 +09001876 doprint "Already booted in Linux kernel $version, but now\n";
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001877 doprint "we booted into Linux kernel $1.\n";
1878 doprint "Assuming that this is a triple fault.\n";
1879 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1880 last;
1881 }
1882 }
1883
Steven Rostedt2545eb62010-11-02 15:01:32 -04001884 if ($line =~ /\n/) {
1885 $full_line = "";
1886 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001887
1888 if ($stop_test_after > 0 && !$booted && !$bug) {
1889 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001890 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001891 $done = 1;
1892 }
1893 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001894 }
1895
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001896 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001897
Steven Rostedt2545eb62010-11-02 15:01:32 -04001898 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001899 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001900 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001901 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001902
Steven Rostedta75fece2010-11-02 14:58:27 -04001903 if (!$booted) {
1904 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001905 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001906 }
1907
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001908 if ($bug_ignored) {
1909 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1910 }
1911
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001912 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001913}
1914
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001915sub eval_kernel_version {
1916 my ($option) = @_;
1917
1918 $option =~ s/\$KERNEL_VERSION/$version/g;
1919
1920 return $option;
1921}
1922
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001923sub do_post_install {
1924
1925 return if (!defined($post_install));
1926
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001927 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001928 run_command "$cp_post_install" or
1929 dodie "Failed to run post install";
1930}
1931
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001932# Sometimes the reboot fails, and will hang. We try to ssh to the box
1933# and if we fail, we force another reboot, that should powercycle it.
1934sub test_booted {
1935 if (!run_ssh "echo testing connection") {
1936 reboot $sleep_time;
1937 }
1938}
1939
Steven Rostedt2545eb62010-11-02 15:01:32 -04001940sub install {
1941
Steven Rostedte0a87422011-09-30 17:50:48 -04001942 return if ($no_install);
1943
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001944 if (defined($pre_install)) {
1945 my $cp_pre_install = eval_kernel_version $pre_install;
1946 run_command "$cp_pre_install" or
1947 dodie "Failed to run pre install";
1948 }
1949
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001950 my $cp_target = eval_kernel_version $target_image;
1951
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001952 test_booted;
1953
Steven Rostedt02ad2612012-03-21 08:21:24 -04001954 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001955 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001956
1957 my $install_mods = 0;
1958
1959 # should we process modules?
1960 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001961 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001962 while (<IN>) {
1963 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001964 if (defined($1)) {
1965 $install_mods = 1;
1966 last;
1967 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001968 }
1969 }
1970 close(IN);
1971
1972 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001973 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001974 doprint "No modules needed\n";
1975 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001976 }
1977
Steven Rostedt627977d2012-03-21 08:16:15 -04001978 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001979 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001980
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001981 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001982 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001983
Steven Rostedte48c5292010-11-02 14:35:37 -04001984 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001985 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001986
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001987 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001988 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001989 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001990
Steven Rostedt02ad2612012-03-21 08:21:24 -04001991 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001992 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001993
Steven Rostedta75fece2010-11-02 14:58:27 -04001994 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001995
Steven Rostedte7b13442011-06-14 20:44:36 -04001996 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001997 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001998
Steven Rostedte48c5292010-11-02 14:35:37 -04001999 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04002000
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04002001 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002002}
2003
Steven Rostedtddf607e2011-06-14 20:49:13 -04002004sub get_version {
2005 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04002006 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002007 doprint "$make kernelrelease ... ";
2008 $version = `$make kernelrelease | tail -1`;
2009 chomp($version);
2010 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002011 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002012}
2013
2014sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002015 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002016
2017 # Install bisects, don't need console
2018 if (defined $console) {
2019 start_monitor;
2020 wait_for_monitor 5;
2021 end_monitor;
2022 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002023
Steven Rostedtddf607e2011-06-14 20:49:13 -04002024 get_grub_index;
2025 get_version;
2026 install;
2027
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002028 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002029 return monitor;
2030}
2031
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002032my $check_build_re = ".*:.*(warning|error|Error):.*";
2033my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2034
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002035sub process_warning_line {
2036 my ($line) = @_;
2037
2038 chomp $line;
2039
2040 # for distcc heterogeneous systems, some compilers
2041 # do things differently causing warning lines
2042 # to be slightly different. This makes an attempt
2043 # to fixe those issues.
2044
2045 # chop off the index into the line
2046 # using distcc, some compilers give different indexes
2047 # depending on white space
2048 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2049
2050 # Some compilers use UTF-8 extended for quotes and some don't.
2051 $line =~ s/$utf8_quote/'/g;
2052
2053 return $line;
2054}
2055
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002056# Read buildlog and check against warnings file for any
2057# new warnings.
2058#
2059# Returns 1 if OK
2060# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002061sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002062 return 1 if (!defined $warnings_file);
2063
2064 my %warnings_list;
2065
2066 # Failed builds should not reboot the target
2067 my $save_no_reboot = $no_reboot;
2068 $no_reboot = 1;
2069
2070 if (-f $warnings_file) {
2071 open(IN, $warnings_file) or
2072 dodie "Error opening $warnings_file";
2073
2074 while (<IN>) {
2075 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002076 my $warning = process_warning_line $_;
2077
2078 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002079 }
2080 }
2081 close(IN);
2082 }
2083
2084 # If warnings file didn't exist, and WARNINGS_FILE exist,
2085 # then we fail on any warning!
2086
2087 open(IN, $buildlog) or dodie "Can't open $buildlog";
2088 while (<IN>) {
2089 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002090 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002091
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002092 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002093 fail "New warning found (not in $warnings_file)\n$_\n";
2094 $no_reboot = $save_no_reboot;
2095 return 0;
2096 }
2097 }
2098 }
2099 $no_reboot = $save_no_reboot;
2100 close(IN);
2101}
2102
2103sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002104 my ($patch) = @_;
2105
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002106 my @files = `git show $patch | diffstat -l`;
2107
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002108 foreach my $file (@files) {
2109 chomp $file;
2110 }
2111
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002112 open(IN, "git show $patch |") or
2113 dodie "failed to show $patch";
2114 while (<IN>) {
2115 if (m,^--- a/(.*),) {
2116 chomp $1;
2117 $files[$#files] = $1;
2118 }
2119 }
2120 close(IN);
2121
2122 open(IN, $buildlog) or dodie "Can't open $buildlog";
2123 while (<IN>) {
2124 if (/^\s*(.*?):.*(warning|error)/) {
2125 my $err = $1;
2126 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002127 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002128 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002129 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002130 }
2131 }
2132 }
2133 }
2134 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002135
2136 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002137}
2138
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002139sub apply_min_config {
2140 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002141
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002142 # Read the config file and remove anything that
2143 # is in the force_config hash (from minconfig and others)
2144 # then add the force config back.
2145
2146 doprint "Applying minimum configurations into $output_config.new\n";
2147
2148 open (OUT, ">$outconfig") or
2149 dodie "Can't create $outconfig";
2150
2151 if (-f $output_config) {
2152 open (IN, $output_config) or
2153 dodie "Failed to open $output_config";
2154 while (<IN>) {
2155 if (/^(# )?(CONFIG_[^\s=]*)/) {
2156 next if (defined($force_config{$2}));
2157 }
2158 print OUT;
2159 }
2160 close IN;
2161 }
2162 foreach my $config (keys %force_config) {
2163 print OUT "$force_config{$config}\n";
2164 }
2165 close OUT;
2166
2167 run_command "mv $outconfig $output_config";
2168}
2169
2170sub make_oldconfig {
2171
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002172 my @force_list = keys %force_config;
2173
2174 if ($#force_list >= 0) {
2175 apply_min_config;
2176 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002177
Adam Leefb16d892012-09-01 01:05:17 +08002178 if (!run_command "$make olddefconfig") {
2179 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002180 # try oldnoconfig
2181 doprint "olddefconfig failed, trying make oldnoconfig\n";
2182 if (!run_command "$make oldnoconfig") {
2183 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2184 # try a yes '' | oldconfig
2185 run_command "yes '' | $make oldconfig" or
2186 dodie "failed make config oldconfig";
2187 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002188 }
2189}
2190
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002191# read a config file and use this to force new configs.
2192sub load_force_config {
2193 my ($config) = @_;
2194
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002195 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002196 open(IN, $config) or
2197 dodie "failed to read $config";
2198 while (<IN>) {
2199 chomp;
2200 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2201 $force_config{$1} = $_;
2202 } elsif (/^# (CONFIG_\S*) is not set/) {
2203 $force_config{$1} = $_;
2204 }
2205 }
2206 close IN;
2207}
2208
Steven Rostedt2545eb62010-11-02 15:01:32 -04002209sub build {
2210 my ($type) = @_;
2211
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002212 unlink $buildlog;
2213
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002214 # Failed builds should not reboot the target
2215 my $save_no_reboot = $no_reboot;
2216 $no_reboot = 1;
2217
Steven Rostedt683a3e62012-05-18 13:34:35 -04002218 # Calculate a new version from here.
2219 $have_version = 0;
2220
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002221 if (defined($pre_build)) {
2222 my $ret = run_command $pre_build;
2223 if (!$ret && defined($pre_build_die) &&
2224 $pre_build_die) {
2225 dodie "failed to pre_build\n";
2226 }
2227 }
2228
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002229 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002230 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002231 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002232
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002233 $type = "oldconfig";
2234 }
2235
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002236 # old config can ask questions
2237 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002238 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002239
2240 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002241 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002242
Andrew Jones13488232011-08-12 15:32:04 +02002243 if (!$noclean) {
2244 run_command "mv $output_config $outputdir/config_temp" or
2245 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002246
Andrew Jones13488232011-08-12 15:32:04 +02002247 run_command "$make mrproper" or dodie "make mrproper";
2248
2249 run_command "mv $outputdir/config_temp $output_config" or
2250 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002251 }
2252
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002253 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002254 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002255 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002256 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002257 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002258
2259 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002260 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2261 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002262 close(OUT);
2263
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002264 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002265 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002266 }
2267
Adam Leefb16d892012-09-01 01:05:17 +08002268 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002269 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002270 dodie "failed make config";
2271 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002272 # Run old config regardless, to enforce min configurations
2273 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002274
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002275 my $build_ret = run_command "$make $build_options", $buildlog;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002276
2277 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002278 # Because a post build may change the kernel version
2279 # do it now.
2280 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002281 my $ret = run_command $post_build;
2282 if (!$ret && defined($post_build_die) &&
2283 $post_build_die) {
2284 dodie "failed to post_build\n";
2285 }
2286 }
2287
2288 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002289 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002290 if ($in_bisect) {
2291 $no_reboot = $save_no_reboot;
2292 return 0;
2293 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002294 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002295 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002296
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002297 $no_reboot = $save_no_reboot;
2298
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002299 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002300}
2301
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002302sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002303 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002304 if (defined($poweroff_after_halt)) {
2305 sleep $poweroff_after_halt;
2306 run_command "$power_off";
2307 }
2308 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002309 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002310 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002311 }
2312}
2313
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002314sub success {
2315 my ($i) = @_;
2316
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002317 if (defined($post_test)) {
2318 run_command $post_test;
2319 }
2320
Steven Rostedte48c5292010-11-02 14:35:37 -04002321 $successes++;
2322
Steven Rostedt9064af52011-06-13 10:38:48 -04002323 my $name = "";
2324
2325 if (defined($test_name)) {
2326 $name = " ($test_name)";
2327 }
2328
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002329 doprint "\n\n*******************************************\n";
2330 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002331 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002332 doprint "*******************************************\n";
2333 doprint "*******************************************\n";
2334
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302335 if (defined($store_successes)) {
2336 save_logs "success", $store_successes;
2337 }
2338
Steven Rostedt576f6272010-11-02 14:58:38 -04002339 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002340 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002341 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002342 }
2343}
2344
Steven Rostedtc960bb92011-03-08 09:22:39 -05002345sub answer_bisect {
2346 for (;;) {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002347 doprint "Pass, fail, or skip? [p/f/s]";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002348 my $ans = <STDIN>;
2349 chomp $ans;
2350 if ($ans eq "p" || $ans eq "P") {
2351 return 1;
2352 } elsif ($ans eq "f" || $ans eq "F") {
2353 return 0;
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002354 } elsif ($ans eq "s" || $ans eq "S") {
2355 return -1;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002356 } else {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002357 print "Please answer 'p', 'f', or 's'\n";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002358 }
2359 }
2360}
2361
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002362sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002363 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002364
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002365 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002366 $reboot_on_error = 0;
2367 $poweroff_on_error = 0;
2368 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002369
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002370 run_command $run_test, $testlog or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302371
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002372 exit $failed;
2373}
2374
2375my $child_done;
2376
2377sub child_finished {
2378 $child_done = 1;
2379}
2380
2381sub do_run_test {
2382 my $child_pid;
2383 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002384 my $line;
2385 my $full_line;
2386 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002387 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002388
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002389 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002390
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002391 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002392
2393 $child_done = 0;
2394
2395 $SIG{CHLD} = qw(child_finished);
2396
2397 $child_pid = fork;
2398
2399 child_run_test if (!$child_pid);
2400
2401 $full_line = "";
2402
2403 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002404 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002405 if (defined($line)) {
2406
2407 # we are not guaranteed to get a full line
2408 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002409 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002410
2411 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002412 if ($ignore_errors) {
2413 $bug_ignored = 1;
2414 } else {
2415 $bug = 1;
2416 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002417 }
2418
2419 if ($full_line =~ /Kernel panic -/) {
2420 $bug = 1;
2421 }
2422
2423 if ($line =~ /\n/) {
2424 $full_line = "";
2425 }
2426 }
2427 } while (!$child_done && !$bug);
2428
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002429 if (!$bug && $bug_ignored) {
2430 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2431 }
2432
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002433 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002434 my $failure_start = time;
2435 my $now;
2436 do {
2437 $line = wait_for_input($monitor_fp, 1);
2438 if (defined($line)) {
2439 doprint $line;
2440 }
2441 $now = time;
2442 if ($now - $failure_start >= $stop_after_failure) {
2443 last;
2444 }
2445 } while (defined($line));
2446
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002447 doprint "Detected kernel crash!\n";
2448 # kill the child with extreme prejudice
2449 kill 9, $child_pid;
2450 }
2451
2452 waitpid $child_pid, 0;
2453 $child_exit = $?;
2454
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002455 if (!$bug && $in_bisect) {
2456 if (defined($bisect_ret_good)) {
2457 if ($child_exit == $bisect_ret_good) {
2458 return 1;
2459 }
2460 }
2461 if (defined($bisect_ret_skip)) {
2462 if ($child_exit == $bisect_ret_skip) {
2463 return -1;
2464 }
2465 }
2466 if (defined($bisect_ret_abort)) {
2467 if ($child_exit == $bisect_ret_abort) {
2468 fail "test abort" and return -2;
2469 }
2470 }
2471 if (defined($bisect_ret_bad)) {
2472 if ($child_exit == $bisect_ret_skip) {
2473 return 0;
2474 }
2475 }
2476 if (defined($bisect_ret_default)) {
2477 if ($bisect_ret_default eq "good") {
2478 return 1;
2479 } elsif ($bisect_ret_default eq "bad") {
2480 return 0;
2481 } elsif ($bisect_ret_default eq "skip") {
2482 return -1;
2483 } elsif ($bisect_ret_default eq "abort") {
2484 return -2;
2485 } else {
2486 fail "unknown default action: $bisect_ret_default"
2487 and return -2;
2488 }
2489 }
2490 }
2491
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002492 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002493 return 0 if $in_bisect;
2494 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002495 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002496 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002497}
2498
Steven Rostedta75fece2010-11-02 14:58:27 -04002499sub run_git_bisect {
2500 my ($command) = @_;
2501
2502 doprint "$command ... ";
2503
2504 my $output = `$command 2>&1`;
2505 my $ret = $?;
2506
2507 logit $output;
2508
2509 if ($ret) {
2510 doprint "FAILED\n";
2511 dodie "Failed to git bisect";
2512 }
2513
2514 doprint "SUCCESS\n";
2515 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2516 doprint "$1 [$2]\n";
2517 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002518 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002519 doprint "Found bad commit... $1\n";
2520 return 0;
2521 } else {
2522 # we already logged it, just print it now.
2523 print $output;
2524 }
2525
2526 return 1;
2527}
2528
Steven Rostedtc23dca72011-03-08 09:26:31 -05002529sub bisect_reboot {
2530 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002531 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002532}
2533
2534# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002535sub run_bisect_test {
2536 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002537
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002538 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002539 my $result;
2540 my $output;
2541 my $ret;
2542
Steven Rostedt0a05c762010-11-08 11:14:10 -05002543 $in_bisect = 1;
2544
2545 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002546
2547 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002548 if ($failed && $bisect_skip) {
2549 $in_bisect = 0;
2550 return -1;
2551 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002552 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002553
2554 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002555 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002556
2557 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002558 if ($failed && $bisect_skip) {
2559 end_monitor;
2560 bisect_reboot;
2561 $in_bisect = 0;
2562 return -1;
2563 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002564 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002565
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002566 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002567 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002568 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002569 }
2570
2571 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002572 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002573 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002574 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002575 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002576
2577 # reboot the box to a kernel we can ssh to
2578 if ($type ne "build") {
2579 bisect_reboot;
2580 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002581 $in_bisect = 0;
2582
2583 return $result;
2584}
2585
2586sub run_bisect {
2587 my ($type) = @_;
2588 my $buildtype = "oldconfig";
2589
2590 # We should have a minconfig to use?
2591 if (defined($minconfig)) {
2592 $buildtype = "useconfig:$minconfig";
2593 }
2594
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002595 # If the user sets bisect_tries to less than 1, then no tries
2596 # is a success.
2597 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002598
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002599 # Still let the user manually decide that though.
2600 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002601 $ret = answer_bisect;
2602 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002603
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002604 for (my $i = 0; $i < $bisect_tries; $i++) {
2605 if ($bisect_tries > 1) {
2606 my $t = $i + 1;
2607 doprint("Running bisect trial $t of $bisect_tries:\n");
2608 }
2609 $ret = run_bisect_test $type, $buildtype;
2610
2611 if ($bisect_manual) {
2612 $ret = answer_bisect;
2613 }
2614
2615 last if (!$ret);
2616 }
2617
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002618 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002619 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002620 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002621 }
2622
Steven Rostedtc23dca72011-03-08 09:26:31 -05002623 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002624 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002625 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002626 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002627 } elsif ($bisect_skip) {
2628 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2629 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002630 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002631}
2632
Steven Rostedtdad98752011-11-22 20:48:57 -05002633sub update_bisect_replay {
2634 my $tmp_log = "$tmpdir/ktest_bisect_log";
2635 run_command "git bisect log > $tmp_log" or
2636 die "can't create bisect log";
2637 return $tmp_log;
2638}
2639
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002640sub bisect {
2641 my ($i) = @_;
2642
2643 my $result;
2644
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002645 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2646 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2647 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002648
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002649 my $good = $bisect_good;
2650 my $bad = $bisect_bad;
2651 my $type = $bisect_type;
2652 my $start = $bisect_start;
2653 my $replay = $bisect_replay;
2654 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002655
2656 if (defined($start_files)) {
2657 $start_files = " -- " . $start_files;
2658 } else {
2659 $start_files = "";
2660 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002661
Steven Rostedta57419b2010-11-02 15:13:54 -04002662 # convert to true sha1's
2663 $good = get_sha1($good);
2664 $bad = get_sha1($bad);
2665
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002666 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002667 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2668 $reverse_bisect = 1;
2669 } else {
2670 $reverse_bisect = 0;
2671 }
2672
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002673 # Can't have a test without having a test to run
2674 if ($type eq "test" && !defined($run_test)) {
2675 $type = "boot";
2676 }
2677
Steven Rostedtdad98752011-11-22 20:48:57 -05002678 # Check if a bisect was running
2679 my $bisect_start_file = "$builddir/.git/BISECT_START";
2680
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002681 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002682 my $do_check = defined($check) && $check ne "0";
2683
2684 if ( -f $bisect_start_file ) {
2685 print "Bisect in progress found\n";
2686 if ($do_check) {
2687 print " If you say yes, then no checks of good or bad will be done\n";
2688 }
2689 if (defined($replay)) {
2690 print "** BISECT_REPLAY is defined in config file **";
2691 print " Ignore config option and perform new git bisect log?\n";
2692 if (read_ync " (yes, no, or cancel) ") {
2693 $replay = update_bisect_replay;
2694 $do_check = 0;
2695 }
2696 } elsif (read_yn "read git log and continue?") {
2697 $replay = update_bisect_replay;
2698 $do_check = 0;
2699 }
2700 }
2701
2702 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002703
2704 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002705 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002706
2707 if ($check ne "good") {
2708 doprint "TESTING BISECT BAD [$bad]\n";
2709 run_command "git checkout $bad" or
2710 die "Failed to checkout $bad";
2711
2712 $result = run_bisect $type;
2713
2714 if ($result ne "bad") {
2715 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2716 }
2717 }
2718
2719 if ($check ne "bad") {
2720 doprint "TESTING BISECT GOOD [$good]\n";
2721 run_command "git checkout $good" or
2722 die "Failed to checkout $good";
2723
2724 $result = run_bisect $type;
2725
2726 if ($result ne "good") {
2727 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2728 }
2729 }
2730
2731 # checkout where we started
2732 run_command "git checkout $head" or
2733 die "Failed to checkout $head";
2734 }
2735
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002736 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002737 dodie "could not start bisect";
2738
2739 run_command "git bisect good $good" or
2740 dodie "could not set bisect good to $good";
2741
2742 run_git_bisect "git bisect bad $bad" or
2743 dodie "could not set bisect bad to $bad";
2744
2745 if (defined($replay)) {
2746 run_command "git bisect replay $replay" or
2747 dodie "failed to run replay";
2748 }
2749
2750 if (defined($start)) {
2751 run_command "git checkout $start" or
2752 dodie "failed to checkout $start";
2753 }
2754
2755 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002756 do {
2757 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002758 $test = run_git_bisect "git bisect $result";
2759 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002760
2761 run_command "git bisect log" or
2762 dodie "could not capture git bisect log";
2763
2764 run_command "git bisect reset" or
2765 dodie "could not reset git bisect";
2766
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002767 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002768
Steven Rostedt0a05c762010-11-08 11:14:10 -05002769 success $i;
2770}
2771
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002772# config_ignore holds the configs that were set (or unset) for
2773# a good config and we will ignore these configs for the rest
2774# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002775my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002776
2777# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002778my %config_set;
2779
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002780# config_off holds the set of configs that the bad config had disabled.
2781# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002782# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002783my %config_off;
2784
2785# config_off_tmp holds a set of configs to turn off for now
2786my @config_off_tmp;
2787
2788# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002789my %config_list;
2790my %null_config;
2791
2792my %dependency;
2793
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002794sub assign_configs {
2795 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002796
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002797 doprint "Reading configs from $config\n";
2798
Steven Rostedt0a05c762010-11-08 11:14:10 -05002799 open (IN, $config)
2800 or dodie "Failed to read $config";
2801
2802 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002803 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04002804 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002805 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002806 } elsif (/^(# (CONFIG\S*) is not set)/) {
2807 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002808 }
2809 }
2810
2811 close(IN);
2812}
2813
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002814sub process_config_ignore {
2815 my ($config) = @_;
2816
2817 assign_configs \%config_ignore, $config;
2818}
2819
Steven Rostedt0a05c762010-11-08 11:14:10 -05002820sub get_dependencies {
2821 my ($config) = @_;
2822
2823 my $arr = $dependency{$config};
2824 if (!defined($arr)) {
2825 return ();
2826 }
2827
2828 my @deps = @{$arr};
2829
2830 foreach my $dep (@{$arr}) {
2831 print "ADD DEP $dep\n";
2832 @deps = (@deps, get_dependencies $dep);
2833 }
2834
2835 return @deps;
2836}
2837
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002838sub save_config {
2839 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002840
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002841 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002842
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002843 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002844
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002845 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002846
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002847 foreach my $config (keys %configs) {
2848 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002849 }
2850 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002851}
2852
2853sub create_config {
2854 my ($name, $pc) = @_;
2855
2856 doprint "Creating old config from $name configs\n";
2857
2858 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002859
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002860 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002861}
2862
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002863# compare two config hashes, and return configs with different vals.
2864# It returns B's config values, but you can use A to see what A was.
2865sub diff_config_vals {
2866 my ($pa, $pb) = @_;
2867
2868 # crappy Perl way to pass in hashes.
2869 my %a = %{$pa};
2870 my %b = %{$pb};
2871
2872 my %ret;
2873
2874 foreach my $item (keys %a) {
2875 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2876 $ret{$item} = $b{$item};
2877 }
2878 }
2879
2880 return %ret;
2881}
2882
2883# compare two config hashes and return the configs in B but not A
2884sub diff_configs {
2885 my ($pa, $pb) = @_;
2886
2887 my %ret;
2888
2889 # crappy Perl way to pass in hashes.
2890 my %a = %{$pa};
2891 my %b = %{$pb};
2892
2893 foreach my $item (keys %b) {
2894 if (!defined($a{$item})) {
2895 $ret{$item} = $b{$item};
2896 }
2897 }
2898
2899 return %ret;
2900}
2901
2902# return if two configs are equal or not
2903# 0 is equal +1 b has something a does not
2904# +1 if a and b have a different item.
2905# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05002906sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002907 my ($pa, $pb) = @_;
2908
2909 my %ret;
2910
2911 # crappy Perl way to pass in hashes.
2912 my %a = %{$pa};
2913 my %b = %{$pb};
2914
2915 foreach my $item (keys %b) {
2916 if (!defined($a{$item})) {
2917 return 1;
2918 }
2919 if ($a{$item} ne $b{$item}) {
2920 return 1;
2921 }
2922 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002923
2924 foreach my $item (keys %a) {
2925 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002926 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002927 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002928 }
2929
Steven Rostedt0a05c762010-11-08 11:14:10 -05002930 return 0;
2931}
2932
2933sub run_config_bisect_test {
2934 my ($type) = @_;
2935
Steven Rostedt (Red Hat)4cc559b2014-04-23 22:27:27 -04002936 my $ret = run_bisect_test $type, "oldconfig";
2937
2938 if ($bisect_manual) {
2939 $ret = answer_bisect;
2940 }
2941
2942 return $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002943}
2944
Steven Rostedt0a05c762010-11-08 11:14:10 -05002945sub process_failed {
2946 my ($config) = @_;
2947
2948 doprint "\n\n***************************************\n";
2949 doprint "Found bad config: $config\n";
2950 doprint "***************************************\n\n";
2951}
2952
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002953# used for config bisecting
2954my $good_config;
2955my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002956
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002957sub process_new_config {
2958 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002959
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002960 my %tmp_config = %{$tc};
2961 my %good_configs = %{$gc};
2962 my %bad_configs = %{$bc};
2963
2964 my %new_configs;
2965
2966 my $runtest = 1;
2967 my $ret;
2968
2969 create_config "tmp_configs", \%tmp_config;
2970 assign_configs \%new_configs, $output_config;
2971
2972 $ret = compare_configs \%new_configs, \%bad_configs;
2973 if (!$ret) {
2974 doprint "New config equals bad config, try next test\n";
2975 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002976 }
2977
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002978 if ($runtest) {
2979 $ret = compare_configs \%new_configs, \%good_configs;
2980 if (!$ret) {
2981 doprint "New config equals good config, try next test\n";
2982 $runtest = 0;
2983 }
2984 }
2985
2986 %{$nc} = %new_configs;
2987
2988 return $runtest;
2989}
2990
2991sub run_config_bisect {
2992 my ($pgood, $pbad) = @_;
2993
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002994 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002995
2996 my %good_configs = %{$pgood};
2997 my %bad_configs = %{$pbad};
2998
2999 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
3000 my %b_configs = diff_configs \%good_configs, \%bad_configs;
3001 my %g_configs = diff_configs \%bad_configs, \%good_configs;
3002
3003 my @diff_arr = keys %diff_configs;
3004 my $len_diff = $#diff_arr + 1;
3005
3006 my @b_arr = keys %b_configs;
3007 my $len_b = $#b_arr + 1;
3008
3009 my @g_arr = keys %g_configs;
3010 my $len_g = $#g_arr + 1;
3011
3012 my $runtest = 1;
3013 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003014 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003015
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003016 # First, lets get it down to a single subset.
3017 # Is the problem with a difference in values?
3018 # Is the problem with a missing config?
3019 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003020
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003021 # Enable all of one set and see if we get a new bad
3022 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003023
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003024 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003025
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003026 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003027
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003028 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003029
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003030 if ($len_diff > 0) {
3031 if ($len_b > 0 || $len_g > 0) {
3032 my %tmp_config = %bad_configs;
3033
3034 doprint "Set tmp config to be bad config with good config values\n";
3035 foreach my $item (@diff_arr) {
3036 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003037 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003038
3039 $runtest = process_new_config \%tmp_config, \%new_configs,
3040 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003041 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003042 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003043
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003044 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003045
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003046 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003047 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003048 return 1;
3049 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003050 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003051
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003052 my $half = int($#diff_arr / 2);
3053 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003054
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003055 doprint "Settings bisect with top half:\n";
3056 doprint "Set tmp config to be bad config with some good config values\n";
3057 foreach my $item (@tophalf) {
3058 $tmp_config{$item} = $good_configs{$item};
3059 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003060
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003061 $runtest = process_new_config \%tmp_config, \%new_configs,
3062 \%good_configs, \%bad_configs;
3063
3064 if (!$runtest) {
3065 my %tmp_config = %bad_configs;
3066
3067 doprint "Try bottom half\n";
3068
3069 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3070
3071 foreach my $item (@bottomhalf) {
3072 $tmp_config{$item} = $good_configs{$item};
3073 }
3074
3075 $runtest = process_new_config \%tmp_config, \%new_configs,
3076 \%good_configs, \%bad_configs;
3077 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003078 }
3079
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003080 if ($runtest) {
3081 $ret = run_config_bisect_test $type;
3082 if ($ret) {
3083 doprint "NEW GOOD CONFIG\n";
3084 %good_configs = %new_configs;
3085 run_command "mv $good_config ${good_config}.last";
3086 save_config \%good_configs, $good_config;
3087 %{$pgood} = %good_configs;
3088 } else {
3089 doprint "NEW BAD CONFIG\n";
3090 %bad_configs = %new_configs;
3091 run_command "mv $bad_config ${bad_config}.last";
3092 save_config \%bad_configs, $bad_config;
3093 %{$pbad} = %bad_configs;
3094 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003095 return 0;
3096 }
3097
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003098 fail "Hmm, need to do a mix match?\n";
3099 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003100}
3101
3102sub config_bisect {
3103 my ($i) = @_;
3104
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003105 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003106 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003107
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003108 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003109
Steven Rostedt30f75da2011-06-13 10:35:35 -04003110 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003111 $good_config = $config_bisect_good;
3112 } elsif (defined($minconfig)) {
3113 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003114 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003115 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003116 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003117 if (!$ret) {
3118 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3119 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003120 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003121 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003122 }
3123
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003124 # we don't want min configs to cause issues here.
3125 doprint "Disabling 'MIN_CONFIG' for this test\n";
3126 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003127
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003128 my %good_configs;
3129 my %bad_configs;
3130 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003131
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003132 doprint "Run good configs through make oldconfig\n";
3133 assign_configs \%tmp_configs, $good_config;
3134 create_config "$good_config", \%tmp_configs;
3135 assign_configs \%good_configs, $output_config;
3136
3137 doprint "Run bad configs through make oldconfig\n";
3138 assign_configs \%tmp_configs, $bad_config;
3139 create_config "$bad_config", \%tmp_configs;
3140 assign_configs \%bad_configs, $output_config;
3141
3142 $good_config = "$tmpdir/good_config";
3143 $bad_config = "$tmpdir/bad_config";
3144
3145 save_config \%good_configs, $good_config;
3146 save_config \%bad_configs, $bad_config;
3147
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003148
3149 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3150 if ($config_bisect_check ne "good") {
3151 doprint "Testing bad config\n";
3152
3153 $ret = run_bisect_test $type, "useconfig:$bad_config";
3154 if ($ret) {
3155 fail "Bad config succeeded when expected to fail!";
3156 return 0;
3157 }
3158 }
3159 if ($config_bisect_check ne "bad") {
3160 doprint "Testing good config\n";
3161
3162 $ret = run_bisect_test $type, "useconfig:$good_config";
3163 if (!$ret) {
3164 fail "Good config failed when expected to succeed!";
3165 return 0;
3166 }
3167 }
3168 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003169
Steven Rostedt0a05c762010-11-08 11:14:10 -05003170 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003171 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003172 } while (!$ret);
3173
3174 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003175
3176 success $i;
3177}
3178
Steven Rostedt27d934b2011-05-20 09:18:18 -04003179sub patchcheck_reboot {
3180 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003181 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003182}
3183
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003184sub patchcheck {
3185 my ($i) = @_;
3186
3187 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003188 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003189 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003190 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003191
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003192 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003193
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003194 my $cherry = $patchcheck_cherry;
3195 if (!defined($cherry)) {
3196 $cherry = 0;
3197 }
3198
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003199 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003200 if (defined($patchcheck_end)) {
3201 $end = $patchcheck_end;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003202 } elsif ($cherry) {
3203 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003204 }
3205
Steven Rostedta57419b2010-11-02 15:13:54 -04003206 # Get the true sha1's since we can use things like HEAD~3
3207 $start = get_sha1($start);
3208 $end = get_sha1($end);
3209
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003210 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003211
3212 # Can't have a test without having a test to run
3213 if ($type eq "test" && !defined($run_test)) {
3214 $type = "boot";
3215 }
3216
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003217 if ($cherry) {
3218 open (IN, "git cherry -v $start $end|") or
3219 dodie "could not get git list";
3220 } else {
3221 open (IN, "git log --pretty=oneline $end|") or
3222 dodie "could not get git list";
3223 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003224
3225 my @list;
3226
3227 while (<IN>) {
3228 chomp;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003229 # git cherry adds a '+' we want to remove
3230 s/^\+ //;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003231 $list[$#list+1] = $_;
3232 last if (/^$start/);
3233 }
3234 close(IN);
3235
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003236 if (!$cherry) {
3237 if ($list[$#list] !~ /^$start/) {
3238 fail "SHA1 $start not found";
3239 }
3240
3241 # go backwards in the list
3242 @list = reverse @list;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003243 }
3244
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003245 doprint("Going to test the following commits:\n");
3246 foreach my $l (@list) {
3247 doprint "$l\n";
3248 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003249
3250 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003251 my %ignored_warnings;
3252
3253 if (defined($ignore_warnings)) {
3254 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3255 $ignored_warnings{$sha1} = 1;
3256 }
3257 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003258
3259 $in_patchcheck = 1;
3260 foreach my $item (@list) {
3261 my $sha1 = $item;
3262 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3263
3264 doprint "\nProcessing commit $item\n\n";
3265
3266 run_command "git checkout $sha1" or
3267 die "Failed to checkout $sha1";
3268
3269 # only clean on the first and last patch
3270 if ($item eq $list[0] ||
3271 $item eq $list[$#list]) {
3272 $noclean = $save_clean;
3273 } else {
3274 $noclean = 1;
3275 }
3276
3277 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003278 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003279 } else {
3280 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003281 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003282 }
3283
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003284 # No need to do per patch checking if warnings file exists
3285 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3286 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003287 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003288
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003289 check_buildlog or return 0;
3290
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003291 next if ($type eq "build");
3292
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003293 my $failed = 0;
3294
Steven Rostedtddf607e2011-06-14 20:49:13 -04003295 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003296
3297 if (!$failed && $type ne "boot"){
3298 do_run_test or $failed = 1;
3299 }
3300 end_monitor;
3301 return 0 if ($failed);
3302
Steven Rostedt27d934b2011-05-20 09:18:18 -04003303 patchcheck_reboot;
3304
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003305 }
3306 $in_patchcheck = 0;
3307 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003308
3309 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003310}
3311
Steven Rostedtb9066f62011-07-15 21:25:24 -04003312my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003313my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003314my $iflevel = 0;
3315my @ifdeps;
3316
3317# prevent recursion
3318my %read_kconfigs;
3319
Steven Rostedtac6974c2011-10-04 09:40:17 -04003320sub add_dep {
3321 # $config depends on $dep
3322 my ($config, $dep) = @_;
3323
3324 if (defined($depends{$config})) {
3325 $depends{$config} .= " " . $dep;
3326 } else {
3327 $depends{$config} = $dep;
3328 }
3329
3330 # record the number of configs depending on $dep
3331 if (defined $depcount{$dep}) {
3332 $depcount{$dep}++;
3333 } else {
3334 $depcount{$dep} = 1;
3335 }
3336}
3337
Steven Rostedtb9066f62011-07-15 21:25:24 -04003338# taken from streamline_config.pl
3339sub read_kconfig {
3340 my ($kconfig) = @_;
3341
3342 my $state = "NONE";
3343 my $config;
3344 my @kconfigs;
3345
3346 my $cont = 0;
3347 my $line;
3348
3349
3350 if (! -f $kconfig) {
3351 doprint "file $kconfig does not exist, skipping\n";
3352 return;
3353 }
3354
3355 open(KIN, "$kconfig")
3356 or die "Can't open $kconfig";
3357 while (<KIN>) {
3358 chomp;
3359
3360 # Make sure that lines ending with \ continue
3361 if ($cont) {
3362 $_ = $line . " " . $_;
3363 }
3364
3365 if (s/\\$//) {
3366 $cont = 1;
3367 $line = $_;
3368 next;
3369 }
3370
3371 $cont = 0;
3372
3373 # collect any Kconfig sources
3374 if (/^source\s*"(.*)"/) {
3375 $kconfigs[$#kconfigs+1] = $1;
3376 }
3377
3378 # configs found
3379 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3380 $state = "NEW";
3381 $config = $2;
3382
3383 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003384 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003385 }
3386
3387 # collect the depends for the config
3388 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3389
Steven Rostedtac6974c2011-10-04 09:40:17 -04003390 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003391
3392 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003393 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3394
3395 # selected by depends on config
3396 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003397
3398 # Check for if statements
3399 } elsif (/^if\s+(.*\S)\s*$/) {
3400 my $deps = $1;
3401 # remove beginning and ending non text
3402 $deps =~ s/^[^a-zA-Z0-9_]*//;
3403 $deps =~ s/[^a-zA-Z0-9_]*$//;
3404
3405 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3406
3407 $ifdeps[$iflevel++] = join ':', @deps;
3408
3409 } elsif (/^endif/) {
3410
3411 $iflevel-- if ($iflevel);
3412
3413 # stop on "help"
3414 } elsif (/^\s*help\s*$/) {
3415 $state = "NONE";
3416 }
3417 }
3418 close(KIN);
3419
3420 # read in any configs that were found.
3421 foreach $kconfig (@kconfigs) {
3422 if (!defined($read_kconfigs{$kconfig})) {
3423 $read_kconfigs{$kconfig} = 1;
3424 read_kconfig("$builddir/$kconfig");
3425 }
3426 }
3427}
3428
3429sub read_depends {
3430 # find out which arch this is by the kconfig file
3431 open (IN, $output_config)
3432 or dodie "Failed to read $output_config";
3433 my $arch;
3434 while (<IN>) {
3435 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3436 $arch = $1;
3437 last;
3438 }
3439 }
3440 close IN;
3441
3442 if (!defined($arch)) {
3443 doprint "Could not find arch from config file\n";
3444 doprint "no dependencies used\n";
3445 return;
3446 }
3447
3448 # arch is really the subarch, we need to know
3449 # what directory to look at.
3450 if ($arch eq "i386" || $arch eq "x86_64") {
3451 $arch = "x86";
3452 } elsif ($arch =~ /^tile/) {
3453 $arch = "tile";
3454 }
3455
3456 my $kconfig = "$builddir/arch/$arch/Kconfig";
3457
3458 if (! -f $kconfig && $arch =~ /\d$/) {
3459 my $orig = $arch;
3460 # some subarchs have numbers, truncate them
3461 $arch =~ s/\d*$//;
3462 $kconfig = "$builddir/arch/$arch/Kconfig";
3463 if (! -f $kconfig) {
3464 doprint "No idea what arch dir $orig is for\n";
3465 doprint "no dependencies used\n";
3466 return;
3467 }
3468 }
3469
3470 read_kconfig($kconfig);
3471}
3472
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003473sub make_new_config {
3474 my @configs = @_;
3475
3476 open (OUT, ">$output_config")
3477 or dodie "Failed to write $output_config";
3478
3479 foreach my $config (@configs) {
3480 print OUT "$config\n";
3481 }
3482 close OUT;
3483}
3484
Steven Rostedtac6974c2011-10-04 09:40:17 -04003485sub chomp_config {
3486 my ($config) = @_;
3487
3488 $config =~ s/CONFIG_//;
3489
3490 return $config;
3491}
3492
Steven Rostedtb9066f62011-07-15 21:25:24 -04003493sub get_depends {
3494 my ($dep) = @_;
3495
Steven Rostedtac6974c2011-10-04 09:40:17 -04003496 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003497
3498 $dep = $depends{"$kconfig"};
3499
3500 # the dep string we have saves the dependencies as they
3501 # were found, including expressions like ! && ||. We
3502 # want to split this out into just an array of configs.
3503
3504 my $valid = "A-Za-z_0-9";
3505
3506 my @configs;
3507
3508 while ($dep =~ /[$valid]/) {
3509
3510 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3511 my $conf = "CONFIG_" . $1;
3512
3513 $configs[$#configs + 1] = $conf;
3514
3515 $dep =~ s/^[^$valid]*[$valid]+//;
3516 } else {
3517 die "this should never happen";
3518 }
3519 }
3520
3521 return @configs;
3522}
3523
3524my %min_configs;
3525my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003526my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003527my %processed_configs;
3528my %nochange_config;
3529
3530sub test_this_config {
3531 my ($config) = @_;
3532
3533 my $found;
3534
3535 # if we already processed this config, skip it
3536 if (defined($processed_configs{$config})) {
3537 return undef;
3538 }
3539 $processed_configs{$config} = 1;
3540
3541 # if this config failed during this round, skip it
3542 if (defined($nochange_config{$config})) {
3543 return undef;
3544 }
3545
Steven Rostedtac6974c2011-10-04 09:40:17 -04003546 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003547
3548 # Test dependencies first
3549 if (defined($depends{"$kconfig"})) {
3550 my @parents = get_depends $config;
3551 foreach my $parent (@parents) {
3552 # if the parent is in the min config, check it first
3553 next if (!defined($min_configs{$parent}));
3554 $found = test_this_config($parent);
3555 if (defined($found)) {
3556 return $found;
3557 }
3558 }
3559 }
3560
3561 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003562 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003563 # .config to make sure it is missing the config that
3564 # we had before
3565 my %configs = %min_configs;
3566 delete $configs{$config};
3567 make_new_config ((values %configs), (values %keep_configs));
3568 make_oldconfig;
3569 undef %configs;
3570 assign_configs \%configs, $output_config;
3571
3572 return $config if (!defined($configs{$config}));
3573
3574 doprint "disabling config $config did not change .config\n";
3575
3576 $nochange_config{$config} = 1;
3577
3578 return undef;
3579}
3580
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003581sub make_min_config {
3582 my ($i) = @_;
3583
Steven Rostedtccc513b2012-05-21 17:13:40 -04003584 my $type = $minconfig_type;
3585 if ($type ne "boot" && $type ne "test") {
3586 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3587 " make_min_config works only with 'boot' and 'test'\n" and return;
3588 }
3589
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003590 if (!defined($output_minconfig)) {
3591 fail "OUTPUT_MIN_CONFIG not defined" and return;
3592 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003593
3594 # If output_minconfig exists, and the start_minconfig
3595 # came from min_config, than ask if we should use
3596 # that instead.
3597 if (-f $output_minconfig && !$start_minconfig_defined) {
3598 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003599 if (!defined($use_output_minconfig)) {
3600 if (read_yn " Use it as minconfig?") {
3601 $start_minconfig = $output_minconfig;
3602 }
3603 } elsif ($use_output_minconfig > 0) {
3604 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003605 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003606 } else {
3607 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003608 }
3609 }
3610
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003611 if (!defined($start_minconfig)) {
3612 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3613 }
3614
Steven Rostedt35ce5952011-07-15 21:57:25 -04003615 my $temp_config = "$tmpdir/temp_config";
3616
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003617 # First things first. We build an allnoconfig to find
3618 # out what the defaults are that we can't touch.
3619 # Some are selections, but we really can't handle selections.
3620
3621 my $save_minconfig = $minconfig;
3622 undef $minconfig;
3623
3624 run_command "$make allnoconfig" or return 0;
3625
Steven Rostedtb9066f62011-07-15 21:25:24 -04003626 read_depends;
3627
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003628 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003629
Steven Rostedt43d1b652011-07-15 22:01:56 -04003630 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003631 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003632
3633 if (defined($ignore_config)) {
3634 # make sure the file exists
3635 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003636 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003637 }
3638
Steven Rostedt43d1b652011-07-15 22:01:56 -04003639 %keep_configs = %save_configs;
3640
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003641 doprint "Load initial configs from $start_minconfig\n";
3642
3643 # Look at the current min configs, and save off all the
3644 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003645 assign_configs \%min_configs, $start_minconfig;
3646
3647 my @config_keys = keys %min_configs;
3648
Steven Rostedtac6974c2011-10-04 09:40:17 -04003649 # All configs need a depcount
3650 foreach my $config (@config_keys) {
3651 my $kconfig = chomp_config $config;
3652 if (!defined $depcount{$kconfig}) {
3653 $depcount{$kconfig} = 0;
3654 }
3655 }
3656
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003657 # Remove anything that was set by the make allnoconfig
3658 # we shouldn't need them as they get set for us anyway.
3659 foreach my $config (@config_keys) {
3660 # Remove anything in the ignore_config
3661 if (defined($keep_configs{$config})) {
3662 my $file = $ignore_config;
3663 $file =~ s,.*/(.*?)$,$1,;
3664 doprint "$config set by $file ... ignored\n";
3665 delete $min_configs{$config};
3666 next;
3667 }
3668 # But make sure the settings are the same. If a min config
3669 # sets a selection, we do not want to get rid of it if
3670 # it is not the same as what we have. Just move it into
3671 # the keep configs.
3672 if (defined($config_ignore{$config})) {
3673 if ($config_ignore{$config} ne $min_configs{$config}) {
3674 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3675 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3676 $keep_configs{$config} = $min_configs{$config};
3677 } else {
3678 doprint "$config set by allnoconfig ... ignored\n";
3679 }
3680 delete $min_configs{$config};
3681 }
3682 }
3683
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003684 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003685 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003686
3687 while (!$done) {
3688
3689 my $config;
3690 my $found;
3691
3692 # Now disable each config one by one and do a make oldconfig
3693 # till we find a config that changes our list.
3694
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003695 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003696
3697 # Sort keys by who is most dependent on
3698 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3699 @test_configs ;
3700
3701 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003702 my $reset = 1;
3703 for (my $i = 0; $i < $#test_configs; $i++) {
3704 if (!defined($nochange_config{$test_configs[0]})) {
3705 $reset = 0;
3706 last;
3707 }
3708 # This config didn't change the .config last time.
3709 # Place it at the end
3710 my $config = shift @test_configs;
3711 push @test_configs, $config;
3712 }
3713
3714 # if every test config has failed to modify the .config file
3715 # in the past, then reset and start over.
3716 if ($reset) {
3717 undef %nochange_config;
3718 }
3719
Steven Rostedtb9066f62011-07-15 21:25:24 -04003720 undef %processed_configs;
3721
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003722 foreach my $config (@test_configs) {
3723
Steven Rostedtb9066f62011-07-15 21:25:24 -04003724 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003725
Steven Rostedtb9066f62011-07-15 21:25:24 -04003726 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003727
3728 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003729 }
3730
3731 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003732 # we could have failed due to the nochange_config hash
3733 # reset and try again
3734 if (!$take_two) {
3735 undef %nochange_config;
3736 $take_two = 1;
3737 next;
3738 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003739 doprint "No more configs found that we can disable\n";
3740 $done = 1;
3741 last;
3742 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003743 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003744
3745 $config = $found;
3746
3747 doprint "Test with $config disabled\n";
3748
3749 # set in_bisect to keep build and monitor from dieing
3750 $in_bisect = 1;
3751
3752 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003753 build "oldconfig" or $failed = 1;
3754 if (!$failed) {
3755 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003756
3757 if ($type eq "test" && !$failed) {
3758 do_run_test or $failed = 1;
3759 }
3760
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003761 end_monitor;
3762 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003763
3764 $in_bisect = 0;
3765
3766 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003767 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003768 # this config is needed, add it to the ignore list.
3769 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003770 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003771 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003772
3773 # update new ignore configs
3774 if (defined($ignore_config)) {
3775 open (OUT, ">$temp_config")
3776 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003777 foreach my $config (keys %save_configs) {
3778 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003779 }
3780 close OUT;
3781 run_command "mv $temp_config $ignore_config" or
3782 dodie "failed to copy update to $ignore_config";
3783 }
3784
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003785 } else {
3786 # We booted without this config, remove it from the minconfigs.
3787 doprint "$config is not needed, disabling\n";
3788
3789 delete $min_configs{$config};
3790
3791 # Also disable anything that is not enabled in this config
3792 my %configs;
3793 assign_configs \%configs, $output_config;
3794 my @config_keys = keys %min_configs;
3795 foreach my $config (@config_keys) {
3796 if (!defined($configs{$config})) {
3797 doprint "$config is not set, disabling\n";
3798 delete $min_configs{$config};
3799 }
3800 }
3801
3802 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003803 open (OUT, ">$temp_config")
3804 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003805 foreach my $config (keys %keep_configs) {
3806 print OUT "$keep_configs{$config}\n";
3807 }
3808 foreach my $config (keys %min_configs) {
3809 print OUT "$min_configs{$config}\n";
3810 }
3811 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003812
3813 run_command "mv $temp_config $output_minconfig" or
3814 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003815 }
3816
3817 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003818 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003819 }
3820
3821 success $i;
3822 return 1;
3823}
3824
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003825sub make_warnings_file {
3826 my ($i) = @_;
3827
3828 if (!defined($warnings_file)) {
3829 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3830 }
3831
3832 if ($build_type eq "nobuild") {
3833 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3834 }
3835
3836 build $build_type or dodie "Failed to build";
3837
3838 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3839
3840 open(IN, $buildlog) or dodie "Can't open $buildlog";
3841 while (<IN>) {
3842
3843 # Some compilers use UTF-8 extended for quotes
3844 # for distcc heterogeneous systems, this causes issues
3845 s/$utf8_quote/'/g;
3846
3847 if (/$check_build_re/) {
3848 print OUT;
3849 }
3850 }
3851 close(IN);
3852
3853 close(OUT);
3854
3855 success $i;
3856}
3857
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09003858$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003859
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003860if ($#ARGV == 0) {
3861 $ktest_config = $ARGV[0];
3862 if (! -f $ktest_config) {
3863 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003864 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003865 exit 0;
3866 }
3867 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003868}
3869
3870if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003871 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003872 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003873 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3874 print OUT << "EOF"
3875# Generated by ktest.pl
3876#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003877
3878# PWD is a ktest.pl variable that will result in the process working
3879# directory that ktest.pl is executed in.
3880
3881# THIS_DIR is automatically assigned the PWD of the path that generated
3882# the config file. It is best to use this variable when assigning other
3883# directory paths within this directory. This allows you to easily
3884# move the test cases to other locations or to other machines.
3885#
3886THIS_DIR := $variable{"PWD"}
3887
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003888# Define each test with TEST_START
3889# The config options below it will override the defaults
3890TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003891TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003892
3893DEFAULTS
3894EOF
3895;
3896 close(OUT);
3897}
3898read_config $ktest_config;
3899
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003900if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003901 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003902}
3903
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003904# Append any configs entered in manually to the config file.
3905my @new_configs = keys %entered_configs;
3906if ($#new_configs >= 0) {
3907 print "\nAppending entered in configs to $ktest_config\n";
3908 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3909 foreach my $config (@new_configs) {
3910 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003911 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003912 }
3913}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003914
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003915if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3916 unlink $opt{"LOG_FILE"};
3917}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003918
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003919doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3920
Steven Rostedta57419b2010-11-02 15:13:54 -04003921for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3922
3923 if (!$i) {
3924 doprint "DEFAULT OPTIONS:\n";
3925 } else {
3926 doprint "\nTEST $i OPTIONS";
3927 if (defined($repeat_tests{$i})) {
3928 $repeat = $repeat_tests{$i};
3929 doprint " ITERATE $repeat";
3930 }
3931 doprint "\n";
3932 }
3933
3934 foreach my $option (sort keys %opt) {
3935
3936 if ($option =~ /\[(\d+)\]$/) {
3937 next if ($i != $1);
3938 } else {
3939 next if ($i);
3940 }
3941
3942 doprint "$option = $opt{$option}\n";
3943 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003944}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003945
Steven Rostedt2a625122011-05-20 15:48:59 -04003946sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003947 my ($name, $i) = @_;
3948
3949 my $option = "$name\[$i\]";
3950
3951 if (defined($opt{$option})) {
3952 return $opt{$option};
3953 }
3954
Steven Rostedta57419b2010-11-02 15:13:54 -04003955 foreach my $test (keys %repeat_tests) {
3956 if ($i >= $test &&
3957 $i < $test + $repeat_tests{$test}) {
3958 $option = "$name\[$test\]";
3959 if (defined($opt{$option})) {
3960 return $opt{$option};
3961 }
3962 }
3963 }
3964
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003965 if (defined($opt{$name})) {
3966 return $opt{$name};
3967 }
3968
3969 return undef;
3970}
3971
Steven Rostedt2a625122011-05-20 15:48:59 -04003972sub set_test_option {
3973 my ($name, $i) = @_;
3974
3975 my $option = __set_test_option($name, $i);
3976 return $option if (!defined($option));
3977
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003978 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003979}
3980
Steven Rostedt2545eb62010-11-02 15:01:32 -04003981# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003982for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003983
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003984 # Do not reboot on failing test options
3985 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003986 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003987
Steven Rostedt683a3e62012-05-18 13:34:35 -04003988 $have_version = 0;
3989
Steven Rostedt576f6272010-11-02 14:58:38 -04003990 $iteration = $i;
3991
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003992 undef %force_config;
3993
Steven Rostedta75fece2010-11-02 14:58:27 -04003994 my $makecmd = set_test_option("MAKE_CMD", $i);
3995
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003996 $outputdir = set_test_option("OUTPUT_DIR", $i);
3997 $builddir = set_test_option("BUILD_DIR", $i);
3998
3999 chdir $builddir || die "can't change directory to $builddir";
4000
4001 if (!-d $outputdir) {
4002 mkpath($outputdir) or
4003 die "can't create $outputdir";
4004 }
4005
4006 $make = "$makecmd O=$outputdir";
4007
Steven Rostedt9cc9e092011-12-22 21:37:22 -05004008 # Load all the options into their mapped variable names
4009 foreach my $opt (keys %option_map) {
4010 ${$option_map{$opt}} = set_test_option($opt, $i);
4011 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004012
Steven Rostedt35ce5952011-07-15 21:57:25 -04004013 $start_minconfig_defined = 1;
4014
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004015 # The first test may override the PRE_KTEST option
4016 if (defined($pre_ktest) && $i == 1) {
4017 doprint "\n";
4018 run_command $pre_ktest;
4019 }
4020
4021 # Any test can override the POST_KTEST option
4022 # The last test takes precedence.
4023 if (defined($post_ktest)) {
4024 $final_post_ktest = $post_ktest;
4025 }
4026
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004027 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004028 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004029 $start_minconfig = $minconfig;
4030 }
4031
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004032 if (!-d $tmpdir) {
4033 mkpath($tmpdir) or
4034 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004035 }
4036
Steven Rostedte48c5292010-11-02 14:35:37 -04004037 $ENV{"SSH_USER"} = $ssh_user;
4038 $ENV{"MACHINE"} = $machine;
4039
Steven Rostedta75fece2010-11-02 14:58:27 -04004040 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304041 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004042 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004043 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004044
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004045 if (!$buildonly) {
4046 $target = "$ssh_user\@$machine";
4047 if ($reboot_type eq "grub") {
4048 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004049 } elsif ($reboot_type eq "grub2") {
4050 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4051 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004052 } elsif ($reboot_type eq "syslinux") {
4053 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004054 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004055 }
4056
4057 my $run_type = $build_type;
4058 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004059 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004060 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004061 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004062 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004063 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004064 } elsif ($test_type eq "make_min_config") {
4065 $run_type = "";
4066 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004067 $run_type = "";
4068 }
4069
Steven Rostedta75fece2010-11-02 14:58:27 -04004070 # mistake in config file?
4071 if (!defined($run_type)) {
4072 $run_type = "ERROR";
4073 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004074
Steven Rostedte0a87422011-09-30 17:50:48 -04004075 my $installme = "";
4076 $installme = " no_install" if ($no_install);
4077
Steven Rostedt2545eb62010-11-02 15:01:32 -04004078 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04004079 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004080
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004081 if (defined($pre_test)) {
4082 run_command $pre_test;
4083 }
4084
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004085 unlink $dmesg;
4086 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304087 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004088
Steven Rostedt250bae82011-07-15 22:05:59 -04004089 if (defined($addconfig)) {
4090 my $min = $minconfig;
4091 if (!defined($minconfig)) {
4092 $min = "";
4093 }
4094 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004095 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004096 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004097 }
4098
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004099 if (defined($checkout)) {
4100 run_command "git checkout $checkout" or
4101 die "failed to checkout $checkout";
4102 }
4103
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004104 $no_reboot = 0;
4105
Steven Rostedt648a1822012-03-21 11:18:27 -04004106 # A test may opt to not reboot the box
4107 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004108 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004109 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004110
Steven Rostedta75fece2010-11-02 14:58:27 -04004111 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004112 bisect $i;
4113 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004114 } elsif ($test_type eq "config_bisect") {
4115 config_bisect $i;
4116 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004117 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004118 patchcheck $i;
4119 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004120 } elsif ($test_type eq "make_min_config") {
4121 make_min_config $i;
4122 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004123 } elsif ($test_type eq "make_warnings_file") {
4124 $no_reboot = 1;
4125 make_warnings_file $i;
4126 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004127 }
4128
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004129 if ($build_type ne "nobuild") {
4130 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004131 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004132 }
4133
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004134 if ($test_type eq "install") {
4135 get_version;
4136 install;
4137 success $i;
4138 next;
4139 }
4140
Steven Rostedta75fece2010-11-02 14:58:27 -04004141 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004142 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004143 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004144
4145 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4146 do_run_test or $failed = 1;
4147 }
4148 end_monitor;
4149 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004150 }
4151
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004152 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004153}
4154
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004155if (defined($final_post_ktest)) {
4156 run_command $final_post_ktest;
4157}
4158
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004159if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004160 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004161} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004162 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004163} elsif (defined($switch_to_good)) {
4164 # still need to get to the good kernel
4165 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004166}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004167
Steven Rostedt648a1822012-03-21 11:18:27 -04004168
Steven Rostedte48c5292010-11-02 14:35:37 -04004169doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4170
Steven Rostedt2545eb62010-11-02 15:01:32 -04004171exit 0;