blob: 085452fa045be66c6233d54d4183e0b767120c9d [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 (;;) {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002341 doprint "Pass, fail, or skip? [p/f/s]";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002342 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;
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002348 } elsif ($ans eq "s" || $ans eq "S") {
2349 return -1;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002350 } else {
Chris J Argesfee9d3e2014-08-27 13:26:53 -05002351 print "Please answer 'p', 'f', or 's'\n";
Steven Rostedtc960bb92011-03-08 09:22:39 -05002352 }
2353 }
2354}
2355
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002356sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002357 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002358
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002359 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002360 $reboot_on_error = 0;
2361 $poweroff_on_error = 0;
2362 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002363
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002364 run_command $run_test, $testlog or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302365
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002366 exit $failed;
2367}
2368
2369my $child_done;
2370
2371sub child_finished {
2372 $child_done = 1;
2373}
2374
2375sub do_run_test {
2376 my $child_pid;
2377 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002378 my $line;
2379 my $full_line;
2380 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002381 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002382
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002383 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002384
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002385 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002386
2387 $child_done = 0;
2388
2389 $SIG{CHLD} = qw(child_finished);
2390
2391 $child_pid = fork;
2392
2393 child_run_test if (!$child_pid);
2394
2395 $full_line = "";
2396
2397 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002398 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002399 if (defined($line)) {
2400
2401 # we are not guaranteed to get a full line
2402 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002403 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002404
2405 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002406 if ($ignore_errors) {
2407 $bug_ignored = 1;
2408 } else {
2409 $bug = 1;
2410 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002411 }
2412
2413 if ($full_line =~ /Kernel panic -/) {
2414 $bug = 1;
2415 }
2416
2417 if ($line =~ /\n/) {
2418 $full_line = "";
2419 }
2420 }
2421 } while (!$child_done && !$bug);
2422
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002423 if (!$bug && $bug_ignored) {
2424 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2425 }
2426
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002427 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002428 my $failure_start = time;
2429 my $now;
2430 do {
2431 $line = wait_for_input($monitor_fp, 1);
2432 if (defined($line)) {
2433 doprint $line;
2434 }
2435 $now = time;
2436 if ($now - $failure_start >= $stop_after_failure) {
2437 last;
2438 }
2439 } while (defined($line));
2440
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002441 doprint "Detected kernel crash!\n";
2442 # kill the child with extreme prejudice
2443 kill 9, $child_pid;
2444 }
2445
2446 waitpid $child_pid, 0;
2447 $child_exit = $?;
2448
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002449 if (!$bug && $in_bisect) {
2450 if (defined($bisect_ret_good)) {
2451 if ($child_exit == $bisect_ret_good) {
2452 return 1;
2453 }
2454 }
2455 if (defined($bisect_ret_skip)) {
2456 if ($child_exit == $bisect_ret_skip) {
2457 return -1;
2458 }
2459 }
2460 if (defined($bisect_ret_abort)) {
2461 if ($child_exit == $bisect_ret_abort) {
2462 fail "test abort" and return -2;
2463 }
2464 }
2465 if (defined($bisect_ret_bad)) {
2466 if ($child_exit == $bisect_ret_skip) {
2467 return 0;
2468 }
2469 }
2470 if (defined($bisect_ret_default)) {
2471 if ($bisect_ret_default eq "good") {
2472 return 1;
2473 } elsif ($bisect_ret_default eq "bad") {
2474 return 0;
2475 } elsif ($bisect_ret_default eq "skip") {
2476 return -1;
2477 } elsif ($bisect_ret_default eq "abort") {
2478 return -2;
2479 } else {
2480 fail "unknown default action: $bisect_ret_default"
2481 and return -2;
2482 }
2483 }
2484 }
2485
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002486 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002487 return 0 if $in_bisect;
2488 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002489 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002490 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002491}
2492
Steven Rostedta75fece2010-11-02 14:58:27 -04002493sub run_git_bisect {
2494 my ($command) = @_;
2495
2496 doprint "$command ... ";
2497
2498 my $output = `$command 2>&1`;
2499 my $ret = $?;
2500
2501 logit $output;
2502
2503 if ($ret) {
2504 doprint "FAILED\n";
2505 dodie "Failed to git bisect";
2506 }
2507
2508 doprint "SUCCESS\n";
2509 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2510 doprint "$1 [$2]\n";
2511 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002512 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002513 doprint "Found bad commit... $1\n";
2514 return 0;
2515 } else {
2516 # we already logged it, just print it now.
2517 print $output;
2518 }
2519
2520 return 1;
2521}
2522
Steven Rostedtc23dca72011-03-08 09:26:31 -05002523sub bisect_reboot {
2524 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002525 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002526}
2527
2528# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002529sub run_bisect_test {
2530 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002531
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002532 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002533 my $result;
2534 my $output;
2535 my $ret;
2536
Steven Rostedt0a05c762010-11-08 11:14:10 -05002537 $in_bisect = 1;
2538
2539 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002540
2541 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002542 if ($failed && $bisect_skip) {
2543 $in_bisect = 0;
2544 return -1;
2545 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002546 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002547
2548 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002549 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002550
2551 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002552 if ($failed && $bisect_skip) {
2553 end_monitor;
2554 bisect_reboot;
2555 $in_bisect = 0;
2556 return -1;
2557 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002558 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002559
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002560 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002561 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002562 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002563 }
2564
2565 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002566 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002567 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002568 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002569 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002570
2571 # reboot the box to a kernel we can ssh to
2572 if ($type ne "build") {
2573 bisect_reboot;
2574 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002575 $in_bisect = 0;
2576
2577 return $result;
2578}
2579
2580sub run_bisect {
2581 my ($type) = @_;
2582 my $buildtype = "oldconfig";
2583
2584 # We should have a minconfig to use?
2585 if (defined($minconfig)) {
2586 $buildtype = "useconfig:$minconfig";
2587 }
2588
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002589 # If the user sets bisect_tries to less than 1, then no tries
2590 # is a success.
2591 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002592
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002593 # Still let the user manually decide that though.
2594 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002595 $ret = answer_bisect;
2596 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002597
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002598 for (my $i = 0; $i < $bisect_tries; $i++) {
2599 if ($bisect_tries > 1) {
2600 my $t = $i + 1;
2601 doprint("Running bisect trial $t of $bisect_tries:\n");
2602 }
2603 $ret = run_bisect_test $type, $buildtype;
2604
2605 if ($bisect_manual) {
2606 $ret = answer_bisect;
2607 }
2608
2609 last if (!$ret);
2610 }
2611
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002612 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002613 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002614 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002615 }
2616
Steven Rostedtc23dca72011-03-08 09:26:31 -05002617 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002618 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002619 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002620 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002621 } elsif ($bisect_skip) {
2622 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2623 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002624 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002625}
2626
Steven Rostedtdad98752011-11-22 20:48:57 -05002627sub update_bisect_replay {
2628 my $tmp_log = "$tmpdir/ktest_bisect_log";
2629 run_command "git bisect log > $tmp_log" or
2630 die "can't create bisect log";
2631 return $tmp_log;
2632}
2633
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002634sub bisect {
2635 my ($i) = @_;
2636
2637 my $result;
2638
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002639 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2640 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2641 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002642
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002643 my $good = $bisect_good;
2644 my $bad = $bisect_bad;
2645 my $type = $bisect_type;
2646 my $start = $bisect_start;
2647 my $replay = $bisect_replay;
2648 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002649
2650 if (defined($start_files)) {
2651 $start_files = " -- " . $start_files;
2652 } else {
2653 $start_files = "";
2654 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002655
Steven Rostedta57419b2010-11-02 15:13:54 -04002656 # convert to true sha1's
2657 $good = get_sha1($good);
2658 $bad = get_sha1($bad);
2659
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002660 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002661 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2662 $reverse_bisect = 1;
2663 } else {
2664 $reverse_bisect = 0;
2665 }
2666
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002667 # Can't have a test without having a test to run
2668 if ($type eq "test" && !defined($run_test)) {
2669 $type = "boot";
2670 }
2671
Steven Rostedtdad98752011-11-22 20:48:57 -05002672 # Check if a bisect was running
2673 my $bisect_start_file = "$builddir/.git/BISECT_START";
2674
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002675 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002676 my $do_check = defined($check) && $check ne "0";
2677
2678 if ( -f $bisect_start_file ) {
2679 print "Bisect in progress found\n";
2680 if ($do_check) {
2681 print " If you say yes, then no checks of good or bad will be done\n";
2682 }
2683 if (defined($replay)) {
2684 print "** BISECT_REPLAY is defined in config file **";
2685 print " Ignore config option and perform new git bisect log?\n";
2686 if (read_ync " (yes, no, or cancel) ") {
2687 $replay = update_bisect_replay;
2688 $do_check = 0;
2689 }
2690 } elsif (read_yn "read git log and continue?") {
2691 $replay = update_bisect_replay;
2692 $do_check = 0;
2693 }
2694 }
2695
2696 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002697
2698 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002699 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002700
2701 if ($check ne "good") {
2702 doprint "TESTING BISECT BAD [$bad]\n";
2703 run_command "git checkout $bad" or
2704 die "Failed to checkout $bad";
2705
2706 $result = run_bisect $type;
2707
2708 if ($result ne "bad") {
2709 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2710 }
2711 }
2712
2713 if ($check ne "bad") {
2714 doprint "TESTING BISECT GOOD [$good]\n";
2715 run_command "git checkout $good" or
2716 die "Failed to checkout $good";
2717
2718 $result = run_bisect $type;
2719
2720 if ($result ne "good") {
2721 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2722 }
2723 }
2724
2725 # checkout where we started
2726 run_command "git checkout $head" or
2727 die "Failed to checkout $head";
2728 }
2729
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002730 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002731 dodie "could not start bisect";
2732
2733 run_command "git bisect good $good" or
2734 dodie "could not set bisect good to $good";
2735
2736 run_git_bisect "git bisect bad $bad" or
2737 dodie "could not set bisect bad to $bad";
2738
2739 if (defined($replay)) {
2740 run_command "git bisect replay $replay" or
2741 dodie "failed to run replay";
2742 }
2743
2744 if (defined($start)) {
2745 run_command "git checkout $start" or
2746 dodie "failed to checkout $start";
2747 }
2748
2749 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002750 do {
2751 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002752 $test = run_git_bisect "git bisect $result";
2753 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002754
2755 run_command "git bisect log" or
2756 dodie "could not capture git bisect log";
2757
2758 run_command "git bisect reset" or
2759 dodie "could not reset git bisect";
2760
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002761 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002762
Steven Rostedt0a05c762010-11-08 11:14:10 -05002763 success $i;
2764}
2765
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002766# config_ignore holds the configs that were set (or unset) for
2767# a good config and we will ignore these configs for the rest
2768# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002769my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002770
2771# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002772my %config_set;
2773
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002774# config_off holds the set of configs that the bad config had disabled.
2775# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002776# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002777my %config_off;
2778
2779# config_off_tmp holds a set of configs to turn off for now
2780my @config_off_tmp;
2781
2782# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002783my %config_list;
2784my %null_config;
2785
2786my %dependency;
2787
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002788sub assign_configs {
2789 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002790
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002791 doprint "Reading configs from $config\n";
2792
Steven Rostedt0a05c762010-11-08 11:14:10 -05002793 open (IN, $config)
2794 or dodie "Failed to read $config";
2795
2796 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002797 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04002798 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002799 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002800 } elsif (/^(# (CONFIG\S*) is not set)/) {
2801 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002802 }
2803 }
2804
2805 close(IN);
2806}
2807
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002808sub process_config_ignore {
2809 my ($config) = @_;
2810
2811 assign_configs \%config_ignore, $config;
2812}
2813
Steven Rostedt0a05c762010-11-08 11:14:10 -05002814sub get_dependencies {
2815 my ($config) = @_;
2816
2817 my $arr = $dependency{$config};
2818 if (!defined($arr)) {
2819 return ();
2820 }
2821
2822 my @deps = @{$arr};
2823
2824 foreach my $dep (@{$arr}) {
2825 print "ADD DEP $dep\n";
2826 @deps = (@deps, get_dependencies $dep);
2827 }
2828
2829 return @deps;
2830}
2831
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002832sub save_config {
2833 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002834
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002835 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002836
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002837 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002838
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002839 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002840
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002841 foreach my $config (keys %configs) {
2842 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002843 }
2844 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002845}
2846
2847sub create_config {
2848 my ($name, $pc) = @_;
2849
2850 doprint "Creating old config from $name configs\n";
2851
2852 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002853
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002854 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002855}
2856
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002857# compare two config hashes, and return configs with different vals.
2858# It returns B's config values, but you can use A to see what A was.
2859sub diff_config_vals {
2860 my ($pa, $pb) = @_;
2861
2862 # crappy Perl way to pass in hashes.
2863 my %a = %{$pa};
2864 my %b = %{$pb};
2865
2866 my %ret;
2867
2868 foreach my $item (keys %a) {
2869 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2870 $ret{$item} = $b{$item};
2871 }
2872 }
2873
2874 return %ret;
2875}
2876
2877# compare two config hashes and return the configs in B but not A
2878sub diff_configs {
2879 my ($pa, $pb) = @_;
2880
2881 my %ret;
2882
2883 # crappy Perl way to pass in hashes.
2884 my %a = %{$pa};
2885 my %b = %{$pb};
2886
2887 foreach my $item (keys %b) {
2888 if (!defined($a{$item})) {
2889 $ret{$item} = $b{$item};
2890 }
2891 }
2892
2893 return %ret;
2894}
2895
2896# return if two configs are equal or not
2897# 0 is equal +1 b has something a does not
2898# +1 if a and b have a different item.
2899# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05002900sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002901 my ($pa, $pb) = @_;
2902
2903 my %ret;
2904
2905 # crappy Perl way to pass in hashes.
2906 my %a = %{$pa};
2907 my %b = %{$pb};
2908
2909 foreach my $item (keys %b) {
2910 if (!defined($a{$item})) {
2911 return 1;
2912 }
2913 if ($a{$item} ne $b{$item}) {
2914 return 1;
2915 }
2916 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002917
2918 foreach my $item (keys %a) {
2919 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002920 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002921 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002922 }
2923
Steven Rostedt0a05c762010-11-08 11:14:10 -05002924 return 0;
2925}
2926
2927sub run_config_bisect_test {
2928 my ($type) = @_;
2929
Steven Rostedt (Red Hat)4cc559b2014-04-23 22:27:27 -04002930 my $ret = run_bisect_test $type, "oldconfig";
2931
2932 if ($bisect_manual) {
2933 $ret = answer_bisect;
2934 }
2935
2936 return $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002937}
2938
Steven Rostedt0a05c762010-11-08 11:14:10 -05002939sub process_failed {
2940 my ($config) = @_;
2941
2942 doprint "\n\n***************************************\n";
2943 doprint "Found bad config: $config\n";
2944 doprint "***************************************\n\n";
2945}
2946
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002947# used for config bisecting
2948my $good_config;
2949my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002950
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002951sub process_new_config {
2952 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002953
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002954 my %tmp_config = %{$tc};
2955 my %good_configs = %{$gc};
2956 my %bad_configs = %{$bc};
2957
2958 my %new_configs;
2959
2960 my $runtest = 1;
2961 my $ret;
2962
2963 create_config "tmp_configs", \%tmp_config;
2964 assign_configs \%new_configs, $output_config;
2965
2966 $ret = compare_configs \%new_configs, \%bad_configs;
2967 if (!$ret) {
2968 doprint "New config equals bad config, try next test\n";
2969 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002970 }
2971
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002972 if ($runtest) {
2973 $ret = compare_configs \%new_configs, \%good_configs;
2974 if (!$ret) {
2975 doprint "New config equals good config, try next test\n";
2976 $runtest = 0;
2977 }
2978 }
2979
2980 %{$nc} = %new_configs;
2981
2982 return $runtest;
2983}
2984
2985sub run_config_bisect {
2986 my ($pgood, $pbad) = @_;
2987
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002988 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002989
2990 my %good_configs = %{$pgood};
2991 my %bad_configs = %{$pbad};
2992
2993 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
2994 my %b_configs = diff_configs \%good_configs, \%bad_configs;
2995 my %g_configs = diff_configs \%bad_configs, \%good_configs;
2996
2997 my @diff_arr = keys %diff_configs;
2998 my $len_diff = $#diff_arr + 1;
2999
3000 my @b_arr = keys %b_configs;
3001 my $len_b = $#b_arr + 1;
3002
3003 my @g_arr = keys %g_configs;
3004 my $len_g = $#g_arr + 1;
3005
3006 my $runtest = 1;
3007 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003008 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003009
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003010 # First, lets get it down to a single subset.
3011 # Is the problem with a difference in values?
3012 # Is the problem with a missing config?
3013 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003014
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003015 # Enable all of one set and see if we get a new bad
3016 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003017
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003018 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003019
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003020 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003021
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003022 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003023
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003024 if ($len_diff > 0) {
3025 if ($len_b > 0 || $len_g > 0) {
3026 my %tmp_config = %bad_configs;
3027
3028 doprint "Set tmp config to be bad config with good config values\n";
3029 foreach my $item (@diff_arr) {
3030 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003031 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003032
3033 $runtest = process_new_config \%tmp_config, \%new_configs,
3034 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003035 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003036 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003037
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003038 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003039
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003040 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003041 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003042 return 1;
3043 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003044 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003045
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003046 my $half = int($#diff_arr / 2);
3047 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003048
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003049 doprint "Settings bisect with top half:\n";
3050 doprint "Set tmp config to be bad config with some good config values\n";
3051 foreach my $item (@tophalf) {
3052 $tmp_config{$item} = $good_configs{$item};
3053 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003054
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003055 $runtest = process_new_config \%tmp_config, \%new_configs,
3056 \%good_configs, \%bad_configs;
3057
3058 if (!$runtest) {
3059 my %tmp_config = %bad_configs;
3060
3061 doprint "Try bottom half\n";
3062
3063 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3064
3065 foreach my $item (@bottomhalf) {
3066 $tmp_config{$item} = $good_configs{$item};
3067 }
3068
3069 $runtest = process_new_config \%tmp_config, \%new_configs,
3070 \%good_configs, \%bad_configs;
3071 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003072 }
3073
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003074 if ($runtest) {
3075 $ret = run_config_bisect_test $type;
3076 if ($ret) {
3077 doprint "NEW GOOD CONFIG\n";
3078 %good_configs = %new_configs;
3079 run_command "mv $good_config ${good_config}.last";
3080 save_config \%good_configs, $good_config;
3081 %{$pgood} = %good_configs;
3082 } else {
3083 doprint "NEW BAD CONFIG\n";
3084 %bad_configs = %new_configs;
3085 run_command "mv $bad_config ${bad_config}.last";
3086 save_config \%bad_configs, $bad_config;
3087 %{$pbad} = %bad_configs;
3088 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003089 return 0;
3090 }
3091
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003092 fail "Hmm, need to do a mix match?\n";
3093 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003094}
3095
3096sub config_bisect {
3097 my ($i) = @_;
3098
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003099 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003100 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003101
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003102 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003103
Steven Rostedt30f75da2011-06-13 10:35:35 -04003104 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003105 $good_config = $config_bisect_good;
3106 } elsif (defined($minconfig)) {
3107 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003108 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003109 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003110 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003111 if (!$ret) {
3112 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3113 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003114 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003115 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003116 }
3117
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003118 # we don't want min configs to cause issues here.
3119 doprint "Disabling 'MIN_CONFIG' for this test\n";
3120 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003121
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003122 my %good_configs;
3123 my %bad_configs;
3124 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003125
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003126 doprint "Run good configs through make oldconfig\n";
3127 assign_configs \%tmp_configs, $good_config;
3128 create_config "$good_config", \%tmp_configs;
3129 assign_configs \%good_configs, $output_config;
3130
3131 doprint "Run bad configs through make oldconfig\n";
3132 assign_configs \%tmp_configs, $bad_config;
3133 create_config "$bad_config", \%tmp_configs;
3134 assign_configs \%bad_configs, $output_config;
3135
3136 $good_config = "$tmpdir/good_config";
3137 $bad_config = "$tmpdir/bad_config";
3138
3139 save_config \%good_configs, $good_config;
3140 save_config \%bad_configs, $bad_config;
3141
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003142
3143 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3144 if ($config_bisect_check ne "good") {
3145 doprint "Testing bad config\n";
3146
3147 $ret = run_bisect_test $type, "useconfig:$bad_config";
3148 if ($ret) {
3149 fail "Bad config succeeded when expected to fail!";
3150 return 0;
3151 }
3152 }
3153 if ($config_bisect_check ne "bad") {
3154 doprint "Testing good config\n";
3155
3156 $ret = run_bisect_test $type, "useconfig:$good_config";
3157 if (!$ret) {
3158 fail "Good config failed when expected to succeed!";
3159 return 0;
3160 }
3161 }
3162 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003163
Steven Rostedt0a05c762010-11-08 11:14:10 -05003164 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003165 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003166 } while (!$ret);
3167
3168 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003169
3170 success $i;
3171}
3172
Steven Rostedt27d934b2011-05-20 09:18:18 -04003173sub patchcheck_reboot {
3174 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003175 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003176}
3177
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003178sub patchcheck {
3179 my ($i) = @_;
3180
3181 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003182 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003183 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003184 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003185
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003186 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003187
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003188 my $cherry = $patchcheck_cherry;
3189 if (!defined($cherry)) {
3190 $cherry = 0;
3191 }
3192
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003193 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003194 if (defined($patchcheck_end)) {
3195 $end = $patchcheck_end;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003196 } elsif ($cherry) {
3197 die "PATCHCHECK_END must be defined with PATCHCHECK_CHERRY\n";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003198 }
3199
Steven Rostedta57419b2010-11-02 15:13:54 -04003200 # Get the true sha1's since we can use things like HEAD~3
3201 $start = get_sha1($start);
3202 $end = get_sha1($end);
3203
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003204 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003205
3206 # Can't have a test without having a test to run
3207 if ($type eq "test" && !defined($run_test)) {
3208 $type = "boot";
3209 }
3210
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003211 if ($cherry) {
3212 open (IN, "git cherry -v $start $end|") or
3213 dodie "could not get git list";
3214 } else {
3215 open (IN, "git log --pretty=oneline $end|") or
3216 dodie "could not get git list";
3217 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003218
3219 my @list;
3220
3221 while (<IN>) {
3222 chomp;
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003223 # git cherry adds a '+' we want to remove
3224 s/^\+ //;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003225 $list[$#list+1] = $_;
3226 last if (/^$start/);
3227 }
3228 close(IN);
3229
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003230 if (!$cherry) {
3231 if ($list[$#list] !~ /^$start/) {
3232 fail "SHA1 $start not found";
3233 }
3234
3235 # go backwards in the list
3236 @list = reverse @list;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003237 }
3238
Steven Rostedt (Red Hat)23a0e162014-09-19 20:10:39 -04003239 doprint("Going to test the following commits:\n");
3240 foreach my $l (@list) {
3241 doprint "$l\n";
3242 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003243
3244 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003245 my %ignored_warnings;
3246
3247 if (defined($ignore_warnings)) {
3248 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3249 $ignored_warnings{$sha1} = 1;
3250 }
3251 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003252
3253 $in_patchcheck = 1;
3254 foreach my $item (@list) {
3255 my $sha1 = $item;
3256 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3257
3258 doprint "\nProcessing commit $item\n\n";
3259
3260 run_command "git checkout $sha1" or
3261 die "Failed to checkout $sha1";
3262
3263 # only clean on the first and last patch
3264 if ($item eq $list[0] ||
3265 $item eq $list[$#list]) {
3266 $noclean = $save_clean;
3267 } else {
3268 $noclean = 1;
3269 }
3270
3271 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003272 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003273 } else {
3274 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003275 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003276 }
3277
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003278 # No need to do per patch checking if warnings file exists
3279 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3280 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003281 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003282
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003283 check_buildlog or return 0;
3284
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003285 next if ($type eq "build");
3286
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003287 my $failed = 0;
3288
Steven Rostedtddf607e2011-06-14 20:49:13 -04003289 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003290
3291 if (!$failed && $type ne "boot"){
3292 do_run_test or $failed = 1;
3293 }
3294 end_monitor;
3295 return 0 if ($failed);
3296
Steven Rostedt27d934b2011-05-20 09:18:18 -04003297 patchcheck_reboot;
3298
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003299 }
3300 $in_patchcheck = 0;
3301 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003302
3303 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003304}
3305
Steven Rostedtb9066f62011-07-15 21:25:24 -04003306my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003307my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003308my $iflevel = 0;
3309my @ifdeps;
3310
3311# prevent recursion
3312my %read_kconfigs;
3313
Steven Rostedtac6974c2011-10-04 09:40:17 -04003314sub add_dep {
3315 # $config depends on $dep
3316 my ($config, $dep) = @_;
3317
3318 if (defined($depends{$config})) {
3319 $depends{$config} .= " " . $dep;
3320 } else {
3321 $depends{$config} = $dep;
3322 }
3323
3324 # record the number of configs depending on $dep
3325 if (defined $depcount{$dep}) {
3326 $depcount{$dep}++;
3327 } else {
3328 $depcount{$dep} = 1;
3329 }
3330}
3331
Steven Rostedtb9066f62011-07-15 21:25:24 -04003332# taken from streamline_config.pl
3333sub read_kconfig {
3334 my ($kconfig) = @_;
3335
3336 my $state = "NONE";
3337 my $config;
3338 my @kconfigs;
3339
3340 my $cont = 0;
3341 my $line;
3342
3343
3344 if (! -f $kconfig) {
3345 doprint "file $kconfig does not exist, skipping\n";
3346 return;
3347 }
3348
3349 open(KIN, "$kconfig")
3350 or die "Can't open $kconfig";
3351 while (<KIN>) {
3352 chomp;
3353
3354 # Make sure that lines ending with \ continue
3355 if ($cont) {
3356 $_ = $line . " " . $_;
3357 }
3358
3359 if (s/\\$//) {
3360 $cont = 1;
3361 $line = $_;
3362 next;
3363 }
3364
3365 $cont = 0;
3366
3367 # collect any Kconfig sources
3368 if (/^source\s*"(.*)"/) {
3369 $kconfigs[$#kconfigs+1] = $1;
3370 }
3371
3372 # configs found
3373 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3374 $state = "NEW";
3375 $config = $2;
3376
3377 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003378 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003379 }
3380
3381 # collect the depends for the config
3382 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3383
Steven Rostedtac6974c2011-10-04 09:40:17 -04003384 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003385
3386 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003387 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3388
3389 # selected by depends on config
3390 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003391
3392 # Check for if statements
3393 } elsif (/^if\s+(.*\S)\s*$/) {
3394 my $deps = $1;
3395 # remove beginning and ending non text
3396 $deps =~ s/^[^a-zA-Z0-9_]*//;
3397 $deps =~ s/[^a-zA-Z0-9_]*$//;
3398
3399 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3400
3401 $ifdeps[$iflevel++] = join ':', @deps;
3402
3403 } elsif (/^endif/) {
3404
3405 $iflevel-- if ($iflevel);
3406
3407 # stop on "help"
3408 } elsif (/^\s*help\s*$/) {
3409 $state = "NONE";
3410 }
3411 }
3412 close(KIN);
3413
3414 # read in any configs that were found.
3415 foreach $kconfig (@kconfigs) {
3416 if (!defined($read_kconfigs{$kconfig})) {
3417 $read_kconfigs{$kconfig} = 1;
3418 read_kconfig("$builddir/$kconfig");
3419 }
3420 }
3421}
3422
3423sub read_depends {
3424 # find out which arch this is by the kconfig file
3425 open (IN, $output_config)
3426 or dodie "Failed to read $output_config";
3427 my $arch;
3428 while (<IN>) {
3429 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3430 $arch = $1;
3431 last;
3432 }
3433 }
3434 close IN;
3435
3436 if (!defined($arch)) {
3437 doprint "Could not find arch from config file\n";
3438 doprint "no dependencies used\n";
3439 return;
3440 }
3441
3442 # arch is really the subarch, we need to know
3443 # what directory to look at.
3444 if ($arch eq "i386" || $arch eq "x86_64") {
3445 $arch = "x86";
3446 } elsif ($arch =~ /^tile/) {
3447 $arch = "tile";
3448 }
3449
3450 my $kconfig = "$builddir/arch/$arch/Kconfig";
3451
3452 if (! -f $kconfig && $arch =~ /\d$/) {
3453 my $orig = $arch;
3454 # some subarchs have numbers, truncate them
3455 $arch =~ s/\d*$//;
3456 $kconfig = "$builddir/arch/$arch/Kconfig";
3457 if (! -f $kconfig) {
3458 doprint "No idea what arch dir $orig is for\n";
3459 doprint "no dependencies used\n";
3460 return;
3461 }
3462 }
3463
3464 read_kconfig($kconfig);
3465}
3466
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003467sub make_new_config {
3468 my @configs = @_;
3469
3470 open (OUT, ">$output_config")
3471 or dodie "Failed to write $output_config";
3472
3473 foreach my $config (@configs) {
3474 print OUT "$config\n";
3475 }
3476 close OUT;
3477}
3478
Steven Rostedtac6974c2011-10-04 09:40:17 -04003479sub chomp_config {
3480 my ($config) = @_;
3481
3482 $config =~ s/CONFIG_//;
3483
3484 return $config;
3485}
3486
Steven Rostedtb9066f62011-07-15 21:25:24 -04003487sub get_depends {
3488 my ($dep) = @_;
3489
Steven Rostedtac6974c2011-10-04 09:40:17 -04003490 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003491
3492 $dep = $depends{"$kconfig"};
3493
3494 # the dep string we have saves the dependencies as they
3495 # were found, including expressions like ! && ||. We
3496 # want to split this out into just an array of configs.
3497
3498 my $valid = "A-Za-z_0-9";
3499
3500 my @configs;
3501
3502 while ($dep =~ /[$valid]/) {
3503
3504 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3505 my $conf = "CONFIG_" . $1;
3506
3507 $configs[$#configs + 1] = $conf;
3508
3509 $dep =~ s/^[^$valid]*[$valid]+//;
3510 } else {
3511 die "this should never happen";
3512 }
3513 }
3514
3515 return @configs;
3516}
3517
3518my %min_configs;
3519my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003520my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003521my %processed_configs;
3522my %nochange_config;
3523
3524sub test_this_config {
3525 my ($config) = @_;
3526
3527 my $found;
3528
3529 # if we already processed this config, skip it
3530 if (defined($processed_configs{$config})) {
3531 return undef;
3532 }
3533 $processed_configs{$config} = 1;
3534
3535 # if this config failed during this round, skip it
3536 if (defined($nochange_config{$config})) {
3537 return undef;
3538 }
3539
Steven Rostedtac6974c2011-10-04 09:40:17 -04003540 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003541
3542 # Test dependencies first
3543 if (defined($depends{"$kconfig"})) {
3544 my @parents = get_depends $config;
3545 foreach my $parent (@parents) {
3546 # if the parent is in the min config, check it first
3547 next if (!defined($min_configs{$parent}));
3548 $found = test_this_config($parent);
3549 if (defined($found)) {
3550 return $found;
3551 }
3552 }
3553 }
3554
3555 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003556 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003557 # .config to make sure it is missing the config that
3558 # we had before
3559 my %configs = %min_configs;
3560 delete $configs{$config};
3561 make_new_config ((values %configs), (values %keep_configs));
3562 make_oldconfig;
3563 undef %configs;
3564 assign_configs \%configs, $output_config;
3565
3566 return $config if (!defined($configs{$config}));
3567
3568 doprint "disabling config $config did not change .config\n";
3569
3570 $nochange_config{$config} = 1;
3571
3572 return undef;
3573}
3574
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003575sub make_min_config {
3576 my ($i) = @_;
3577
Steven Rostedtccc513b2012-05-21 17:13:40 -04003578 my $type = $minconfig_type;
3579 if ($type ne "boot" && $type ne "test") {
3580 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3581 " make_min_config works only with 'boot' and 'test'\n" and return;
3582 }
3583
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003584 if (!defined($output_minconfig)) {
3585 fail "OUTPUT_MIN_CONFIG not defined" and return;
3586 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003587
3588 # If output_minconfig exists, and the start_minconfig
3589 # came from min_config, than ask if we should use
3590 # that instead.
3591 if (-f $output_minconfig && !$start_minconfig_defined) {
3592 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003593 if (!defined($use_output_minconfig)) {
3594 if (read_yn " Use it as minconfig?") {
3595 $start_minconfig = $output_minconfig;
3596 }
3597 } elsif ($use_output_minconfig > 0) {
3598 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003599 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003600 } else {
3601 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003602 }
3603 }
3604
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003605 if (!defined($start_minconfig)) {
3606 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3607 }
3608
Steven Rostedt35ce5952011-07-15 21:57:25 -04003609 my $temp_config = "$tmpdir/temp_config";
3610
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003611 # First things first. We build an allnoconfig to find
3612 # out what the defaults are that we can't touch.
3613 # Some are selections, but we really can't handle selections.
3614
3615 my $save_minconfig = $minconfig;
3616 undef $minconfig;
3617
3618 run_command "$make allnoconfig" or return 0;
3619
Steven Rostedtb9066f62011-07-15 21:25:24 -04003620 read_depends;
3621
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003622 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003623
Steven Rostedt43d1b652011-07-15 22:01:56 -04003624 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003625 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003626
3627 if (defined($ignore_config)) {
3628 # make sure the file exists
3629 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003630 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003631 }
3632
Steven Rostedt43d1b652011-07-15 22:01:56 -04003633 %keep_configs = %save_configs;
3634
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003635 doprint "Load initial configs from $start_minconfig\n";
3636
3637 # Look at the current min configs, and save off all the
3638 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003639 assign_configs \%min_configs, $start_minconfig;
3640
3641 my @config_keys = keys %min_configs;
3642
Steven Rostedtac6974c2011-10-04 09:40:17 -04003643 # All configs need a depcount
3644 foreach my $config (@config_keys) {
3645 my $kconfig = chomp_config $config;
3646 if (!defined $depcount{$kconfig}) {
3647 $depcount{$kconfig} = 0;
3648 }
3649 }
3650
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003651 # Remove anything that was set by the make allnoconfig
3652 # we shouldn't need them as they get set for us anyway.
3653 foreach my $config (@config_keys) {
3654 # Remove anything in the ignore_config
3655 if (defined($keep_configs{$config})) {
3656 my $file = $ignore_config;
3657 $file =~ s,.*/(.*?)$,$1,;
3658 doprint "$config set by $file ... ignored\n";
3659 delete $min_configs{$config};
3660 next;
3661 }
3662 # But make sure the settings are the same. If a min config
3663 # sets a selection, we do not want to get rid of it if
3664 # it is not the same as what we have. Just move it into
3665 # the keep configs.
3666 if (defined($config_ignore{$config})) {
3667 if ($config_ignore{$config} ne $min_configs{$config}) {
3668 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3669 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3670 $keep_configs{$config} = $min_configs{$config};
3671 } else {
3672 doprint "$config set by allnoconfig ... ignored\n";
3673 }
3674 delete $min_configs{$config};
3675 }
3676 }
3677
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003678 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003679 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003680
3681 while (!$done) {
3682
3683 my $config;
3684 my $found;
3685
3686 # Now disable each config one by one and do a make oldconfig
3687 # till we find a config that changes our list.
3688
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003689 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003690
3691 # Sort keys by who is most dependent on
3692 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3693 @test_configs ;
3694
3695 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003696 my $reset = 1;
3697 for (my $i = 0; $i < $#test_configs; $i++) {
3698 if (!defined($nochange_config{$test_configs[0]})) {
3699 $reset = 0;
3700 last;
3701 }
3702 # This config didn't change the .config last time.
3703 # Place it at the end
3704 my $config = shift @test_configs;
3705 push @test_configs, $config;
3706 }
3707
3708 # if every test config has failed to modify the .config file
3709 # in the past, then reset and start over.
3710 if ($reset) {
3711 undef %nochange_config;
3712 }
3713
Steven Rostedtb9066f62011-07-15 21:25:24 -04003714 undef %processed_configs;
3715
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003716 foreach my $config (@test_configs) {
3717
Steven Rostedtb9066f62011-07-15 21:25:24 -04003718 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003719
Steven Rostedtb9066f62011-07-15 21:25:24 -04003720 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003721
3722 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003723 }
3724
3725 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003726 # we could have failed due to the nochange_config hash
3727 # reset and try again
3728 if (!$take_two) {
3729 undef %nochange_config;
3730 $take_two = 1;
3731 next;
3732 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003733 doprint "No more configs found that we can disable\n";
3734 $done = 1;
3735 last;
3736 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003737 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003738
3739 $config = $found;
3740
3741 doprint "Test with $config disabled\n";
3742
3743 # set in_bisect to keep build and monitor from dieing
3744 $in_bisect = 1;
3745
3746 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003747 build "oldconfig" or $failed = 1;
3748 if (!$failed) {
3749 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003750
3751 if ($type eq "test" && !$failed) {
3752 do_run_test or $failed = 1;
3753 }
3754
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003755 end_monitor;
3756 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003757
3758 $in_bisect = 0;
3759
3760 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003761 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003762 # this config is needed, add it to the ignore list.
3763 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003764 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003765 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003766
3767 # update new ignore configs
3768 if (defined($ignore_config)) {
3769 open (OUT, ">$temp_config")
3770 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003771 foreach my $config (keys %save_configs) {
3772 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003773 }
3774 close OUT;
3775 run_command "mv $temp_config $ignore_config" or
3776 dodie "failed to copy update to $ignore_config";
3777 }
3778
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003779 } else {
3780 # We booted without this config, remove it from the minconfigs.
3781 doprint "$config is not needed, disabling\n";
3782
3783 delete $min_configs{$config};
3784
3785 # Also disable anything that is not enabled in this config
3786 my %configs;
3787 assign_configs \%configs, $output_config;
3788 my @config_keys = keys %min_configs;
3789 foreach my $config (@config_keys) {
3790 if (!defined($configs{$config})) {
3791 doprint "$config is not set, disabling\n";
3792 delete $min_configs{$config};
3793 }
3794 }
3795
3796 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003797 open (OUT, ">$temp_config")
3798 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003799 foreach my $config (keys %keep_configs) {
3800 print OUT "$keep_configs{$config}\n";
3801 }
3802 foreach my $config (keys %min_configs) {
3803 print OUT "$min_configs{$config}\n";
3804 }
3805 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003806
3807 run_command "mv $temp_config $output_minconfig" or
3808 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003809 }
3810
3811 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003812 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003813 }
3814
3815 success $i;
3816 return 1;
3817}
3818
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003819sub make_warnings_file {
3820 my ($i) = @_;
3821
3822 if (!defined($warnings_file)) {
3823 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3824 }
3825
3826 if ($build_type eq "nobuild") {
3827 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3828 }
3829
3830 build $build_type or dodie "Failed to build";
3831
3832 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3833
3834 open(IN, $buildlog) or dodie "Can't open $buildlog";
3835 while (<IN>) {
3836
3837 # Some compilers use UTF-8 extended for quotes
3838 # for distcc heterogeneous systems, this causes issues
3839 s/$utf8_quote/'/g;
3840
3841 if (/$check_build_re/) {
3842 print OUT;
3843 }
3844 }
3845 close(IN);
3846
3847 close(OUT);
3848
3849 success $i;
3850}
3851
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09003852$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003853
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003854if ($#ARGV == 0) {
3855 $ktest_config = $ARGV[0];
3856 if (! -f $ktest_config) {
3857 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003858 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003859 exit 0;
3860 }
3861 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003862}
3863
3864if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003865 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003866 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003867 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3868 print OUT << "EOF"
3869# Generated by ktest.pl
3870#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003871
3872# PWD is a ktest.pl variable that will result in the process working
3873# directory that ktest.pl is executed in.
3874
3875# THIS_DIR is automatically assigned the PWD of the path that generated
3876# the config file. It is best to use this variable when assigning other
3877# directory paths within this directory. This allows you to easily
3878# move the test cases to other locations or to other machines.
3879#
3880THIS_DIR := $variable{"PWD"}
3881
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003882# Define each test with TEST_START
3883# The config options below it will override the defaults
3884TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003885TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003886
3887DEFAULTS
3888EOF
3889;
3890 close(OUT);
3891}
3892read_config $ktest_config;
3893
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003894if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003895 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003896}
3897
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003898# Append any configs entered in manually to the config file.
3899my @new_configs = keys %entered_configs;
3900if ($#new_configs >= 0) {
3901 print "\nAppending entered in configs to $ktest_config\n";
3902 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3903 foreach my $config (@new_configs) {
3904 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003905 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003906 }
3907}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003908
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003909if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3910 unlink $opt{"LOG_FILE"};
3911}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003912
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003913doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3914
Steven Rostedta57419b2010-11-02 15:13:54 -04003915for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3916
3917 if (!$i) {
3918 doprint "DEFAULT OPTIONS:\n";
3919 } else {
3920 doprint "\nTEST $i OPTIONS";
3921 if (defined($repeat_tests{$i})) {
3922 $repeat = $repeat_tests{$i};
3923 doprint " ITERATE $repeat";
3924 }
3925 doprint "\n";
3926 }
3927
3928 foreach my $option (sort keys %opt) {
3929
3930 if ($option =~ /\[(\d+)\]$/) {
3931 next if ($i != $1);
3932 } else {
3933 next if ($i);
3934 }
3935
3936 doprint "$option = $opt{$option}\n";
3937 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003938}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003939
Steven Rostedt2a625122011-05-20 15:48:59 -04003940sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003941 my ($name, $i) = @_;
3942
3943 my $option = "$name\[$i\]";
3944
3945 if (defined($opt{$option})) {
3946 return $opt{$option};
3947 }
3948
Steven Rostedta57419b2010-11-02 15:13:54 -04003949 foreach my $test (keys %repeat_tests) {
3950 if ($i >= $test &&
3951 $i < $test + $repeat_tests{$test}) {
3952 $option = "$name\[$test\]";
3953 if (defined($opt{$option})) {
3954 return $opt{$option};
3955 }
3956 }
3957 }
3958
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003959 if (defined($opt{$name})) {
3960 return $opt{$name};
3961 }
3962
3963 return undef;
3964}
3965
Steven Rostedt2a625122011-05-20 15:48:59 -04003966sub set_test_option {
3967 my ($name, $i) = @_;
3968
3969 my $option = __set_test_option($name, $i);
3970 return $option if (!defined($option));
3971
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003972 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003973}
3974
Steven Rostedt2545eb62010-11-02 15:01:32 -04003975# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003976for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003977
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003978 # Do not reboot on failing test options
3979 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003980 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003981
Steven Rostedt683a3e62012-05-18 13:34:35 -04003982 $have_version = 0;
3983
Steven Rostedt576f6272010-11-02 14:58:38 -04003984 $iteration = $i;
3985
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003986 undef %force_config;
3987
Steven Rostedta75fece2010-11-02 14:58:27 -04003988 my $makecmd = set_test_option("MAKE_CMD", $i);
3989
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003990 $outputdir = set_test_option("OUTPUT_DIR", $i);
3991 $builddir = set_test_option("BUILD_DIR", $i);
3992
3993 chdir $builddir || die "can't change directory to $builddir";
3994
3995 if (!-d $outputdir) {
3996 mkpath($outputdir) or
3997 die "can't create $outputdir";
3998 }
3999
4000 $make = "$makecmd O=$outputdir";
4001
Steven Rostedt9cc9e092011-12-22 21:37:22 -05004002 # Load all the options into their mapped variable names
4003 foreach my $opt (keys %option_map) {
4004 ${$option_map{$opt}} = set_test_option($opt, $i);
4005 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004006
Steven Rostedt35ce5952011-07-15 21:57:25 -04004007 $start_minconfig_defined = 1;
4008
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004009 # The first test may override the PRE_KTEST option
4010 if (defined($pre_ktest) && $i == 1) {
4011 doprint "\n";
4012 run_command $pre_ktest;
4013 }
4014
4015 # Any test can override the POST_KTEST option
4016 # The last test takes precedence.
4017 if (defined($post_ktest)) {
4018 $final_post_ktest = $post_ktest;
4019 }
4020
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004021 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004022 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004023 $start_minconfig = $minconfig;
4024 }
4025
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004026 if (!-d $tmpdir) {
4027 mkpath($tmpdir) or
4028 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004029 }
4030
Steven Rostedte48c5292010-11-02 14:35:37 -04004031 $ENV{"SSH_USER"} = $ssh_user;
4032 $ENV{"MACHINE"} = $machine;
4033
Steven Rostedta75fece2010-11-02 14:58:27 -04004034 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304035 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004036 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004037 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004038
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004039 if (!$buildonly) {
4040 $target = "$ssh_user\@$machine";
4041 if ($reboot_type eq "grub") {
4042 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004043 } elsif ($reboot_type eq "grub2") {
4044 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4045 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004046 } elsif ($reboot_type eq "syslinux") {
4047 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004048 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004049 }
4050
4051 my $run_type = $build_type;
4052 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004053 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004054 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004055 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004056 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004057 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004058 } elsif ($test_type eq "make_min_config") {
4059 $run_type = "";
4060 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004061 $run_type = "";
4062 }
4063
Steven Rostedta75fece2010-11-02 14:58:27 -04004064 # mistake in config file?
4065 if (!defined($run_type)) {
4066 $run_type = "ERROR";
4067 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004068
Steven Rostedte0a87422011-09-30 17:50:48 -04004069 my $installme = "";
4070 $installme = " no_install" if ($no_install);
4071
Steven Rostedt2545eb62010-11-02 15:01:32 -04004072 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04004073 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004074
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004075 if (defined($pre_test)) {
4076 run_command $pre_test;
4077 }
4078
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004079 unlink $dmesg;
4080 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304081 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004082
Steven Rostedt250bae82011-07-15 22:05:59 -04004083 if (defined($addconfig)) {
4084 my $min = $minconfig;
4085 if (!defined($minconfig)) {
4086 $min = "";
4087 }
4088 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004089 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004090 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004091 }
4092
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004093 if (defined($checkout)) {
4094 run_command "git checkout $checkout" or
4095 die "failed to checkout $checkout";
4096 }
4097
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004098 $no_reboot = 0;
4099
Steven Rostedt648a1822012-03-21 11:18:27 -04004100 # A test may opt to not reboot the box
4101 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004102 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004103 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004104
Steven Rostedta75fece2010-11-02 14:58:27 -04004105 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004106 bisect $i;
4107 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004108 } elsif ($test_type eq "config_bisect") {
4109 config_bisect $i;
4110 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004111 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004112 patchcheck $i;
4113 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004114 } elsif ($test_type eq "make_min_config") {
4115 make_min_config $i;
4116 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004117 } elsif ($test_type eq "make_warnings_file") {
4118 $no_reboot = 1;
4119 make_warnings_file $i;
4120 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004121 }
4122
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004123 if ($build_type ne "nobuild") {
4124 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004125 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004126 }
4127
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004128 if ($test_type eq "install") {
4129 get_version;
4130 install;
4131 success $i;
4132 next;
4133 }
4134
Steven Rostedta75fece2010-11-02 14:58:27 -04004135 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004136 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004137 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004138
4139 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4140 do_run_test or $failed = 1;
4141 }
4142 end_monitor;
4143 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004144 }
4145
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004146 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004147}
4148
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004149if (defined($final_post_ktest)) {
4150 run_command $final_post_ktest;
4151}
4152
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004153if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004154 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004155} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004156 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004157} elsif (defined($switch_to_good)) {
4158 # still need to get to the good kernel
4159 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004160}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004161
Steven Rostedt648a1822012-03-21 11:18:27 -04004162
Steven Rostedte48c5292010-11-02 14:35:37 -04004163doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4164
Steven Rostedt2545eb62010-11-02 15:01:32 -04004165exit 0;