blob: 82006c2d88c927568d66a6890d65b786ee28326d [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 Rostedtccc513b2012-05-21 17:13:40 -040044 "MIN_CONFIG_TYPE" => "boot",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050045 "SUCCESS_LINE" => "login:",
46 "DETECT_TRIPLE_FAULT" => 1,
47 "NO_INSTALL" => 0,
48 "BOOTED_TIMEOUT" => 1,
49 "DIE_ON_FAILURE" => 1,
50 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
51 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
Steven Rostedt02ad2612012-03-21 08:21:24 -040052 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050053 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
54 "STOP_AFTER_SUCCESS" => 10,
55 "STOP_AFTER_FAILURE" => 60,
56 "STOP_TEST_AFTER" => 600,
Steven Rostedt407b95b2012-07-19 16:05:42 -040057 "MAX_MONITOR_WAIT" => 1800,
Steven Rostedta15ba912012-11-13 14:30:37 -050058 "GRUB_REBOOT" => "grub2-reboot",
Steven Rostedt77869542012-12-11 17:37:41 -050059 "SYSLINUX" => "extlinux",
60 "SYSLINUX_PATH" => "/boot/extlinux",
Steven Rostedt600bbf02011-11-21 20:12:04 -050061
62# required, and we will ask users if they don't have them but we keep the default
63# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050064 "REBOOT_TYPE" => "grub",
65 "LOCALVERSION" => "-test",
66 "SSH_USER" => "root",
67 "BUILD_TARGET" => "arch/x86/boot/bzImage",
68 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050069
70 "LOG_FILE" => undef,
71 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050072);
Steven Rostedt2545eb62010-11-02 15:01:32 -040073
Steven Rostedt8d1491b2010-11-18 15:39:48 -050074my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040075my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040076my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $machine;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -040078my $last_machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040079my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040080my $tmpdir;
81my $builddir;
82my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050083my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040084my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040085my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040086my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040087my $final_post_ktest;
88my $pre_ktest;
89my $post_ktest;
90my $pre_test;
91my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040092my $pre_build;
93my $post_build;
94my $pre_build_die;
95my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040096my $reboot_type;
97my $reboot_script;
98my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040099my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -0400100my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -0500101my $switch_to_good;
102my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -0400103my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -0400104my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -0400105my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -0400106my $powercycle_after_reboot;
107my $poweroff_after_halt;
Steven Rostedt407b95b2012-07-19 16:05:42 -0400108my $max_monitor_wait;
Steven Rostedte48c5292010-11-02 14:35:37 -0400109my $ssh_exec;
110my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400111my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400112my $power_off;
113my $grub_menu;
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -0500114my $last_grub_menu;
Steven Rostedta15ba912012-11-13 14:30:37 -0500115my $grub_file;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400116my $grub_number;
Steven Rostedta15ba912012-11-13 14:30:37 -0500117my $grub_reboot;
Steven Rostedt77869542012-12-11 17:37:41 -0500118my $syslinux;
119my $syslinux_path;
120my $syslinux_label;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400121my $target;
122my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400123my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400124my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400125my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400126my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400127my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400128my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400129my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400130my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400131my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400132my $use_output_minconfig;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500133my $warnings_file;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400134my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500135my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400136my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400137my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500138my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400139my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500140my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500141my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400142my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500143my $bisect_ret_good;
144my $bisect_ret_bad;
145my $bisect_ret_skip;
146my $bisect_ret_abort;
147my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400148my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400149my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400150my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400151my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530152my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400153my $dmesg;
154my $monitor_fp;
155my $monitor_pid;
156my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400157my $sleep_time;
158my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400159my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400160my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400161my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530162my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400163my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400164my $timeout;
165my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400166my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400167my $console;
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900168my $close_console_signal;
Steven Rostedt2b803362011-09-30 18:00:23 -0400169my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400170my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500171my $stop_after_success;
172my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500173my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400174my $build_target;
175my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500176my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400177my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400178my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400179my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400180
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500181my $bisect_good;
182my $bisect_bad;
183my $bisect_type;
184my $bisect_start;
185my $bisect_replay;
186my $bisect_files;
187my $bisect_reverse;
188my $bisect_check;
189
190my $config_bisect;
191my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400192my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500193
194my $patchcheck_type;
195my $patchcheck_start;
196my $patchcheck_end;
197
Steven Rostedt165708b2011-11-26 20:56:52 -0500198# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500199# which would require more options.
200my $buildonly = 1;
201
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500202# tell build not to worry about warnings, even when WARNINGS_FILE is set
203my $warnings_ok = 0;
204
Steven Rostedtdbd37832011-11-23 16:00:48 -0500205# set when creating a new config
206my $newconfig = 0;
207
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500208my %entered_configs;
209my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400210my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400211
212# force_config is the list of configs that we force enabled (or disabled)
213# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400214my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500215
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400216# do not force reboots on config problems
217my $no_reboot = 1;
218
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400219# reboot on success
220my $reboot_success = 0;
221
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500222my %option_map = (
223 "MACHINE" => \$machine,
224 "SSH_USER" => \$ssh_user,
225 "TMP_DIR" => \$tmpdir,
226 "OUTPUT_DIR" => \$outputdir,
227 "BUILD_DIR" => \$builddir,
228 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400229 "PRE_KTEST" => \$pre_ktest,
230 "POST_KTEST" => \$post_ktest,
231 "PRE_TEST" => \$pre_test,
232 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500233 "BUILD_TYPE" => \$build_type,
234 "BUILD_OPTIONS" => \$build_options,
235 "PRE_BUILD" => \$pre_build,
236 "POST_BUILD" => \$post_build,
237 "PRE_BUILD_DIE" => \$pre_build_die,
238 "POST_BUILD_DIE" => \$post_build_die,
239 "POWER_CYCLE" => \$power_cycle,
240 "REBOOT" => \$reboot,
241 "BUILD_NOCLEAN" => \$noclean,
242 "MIN_CONFIG" => \$minconfig,
243 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
244 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400245 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400246 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500247 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500248 "IGNORE_CONFIG" => \$ignore_config,
249 "TEST" => \$run_test,
250 "ADD_CONFIG" => \$addconfig,
251 "REBOOT_TYPE" => \$reboot_type,
252 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500253 "GRUB_FILE" => \$grub_file,
254 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500255 "SYSLINUX" => \$syslinux,
256 "SYSLINUX_PATH" => \$syslinux_path,
257 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400258 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500259 "POST_INSTALL" => \$post_install,
260 "NO_INSTALL" => \$no_install,
261 "REBOOT_SCRIPT" => \$reboot_script,
262 "REBOOT_ON_ERROR" => \$reboot_on_error,
263 "SWITCH_TO_GOOD" => \$switch_to_good,
264 "SWITCH_TO_TEST" => \$switch_to_test,
265 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400266 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500267 "DIE_ON_FAILURE" => \$die_on_failure,
268 "POWER_OFF" => \$power_off,
269 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
270 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400271 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500272 "SLEEP_TIME" => \$sleep_time,
273 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
274 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
275 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500276 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500277 "BISECT_MANUAL" => \$bisect_manual,
278 "BISECT_SKIP" => \$bisect_skip,
279 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
280 "BISECT_RET_GOOD" => \$bisect_ret_good,
281 "BISECT_RET_BAD" => \$bisect_ret_bad,
282 "BISECT_RET_SKIP" => \$bisect_ret_skip,
283 "BISECT_RET_ABORT" => \$bisect_ret_abort,
284 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
285 "STORE_FAILURES" => \$store_failures,
286 "STORE_SUCCESSES" => \$store_successes,
287 "TEST_NAME" => \$test_name,
288 "TIMEOUT" => \$timeout,
289 "BOOTED_TIMEOUT" => \$booted_timeout,
290 "CONSOLE" => \$console,
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +0900291 "CLOSE_CONSOLE_SIGNAL" => \$close_console_signal,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500292 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
293 "SUCCESS_LINE" => \$success_line,
294 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
295 "STOP_AFTER_SUCCESS" => \$stop_after_success,
296 "STOP_AFTER_FAILURE" => \$stop_after_failure,
297 "STOP_TEST_AFTER" => \$stop_test_after,
298 "BUILD_TARGET" => \$build_target,
299 "SSH_EXEC" => \$ssh_exec,
300 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400301 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500302 "CHECKOUT" => \$checkout,
303 "TARGET_IMAGE" => \$target_image,
304 "LOCALVERSION" => \$localversion,
305
306 "BISECT_GOOD" => \$bisect_good,
307 "BISECT_BAD" => \$bisect_bad,
308 "BISECT_TYPE" => \$bisect_type,
309 "BISECT_START" => \$bisect_start,
310 "BISECT_REPLAY" => \$bisect_replay,
311 "BISECT_FILES" => \$bisect_files,
312 "BISECT_REVERSE" => \$bisect_reverse,
313 "BISECT_CHECK" => \$bisect_check,
314
315 "CONFIG_BISECT" => \$config_bisect,
316 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400317 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500318
319 "PATCHCHECK_TYPE" => \$patchcheck_type,
320 "PATCHCHECK_START" => \$patchcheck_start,
321 "PATCHCHECK_END" => \$patchcheck_end,
322);
323
324# Options may be used by other options, record them.
325my %used_options;
326
Steven Rostedt7bf51072011-10-22 09:07:03 -0400327# default variables that can be used
328chomp ($variable{"PWD"} = `pwd`);
329
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500330$config_help{"MACHINE"} = << "EOF"
331 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500332 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500333EOF
334 ;
335$config_help{"SSH_USER"} = << "EOF"
336 The box is expected to have ssh on normal bootup, provide the user
337 (most likely root, since you need privileged operations)
338EOF
339 ;
340$config_help{"BUILD_DIR"} = << "EOF"
341 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500342 You can use \${PWD} that will be the path where ktest.pl is run, or use
343 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500344EOF
345 ;
346$config_help{"OUTPUT_DIR"} = << "EOF"
347 The directory that the objects will be built (full path).
348 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500349 You can use \${PWD} that will be the path where ktest.pl is run, or use
350 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500351EOF
352 ;
353$config_help{"BUILD_TARGET"} = << "EOF"
354 The location of the compiled file to copy to the target.
355 (relative to OUTPUT_DIR)
356EOF
357 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500358$config_help{"BUILD_OPTIONS"} = << "EOF"
359 Options to add to \"make\" when building.
360 i.e. -j20
361EOF
362 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500363$config_help{"TARGET_IMAGE"} = << "EOF"
364 The place to put your image on the test machine.
365EOF
366 ;
367$config_help{"POWER_CYCLE"} = << "EOF"
368 A script or command to reboot the box.
369
370 Here is a digital loggers power switch example
371 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
372
373 Here is an example to reboot a virtual box on the current host
374 with the name "Guest".
375 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
376EOF
377 ;
378$config_help{"CONSOLE"} = << "EOF"
379 The script or command that reads the console
380
381 If you use ttywatch server, something like the following would work.
382CONSOLE = nc -d localhost 3001
383
384 For a virtual machine with guest name "Guest".
385CONSOLE = virsh console Guest
386EOF
387 ;
388$config_help{"LOCALVERSION"} = << "EOF"
389 Required version ending to differentiate the test
390 from other linux builds on the system.
391EOF
392 ;
393$config_help{"REBOOT_TYPE"} = << "EOF"
394 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500395 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500396
397 If you specify grub, it will assume grub version 1
398 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
399 and select that target to reboot to the kernel. If this is not
400 your setup, then specify "script" and have a command or script
401 specified in REBOOT_SCRIPT to boot to the target.
402
403 The entry in /boot/grub/menu.lst must be entered in manually.
404 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500405
406 If you specify grub2, then you also need to specify both \$GRUB_MENU
407 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500408
409 If you specify syslinux, then you may use SYSLINUX to define the syslinux
410 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
411 the syslinux install (defaults to /boot/extlinux). But you have to specify
412 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500413EOF
414 ;
415$config_help{"GRUB_MENU"} = << "EOF"
416 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500417 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500418
419 Note, ktest.pl will not update the grub menu.lst, you need to
420 manually add an option for the test. ktest.pl will search
421 the grub menu.lst for this option to find what kernel to
422 reboot into.
423
424 For example, if in the /boot/grub/menu.lst the test kernel title has:
425 title Test Kernel
426 kernel vmlinuz-test
427 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500428
429 For grub2, a search of \$GRUB_FILE is performed for the lines
430 that begin with "menuentry". It will not detect submenus. The
431 menu must be a non-nested menu. Add the quotes used in the menu
432 to guarantee your selection, as the first menuentry with the content
433 of \$GRUB_MENU that is found will be used.
434EOF
435 ;
436$config_help{"GRUB_FILE"} = << "EOF"
437 If grub2 is used, the full path for the grub.cfg file is placed
438 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500439EOF
440 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500441$config_help{"SYSLINUX_LABEL"} = << "EOF"
442 If syslinux is used, the label that boots the target kernel must
443 be specified with SYSLINUX_LABEL.
444EOF
445 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500446$config_help{"REBOOT_SCRIPT"} = << "EOF"
447 A script to reboot the target into the test kernel
448 (Only mandatory if REBOOT_TYPE = script)
449EOF
450 ;
451
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500452sub _logit {
453 if (defined($opt{"LOG_FILE"})) {
454 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
455 print OUT @_;
456 close(OUT);
457 }
458}
459
460sub logit {
461 if (defined($opt{"LOG_FILE"})) {
462 _logit @_;
463 } else {
464 print @_;
465 }
466}
467
468sub doprint {
469 print @_;
470 _logit @_;
471}
472
Steven Rostedtdad98752011-11-22 20:48:57 -0500473sub read_prompt {
474 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400475
476 my $ans;
477
478 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500479 if ($cancel) {
480 print "$prompt [y/n/C] ";
481 } else {
482 print "$prompt [Y/n] ";
483 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400484 $ans = <STDIN>;
485 chomp $ans;
486 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500487 if ($cancel) {
488 $ans = "c";
489 } else {
490 $ans = "y";
491 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400492 }
493 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500494 if ($cancel) {
495 last if ($ans =~ /^c$/i);
496 print "Please answer either 'y', 'n' or 'c'.\n";
497 } else {
498 print "Please answer either 'y' or 'n'.\n";
499 }
500 }
501 if ($ans =~ /^c/i) {
502 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400503 }
504 if ($ans !~ /^y$/i) {
505 return 0;
506 }
507 return 1;
508}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500509
Steven Rostedtdad98752011-11-22 20:48:57 -0500510sub read_yn {
511 my ($prompt) = @_;
512
513 return read_prompt 0, $prompt;
514}
515
516sub read_ync {
517 my ($prompt) = @_;
518
519 return read_prompt 1, $prompt;
520}
521
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500522sub get_ktest_config {
523 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400524 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500525
526 return if (defined($opt{$config}));
527
528 if (defined($config_help{$config})) {
529 print "\n";
530 print $config_help{$config};
531 }
532
533 for (;;) {
534 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500535 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500536 print "\[$default{$config}\] ";
537 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400538 $ans = <STDIN>;
539 $ans =~ s/^\s*(.*\S)\s*$/$1/;
540 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500541 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400542 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500543 } else {
544 print "Your answer can not be blank\n";
545 next;
546 }
547 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500548 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500549 last;
550 }
551}
552
553sub get_ktest_configs {
554 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500555 get_ktest_config("BUILD_DIR");
556 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500557
Steven Rostedtdbd37832011-11-23 16:00:48 -0500558 if ($newconfig) {
559 get_ktest_config("BUILD_OPTIONS");
560 }
561
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500562 # options required for other than just building a kernel
563 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500564 get_ktest_config("POWER_CYCLE");
565 get_ktest_config("CONSOLE");
566 }
567
568 # options required for install and more
569 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500570 get_ktest_config("SSH_USER");
571 get_ktest_config("BUILD_TARGET");
572 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500573 }
574
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500575 get_ktest_config("LOCALVERSION");
576
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500577 return if ($buildonly);
578
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500579 my $rtype = $opt{"REBOOT_TYPE"};
580
581 if (!defined($rtype)) {
582 if (!defined($opt{"GRUB_MENU"})) {
583 get_ktest_config("REBOOT_TYPE");
584 $rtype = $entered_configs{"REBOOT_TYPE"};
585 } else {
586 $rtype = "grub";
587 }
588 }
589
590 if ($rtype eq "grub") {
591 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500592 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500593
594 if ($rtype eq "grub2") {
595 get_ktest_config("GRUB_MENU");
596 get_ktest_config("GRUB_FILE");
597 }
Steven Rostedt77869542012-12-11 17:37:41 -0500598
599 if ($rtype eq "syslinux") {
600 get_ktest_config("SYSLINUX_LABEL");
601 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500602}
603
Steven Rostedt77d942c2011-05-20 13:36:58 -0400604sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400605 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400606 my $retval = "";
607
608 # We want to check for '\', and it is just easier
609 # to check the previous characet of '$' and not need
610 # to worry if '$' is the first character. By adding
611 # a space to $value, we can just check [^\\]\$ and
612 # it will still work.
613 $value = " $value";
614
615 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
616 my $begin = $1;
617 my $var = $2;
618 my $end = $3;
619 # append beginning of value to retval
620 $retval = "$retval$begin";
621 if (defined($variable{$var})) {
622 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400623 } elsif (defined($remove_undef) && $remove_undef) {
624 # for if statements, any variable that is not defined,
625 # we simple convert to 0
626 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400627 } else {
628 # put back the origin piece.
629 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500630 # This could be an option that is used later, save
631 # it so we don't warn if this option is not one of
632 # ktests options.
633 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400634 }
635 $value = $end;
636 }
637 $retval = "$retval$value";
638
639 # remove the space added in the beginning
640 $retval =~ s/ //;
641
642 return "$retval"
643}
644
Steven Rostedta57419b2010-11-02 15:13:54 -0400645sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400646 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400647
Steven Rostedtcad96662011-12-22 11:32:52 -0500648 my $prvalue = process_variables($rvalue);
649
650 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500651 # Note if a test is something other than build, then we
652 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500653 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500654 # for bisect, we need to check BISECT_TYPE
655 if ($prvalue ne "bisect") {
656 $buildonly = 0;
657 }
658 } else {
659 # install still limits some manditory options.
660 $buildonly = 2;
661 }
662 }
663
664 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
665 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500666 $buildonly = 0;
667 } else {
668 # install still limits some manditory options.
669 $buildonly = 2;
670 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500671 }
672
Steven Rostedta57419b2010-11-02 15:13:54 -0400673 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400674 if (!$override || defined(${$overrides}{$lvalue})) {
675 my $extra = "";
676 if ($override) {
677 $extra = "In the same override section!\n";
678 }
679 die "$name: $.: Option $lvalue defined more than once!\n$extra";
680 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500681 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400682 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500683 if ($rvalue =~ /^\s*$/) {
684 delete $opt{$lvalue};
685 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500686 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500687 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400688}
689
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500690sub set_eval {
691 my ($lvalue, $rvalue, $name) = @_;
692
693 my $prvalue = process_variables($rvalue);
694 my $arr;
695
696 if (defined($evals{$lvalue})) {
697 $arr = $evals{$lvalue};
698 } else {
699 $arr = [];
700 $evals{$lvalue} = $arr;
701 }
702
703 push @{$arr}, $rvalue;
704}
705
Steven Rostedt77d942c2011-05-20 13:36:58 -0400706sub set_variable {
707 my ($lvalue, $rvalue) = @_;
708
709 if ($rvalue =~ /^\s*$/) {
710 delete $variable{$lvalue};
711 } else {
712 $rvalue = process_variables($rvalue);
713 $variable{$lvalue} = $rvalue;
714 }
715}
716
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400717sub process_compare {
718 my ($lval, $cmp, $rval) = @_;
719
720 # remove whitespace
721
722 $lval =~ s/^\s*//;
723 $lval =~ s/\s*$//;
724
725 $rval =~ s/^\s*//;
726 $rval =~ s/\s*$//;
727
728 if ($cmp eq "==") {
729 return $lval eq $rval;
730 } elsif ($cmp eq "!=") {
731 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400732 } elsif ($cmp eq "=~") {
733 return $lval =~ m/$rval/;
734 } elsif ($cmp eq "!~") {
735 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400736 }
737
738 my $statement = "$lval $cmp $rval";
739 my $ret = eval $statement;
740
741 # $@ stores error of eval
742 if ($@) {
743 return -1;
744 }
745
746 return $ret;
747}
748
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400749sub value_defined {
750 my ($val) = @_;
751
752 return defined($variable{$2}) ||
753 defined($opt{$2});
754}
755
Steven Rostedt8d735212011-10-17 11:36:44 -0400756my $d = 0;
757sub process_expression {
758 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400759
Steven Rostedt8d735212011-10-17 11:36:44 -0400760 my $c = $d++;
761
762 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
763 my $express = $1;
764
765 if (process_expression($name, $express)) {
766 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
767 } else {
768 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
769 }
770 }
771
772 $d--;
773 my $OR = "\\|\\|";
774 my $AND = "\\&\\&";
775
776 while ($val =~ s/^(.*?)($OR|$AND)//) {
777 my $express = $1;
778 my $op = $2;
779
780 if (process_expression($name, $express)) {
781 if ($op eq "||") {
782 return 1;
783 }
784 } else {
785 if ($op eq "&&") {
786 return 0;
787 }
788 }
789 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400790
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400791 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400792 my $ret = process_compare($1, $2, $3);
793 if ($ret < 0) {
794 die "$name: $.: Unable to process comparison\n";
795 }
796 return $ret;
797 }
798
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400799 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
800 if (defined $1) {
801 return !value_defined($2);
802 } else {
803 return value_defined($2);
804 }
805 }
806
Steven Rostedt45d73a52011-09-30 19:44:53 -0400807 if ($val =~ /^\s*0\s*$/) {
808 return 0;
809 } elsif ($val =~ /^\s*\d+\s*$/) {
810 return 1;
811 }
812
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400813 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400814}
815
816sub process_if {
817 my ($name, $value) = @_;
818
819 # Convert variables and replace undefined ones with 0
820 my $val = process_variables($value, 1);
821 my $ret = process_expression $name, $val;
822
823 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400824}
825
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400826sub __read_config {
827 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400828
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400829 my $in;
830 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400831
Steven Rostedta57419b2010-11-02 15:13:54 -0400832 my $name = $config;
833 $name =~ s,.*/(.*),$1,;
834
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400835 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400836 my $default = 1;
837 my $repeat = 1;
838 my $num_tests_set = 0;
839 my $skip = 0;
840 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400841 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400842 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400843 my $if = 0;
844 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400845 my $override = 0;
846
847 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400848
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400849 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400850
851 # ignore blank lines and comments
852 next if (/^\s*$/ || /\s*\#/);
853
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400854 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400855
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400856 my $type = $1;
857 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400858 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400859
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400860 my $old_test_num;
861 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400862 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400863
864 if ($type eq "TEST_START") {
865
866 if ($num_tests_set) {
867 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
868 }
869
870 $old_test_num = $test_num;
871 $old_repeat = $repeat;
872
873 $test_num += $repeat;
874 $default = 0;
875 $repeat = 1;
876 } else {
877 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400878 }
879
Steven Rostedta9f84422011-10-17 11:06:29 -0400880 # If SKIP is anywhere in the line, the command will be skipped
881 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400882 $skip = 1;
883 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400884 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400885 $skip = 0;
886 }
887
Steven Rostedta9f84422011-10-17 11:06:29 -0400888 if ($rest =~ s/\sELSE\b//) {
889 if (!$if) {
890 die "$name: $.: ELSE found with out matching IF section\n$_";
891 }
892 $if = 0;
893
894 if ($if_set) {
895 $skip = 1;
896 } else {
897 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400898 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400899 }
900
Steven Rostedta9f84422011-10-17 11:06:29 -0400901 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400902 if (process_if($name, $1)) {
903 $if_set = 1;
904 } else {
905 $skip = 1;
906 }
907 $if = 1;
908 } else {
909 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400910 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400911 }
912
Steven Rostedta9f84422011-10-17 11:06:29 -0400913 if (!$skip) {
914 if ($type eq "TEST_START") {
915 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
916 $repeat = $1;
917 $repeat_tests{"$test_num"} = $repeat;
918 }
919 } elsif ($rest =~ s/\sOVERRIDE\b//) {
920 # DEFAULT only
921 $override = 1;
922 # Clear previous overrides
923 %overrides = ();
924 }
925 }
926
927 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400928 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400929 }
930
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400931 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400932 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400933 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400934 }
935
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400936 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400937 if (!$if) {
938 die "$name: $.: ELSE found with out matching IF section\n$_";
939 }
940 $rest = $1;
941 if ($if_set) {
942 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400943 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400944 } else {
945 $skip = 0;
946
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400947 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400948 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400949 if (process_if($name, $1)) {
950 $if_set = 1;
951 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400952 $skip = 1;
953 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400954 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400955 } else {
956 $if = 0;
957 }
958 }
959
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400960 if ($rest !~ /^\s*$/) {
961 die "$name: $.: Gargbage found after DEFAULTS\n$_";
962 }
963
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400964 } elsif (/^\s*INCLUDE\s+(\S+)/) {
965
966 next if ($skip);
967
968 if (!$default) {
969 die "$name: $.: INCLUDE can only be done in default sections\n$_";
970 }
971
972 my $file = process_variables($1);
973
974 if ($file !~ m,^/,) {
975 # check the path of the config file first
976 if ($config =~ m,(.*)/,) {
977 if (-f "$1/$file") {
978 $file = "$1/$file";
979 }
980 }
981 }
982
983 if ( ! -r $file ) {
984 die "$name: $.: Can't read file $file\n$_";
985 }
986
987 if (__read_config($file, \$test_num)) {
988 $test_case = 1;
989 }
990
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -0500991 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=~\s*(.*?)\s*$/) {
992
993 next if ($skip);
994
995 my $lvalue = $1;
996 my $rvalue = $2;
997
998 if ($default || $lvalue =~ /\[\d+\]$/) {
999 set_eval($lvalue, $rvalue, $name);
1000 } else {
1001 my $val = "$lvalue\[$test_num\]";
1002 set_eval($val, $rvalue, $name);
1003 }
1004
Steven Rostedta57419b2010-11-02 15:13:54 -04001005 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
1006
1007 next if ($skip);
1008
Steven Rostedt2545eb62010-11-02 15:01:32 -04001009 my $lvalue = $1;
1010 my $rvalue = $2;
1011
Steven Rostedta57419b2010-11-02 15:13:54 -04001012 if (!$default &&
1013 ($lvalue eq "NUM_TESTS" ||
1014 $lvalue eq "LOG_FILE" ||
1015 $lvalue eq "CLEAR_LOG")) {
1016 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001017 }
Steven Rostedta57419b2010-11-02 15:13:54 -04001018
1019 if ($lvalue eq "NUM_TESTS") {
1020 if ($test_num) {
1021 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
1022 }
1023 if (!$default) {
1024 die "$name: $.: NUM_TESTS must be set in default section\n";
1025 }
1026 $num_tests_set = 1;
1027 }
1028
1029 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001030 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001031 } else {
1032 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -04001033 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -04001034
1035 if ($repeat > 1) {
1036 $repeats{$val} = $repeat;
1037 }
1038 }
Steven Rostedt77d942c2011-05-20 13:36:58 -04001039 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
1040 next if ($skip);
1041
1042 my $lvalue = $1;
1043 my $rvalue = $2;
1044
1045 # process config variables.
1046 # Config variables are only active while reading the
1047 # config and can be defined anywhere. They also ignore
1048 # TEST_START and DEFAULTS, but are skipped if they are in
1049 # on of these sections that have SKIP defined.
1050 # The save variable can be
1051 # defined multiple times and the new one simply overrides
1052 # the prevous one.
1053 set_variable($lvalue, $rvalue);
1054
Steven Rostedta57419b2010-11-02 15:13:54 -04001055 } else {
1056 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001057 }
1058 }
1059
Steven Rostedta57419b2010-11-02 15:13:54 -04001060 if ($test_num) {
1061 $test_num += $repeat - 1;
1062 $opt{"NUM_TESTS"} = $test_num;
1063 }
1064
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001065 close($in);
1066
1067 $$current_test_num = $test_num;
1068
1069 return $test_case;
1070}
1071
Steven Rostedtc4261d02011-11-23 13:41:18 -05001072sub get_test_case {
1073 print "What test case would you like to run?\n";
1074 print " (build, install or boot)\n";
1075 print " Other tests are available but require editing the config file\n";
1076 my $ans = <STDIN>;
1077 chomp $ans;
1078 $default{"TEST_TYPE"} = $ans;
1079}
1080
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001081sub read_config {
1082 my ($config) = @_;
1083
1084 my $test_case;
1085 my $test_num = 0;
1086
1087 $test_case = __read_config $config, \$test_num;
1088
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001089 # make sure we have all mandatory configs
1090 get_ktest_configs;
1091
Steven Rostedt0df213c2011-06-14 20:51:37 -04001092 # was a test specified?
1093 if (!$test_case) {
1094 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001095 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001096 }
1097
Steven Rostedta75fece2010-11-02 14:58:27 -04001098 # set any defaults
1099
1100 foreach my $default (keys %default) {
1101 if (!defined($opt{$default})) {
1102 $opt{$default} = $default{$default};
1103 }
1104 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001105
1106 if ($opt{"IGNORE_UNUSED"} == 1) {
1107 return;
1108 }
1109
1110 my %not_used;
1111
1112 # check if there are any stragglers (typos?)
1113 foreach my $option (keys %opt) {
1114 my $op = $option;
1115 # remove per test labels.
1116 $op =~ s/\[.*\]//;
1117 if (!exists($option_map{$op}) &&
1118 !exists($default{$op}) &&
1119 !exists($used_options{$op})) {
1120 $not_used{$op} = 1;
1121 }
1122 }
1123
1124 if (%not_used) {
1125 my $s = "s are";
1126 $s = " is" if (keys %not_used == 1);
1127 print "The following option$s not used; could be a typo:\n";
1128 foreach my $option (keys %not_used) {
1129 print "$option\n";
1130 }
1131 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1132 if (!read_yn "Do you want to continue?") {
1133 exit -1;
1134 }
1135 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001136}
1137
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001138sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001139 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001140
1141 # Add space to evaluate the character before $
1142 $option = " $option";
1143 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301144 my $repeated = 0;
1145 my $parent = 0;
1146
1147 foreach my $test (keys %repeat_tests) {
1148 if ($i >= $test &&
1149 $i < $test + $repeat_tests{$test}) {
1150
1151 $repeated = 1;
1152 $parent = $test;
1153 last;
1154 }
1155 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001156
1157 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1158 my $start = $1;
1159 my $var = $2;
1160 my $end = $3;
1161
1162 # Append beginning of line
1163 $retval = "$retval$start";
1164
1165 # If the iteration option OPT[$i] exists, then use that.
1166 # otherwise see if the default OPT (without [$i]) exists.
1167
1168 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301169 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001170
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001171 # If a variable contains itself, use the default var
1172 if (($var eq $name) && defined($opt{$var})) {
1173 $o = $opt{$var};
1174 $retval = "$retval$o";
1175 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001176 $o = $opt{$o};
1177 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301178 } elsif ($repeated && defined($opt{$parento})) {
1179 $o = $opt{$parento};
1180 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001181 } elsif (defined($opt{$var})) {
1182 $o = $opt{$var};
1183 $retval = "$retval$o";
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05001184 } elsif ($var eq "KERNEL_VERSION" && defined($make)) {
1185 # special option KERNEL_VERSION uses kernel version
1186 get_version();
1187 $retval = "$retval$version";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001188 } else {
1189 $retval = "$retval\$\{$var\}";
1190 }
1191
1192 $option = $end;
1193 }
1194
1195 $retval = "$retval$option";
1196
1197 $retval =~ s/^ //;
1198
1199 return $retval;
1200}
1201
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001202sub process_evals {
1203 my ($name, $option, $i) = @_;
1204
1205 my $option_name = "$name\[$i\]";
1206 my $ev;
1207
1208 my $old_option = $option;
1209
1210 if (defined($evals{$option_name})) {
1211 $ev = $evals{$option_name};
1212 } elsif (defined($evals{$name})) {
1213 $ev = $evals{$name};
1214 } else {
1215 return $option;
1216 }
1217
1218 for my $e (@{$ev}) {
1219 eval "\$option =~ $e";
1220 }
1221
1222 if ($option ne $old_option) {
1223 doprint("$name changed from '$old_option' to '$option'\n");
1224 }
1225
1226 return $option;
1227}
1228
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001229sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001230 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001231
1232 my $prev = "";
1233
1234 # Since an option can evaluate to another option,
1235 # keep iterating until we do not evaluate any more
1236 # options.
1237 my $r = 0;
1238 while ($prev ne $option) {
1239 # Check for recursive evaluations.
1240 # 100 deep should be more than enough.
1241 if ($r++ > 100) {
1242 die "Over 100 evaluations accurred with $option\n" .
1243 "Check for recursive variables\n";
1244 }
1245 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001246 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001247 }
1248
Steven Rostedt (Red Hat)c75d22d2013-12-11 21:16:59 -05001249 $option = process_evals($name, $option, $i);
1250
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001251 return $option;
1252}
1253
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001254sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001255sub start_monitor;
1256sub end_monitor;
1257sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001258
1259sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001260 my ($time) = @_;
1261
Steven Rostedta4968722012-12-11 14:59:05 -05001262 # Make sure everything has been written to disk
1263 run_ssh("sync");
1264
Steven Rostedt2b803362011-09-30 18:00:23 -04001265 if (defined($time)) {
1266 start_monitor;
1267 # flush out current monitor
1268 # May contain the reboot success line
1269 wait_for_monitor 1;
1270 }
1271
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001272 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001273 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001274 if (defined($powercycle_after_reboot)) {
1275 sleep $powercycle_after_reboot;
1276 run_command "$power_cycle";
1277 }
1278 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001279 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001280 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001281 }
Andrew Jones2728be42011-08-12 15:32:05 +02001282
1283 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001284
1285 # We only want to get to the new kernel, don't fail
1286 # if we stumble over a call trace.
1287 my $save_ignore_errors = $ignore_errors;
1288 $ignore_errors = 1;
1289
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001290 # Look for the good kernel to boot
1291 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001292 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001293 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001294 run_command "$power_cycle";
1295 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001296
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001297 $ignore_errors = $save_ignore_errors;
1298
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001299 # Still need to wait for the reboot to finish
1300 wait_for_monitor($time, $reboot_success_line);
1301
Andrew Jones2728be42011-08-12 15:32:05 +02001302 end_monitor;
1303 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001304}
1305
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001306sub reboot_to_good {
1307 my ($time) = @_;
1308
1309 if (defined($switch_to_good)) {
1310 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001311 }
1312
1313 reboot $time;
1314}
1315
Steven Rostedt576f6272010-11-02 14:58:38 -04001316sub do_not_reboot {
1317 my $i = $iteration;
1318
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001319 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001320 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1321 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1322}
1323
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001324sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001325 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001326
Steven Rostedt576f6272010-11-02 14:58:38 -04001327 my $i = $iteration;
1328
1329 if ($reboot_on_error && !do_not_reboot) {
1330
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001331 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001332 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001333
Steven Rostedta75fece2010-11-02 14:58:27 -04001334 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001335 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001336 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001337 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001338
Steven Rostedtf80802c2011-03-07 13:18:47 -05001339 if (defined($opt{"LOG_FILE"})) {
1340 print " See $opt{LOG_FILE} for more info.\n";
1341 }
1342
Steven Rostedt576f6272010-11-02 14:58:38 -04001343 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001344}
1345
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001346sub open_console {
1347 my ($fp) = @_;
1348
1349 my $flags;
1350
Steven Rostedta75fece2010-11-02 14:58:27 -04001351 my $pid = open($fp, "$console|") or
1352 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001353
1354 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001355 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001356 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001357 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001358
1359 return $pid;
1360}
1361
1362sub close_console {
1363 my ($fp, $pid) = @_;
1364
1365 doprint "kill child process $pid\n";
Satoru Takeuchi5a5d8e42013-12-01 07:57:58 +09001366 kill $close_console_signal, $pid;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001367
1368 print "closing!\n";
1369 close($fp);
1370}
1371
1372sub start_monitor {
1373 if ($monitor_cnt++) {
1374 return;
1375 }
1376 $monitor_fp = \*MONFD;
1377 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001378
1379 return;
1380
1381 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001382}
1383
1384sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001385 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001386 if (--$monitor_cnt) {
1387 return;
1388 }
1389 close_console($monitor_fp, $monitor_pid);
1390}
1391
1392sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001393 my ($time, $stop) = @_;
1394 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001395 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001396 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001397 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001398 my $skip_call_trace = 0;
1399 my $bug = 0;
1400 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001401 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001402
Steven Rostedta75fece2010-11-02 14:58:27 -04001403 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001404
1405 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001406 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001407 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001408 last if (!defined($line));
1409 print "$line";
1410 $full_line .= $line;
1411
1412 if (defined($stop) && $full_line =~ /$stop/) {
1413 doprint "wait for monitor detected $stop\n";
1414 $booted = 1;
1415 }
1416
Steven Rostedt8a80c722012-07-19 16:08:33 -04001417 if ($full_line =~ /\[ backtrace testing \]/) {
1418 $skip_call_trace = 1;
1419 }
1420
1421 if ($full_line =~ /call trace:/i) {
1422 if (!$bug && !$skip_call_trace) {
1423 if ($ignore_errors) {
1424 $bug_ignored = 1;
1425 } else {
1426 $bug = 1;
1427 }
1428 }
1429 }
1430
1431 if ($full_line =~ /\[ end of backtrace testing \]/) {
1432 $skip_call_trace = 0;
1433 }
1434
1435 if ($full_line =~ /Kernel panic -/) {
1436 $bug = 1;
1437 }
1438
Steven Rostedt2b803362011-09-30 18:00:23 -04001439 if ($line =~ /\n/) {
1440 $full_line = "";
1441 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001442 $now = time;
1443 if ($now - $start_time >= $max_monitor_wait) {
1444 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1445 return 1;
1446 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001447 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001448 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001449 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001450}
1451
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301452sub save_logs {
1453 my ($result, $basedir) = @_;
1454 my @t = localtime;
1455 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1456 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1457
1458 my $type = $build_type;
1459 if ($type =~ /useconfig/) {
1460 $type = "useconfig";
1461 }
1462
1463 my $dir = "$machine-$test_type-$type-$result-$date";
1464
1465 $dir = "$basedir/$dir";
1466
1467 if (!-d $dir) {
1468 mkpath($dir) or
1469 die "can't create $dir";
1470 }
1471
1472 my %files = (
1473 "config" => $output_config,
1474 "buildlog" => $buildlog,
1475 "dmesg" => $dmesg,
1476 "testlog" => $testlog,
1477 );
1478
1479 while (my ($name, $source) = each(%files)) {
1480 if (-f "$source") {
1481 cp "$source", "$dir/$name" or
1482 die "failed to copy $source";
1483 }
1484 }
1485
1486 doprint "*** Saved info to $dir ***\n";
1487}
1488
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001489sub fail {
1490
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001491 if (defined($post_test)) {
1492 run_command $post_test;
1493 }
1494
Steven Rostedta75fece2010-11-02 14:58:27 -04001495 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001496 dodie @_;
1497 }
1498
Steven Rostedta75fece2010-11-02 14:58:27 -04001499 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001500
Steven Rostedt576f6272010-11-02 14:58:38 -04001501 my $i = $iteration;
1502
Steven Rostedta75fece2010-11-02 14:58:27 -04001503 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001504 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001505 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001506 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001507 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001508
Steven Rostedt9064af52011-06-13 10:38:48 -04001509 my $name = "";
1510
1511 if (defined($test_name)) {
1512 $name = " ($test_name)";
1513 }
1514
Steven Rostedt576f6272010-11-02 14:58:38 -04001515 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1516 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001517 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001518 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1519 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001520
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301521 if (defined($store_failures)) {
1522 save_logs "fail", $store_failures;
1523 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001524
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001525 return 1;
1526}
1527
Steven Rostedt2545eb62010-11-02 15:01:32 -04001528sub run_command {
1529 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001530 my $dolog = 0;
1531 my $dord = 0;
1532 my $pid;
1533
Steven Rostedte48c5292010-11-02 14:35:37 -04001534 $command =~ s/\$SSH_USER/$ssh_user/g;
1535 $command =~ s/\$MACHINE/$machine/g;
1536
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001537 doprint("$command ... ");
1538
1539 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001540 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001541
1542 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001543 open(LOG, ">>$opt{LOG_FILE}") or
1544 dodie "failed to write to log";
1545 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001546 }
1547
1548 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001549 open (RD, ">$redirect") or
1550 dodie "failed to write to redirect $redirect";
1551 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001552 }
1553
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001554 while (<CMD>) {
1555 print LOG if ($dolog);
1556 print RD if ($dord);
1557 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001558
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001559 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001560 my $failed = $?;
1561
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001562 close(CMD);
1563 close(LOG) if ($dolog);
1564 close(RD) if ($dord);
1565
Steven Rostedt2545eb62010-11-02 15:01:32 -04001566 if ($failed) {
1567 doprint "FAILED!\n";
1568 } else {
1569 doprint "SUCCESS\n";
1570 }
1571
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001572 return !$failed;
1573}
1574
Steven Rostedte48c5292010-11-02 14:35:37 -04001575sub run_ssh {
1576 my ($cmd) = @_;
1577 my $cp_exec = $ssh_exec;
1578
1579 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1580 return run_command "$cp_exec";
1581}
1582
1583sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001584 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001585
1586 $cp_scp =~ s/\$SRC_FILE/$src/g;
1587 $cp_scp =~ s/\$DST_FILE/$dst/g;
1588
1589 return run_command "$cp_scp";
1590}
1591
Steven Rostedt02ad2612012-03-21 08:21:24 -04001592sub run_scp_install {
1593 my ($src, $dst) = @_;
1594
1595 my $cp_scp = $scp_to_target_install;
1596
1597 return run_scp($src, $dst, $cp_scp);
1598}
1599
1600sub run_scp_mod {
1601 my ($src, $dst) = @_;
1602
1603 my $cp_scp = $scp_to_target;
1604
1605 return run_scp($src, $dst, $cp_scp);
1606}
1607
Steven Rostedta15ba912012-11-13 14:30:37 -05001608sub get_grub2_index {
1609
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001610 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001611 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1612 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001613
1614 doprint "Find grub2 menu ... ";
1615 $grub_number = -1;
1616
1617 my $ssh_grub = $ssh_exec;
1618 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1619
1620 open(IN, "$ssh_grub |")
1621 or die "unable to get $grub_file";
1622
1623 my $found = 0;
1624
1625 while (<IN>) {
1626 if (/^menuentry.*$grub_menu/) {
1627 $grub_number++;
1628 $found = 1;
1629 last;
1630 } elsif (/^menuentry\s/) {
1631 $grub_number++;
1632 }
1633 }
1634 close(IN);
1635
1636 die "Could not find '$grub_menu' in $grub_file on $machine"
1637 if (!$found);
1638 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001639 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001640 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001641}
1642
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001643sub get_grub_index {
1644
Steven Rostedta15ba912012-11-13 14:30:37 -05001645 if ($reboot_type eq "grub2") {
1646 get_grub2_index;
1647 return;
1648 }
1649
Steven Rostedta75fece2010-11-02 14:58:27 -04001650 if ($reboot_type ne "grub") {
1651 return;
1652 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001653 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001654 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1655 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001656
1657 doprint "Find grub menu ... ";
1658 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001659
1660 my $ssh_grub = $ssh_exec;
1661 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1662
1663 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001664 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001665
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001666 my $found = 0;
1667
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001668 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001669 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001670 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001671 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001672 last;
1673 } elsif (/^\s*title\s/) {
1674 $grub_number++;
1675 }
1676 }
1677 close(IN);
1678
Steven Rostedta75fece2010-11-02 14:58:27 -04001679 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001680 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001681 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001682 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001683 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001684}
1685
Steven Rostedt2545eb62010-11-02 15:01:32 -04001686sub wait_for_input
1687{
1688 my ($fp, $time) = @_;
1689 my $rin;
1690 my $ready;
1691 my $line;
1692 my $ch;
1693
1694 if (!defined($time)) {
1695 $time = $timeout;
1696 }
1697
1698 $rin = '';
1699 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001700 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001701
1702 $line = "";
1703
1704 # try to read one char at a time
1705 while (sysread $fp, $ch, 1) {
1706 $line .= $ch;
1707 last if ($ch eq "\n");
1708 }
1709
1710 if (!length($line)) {
1711 return undef;
1712 }
1713
1714 return $line;
1715}
1716
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001717sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001718 if (defined($switch_to_test)) {
1719 run_command $switch_to_test;
1720 }
1721
Steven Rostedta75fece2010-11-02 14:58:27 -04001722 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001723 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001724 } elsif ($reboot_type eq "grub2") {
1725 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001726 } elsif ($reboot_type eq "syslinux") {
1727 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001728 } elsif (defined $reboot_script) {
1729 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001730 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001731 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001732}
1733
Steven Rostedta57419b2010-11-02 15:13:54 -04001734sub get_sha1 {
1735 my ($commit) = @_;
1736
1737 doprint "git rev-list --max-count=1 $commit ... ";
1738 my $sha1 = `git rev-list --max-count=1 $commit`;
1739 my $ret = $?;
1740
1741 logit $sha1;
1742
1743 if ($ret) {
1744 doprint "FAILED\n";
1745 dodie "Failed to get git $commit";
1746 }
1747
1748 print "SUCCESS\n";
1749
1750 chomp $sha1;
1751
1752 return $sha1;
1753}
1754
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001755sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001756 my $booted = 0;
1757 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001758 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001759 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001760 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001761
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001762 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001763
1764 my $line;
1765 my $full_line = "";
1766
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001767 open(DMESG, "> $dmesg") or
1768 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001769
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001770 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001771
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001772 my $success_start;
1773 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001774 my $monitor_start = time;
1775 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001776 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001777
Steven Rostedt2d01b262011-03-08 09:47:54 -05001778 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001779
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001780 if ($bug && defined($stop_after_failure) &&
1781 $stop_after_failure >= 0) {
1782 my $time = $stop_after_failure - (time - $failure_start);
1783 $line = wait_for_input($monitor_fp, $time);
1784 if (!defined($line)) {
1785 doprint "bug timed out after $booted_timeout seconds\n";
1786 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1787 last;
1788 }
1789 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001790 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001791 if (!defined($line)) {
1792 my $s = $booted_timeout == 1 ? "" : "s";
1793 doprint "Successful boot found: break after $booted_timeout second$s\n";
1794 last;
1795 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001796 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001797 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001798 if (!defined($line)) {
1799 my $s = $timeout == 1 ? "" : "s";
1800 doprint "Timed out after $timeout second$s\n";
1801 last;
1802 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001803 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001804
Steven Rostedt2545eb62010-11-02 15:01:32 -04001805 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001806 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001807
1808 # we are not guaranteed to get a full line
1809 $full_line .= $line;
1810
Steven Rostedta75fece2010-11-02 14:58:27 -04001811 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001812 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001813 $success_start = time;
1814 }
1815
1816 if ($booted && defined($stop_after_success) &&
1817 $stop_after_success >= 0) {
1818 my $now = time;
1819 if ($now - $success_start >= $stop_after_success) {
1820 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1821 last;
1822 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001823 }
1824
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001825 if ($full_line =~ /\[ backtrace testing \]/) {
1826 $skip_call_trace = 1;
1827 }
1828
Steven Rostedt2545eb62010-11-02 15:01:32 -04001829 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001830 if (!$bug && !$skip_call_trace) {
1831 if ($ignore_errors) {
1832 $bug_ignored = 1;
1833 } else {
1834 $bug = 1;
1835 $failure_start = time;
1836 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001837 }
1838 }
1839
1840 if ($bug && defined($stop_after_failure) &&
1841 $stop_after_failure >= 0) {
1842 my $now = time;
1843 if ($now - $failure_start >= $stop_after_failure) {
1844 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1845 last;
1846 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001847 }
1848
1849 if ($full_line =~ /\[ end of backtrace testing \]/) {
1850 $skip_call_trace = 0;
1851 }
1852
1853 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001854 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001855 $bug = 1;
1856 }
1857
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001858 # Detect triple faults by testing the banner
1859 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1860 if ($1 eq $version) {
1861 $version_found = 1;
1862 } elsif ($version_found && $detect_triplefault) {
1863 # We already booted into the kernel we are testing,
1864 # but now we booted into another kernel?
1865 # Consider this a triple fault.
1866 doprint "Aleady booted in Linux kernel $version, but now\n";
1867 doprint "we booted into Linux kernel $1.\n";
1868 doprint "Assuming that this is a triple fault.\n";
1869 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1870 last;
1871 }
1872 }
1873
Steven Rostedt2545eb62010-11-02 15:01:32 -04001874 if ($line =~ /\n/) {
1875 $full_line = "";
1876 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001877
1878 if ($stop_test_after > 0 && !$booted && !$bug) {
1879 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001880 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001881 $done = 1;
1882 }
1883 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001884 }
1885
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001886 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001887
Steven Rostedt2545eb62010-11-02 15:01:32 -04001888 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001889 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001890 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001891 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001892
Steven Rostedta75fece2010-11-02 14:58:27 -04001893 if (!$booted) {
1894 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001895 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001896 }
1897
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001898 if ($bug_ignored) {
1899 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1900 }
1901
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001902 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001903}
1904
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001905sub eval_kernel_version {
1906 my ($option) = @_;
1907
1908 $option =~ s/\$KERNEL_VERSION/$version/g;
1909
1910 return $option;
1911}
1912
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001913sub do_post_install {
1914
1915 return if (!defined($post_install));
1916
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001917 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001918 run_command "$cp_post_install" or
1919 dodie "Failed to run post install";
1920}
1921
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001922# Sometimes the reboot fails, and will hang. We try to ssh to the box
1923# and if we fail, we force another reboot, that should powercycle it.
1924sub test_booted {
1925 if (!run_ssh "echo testing connection") {
1926 reboot $sleep_time;
1927 }
1928}
1929
Steven Rostedt2545eb62010-11-02 15:01:32 -04001930sub install {
1931
Steven Rostedte0a87422011-09-30 17:50:48 -04001932 return if ($no_install);
1933
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001934 if (defined($pre_install)) {
1935 my $cp_pre_install = eval_kernel_version $pre_install;
1936 run_command "$cp_pre_install" or
1937 dodie "Failed to run pre install";
1938 }
1939
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001940 my $cp_target = eval_kernel_version $target_image;
1941
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001942 test_booted;
1943
Steven Rostedt02ad2612012-03-21 08:21:24 -04001944 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001945 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001946
1947 my $install_mods = 0;
1948
1949 # should we process modules?
1950 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001951 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001952 while (<IN>) {
1953 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001954 if (defined($1)) {
1955 $install_mods = 1;
1956 last;
1957 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001958 }
1959 }
1960 close(IN);
1961
1962 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001963 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001964 doprint "No modules needed\n";
1965 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001966 }
1967
Steven Rostedt627977d2012-03-21 08:16:15 -04001968 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001969 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001970
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001971 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001972 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001973
Steven Rostedte48c5292010-11-02 14:35:37 -04001974 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001975 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001976
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001977 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001978 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001979 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001980
Steven Rostedt02ad2612012-03-21 08:21:24 -04001981 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001982 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001983
Steven Rostedta75fece2010-11-02 14:58:27 -04001984 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001985
Steven Rostedte7b13442011-06-14 20:44:36 -04001986 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001987 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001988
Steven Rostedte48c5292010-11-02 14:35:37 -04001989 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001990
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001991 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001992}
1993
Steven Rostedtddf607e2011-06-14 20:49:13 -04001994sub get_version {
1995 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001996 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001997 doprint "$make kernelrelease ... ";
1998 $version = `$make kernelrelease | tail -1`;
1999 chomp($version);
2000 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04002001 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04002002}
2003
2004sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002005 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002006
2007 # Install bisects, don't need console
2008 if (defined $console) {
2009 start_monitor;
2010 wait_for_monitor 5;
2011 end_monitor;
2012 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04002013
Steven Rostedtddf607e2011-06-14 20:49:13 -04002014 get_grub_index;
2015 get_version;
2016 install;
2017
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05002018 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04002019 return monitor;
2020}
2021
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002022my $check_build_re = ".*:.*(warning|error|Error):.*";
2023my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
2024
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002025sub process_warning_line {
2026 my ($line) = @_;
2027
2028 chomp $line;
2029
2030 # for distcc heterogeneous systems, some compilers
2031 # do things differently causing warning lines
2032 # to be slightly different. This makes an attempt
2033 # to fixe those issues.
2034
2035 # chop off the index into the line
2036 # using distcc, some compilers give different indexes
2037 # depending on white space
2038 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
2039
2040 # Some compilers use UTF-8 extended for quotes and some don't.
2041 $line =~ s/$utf8_quote/'/g;
2042
2043 return $line;
2044}
2045
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002046# Read buildlog and check against warnings file for any
2047# new warnings.
2048#
2049# Returns 1 if OK
2050# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002051sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002052 return 1 if (!defined $warnings_file);
2053
2054 my %warnings_list;
2055
2056 # Failed builds should not reboot the target
2057 my $save_no_reboot = $no_reboot;
2058 $no_reboot = 1;
2059
2060 if (-f $warnings_file) {
2061 open(IN, $warnings_file) or
2062 dodie "Error opening $warnings_file";
2063
2064 while (<IN>) {
2065 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002066 my $warning = process_warning_line $_;
2067
2068 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002069 }
2070 }
2071 close(IN);
2072 }
2073
2074 # If warnings file didn't exist, and WARNINGS_FILE exist,
2075 # then we fail on any warning!
2076
2077 open(IN, $buildlog) or dodie "Can't open $buildlog";
2078 while (<IN>) {
2079 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002080 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002081
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002082 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002083 fail "New warning found (not in $warnings_file)\n$_\n";
2084 $no_reboot = $save_no_reboot;
2085 return 0;
2086 }
2087 }
2088 }
2089 $no_reboot = $save_no_reboot;
2090 close(IN);
2091}
2092
2093sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002094 my ($patch) = @_;
2095
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002096 my @files = `git show $patch | diffstat -l`;
2097
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002098 foreach my $file (@files) {
2099 chomp $file;
2100 }
2101
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002102 open(IN, "git show $patch |") or
2103 dodie "failed to show $patch";
2104 while (<IN>) {
2105 if (m,^--- a/(.*),) {
2106 chomp $1;
2107 $files[$#files] = $1;
2108 }
2109 }
2110 close(IN);
2111
2112 open(IN, $buildlog) or dodie "Can't open $buildlog";
2113 while (<IN>) {
2114 if (/^\s*(.*?):.*(warning|error)/) {
2115 my $err = $1;
2116 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002117 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002118 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002119 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002120 }
2121 }
2122 }
2123 }
2124 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002125
2126 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002127}
2128
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002129sub apply_min_config {
2130 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002131
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002132 # Read the config file and remove anything that
2133 # is in the force_config hash (from minconfig and others)
2134 # then add the force config back.
2135
2136 doprint "Applying minimum configurations into $output_config.new\n";
2137
2138 open (OUT, ">$outconfig") or
2139 dodie "Can't create $outconfig";
2140
2141 if (-f $output_config) {
2142 open (IN, $output_config) or
2143 dodie "Failed to open $output_config";
2144 while (<IN>) {
2145 if (/^(# )?(CONFIG_[^\s=]*)/) {
2146 next if (defined($force_config{$2}));
2147 }
2148 print OUT;
2149 }
2150 close IN;
2151 }
2152 foreach my $config (keys %force_config) {
2153 print OUT "$force_config{$config}\n";
2154 }
2155 close OUT;
2156
2157 run_command "mv $outconfig $output_config";
2158}
2159
2160sub make_oldconfig {
2161
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002162 my @force_list = keys %force_config;
2163
2164 if ($#force_list >= 0) {
2165 apply_min_config;
2166 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002167
Adam Leefb16d892012-09-01 01:05:17 +08002168 if (!run_command "$make olddefconfig") {
2169 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002170 # try oldnoconfig
2171 doprint "olddefconfig failed, trying make oldnoconfig\n";
2172 if (!run_command "$make oldnoconfig") {
2173 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2174 # try a yes '' | oldconfig
2175 run_command "yes '' | $make oldconfig" or
2176 dodie "failed make config oldconfig";
2177 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002178 }
2179}
2180
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002181# read a config file and use this to force new configs.
2182sub load_force_config {
2183 my ($config) = @_;
2184
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002185 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002186 open(IN, $config) or
2187 dodie "failed to read $config";
2188 while (<IN>) {
2189 chomp;
2190 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2191 $force_config{$1} = $_;
2192 } elsif (/^# (CONFIG_\S*) is not set/) {
2193 $force_config{$1} = $_;
2194 }
2195 }
2196 close IN;
2197}
2198
Steven Rostedt2545eb62010-11-02 15:01:32 -04002199sub build {
2200 my ($type) = @_;
2201
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002202 unlink $buildlog;
2203
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002204 # Failed builds should not reboot the target
2205 my $save_no_reboot = $no_reboot;
2206 $no_reboot = 1;
2207
Steven Rostedt683a3e62012-05-18 13:34:35 -04002208 # Calculate a new version from here.
2209 $have_version = 0;
2210
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002211 if (defined($pre_build)) {
2212 my $ret = run_command $pre_build;
2213 if (!$ret && defined($pre_build_die) &&
2214 $pre_build_die) {
2215 dodie "failed to pre_build\n";
2216 }
2217 }
2218
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002219 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002220 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002221 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002222
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002223 $type = "oldconfig";
2224 }
2225
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002226 # old config can ask questions
2227 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002228 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002229
2230 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002231 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002232
Andrew Jones13488232011-08-12 15:32:04 +02002233 if (!$noclean) {
2234 run_command "mv $output_config $outputdir/config_temp" or
2235 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002236
Andrew Jones13488232011-08-12 15:32:04 +02002237 run_command "$make mrproper" or dodie "make mrproper";
2238
2239 run_command "mv $outputdir/config_temp $output_config" or
2240 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002241 }
2242
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002243 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002244 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002245 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002246 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002247 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002248
2249 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002250 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2251 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002252 close(OUT);
2253
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002254 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002255 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002256 }
2257
Adam Leefb16d892012-09-01 01:05:17 +08002258 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002259 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002260 dodie "failed make config";
2261 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002262 # Run old config regardless, to enforce min configurations
2263 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002264
Steven Rostedta75fece2010-11-02 14:58:27 -04002265 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002266 my $build_ret = run_command "$make $build_options";
2267 undef $redirect;
2268
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
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302360 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002361 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302362 undef $redirect;
2363
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002364 exit $failed;
2365}
2366
2367my $child_done;
2368
2369sub child_finished {
2370 $child_done = 1;
2371}
2372
2373sub do_run_test {
2374 my $child_pid;
2375 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002376 my $line;
2377 my $full_line;
2378 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002379 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002380
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002381 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002382
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002383 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002384
2385 $child_done = 0;
2386
2387 $SIG{CHLD} = qw(child_finished);
2388
2389 $child_pid = fork;
2390
2391 child_run_test if (!$child_pid);
2392
2393 $full_line = "";
2394
2395 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002396 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002397 if (defined($line)) {
2398
2399 # we are not guaranteed to get a full line
2400 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002401 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002402
2403 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002404 if ($ignore_errors) {
2405 $bug_ignored = 1;
2406 } else {
2407 $bug = 1;
2408 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002409 }
2410
2411 if ($full_line =~ /Kernel panic -/) {
2412 $bug = 1;
2413 }
2414
2415 if ($line =~ /\n/) {
2416 $full_line = "";
2417 }
2418 }
2419 } while (!$child_done && !$bug);
2420
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002421 if (!$bug && $bug_ignored) {
2422 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2423 }
2424
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002425 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002426 my $failure_start = time;
2427 my $now;
2428 do {
2429 $line = wait_for_input($monitor_fp, 1);
2430 if (defined($line)) {
2431 doprint $line;
2432 }
2433 $now = time;
2434 if ($now - $failure_start >= $stop_after_failure) {
2435 last;
2436 }
2437 } while (defined($line));
2438
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002439 doprint "Detected kernel crash!\n";
2440 # kill the child with extreme prejudice
2441 kill 9, $child_pid;
2442 }
2443
2444 waitpid $child_pid, 0;
2445 $child_exit = $?;
2446
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002447 if (!$bug && $in_bisect) {
2448 if (defined($bisect_ret_good)) {
2449 if ($child_exit == $bisect_ret_good) {
2450 return 1;
2451 }
2452 }
2453 if (defined($bisect_ret_skip)) {
2454 if ($child_exit == $bisect_ret_skip) {
2455 return -1;
2456 }
2457 }
2458 if (defined($bisect_ret_abort)) {
2459 if ($child_exit == $bisect_ret_abort) {
2460 fail "test abort" and return -2;
2461 }
2462 }
2463 if (defined($bisect_ret_bad)) {
2464 if ($child_exit == $bisect_ret_skip) {
2465 return 0;
2466 }
2467 }
2468 if (defined($bisect_ret_default)) {
2469 if ($bisect_ret_default eq "good") {
2470 return 1;
2471 } elsif ($bisect_ret_default eq "bad") {
2472 return 0;
2473 } elsif ($bisect_ret_default eq "skip") {
2474 return -1;
2475 } elsif ($bisect_ret_default eq "abort") {
2476 return -2;
2477 } else {
2478 fail "unknown default action: $bisect_ret_default"
2479 and return -2;
2480 }
2481 }
2482 }
2483
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002484 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002485 return 0 if $in_bisect;
2486 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002487 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002488 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002489}
2490
Steven Rostedta75fece2010-11-02 14:58:27 -04002491sub run_git_bisect {
2492 my ($command) = @_;
2493
2494 doprint "$command ... ";
2495
2496 my $output = `$command 2>&1`;
2497 my $ret = $?;
2498
2499 logit $output;
2500
2501 if ($ret) {
2502 doprint "FAILED\n";
2503 dodie "Failed to git bisect";
2504 }
2505
2506 doprint "SUCCESS\n";
2507 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2508 doprint "$1 [$2]\n";
2509 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002510 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002511 doprint "Found bad commit... $1\n";
2512 return 0;
2513 } else {
2514 # we already logged it, just print it now.
2515 print $output;
2516 }
2517
2518 return 1;
2519}
2520
Steven Rostedtc23dca72011-03-08 09:26:31 -05002521sub bisect_reboot {
2522 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002523 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002524}
2525
2526# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002527sub run_bisect_test {
2528 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002529
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002530 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002531 my $result;
2532 my $output;
2533 my $ret;
2534
Steven Rostedt0a05c762010-11-08 11:14:10 -05002535 $in_bisect = 1;
2536
2537 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002538
2539 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002540 if ($failed && $bisect_skip) {
2541 $in_bisect = 0;
2542 return -1;
2543 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002544 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002545
2546 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002547 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002548
2549 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002550 if ($failed && $bisect_skip) {
2551 end_monitor;
2552 bisect_reboot;
2553 $in_bisect = 0;
2554 return -1;
2555 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002556 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002557
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002558 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002559 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002560 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002561 }
2562
2563 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002564 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002565 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002566 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002567 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002568
2569 # reboot the box to a kernel we can ssh to
2570 if ($type ne "build") {
2571 bisect_reboot;
2572 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002573 $in_bisect = 0;
2574
2575 return $result;
2576}
2577
2578sub run_bisect {
2579 my ($type) = @_;
2580 my $buildtype = "oldconfig";
2581
2582 # We should have a minconfig to use?
2583 if (defined($minconfig)) {
2584 $buildtype = "useconfig:$minconfig";
2585 }
2586
2587 my $ret = run_bisect_test $type, $buildtype;
2588
Steven Rostedtc960bb92011-03-08 09:22:39 -05002589 if ($bisect_manual) {
2590 $ret = answer_bisect;
2591 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002592
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002593 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002594 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002595 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002596 }
2597
Steven Rostedtc23dca72011-03-08 09:26:31 -05002598 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002599 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002600 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002601 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002602 } elsif ($bisect_skip) {
2603 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2604 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002605 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002606}
2607
Steven Rostedtdad98752011-11-22 20:48:57 -05002608sub update_bisect_replay {
2609 my $tmp_log = "$tmpdir/ktest_bisect_log";
2610 run_command "git bisect log > $tmp_log" or
2611 die "can't create bisect log";
2612 return $tmp_log;
2613}
2614
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002615sub bisect {
2616 my ($i) = @_;
2617
2618 my $result;
2619
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002620 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2621 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2622 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002623
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002624 my $good = $bisect_good;
2625 my $bad = $bisect_bad;
2626 my $type = $bisect_type;
2627 my $start = $bisect_start;
2628 my $replay = $bisect_replay;
2629 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002630
2631 if (defined($start_files)) {
2632 $start_files = " -- " . $start_files;
2633 } else {
2634 $start_files = "";
2635 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002636
Steven Rostedta57419b2010-11-02 15:13:54 -04002637 # convert to true sha1's
2638 $good = get_sha1($good);
2639 $bad = get_sha1($bad);
2640
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002641 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002642 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2643 $reverse_bisect = 1;
2644 } else {
2645 $reverse_bisect = 0;
2646 }
2647
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002648 # Can't have a test without having a test to run
2649 if ($type eq "test" && !defined($run_test)) {
2650 $type = "boot";
2651 }
2652
Steven Rostedtdad98752011-11-22 20:48:57 -05002653 # Check if a bisect was running
2654 my $bisect_start_file = "$builddir/.git/BISECT_START";
2655
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002656 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002657 my $do_check = defined($check) && $check ne "0";
2658
2659 if ( -f $bisect_start_file ) {
2660 print "Bisect in progress found\n";
2661 if ($do_check) {
2662 print " If you say yes, then no checks of good or bad will be done\n";
2663 }
2664 if (defined($replay)) {
2665 print "** BISECT_REPLAY is defined in config file **";
2666 print " Ignore config option and perform new git bisect log?\n";
2667 if (read_ync " (yes, no, or cancel) ") {
2668 $replay = update_bisect_replay;
2669 $do_check = 0;
2670 }
2671 } elsif (read_yn "read git log and continue?") {
2672 $replay = update_bisect_replay;
2673 $do_check = 0;
2674 }
2675 }
2676
2677 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002678
2679 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002680 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002681
2682 if ($check ne "good") {
2683 doprint "TESTING BISECT BAD [$bad]\n";
2684 run_command "git checkout $bad" or
2685 die "Failed to checkout $bad";
2686
2687 $result = run_bisect $type;
2688
2689 if ($result ne "bad") {
2690 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2691 }
2692 }
2693
2694 if ($check ne "bad") {
2695 doprint "TESTING BISECT GOOD [$good]\n";
2696 run_command "git checkout $good" or
2697 die "Failed to checkout $good";
2698
2699 $result = run_bisect $type;
2700
2701 if ($result ne "good") {
2702 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2703 }
2704 }
2705
2706 # checkout where we started
2707 run_command "git checkout $head" or
2708 die "Failed to checkout $head";
2709 }
2710
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002711 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002712 dodie "could not start bisect";
2713
2714 run_command "git bisect good $good" or
2715 dodie "could not set bisect good to $good";
2716
2717 run_git_bisect "git bisect bad $bad" or
2718 dodie "could not set bisect bad to $bad";
2719
2720 if (defined($replay)) {
2721 run_command "git bisect replay $replay" or
2722 dodie "failed to run replay";
2723 }
2724
2725 if (defined($start)) {
2726 run_command "git checkout $start" or
2727 dodie "failed to checkout $start";
2728 }
2729
2730 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002731 do {
2732 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002733 $test = run_git_bisect "git bisect $result";
2734 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002735
2736 run_command "git bisect log" or
2737 dodie "could not capture git bisect log";
2738
2739 run_command "git bisect reset" or
2740 dodie "could not reset git bisect";
2741
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002742 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002743
Steven Rostedt0a05c762010-11-08 11:14:10 -05002744 success $i;
2745}
2746
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002747# config_ignore holds the configs that were set (or unset) for
2748# a good config and we will ignore these configs for the rest
2749# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002750my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002751
2752# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002753my %config_set;
2754
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002755# config_off holds the set of configs that the bad config had disabled.
2756# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002757# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002758my %config_off;
2759
2760# config_off_tmp holds a set of configs to turn off for now
2761my @config_off_tmp;
2762
2763# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002764my %config_list;
2765my %null_config;
2766
2767my %dependency;
2768
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002769sub assign_configs {
2770 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002771
2772 open (IN, $config)
2773 or dodie "Failed to read $config";
2774
2775 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002776 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002777 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002778 }
2779 }
2780
2781 close(IN);
2782}
2783
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002784sub process_config_ignore {
2785 my ($config) = @_;
2786
2787 assign_configs \%config_ignore, $config;
2788}
2789
Steven Rostedt0a05c762010-11-08 11:14:10 -05002790sub read_current_config {
2791 my ($config_ref) = @_;
2792
2793 %{$config_ref} = ();
2794 undef %{$config_ref};
2795
2796 my @key = keys %{$config_ref};
2797 if ($#key >= 0) {
2798 print "did not delete!\n";
2799 exit;
2800 }
2801 open (IN, "$output_config");
2802
2803 while (<IN>) {
2804 if (/^(CONFIG\S+)=(.*)/) {
2805 ${$config_ref}{$1} = $2;
2806 }
2807 }
2808 close(IN);
2809}
2810
2811sub get_dependencies {
2812 my ($config) = @_;
2813
2814 my $arr = $dependency{$config};
2815 if (!defined($arr)) {
2816 return ();
2817 }
2818
2819 my @deps = @{$arr};
2820
2821 foreach my $dep (@{$arr}) {
2822 print "ADD DEP $dep\n";
2823 @deps = (@deps, get_dependencies $dep);
2824 }
2825
2826 return @deps;
2827}
2828
2829sub create_config {
2830 my @configs = @_;
2831
2832 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2833
2834 foreach my $config (@configs) {
2835 print OUT "$config_set{$config}\n";
2836 my @deps = get_dependencies $config;
2837 foreach my $dep (@deps) {
2838 print OUT "$config_set{$dep}\n";
2839 }
2840 }
2841
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002842 # turn off configs to keep off
2843 foreach my $config (keys %config_off) {
2844 print OUT "# $config is not set\n";
2845 }
2846
2847 # turn off configs that should be off for now
2848 foreach my $config (@config_off_tmp) {
2849 print OUT "# $config is not set\n";
2850 }
2851
Steven Rostedt0a05c762010-11-08 11:14:10 -05002852 foreach my $config (keys %config_ignore) {
2853 print OUT "$config_ignore{$config}\n";
2854 }
2855 close(OUT);
2856
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002857 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002858}
2859
2860sub compare_configs {
2861 my (%a, %b) = @_;
2862
2863 foreach my $item (keys %a) {
2864 if (!defined($b{$item})) {
2865 print "diff $item\n";
2866 return 1;
2867 }
2868 delete $b{$item};
2869 }
2870
2871 my @keys = keys %b;
2872 if ($#keys) {
2873 print "diff2 $keys[0]\n";
2874 }
2875 return -1 if ($#keys >= 0);
2876
2877 return 0;
2878}
2879
2880sub run_config_bisect_test {
2881 my ($type) = @_;
2882
2883 return run_bisect_test $type, "oldconfig";
2884}
2885
2886sub process_passed {
2887 my (%configs) = @_;
2888
2889 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2890 # Passed! All these configs are part of a good compile.
2891 # Add them to the min options.
2892 foreach my $config (keys %configs) {
2893 if (defined($config_list{$config})) {
2894 doprint " removing $config\n";
2895 $config_ignore{$config} = $config_list{$config};
2896 delete $config_list{$config};
2897 }
2898 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002899 doprint "config copied to $outputdir/config_good\n";
2900 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002901}
2902
2903sub process_failed {
2904 my ($config) = @_;
2905
2906 doprint "\n\n***************************************\n";
2907 doprint "Found bad config: $config\n";
2908 doprint "***************************************\n\n";
2909}
2910
2911sub run_config_bisect {
2912
2913 my @start_list = keys %config_list;
2914
2915 if ($#start_list < 0) {
2916 doprint "No more configs to test!!!\n";
2917 return -1;
2918 }
2919
2920 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002921 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002922 my $ret;
2923 my %current_config;
2924
2925 my $count = $#start_list + 1;
2926 doprint " $count configs to test\n";
2927
2928 my $half = int($#start_list / 2);
2929
2930 do {
2931 my @tophalf = @start_list[0 .. $half];
2932
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002933 # keep the bottom half off
2934 if ($half < $#start_list) {
2935 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2936 } else {
2937 @config_off_tmp = ();
2938 }
2939
Steven Rostedt0a05c762010-11-08 11:14:10 -05002940 create_config @tophalf;
2941 read_current_config \%current_config;
2942
2943 $count = $#tophalf + 1;
2944 doprint "Testing $count configs\n";
2945 my $found = 0;
2946 # make sure we test something
2947 foreach my $config (@tophalf) {
2948 if (defined($current_config{$config})) {
2949 logit " $config\n";
2950 $found = 1;
2951 }
2952 }
2953 if (!$found) {
2954 # try the other half
2955 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002956
2957 # keep the top half off
2958 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002959 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002960
Steven Rostedt0a05c762010-11-08 11:14:10 -05002961 create_config @tophalf;
2962 read_current_config \%current_config;
2963 foreach my $config (@tophalf) {
2964 if (defined($current_config{$config})) {
2965 logit " $config\n";
2966 $found = 1;
2967 }
2968 }
2969 if (!$found) {
2970 doprint "Failed: Can't make new config with current configs\n";
2971 foreach my $config (@start_list) {
2972 doprint " CONFIG: $config\n";
2973 }
2974 return -1;
2975 }
2976 $count = $#tophalf + 1;
2977 doprint "Testing $count configs\n";
2978 }
2979
2980 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002981 if ($bisect_manual) {
2982 $ret = answer_bisect;
2983 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002984 if ($ret) {
2985 process_passed %current_config;
2986 return 0;
2987 }
2988
2989 doprint "This config had a failure.\n";
2990 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002991 doprint "config copied to $outputdir/config_bad\n";
2992 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002993
2994 # A config exists in this group that was bad.
2995 foreach my $config (keys %config_list) {
2996 if (!defined($current_config{$config})) {
2997 doprint " removing $config\n";
2998 delete $config_list{$config};
2999 }
3000 }
3001
3002 @start_list = @tophalf;
3003
3004 if ($#start_list == 0) {
3005 process_failed $start_list[0];
3006 return 1;
3007 }
3008
3009 # remove half the configs we are looking at and see if
3010 # they are good.
3011 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04003012 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05003013
Steven Rostedtc960bb92011-03-08 09:22:39 -05003014 # we found a single config, try it again unless we are running manually
3015
3016 if ($bisect_manual) {
3017 process_failed $start_list[0];
3018 return 1;
3019 }
3020
Steven Rostedt0a05c762010-11-08 11:14:10 -05003021 my @tophalf = @start_list[0 .. 0];
3022
3023 $ret = run_config_bisect_test $type;
3024 if ($ret) {
3025 process_passed %current_config;
3026 return 0;
3027 }
3028
3029 process_failed $start_list[0];
3030 return 1;
3031}
3032
3033sub config_bisect {
3034 my ($i) = @_;
3035
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003036 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003037
3038 my $tmpconfig = "$tmpdir/use_config";
3039
Steven Rostedt30f75da2011-06-13 10:35:35 -04003040 if (defined($config_bisect_good)) {
3041 process_config_ignore $config_bisect_good;
3042 }
3043
Steven Rostedt0a05c762010-11-08 11:14:10 -05003044 # Make the file with the bad config and the min config
3045 if (defined($minconfig)) {
3046 # read the min config for things to ignore
3047 run_command "cp $minconfig $tmpconfig" or
3048 dodie "failed to copy $minconfig to $tmpconfig";
3049 } else {
3050 unlink $tmpconfig;
3051 }
3052
Steven Rostedt0a05c762010-11-08 11:14:10 -05003053 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003054 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05003055 process_config_ignore $tmpconfig;
3056 }
3057
3058 # now process the start config
3059 run_command "cp $start_config $output_config" or
3060 dodie "failed to copy $start_config to $output_config";
3061
3062 # read directly what we want to check
3063 my %config_check;
3064 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09003065 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05003066
3067 while (<IN>) {
3068 if (/^((CONFIG\S*)=.*)/) {
3069 $config_check{$2} = $1;
3070 }
3071 }
3072 close(IN);
3073
Steven Rostedt250bae82011-07-15 22:05:59 -04003074 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003075 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003076
3077 # check to see what we lost (or gained)
3078 open (IN, $output_config)
3079 or dodie "Failed to read $start_config";
3080
3081 my %removed_configs;
3082 my %added_configs;
3083
3084 while (<IN>) {
3085 if (/^((CONFIG\S*)=.*)/) {
3086 # save off all options
3087 $config_set{$2} = $1;
3088 if (defined($config_check{$2})) {
3089 if (defined($config_ignore{$2})) {
3090 $removed_configs{$2} = $1;
3091 } else {
3092 $config_list{$2} = $1;
3093 }
3094 } elsif (!defined($config_ignore{$2})) {
3095 $added_configs{$2} = $1;
3096 $config_list{$2} = $1;
3097 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003098 } elsif (/^# ((CONFIG\S*).*)/) {
3099 # Keep these configs disabled
3100 $config_set{$2} = $1;
3101 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003102 }
3103 }
3104 close(IN);
3105
3106 my @confs = keys %removed_configs;
3107 if ($#confs >= 0) {
3108 doprint "Configs overridden by default configs and removed from check:\n";
3109 foreach my $config (@confs) {
3110 doprint " $config\n";
3111 }
3112 }
3113 @confs = keys %added_configs;
3114 if ($#confs >= 0) {
3115 doprint "Configs appearing in make oldconfig and added:\n";
3116 foreach my $config (@confs) {
3117 doprint " $config\n";
3118 }
3119 }
3120
3121 my %config_test;
3122 my $once = 0;
3123
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003124 @config_off_tmp = ();
3125
Steven Rostedt0a05c762010-11-08 11:14:10 -05003126 # Sometimes kconfig does weird things. We must make sure
3127 # that the config we autocreate has everything we need
3128 # to test, otherwise we may miss testing configs, or
3129 # may not be able to create a new config.
3130 # Here we create a config with everything set.
3131 create_config (keys %config_list);
3132 read_current_config \%config_test;
3133 foreach my $config (keys %config_list) {
3134 if (!defined($config_test{$config})) {
3135 if (!$once) {
3136 $once = 1;
3137 doprint "Configs not produced by kconfig (will not be checked):\n";
3138 }
3139 doprint " $config\n";
3140 delete $config_list{$config};
3141 }
3142 }
3143 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04003144
3145 if (defined($config_bisect_check) && $config_bisect_check) {
3146 doprint " Checking to make sure bad config with min config fails\n";
3147 create_config keys %config_list;
3148 $ret = run_config_bisect_test $config_bisect_type;
3149 if ($ret) {
3150 doprint " FAILED! Bad config with min config boots fine\n";
3151 return -1;
3152 }
3153 doprint " Bad config with min config fails as expected\n";
3154 }
3155
Steven Rostedt0a05c762010-11-08 11:14:10 -05003156 do {
3157 $ret = run_config_bisect;
3158 } while (!$ret);
3159
3160 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003161
3162 success $i;
3163}
3164
Steven Rostedt27d934b2011-05-20 09:18:18 -04003165sub patchcheck_reboot {
3166 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003167 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003168}
3169
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003170sub patchcheck {
3171 my ($i) = @_;
3172
3173 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003174 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003175 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003176 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003177
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003178 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003179
3180 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003181 if (defined($patchcheck_end)) {
3182 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003183 }
3184
Steven Rostedta57419b2010-11-02 15:13:54 -04003185 # Get the true sha1's since we can use things like HEAD~3
3186 $start = get_sha1($start);
3187 $end = get_sha1($end);
3188
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003189 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003190
3191 # Can't have a test without having a test to run
3192 if ($type eq "test" && !defined($run_test)) {
3193 $type = "boot";
3194 }
3195
3196 open (IN, "git log --pretty=oneline $end|") or
3197 dodie "could not get git list";
3198
3199 my @list;
3200
3201 while (<IN>) {
3202 chomp;
3203 $list[$#list+1] = $_;
3204 last if (/^$start/);
3205 }
3206 close(IN);
3207
3208 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003209 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003210 }
3211
3212 # go backwards in the list
3213 @list = reverse @list;
3214
3215 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003216 my %ignored_warnings;
3217
3218 if (defined($ignore_warnings)) {
3219 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3220 $ignored_warnings{$sha1} = 1;
3221 }
3222 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003223
3224 $in_patchcheck = 1;
3225 foreach my $item (@list) {
3226 my $sha1 = $item;
3227 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3228
3229 doprint "\nProcessing commit $item\n\n";
3230
3231 run_command "git checkout $sha1" or
3232 die "Failed to checkout $sha1";
3233
3234 # only clean on the first and last patch
3235 if ($item eq $list[0] ||
3236 $item eq $list[$#list]) {
3237 $noclean = $save_clean;
3238 } else {
3239 $noclean = 1;
3240 }
3241
3242 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003243 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003244 } else {
3245 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003246 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003247 }
3248
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003249 # No need to do per patch checking if warnings file exists
3250 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3251 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003252 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003253
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003254 check_buildlog or return 0;
3255
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003256 next if ($type eq "build");
3257
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003258 my $failed = 0;
3259
Steven Rostedtddf607e2011-06-14 20:49:13 -04003260 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003261
3262 if (!$failed && $type ne "boot"){
3263 do_run_test or $failed = 1;
3264 }
3265 end_monitor;
3266 return 0 if ($failed);
3267
Steven Rostedt27d934b2011-05-20 09:18:18 -04003268 patchcheck_reboot;
3269
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003270 }
3271 $in_patchcheck = 0;
3272 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003273
3274 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003275}
3276
Steven Rostedtb9066f62011-07-15 21:25:24 -04003277my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003278my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003279my $iflevel = 0;
3280my @ifdeps;
3281
3282# prevent recursion
3283my %read_kconfigs;
3284
Steven Rostedtac6974c2011-10-04 09:40:17 -04003285sub add_dep {
3286 # $config depends on $dep
3287 my ($config, $dep) = @_;
3288
3289 if (defined($depends{$config})) {
3290 $depends{$config} .= " " . $dep;
3291 } else {
3292 $depends{$config} = $dep;
3293 }
3294
3295 # record the number of configs depending on $dep
3296 if (defined $depcount{$dep}) {
3297 $depcount{$dep}++;
3298 } else {
3299 $depcount{$dep} = 1;
3300 }
3301}
3302
Steven Rostedtb9066f62011-07-15 21:25:24 -04003303# taken from streamline_config.pl
3304sub read_kconfig {
3305 my ($kconfig) = @_;
3306
3307 my $state = "NONE";
3308 my $config;
3309 my @kconfigs;
3310
3311 my $cont = 0;
3312 my $line;
3313
3314
3315 if (! -f $kconfig) {
3316 doprint "file $kconfig does not exist, skipping\n";
3317 return;
3318 }
3319
3320 open(KIN, "$kconfig")
3321 or die "Can't open $kconfig";
3322 while (<KIN>) {
3323 chomp;
3324
3325 # Make sure that lines ending with \ continue
3326 if ($cont) {
3327 $_ = $line . " " . $_;
3328 }
3329
3330 if (s/\\$//) {
3331 $cont = 1;
3332 $line = $_;
3333 next;
3334 }
3335
3336 $cont = 0;
3337
3338 # collect any Kconfig sources
3339 if (/^source\s*"(.*)"/) {
3340 $kconfigs[$#kconfigs+1] = $1;
3341 }
3342
3343 # configs found
3344 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3345 $state = "NEW";
3346 $config = $2;
3347
3348 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003349 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003350 }
3351
3352 # collect the depends for the config
3353 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3354
Steven Rostedtac6974c2011-10-04 09:40:17 -04003355 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003356
3357 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003358 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3359
3360 # selected by depends on config
3361 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003362
3363 # Check for if statements
3364 } elsif (/^if\s+(.*\S)\s*$/) {
3365 my $deps = $1;
3366 # remove beginning and ending non text
3367 $deps =~ s/^[^a-zA-Z0-9_]*//;
3368 $deps =~ s/[^a-zA-Z0-9_]*$//;
3369
3370 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3371
3372 $ifdeps[$iflevel++] = join ':', @deps;
3373
3374 } elsif (/^endif/) {
3375
3376 $iflevel-- if ($iflevel);
3377
3378 # stop on "help"
3379 } elsif (/^\s*help\s*$/) {
3380 $state = "NONE";
3381 }
3382 }
3383 close(KIN);
3384
3385 # read in any configs that were found.
3386 foreach $kconfig (@kconfigs) {
3387 if (!defined($read_kconfigs{$kconfig})) {
3388 $read_kconfigs{$kconfig} = 1;
3389 read_kconfig("$builddir/$kconfig");
3390 }
3391 }
3392}
3393
3394sub read_depends {
3395 # find out which arch this is by the kconfig file
3396 open (IN, $output_config)
3397 or dodie "Failed to read $output_config";
3398 my $arch;
3399 while (<IN>) {
3400 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3401 $arch = $1;
3402 last;
3403 }
3404 }
3405 close IN;
3406
3407 if (!defined($arch)) {
3408 doprint "Could not find arch from config file\n";
3409 doprint "no dependencies used\n";
3410 return;
3411 }
3412
3413 # arch is really the subarch, we need to know
3414 # what directory to look at.
3415 if ($arch eq "i386" || $arch eq "x86_64") {
3416 $arch = "x86";
3417 } elsif ($arch =~ /^tile/) {
3418 $arch = "tile";
3419 }
3420
3421 my $kconfig = "$builddir/arch/$arch/Kconfig";
3422
3423 if (! -f $kconfig && $arch =~ /\d$/) {
3424 my $orig = $arch;
3425 # some subarchs have numbers, truncate them
3426 $arch =~ s/\d*$//;
3427 $kconfig = "$builddir/arch/$arch/Kconfig";
3428 if (! -f $kconfig) {
3429 doprint "No idea what arch dir $orig is for\n";
3430 doprint "no dependencies used\n";
3431 return;
3432 }
3433 }
3434
3435 read_kconfig($kconfig);
3436}
3437
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003438sub read_config_list {
3439 my ($config) = @_;
3440
3441 open (IN, $config)
3442 or dodie "Failed to read $config";
3443
3444 while (<IN>) {
3445 if (/^((CONFIG\S*)=.*)/) {
3446 if (!defined($config_ignore{$2})) {
3447 $config_list{$2} = $1;
3448 }
3449 }
3450 }
3451
3452 close(IN);
3453}
3454
3455sub read_output_config {
3456 my ($config) = @_;
3457
3458 assign_configs \%config_ignore, $config;
3459}
3460
3461sub make_new_config {
3462 my @configs = @_;
3463
3464 open (OUT, ">$output_config")
3465 or dodie "Failed to write $output_config";
3466
3467 foreach my $config (@configs) {
3468 print OUT "$config\n";
3469 }
3470 close OUT;
3471}
3472
Steven Rostedtac6974c2011-10-04 09:40:17 -04003473sub chomp_config {
3474 my ($config) = @_;
3475
3476 $config =~ s/CONFIG_//;
3477
3478 return $config;
3479}
3480
Steven Rostedtb9066f62011-07-15 21:25:24 -04003481sub get_depends {
3482 my ($dep) = @_;
3483
Steven Rostedtac6974c2011-10-04 09:40:17 -04003484 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003485
3486 $dep = $depends{"$kconfig"};
3487
3488 # the dep string we have saves the dependencies as they
3489 # were found, including expressions like ! && ||. We
3490 # want to split this out into just an array of configs.
3491
3492 my $valid = "A-Za-z_0-9";
3493
3494 my @configs;
3495
3496 while ($dep =~ /[$valid]/) {
3497
3498 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3499 my $conf = "CONFIG_" . $1;
3500
3501 $configs[$#configs + 1] = $conf;
3502
3503 $dep =~ s/^[^$valid]*[$valid]+//;
3504 } else {
3505 die "this should never happen";
3506 }
3507 }
3508
3509 return @configs;
3510}
3511
3512my %min_configs;
3513my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003514my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003515my %processed_configs;
3516my %nochange_config;
3517
3518sub test_this_config {
3519 my ($config) = @_;
3520
3521 my $found;
3522
3523 # if we already processed this config, skip it
3524 if (defined($processed_configs{$config})) {
3525 return undef;
3526 }
3527 $processed_configs{$config} = 1;
3528
3529 # if this config failed during this round, skip it
3530 if (defined($nochange_config{$config})) {
3531 return undef;
3532 }
3533
Steven Rostedtac6974c2011-10-04 09:40:17 -04003534 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003535
3536 # Test dependencies first
3537 if (defined($depends{"$kconfig"})) {
3538 my @parents = get_depends $config;
3539 foreach my $parent (@parents) {
3540 # if the parent is in the min config, check it first
3541 next if (!defined($min_configs{$parent}));
3542 $found = test_this_config($parent);
3543 if (defined($found)) {
3544 return $found;
3545 }
3546 }
3547 }
3548
3549 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003550 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003551 # .config to make sure it is missing the config that
3552 # we had before
3553 my %configs = %min_configs;
3554 delete $configs{$config};
3555 make_new_config ((values %configs), (values %keep_configs));
3556 make_oldconfig;
3557 undef %configs;
3558 assign_configs \%configs, $output_config;
3559
3560 return $config if (!defined($configs{$config}));
3561
3562 doprint "disabling config $config did not change .config\n";
3563
3564 $nochange_config{$config} = 1;
3565
3566 return undef;
3567}
3568
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003569sub make_min_config {
3570 my ($i) = @_;
3571
Steven Rostedtccc513b2012-05-21 17:13:40 -04003572 my $type = $minconfig_type;
3573 if ($type ne "boot" && $type ne "test") {
3574 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3575 " make_min_config works only with 'boot' and 'test'\n" and return;
3576 }
3577
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003578 if (!defined($output_minconfig)) {
3579 fail "OUTPUT_MIN_CONFIG not defined" and return;
3580 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003581
3582 # If output_minconfig exists, and the start_minconfig
3583 # came from min_config, than ask if we should use
3584 # that instead.
3585 if (-f $output_minconfig && !$start_minconfig_defined) {
3586 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003587 if (!defined($use_output_minconfig)) {
3588 if (read_yn " Use it as minconfig?") {
3589 $start_minconfig = $output_minconfig;
3590 }
3591 } elsif ($use_output_minconfig > 0) {
3592 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003593 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003594 } else {
3595 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003596 }
3597 }
3598
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003599 if (!defined($start_minconfig)) {
3600 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3601 }
3602
Steven Rostedt35ce5952011-07-15 21:57:25 -04003603 my $temp_config = "$tmpdir/temp_config";
3604
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003605 # First things first. We build an allnoconfig to find
3606 # out what the defaults are that we can't touch.
3607 # Some are selections, but we really can't handle selections.
3608
3609 my $save_minconfig = $minconfig;
3610 undef $minconfig;
3611
3612 run_command "$make allnoconfig" or return 0;
3613
Steven Rostedtb9066f62011-07-15 21:25:24 -04003614 read_depends;
3615
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003616 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003617
Steven Rostedt43d1b652011-07-15 22:01:56 -04003618 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003619 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003620
3621 if (defined($ignore_config)) {
3622 # make sure the file exists
3623 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003624 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003625 }
3626
Steven Rostedt43d1b652011-07-15 22:01:56 -04003627 %keep_configs = %save_configs;
3628
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003629 doprint "Load initial configs from $start_minconfig\n";
3630
3631 # Look at the current min configs, and save off all the
3632 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003633 assign_configs \%min_configs, $start_minconfig;
3634
3635 my @config_keys = keys %min_configs;
3636
Steven Rostedtac6974c2011-10-04 09:40:17 -04003637 # All configs need a depcount
3638 foreach my $config (@config_keys) {
3639 my $kconfig = chomp_config $config;
3640 if (!defined $depcount{$kconfig}) {
3641 $depcount{$kconfig} = 0;
3642 }
3643 }
3644
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003645 # Remove anything that was set by the make allnoconfig
3646 # we shouldn't need them as they get set for us anyway.
3647 foreach my $config (@config_keys) {
3648 # Remove anything in the ignore_config
3649 if (defined($keep_configs{$config})) {
3650 my $file = $ignore_config;
3651 $file =~ s,.*/(.*?)$,$1,;
3652 doprint "$config set by $file ... ignored\n";
3653 delete $min_configs{$config};
3654 next;
3655 }
3656 # But make sure the settings are the same. If a min config
3657 # sets a selection, we do not want to get rid of it if
3658 # it is not the same as what we have. Just move it into
3659 # the keep configs.
3660 if (defined($config_ignore{$config})) {
3661 if ($config_ignore{$config} ne $min_configs{$config}) {
3662 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3663 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3664 $keep_configs{$config} = $min_configs{$config};
3665 } else {
3666 doprint "$config set by allnoconfig ... ignored\n";
3667 }
3668 delete $min_configs{$config};
3669 }
3670 }
3671
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003672 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003673 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003674
3675 while (!$done) {
3676
3677 my $config;
3678 my $found;
3679
3680 # Now disable each config one by one and do a make oldconfig
3681 # till we find a config that changes our list.
3682
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003683 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003684
3685 # Sort keys by who is most dependent on
3686 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3687 @test_configs ;
3688
3689 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003690 my $reset = 1;
3691 for (my $i = 0; $i < $#test_configs; $i++) {
3692 if (!defined($nochange_config{$test_configs[0]})) {
3693 $reset = 0;
3694 last;
3695 }
3696 # This config didn't change the .config last time.
3697 # Place it at the end
3698 my $config = shift @test_configs;
3699 push @test_configs, $config;
3700 }
3701
3702 # if every test config has failed to modify the .config file
3703 # in the past, then reset and start over.
3704 if ($reset) {
3705 undef %nochange_config;
3706 }
3707
Steven Rostedtb9066f62011-07-15 21:25:24 -04003708 undef %processed_configs;
3709
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003710 foreach my $config (@test_configs) {
3711
Steven Rostedtb9066f62011-07-15 21:25:24 -04003712 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003713
Steven Rostedtb9066f62011-07-15 21:25:24 -04003714 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003715
3716 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003717 }
3718
3719 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003720 # we could have failed due to the nochange_config hash
3721 # reset and try again
3722 if (!$take_two) {
3723 undef %nochange_config;
3724 $take_two = 1;
3725 next;
3726 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003727 doprint "No more configs found that we can disable\n";
3728 $done = 1;
3729 last;
3730 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003731 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003732
3733 $config = $found;
3734
3735 doprint "Test with $config disabled\n";
3736
3737 # set in_bisect to keep build and monitor from dieing
3738 $in_bisect = 1;
3739
3740 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003741 build "oldconfig" or $failed = 1;
3742 if (!$failed) {
3743 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003744
3745 if ($type eq "test" && !$failed) {
3746 do_run_test or $failed = 1;
3747 }
3748
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003749 end_monitor;
3750 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003751
3752 $in_bisect = 0;
3753
3754 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003755 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003756 # this config is needed, add it to the ignore list.
3757 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003758 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003759 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003760
3761 # update new ignore configs
3762 if (defined($ignore_config)) {
3763 open (OUT, ">$temp_config")
3764 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003765 foreach my $config (keys %save_configs) {
3766 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003767 }
3768 close OUT;
3769 run_command "mv $temp_config $ignore_config" or
3770 dodie "failed to copy update to $ignore_config";
3771 }
3772
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003773 } else {
3774 # We booted without this config, remove it from the minconfigs.
3775 doprint "$config is not needed, disabling\n";
3776
3777 delete $min_configs{$config};
3778
3779 # Also disable anything that is not enabled in this config
3780 my %configs;
3781 assign_configs \%configs, $output_config;
3782 my @config_keys = keys %min_configs;
3783 foreach my $config (@config_keys) {
3784 if (!defined($configs{$config})) {
3785 doprint "$config is not set, disabling\n";
3786 delete $min_configs{$config};
3787 }
3788 }
3789
3790 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003791 open (OUT, ">$temp_config")
3792 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003793 foreach my $config (keys %keep_configs) {
3794 print OUT "$keep_configs{$config}\n";
3795 }
3796 foreach my $config (keys %min_configs) {
3797 print OUT "$min_configs{$config}\n";
3798 }
3799 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003800
3801 run_command "mv $temp_config $output_minconfig" or
3802 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003803 }
3804
3805 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003806 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003807 }
3808
3809 success $i;
3810 return 1;
3811}
3812
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003813sub make_warnings_file {
3814 my ($i) = @_;
3815
3816 if (!defined($warnings_file)) {
3817 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3818 }
3819
3820 if ($build_type eq "nobuild") {
3821 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3822 }
3823
3824 build $build_type or dodie "Failed to build";
3825
3826 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3827
3828 open(IN, $buildlog) or dodie "Can't open $buildlog";
3829 while (<IN>) {
3830
3831 # Some compilers use UTF-8 extended for quotes
3832 # for distcc heterogeneous systems, this causes issues
3833 s/$utf8_quote/'/g;
3834
3835 if (/$check_build_re/) {
3836 print OUT;
3837 }
3838 }
3839 close(IN);
3840
3841 close(OUT);
3842
3843 success $i;
3844}
3845
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003846$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003847
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003848if ($#ARGV == 0) {
3849 $ktest_config = $ARGV[0];
3850 if (! -f $ktest_config) {
3851 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003852 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003853 exit 0;
3854 }
3855 }
3856} else {
3857 $ktest_config = "ktest.conf";
3858}
3859
3860if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003861 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003862 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003863 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3864 print OUT << "EOF"
3865# Generated by ktest.pl
3866#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003867
3868# PWD is a ktest.pl variable that will result in the process working
3869# directory that ktest.pl is executed in.
3870
3871# THIS_DIR is automatically assigned the PWD of the path that generated
3872# the config file. It is best to use this variable when assigning other
3873# directory paths within this directory. This allows you to easily
3874# move the test cases to other locations or to other machines.
3875#
3876THIS_DIR := $variable{"PWD"}
3877
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003878# Define each test with TEST_START
3879# The config options below it will override the defaults
3880TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003881TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003882
3883DEFAULTS
3884EOF
3885;
3886 close(OUT);
3887}
3888read_config $ktest_config;
3889
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003890if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003891 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003892}
3893
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003894# Append any configs entered in manually to the config file.
3895my @new_configs = keys %entered_configs;
3896if ($#new_configs >= 0) {
3897 print "\nAppending entered in configs to $ktest_config\n";
3898 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3899 foreach my $config (@new_configs) {
3900 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003901 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003902 }
3903}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003904
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003905if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3906 unlink $opt{"LOG_FILE"};
3907}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003908
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003909doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3910
Steven Rostedta57419b2010-11-02 15:13:54 -04003911for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3912
3913 if (!$i) {
3914 doprint "DEFAULT OPTIONS:\n";
3915 } else {
3916 doprint "\nTEST $i OPTIONS";
3917 if (defined($repeat_tests{$i})) {
3918 $repeat = $repeat_tests{$i};
3919 doprint " ITERATE $repeat";
3920 }
3921 doprint "\n";
3922 }
3923
3924 foreach my $option (sort keys %opt) {
3925
3926 if ($option =~ /\[(\d+)\]$/) {
3927 next if ($i != $1);
3928 } else {
3929 next if ($i);
3930 }
3931
3932 doprint "$option = $opt{$option}\n";
3933 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003934}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003935
Steven Rostedt2a625122011-05-20 15:48:59 -04003936sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003937 my ($name, $i) = @_;
3938
3939 my $option = "$name\[$i\]";
3940
3941 if (defined($opt{$option})) {
3942 return $opt{$option};
3943 }
3944
Steven Rostedta57419b2010-11-02 15:13:54 -04003945 foreach my $test (keys %repeat_tests) {
3946 if ($i >= $test &&
3947 $i < $test + $repeat_tests{$test}) {
3948 $option = "$name\[$test\]";
3949 if (defined($opt{$option})) {
3950 return $opt{$option};
3951 }
3952 }
3953 }
3954
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003955 if (defined($opt{$name})) {
3956 return $opt{$name};
3957 }
3958
3959 return undef;
3960}
3961
Steven Rostedt2a625122011-05-20 15:48:59 -04003962sub set_test_option {
3963 my ($name, $i) = @_;
3964
3965 my $option = __set_test_option($name, $i);
3966 return $option if (!defined($option));
3967
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003968 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003969}
3970
Steven Rostedt2545eb62010-11-02 15:01:32 -04003971# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003972for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003973
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003974 # Do not reboot on failing test options
3975 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003976 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003977
Steven Rostedt683a3e62012-05-18 13:34:35 -04003978 $have_version = 0;
3979
Steven Rostedt576f6272010-11-02 14:58:38 -04003980 $iteration = $i;
3981
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003982 undef %force_config;
3983
Steven Rostedta75fece2010-11-02 14:58:27 -04003984 my $makecmd = set_test_option("MAKE_CMD", $i);
3985
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05003986 $outputdir = set_test_option("OUTPUT_DIR", $i);
3987 $builddir = set_test_option("BUILD_DIR", $i);
3988
3989 chdir $builddir || die "can't change directory to $builddir";
3990
3991 if (!-d $outputdir) {
3992 mkpath($outputdir) or
3993 die "can't create $outputdir";
3994 }
3995
3996 $make = "$makecmd O=$outputdir";
3997
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003998 # Load all the options into their mapped variable names
3999 foreach my $opt (keys %option_map) {
4000 ${$option_map{$opt}} = set_test_option($opt, $i);
4001 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004002
Steven Rostedt35ce5952011-07-15 21:57:25 -04004003 $start_minconfig_defined = 1;
4004
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004005 # The first test may override the PRE_KTEST option
4006 if (defined($pre_ktest) && $i == 1) {
4007 doprint "\n";
4008 run_command $pre_ktest;
4009 }
4010
4011 # Any test can override the POST_KTEST option
4012 # The last test takes precedence.
4013 if (defined($post_ktest)) {
4014 $final_post_ktest = $post_ktest;
4015 }
4016
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004017 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04004018 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004019 $start_minconfig = $minconfig;
4020 }
4021
Steven Rostedt (Red Hat)8e80bf02013-12-11 15:40:46 -05004022 if (!-d $tmpdir) {
4023 mkpath($tmpdir) or
4024 die "can't create $tmpdir";
Steven Rostedta75fece2010-11-02 14:58:27 -04004025 }
4026
Steven Rostedte48c5292010-11-02 14:35:37 -04004027 $ENV{"SSH_USER"} = $ssh_user;
4028 $ENV{"MACHINE"} = $machine;
4029
Steven Rostedta75fece2010-11-02 14:58:27 -04004030 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304031 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04004032 $dmesg = "$tmpdir/dmesg-$machine";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05004033 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04004034
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004035 if (!$buildonly) {
4036 $target = "$ssh_user\@$machine";
4037 if ($reboot_type eq "grub") {
4038 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05004039 } elsif ($reboot_type eq "grub2") {
4040 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
4041 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05004042 } elsif ($reboot_type eq "syslinux") {
4043 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05004044 }
Steven Rostedta75fece2010-11-02 14:58:27 -04004045 }
4046
4047 my $run_type = $build_type;
4048 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004049 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04004050 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004051 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004052 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05004053 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004054 } elsif ($test_type eq "make_min_config") {
4055 $run_type = "";
4056 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004057 $run_type = "";
4058 }
4059
Steven Rostedta75fece2010-11-02 14:58:27 -04004060 # mistake in config file?
4061 if (!defined($run_type)) {
4062 $run_type = "ERROR";
4063 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04004064
Steven Rostedte0a87422011-09-30 17:50:48 -04004065 my $installme = "";
4066 $installme = " no_install" if ($no_install);
4067
Steven Rostedt2545eb62010-11-02 15:01:32 -04004068 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04004069 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004070
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004071 if (defined($pre_test)) {
4072 run_command $pre_test;
4073 }
4074
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004075 unlink $dmesg;
4076 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304077 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004078
Steven Rostedt250bae82011-07-15 22:05:59 -04004079 if (defined($addconfig)) {
4080 my $min = $minconfig;
4081 if (!defined($minconfig)) {
4082 $min = "";
4083 }
4084 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004085 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004086 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004087 }
4088
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004089 if (defined($checkout)) {
4090 run_command "git checkout $checkout" or
4091 die "failed to checkout $checkout";
4092 }
4093
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004094 $no_reboot = 0;
4095
Steven Rostedt648a1822012-03-21 11:18:27 -04004096 # A test may opt to not reboot the box
4097 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004098 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004099 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004100
Steven Rostedta75fece2010-11-02 14:58:27 -04004101 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004102 bisect $i;
4103 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004104 } elsif ($test_type eq "config_bisect") {
4105 config_bisect $i;
4106 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004107 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004108 patchcheck $i;
4109 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004110 } elsif ($test_type eq "make_min_config") {
4111 make_min_config $i;
4112 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004113 } elsif ($test_type eq "make_warnings_file") {
4114 $no_reboot = 1;
4115 make_warnings_file $i;
4116 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004117 }
4118
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004119 if ($build_type ne "nobuild") {
4120 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004121 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004122 }
4123
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004124 if ($test_type eq "install") {
4125 get_version;
4126 install;
4127 success $i;
4128 next;
4129 }
4130
Steven Rostedta75fece2010-11-02 14:58:27 -04004131 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004132 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004133 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004134
4135 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4136 do_run_test or $failed = 1;
4137 }
4138 end_monitor;
4139 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004140 }
4141
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004142 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004143}
4144
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004145if (defined($final_post_ktest)) {
4146 run_command $final_post_ktest;
4147}
4148
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004149if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004150 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004151} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004152 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004153} elsif (defined($switch_to_good)) {
4154 # still need to get to the good kernel
4155 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004156}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004157
Steven Rostedt648a1822012-03-21 11:18:27 -04004158
Steven Rostedte48c5292010-11-02 14:35:37 -04004159doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4160
Steven Rostedt2545eb62010-11-02 15:01:32 -04004161exit 0;