blob: 3b7a180d9c0de3b6e327a6c3bbcf2596293014c3 [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 Rostedt8a80c722012-07-19 16:08:33 -04001453 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001454}
1455
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301456sub save_logs {
1457 my ($result, $basedir) = @_;
1458 my @t = localtime;
1459 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1460 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1461
1462 my $type = $build_type;
1463 if ($type =~ /useconfig/) {
1464 $type = "useconfig";
1465 }
1466
1467 my $dir = "$machine-$test_type-$type-$result-$date";
1468
1469 $dir = "$basedir/$dir";
1470
1471 if (!-d $dir) {
1472 mkpath($dir) or
1473 die "can't create $dir";
1474 }
1475
1476 my %files = (
1477 "config" => $output_config,
1478 "buildlog" => $buildlog,
1479 "dmesg" => $dmesg,
1480 "testlog" => $testlog,
1481 );
1482
1483 while (my ($name, $source) = each(%files)) {
1484 if (-f "$source") {
1485 cp "$source", "$dir/$name" or
1486 die "failed to copy $source";
1487 }
1488 }
1489
1490 doprint "*** Saved info to $dir ***\n";
1491}
1492
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001493sub fail {
1494
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001495 if (defined($post_test)) {
1496 run_command $post_test;
1497 }
1498
Steven Rostedta75fece2010-11-02 14:58:27 -04001499 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001500 dodie @_;
1501 }
1502
Steven Rostedta75fece2010-11-02 14:58:27 -04001503 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001504
Steven Rostedt576f6272010-11-02 14:58:38 -04001505 my $i = $iteration;
1506
Steven Rostedta75fece2010-11-02 14:58:27 -04001507 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001508 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001509 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001510 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001511 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001512
Steven Rostedt9064af52011-06-13 10:38:48 -04001513 my $name = "";
1514
1515 if (defined($test_name)) {
1516 $name = " ($test_name)";
1517 }
1518
Steven Rostedt576f6272010-11-02 14:58:38 -04001519 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1520 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001521 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001522 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1523 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001524
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301525 if (defined($store_failures)) {
1526 save_logs "fail", $store_failures;
1527 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001528
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001529 return 1;
1530}
1531
Steven Rostedt2545eb62010-11-02 15:01:32 -04001532sub run_command {
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09001533 my ($command, $redirect) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001534 my $dolog = 0;
1535 my $dord = 0;
1536 my $pid;
1537
Steven Rostedte48c5292010-11-02 14:35:37 -04001538 $command =~ s/\$SSH_USER/$ssh_user/g;
1539 $command =~ s/\$MACHINE/$machine/g;
1540
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001541 doprint("$command ... ");
1542
1543 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001544 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001545
1546 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001547 open(LOG, ">>$opt{LOG_FILE}") or
1548 dodie "failed to write to log";
1549 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001550 }
1551
1552 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001553 open (RD, ">$redirect") or
1554 dodie "failed to write to redirect $redirect";
1555 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001556 }
1557
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001558 while (<CMD>) {
1559 print LOG if ($dolog);
1560 print RD if ($dord);
1561 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001562
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001563 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001564 my $failed = $?;
1565
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001566 close(CMD);
1567 close(LOG) if ($dolog);
1568 close(RD) if ($dord);
1569
Steven Rostedt2545eb62010-11-02 15:01:32 -04001570 if ($failed) {
1571 doprint "FAILED!\n";
1572 } else {
1573 doprint "SUCCESS\n";
1574 }
1575
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001576 return !$failed;
1577}
1578
Steven Rostedte48c5292010-11-02 14:35:37 -04001579sub run_ssh {
1580 my ($cmd) = @_;
1581 my $cp_exec = $ssh_exec;
1582
1583 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1584 return run_command "$cp_exec";
1585}
1586
1587sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001588 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001589
1590 $cp_scp =~ s/\$SRC_FILE/$src/g;
1591 $cp_scp =~ s/\$DST_FILE/$dst/g;
1592
1593 return run_command "$cp_scp";
1594}
1595
Steven Rostedt02ad2612012-03-21 08:21:24 -04001596sub run_scp_install {
1597 my ($src, $dst) = @_;
1598
1599 my $cp_scp = $scp_to_target_install;
1600
1601 return run_scp($src, $dst, $cp_scp);
1602}
1603
1604sub run_scp_mod {
1605 my ($src, $dst) = @_;
1606
1607 my $cp_scp = $scp_to_target;
1608
1609 return run_scp($src, $dst, $cp_scp);
1610}
1611
Steven Rostedta15ba912012-11-13 14:30:37 -05001612sub get_grub2_index {
1613
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001614 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001615 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1616 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001617
1618 doprint "Find grub2 menu ... ";
1619 $grub_number = -1;
1620
1621 my $ssh_grub = $ssh_exec;
1622 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1623
1624 open(IN, "$ssh_grub |")
1625 or die "unable to get $grub_file";
1626
1627 my $found = 0;
1628
1629 while (<IN>) {
1630 if (/^menuentry.*$grub_menu/) {
1631 $grub_number++;
1632 $found = 1;
1633 last;
1634 } elsif (/^menuentry\s/) {
1635 $grub_number++;
1636 }
1637 }
1638 close(IN);
1639
1640 die "Could not find '$grub_menu' in $grub_file on $machine"
1641 if (!$found);
1642 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001643 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001644 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001645}
1646
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001647sub get_grub_index {
1648
Steven Rostedta15ba912012-11-13 14:30:37 -05001649 if ($reboot_type eq "grub2") {
1650 get_grub2_index;
1651 return;
1652 }
1653
Steven Rostedta75fece2010-11-02 14:58:27 -04001654 if ($reboot_type ne "grub") {
1655 return;
1656 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001657 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001658 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1659 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001660
1661 doprint "Find grub menu ... ";
1662 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001663
1664 my $ssh_grub = $ssh_exec;
1665 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1666
1667 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001668 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001669
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001670 my $found = 0;
1671
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001672 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001673 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001674 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001675 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001676 last;
1677 } elsif (/^\s*title\s/) {
1678 $grub_number++;
1679 }
1680 }
1681 close(IN);
1682
Steven Rostedta75fece2010-11-02 14:58:27 -04001683 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001684 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001685 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001686 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001687 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001688}
1689
Steven Rostedt2545eb62010-11-02 15:01:32 -04001690sub wait_for_input
1691{
1692 my ($fp, $time) = @_;
1693 my $rin;
1694 my $ready;
1695 my $line;
1696 my $ch;
1697
1698 if (!defined($time)) {
1699 $time = $timeout;
1700 }
1701
1702 $rin = '';
1703 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001704 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001705
1706 $line = "";
1707
1708 # try to read one char at a time
1709 while (sysread $fp, $ch, 1) {
1710 $line .= $ch;
1711 last if ($ch eq "\n");
1712 }
1713
1714 if (!length($line)) {
1715 return undef;
1716 }
1717
1718 return $line;
1719}
1720
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001721sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001722 if (defined($switch_to_test)) {
1723 run_command $switch_to_test;
1724 }
1725
Steven Rostedta75fece2010-11-02 14:58:27 -04001726 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001727 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001728 } elsif ($reboot_type eq "grub2") {
1729 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001730 } elsif ($reboot_type eq "syslinux") {
1731 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001732 } elsif (defined $reboot_script) {
1733 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001734 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001735 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001736}
1737
Steven Rostedta57419b2010-11-02 15:13:54 -04001738sub get_sha1 {
1739 my ($commit) = @_;
1740
1741 doprint "git rev-list --max-count=1 $commit ... ";
1742 my $sha1 = `git rev-list --max-count=1 $commit`;
1743 my $ret = $?;
1744
1745 logit $sha1;
1746
1747 if ($ret) {
1748 doprint "FAILED\n";
1749 dodie "Failed to get git $commit";
1750 }
1751
1752 print "SUCCESS\n";
1753
1754 chomp $sha1;
1755
1756 return $sha1;
1757}
1758
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001759sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001760 my $booted = 0;
1761 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001762 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001763 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001764 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001765
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001766 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001767
1768 my $line;
1769 my $full_line = "";
1770
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001771 open(DMESG, "> $dmesg") or
1772 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001773
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001774 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001775
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001776 my $success_start;
1777 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001778 my $monitor_start = time;
1779 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001780 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001781
Steven Rostedt2d01b262011-03-08 09:47:54 -05001782 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001783
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001784 if ($bug && defined($stop_after_failure) &&
1785 $stop_after_failure >= 0) {
1786 my $time = $stop_after_failure - (time - $failure_start);
1787 $line = wait_for_input($monitor_fp, $time);
1788 if (!defined($line)) {
1789 doprint "bug timed out after $booted_timeout seconds\n";
1790 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1791 last;
1792 }
1793 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001794 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001795 if (!defined($line)) {
1796 my $s = $booted_timeout == 1 ? "" : "s";
1797 doprint "Successful boot found: break after $booted_timeout second$s\n";
1798 last;
1799 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001800 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001801 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001802 if (!defined($line)) {
1803 my $s = $timeout == 1 ? "" : "s";
1804 doprint "Timed out after $timeout second$s\n";
1805 last;
1806 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001807 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001808
Steven Rostedt2545eb62010-11-02 15:01:32 -04001809 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001810 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001811
1812 # we are not guaranteed to get a full line
1813 $full_line .= $line;
1814
Steven Rostedta75fece2010-11-02 14:58:27 -04001815 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001816 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001817 $success_start = time;
1818 }
1819
1820 if ($booted && defined($stop_after_success) &&
1821 $stop_after_success >= 0) {
1822 my $now = time;
1823 if ($now - $success_start >= $stop_after_success) {
1824 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1825 last;
1826 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001827 }
1828
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001829 if ($full_line =~ /\[ backtrace testing \]/) {
1830 $skip_call_trace = 1;
1831 }
1832
Steven Rostedt2545eb62010-11-02 15:01:32 -04001833 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001834 if (!$bug && !$skip_call_trace) {
1835 if ($ignore_errors) {
1836 $bug_ignored = 1;
1837 } else {
1838 $bug = 1;
1839 $failure_start = time;
1840 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001841 }
1842 }
1843
1844 if ($bug && defined($stop_after_failure) &&
1845 $stop_after_failure >= 0) {
1846 my $now = time;
1847 if ($now - $failure_start >= $stop_after_failure) {
1848 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1849 last;
1850 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001851 }
1852
1853 if ($full_line =~ /\[ end of backtrace testing \]/) {
1854 $skip_call_trace = 0;
1855 }
1856
1857 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001858 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001859 $bug = 1;
1860 }
1861
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001862 # Detect triple faults by testing the banner
1863 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1864 if ($1 eq $version) {
1865 $version_found = 1;
1866 } elsif ($version_found && $detect_triplefault) {
1867 # We already booted into the kernel we are testing,
1868 # but now we booted into another kernel?
1869 # Consider this a triple fault.
Masanari Iida8b513d02013-05-21 23:13:12 +09001870 doprint "Already booted in Linux kernel $version, but now\n";
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001871 doprint "we booted into Linux kernel $1.\n";
1872 doprint "Assuming that this is a triple fault.\n";
1873 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1874 last;
1875 }
1876 }
1877
Steven Rostedt2545eb62010-11-02 15:01:32 -04001878 if ($line =~ /\n/) {
1879 $full_line = "";
1880 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001881
1882 if ($stop_test_after > 0 && !$booted && !$bug) {
1883 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001884 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001885 $done = 1;
1886 }
1887 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001888 }
1889
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001890 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001891
Steven Rostedt2545eb62010-11-02 15:01:32 -04001892 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001893 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001894 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001895 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001896
Steven Rostedta75fece2010-11-02 14:58:27 -04001897 if (!$booted) {
1898 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001899 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001900 }
1901
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001902 if ($bug_ignored) {
1903 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1904 }
1905
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001906 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001907}
1908
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001909sub eval_kernel_version {
1910 my ($option) = @_;
1911
1912 $option =~ s/\$KERNEL_VERSION/$version/g;
1913
1914 return $option;
1915}
1916
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001917sub do_post_install {
1918
1919 return if (!defined($post_install));
1920
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001921 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001922 run_command "$cp_post_install" or
1923 dodie "Failed to run post install";
1924}
1925
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001926# Sometimes the reboot fails, and will hang. We try to ssh to the box
1927# and if we fail, we force another reboot, that should powercycle it.
1928sub test_booted {
1929 if (!run_ssh "echo testing connection") {
1930 reboot $sleep_time;
1931 }
1932}
1933
Steven Rostedt2545eb62010-11-02 15:01:32 -04001934sub install {
1935
Steven Rostedte0a87422011-09-30 17:50:48 -04001936 return if ($no_install);
1937
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001938 if (defined($pre_install)) {
1939 my $cp_pre_install = eval_kernel_version $pre_install;
1940 run_command "$cp_pre_install" or
1941 dodie "Failed to run pre install";
1942 }
1943
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001944 my $cp_target = eval_kernel_version $target_image;
1945
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001946 test_booted;
1947
Steven Rostedt02ad2612012-03-21 08:21:24 -04001948 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001949 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001950
1951 my $install_mods = 0;
1952
1953 # should we process modules?
1954 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001955 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001956 while (<IN>) {
1957 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001958 if (defined($1)) {
1959 $install_mods = 1;
1960 last;
1961 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001962 }
1963 }
1964 close(IN);
1965
1966 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001967 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001968 doprint "No modules needed\n";
1969 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001970 }
1971
Steven Rostedt627977d2012-03-21 08:16:15 -04001972 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001973 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001974
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001975 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001976 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001977
Steven Rostedte48c5292010-11-02 14:35:37 -04001978 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001979 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001980
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001981 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001982 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001983 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001984
Steven Rostedt02ad2612012-03-21 08:21:24 -04001985 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001986 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001987
Steven Rostedta75fece2010-11-02 14:58:27 -04001988 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001989
Steven Rostedte7b13442011-06-14 20:44:36 -04001990 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001991 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001992
Steven Rostedte48c5292010-11-02 14:35:37 -04001993 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001994
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001995 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001996}
1997
Steven Rostedtddf607e2011-06-14 20:49:13 -04001998sub get_version {
1999 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04002000 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002001 doprint "$make kernelrelease ... ";
2002 $version = `$make kernelrelease | tail -1`;
2003 chomp($version);
2004 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002005 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002006}
2007
2008sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002009 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002010
2011 # Install bisects, don't need console
2012 if (defined $console) {
2013 start_monitor;
2014 wait_for_monitor 5;
2015 end_monitor;
2016 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002017
Steven Rostedtddf607e2011-06-14 20:49:13 -04002018 get_grub_index;
2019 get_version;
2020 install;
2021
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002022 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002023 return monitor;
2024}
2025
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002026my $check_build_re = ".*:.*(warning|error|Error):.*";
2027my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2028
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002029sub process_warning_line {
2030 my ($line) = @_;
2031
2032 chomp $line;
2033
2034 # for distcc heterogeneous systems, some compilers
2035 # do things differently causing warning lines
2036 # to be slightly different. This makes an attempt
2037 # to fixe those issues.
2038
2039 # chop off the index into the line
2040 # using distcc, some compilers give different indexes
2041 # depending on white space
2042 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2043
2044 # Some compilers use UTF-8 extended for quotes and some don't.
2045 $line =~ s/$utf8_quote/'/g;
2046
2047 return $line;
2048}
2049
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002050# Read buildlog and check against warnings file for any
2051# new warnings.
2052#
2053# Returns 1 if OK
2054# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002055sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002056 return 1 if (!defined $warnings_file);
2057
2058 my %warnings_list;
2059
2060 # Failed builds should not reboot the target
2061 my $save_no_reboot = $no_reboot;
2062 $no_reboot = 1;
2063
2064 if (-f $warnings_file) {
2065 open(IN, $warnings_file) or
2066 dodie "Error opening $warnings_file";
2067
2068 while (<IN>) {
2069 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002070 my $warning = process_warning_line $_;
2071
2072 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002073 }
2074 }
2075 close(IN);
2076 }
2077
2078 # If warnings file didn't exist, and WARNINGS_FILE exist,
2079 # then we fail on any warning!
2080
2081 open(IN, $buildlog) or dodie "Can't open $buildlog";
2082 while (<IN>) {
2083 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002084 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002085
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002086 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002087 fail "New warning found (not in $warnings_file)\n$_\n";
2088 $no_reboot = $save_no_reboot;
2089 return 0;
2090 }
2091 }
2092 }
2093 $no_reboot = $save_no_reboot;
2094 close(IN);
2095}
2096
2097sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002098 my ($patch) = @_;
2099
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002100 my @files = `git show $patch | diffstat -l`;
2101
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002102 foreach my $file (@files) {
2103 chomp $file;
2104 }
2105
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002106 open(IN, "git show $patch |") or
2107 dodie "failed to show $patch";
2108 while (<IN>) {
2109 if (m,^--- a/(.*),) {
2110 chomp $1;
2111 $files[$#files] = $1;
2112 }
2113 }
2114 close(IN);
2115
2116 open(IN, $buildlog) or dodie "Can't open $buildlog";
2117 while (<IN>) {
2118 if (/^\s*(.*?):.*(warning|error)/) {
2119 my $err = $1;
2120 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002121 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002122 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002123 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002124 }
2125 }
2126 }
2127 }
2128 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002129
2130 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002131}
2132
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002133sub apply_min_config {
2134 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002135
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002136 # Read the config file and remove anything that
2137 # is in the force_config hash (from minconfig and others)
2138 # then add the force config back.
2139
2140 doprint "Applying minimum configurations into $output_config.new\n";
2141
2142 open (OUT, ">$outconfig") or
2143 dodie "Can't create $outconfig";
2144
2145 if (-f $output_config) {
2146 open (IN, $output_config) or
2147 dodie "Failed to open $output_config";
2148 while (<IN>) {
2149 if (/^(# )?(CONFIG_[^\s=]*)/) {
2150 next if (defined($force_config{$2}));
2151 }
2152 print OUT;
2153 }
2154 close IN;
2155 }
2156 foreach my $config (keys %force_config) {
2157 print OUT "$force_config{$config}\n";
2158 }
2159 close OUT;
2160
2161 run_command "mv $outconfig $output_config";
2162}
2163
2164sub make_oldconfig {
2165
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002166 my @force_list = keys %force_config;
2167
2168 if ($#force_list >= 0) {
2169 apply_min_config;
2170 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002171
Adam Leefb16d892012-09-01 01:05:17 +08002172 if (!run_command "$make olddefconfig") {
2173 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002174 # try oldnoconfig
2175 doprint "olddefconfig failed, trying make oldnoconfig\n";
2176 if (!run_command "$make oldnoconfig") {
2177 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2178 # try a yes '' | oldconfig
2179 run_command "yes '' | $make oldconfig" or
2180 dodie "failed make config oldconfig";
2181 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002182 }
2183}
2184
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002185# read a config file and use this to force new configs.
2186sub load_force_config {
2187 my ($config) = @_;
2188
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002189 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002190 open(IN, $config) or
2191 dodie "failed to read $config";
2192 while (<IN>) {
2193 chomp;
2194 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2195 $force_config{$1} = $_;
2196 } elsif (/^# (CONFIG_\S*) is not set/) {
2197 $force_config{$1} = $_;
2198 }
2199 }
2200 close IN;
2201}
2202
Steven Rostedt2545eb62010-11-02 15:01:32 -04002203sub build {
2204 my ($type) = @_;
2205
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002206 unlink $buildlog;
2207
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002208 # Failed builds should not reboot the target
2209 my $save_no_reboot = $no_reboot;
2210 $no_reboot = 1;
2211
Steven Rostedt683a3e62012-05-18 13:34:35 -04002212 # Calculate a new version from here.
2213 $have_version = 0;
2214
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002215 if (defined($pre_build)) {
2216 my $ret = run_command $pre_build;
2217 if (!$ret && defined($pre_build_die) &&
2218 $pre_build_die) {
2219 dodie "failed to pre_build\n";
2220 }
2221 }
2222
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002223 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002224 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002225 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002226
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002227 $type = "oldconfig";
2228 }
2229
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002230 # old config can ask questions
2231 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002232 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002233
2234 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002235 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002236
Andrew Jones13488232011-08-12 15:32:04 +02002237 if (!$noclean) {
2238 run_command "mv $output_config $outputdir/config_temp" or
2239 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002240
Andrew Jones13488232011-08-12 15:32:04 +02002241 run_command "$make mrproper" or dodie "make mrproper";
2242
2243 run_command "mv $outputdir/config_temp $output_config" or
2244 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002245 }
2246
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002247 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002248 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002249 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002250 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002251 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002252
2253 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002254 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2255 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002256 close(OUT);
2257
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002258 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002259 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002260 }
2261
Adam Leefb16d892012-09-01 01:05:17 +08002262 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002263 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002264 dodie "failed make config";
2265 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002266 # Run old config regardless, to enforce min configurations
2267 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002268
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002269 my $build_ret = run_command "$make $build_options", $buildlog;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002270
2271 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002272 # Because a post build may change the kernel version
2273 # do it now.
2274 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002275 my $ret = run_command $post_build;
2276 if (!$ret && defined($post_build_die) &&
2277 $post_build_die) {
2278 dodie "failed to post_build\n";
2279 }
2280 }
2281
2282 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002283 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002284 if ($in_bisect) {
2285 $no_reboot = $save_no_reboot;
2286 return 0;
2287 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002288 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002289 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002290
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002291 $no_reboot = $save_no_reboot;
2292
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002293 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002294}
2295
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002296sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002297 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002298 if (defined($poweroff_after_halt)) {
2299 sleep $poweroff_after_halt;
2300 run_command "$power_off";
2301 }
2302 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002303 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002304 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002305 }
2306}
2307
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002308sub success {
2309 my ($i) = @_;
2310
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002311 if (defined($post_test)) {
2312 run_command $post_test;
2313 }
2314
Steven Rostedte48c5292010-11-02 14:35:37 -04002315 $successes++;
2316
Steven Rostedt9064af52011-06-13 10:38:48 -04002317 my $name = "";
2318
2319 if (defined($test_name)) {
2320 $name = " ($test_name)";
2321 }
2322
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002323 doprint "\n\n*******************************************\n";
2324 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002325 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002326 doprint "*******************************************\n";
2327 doprint "*******************************************\n";
2328
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302329 if (defined($store_successes)) {
2330 save_logs "success", $store_successes;
2331 }
2332
Steven Rostedt576f6272010-11-02 14:58:38 -04002333 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002334 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002335 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002336 }
2337}
2338
Steven Rostedtc960bb92011-03-08 09:22:39 -05002339sub answer_bisect {
2340 for (;;) {
2341 doprint "Pass or fail? [p/f]";
2342 my $ans = <STDIN>;
2343 chomp $ans;
2344 if ($ans eq "p" || $ans eq "P") {
2345 return 1;
2346 } elsif ($ans eq "f" || $ans eq "F") {
2347 return 0;
2348 } else {
2349 print "Please answer 'P' or 'F'\n";
2350 }
2351 }
2352}
2353
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002354sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002355 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002356
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002357 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002358 $reboot_on_error = 0;
2359 $poweroff_on_error = 0;
2360 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002361
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002362 run_command $run_test, $testlog or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302363
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002364 exit $failed;
2365}
2366
2367my $child_done;
2368
2369sub child_finished {
2370 $child_done = 1;
2371}
2372
2373sub do_run_test {
2374 my $child_pid;
2375 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002376 my $line;
2377 my $full_line;
2378 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002379 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002380
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002381 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002382
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002383 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002384
2385 $child_done = 0;
2386
2387 $SIG{CHLD} = qw(child_finished);
2388
2389 $child_pid = fork;
2390
2391 child_run_test if (!$child_pid);
2392
2393 $full_line = "";
2394
2395 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002396 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002397 if (defined($line)) {
2398
2399 # we are not guaranteed to get a full line
2400 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002401 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002402
2403 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002404 if ($ignore_errors) {
2405 $bug_ignored = 1;
2406 } else {
2407 $bug = 1;
2408 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002409 }
2410
2411 if ($full_line =~ /Kernel panic -/) {
2412 $bug = 1;
2413 }
2414
2415 if ($line =~ /\n/) {
2416 $full_line = "";
2417 }
2418 }
2419 } while (!$child_done && !$bug);
2420
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002421 if (!$bug && $bug_ignored) {
2422 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2423 }
2424
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002425 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002426 my $failure_start = time;
2427 my $now;
2428 do {
2429 $line = wait_for_input($monitor_fp, 1);
2430 if (defined($line)) {
2431 doprint $line;
2432 }
2433 $now = time;
2434 if ($now - $failure_start >= $stop_after_failure) {
2435 last;
2436 }
2437 } while (defined($line));
2438
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002439 doprint "Detected kernel crash!\n";
2440 # kill the child with extreme prejudice
2441 kill 9, $child_pid;
2442 }
2443
2444 waitpid $child_pid, 0;
2445 $child_exit = $?;
2446
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002447 if (!$bug && $in_bisect) {
2448 if (defined($bisect_ret_good)) {
2449 if ($child_exit == $bisect_ret_good) {
2450 return 1;
2451 }
2452 }
2453 if (defined($bisect_ret_skip)) {
2454 if ($child_exit == $bisect_ret_skip) {
2455 return -1;
2456 }
2457 }
2458 if (defined($bisect_ret_abort)) {
2459 if ($child_exit == $bisect_ret_abort) {
2460 fail "test abort" and return -2;
2461 }
2462 }
2463 if (defined($bisect_ret_bad)) {
2464 if ($child_exit == $bisect_ret_skip) {
2465 return 0;
2466 }
2467 }
2468 if (defined($bisect_ret_default)) {
2469 if ($bisect_ret_default eq "good") {
2470 return 1;
2471 } elsif ($bisect_ret_default eq "bad") {
2472 return 0;
2473 } elsif ($bisect_ret_default eq "skip") {
2474 return -1;
2475 } elsif ($bisect_ret_default eq "abort") {
2476 return -2;
2477 } else {
2478 fail "unknown default action: $bisect_ret_default"
2479 and return -2;
2480 }
2481 }
2482 }
2483
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002484 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002485 return 0 if $in_bisect;
2486 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002487 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002488 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002489}
2490
Steven Rostedta75fece2010-11-02 14:58:27 -04002491sub run_git_bisect {
2492 my ($command) = @_;
2493
2494 doprint "$command ... ";
2495
2496 my $output = `$command 2>&1`;
2497 my $ret = $?;
2498
2499 logit $output;
2500
2501 if ($ret) {
2502 doprint "FAILED\n";
2503 dodie "Failed to git bisect";
2504 }
2505
2506 doprint "SUCCESS\n";
2507 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2508 doprint "$1 [$2]\n";
2509 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002510 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002511 doprint "Found bad commit... $1\n";
2512 return 0;
2513 } else {
2514 # we already logged it, just print it now.
2515 print $output;
2516 }
2517
2518 return 1;
2519}
2520
Steven Rostedtc23dca72011-03-08 09:26:31 -05002521sub bisect_reboot {
2522 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002523 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002524}
2525
2526# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002527sub run_bisect_test {
2528 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002529
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002530 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002531 my $result;
2532 my $output;
2533 my $ret;
2534
Steven Rostedt0a05c762010-11-08 11:14:10 -05002535 $in_bisect = 1;
2536
2537 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002538
2539 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002540 if ($failed && $bisect_skip) {
2541 $in_bisect = 0;
2542 return -1;
2543 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002544 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002545
2546 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002547 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002548
2549 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002550 if ($failed && $bisect_skip) {
2551 end_monitor;
2552 bisect_reboot;
2553 $in_bisect = 0;
2554 return -1;
2555 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002556 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002557
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002558 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002559 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002560 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002561 }
2562
2563 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002564 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002565 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002566 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002567 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002568
2569 # reboot the box to a kernel we can ssh to
2570 if ($type ne "build") {
2571 bisect_reboot;
2572 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002573 $in_bisect = 0;
2574
2575 return $result;
2576}
2577
2578sub run_bisect {
2579 my ($type) = @_;
2580 my $buildtype = "oldconfig";
2581
2582 # We should have a minconfig to use?
2583 if (defined($minconfig)) {
2584 $buildtype = "useconfig:$minconfig";
2585 }
2586
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002587 # If the user sets bisect_tries to less than 1, then no tries
2588 # is a success.
2589 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002590
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002591 # Still let the user manually decide that though.
2592 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002593 $ret = answer_bisect;
2594 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002595
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002596 for (my $i = 0; $i < $bisect_tries; $i++) {
2597 if ($bisect_tries > 1) {
2598 my $t = $i + 1;
2599 doprint("Running bisect trial $t of $bisect_tries:\n");
2600 }
2601 $ret = run_bisect_test $type, $buildtype;
2602
2603 if ($bisect_manual) {
2604 $ret = answer_bisect;
2605 }
2606
2607 last if (!$ret);
2608 }
2609
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002610 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002611 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002612 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002613 }
2614
Steven Rostedtc23dca72011-03-08 09:26:31 -05002615 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002616 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002617 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002618 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002619 } elsif ($bisect_skip) {
2620 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2621 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002622 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002623}
2624
Steven Rostedtdad98752011-11-22 20:48:57 -05002625sub update_bisect_replay {
2626 my $tmp_log = "$tmpdir/ktest_bisect_log";
2627 run_command "git bisect log > $tmp_log" or
2628 die "can't create bisect log";
2629 return $tmp_log;
2630}
2631
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002632sub bisect {
2633 my ($i) = @_;
2634
2635 my $result;
2636
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002637 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2638 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2639 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002640
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002641 my $good = $bisect_good;
2642 my $bad = $bisect_bad;
2643 my $type = $bisect_type;
2644 my $start = $bisect_start;
2645 my $replay = $bisect_replay;
2646 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002647
2648 if (defined($start_files)) {
2649 $start_files = " -- " . $start_files;
2650 } else {
2651 $start_files = "";
2652 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002653
Steven Rostedta57419b2010-11-02 15:13:54 -04002654 # convert to true sha1's
2655 $good = get_sha1($good);
2656 $bad = get_sha1($bad);
2657
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002658 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002659 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2660 $reverse_bisect = 1;
2661 } else {
2662 $reverse_bisect = 0;
2663 }
2664
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002665 # Can't have a test without having a test to run
2666 if ($type eq "test" && !defined($run_test)) {
2667 $type = "boot";
2668 }
2669
Steven Rostedtdad98752011-11-22 20:48:57 -05002670 # Check if a bisect was running
2671 my $bisect_start_file = "$builddir/.git/BISECT_START";
2672
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002673 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002674 my $do_check = defined($check) && $check ne "0";
2675
2676 if ( -f $bisect_start_file ) {
2677 print "Bisect in progress found\n";
2678 if ($do_check) {
2679 print " If you say yes, then no checks of good or bad will be done\n";
2680 }
2681 if (defined($replay)) {
2682 print "** BISECT_REPLAY is defined in config file **";
2683 print " Ignore config option and perform new git bisect log?\n";
2684 if (read_ync " (yes, no, or cancel) ") {
2685 $replay = update_bisect_replay;
2686 $do_check = 0;
2687 }
2688 } elsif (read_yn "read git log and continue?") {
2689 $replay = update_bisect_replay;
2690 $do_check = 0;
2691 }
2692 }
2693
2694 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002695
2696 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002697 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002698
2699 if ($check ne "good") {
2700 doprint "TESTING BISECT BAD [$bad]\n";
2701 run_command "git checkout $bad" or
2702 die "Failed to checkout $bad";
2703
2704 $result = run_bisect $type;
2705
2706 if ($result ne "bad") {
2707 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2708 }
2709 }
2710
2711 if ($check ne "bad") {
2712 doprint "TESTING BISECT GOOD [$good]\n";
2713 run_command "git checkout $good" or
2714 die "Failed to checkout $good";
2715
2716 $result = run_bisect $type;
2717
2718 if ($result ne "good") {
2719 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2720 }
2721 }
2722
2723 # checkout where we started
2724 run_command "git checkout $head" or
2725 die "Failed to checkout $head";
2726 }
2727
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002728 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002729 dodie "could not start bisect";
2730
2731 run_command "git bisect good $good" or
2732 dodie "could not set bisect good to $good";
2733
2734 run_git_bisect "git bisect bad $bad" or
2735 dodie "could not set bisect bad to $bad";
2736
2737 if (defined($replay)) {
2738 run_command "git bisect replay $replay" or
2739 dodie "failed to run replay";
2740 }
2741
2742 if (defined($start)) {
2743 run_command "git checkout $start" or
2744 dodie "failed to checkout $start";
2745 }
2746
2747 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002748 do {
2749 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002750 $test = run_git_bisect "git bisect $result";
2751 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002752
2753 run_command "git bisect log" or
2754 dodie "could not capture git bisect log";
2755
2756 run_command "git bisect reset" or
2757 dodie "could not reset git bisect";
2758
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002759 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002760
Steven Rostedt0a05c762010-11-08 11:14:10 -05002761 success $i;
2762}
2763
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002764# config_ignore holds the configs that were set (or unset) for
2765# a good config and we will ignore these configs for the rest
2766# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002767my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002768
2769# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002770my %config_set;
2771
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002772# config_off holds the set of configs that the bad config had disabled.
2773# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002774# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002775my %config_off;
2776
2777# config_off_tmp holds a set of configs to turn off for now
2778my @config_off_tmp;
2779
2780# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002781my %config_list;
2782my %null_config;
2783
2784my %dependency;
2785
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002786sub assign_configs {
2787 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002788
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002789 doprint "Reading configs from $config\n";
2790
Steven Rostedt0a05c762010-11-08 11:14:10 -05002791 open (IN, $config)
2792 or dodie "Failed to read $config";
2793
2794 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002795 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04002796 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002797 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002798 } elsif (/^(# (CONFIG\S*) is not set)/) {
2799 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002800 }
2801 }
2802
2803 close(IN);
2804}
2805
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002806sub process_config_ignore {
2807 my ($config) = @_;
2808
2809 assign_configs \%config_ignore, $config;
2810}
2811
Steven Rostedt0a05c762010-11-08 11:14:10 -05002812sub get_dependencies {
2813 my ($config) = @_;
2814
2815 my $arr = $dependency{$config};
2816 if (!defined($arr)) {
2817 return ();
2818 }
2819
2820 my @deps = @{$arr};
2821
2822 foreach my $dep (@{$arr}) {
2823 print "ADD DEP $dep\n";
2824 @deps = (@deps, get_dependencies $dep);
2825 }
2826
2827 return @deps;
2828}
2829
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002830sub save_config {
2831 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002832
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002833 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002834
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002835 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002836
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002837 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002838
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002839 foreach my $config (keys %configs) {
2840 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002841 }
2842 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002843}
2844
2845sub create_config {
2846 my ($name, $pc) = @_;
2847
2848 doprint "Creating old config from $name configs\n";
2849
2850 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002851
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002852 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002853}
2854
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002855# compare two config hashes, and return configs with different vals.
2856# It returns B's config values, but you can use A to see what A was.
2857sub diff_config_vals {
2858 my ($pa, $pb) = @_;
2859
2860 # crappy Perl way to pass in hashes.
2861 my %a = %{$pa};
2862 my %b = %{$pb};
2863
2864 my %ret;
2865
2866 foreach my $item (keys %a) {
2867 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2868 $ret{$item} = $b{$item};
2869 }
2870 }
2871
2872 return %ret;
2873}
2874
2875# compare two config hashes and return the configs in B but not A
2876sub diff_configs {
2877 my ($pa, $pb) = @_;
2878
2879 my %ret;
2880
2881 # crappy Perl way to pass in hashes.
2882 my %a = %{$pa};
2883 my %b = %{$pb};
2884
2885 foreach my $item (keys %b) {
2886 if (!defined($a{$item})) {
2887 $ret{$item} = $b{$item};
2888 }
2889 }
2890
2891 return %ret;
2892}
2893
2894# return if two configs are equal or not
2895# 0 is equal +1 b has something a does not
2896# +1 if a and b have a different item.
2897# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05002898sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002899 my ($pa, $pb) = @_;
2900
2901 my %ret;
2902
2903 # crappy Perl way to pass in hashes.
2904 my %a = %{$pa};
2905 my %b = %{$pb};
2906
2907 foreach my $item (keys %b) {
2908 if (!defined($a{$item})) {
2909 return 1;
2910 }
2911 if ($a{$item} ne $b{$item}) {
2912 return 1;
2913 }
2914 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002915
2916 foreach my $item (keys %a) {
2917 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002918 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002919 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002920 }
2921
Steven Rostedt0a05c762010-11-08 11:14:10 -05002922 return 0;
2923}
2924
2925sub run_config_bisect_test {
2926 my ($type) = @_;
2927
Steven Rostedt (Red Hat)4cc559b2014-04-23 22:27:27 -04002928 my $ret = run_bisect_test $type, "oldconfig";
2929
2930 if ($bisect_manual) {
2931 $ret = answer_bisect;
2932 }
2933
2934 return $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002935}
2936
Steven Rostedt0a05c762010-11-08 11:14:10 -05002937sub process_failed {
2938 my ($config) = @_;
2939
2940 doprint "\n\n***************************************\n";
2941 doprint "Found bad config: $config\n";
2942 doprint "***************************************\n\n";
2943}
2944
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002945# used for config bisecting
2946my $good_config;
2947my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002948
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002949sub process_new_config {
2950 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002951
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002952 my %tmp_config = %{$tc};
2953 my %good_configs = %{$gc};
2954 my %bad_configs = %{$bc};
2955
2956 my %new_configs;
2957
2958 my $runtest = 1;
2959 my $ret;
2960
2961 create_config "tmp_configs", \%tmp_config;
2962 assign_configs \%new_configs, $output_config;
2963
2964 $ret = compare_configs \%new_configs, \%bad_configs;
2965 if (!$ret) {
2966 doprint "New config equals bad config, try next test\n";
2967 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002968 }
2969
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002970 if ($runtest) {
2971 $ret = compare_configs \%new_configs, \%good_configs;
2972 if (!$ret) {
2973 doprint "New config equals good config, try next test\n";
2974 $runtest = 0;
2975 }
2976 }
2977
2978 %{$nc} = %new_configs;
2979
2980 return $runtest;
2981}
2982
2983sub run_config_bisect {
2984 my ($pgood, $pbad) = @_;
2985
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002986 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002987
2988 my %good_configs = %{$pgood};
2989 my %bad_configs = %{$pbad};
2990
2991 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
2992 my %b_configs = diff_configs \%good_configs, \%bad_configs;
2993 my %g_configs = diff_configs \%bad_configs, \%good_configs;
2994
2995 my @diff_arr = keys %diff_configs;
2996 my $len_diff = $#diff_arr + 1;
2997
2998 my @b_arr = keys %b_configs;
2999 my $len_b = $#b_arr + 1;
3000
3001 my @g_arr = keys %g_configs;
3002 my $len_g = $#g_arr + 1;
3003
3004 my $runtest = 1;
3005 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003006 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003007
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003008 # First, lets get it down to a single subset.
3009 # Is the problem with a difference in values?
3010 # Is the problem with a missing config?
3011 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003012
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003013 # Enable all of one set and see if we get a new bad
3014 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003015
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003016 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003017
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003018 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003019
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003020 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003021
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003022 if ($len_diff > 0) {
3023 if ($len_b > 0 || $len_g > 0) {
3024 my %tmp_config = %bad_configs;
3025
3026 doprint "Set tmp config to be bad config with good config values\n";
3027 foreach my $item (@diff_arr) {
3028 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003029 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003030
3031 $runtest = process_new_config \%tmp_config, \%new_configs,
3032 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003033 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003034 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003035
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003036 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003037
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003038 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003039 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003040 return 1;
3041 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003042 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003043
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003044 my $half = int($#diff_arr / 2);
3045 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003046
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003047 doprint "Settings bisect with top half:\n";
3048 doprint "Set tmp config to be bad config with some good config values\n";
3049 foreach my $item (@tophalf) {
3050 $tmp_config{$item} = $good_configs{$item};
3051 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003052
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003053 $runtest = process_new_config \%tmp_config, \%new_configs,
3054 \%good_configs, \%bad_configs;
3055
3056 if (!$runtest) {
3057 my %tmp_config = %bad_configs;
3058
3059 doprint "Try bottom half\n";
3060
3061 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3062
3063 foreach my $item (@bottomhalf) {
3064 $tmp_config{$item} = $good_configs{$item};
3065 }
3066
3067 $runtest = process_new_config \%tmp_config, \%new_configs,
3068 \%good_configs, \%bad_configs;
3069 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003070 }
3071
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003072 if ($runtest) {
3073 $ret = run_config_bisect_test $type;
3074 if ($ret) {
3075 doprint "NEW GOOD CONFIG\n";
3076 %good_configs = %new_configs;
3077 run_command "mv $good_config ${good_config}.last";
3078 save_config \%good_configs, $good_config;
3079 %{$pgood} = %good_configs;
3080 } else {
3081 doprint "NEW BAD CONFIG\n";
3082 %bad_configs = %new_configs;
3083 run_command "mv $bad_config ${bad_config}.last";
3084 save_config \%bad_configs, $bad_config;
3085 %{$pbad} = %bad_configs;
3086 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003087 return 0;
3088 }
3089
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003090 fail "Hmm, need to do a mix match?\n";
3091 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003092}
3093
3094sub config_bisect {
3095 my ($i) = @_;
3096
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003097 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003098 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003099
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003100 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003101
Steven Rostedt30f75da2011-06-13 10:35:35 -04003102 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003103 $good_config = $config_bisect_good;
3104 } elsif (defined($minconfig)) {
3105 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003106 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003107 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003108 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003109 if (!$ret) {
3110 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3111 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003112 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003113 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003114 }
3115
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003116 # we don't want min configs to cause issues here.
3117 doprint "Disabling 'MIN_CONFIG' for this test\n";
3118 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003119
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003120 my %good_configs;
3121 my %bad_configs;
3122 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003123
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003124 doprint "Run good configs through make oldconfig\n";
3125 assign_configs \%tmp_configs, $good_config;
3126 create_config "$good_config", \%tmp_configs;
3127 assign_configs \%good_configs, $output_config;
3128
3129 doprint "Run bad configs through make oldconfig\n";
3130 assign_configs \%tmp_configs, $bad_config;
3131 create_config "$bad_config", \%tmp_configs;
3132 assign_configs \%bad_configs, $output_config;
3133
3134 $good_config = "$tmpdir/good_config";
3135 $bad_config = "$tmpdir/bad_config";
3136
3137 save_config \%good_configs, $good_config;
3138 save_config \%bad_configs, $bad_config;
3139
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003140
3141 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3142 if ($config_bisect_check ne "good") {
3143 doprint "Testing bad config\n";
3144
3145 $ret = run_bisect_test $type, "useconfig:$bad_config";
3146 if ($ret) {
3147 fail "Bad config succeeded when expected to fail!";
3148 return 0;
3149 }
3150 }
3151 if ($config_bisect_check ne "bad") {
3152 doprint "Testing good config\n";
3153
3154 $ret = run_bisect_test $type, "useconfig:$good_config";
3155 if (!$ret) {
3156 fail "Good config failed when expected to succeed!";
3157 return 0;
3158 }
3159 }
3160 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003161
Steven Rostedt0a05c762010-11-08 11:14:10 -05003162 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003163 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003164 } while (!$ret);
3165
3166 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003167
3168 success $i;
3169}
3170
Steven Rostedt27d934b2011-05-20 09:18:18 -04003171sub patchcheck_reboot {
3172 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003173 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003174}
3175
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003176sub patchcheck {
3177 my ($i) = @_;
3178
3179 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003180 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003181 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003182 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003183
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003184 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003185
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003186 my $cherry = $patchcheck_cherry;
3187 if (!defined($cherry)) {
3188 $cherry = 0;
3189 }
3190
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003191 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003192 if (defined($patchcheck_end)) {
3193 $end = $patchcheck_end;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003194 } elsif ($cherry) {
3195 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003196 }
3197
Steven Rostedta57419b2010-11-02 15:13:54 -04003198 # Get the true sha1's since we can use things like HEAD~3
3199 $start = get_sha1($start);
3200 $end = get_sha1($end);
3201
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003202 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003203
3204 # Can't have a test without having a test to run
3205 if ($type eq "test" && !defined($run_test)) {
3206 $type = "boot";
3207 }
3208
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003209 if ($cherry) {
3210 open (IN, "git cherry -v $start $end|") or
3211 dodie "could not get git list";
3212 } else {
3213 open (IN, "git log --pretty=oneline $end|") or
3214 dodie "could not get git list";
3215 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003216
3217 my @list;
3218
3219 while (<IN>) {
3220 chomp;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003221 # git cherry adds a '+' we want to remove
3222 s/^\+ //;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003223 $list[$#list+1] = $_;
3224 last if (/^$start/);
3225 }
3226 close(IN);
3227
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003228 if (!$cherry) {
3229 if ($list[$#list] !~ /^$start/) {
3230 fail "SHA1 $start not found";
3231 }
3232
3233 # go backwards in the list
3234 @list = reverse @list;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003235 }
3236
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003237 doprint("Going to test the following commits:\n");
3238 foreach my $l (@list) {
3239 doprint "$l\n";
3240 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003241
3242 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003243 my %ignored_warnings;
3244
3245 if (defined($ignore_warnings)) {
3246 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3247 $ignored_warnings{$sha1} = 1;
3248 }
3249 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003250
3251 $in_patchcheck = 1;
3252 foreach my $item (@list) {
3253 my $sha1 = $item;
3254 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3255
3256 doprint "\nProcessing commit $item\n\n";
3257
3258 run_command "git checkout $sha1" or
3259 die "Failed to checkout $sha1";
3260
3261 # only clean on the first and last patch
3262 if ($item eq $list[0] ||
3263 $item eq $list[$#list]) {
3264 $noclean = $save_clean;
3265 } else {
3266 $noclean = 1;
3267 }
3268
3269 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003270 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003271 } else {
3272 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003273 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003274 }
3275
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003276 # No need to do per patch checking if warnings file exists
3277 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3278 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003279 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003280
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003281 check_buildlog or return 0;
3282
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003283 next if ($type eq "build");
3284
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003285 my $failed = 0;
3286
Steven Rostedtddf607e2011-06-14 20:49:13 -04003287 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003288
3289 if (!$failed && $type ne "boot"){
3290 do_run_test or $failed = 1;
3291 }
3292 end_monitor;
3293 return 0 if ($failed);
3294
Steven Rostedt27d934b2011-05-20 09:18:18 -04003295 patchcheck_reboot;
3296
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003297 }
3298 $in_patchcheck = 0;
3299 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003300
3301 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003302}
3303
Steven Rostedtb9066f62011-07-15 21:25:24 -04003304my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003305my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003306my $iflevel = 0;
3307my @ifdeps;
3308
3309# prevent recursion
3310my %read_kconfigs;
3311
Steven Rostedtac6974c2011-10-04 09:40:17 -04003312sub add_dep {
3313 # $config depends on $dep
3314 my ($config, $dep) = @_;
3315
3316 if (defined($depends{$config})) {
3317 $depends{$config} .= " " . $dep;
3318 } else {
3319 $depends{$config} = $dep;
3320 }
3321
3322 # record the number of configs depending on $dep
3323 if (defined $depcount{$dep}) {
3324 $depcount{$dep}++;
3325 } else {
3326 $depcount{$dep} = 1;
3327 }
3328}
3329
Steven Rostedtb9066f62011-07-15 21:25:24 -04003330# taken from streamline_config.pl
3331sub read_kconfig {
3332 my ($kconfig) = @_;
3333
3334 my $state = "NONE";
3335 my $config;
3336 my @kconfigs;
3337
3338 my $cont = 0;
3339 my $line;
3340
3341
3342 if (! -f $kconfig) {
3343 doprint "file $kconfig does not exist, skipping\n";
3344 return;
3345 }
3346
3347 open(KIN, "$kconfig")
3348 or die "Can't open $kconfig";
3349 while (<KIN>) {
3350 chomp;
3351
3352 # Make sure that lines ending with \ continue
3353 if ($cont) {
3354 $_ = $line . " " . $_;
3355 }
3356
3357 if (s/\\$//) {
3358 $cont = 1;
3359 $line = $_;
3360 next;
3361 }
3362
3363 $cont = 0;
3364
3365 # collect any Kconfig sources
3366 if (/^source\s*"(.*)"/) {
3367 $kconfigs[$#kconfigs+1] = $1;
3368 }
3369
3370 # configs found
3371 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3372 $state = "NEW";
3373 $config = $2;
3374
3375 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003376 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003377 }
3378
3379 # collect the depends for the config
3380 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3381
Steven Rostedtac6974c2011-10-04 09:40:17 -04003382 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003383
3384 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003385 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3386
3387 # selected by depends on config
3388 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003389
3390 # Check for if statements
3391 } elsif (/^if\s+(.*\S)\s*$/) {
3392 my $deps = $1;
3393 # remove beginning and ending non text
3394 $deps =~ s/^[^a-zA-Z0-9_]*//;
3395 $deps =~ s/[^a-zA-Z0-9_]*$//;
3396
3397 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3398
3399 $ifdeps[$iflevel++] = join ':', @deps;
3400
3401 } elsif (/^endif/) {
3402
3403 $iflevel-- if ($iflevel);
3404
3405 # stop on "help"
3406 } elsif (/^\s*help\s*$/) {
3407 $state = "NONE";
3408 }
3409 }
3410 close(KIN);
3411
3412 # read in any configs that were found.
3413 foreach $kconfig (@kconfigs) {
3414 if (!defined($read_kconfigs{$kconfig})) {
3415 $read_kconfigs{$kconfig} = 1;
3416 read_kconfig("$builddir/$kconfig");
3417 }
3418 }
3419}
3420
3421sub read_depends {
3422 # find out which arch this is by the kconfig file
3423 open (IN, $output_config)
3424 or dodie "Failed to read $output_config";
3425 my $arch;
3426 while (<IN>) {
3427 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3428 $arch = $1;
3429 last;
3430 }
3431 }
3432 close IN;
3433
3434 if (!defined($arch)) {
3435 doprint "Could not find arch from config file\n";
3436 doprint "no dependencies used\n";
3437 return;
3438 }
3439
3440 # arch is really the subarch, we need to know
3441 # what directory to look at.
3442 if ($arch eq "i386" || $arch eq "x86_64") {
3443 $arch = "x86";
3444 } elsif ($arch =~ /^tile/) {
3445 $arch = "tile";
3446 }
3447
3448 my $kconfig = "$builddir/arch/$arch/Kconfig";
3449
3450 if (! -f $kconfig && $arch =~ /\d$/) {
3451 my $orig = $arch;
3452 # some subarchs have numbers, truncate them
3453 $arch =~ s/\d*$//;
3454 $kconfig = "$builddir/arch/$arch/Kconfig";
3455 if (! -f $kconfig) {
3456 doprint "No idea what arch dir $orig is for\n";
3457 doprint "no dependencies used\n";
3458 return;
3459 }
3460 }
3461
3462 read_kconfig($kconfig);
3463}
3464
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003465sub make_new_config {
3466 my @configs = @_;
3467
3468 open (OUT, ">$output_config")
3469 or dodie "Failed to write $output_config";
3470
3471 foreach my $config (@configs) {
3472 print OUT "$config\n";
3473 }
3474 close OUT;
3475}
3476
Steven Rostedtac6974c2011-10-04 09:40:17 -04003477sub chomp_config {
3478 my ($config) = @_;
3479
3480 $config =~ s/CONFIG_//;
3481
3482 return $config;
3483}
3484
Steven Rostedtb9066f62011-07-15 21:25:24 -04003485sub get_depends {
3486 my ($dep) = @_;
3487
Steven Rostedtac6974c2011-10-04 09:40:17 -04003488 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003489
3490 $dep = $depends{"$kconfig"};
3491
3492 # the dep string we have saves the dependencies as they
3493 # were found, including expressions like ! && ||. We
3494 # want to split this out into just an array of configs.
3495
3496 my $valid = "A-Za-z_0-9";
3497
3498 my @configs;
3499
3500 while ($dep =~ /[$valid]/) {
3501
3502 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3503 my $conf = "CONFIG_" . $1;
3504
3505 $configs[$#configs + 1] = $conf;
3506
3507 $dep =~ s/^[^$valid]*[$valid]+//;
3508 } else {
3509 die "this should never happen";
3510 }
3511 }
3512
3513 return @configs;
3514}
3515
3516my %min_configs;
3517my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003518my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003519my %processed_configs;
3520my %nochange_config;
3521
3522sub test_this_config {
3523 my ($config) = @_;
3524
3525 my $found;
3526
3527 # if we already processed this config, skip it
3528 if (defined($processed_configs{$config})) {
3529 return undef;
3530 }
3531 $processed_configs{$config} = 1;
3532
3533 # if this config failed during this round, skip it
3534 if (defined($nochange_config{$config})) {
3535 return undef;
3536 }
3537
Steven Rostedtac6974c2011-10-04 09:40:17 -04003538 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003539
3540 # Test dependencies first
3541 if (defined($depends{"$kconfig"})) {
3542 my @parents = get_depends $config;
3543 foreach my $parent (@parents) {
3544 # if the parent is in the min config, check it first
3545 next if (!defined($min_configs{$parent}));
3546 $found = test_this_config($parent);
3547 if (defined($found)) {
3548 return $found;
3549 }
3550 }
3551 }
3552
3553 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003554 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003555 # .config to make sure it is missing the config that
3556 # we had before
3557 my %configs = %min_configs;
3558 delete $configs{$config};
3559 make_new_config ((values %configs), (values %keep_configs));
3560 make_oldconfig;
3561 undef %configs;
3562 assign_configs \%configs, $output_config;
3563
3564 return $config if (!defined($configs{$config}));
3565
3566 doprint "disabling config $config did not change .config\n";
3567
3568 $nochange_config{$config} = 1;
3569
3570 return undef;
3571}
3572
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003573sub make_min_config {
3574 my ($i) = @_;
3575
Steven Rostedtccc513b2012-05-21 17:13:40 -04003576 my $type = $minconfig_type;
3577 if ($type ne "boot" && $type ne "test") {
3578 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3579 " make_min_config works only with 'boot' and 'test'\n" and return;
3580 }
3581
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003582 if (!defined($output_minconfig)) {
3583 fail "OUTPUT_MIN_CONFIG not defined" and return;
3584 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003585
3586 # If output_minconfig exists, and the start_minconfig
3587 # came from min_config, than ask if we should use
3588 # that instead.
3589 if (-f $output_minconfig && !$start_minconfig_defined) {
3590 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003591 if (!defined($use_output_minconfig)) {
3592 if (read_yn " Use it as minconfig?") {
3593 $start_minconfig = $output_minconfig;
3594 }
3595 } elsif ($use_output_minconfig > 0) {
3596 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003597 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003598 } else {
3599 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003600 }
3601 }
3602
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003603 if (!defined($start_minconfig)) {
3604 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3605 }
3606
Steven Rostedt35ce5952011-07-15 21:57:25 -04003607 my $temp_config = "$tmpdir/temp_config";
3608
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003609 # First things first. We build an allnoconfig to find
3610 # out what the defaults are that we can't touch.
3611 # Some are selections, but we really can't handle selections.
3612
3613 my $save_minconfig = $minconfig;
3614 undef $minconfig;
3615
3616 run_command "$make allnoconfig" or return 0;
3617
Steven Rostedtb9066f62011-07-15 21:25:24 -04003618 read_depends;
3619
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003620 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003621
Steven Rostedt43d1b652011-07-15 22:01:56 -04003622 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003623 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003624
3625 if (defined($ignore_config)) {
3626 # make sure the file exists
3627 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003628 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003629 }
3630
Steven Rostedt43d1b652011-07-15 22:01:56 -04003631 %keep_configs = %save_configs;
3632
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003633 doprint "Load initial configs from $start_minconfig\n";
3634
3635 # Look at the current min configs, and save off all the
3636 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003637 assign_configs \%min_configs, $start_minconfig;
3638
3639 my @config_keys = keys %min_configs;
3640
Steven Rostedtac6974c2011-10-04 09:40:17 -04003641 # All configs need a depcount
3642 foreach my $config (@config_keys) {
3643 my $kconfig = chomp_config $config;
3644 if (!defined $depcount{$kconfig}) {
3645 $depcount{$kconfig} = 0;
3646 }
3647 }
3648
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003649 # Remove anything that was set by the make allnoconfig
3650 # we shouldn't need them as they get set for us anyway.
3651 foreach my $config (@config_keys) {
3652 # Remove anything in the ignore_config
3653 if (defined($keep_configs{$config})) {
3654 my $file = $ignore_config;
3655 $file =~ s,.*/(.*?)$,$1,;
3656 doprint "$config set by $file ... ignored\n";
3657 delete $min_configs{$config};
3658 next;
3659 }
3660 # But make sure the settings are the same. If a min config
3661 # sets a selection, we do not want to get rid of it if
3662 # it is not the same as what we have. Just move it into
3663 # the keep configs.
3664 if (defined($config_ignore{$config})) {
3665 if ($config_ignore{$config} ne $min_configs{$config}) {
3666 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3667 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3668 $keep_configs{$config} = $min_configs{$config};
3669 } else {
3670 doprint "$config set by allnoconfig ... ignored\n";
3671 }
3672 delete $min_configs{$config};
3673 }
3674 }
3675
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003676 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003677 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003678
3679 while (!$done) {
3680
3681 my $config;
3682 my $found;
3683
3684 # Now disable each config one by one and do a make oldconfig
3685 # till we find a config that changes our list.
3686
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003687 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003688
3689 # Sort keys by who is most dependent on
3690 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3691 @test_configs ;
3692
3693 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003694 my $reset = 1;
3695 for (my $i = 0; $i < $#test_configs; $i++) {
3696 if (!defined($nochange_config{$test_configs[0]})) {
3697 $reset = 0;
3698 last;
3699 }
3700 # This config didn't change the .config last time.
3701 # Place it at the end
3702 my $config = shift @test_configs;
3703 push @test_configs, $config;
3704 }
3705
3706 # if every test config has failed to modify the .config file
3707 # in the past, then reset and start over.
3708 if ($reset) {
3709 undef %nochange_config;
3710 }
3711
Steven Rostedtb9066f62011-07-15 21:25:24 -04003712 undef %processed_configs;
3713
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003714 foreach my $config (@test_configs) {
3715
Steven Rostedtb9066f62011-07-15 21:25:24 -04003716 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003717
Steven Rostedtb9066f62011-07-15 21:25:24 -04003718 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003719
3720 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003721 }
3722
3723 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003724 # we could have failed due to the nochange_config hash
3725 # reset and try again
3726 if (!$take_two) {
3727 undef %nochange_config;
3728 $take_two = 1;
3729 next;
3730 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003731 doprint "No more configs found that we can disable\n";
3732 $done = 1;
3733 last;
3734 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003735 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003736
3737 $config = $found;
3738
3739 doprint "Test with $config disabled\n";
3740
3741 # set in_bisect to keep build and monitor from dieing
3742 $in_bisect = 1;
3743
3744 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003745 build "oldconfig" or $failed = 1;
3746 if (!$failed) {
3747 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003748
3749 if ($type eq "test" && !$failed) {
3750 do_run_test or $failed = 1;
3751 }
3752
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003753 end_monitor;
3754 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003755
3756 $in_bisect = 0;
3757
3758 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003759 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003760 # this config is needed, add it to the ignore list.
3761 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003762 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003763 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003764
3765 # update new ignore configs
3766 if (defined($ignore_config)) {
3767 open (OUT, ">$temp_config")
3768 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003769 foreach my $config (keys %save_configs) {
3770 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003771 }
3772 close OUT;
3773 run_command "mv $temp_config $ignore_config" or
3774 dodie "failed to copy update to $ignore_config";
3775 }
3776
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003777 } else {
3778 # We booted without this config, remove it from the minconfigs.
3779 doprint "$config is not needed, disabling\n";
3780
3781 delete $min_configs{$config};
3782
3783 # Also disable anything that is not enabled in this config
3784 my %configs;
3785 assign_configs \%configs, $output_config;
3786 my @config_keys = keys %min_configs;
3787 foreach my $config (@config_keys) {
3788 if (!defined($configs{$config})) {
3789 doprint "$config is not set, disabling\n";
3790 delete $min_configs{$config};
3791 }
3792 }
3793
3794 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003795 open (OUT, ">$temp_config")
3796 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003797 foreach my $config (keys %keep_configs) {
3798 print OUT "$keep_configs{$config}\n";
3799 }
3800 foreach my $config (keys %min_configs) {
3801 print OUT "$min_configs{$config}\n";
3802 }
3803 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003804
3805 run_command "mv $temp_config $output_minconfig" or
3806 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003807 }
3808
3809 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003810 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003811 }
3812
3813 success $i;
3814 return 1;
3815}
3816
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003817sub make_warnings_file {
3818 my ($i) = @_;
3819
3820 if (!defined($warnings_file)) {
3821 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3822 }
3823
3824 if ($build_type eq "nobuild") {
3825 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3826 }
3827
3828 build $build_type or dodie "Failed to build";
3829
3830 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3831
3832 open(IN, $buildlog) or dodie "Can't open $buildlog";
3833 while (<IN>) {
3834
3835 # Some compilers use UTF-8 extended for quotes
3836 # for distcc heterogeneous systems, this causes issues
3837 s/$utf8_quote/'/g;
3838
3839 if (/$check_build_re/) {
3840 print OUT;
3841 }
3842 }
3843 close(IN);
3844
3845 close(OUT);
3846
3847 success $i;
3848}
3849
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09003850$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003851
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003852if ($#ARGV == 0) {
3853 $ktest_config = $ARGV[0];
3854 if (! -f $ktest_config) {
3855 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003856 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003857 exit 0;
3858 }
3859 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003860}
3861
3862if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003863 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003864 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003865 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3866 print OUT << "EOF"
3867# Generated by ktest.pl
3868#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003869
3870# PWD is a ktest.pl variable that will result in the process working
3871# directory that ktest.pl is executed in.
3872
3873# THIS_DIR is automatically assigned the PWD of the path that generated
3874# the config file. It is best to use this variable when assigning other
3875# directory paths within this directory. This allows you to easily
3876# move the test cases to other locations or to other machines.
3877#
3878THIS_DIR := $variable{"PWD"}
3879
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003880# Define each test with TEST_START
3881# The config options below it will override the defaults
3882TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003883TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003884
3885DEFAULTS
3886EOF
3887;
3888 close(OUT);
3889}
3890read_config $ktest_config;
3891
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003892if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003893 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003894}
3895
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003896# Append any configs entered in manually to the config file.
3897my @new_configs = keys %entered_configs;
3898if ($#new_configs >= 0) {
3899 print "\nAppending entered in configs to $ktest_config\n";
3900 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3901 foreach my $config (@new_configs) {
3902 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003903 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003904 }
3905}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003906
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003907if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3908 unlink $opt{"LOG_FILE"};
3909}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003910
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003911doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3912
Steven Rostedta57419b2010-11-02 15:13:54 -04003913for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3914
3915 if (!$i) {
3916 doprint "DEFAULT OPTIONS:\n";
3917 } else {
3918 doprint "\nTEST $i OPTIONS";
3919 if (defined($repeat_tests{$i})) {
3920 $repeat = $repeat_tests{$i};
3921 doprint " ITERATE $repeat";
3922 }
3923 doprint "\n";
3924 }
3925
3926 foreach my $option (sort keys %opt) {
3927
3928 if ($option =~ /\[(\d+)\]$/) {
3929 next if ($i != $1);
3930 } else {
3931 next if ($i);
3932 }
3933
3934 doprint "$option = $opt{$option}\n";
3935 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003936}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003937
Steven Rostedt2a625122011-05-20 15:48:59 -04003938sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003939 my ($name, $i) = @_;
3940
3941 my $option = "$name\[$i\]";
3942
3943 if (defined($opt{$option})) {
3944 return $opt{$option};
3945 }
3946
Steven Rostedta57419b2010-11-02 15:13:54 -04003947 foreach my $test (keys %repeat_tests) {
3948 if ($i >= $test &&
3949 $i < $test + $repeat_tests{$test}) {
3950 $option = "$name\[$test\]";
3951 if (defined($opt{$option})) {
3952 return $opt{$option};
3953 }
3954 }
3955 }
3956
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003957 if (defined($opt{$name})) {
3958 return $opt{$name};
3959 }
3960
3961 return undef;
3962}
3963
Steven Rostedt2a625122011-05-20 15:48:59 -04003964sub set_test_option {
3965 my ($name, $i) = @_;
3966
3967 my $option = __set_test_option($name, $i);
3968 return $option if (!defined($option));
3969
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003970 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003971}
3972
Steven Rostedt2545eb62010-11-02 15:01:32 -04003973# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003974for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003975
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003976 # Do not reboot on failing test options
3977 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003978 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003979
Steven Rostedt683a3e62012-05-18 13:34:35 -04003980 $have_version = 0;
3981
Steven Rostedt576f6272010-11-02 14:58:38 -04003982 $iteration = $i;
3983
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003984 undef %force_config;
3985
Steven Rostedta75fece2010-11-02 14:58:27 -04003986 my $makecmd = set_test_option("MAKE_CMD", $i);
3987
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003988 $outputdir = set_test_option("OUTPUT_DIR", $i);
3989 $builddir = set_test_option("BUILD_DIR", $i);
3990
3991 chdir $builddir || die "can't change directory to $builddir";
3992
3993 if (!-d $outputdir) {
3994 mkpath($outputdir) or
3995 die "can't create $outputdir";
3996 }
3997
3998 $make = "$makecmd O=$outputdir";
3999
Steven Rostedt9cc9e092011-12-22 21:37:22 -05004000 # Load all the options into their mapped variable names
4001 foreach my $opt (keys %option_map) {
4002 ${$option_map{$opt}} = set_test_option($opt, $i);
4003 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004004
Steven Rostedt35ce5952011-07-15 21:57:25 -04004005 $start_minconfig_defined = 1;
4006
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004007 # The first test may override the PRE_KTEST option
4008 if (defined($pre_ktest) && $i == 1) {
4009 doprint "\n";
4010 run_command $pre_ktest;
4011 }
4012
4013 # Any test can override the POST_KTEST option
4014 # The last test takes precedence.
4015 if (defined($post_ktest)) {
4016 $final_post_ktest = $post_ktest;
4017 }
4018
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004019 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004020 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004021 $start_minconfig = $minconfig;
4022 }
4023
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004024 if (!-d $tmpdir) {
4025 mkpath($tmpdir) or
4026 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004027 }
4028
Steven Rostedte48c5292010-11-02 14:35:37 -04004029 $ENV{"SSH_USER"} = $ssh_user;
4030 $ENV{"MACHINE"} = $machine;
4031
Steven Rostedta75fece2010-11-02 14:58:27 -04004032 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304033 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004034 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004035 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004036
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004037 if (!$buildonly) {
4038 $target = "$ssh_user\@$machine";
4039 if ($reboot_type eq "grub") {
4040 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004041 } elsif ($reboot_type eq "grub2") {
4042 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4043 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004044 } elsif ($reboot_type eq "syslinux") {
4045 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004046 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004047 }
4048
4049 my $run_type = $build_type;
4050 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004051 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004052 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004053 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004054 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004055 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004056 } elsif ($test_type eq "make_min_config") {
4057 $run_type = "";
4058 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004059 $run_type = "";
4060 }
4061
Steven Rostedta75fece2010-11-02 14:58:27 -04004062 # mistake in config file?
4063 if (!defined($run_type)) {
4064 $run_type = "ERROR";
4065 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004066
Steven Rostedte0a87422011-09-30 17:50:48 -04004067 my $installme = "";
4068 $installme = " no_install" if ($no_install);
4069
Steven Rostedt2545eb62010-11-02 15:01:32 -04004070 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04004071 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004072
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004073 if (defined($pre_test)) {
4074 run_command $pre_test;
4075 }
4076
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004077 unlink $dmesg;
4078 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304079 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004080
Steven Rostedt250bae82011-07-15 22:05:59 -04004081 if (defined($addconfig)) {
4082 my $min = $minconfig;
4083 if (!defined($minconfig)) {
4084 $min = "";
4085 }
4086 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004087 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004088 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004089 }
4090
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004091 if (defined($checkout)) {
4092 run_command "git checkout $checkout" or
4093 die "failed to checkout $checkout";
4094 }
4095
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004096 $no_reboot = 0;
4097
Steven Rostedt648a1822012-03-21 11:18:27 -04004098 # A test may opt to not reboot the box
4099 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004100 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004101 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004102
Steven Rostedta75fece2010-11-02 14:58:27 -04004103 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004104 bisect $i;
4105 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004106 } elsif ($test_type eq "config_bisect") {
4107 config_bisect $i;
4108 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004109 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004110 patchcheck $i;
4111 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004112 } elsif ($test_type eq "make_min_config") {
4113 make_min_config $i;
4114 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004115 } elsif ($test_type eq "make_warnings_file") {
4116 $no_reboot = 1;
4117 make_warnings_file $i;
4118 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004119 }
4120
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004121 if ($build_type ne "nobuild") {
4122 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004123 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004124 }
4125
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004126 if ($test_type eq "install") {
4127 get_version;
4128 install;
4129 success $i;
4130 next;
4131 }
4132
Steven Rostedta75fece2010-11-02 14:58:27 -04004133 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004134 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004135 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004136
4137 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4138 do_run_test or $failed = 1;
4139 }
4140 end_monitor;
4141 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004142 }
4143
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004144 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004145}
4146
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004147if (defined($final_post_ktest)) {
4148 run_command $final_post_ktest;
4149}
4150
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004151if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004152 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004153} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004154 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004155} elsif (defined($switch_to_good)) {
4156 # still need to get to the good kernel
4157 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004158}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004159
Steven Rostedt648a1822012-03-21 11:18:27 -04004160
Steven Rostedte48c5292010-11-02 14:35:37 -04004161doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4162
Steven Rostedt2545eb62010-11-02 15:01:32 -04004163exit 0;