blob: 880566803431bc9ee75f067c01e2f1e7d505ec79 [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;
197my $patchcheck_end;
198
Steven Rostedt165708b2011-11-26 20:56:52 -0500199# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500200# which would require more options.
201my $buildonly = 1;
202
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500203# tell build not to worry about warnings, even when WARNINGS_FILE is set
204my $warnings_ok = 0;
205
Steven Rostedtdbd37832011-11-23 16:00:48 -0500206# set when creating a new config
207my $newconfig = 0;
208
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500209my %entered_configs;
210my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400211my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400212
213# force_config is the list of configs that we force enabled (or disabled)
214# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400215my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500216
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400217# do not force reboots on config problems
218my $no_reboot = 1;
219
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400220# reboot on success
221my $reboot_success = 0;
222
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500223my %option_map = (
224 "MACHINE" => \$machine,
225 "SSH_USER" => \$ssh_user,
226 "TMP_DIR" => \$tmpdir,
227 "OUTPUT_DIR" => \$outputdir,
228 "BUILD_DIR" => \$builddir,
229 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400230 "PRE_KTEST" => \$pre_ktest,
231 "POST_KTEST" => \$post_ktest,
232 "PRE_TEST" => \$pre_test,
233 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500234 "BUILD_TYPE" => \$build_type,
235 "BUILD_OPTIONS" => \$build_options,
236 "PRE_BUILD" => \$pre_build,
237 "POST_BUILD" => \$post_build,
238 "PRE_BUILD_DIE" => \$pre_build_die,
239 "POST_BUILD_DIE" => \$post_build_die,
240 "POWER_CYCLE" => \$power_cycle,
241 "REBOOT" => \$reboot,
242 "BUILD_NOCLEAN" => \$noclean,
243 "MIN_CONFIG" => \$minconfig,
244 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
245 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400246 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400247 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500248 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500249 "IGNORE_CONFIG" => \$ignore_config,
250 "TEST" => \$run_test,
251 "ADD_CONFIG" => \$addconfig,
252 "REBOOT_TYPE" => \$reboot_type,
253 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500254 "GRUB_FILE" => \$grub_file,
255 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500256 "SYSLINUX" => \$syslinux,
257 "SYSLINUX_PATH" => \$syslinux_path,
258 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400259 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500260 "POST_INSTALL" => \$post_install,
261 "NO_INSTALL" => \$no_install,
262 "REBOOT_SCRIPT" => \$reboot_script,
263 "REBOOT_ON_ERROR" => \$reboot_on_error,
264 "SWITCH_TO_GOOD" => \$switch_to_good,
265 "SWITCH_TO_TEST" => \$switch_to_test,
266 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400267 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500268 "DIE_ON_FAILURE" => \$die_on_failure,
269 "POWER_OFF" => \$power_off,
270 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
271 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400272 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500273 "SLEEP_TIME" => \$sleep_time,
274 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
275 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
276 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500277 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500278 "BISECT_MANUAL" => \$bisect_manual,
279 "BISECT_SKIP" => \$bisect_skip,
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -0500280 "BISECT_TRIES" => \$bisect_tries,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500281 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
282 "BISECT_RET_GOOD" => \$bisect_ret_good,
283 "BISECT_RET_BAD" => \$bisect_ret_bad,
284 "BISECT_RET_SKIP" => \$bisect_ret_skip,
285 "BISECT_RET_ABORT" => \$bisect_ret_abort,
286 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
287 "STORE_FAILURES" => \$store_failures,
288 "STORE_SUCCESSES" => \$store_successes,
289 "TEST_NAME" => \$test_name,
290 "TIMEOUT" => \$timeout,
291 "BOOTED_TIMEOUT" => \$booted_timeout,
292 "CONSOLE" => \$console,
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900293 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500294 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
295 "SUCCESS_LINE" => \$success_line,
296 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
297 "STOP_AFTER_SUCCESS" => \$stop_after_success,
298 "STOP_AFTER_FAILURE" => \$stop_after_failure,
299 "STOP_TEST_AFTER" => \$stop_test_after,
300 "BUILD_TARGET" => \$build_target,
301 "SSH_EXEC" => \$ssh_exec,
302 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400303 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500304 "CHECKOUT" => \$checkout,
305 "TARGET_IMAGE" => \$target_image,
306 "LOCALVERSION" => \$localversion,
307
308 "BISECT_GOOD" => \$bisect_good,
309 "BISECT_BAD" => \$bisect_bad,
310 "BISECT_TYPE" => \$bisect_type,
311 "BISECT_START" => \$bisect_start,
312 "BISECT_REPLAY" => \$bisect_replay,
313 "BISECT_FILES" => \$bisect_files,
314 "BISECT_REVERSE" => \$bisect_reverse,
315 "BISECT_CHECK" => \$bisect_check,
316
317 "CONFIG_BISECT" => \$config_bisect,
318 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400319 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500320
321 "PATCHCHECK_TYPE" => \$patchcheck_type,
322 "PATCHCHECK_START" => \$patchcheck_start,
323 "PATCHCHECK_END" => \$patchcheck_end,
324);
325
326# Options may be used by other options, record them.
327my %used_options;
328
Steven Rostedt7bf51072011-10-22 09:07:03 -0400329# default variables that can be used
330chomp ($variable{"PWD"} = `pwd`);
331
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500332$config_help{"MACHINE"} = << "EOF"
333 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500334 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500335EOF
336 ;
337$config_help{"SSH_USER"} = << "EOF"
338 The box is expected to have ssh on normal bootup, provide the user
339 (most likely root, since you need privileged operations)
340EOF
341 ;
342$config_help{"BUILD_DIR"} = << "EOF"
343 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500344 You can use \${PWD} that will be the path where ktest.pl is run, or use
345 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500346EOF
347 ;
348$config_help{"OUTPUT_DIR"} = << "EOF"
349 The directory that the objects will be built (full path).
350 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500351 You can use \${PWD} that will be the path where ktest.pl is run, or use
352 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500353EOF
354 ;
355$config_help{"BUILD_TARGET"} = << "EOF"
356 The location of the compiled file to copy to the target.
357 (relative to OUTPUT_DIR)
358EOF
359 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500360$config_help{"BUILD_OPTIONS"} = << "EOF"
361 Options to add to \"make\" when building.
362 i.e. -j20
363EOF
364 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500365$config_help{"TARGET_IMAGE"} = << "EOF"
366 The place to put your image on the test machine.
367EOF
368 ;
369$config_help{"POWER_CYCLE"} = << "EOF"
370 A script or command to reboot the box.
371
372 Here is a digital loggers power switch example
373 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
374
375 Here is an example to reboot a virtual box on the current host
376 with the name "Guest".
377 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
378EOF
379 ;
380$config_help{"CONSOLE"} = << "EOF"
381 The script or command that reads the console
382
383 If you use ttywatch server, something like the following would work.
384CONSOLE = nc -d localhost 3001
385
386 For a virtual machine with guest name "Guest".
387CONSOLE = virsh console Guest
388EOF
389 ;
390$config_help{"LOCALVERSION"} = << "EOF"
391 Required version ending to differentiate the test
392 from other linux builds on the system.
393EOF
394 ;
395$config_help{"REBOOT_TYPE"} = << "EOF"
396 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500397 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500398
399 If you specify grub, it will assume grub version 1
400 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
401 and select that target to reboot to the kernel. If this is not
402 your setup, then specify "script" and have a command or script
403 specified in REBOOT_SCRIPT to boot to the target.
404
405 The entry in /boot/grub/menu.lst must be entered in manually.
406 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500407
408 If you specify grub2, then you also need to specify both \$GRUB_MENU
409 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500410
411 If you specify syslinux, then you may use SYSLINUX to define the syslinux
412 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
413 the syslinux install (defaults to /boot/extlinux). But you have to specify
414 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500415EOF
416 ;
417$config_help{"GRUB_MENU"} = << "EOF"
418 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500419 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500420
421 Note, ktest.pl will not update the grub menu.lst, you need to
422 manually add an option for the test. ktest.pl will search
423 the grub menu.lst for this option to find what kernel to
424 reboot into.
425
426 For example, if in the /boot/grub/menu.lst the test kernel title has:
427 title Test Kernel
428 kernel vmlinuz-test
429 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500430
431 For grub2, a search of \$GRUB_FILE is performed for the lines
432 that begin with "menuentry". It will not detect submenus. The
433 menu must be a non-nested menu. Add the quotes used in the menu
434 to guarantee your selection, as the first menuentry with the content
435 of \$GRUB_MENU that is found will be used.
436EOF
437 ;
438$config_help{"GRUB_FILE"} = << "EOF"
439 If grub2 is used, the full path for the grub.cfg file is placed
440 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500441EOF
442 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500443$config_help{"SYSLINUX_LABEL"} = << "EOF"
444 If syslinux is used, the label that boots the target kernel must
445 be specified with SYSLINUX_LABEL.
446EOF
447 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500448$config_help{"REBOOT_SCRIPT"} = << "EOF"
449 A script to reboot the target into the test kernel
450 (Only mandatory if REBOOT_TYPE = script)
451EOF
452 ;
453
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500454sub _logit {
455 if (defined($opt{"LOG_FILE"})) {
456 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
457 print OUT @_;
458 close(OUT);
459 }
460}
461
462sub logit {
463 if (defined($opt{"LOG_FILE"})) {
464 _logit @_;
465 } else {
466 print @_;
467 }
468}
469
470sub doprint {
471 print @_;
472 _logit @_;
473}
474
Steven Rostedtdad98752011-11-22 20:48:57 -0500475sub read_prompt {
476 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400477
478 my $ans;
479
480 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500481 if ($cancel) {
482 print "$prompt [y/n/C] ";
483 } else {
484 print "$prompt [Y/n] ";
485 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400486 $ans = <STDIN>;
487 chomp $ans;
488 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500489 if ($cancel) {
490 $ans = "c";
491 } else {
492 $ans = "y";
493 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400494 }
495 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500496 if ($cancel) {
497 last if ($ans =~ /^c$/i);
498 print "Please answer either 'y', 'n' or 'c'.\n";
499 } else {
500 print "Please answer either 'y' or 'n'.\n";
501 }
502 }
503 if ($ans =~ /^c/i) {
504 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400505 }
506 if ($ans !~ /^y$/i) {
507 return 0;
508 }
509 return 1;
510}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500511
Steven Rostedtdad98752011-11-22 20:48:57 -0500512sub read_yn {
513 my ($prompt) = @_;
514
515 return read_prompt 0, $prompt;
516}
517
518sub read_ync {
519 my ($prompt) = @_;
520
521 return read_prompt 1, $prompt;
522}
523
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900524sub get_mandatory_config {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500525 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400526 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500527
528 return if (defined($opt{$config}));
529
530 if (defined($config_help{$config})) {
531 print "\n";
532 print $config_help{$config};
533 }
534
535 for (;;) {
536 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500537 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500538 print "\[$default{$config}\] ";
539 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400540 $ans = <STDIN>;
541 $ans =~ s/^\s*(.*\S)\s*$/$1/;
542 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500543 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400544 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500545 } else {
546 print "Your answer can not be blank\n";
547 next;
548 }
549 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500550 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500551 last;
552 }
553}
554
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900555sub get_mandatory_configs {
556 get_mandatory_config("MACHINE");
557 get_mandatory_config("BUILD_DIR");
558 get_mandatory_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500559
Steven Rostedtdbd37832011-11-23 16:00:48 -0500560 if ($newconfig) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900561 get_mandatory_config("BUILD_OPTIONS");
Steven Rostedtdbd37832011-11-23 16:00:48 -0500562 }
563
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500564 # options required for other than just building a kernel
565 if (!$buildonly) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900566 get_mandatory_config("POWER_CYCLE");
567 get_mandatory_config("CONSOLE");
Steven Rostedt165708b2011-11-26 20:56:52 -0500568 }
569
570 # options required for install and more
571 if ($buildonly != 1) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900572 get_mandatory_config("SSH_USER");
573 get_mandatory_config("BUILD_TARGET");
574 get_mandatory_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500575 }
576
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900577 get_mandatory_config("LOCALVERSION");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500578
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500579 return if ($buildonly);
580
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500581 my $rtype = $opt{"REBOOT_TYPE"};
582
583 if (!defined($rtype)) {
584 if (!defined($opt{"GRUB_MENU"})) {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900585 get_mandatory_config("REBOOT_TYPE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500586 $rtype = $entered_configs{"REBOOT_TYPE"};
587 } else {
588 $rtype = "grub";
589 }
590 }
591
592 if ($rtype eq "grub") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900593 get_mandatory_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500594 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500595
596 if ($rtype eq "grub2") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900597 get_mandatory_config("GRUB_MENU");
598 get_mandatory_config("GRUB_FILE");
Steven Rostedta15ba912012-11-13 14:30:37 -0500599 }
Steven Rostedt77869542012-12-11 17:37:41 -0500600
601 if ($rtype eq "syslinux") {
Satoru Takeuchi5269faa2014-03-09 23:32:04 +0900602 get_mandatory_config("SYSLINUX_LABEL");
Steven Rostedt77869542012-12-11 17:37:41 -0500603 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500604}
605
Steven Rostedt77d942c2011-05-20 13:36:58 -0400606sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400607 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400608 my $retval = "";
609
610 # We want to check for '\', and it is just easier
611 # to check the previous characet of '$' and not need
612 # to worry if '$' is the first character. By adding
613 # a space to $value, we can just check [^\\]\$ and
614 # it will still work.
615 $value = " $value";
616
617 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
618 my $begin = $1;
619 my $var = $2;
620 my $end = $3;
621 # append beginning of value to retval
622 $retval = "$retval$begin";
623 if (defined($variable{$var})) {
624 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400625 } elsif (defined($remove_undef) && $remove_undef) {
626 # for if statements, any variable that is not defined,
627 # we simple convert to 0
628 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400629 } else {
630 # put back the origin piece.
631 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500632 # This could be an option that is used later, save
633 # it so we don't warn if this option is not one of
634 # ktests options.
635 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400636 }
637 $value = $end;
638 }
639 $retval = "$retval$value";
640
641 # remove the space added in the beginning
642 $retval =~ s/ //;
643
644 return "$retval"
645}
646
Steven Rostedta57419b2010-11-02 15:13:54 -0400647sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400648 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400649
Steven Rostedtcad96662011-12-22 11:32:52 -0500650 my $prvalue = process_variables($rvalue);
651
652 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500653 # Note if a test is something other than build, then we
654 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500655 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500656 # for bisect, we need to check BISECT_TYPE
657 if ($prvalue ne "bisect") {
658 $buildonly = 0;
659 }
660 } else {
661 # install still limits some manditory options.
662 $buildonly = 2;
663 }
664 }
665
666 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
667 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500668 $buildonly = 0;
669 } else {
670 # install still limits some manditory options.
671 $buildonly = 2;
672 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500673 }
674
Steven Rostedta57419b2010-11-02 15:13:54 -0400675 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400676 if (!$override || defined(${$overrides}{$lvalue})) {
677 my $extra = "";
678 if ($override) {
679 $extra = "In the same override section!\n";
680 }
681 die "$name: $.: Option $lvalue defined more than once!\n$extra";
682 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500683 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400684 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500685 if ($rvalue =~ /^\s*$/) {
686 delete $opt{$lvalue};
687 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500688 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500689 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400690}
691
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500692sub set_eval {
693 my ($lvalue, $rvalue, $name) = @_;
694
695 my $prvalue = process_variables($rvalue);
696 my $arr;
697
698 if (defined($evals{$lvalue})) {
699 $arr = $evals{$lvalue};
700 } else {
701 $arr = [];
702 $evals{$lvalue} = $arr;
703 }
704
705 push @{$arr}, $rvalue;
706}
707
Steven Rostedt77d942c2011-05-20 13:36:58 -0400708sub set_variable {
709 my ($lvalue, $rvalue) = @_;
710
711 if ($rvalue =~ /^\s*$/) {
712 delete $variable{$lvalue};
713 } else {
714 $rvalue = process_variables($rvalue);
715 $variable{$lvalue} = $rvalue;
716 }
717}
718
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400719sub process_compare {
720 my ($lval, $cmp, $rval) = @_;
721
722 # remove whitespace
723
724 $lval =~ s/^\s*//;
725 $lval =~ s/\s*$//;
726
727 $rval =~ s/^\s*//;
728 $rval =~ s/\s*$//;
729
730 if ($cmp eq "==") {
731 return $lval eq $rval;
732 } elsif ($cmp eq "!=") {
733 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400734 } elsif ($cmp eq "=~") {
735 return $lval =~ m/$rval/;
736 } elsif ($cmp eq "!~") {
737 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400738 }
739
740 my $statement = "$lval $cmp $rval";
741 my $ret = eval $statement;
742
743 # $@ stores error of eval
744 if ($@) {
745 return -1;
746 }
747
748 return $ret;
749}
750
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400751sub value_defined {
752 my ($val) = @_;
753
754 return defined($variable{$2}) ||
755 defined($opt{$2});
756}
757
Steven Rostedt8d735212011-10-17 11:36:44 -0400758my $d = 0;
759sub process_expression {
760 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400761
Steven Rostedt8d735212011-10-17 11:36:44 -0400762 my $c = $d++;
763
764 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
765 my $express = $1;
766
767 if (process_expression($name, $express)) {
768 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
769 } else {
770 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
771 }
772 }
773
774 $d--;
775 my $OR = "\\|\\|";
776 my $AND = "\\&\\&";
777
778 while ($val =~ s/^(.*?)($OR|$AND)//) {
779 my $express = $1;
780 my $op = $2;
781
782 if (process_expression($name, $express)) {
783 if ($op eq "||") {
784 return 1;
785 }
786 } else {
787 if ($op eq "&&") {
788 return 0;
789 }
790 }
791 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400792
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400793 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400794 my $ret = process_compare($1, $2, $3);
795 if ($ret < 0) {
796 die "$name: $.: Unable to process comparison\n";
797 }
798 return $ret;
799 }
800
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400801 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
802 if (defined $1) {
803 return !value_defined($2);
804 } else {
805 return value_defined($2);
806 }
807 }
808
Steven Rostedt45d73a52011-09-30 19:44:53 -0400809 if ($val =~ /^\s*0\s*$/) {
810 return 0;
811 } elsif ($val =~ /^\s*\d+\s*$/) {
812 return 1;
813 }
814
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400815 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400816}
817
818sub process_if {
819 my ($name, $value) = @_;
820
821 # Convert variables and replace undefined ones with 0
822 my $val = process_variables($value, 1);
823 my $ret = process_expression $name, $val;
824
825 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400826}
827
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400828sub __read_config {
829 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400830
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400831 my $in;
832 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400833
Steven Rostedta57419b2010-11-02 15:13:54 -0400834 my $name = $config;
835 $name =~ s,.*/(.*),$1,;
836
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400837 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400838 my $default = 1;
839 my $repeat = 1;
840 my $num_tests_set = 0;
841 my $skip = 0;
842 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400843 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400844 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400845 my $if = 0;
846 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400847 my $override = 0;
848
849 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400850
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400851 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400852
853 # ignore blank lines and comments
854 next if (/^\s*$/ || /\s*\#/);
855
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400856 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400857
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400858 my $type = $1;
859 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400860 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400861
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400862 my $old_test_num;
863 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400864 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400865
866 if ($type eq "TEST_START") {
867
868 if ($num_tests_set) {
869 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
870 }
871
872 $old_test_num = $test_num;
873 $old_repeat = $repeat;
874
875 $test_num += $repeat;
876 $default = 0;
877 $repeat = 1;
878 } else {
879 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400880 }
881
Steven Rostedta9f84422011-10-17 11:06:29 -0400882 # If SKIP is anywhere in the line, the command will be skipped
883 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400884 $skip = 1;
885 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400886 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400887 $skip = 0;
888 }
889
Steven Rostedta9f84422011-10-17 11:06:29 -0400890 if ($rest =~ s/\sELSE\b//) {
891 if (!$if) {
892 die "$name: $.: ELSE found with out matching IF section\n$_";
893 }
894 $if = 0;
895
896 if ($if_set) {
897 $skip = 1;
898 } else {
899 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400900 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400901 }
902
Steven Rostedta9f84422011-10-17 11:06:29 -0400903 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400904 if (process_if($name, $1)) {
905 $if_set = 1;
906 } else {
907 $skip = 1;
908 }
909 $if = 1;
910 } else {
911 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400912 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400913 }
914
Steven Rostedta9f84422011-10-17 11:06:29 -0400915 if (!$skip) {
916 if ($type eq "TEST_START") {
917 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
918 $repeat = $1;
919 $repeat_tests{"$test_num"} = $repeat;
920 }
921 } elsif ($rest =~ s/\sOVERRIDE\b//) {
922 # DEFAULT only
923 $override = 1;
924 # Clear previous overrides
925 %overrides = ();
926 }
927 }
928
929 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400930 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400931 }
932
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400933 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400934 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400935 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400936 }
937
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400938 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400939 if (!$if) {
940 die "$name: $.: ELSE found with out matching IF section\n$_";
941 }
942 $rest = $1;
943 if ($if_set) {
944 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400945 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400946 } else {
947 $skip = 0;
948
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400949 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400950 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400951 if (process_if($name, $1)) {
952 $if_set = 1;
953 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400954 $skip = 1;
955 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400956 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400957 } else {
958 $if = 0;
959 }
960 }
961
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400962 if ($rest !~ /^\s*$/) {
963 die "$name: $.: Gargbage found after DEFAULTS\n$_";
964 }
965
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400966 } elsif (/^\s*INCLUDE\s+(\S+)/) {
967
968 next if ($skip);
969
970 if (!$default) {
971 die "$name: $.: INCLUDE can only be done in default sections\n$_";
972 }
973
974 my $file = process_variables($1);
975
976 if ($file !~ m,^/,) {
977 # check the path of the config file first
978 if ($config =~ m,(.*)/,) {
979 if (-f "$1/$file") {
980 $file = "$1/$file";
981 }
982 }
983 }
984
985 if ( ! -r $file ) {
986 die "$name: $.: Can't read file $file\n$_";
987 }
988
989 if (__read_config($file, \$test_num)) {
990 $test_case = 1;
991 }
992
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500993 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
994
995 next if ($skip);
996
997 my $lvalue = $1;
998 my $rvalue = $2;
999
1000 if ($default || $lvalue =~ /\[\d+\]$/) {
1001 set_eval($lvalue, $rvalue, $name);
1002 } else {
1003 my $val = "$lvalue\[$test_num\]";
1004 set_eval($val, $rvalue, $name);
1005 }
1006
Steven Rostedta57419b2010-11-02 15:13:54 -04001007 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1008
1009 next if ($skip);
1010
Steven Rostedt2545eb62010-11-02 15:01:32 -04001011 my $lvalue = $1;
1012 my $rvalue = $2;
1013
Steven Rostedta57419b2010-11-02 15:13:54 -04001014 if (!$default &&
1015 ($lvalue eq "NUM_TESTS" ||
1016 $lvalue eq "LOG_FILE" ||
1017 $lvalue eq "CLEAR_LOG")) {
1018 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001019 }
Steven Rostedta57419b2010-11-02 15:13:54 -04001020
1021 if ($lvalue eq "NUM_TESTS") {
1022 if ($test_num) {
1023 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1024 }
1025 if (!$default) {
1026 die "$name: $.: NUM_TESTS must be set in default section\n";
1027 }
1028 $num_tests_set = 1;
1029 }
1030
1031 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001032 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001033 } else {
1034 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001035 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001036
1037 if ($repeat > 1) {
1038 $repeats{$val} = $repeat;
1039 }
1040 }
Steven Rostedt77d942c2011-05-20 13:36:58 -04001041 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1042 next if ($skip);
1043
1044 my $lvalue = $1;
1045 my $rvalue = $2;
1046
1047 # process config variables.
1048 # Config variables are only active while reading the
1049 # config and can be defined anywhere. They also ignore
1050 # TEST_START and DEFAULTS, but are skipped if they are in
1051 # on of these sections that have SKIP defined.
1052 # The save variable can be
1053 # defined multiple times and the new one simply overrides
1054 # the prevous one.
1055 set_variable($lvalue, $rvalue);
1056
Steven Rostedta57419b2010-11-02 15:13:54 -04001057 } else {
1058 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001059 }
1060 }
1061
Steven Rostedta57419b2010-11-02 15:13:54 -04001062 if ($test_num) {
1063 $test_num += $repeat - 1;
1064 $opt{"NUM_TESTS"} = $test_num;
1065 }
1066
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001067 close($in);
1068
1069 $$current_test_num = $test_num;
1070
1071 return $test_case;
1072}
1073
Steven Rostedtc4261d02011-11-23 13:41:18 -05001074sub get_test_case {
1075 print "What test case would you like to run?\n";
1076 print " (build, install or boot)\n";
1077 print " Other tests are available but require editing the config file\n";
1078 my $ans = <STDIN>;
1079 chomp $ans;
1080 $default{"TEST_TYPE"} = $ans;
1081}
1082
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001083sub read_config {
1084 my ($config) = @_;
1085
1086 my $test_case;
1087 my $test_num = 0;
1088
1089 $test_case = __read_config $config, \$test_num;
1090
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001091 # make sure we have all mandatory configs
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09001092 get_mandatory_configs;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001093
Steven Rostedt0df213c2011-06-14 20:51:37 -04001094 # was a test specified?
1095 if (!$test_case) {
1096 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001097 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001098 }
1099
Steven Rostedta75fece2010-11-02 14:58:27 -04001100 # set any defaults
1101
1102 foreach my $default (keys %default) {
1103 if (!defined($opt{$default})) {
1104 $opt{$default} = $default{$default};
1105 }
1106 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001107
1108 if ($opt{"IGNORE_UNUSED"} == 1) {
1109 return;
1110 }
1111
1112 my %not_used;
1113
1114 # check if there are any stragglers (typos?)
1115 foreach my $option (keys %opt) {
1116 my $op = $option;
1117 # remove per test labels.
1118 $op =~ s/\[.*\]//;
1119 if (!exists($option_map{$op}) &&
1120 !exists($default{$op}) &&
1121 !exists($used_options{$op})) {
1122 $not_used{$op} = 1;
1123 }
1124 }
1125
1126 if (%not_used) {
1127 my $s = "s are";
1128 $s = " is" if (keys %not_used == 1);
1129 print "The following option$s not used; could be a typo:\n";
1130 foreach my $option (keys %not_used) {
1131 print "$option\n";
1132 }
1133 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1134 if (!read_yn "Do you want to continue?") {
1135 exit -1;
1136 }
1137 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001138}
1139
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001140sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001141 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001142
1143 # Add space to evaluate the character before $
1144 $option = " $option";
1145 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301146 my $repeated = 0;
1147 my $parent = 0;
1148
1149 foreach my $test (keys %repeat_tests) {
1150 if ($i >= $test &&
1151 $i < $test + $repeat_tests{$test}) {
1152
1153 $repeated = 1;
1154 $parent = $test;
1155 last;
1156 }
1157 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001158
1159 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1160 my $start = $1;
1161 my $var = $2;
1162 my $end = $3;
1163
1164 # Append beginning of line
1165 $retval = "$retval$start";
1166
1167 # If the iteration option OPT[$i] exists, then use that.
1168 # otherwise see if the default OPT (without [$i]) exists.
1169
1170 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301171 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001172
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001173 # If a variable contains itself, use the default var
1174 if (($var eq $name) && defined($opt{$var})) {
1175 $o = $opt{$var};
1176 $retval = "$retval$o";
1177 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001178 $o = $opt{$o};
1179 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301180 } elsif ($repeated && defined($opt{$parento})) {
1181 $o = $opt{$parento};
1182 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001183 } elsif (defined($opt{$var})) {
1184 $o = $opt{$var};
1185 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001186 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1187 # special option KERNEL_VERSION uses kernel version
1188 get_version();
1189 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001190 } else {
1191 $retval = "$retval\$\{$var\}";
1192 }
1193
1194 $option = $end;
1195 }
1196
1197 $retval = "$retval$option";
1198
1199 $retval =~ s/^ //;
1200
1201 return $retval;
1202}
1203
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001204sub process_evals {
1205 my ($name, $option, $i) = @_;
1206
1207 my $option_name = "$name\[$i\]";
1208 my $ev;
1209
1210 my $old_option = $option;
1211
1212 if (defined($evals{$option_name})) {
1213 $ev = $evals{$option_name};
1214 } elsif (defined($evals{$name})) {
1215 $ev = $evals{$name};
1216 } else {
1217 return $option;
1218 }
1219
1220 for my $e (@{$ev}) {
1221 eval "\$option =~ $e";
1222 }
1223
1224 if ($option ne $old_option) {
1225 doprint("$name changed from '$old_option' to '$option'\n");
1226 }
1227
1228 return $option;
1229}
1230
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001231sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001232 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001233
1234 my $prev = "";
1235
1236 # Since an option can evaluate to another option,
1237 # keep iterating until we do not evaluate any more
1238 # options.
1239 my $r = 0;
1240 while ($prev ne $option) {
1241 # Check for recursive evaluations.
1242 # 100 deep should be more than enough.
1243 if ($r++ > 100) {
1244 die "Over 100 evaluations accurred with $option\n" .
1245 "Check for recursive variables\n";
1246 }
1247 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001248 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001249 }
1250
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001251 $option = process_evals($name, $option, $i);
1252
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001253 return $option;
1254}
1255
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001256sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001257sub start_monitor;
1258sub end_monitor;
1259sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001260
1261sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001262 my ($time) = @_;
1263
Steven Rostedta4968722012-12-11 14:59:05 -05001264 # Make sure everything has been written to disk
1265 run_ssh("sync");
1266
Steven Rostedt2b803362011-09-30 18:00:23 -04001267 if (defined($time)) {
1268 start_monitor;
1269 # flush out current monitor
1270 # May contain the reboot success line
1271 wait_for_monitor 1;
1272 }
1273
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001274 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001275 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001276 if (defined($powercycle_after_reboot)) {
1277 sleep $powercycle_after_reboot;
1278 run_command "$power_cycle";
1279 }
1280 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001281 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001282 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001283 }
Andrew Jones2728be42011-08-12 15:32:05 +02001284
1285 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001286
1287 # We only want to get to the new kernel, don't fail
1288 # if we stumble over a call trace.
1289 my $save_ignore_errors = $ignore_errors;
1290 $ignore_errors = 1;
1291
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001292 # Look for the good kernel to boot
1293 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001294 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001295 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001296 run_command "$power_cycle";
1297 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001298
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001299 $ignore_errors = $save_ignore_errors;
1300
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001301 # Still need to wait for the reboot to finish
1302 wait_for_monitor($time, $reboot_success_line);
1303
Andrew Jones2728be42011-08-12 15:32:05 +02001304 end_monitor;
1305 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001306}
1307
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001308sub reboot_to_good {
1309 my ($time) = @_;
1310
1311 if (defined($switch_to_good)) {
1312 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001313 }
1314
1315 reboot $time;
1316}
1317
Steven Rostedt576f6272010-11-02 14:58:38 -04001318sub do_not_reboot {
1319 my $i = $iteration;
1320
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001321 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001322 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1323 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1324}
1325
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001326sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001327 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001328
Steven Rostedt576f6272010-11-02 14:58:38 -04001329 my $i = $iteration;
1330
1331 if ($reboot_on_error && !do_not_reboot) {
1332
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001333 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001334 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001335
Steven Rostedta75fece2010-11-02 14:58:27 -04001336 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001337 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001338 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001339 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001340
Steven Rostedtf80802c2011-03-07 13:18:47 -05001341 if (defined($opt{"LOG_FILE"})) {
1342 print " See $opt{LOG_FILE} for more info.\n";
1343 }
1344
Steven Rostedt576f6272010-11-02 14:58:38 -04001345 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001346}
1347
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001348sub open_console {
1349 my ($fp) = @_;
1350
1351 my $flags;
1352
Steven Rostedta75fece2010-11-02 14:58:27 -04001353 my $pid = open($fp, "$console|") or
1354 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001355
1356 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001357 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001358 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001359 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001360
1361 return $pid;
1362}
1363
1364sub close_console {
1365 my ($fp, $pid) = @_;
1366
1367 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001368 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001369
1370 print "closing!\n";
1371 close($fp);
1372}
1373
1374sub start_monitor {
1375 if ($monitor_cnt++) {
1376 return;
1377 }
1378 $monitor_fp = \*MONFD;
1379 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001380
1381 return;
1382
1383 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001384}
1385
1386sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001387 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001388 if (--$monitor_cnt) {
1389 return;
1390 }
1391 close_console($monitor_fp, $monitor_pid);
1392}
1393
1394sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001395 my ($time, $stop) = @_;
1396 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001397 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001398 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001399 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001400 my $skip_call_trace = 0;
1401 my $bug = 0;
1402 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001403 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001404
Steven Rostedta75fece2010-11-02 14:58:27 -04001405 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001406
1407 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001408 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001409 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001410 last if (!defined($line));
1411 print "$line";
1412 $full_line .= $line;
1413
1414 if (defined($stop) && $full_line =~ /$stop/) {
1415 doprint "wait for monitor detected $stop\n";
1416 $booted = 1;
1417 }
1418
Steven Rostedt8a80c722012-07-19 16:08:33 -04001419 if ($full_line =~ /\[ backtrace testing \]/) {
1420 $skip_call_trace = 1;
1421 }
1422
1423 if ($full_line =~ /call trace:/i) {
1424 if (!$bug && !$skip_call_trace) {
1425 if ($ignore_errors) {
1426 $bug_ignored = 1;
1427 } else {
1428 $bug = 1;
1429 }
1430 }
1431 }
1432
1433 if ($full_line =~ /\[ end of backtrace testing \]/) {
1434 $skip_call_trace = 0;
1435 }
1436
1437 if ($full_line =~ /Kernel panic -/) {
1438 $bug = 1;
1439 }
1440
Steven Rostedt2b803362011-09-30 18:00:23 -04001441 if ($line =~ /\n/) {
1442 $full_line = "";
1443 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001444 $now = time;
1445 if ($now - $start_time >= $max_monitor_wait) {
1446 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1447 return 1;
1448 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001449 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001450 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001451 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001452}
1453
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301454sub save_logs {
1455 my ($result, $basedir) = @_;
1456 my @t = localtime;
1457 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1458 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1459
1460 my $type = $build_type;
1461 if ($type =~ /useconfig/) {
1462 $type = "useconfig";
1463 }
1464
1465 my $dir = "$machine-$test_type-$type-$result-$date";
1466
1467 $dir = "$basedir/$dir";
1468
1469 if (!-d $dir) {
1470 mkpath($dir) or
1471 die "can't create $dir";
1472 }
1473
1474 my %files = (
1475 "config" => $output_config,
1476 "buildlog" => $buildlog,
1477 "dmesg" => $dmesg,
1478 "testlog" => $testlog,
1479 );
1480
1481 while (my ($name, $source) = each(%files)) {
1482 if (-f "$source") {
1483 cp "$source", "$dir/$name" or
1484 die "failed to copy $source";
1485 }
1486 }
1487
1488 doprint "*** Saved info to $dir ***\n";
1489}
1490
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001491sub fail {
1492
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001493 if (defined($post_test)) {
1494 run_command $post_test;
1495 }
1496
Steven Rostedta75fece2010-11-02 14:58:27 -04001497 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001498 dodie @_;
1499 }
1500
Steven Rostedta75fece2010-11-02 14:58:27 -04001501 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001502
Steven Rostedt576f6272010-11-02 14:58:38 -04001503 my $i = $iteration;
1504
Steven Rostedta75fece2010-11-02 14:58:27 -04001505 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001506 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001507 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001508 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001509 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001510
Steven Rostedt9064af52011-06-13 10:38:48 -04001511 my $name = "";
1512
1513 if (defined($test_name)) {
1514 $name = " ($test_name)";
1515 }
1516
Steven Rostedt576f6272010-11-02 14:58:38 -04001517 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1518 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001519 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001520 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1521 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001522
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301523 if (defined($store_failures)) {
1524 save_logs "fail", $store_failures;
1525 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001526
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001527 return 1;
1528}
1529
Steven Rostedt2545eb62010-11-02 15:01:32 -04001530sub run_command {
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09001531 my ($command, $redirect) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001532 my $dolog = 0;
1533 my $dord = 0;
1534 my $pid;
1535
Steven Rostedte48c5292010-11-02 14:35:37 -04001536 $command =~ s/\$SSH_USER/$ssh_user/g;
1537 $command =~ s/\$MACHINE/$machine/g;
1538
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001539 doprint("$command ... ");
1540
1541 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001542 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001543
1544 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001545 open(LOG, ">>$opt{LOG_FILE}") or
1546 dodie "failed to write to log";
1547 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001548 }
1549
1550 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001551 open (RD, ">$redirect") or
1552 dodie "failed to write to redirect $redirect";
1553 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001554 }
1555
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001556 while (<CMD>) {
1557 print LOG if ($dolog);
1558 print RD if ($dord);
1559 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001560
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001561 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001562 my $failed = $?;
1563
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001564 close(CMD);
1565 close(LOG) if ($dolog);
1566 close(RD) if ($dord);
1567
Steven Rostedt2545eb62010-11-02 15:01:32 -04001568 if ($failed) {
1569 doprint "FAILED!\n";
1570 } else {
1571 doprint "SUCCESS\n";
1572 }
1573
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001574 return !$failed;
1575}
1576
Steven Rostedte48c5292010-11-02 14:35:37 -04001577sub run_ssh {
1578 my ($cmd) = @_;
1579 my $cp_exec = $ssh_exec;
1580
1581 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1582 return run_command "$cp_exec";
1583}
1584
1585sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001586 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001587
1588 $cp_scp =~ s/\$SRC_FILE/$src/g;
1589 $cp_scp =~ s/\$DST_FILE/$dst/g;
1590
1591 return run_command "$cp_scp";
1592}
1593
Steven Rostedt02ad2612012-03-21 08:21:24 -04001594sub run_scp_install {
1595 my ($src, $dst) = @_;
1596
1597 my $cp_scp = $scp_to_target_install;
1598
1599 return run_scp($src, $dst, $cp_scp);
1600}
1601
1602sub run_scp_mod {
1603 my ($src, $dst) = @_;
1604
1605 my $cp_scp = $scp_to_target;
1606
1607 return run_scp($src, $dst, $cp_scp);
1608}
1609
Steven Rostedta15ba912012-11-13 14:30:37 -05001610sub get_grub2_index {
1611
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001612 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001613 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1614 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001615
1616 doprint "Find grub2 menu ... ";
1617 $grub_number = -1;
1618
1619 my $ssh_grub = $ssh_exec;
1620 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1621
1622 open(IN, "$ssh_grub |")
1623 or die "unable to get $grub_file";
1624
1625 my $found = 0;
1626
1627 while (<IN>) {
1628 if (/^menuentry.*$grub_menu/) {
1629 $grub_number++;
1630 $found = 1;
1631 last;
1632 } elsif (/^menuentry\s/) {
1633 $grub_number++;
1634 }
1635 }
1636 close(IN);
1637
1638 die "Could not find '$grub_menu' in $grub_file on $machine"
1639 if (!$found);
1640 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001641 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001642 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001643}
1644
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001645sub get_grub_index {
1646
Steven Rostedta15ba912012-11-13 14:30:37 -05001647 if ($reboot_type eq "grub2") {
1648 get_grub2_index;
1649 return;
1650 }
1651
Steven Rostedta75fece2010-11-02 14:58:27 -04001652 if ($reboot_type ne "grub") {
1653 return;
1654 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001655 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001656 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1657 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001658
1659 doprint "Find grub menu ... ";
1660 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001661
1662 my $ssh_grub = $ssh_exec;
1663 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1664
1665 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001666 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001667
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001668 my $found = 0;
1669
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001670 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001671 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001672 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001673 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001674 last;
1675 } elsif (/^\s*title\s/) {
1676 $grub_number++;
1677 }
1678 }
1679 close(IN);
1680
Steven Rostedta75fece2010-11-02 14:58:27 -04001681 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001682 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001683 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001684 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001685 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001686}
1687
Steven Rostedt2545eb62010-11-02 15:01:32 -04001688sub wait_for_input
1689{
1690 my ($fp, $time) = @_;
1691 my $rin;
1692 my $ready;
1693 my $line;
1694 my $ch;
1695
1696 if (!defined($time)) {
1697 $time = $timeout;
1698 }
1699
1700 $rin = '';
1701 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001702 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001703
1704 $line = "";
1705
1706 # try to read one char at a time
1707 while (sysread $fp, $ch, 1) {
1708 $line .= $ch;
1709 last if ($ch eq "\n");
1710 }
1711
1712 if (!length($line)) {
1713 return undef;
1714 }
1715
1716 return $line;
1717}
1718
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001719sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001720 if (defined($switch_to_test)) {
1721 run_command $switch_to_test;
1722 }
1723
Steven Rostedta75fece2010-11-02 14:58:27 -04001724 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001725 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001726 } elsif ($reboot_type eq "grub2") {
1727 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001728 } elsif ($reboot_type eq "syslinux") {
1729 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001730 } elsif (defined $reboot_script) {
1731 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001732 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001733 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001734}
1735
Steven Rostedta57419b2010-11-02 15:13:54 -04001736sub get_sha1 {
1737 my ($commit) = @_;
1738
1739 doprint "git rev-list --max-count=1 $commit ... ";
1740 my $sha1 = `git rev-list --max-count=1 $commit`;
1741 my $ret = $?;
1742
1743 logit $sha1;
1744
1745 if ($ret) {
1746 doprint "FAILED\n";
1747 dodie "Failed to get git $commit";
1748 }
1749
1750 print "SUCCESS\n";
1751
1752 chomp $sha1;
1753
1754 return $sha1;
1755}
1756
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001757sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001758 my $booted = 0;
1759 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001760 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001761 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001762 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001763
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001764 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001765
1766 my $line;
1767 my $full_line = "";
1768
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001769 open(DMESG, "> $dmesg") or
1770 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001771
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001772 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001773
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001774 my $success_start;
1775 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001776 my $monitor_start = time;
1777 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001778 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001779
Steven Rostedt2d01b262011-03-08 09:47:54 -05001780 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001781
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001782 if ($bug && defined($stop_after_failure) &&
1783 $stop_after_failure >= 0) {
1784 my $time = $stop_after_failure - (time - $failure_start);
1785 $line = wait_for_input($monitor_fp, $time);
1786 if (!defined($line)) {
1787 doprint "bug timed out after $booted_timeout seconds\n";
1788 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1789 last;
1790 }
1791 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001792 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001793 if (!defined($line)) {
1794 my $s = $booted_timeout == 1 ? "" : "s";
1795 doprint "Successful boot found: break after $booted_timeout second$s\n";
1796 last;
1797 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001798 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001799 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001800 if (!defined($line)) {
1801 my $s = $timeout == 1 ? "" : "s";
1802 doprint "Timed out after $timeout second$s\n";
1803 last;
1804 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001805 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001806
Steven Rostedt2545eb62010-11-02 15:01:32 -04001807 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001808 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001809
1810 # we are not guaranteed to get a full line
1811 $full_line .= $line;
1812
Steven Rostedta75fece2010-11-02 14:58:27 -04001813 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001814 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001815 $success_start = time;
1816 }
1817
1818 if ($booted && defined($stop_after_success) &&
1819 $stop_after_success >= 0) {
1820 my $now = time;
1821 if ($now - $success_start >= $stop_after_success) {
1822 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1823 last;
1824 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001825 }
1826
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001827 if ($full_line =~ /\[ backtrace testing \]/) {
1828 $skip_call_trace = 1;
1829 }
1830
Steven Rostedt2545eb62010-11-02 15:01:32 -04001831 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001832 if (!$bug && !$skip_call_trace) {
1833 if ($ignore_errors) {
1834 $bug_ignored = 1;
1835 } else {
1836 $bug = 1;
1837 $failure_start = time;
1838 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001839 }
1840 }
1841
1842 if ($bug && defined($stop_after_failure) &&
1843 $stop_after_failure >= 0) {
1844 my $now = time;
1845 if ($now - $failure_start >= $stop_after_failure) {
1846 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1847 last;
1848 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001849 }
1850
1851 if ($full_line =~ /\[ end of backtrace testing \]/) {
1852 $skip_call_trace = 0;
1853 }
1854
1855 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001856 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001857 $bug = 1;
1858 }
1859
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001860 # Detect triple faults by testing the banner
1861 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1862 if ($1 eq $version) {
1863 $version_found = 1;
1864 } elsif ($version_found && $detect_triplefault) {
1865 # We already booted into the kernel we are testing,
1866 # but now we booted into another kernel?
1867 # Consider this a triple fault.
Masanari Iida8b513d02013-05-21 23:13:12 +09001868 doprint "Already booted in Linux kernel $version, but now\n";
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001869 doprint "we booted into Linux kernel $1.\n";
1870 doprint "Assuming that this is a triple fault.\n";
1871 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1872 last;
1873 }
1874 }
1875
Steven Rostedt2545eb62010-11-02 15:01:32 -04001876 if ($line =~ /\n/) {
1877 $full_line = "";
1878 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001879
1880 if ($stop_test_after > 0 && !$booted && !$bug) {
1881 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001882 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001883 $done = 1;
1884 }
1885 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001886 }
1887
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001888 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001889
Steven Rostedt2545eb62010-11-02 15:01:32 -04001890 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001891 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001892 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001893 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001894
Steven Rostedta75fece2010-11-02 14:58:27 -04001895 if (!$booted) {
1896 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001897 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001898 }
1899
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001900 if ($bug_ignored) {
1901 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1902 }
1903
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001904 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001905}
1906
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001907sub eval_kernel_version {
1908 my ($option) = @_;
1909
1910 $option =~ s/\$KERNEL_VERSION/$version/g;
1911
1912 return $option;
1913}
1914
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001915sub do_post_install {
1916
1917 return if (!defined($post_install));
1918
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001919 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001920 run_command "$cp_post_install" or
1921 dodie "Failed to run post install";
1922}
1923
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001924# Sometimes the reboot fails, and will hang. We try to ssh to the box
1925# and if we fail, we force another reboot, that should powercycle it.
1926sub test_booted {
1927 if (!run_ssh "echo testing connection") {
1928 reboot $sleep_time;
1929 }
1930}
1931
Steven Rostedt2545eb62010-11-02 15:01:32 -04001932sub install {
1933
Steven Rostedte0a87422011-09-30 17:50:48 -04001934 return if ($no_install);
1935
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001936 if (defined($pre_install)) {
1937 my $cp_pre_install = eval_kernel_version $pre_install;
1938 run_command "$cp_pre_install" or
1939 dodie "Failed to run pre install";
1940 }
1941
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001942 my $cp_target = eval_kernel_version $target_image;
1943
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001944 test_booted;
1945
Steven Rostedt02ad2612012-03-21 08:21:24 -04001946 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001947 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001948
1949 my $install_mods = 0;
1950
1951 # should we process modules?
1952 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001953 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001954 while (<IN>) {
1955 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001956 if (defined($1)) {
1957 $install_mods = 1;
1958 last;
1959 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001960 }
1961 }
1962 close(IN);
1963
1964 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001965 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001966 doprint "No modules needed\n";
1967 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001968 }
1969
Steven Rostedt627977d2012-03-21 08:16:15 -04001970 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001971 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001972
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001973 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001974 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001975
Steven Rostedte48c5292010-11-02 14:35:37 -04001976 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001977 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001978
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001979 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001980 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001981 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001982
Steven Rostedt02ad2612012-03-21 08:21:24 -04001983 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001984 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001985
Steven Rostedta75fece2010-11-02 14:58:27 -04001986 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001987
Steven Rostedte7b13442011-06-14 20:44:36 -04001988 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001989 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001990
Steven Rostedte48c5292010-11-02 14:35:37 -04001991 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001992
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001993 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001994}
1995
Steven Rostedtddf607e2011-06-14 20:49:13 -04001996sub get_version {
1997 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001998 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001999 doprint "$make kernelrelease ... ";
2000 $version = `$make kernelrelease | tail -1`;
2001 chomp($version);
2002 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002003 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002004}
2005
2006sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002007 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002008
2009 # Install bisects, don't need console
2010 if (defined $console) {
2011 start_monitor;
2012 wait_for_monitor 5;
2013 end_monitor;
2014 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002015
Steven Rostedtddf607e2011-06-14 20:49:13 -04002016 get_grub_index;
2017 get_version;
2018 install;
2019
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002020 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002021 return monitor;
2022}
2023
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002024my $check_build_re = ".*:.*(warning|error|Error):.*";
2025my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2026
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002027sub process_warning_line {
2028 my ($line) = @_;
2029
2030 chomp $line;
2031
2032 # for distcc heterogeneous systems, some compilers
2033 # do things differently causing warning lines
2034 # to be slightly different. This makes an attempt
2035 # to fixe those issues.
2036
2037 # chop off the index into the line
2038 # using distcc, some compilers give different indexes
2039 # depending on white space
2040 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2041
2042 # Some compilers use UTF-8 extended for quotes and some don't.
2043 $line =~ s/$utf8_quote/'/g;
2044
2045 return $line;
2046}
2047
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002048# Read buildlog and check against warnings file for any
2049# new warnings.
2050#
2051# Returns 1 if OK
2052# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002053sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002054 return 1 if (!defined $warnings_file);
2055
2056 my %warnings_list;
2057
2058 # Failed builds should not reboot the target
2059 my $save_no_reboot = $no_reboot;
2060 $no_reboot = 1;
2061
2062 if (-f $warnings_file) {
2063 open(IN, $warnings_file) or
2064 dodie "Error opening $warnings_file";
2065
2066 while (<IN>) {
2067 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002068 my $warning = process_warning_line $_;
2069
2070 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002071 }
2072 }
2073 close(IN);
2074 }
2075
2076 # If warnings file didn't exist, and WARNINGS_FILE exist,
2077 # then we fail on any warning!
2078
2079 open(IN, $buildlog) or dodie "Can't open $buildlog";
2080 while (<IN>) {
2081 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002082 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002083
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002084 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002085 fail "New warning found (not in $warnings_file)\n$_\n";
2086 $no_reboot = $save_no_reboot;
2087 return 0;
2088 }
2089 }
2090 }
2091 $no_reboot = $save_no_reboot;
2092 close(IN);
2093}
2094
2095sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002096 my ($patch) = @_;
2097
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002098 my @files = `git show $patch | diffstat -l`;
2099
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002100 foreach my $file (@files) {
2101 chomp $file;
2102 }
2103
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002104 open(IN, "git show $patch |") or
2105 dodie "failed to show $patch";
2106 while (<IN>) {
2107 if (m,^--- a/(.*),) {
2108 chomp $1;
2109 $files[$#files] = $1;
2110 }
2111 }
2112 close(IN);
2113
2114 open(IN, $buildlog) or dodie "Can't open $buildlog";
2115 while (<IN>) {
2116 if (/^\s*(.*?):.*(warning|error)/) {
2117 my $err = $1;
2118 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002119 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002120 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002121 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002122 }
2123 }
2124 }
2125 }
2126 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002127
2128 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002129}
2130
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002131sub apply_min_config {
2132 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002133
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002134 # Read the config file and remove anything that
2135 # is in the force_config hash (from minconfig and others)
2136 # then add the force config back.
2137
2138 doprint "Applying minimum configurations into $output_config.new\n";
2139
2140 open (OUT, ">$outconfig") or
2141 dodie "Can't create $outconfig";
2142
2143 if (-f $output_config) {
2144 open (IN, $output_config) or
2145 dodie "Failed to open $output_config";
2146 while (<IN>) {
2147 if (/^(# )?(CONFIG_[^\s=]*)/) {
2148 next if (defined($force_config{$2}));
2149 }
2150 print OUT;
2151 }
2152 close IN;
2153 }
2154 foreach my $config (keys %force_config) {
2155 print OUT "$force_config{$config}\n";
2156 }
2157 close OUT;
2158
2159 run_command "mv $outconfig $output_config";
2160}
2161
2162sub make_oldconfig {
2163
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002164 my @force_list = keys %force_config;
2165
2166 if ($#force_list >= 0) {
2167 apply_min_config;
2168 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002169
Adam Leefb16d892012-09-01 01:05:17 +08002170 if (!run_command "$make olddefconfig") {
2171 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002172 # try oldnoconfig
2173 doprint "olddefconfig failed, trying make oldnoconfig\n";
2174 if (!run_command "$make oldnoconfig") {
2175 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2176 # try a yes '' | oldconfig
2177 run_command "yes '' | $make oldconfig" or
2178 dodie "failed make config oldconfig";
2179 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002180 }
2181}
2182
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002183# read a config file and use this to force new configs.
2184sub load_force_config {
2185 my ($config) = @_;
2186
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002187 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002188 open(IN, $config) or
2189 dodie "failed to read $config";
2190 while (<IN>) {
2191 chomp;
2192 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2193 $force_config{$1} = $_;
2194 } elsif (/^# (CONFIG_\S*) is not set/) {
2195 $force_config{$1} = $_;
2196 }
2197 }
2198 close IN;
2199}
2200
Steven Rostedt2545eb62010-11-02 15:01:32 -04002201sub build {
2202 my ($type) = @_;
2203
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002204 unlink $buildlog;
2205
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002206 # Failed builds should not reboot the target
2207 my $save_no_reboot = $no_reboot;
2208 $no_reboot = 1;
2209
Steven Rostedt683a3e62012-05-18 13:34:35 -04002210 # Calculate a new version from here.
2211 $have_version = 0;
2212
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002213 if (defined($pre_build)) {
2214 my $ret = run_command $pre_build;
2215 if (!$ret && defined($pre_build_die) &&
2216 $pre_build_die) {
2217 dodie "failed to pre_build\n";
2218 }
2219 }
2220
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002221 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002222 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002223 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002224
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002225 $type = "oldconfig";
2226 }
2227
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002228 # old config can ask questions
2229 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002230 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002231
2232 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002233 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002234
Andrew Jones13488232011-08-12 15:32:04 +02002235 if (!$noclean) {
2236 run_command "mv $output_config $outputdir/config_temp" or
2237 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002238
Andrew Jones13488232011-08-12 15:32:04 +02002239 run_command "$make mrproper" or dodie "make mrproper";
2240
2241 run_command "mv $outputdir/config_temp $output_config" or
2242 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002243 }
2244
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002245 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002246 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002247 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002248 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002249 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002250
2251 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002252 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2253 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002254 close(OUT);
2255
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002256 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002257 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002258 }
2259
Adam Leefb16d892012-09-01 01:05:17 +08002260 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002261 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002262 dodie "failed make config";
2263 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002264 # Run old config regardless, to enforce min configurations
2265 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002266
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002267 my $build_ret = run_command "$make $build_options", $buildlog;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002268
2269 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002270 # Because a post build may change the kernel version
2271 # do it now.
2272 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002273 my $ret = run_command $post_build;
2274 if (!$ret && defined($post_build_die) &&
2275 $post_build_die) {
2276 dodie "failed to post_build\n";
2277 }
2278 }
2279
2280 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002281 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002282 if ($in_bisect) {
2283 $no_reboot = $save_no_reboot;
2284 return 0;
2285 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002286 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002287 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002288
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002289 $no_reboot = $save_no_reboot;
2290
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002291 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002292}
2293
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002294sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002295 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002296 if (defined($poweroff_after_halt)) {
2297 sleep $poweroff_after_halt;
2298 run_command "$power_off";
2299 }
2300 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002301 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002302 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002303 }
2304}
2305
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002306sub success {
2307 my ($i) = @_;
2308
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002309 if (defined($post_test)) {
2310 run_command $post_test;
2311 }
2312
Steven Rostedte48c5292010-11-02 14:35:37 -04002313 $successes++;
2314
Steven Rostedt9064af52011-06-13 10:38:48 -04002315 my $name = "";
2316
2317 if (defined($test_name)) {
2318 $name = " ($test_name)";
2319 }
2320
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002321 doprint "\n\n*******************************************\n";
2322 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002323 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002324 doprint "*******************************************\n";
2325 doprint "*******************************************\n";
2326
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302327 if (defined($store_successes)) {
2328 save_logs "success", $store_successes;
2329 }
2330
Steven Rostedt576f6272010-11-02 14:58:38 -04002331 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002332 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002333 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002334 }
2335}
2336
Steven Rostedtc960bb92011-03-08 09:22:39 -05002337sub answer_bisect {
2338 for (;;) {
2339 doprint "Pass or fail? [p/f]";
2340 my $ans = <STDIN>;
2341 chomp $ans;
2342 if ($ans eq "p" || $ans eq "P") {
2343 return 1;
2344 } elsif ($ans eq "f" || $ans eq "F") {
2345 return 0;
2346 } else {
2347 print "Please answer 'P' or 'F'\n";
2348 }
2349 }
2350}
2351
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002352sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002353 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002354
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002355 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002356 $reboot_on_error = 0;
2357 $poweroff_on_error = 0;
2358 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002359
Satoru Takeuchif983a2b2014-03-02 21:20:31 +09002360 run_command $run_test, $testlog or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302361
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002362 exit $failed;
2363}
2364
2365my $child_done;
2366
2367sub child_finished {
2368 $child_done = 1;
2369}
2370
2371sub do_run_test {
2372 my $child_pid;
2373 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002374 my $line;
2375 my $full_line;
2376 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002377 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002378
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002379 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002380
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002381 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002382
2383 $child_done = 0;
2384
2385 $SIG{CHLD} = qw(child_finished);
2386
2387 $child_pid = fork;
2388
2389 child_run_test if (!$child_pid);
2390
2391 $full_line = "";
2392
2393 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002394 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002395 if (defined($line)) {
2396
2397 # we are not guaranteed to get a full line
2398 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002399 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002400
2401 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002402 if ($ignore_errors) {
2403 $bug_ignored = 1;
2404 } else {
2405 $bug = 1;
2406 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002407 }
2408
2409 if ($full_line =~ /Kernel panic -/) {
2410 $bug = 1;
2411 }
2412
2413 if ($line =~ /\n/) {
2414 $full_line = "";
2415 }
2416 }
2417 } while (!$child_done && !$bug);
2418
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002419 if (!$bug && $bug_ignored) {
2420 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2421 }
2422
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002423 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002424 my $failure_start = time;
2425 my $now;
2426 do {
2427 $line = wait_for_input($monitor_fp, 1);
2428 if (defined($line)) {
2429 doprint $line;
2430 }
2431 $now = time;
2432 if ($now - $failure_start >= $stop_after_failure) {
2433 last;
2434 }
2435 } while (defined($line));
2436
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002437 doprint "Detected kernel crash!\n";
2438 # kill the child with extreme prejudice
2439 kill 9, $child_pid;
2440 }
2441
2442 waitpid $child_pid, 0;
2443 $child_exit = $?;
2444
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002445 if (!$bug && $in_bisect) {
2446 if (defined($bisect_ret_good)) {
2447 if ($child_exit == $bisect_ret_good) {
2448 return 1;
2449 }
2450 }
2451 if (defined($bisect_ret_skip)) {
2452 if ($child_exit == $bisect_ret_skip) {
2453 return -1;
2454 }
2455 }
2456 if (defined($bisect_ret_abort)) {
2457 if ($child_exit == $bisect_ret_abort) {
2458 fail "test abort" and return -2;
2459 }
2460 }
2461 if (defined($bisect_ret_bad)) {
2462 if ($child_exit == $bisect_ret_skip) {
2463 return 0;
2464 }
2465 }
2466 if (defined($bisect_ret_default)) {
2467 if ($bisect_ret_default eq "good") {
2468 return 1;
2469 } elsif ($bisect_ret_default eq "bad") {
2470 return 0;
2471 } elsif ($bisect_ret_default eq "skip") {
2472 return -1;
2473 } elsif ($bisect_ret_default eq "abort") {
2474 return -2;
2475 } else {
2476 fail "unknown default action: $bisect_ret_default"
2477 and return -2;
2478 }
2479 }
2480 }
2481
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002482 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002483 return 0 if $in_bisect;
2484 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002485 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002486 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002487}
2488
Steven Rostedta75fece2010-11-02 14:58:27 -04002489sub run_git_bisect {
2490 my ($command) = @_;
2491
2492 doprint "$command ... ";
2493
2494 my $output = `$command 2>&1`;
2495 my $ret = $?;
2496
2497 logit $output;
2498
2499 if ($ret) {
2500 doprint "FAILED\n";
2501 dodie "Failed to git bisect";
2502 }
2503
2504 doprint "SUCCESS\n";
2505 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2506 doprint "$1 [$2]\n";
2507 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002508 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002509 doprint "Found bad commit... $1\n";
2510 return 0;
2511 } else {
2512 # we already logged it, just print it now.
2513 print $output;
2514 }
2515
2516 return 1;
2517}
2518
Steven Rostedtc23dca72011-03-08 09:26:31 -05002519sub bisect_reboot {
2520 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002521 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002522}
2523
2524# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002525sub run_bisect_test {
2526 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002527
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002528 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002529 my $result;
2530 my $output;
2531 my $ret;
2532
Steven Rostedt0a05c762010-11-08 11:14:10 -05002533 $in_bisect = 1;
2534
2535 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002536
2537 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002538 if ($failed && $bisect_skip) {
2539 $in_bisect = 0;
2540 return -1;
2541 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002542 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002543
2544 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002545 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002546
2547 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002548 if ($failed && $bisect_skip) {
2549 end_monitor;
2550 bisect_reboot;
2551 $in_bisect = 0;
2552 return -1;
2553 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002554 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002555
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002556 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002557 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002558 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002559 }
2560
2561 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002562 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002563 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002564 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002565 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002566
2567 # reboot the box to a kernel we can ssh to
2568 if ($type ne "build") {
2569 bisect_reboot;
2570 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002571 $in_bisect = 0;
2572
2573 return $result;
2574}
2575
2576sub run_bisect {
2577 my ($type) = @_;
2578 my $buildtype = "oldconfig";
2579
2580 # We should have a minconfig to use?
2581 if (defined($minconfig)) {
2582 $buildtype = "useconfig:$minconfig";
2583 }
2584
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002585 # If the user sets bisect_tries to less than 1, then no tries
2586 # is a success.
2587 my $ret = 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002588
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002589 # Still let the user manually decide that though.
2590 if ($bisect_tries < 1 && $bisect_manual) {
Steven Rostedtc960bb92011-03-08 09:22:39 -05002591 $ret = answer_bisect;
2592 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002593
Steven Rostedt (Red Hat)961d9ca2014-01-18 19:52:13 -05002594 for (my $i = 0; $i < $bisect_tries; $i++) {
2595 if ($bisect_tries > 1) {
2596 my $t = $i + 1;
2597 doprint("Running bisect trial $t of $bisect_tries:\n");
2598 }
2599 $ret = run_bisect_test $type, $buildtype;
2600
2601 if ($bisect_manual) {
2602 $ret = answer_bisect;
2603 }
2604
2605 last if (!$ret);
2606 }
2607
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002608 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002609 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002610 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002611 }
2612
Steven Rostedtc23dca72011-03-08 09:26:31 -05002613 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002614 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002615 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002616 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002617 } elsif ($bisect_skip) {
2618 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2619 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002620 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002621}
2622
Steven Rostedtdad98752011-11-22 20:48:57 -05002623sub update_bisect_replay {
2624 my $tmp_log = "$tmpdir/ktest_bisect_log";
2625 run_command "git bisect log > $tmp_log" or
2626 die "can't create bisect log";
2627 return $tmp_log;
2628}
2629
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002630sub bisect {
2631 my ($i) = @_;
2632
2633 my $result;
2634
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002635 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2636 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2637 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002638
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002639 my $good = $bisect_good;
2640 my $bad = $bisect_bad;
2641 my $type = $bisect_type;
2642 my $start = $bisect_start;
2643 my $replay = $bisect_replay;
2644 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002645
2646 if (defined($start_files)) {
2647 $start_files = " -- " . $start_files;
2648 } else {
2649 $start_files = "";
2650 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002651
Steven Rostedta57419b2010-11-02 15:13:54 -04002652 # convert to true sha1's
2653 $good = get_sha1($good);
2654 $bad = get_sha1($bad);
2655
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002656 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002657 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2658 $reverse_bisect = 1;
2659 } else {
2660 $reverse_bisect = 0;
2661 }
2662
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002663 # Can't have a test without having a test to run
2664 if ($type eq "test" && !defined($run_test)) {
2665 $type = "boot";
2666 }
2667
Steven Rostedtdad98752011-11-22 20:48:57 -05002668 # Check if a bisect was running
2669 my $bisect_start_file = "$builddir/.git/BISECT_START";
2670
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002671 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002672 my $do_check = defined($check) && $check ne "0";
2673
2674 if ( -f $bisect_start_file ) {
2675 print "Bisect in progress found\n";
2676 if ($do_check) {
2677 print " If you say yes, then no checks of good or bad will be done\n";
2678 }
2679 if (defined($replay)) {
2680 print "** BISECT_REPLAY is defined in config file **";
2681 print " Ignore config option and perform new git bisect log?\n";
2682 if (read_ync " (yes, no, or cancel) ") {
2683 $replay = update_bisect_replay;
2684 $do_check = 0;
2685 }
2686 } elsif (read_yn "read git log and continue?") {
2687 $replay = update_bisect_replay;
2688 $do_check = 0;
2689 }
2690 }
2691
2692 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002693
2694 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002695 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002696
2697 if ($check ne "good") {
2698 doprint "TESTING BISECT BAD [$bad]\n";
2699 run_command "git checkout $bad" or
2700 die "Failed to checkout $bad";
2701
2702 $result = run_bisect $type;
2703
2704 if ($result ne "bad") {
2705 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2706 }
2707 }
2708
2709 if ($check ne "bad") {
2710 doprint "TESTING BISECT GOOD [$good]\n";
2711 run_command "git checkout $good" or
2712 die "Failed to checkout $good";
2713
2714 $result = run_bisect $type;
2715
2716 if ($result ne "good") {
2717 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2718 }
2719 }
2720
2721 # checkout where we started
2722 run_command "git checkout $head" or
2723 die "Failed to checkout $head";
2724 }
2725
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002726 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002727 dodie "could not start bisect";
2728
2729 run_command "git bisect good $good" or
2730 dodie "could not set bisect good to $good";
2731
2732 run_git_bisect "git bisect bad $bad" or
2733 dodie "could not set bisect bad to $bad";
2734
2735 if (defined($replay)) {
2736 run_command "git bisect replay $replay" or
2737 dodie "failed to run replay";
2738 }
2739
2740 if (defined($start)) {
2741 run_command "git checkout $start" or
2742 dodie "failed to checkout $start";
2743 }
2744
2745 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002746 do {
2747 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002748 $test = run_git_bisect "git bisect $result";
2749 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002750
2751 run_command "git bisect log" or
2752 dodie "could not capture git bisect log";
2753
2754 run_command "git bisect reset" or
2755 dodie "could not reset git bisect";
2756
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002757 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002758
Steven Rostedt0a05c762010-11-08 11:14:10 -05002759 success $i;
2760}
2761
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002762# config_ignore holds the configs that were set (or unset) for
2763# a good config and we will ignore these configs for the rest
2764# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002765my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002766
2767# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002768my %config_set;
2769
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002770# config_off holds the set of configs that the bad config had disabled.
2771# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002772# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002773my %config_off;
2774
2775# config_off_tmp holds a set of configs to turn off for now
2776my @config_off_tmp;
2777
2778# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002779my %config_list;
2780my %null_config;
2781
2782my %dependency;
2783
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002784sub assign_configs {
2785 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002786
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002787 doprint "Reading configs from $config\n";
2788
Steven Rostedt0a05c762010-11-08 11:14:10 -05002789 open (IN, $config)
2790 or dodie "Failed to read $config";
2791
2792 while (<IN>) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002793 chomp;
Steven Rostedt9bf71742011-06-01 23:27:19 -04002794 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002795 ${$hash}{$2} = $1;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002796 } elsif (/^(# (CONFIG\S*) is not set)/) {
2797 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002798 }
2799 }
2800
2801 close(IN);
2802}
2803
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002804sub process_config_ignore {
2805 my ($config) = @_;
2806
2807 assign_configs \%config_ignore, $config;
2808}
2809
Steven Rostedt0a05c762010-11-08 11:14:10 -05002810sub get_dependencies {
2811 my ($config) = @_;
2812
2813 my $arr = $dependency{$config};
2814 if (!defined($arr)) {
2815 return ();
2816 }
2817
2818 my @deps = @{$arr};
2819
2820 foreach my $dep (@{$arr}) {
2821 print "ADD DEP $dep\n";
2822 @deps = (@deps, get_dependencies $dep);
2823 }
2824
2825 return @deps;
2826}
2827
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002828sub save_config {
2829 my ($pc, $file) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002830
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002831 my %configs = %{$pc};
Steven Rostedt0a05c762010-11-08 11:14:10 -05002832
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002833 doprint "Saving configs into $file\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002834
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002835 open(OUT, ">$file") or dodie "Can not write to $file";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002836
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002837 foreach my $config (keys %configs) {
2838 print OUT "$configs{$config}\n";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002839 }
2840 close(OUT);
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002841}
2842
2843sub create_config {
2844 my ($name, $pc) = @_;
2845
2846 doprint "Creating old config from $name configs\n";
2847
2848 save_config $pc, $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002849
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002850 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002851}
2852
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002853# compare two config hashes, and return configs with different vals.
2854# It returns B's config values, but you can use A to see what A was.
2855sub diff_config_vals {
2856 my ($pa, $pb) = @_;
2857
2858 # crappy Perl way to pass in hashes.
2859 my %a = %{$pa};
2860 my %b = %{$pb};
2861
2862 my %ret;
2863
2864 foreach my $item (keys %a) {
2865 if (defined($b{$item}) && $b{$item} ne $a{$item}) {
2866 $ret{$item} = $b{$item};
2867 }
2868 }
2869
2870 return %ret;
2871}
2872
2873# compare two config hashes and return the configs in B but not A
2874sub diff_configs {
2875 my ($pa, $pb) = @_;
2876
2877 my %ret;
2878
2879 # crappy Perl way to pass in hashes.
2880 my %a = %{$pa};
2881 my %b = %{$pb};
2882
2883 foreach my $item (keys %b) {
2884 if (!defined($a{$item})) {
2885 $ret{$item} = $b{$item};
2886 }
2887 }
2888
2889 return %ret;
2890}
2891
2892# return if two configs are equal or not
2893# 0 is equal +1 b has something a does not
2894# +1 if a and b have a different item.
2895# -1 if a has something b does not
Steven Rostedt0a05c762010-11-08 11:14:10 -05002896sub compare_configs {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002897 my ($pa, $pb) = @_;
2898
2899 my %ret;
2900
2901 # crappy Perl way to pass in hashes.
2902 my %a = %{$pa};
2903 my %b = %{$pb};
2904
2905 foreach my $item (keys %b) {
2906 if (!defined($a{$item})) {
2907 return 1;
2908 }
2909 if ($a{$item} ne $b{$item}) {
2910 return 1;
2911 }
2912 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002913
2914 foreach my $item (keys %a) {
2915 if (!defined($b{$item})) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002916 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002917 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002918 }
2919
Steven Rostedt0a05c762010-11-08 11:14:10 -05002920 return 0;
2921}
2922
2923sub run_config_bisect_test {
2924 my ($type) = @_;
2925
2926 return run_bisect_test $type, "oldconfig";
2927}
2928
Steven Rostedt0a05c762010-11-08 11:14:10 -05002929sub process_failed {
2930 my ($config) = @_;
2931
2932 doprint "\n\n***************************************\n";
2933 doprint "Found bad config: $config\n";
2934 doprint "***************************************\n\n";
2935}
2936
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002937# used for config bisecting
2938my $good_config;
2939my $bad_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002940
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002941sub process_new_config {
2942 my ($tc, $nc, $gc, $bc) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002943
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002944 my %tmp_config = %{$tc};
2945 my %good_configs = %{$gc};
2946 my %bad_configs = %{$bc};
2947
2948 my %new_configs;
2949
2950 my $runtest = 1;
2951 my $ret;
2952
2953 create_config "tmp_configs", \%tmp_config;
2954 assign_configs \%new_configs, $output_config;
2955
2956 $ret = compare_configs \%new_configs, \%bad_configs;
2957 if (!$ret) {
2958 doprint "New config equals bad config, try next test\n";
2959 $runtest = 0;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002960 }
2961
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002962 if ($runtest) {
2963 $ret = compare_configs \%new_configs, \%good_configs;
2964 if (!$ret) {
2965 doprint "New config equals good config, try next test\n";
2966 $runtest = 0;
2967 }
2968 }
2969
2970 %{$nc} = %new_configs;
2971
2972 return $runtest;
2973}
2974
2975sub run_config_bisect {
2976 my ($pgood, $pbad) = @_;
2977
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002978 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04002979
2980 my %good_configs = %{$pgood};
2981 my %bad_configs = %{$pbad};
2982
2983 my %diff_configs = diff_config_vals \%good_configs, \%bad_configs;
2984 my %b_configs = diff_configs \%good_configs, \%bad_configs;
2985 my %g_configs = diff_configs \%bad_configs, \%good_configs;
2986
2987 my @diff_arr = keys %diff_configs;
2988 my $len_diff = $#diff_arr + 1;
2989
2990 my @b_arr = keys %b_configs;
2991 my $len_b = $#b_arr + 1;
2992
2993 my @g_arr = keys %g_configs;
2994 my $len_g = $#g_arr + 1;
2995
2996 my $runtest = 1;
2997 my %new_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002998 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002999
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003000 # First, lets get it down to a single subset.
3001 # Is the problem with a difference in values?
3002 # Is the problem with a missing config?
3003 # Is the problem with a config that breaks things?
Steven Rostedt0a05c762010-11-08 11:14:10 -05003004
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003005 # Enable all of one set and see if we get a new bad
3006 # or good config.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003007
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003008 # first set the good config to the bad values.
Steven Rostedt0a05c762010-11-08 11:14:10 -05003009
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003010 doprint "d=$len_diff g=$len_g b=$len_b\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003011
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003012 # first lets enable things in bad config that are enabled in good config
Steven Rostedt0a05c762010-11-08 11:14:10 -05003013
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003014 if ($len_diff > 0) {
3015 if ($len_b > 0 || $len_g > 0) {
3016 my %tmp_config = %bad_configs;
3017
3018 doprint "Set tmp config to be bad config with good config values\n";
3019 foreach my $item (@diff_arr) {
3020 $tmp_config{$item} = $good_configs{$item};
Steven Rostedt0a05c762010-11-08 11:14:10 -05003021 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003022
3023 $runtest = process_new_config \%tmp_config, \%new_configs,
3024 \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003025 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003026 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003027
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003028 if (!$runtest && $len_diff > 0) {
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003029
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003030 if ($len_diff == 1) {
Steven Rostedt (Red Hat)4186cb42014-04-23 22:09:59 -04003031 process_failed $diff_arr[0];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003032 return 1;
3033 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003034 my %tmp_config = %bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003035
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003036 my $half = int($#diff_arr / 2);
3037 my @tophalf = @diff_arr[0 .. $half];
Steven Rostedt0a05c762010-11-08 11:14:10 -05003038
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003039 doprint "Settings bisect with top half:\n";
3040 doprint "Set tmp config to be bad config with some good config values\n";
3041 foreach my $item (@tophalf) {
3042 $tmp_config{$item} = $good_configs{$item};
3043 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003044
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003045 $runtest = process_new_config \%tmp_config, \%new_configs,
3046 \%good_configs, \%bad_configs;
3047
3048 if (!$runtest) {
3049 my %tmp_config = %bad_configs;
3050
3051 doprint "Try bottom half\n";
3052
3053 my @bottomhalf = @diff_arr[$half+1 .. $#diff_arr];
3054
3055 foreach my $item (@bottomhalf) {
3056 $tmp_config{$item} = $good_configs{$item};
3057 }
3058
3059 $runtest = process_new_config \%tmp_config, \%new_configs,
3060 \%good_configs, \%bad_configs;
3061 }
Steven Rostedtc960bb92011-03-08 09:22:39 -05003062 }
3063
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003064 if ($runtest) {
3065 $ret = run_config_bisect_test $type;
3066 if ($ret) {
3067 doprint "NEW GOOD CONFIG\n";
3068 %good_configs = %new_configs;
3069 run_command "mv $good_config ${good_config}.last";
3070 save_config \%good_configs, $good_config;
3071 %{$pgood} = %good_configs;
3072 } else {
3073 doprint "NEW BAD CONFIG\n";
3074 %bad_configs = %new_configs;
3075 run_command "mv $bad_config ${bad_config}.last";
3076 save_config \%bad_configs, $bad_config;
3077 %{$pbad} = %bad_configs;
3078 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05003079 return 0;
3080 }
3081
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003082 fail "Hmm, need to do a mix match?\n";
3083 return -1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003084}
3085
3086sub config_bisect {
3087 my ($i) = @_;
3088
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003089 my $type = $config_bisect_type;
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003090 my $ret;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003091
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003092 $bad_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003093
Steven Rostedt30f75da2011-06-13 10:35:35 -04003094 if (defined($config_bisect_good)) {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003095 $good_config = $config_bisect_good;
3096 } elsif (defined($minconfig)) {
3097 $good_config = $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003098 } else {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003099 doprint "No config specified, checking if defconfig works";
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003100 $ret = run_bisect_test $type, "defconfig";
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003101 if (!$ret) {
3102 fail "Have no good config to compare with, please set CONFIG_BISECT_GOOD";
3103 return 1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003104 }
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003105 $good_config = $output_config;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003106 }
3107
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003108 # we don't want min configs to cause issues here.
3109 doprint "Disabling 'MIN_CONFIG' for this test\n";
3110 undef $minconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003111
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003112 my %good_configs;
3113 my %bad_configs;
3114 my %tmp_configs;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003115
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003116 doprint "Run good configs through make oldconfig\n";
3117 assign_configs \%tmp_configs, $good_config;
3118 create_config "$good_config", \%tmp_configs;
3119 assign_configs \%good_configs, $output_config;
3120
3121 doprint "Run bad configs through make oldconfig\n";
3122 assign_configs \%tmp_configs, $bad_config;
3123 create_config "$bad_config", \%tmp_configs;
3124 assign_configs \%bad_configs, $output_config;
3125
3126 $good_config = "$tmpdir/good_config";
3127 $bad_config = "$tmpdir/bad_config";
3128
3129 save_config \%good_configs, $good_config;
3130 save_config \%bad_configs, $bad_config;
3131
Steven Rostedt (Red Hat)c4d1d112014-04-23 22:04:56 -04003132
3133 if (defined($config_bisect_check) && $config_bisect_check ne "0") {
3134 if ($config_bisect_check ne "good") {
3135 doprint "Testing bad config\n";
3136
3137 $ret = run_bisect_test $type, "useconfig:$bad_config";
3138 if ($ret) {
3139 fail "Bad config succeeded when expected to fail!";
3140 return 0;
3141 }
3142 }
3143 if ($config_bisect_check ne "bad") {
3144 doprint "Testing good config\n";
3145
3146 $ret = run_bisect_test $type, "useconfig:$good_config";
3147 if (!$ret) {
3148 fail "Good config failed when expected to succeed!";
3149 return 0;
3150 }
3151 }
3152 }
Steven Rostedtb0918612012-07-19 15:26:00 -04003153
Steven Rostedt0a05c762010-11-08 11:14:10 -05003154 do {
Steven Rostedt (Red Hat)6071c222014-04-23 15:24:04 -04003155 $ret = run_config_bisect \%good_configs, \%bad_configs;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003156 } while (!$ret);
3157
3158 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003159
3160 success $i;
3161}
3162
Steven Rostedt27d934b2011-05-20 09:18:18 -04003163sub patchcheck_reboot {
3164 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003165 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003166}
3167
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003168sub patchcheck {
3169 my ($i) = @_;
3170
3171 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003172 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003173 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003174 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003175
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003176 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003177
3178 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003179 if (defined($patchcheck_end)) {
3180 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003181 }
3182
Steven Rostedta57419b2010-11-02 15:13:54 -04003183 # Get the true sha1's since we can use things like HEAD~3
3184 $start = get_sha1($start);
3185 $end = get_sha1($end);
3186
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003187 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003188
3189 # Can't have a test without having a test to run
3190 if ($type eq "test" && !defined($run_test)) {
3191 $type = "boot";
3192 }
3193
3194 open (IN, "git log --pretty=oneline $end|") or
3195 dodie "could not get git list";
3196
3197 my @list;
3198
3199 while (<IN>) {
3200 chomp;
3201 $list[$#list+1] = $_;
3202 last if (/^$start/);
3203 }
3204 close(IN);
3205
3206 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003207 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003208 }
3209
3210 # go backwards in the list
3211 @list = reverse @list;
3212
3213 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003214 my %ignored_warnings;
3215
3216 if (defined($ignore_warnings)) {
3217 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3218 $ignored_warnings{$sha1} = 1;
3219 }
3220 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003221
3222 $in_patchcheck = 1;
3223 foreach my $item (@list) {
3224 my $sha1 = $item;
3225 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3226
3227 doprint "\nProcessing commit $item\n\n";
3228
3229 run_command "git checkout $sha1" or
3230 die "Failed to checkout $sha1";
3231
3232 # only clean on the first and last patch
3233 if ($item eq $list[0] ||
3234 $item eq $list[$#list]) {
3235 $noclean = $save_clean;
3236 } else {
3237 $noclean = 1;
3238 }
3239
3240 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003241 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003242 } else {
3243 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003244 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003245 }
3246
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003247 # No need to do per patch checking if warnings file exists
3248 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3249 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003250 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003251
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003252 check_buildlog or return 0;
3253
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003254 next if ($type eq "build");
3255
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003256 my $failed = 0;
3257
Steven Rostedtddf607e2011-06-14 20:49:13 -04003258 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003259
3260 if (!$failed && $type ne "boot"){
3261 do_run_test or $failed = 1;
3262 }
3263 end_monitor;
3264 return 0 if ($failed);
3265
Steven Rostedt27d934b2011-05-20 09:18:18 -04003266 patchcheck_reboot;
3267
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003268 }
3269 $in_patchcheck = 0;
3270 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003271
3272 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003273}
3274
Steven Rostedtb9066f62011-07-15 21:25:24 -04003275my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003276my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003277my $iflevel = 0;
3278my @ifdeps;
3279
3280# prevent recursion
3281my %read_kconfigs;
3282
Steven Rostedtac6974c2011-10-04 09:40:17 -04003283sub add_dep {
3284 # $config depends on $dep
3285 my ($config, $dep) = @_;
3286
3287 if (defined($depends{$config})) {
3288 $depends{$config} .= " " . $dep;
3289 } else {
3290 $depends{$config} = $dep;
3291 }
3292
3293 # record the number of configs depending on $dep
3294 if (defined $depcount{$dep}) {
3295 $depcount{$dep}++;
3296 } else {
3297 $depcount{$dep} = 1;
3298 }
3299}
3300
Steven Rostedtb9066f62011-07-15 21:25:24 -04003301# taken from streamline_config.pl
3302sub read_kconfig {
3303 my ($kconfig) = @_;
3304
3305 my $state = "NONE";
3306 my $config;
3307 my @kconfigs;
3308
3309 my $cont = 0;
3310 my $line;
3311
3312
3313 if (! -f $kconfig) {
3314 doprint "file $kconfig does not exist, skipping\n";
3315 return;
3316 }
3317
3318 open(KIN, "$kconfig")
3319 or die "Can't open $kconfig";
3320 while (<KIN>) {
3321 chomp;
3322
3323 # Make sure that lines ending with \ continue
3324 if ($cont) {
3325 $_ = $line . " " . $_;
3326 }
3327
3328 if (s/\\$//) {
3329 $cont = 1;
3330 $line = $_;
3331 next;
3332 }
3333
3334 $cont = 0;
3335
3336 # collect any Kconfig sources
3337 if (/^source\s*"(.*)"/) {
3338 $kconfigs[$#kconfigs+1] = $1;
3339 }
3340
3341 # configs found
3342 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3343 $state = "NEW";
3344 $config = $2;
3345
3346 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003347 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003348 }
3349
3350 # collect the depends for the config
3351 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3352
Steven Rostedtac6974c2011-10-04 09:40:17 -04003353 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003354
3355 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003356 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3357
3358 # selected by depends on config
3359 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003360
3361 # Check for if statements
3362 } elsif (/^if\s+(.*\S)\s*$/) {
3363 my $deps = $1;
3364 # remove beginning and ending non text
3365 $deps =~ s/^[^a-zA-Z0-9_]*//;
3366 $deps =~ s/[^a-zA-Z0-9_]*$//;
3367
3368 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3369
3370 $ifdeps[$iflevel++] = join ':', @deps;
3371
3372 } elsif (/^endif/) {
3373
3374 $iflevel-- if ($iflevel);
3375
3376 # stop on "help"
3377 } elsif (/^\s*help\s*$/) {
3378 $state = "NONE";
3379 }
3380 }
3381 close(KIN);
3382
3383 # read in any configs that were found.
3384 foreach $kconfig (@kconfigs) {
3385 if (!defined($read_kconfigs{$kconfig})) {
3386 $read_kconfigs{$kconfig} = 1;
3387 read_kconfig("$builddir/$kconfig");
3388 }
3389 }
3390}
3391
3392sub read_depends {
3393 # find out which arch this is by the kconfig file
3394 open (IN, $output_config)
3395 or dodie "Failed to read $output_config";
3396 my $arch;
3397 while (<IN>) {
3398 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3399 $arch = $1;
3400 last;
3401 }
3402 }
3403 close IN;
3404
3405 if (!defined($arch)) {
3406 doprint "Could not find arch from config file\n";
3407 doprint "no dependencies used\n";
3408 return;
3409 }
3410
3411 # arch is really the subarch, we need to know
3412 # what directory to look at.
3413 if ($arch eq "i386" || $arch eq "x86_64") {
3414 $arch = "x86";
3415 } elsif ($arch =~ /^tile/) {
3416 $arch = "tile";
3417 }
3418
3419 my $kconfig = "$builddir/arch/$arch/Kconfig";
3420
3421 if (! -f $kconfig && $arch =~ /\d$/) {
3422 my $orig = $arch;
3423 # some subarchs have numbers, truncate them
3424 $arch =~ s/\d*$//;
3425 $kconfig = "$builddir/arch/$arch/Kconfig";
3426 if (! -f $kconfig) {
3427 doprint "No idea what arch dir $orig is for\n";
3428 doprint "no dependencies used\n";
3429 return;
3430 }
3431 }
3432
3433 read_kconfig($kconfig);
3434}
3435
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003436sub make_new_config {
3437 my @configs = @_;
3438
3439 open (OUT, ">$output_config")
3440 or dodie "Failed to write $output_config";
3441
3442 foreach my $config (@configs) {
3443 print OUT "$config\n";
3444 }
3445 close OUT;
3446}
3447
Steven Rostedtac6974c2011-10-04 09:40:17 -04003448sub chomp_config {
3449 my ($config) = @_;
3450
3451 $config =~ s/CONFIG_//;
3452
3453 return $config;
3454}
3455
Steven Rostedtb9066f62011-07-15 21:25:24 -04003456sub get_depends {
3457 my ($dep) = @_;
3458
Steven Rostedtac6974c2011-10-04 09:40:17 -04003459 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003460
3461 $dep = $depends{"$kconfig"};
3462
3463 # the dep string we have saves the dependencies as they
3464 # were found, including expressions like ! && ||. We
3465 # want to split this out into just an array of configs.
3466
3467 my $valid = "A-Za-z_0-9";
3468
3469 my @configs;
3470
3471 while ($dep =~ /[$valid]/) {
3472
3473 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3474 my $conf = "CONFIG_" . $1;
3475
3476 $configs[$#configs + 1] = $conf;
3477
3478 $dep =~ s/^[^$valid]*[$valid]+//;
3479 } else {
3480 die "this should never happen";
3481 }
3482 }
3483
3484 return @configs;
3485}
3486
3487my %min_configs;
3488my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003489my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003490my %processed_configs;
3491my %nochange_config;
3492
3493sub test_this_config {
3494 my ($config) = @_;
3495
3496 my $found;
3497
3498 # if we already processed this config, skip it
3499 if (defined($processed_configs{$config})) {
3500 return undef;
3501 }
3502 $processed_configs{$config} = 1;
3503
3504 # if this config failed during this round, skip it
3505 if (defined($nochange_config{$config})) {
3506 return undef;
3507 }
3508
Steven Rostedtac6974c2011-10-04 09:40:17 -04003509 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003510
3511 # Test dependencies first
3512 if (defined($depends{"$kconfig"})) {
3513 my @parents = get_depends $config;
3514 foreach my $parent (@parents) {
3515 # if the parent is in the min config, check it first
3516 next if (!defined($min_configs{$parent}));
3517 $found = test_this_config($parent);
3518 if (defined($found)) {
3519 return $found;
3520 }
3521 }
3522 }
3523
3524 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003525 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003526 # .config to make sure it is missing the config that
3527 # we had before
3528 my %configs = %min_configs;
3529 delete $configs{$config};
3530 make_new_config ((values %configs), (values %keep_configs));
3531 make_oldconfig;
3532 undef %configs;
3533 assign_configs \%configs, $output_config;
3534
3535 return $config if (!defined($configs{$config}));
3536
3537 doprint "disabling config $config did not change .config\n";
3538
3539 $nochange_config{$config} = 1;
3540
3541 return undef;
3542}
3543
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003544sub make_min_config {
3545 my ($i) = @_;
3546
Steven Rostedtccc513b2012-05-21 17:13:40 -04003547 my $type = $minconfig_type;
3548 if ($type ne "boot" && $type ne "test") {
3549 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3550 " make_min_config works only with 'boot' and 'test'\n" and return;
3551 }
3552
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003553 if (!defined($output_minconfig)) {
3554 fail "OUTPUT_MIN_CONFIG not defined" and return;
3555 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003556
3557 # If output_minconfig exists, and the start_minconfig
3558 # came from min_config, than ask if we should use
3559 # that instead.
3560 if (-f $output_minconfig && !$start_minconfig_defined) {
3561 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003562 if (!defined($use_output_minconfig)) {
3563 if (read_yn " Use it as minconfig?") {
3564 $start_minconfig = $output_minconfig;
3565 }
3566 } elsif ($use_output_minconfig > 0) {
3567 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003568 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003569 } else {
3570 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003571 }
3572 }
3573
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003574 if (!defined($start_minconfig)) {
3575 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3576 }
3577
Steven Rostedt35ce5952011-07-15 21:57:25 -04003578 my $temp_config = "$tmpdir/temp_config";
3579
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003580 # First things first. We build an allnoconfig to find
3581 # out what the defaults are that we can't touch.
3582 # Some are selections, but we really can't handle selections.
3583
3584 my $save_minconfig = $minconfig;
3585 undef $minconfig;
3586
3587 run_command "$make allnoconfig" or return 0;
3588
Steven Rostedtb9066f62011-07-15 21:25:24 -04003589 read_depends;
3590
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003591 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003592
Steven Rostedt43d1b652011-07-15 22:01:56 -04003593 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003594 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003595
3596 if (defined($ignore_config)) {
3597 # make sure the file exists
3598 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003599 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003600 }
3601
Steven Rostedt43d1b652011-07-15 22:01:56 -04003602 %keep_configs = %save_configs;
3603
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003604 doprint "Load initial configs from $start_minconfig\n";
3605
3606 # Look at the current min configs, and save off all the
3607 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003608 assign_configs \%min_configs, $start_minconfig;
3609
3610 my @config_keys = keys %min_configs;
3611
Steven Rostedtac6974c2011-10-04 09:40:17 -04003612 # All configs need a depcount
3613 foreach my $config (@config_keys) {
3614 my $kconfig = chomp_config $config;
3615 if (!defined $depcount{$kconfig}) {
3616 $depcount{$kconfig} = 0;
3617 }
3618 }
3619
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003620 # Remove anything that was set by the make allnoconfig
3621 # we shouldn't need them as they get set for us anyway.
3622 foreach my $config (@config_keys) {
3623 # Remove anything in the ignore_config
3624 if (defined($keep_configs{$config})) {
3625 my $file = $ignore_config;
3626 $file =~ s,.*/(.*?)$,$1,;
3627 doprint "$config set by $file ... ignored\n";
3628 delete $min_configs{$config};
3629 next;
3630 }
3631 # But make sure the settings are the same. If a min config
3632 # sets a selection, we do not want to get rid of it if
3633 # it is not the same as what we have. Just move it into
3634 # the keep configs.
3635 if (defined($config_ignore{$config})) {
3636 if ($config_ignore{$config} ne $min_configs{$config}) {
3637 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3638 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3639 $keep_configs{$config} = $min_configs{$config};
3640 } else {
3641 doprint "$config set by allnoconfig ... ignored\n";
3642 }
3643 delete $min_configs{$config};
3644 }
3645 }
3646
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003647 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003648 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003649
3650 while (!$done) {
3651
3652 my $config;
3653 my $found;
3654
3655 # Now disable each config one by one and do a make oldconfig
3656 # till we find a config that changes our list.
3657
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003658 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003659
3660 # Sort keys by who is most dependent on
3661 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3662 @test_configs ;
3663
3664 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003665 my $reset = 1;
3666 for (my $i = 0; $i < $#test_configs; $i++) {
3667 if (!defined($nochange_config{$test_configs[0]})) {
3668 $reset = 0;
3669 last;
3670 }
3671 # This config didn't change the .config last time.
3672 # Place it at the end
3673 my $config = shift @test_configs;
3674 push @test_configs, $config;
3675 }
3676
3677 # if every test config has failed to modify the .config file
3678 # in the past, then reset and start over.
3679 if ($reset) {
3680 undef %nochange_config;
3681 }
3682
Steven Rostedtb9066f62011-07-15 21:25:24 -04003683 undef %processed_configs;
3684
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003685 foreach my $config (@test_configs) {
3686
Steven Rostedtb9066f62011-07-15 21:25:24 -04003687 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003688
Steven Rostedtb9066f62011-07-15 21:25:24 -04003689 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003690
3691 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003692 }
3693
3694 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003695 # we could have failed due to the nochange_config hash
3696 # reset and try again
3697 if (!$take_two) {
3698 undef %nochange_config;
3699 $take_two = 1;
3700 next;
3701 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003702 doprint "No more configs found that we can disable\n";
3703 $done = 1;
3704 last;
3705 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003706 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003707
3708 $config = $found;
3709
3710 doprint "Test with $config disabled\n";
3711
3712 # set in_bisect to keep build and monitor from dieing
3713 $in_bisect = 1;
3714
3715 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003716 build "oldconfig" or $failed = 1;
3717 if (!$failed) {
3718 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003719
3720 if ($type eq "test" && !$failed) {
3721 do_run_test or $failed = 1;
3722 }
3723
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003724 end_monitor;
3725 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003726
3727 $in_bisect = 0;
3728
3729 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003730 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003731 # this config is needed, add it to the ignore list.
3732 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003733 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003734 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003735
3736 # update new ignore configs
3737 if (defined($ignore_config)) {
3738 open (OUT, ">$temp_config")
3739 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003740 foreach my $config (keys %save_configs) {
3741 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003742 }
3743 close OUT;
3744 run_command "mv $temp_config $ignore_config" or
3745 dodie "failed to copy update to $ignore_config";
3746 }
3747
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003748 } else {
3749 # We booted without this config, remove it from the minconfigs.
3750 doprint "$config is not needed, disabling\n";
3751
3752 delete $min_configs{$config};
3753
3754 # Also disable anything that is not enabled in this config
3755 my %configs;
3756 assign_configs \%configs, $output_config;
3757 my @config_keys = keys %min_configs;
3758 foreach my $config (@config_keys) {
3759 if (!defined($configs{$config})) {
3760 doprint "$config is not set, disabling\n";
3761 delete $min_configs{$config};
3762 }
3763 }
3764
3765 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003766 open (OUT, ">$temp_config")
3767 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003768 foreach my $config (keys %keep_configs) {
3769 print OUT "$keep_configs{$config}\n";
3770 }
3771 foreach my $config (keys %min_configs) {
3772 print OUT "$min_configs{$config}\n";
3773 }
3774 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003775
3776 run_command "mv $temp_config $output_minconfig" or
3777 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003778 }
3779
3780 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003781 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003782 }
3783
3784 success $i;
3785 return 1;
3786}
3787
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003788sub make_warnings_file {
3789 my ($i) = @_;
3790
3791 if (!defined($warnings_file)) {
3792 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3793 }
3794
3795 if ($build_type eq "nobuild") {
3796 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3797 }
3798
3799 build $build_type or dodie "Failed to build";
3800
3801 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3802
3803 open(IN, $buildlog) or dodie "Can't open $buildlog";
3804 while (<IN>) {
3805
3806 # Some compilers use UTF-8 extended for quotes
3807 # for distcc heterogeneous systems, this causes issues
3808 s/$utf8_quote/'/g;
3809
3810 if (/$check_build_re/) {
3811 print OUT;
3812 }
3813 }
3814 close(IN);
3815
3816 close(OUT);
3817
3818 success $i;
3819}
3820
Satoru Takeuchi5269faa2014-03-09 23:32:04 +09003821$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl [config-file]\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003822
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003823if ($#ARGV == 0) {
3824 $ktest_config = $ARGV[0];
3825 if (! -f $ktest_config) {
3826 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003827 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003828 exit 0;
3829 }
3830 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003831}
3832
3833if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003834 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003835 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003836 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3837 print OUT << "EOF"
3838# Generated by ktest.pl
3839#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003840
3841# PWD is a ktest.pl variable that will result in the process working
3842# directory that ktest.pl is executed in.
3843
3844# THIS_DIR is automatically assigned the PWD of the path that generated
3845# the config file. It is best to use this variable when assigning other
3846# directory paths within this directory. This allows you to easily
3847# move the test cases to other locations or to other machines.
3848#
3849THIS_DIR := $variable{"PWD"}
3850
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003851# Define each test with TEST_START
3852# The config options below it will override the defaults
3853TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003854TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003855
3856DEFAULTS
3857EOF
3858;
3859 close(OUT);
3860}
3861read_config $ktest_config;
3862
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003863if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003864 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003865}
3866
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003867# Append any configs entered in manually to the config file.
3868my @new_configs = keys %entered_configs;
3869if ($#new_configs >= 0) {
3870 print "\nAppending entered in configs to $ktest_config\n";
3871 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3872 foreach my $config (@new_configs) {
3873 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003874 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003875 }
3876}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003877
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003878if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3879 unlink $opt{"LOG_FILE"};
3880}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003881
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003882doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3883
Steven Rostedta57419b2010-11-02 15:13:54 -04003884for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3885
3886 if (!$i) {
3887 doprint "DEFAULT OPTIONS:\n";
3888 } else {
3889 doprint "\nTEST $i OPTIONS";
3890 if (defined($repeat_tests{$i})) {
3891 $repeat = $repeat_tests{$i};
3892 doprint " ITERATE $repeat";
3893 }
3894 doprint "\n";
3895 }
3896
3897 foreach my $option (sort keys %opt) {
3898
3899 if ($option =~ /\[(\d+)\]$/) {
3900 next if ($i != $1);
3901 } else {
3902 next if ($i);
3903 }
3904
3905 doprint "$option = $opt{$option}\n";
3906 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003907}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003908
Steven Rostedt2a625122011-05-20 15:48:59 -04003909sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003910 my ($name, $i) = @_;
3911
3912 my $option = "$name\[$i\]";
3913
3914 if (defined($opt{$option})) {
3915 return $opt{$option};
3916 }
3917
Steven Rostedta57419b2010-11-02 15:13:54 -04003918 foreach my $test (keys %repeat_tests) {
3919 if ($i >= $test &&
3920 $i < $test + $repeat_tests{$test}) {
3921 $option = "$name\[$test\]";
3922 if (defined($opt{$option})) {
3923 return $opt{$option};
3924 }
3925 }
3926 }
3927
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003928 if (defined($opt{$name})) {
3929 return $opt{$name};
3930 }
3931
3932 return undef;
3933}
3934
Steven Rostedt2a625122011-05-20 15:48:59 -04003935sub set_test_option {
3936 my ($name, $i) = @_;
3937
3938 my $option = __set_test_option($name, $i);
3939 return $option if (!defined($option));
3940
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003941 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003942}
3943
Steven Rostedt2545eb62010-11-02 15:01:32 -04003944# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003945for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003946
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003947 # Do not reboot on failing test options
3948 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003949 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003950
Steven Rostedt683a3e62012-05-18 13:34:35 -04003951 $have_version = 0;
3952
Steven Rostedt576f6272010-11-02 14:58:38 -04003953 $iteration = $i;
3954
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003955 undef %force_config;
3956
Steven Rostedta75fece2010-11-02 14:58:27 -04003957 my $makecmd = set_test_option("MAKE_CMD", $i);
3958
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003959 $outputdir = set_test_option("OUTPUT_DIR", $i);
3960 $builddir = set_test_option("BUILD_DIR", $i);
3961
3962 chdir $builddir || die "can't change directory to $builddir";
3963
3964 if (!-d $outputdir) {
3965 mkpath($outputdir) or
3966 die "can't create $outputdir";
3967 }
3968
3969 $make = "$makecmd O=$outputdir";
3970
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003971 # Load all the options into their mapped variable names
3972 foreach my $opt (keys %option_map) {
3973 ${$option_map{$opt}} = set_test_option($opt, $i);
3974 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003975
Steven Rostedt35ce5952011-07-15 21:57:25 -04003976 $start_minconfig_defined = 1;
3977
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003978 # The first test may override the PRE_KTEST option
3979 if (defined($pre_ktest) && $i == 1) {
3980 doprint "\n";
3981 run_command $pre_ktest;
3982 }
3983
3984 # Any test can override the POST_KTEST option
3985 # The last test takes precedence.
3986 if (defined($post_ktest)) {
3987 $final_post_ktest = $post_ktest;
3988 }
3989
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003990 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003991 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003992 $start_minconfig = $minconfig;
3993 }
3994
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003995 if (!-d $tmpdir) {
3996 mkpath($tmpdir) or
3997 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04003998 }
3999
Steven Rostedte48c5292010-11-02 14:35:37 -04004000 $ENV{"SSH_USER"} = $ssh_user;
4001 $ENV{"MACHINE"} = $machine;
4002
Steven Rostedta75fece2010-11-02 14:58:27 -04004003 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304004 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004005 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004006 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004007
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004008 if (!$buildonly) {
4009 $target = "$ssh_user\@$machine";
4010 if ($reboot_type eq "grub") {
4011 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004012 } elsif ($reboot_type eq "grub2") {
4013 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4014 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004015 } elsif ($reboot_type eq "syslinux") {
4016 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004017 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004018 }
4019
4020 my $run_type = $build_type;
4021 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004022 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004023 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004024 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004025 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004026 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004027 } elsif ($test_type eq "make_min_config") {
4028 $run_type = "";
4029 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004030 $run_type = "";
4031 }
4032
Steven Rostedta75fece2010-11-02 14:58:27 -04004033 # mistake in config file?
4034 if (!defined($run_type)) {
4035 $run_type = "ERROR";
4036 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004037
Steven Rostedte0a87422011-09-30 17:50:48 -04004038 my $installme = "";
4039 $installme = " no_install" if ($no_install);
4040
Steven Rostedt2545eb62010-11-02 15:01:32 -04004041 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04004042 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004043
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004044 if (defined($pre_test)) {
4045 run_command $pre_test;
4046 }
4047
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004048 unlink $dmesg;
4049 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304050 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004051
Steven Rostedt250bae82011-07-15 22:05:59 -04004052 if (defined($addconfig)) {
4053 my $min = $minconfig;
4054 if (!defined($minconfig)) {
4055 $min = "";
4056 }
4057 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004058 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004059 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004060 }
4061
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004062 if (defined($checkout)) {
4063 run_command "git checkout $checkout" or
4064 die "failed to checkout $checkout";
4065 }
4066
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004067 $no_reboot = 0;
4068
Steven Rostedt648a1822012-03-21 11:18:27 -04004069 # A test may opt to not reboot the box
4070 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004071 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004072 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004073
Steven Rostedta75fece2010-11-02 14:58:27 -04004074 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004075 bisect $i;
4076 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004077 } elsif ($test_type eq "config_bisect") {
4078 config_bisect $i;
4079 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004080 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004081 patchcheck $i;
4082 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004083 } elsif ($test_type eq "make_min_config") {
4084 make_min_config $i;
4085 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004086 } elsif ($test_type eq "make_warnings_file") {
4087 $no_reboot = 1;
4088 make_warnings_file $i;
4089 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004090 }
4091
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004092 if ($build_type ne "nobuild") {
4093 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004094 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004095 }
4096
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004097 if ($test_type eq "install") {
4098 get_version;
4099 install;
4100 success $i;
4101 next;
4102 }
4103
Steven Rostedta75fece2010-11-02 14:58:27 -04004104 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004105 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004106 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004107
4108 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4109 do_run_test or $failed = 1;
4110 }
4111 end_monitor;
4112 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004113 }
4114
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004115 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004116}
4117
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004118if (defined($final_post_ktest)) {
4119 run_command $final_post_ktest;
4120}
4121
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004122if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004123 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004124} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004125 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004126} elsif (defined($switch_to_good)) {
4127 # still need to get to the good kernel
4128 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004129}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004130
Steven Rostedt648a1822012-03-21 11:18:27 -04004131
Steven Rostedte48c5292010-11-02 14:35:37 -04004132doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4133
Steven Rostedt2545eb62010-11-02 15:01:32 -04004134exit 0;