blob: 0d7fd8b515441fc7bd583d0084d44343b72fcc78 [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 Rostedt2545eb62010-11-02 15:01:32 -040021
22#default opts
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050023my %default = (
24 "NUM_TESTS" => 1,
25 "TEST_TYPE" => "build",
26 "BUILD_TYPE" => "randconfig",
27 "MAKE_CMD" => "make",
28 "TIMEOUT" => 120,
29 "TMP_DIR" => "/tmp/ktest/\${MACHINE}",
30 "SLEEP_TIME" => 60, # sleep time between tests
31 "BUILD_NOCLEAN" => 0,
32 "REBOOT_ON_ERROR" => 0,
33 "POWEROFF_ON_ERROR" => 0,
34 "REBOOT_ON_SUCCESS" => 1,
35 "POWEROFF_ON_SUCCESS" => 0,
36 "BUILD_OPTIONS" => "",
37 "BISECT_SLEEP_TIME" => 60, # sleep time between bisects
38 "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks
39 "CLEAR_LOG" => 0,
40 "BISECT_MANUAL" => 0,
41 "BISECT_SKIP" => 1,
Steven Rostedtccc513b2012-05-21 17:13:40 -040042 "MIN_CONFIG_TYPE" => "boot",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050043 "SUCCESS_LINE" => "login:",
44 "DETECT_TRIPLE_FAULT" => 1,
45 "NO_INSTALL" => 0,
46 "BOOTED_TIMEOUT" => 1,
47 "DIE_ON_FAILURE" => 1,
48 "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND",
49 "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE",
Steven Rostedt02ad2612012-03-21 08:21:24 -040050 "SCP_TO_TARGET_INSTALL" => "\${SCP_TO_TARGET}",
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050051 "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot",
52 "STOP_AFTER_SUCCESS" => 10,
53 "STOP_AFTER_FAILURE" => 60,
54 "STOP_TEST_AFTER" => 600,
Steven Rostedt407b95b2012-07-19 16:05:42 -040055 "MAX_MONITOR_WAIT" => 1800,
Steven Rostedta15ba912012-11-13 14:30:37 -050056 "GRUB_REBOOT" => "grub2-reboot",
Steven Rostedt77869542012-12-11 17:37:41 -050057 "SYSLINUX" => "extlinux",
58 "SYSLINUX_PATH" => "/boot/extlinux",
Steven Rostedt600bbf02011-11-21 20:12:04 -050059
60# required, and we will ask users if they don't have them but we keep the default
61# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050062 "REBOOT_TYPE" => "grub",
63 "LOCALVERSION" => "-test",
64 "SSH_USER" => "root",
65 "BUILD_TARGET" => "arch/x86/boot/bzImage",
66 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050067
68 "LOG_FILE" => undef,
69 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050070);
Steven Rostedt2545eb62010-11-02 15:01:32 -040071
Steven Rostedt8d1491b2010-11-18 15:39:48 -050072my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040073my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040074my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040075my $machine;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -040076my $last_machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040077my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040078my $tmpdir;
79my $builddir;
80my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050081my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040082my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040083my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040084my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040085my $final_post_ktest;
86my $pre_ktest;
87my $post_ktest;
88my $pre_test;
89my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040090my $pre_build;
91my $post_build;
92my $pre_build_die;
93my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040094my $reboot_type;
95my $reboot_script;
96my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040097my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040098my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -050099my $switch_to_good;
100my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -0400101my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -0400102my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -0400103my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -0400104my $powercycle_after_reboot;
105my $poweroff_after_halt;
Steven Rostedt407b95b2012-07-19 16:05:42 -0400106my $max_monitor_wait;
Steven Rostedte48c5292010-11-02 14:35:37 -0400107my $ssh_exec;
108my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400109my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400110my $power_off;
111my $grub_menu;
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -0500112my $last_grub_menu;
Steven Rostedta15ba912012-11-13 14:30:37 -0500113my $grub_file;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400114my $grub_number;
Steven Rostedta15ba912012-11-13 14:30:37 -0500115my $grub_reboot;
Steven Rostedt77869542012-12-11 17:37:41 -0500116my $syslinux;
117my $syslinux_path;
118my $syslinux_label;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400119my $target;
120my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400121my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400122my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400123my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400124my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400125my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400126my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400127my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400128my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400129my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400130my $use_output_minconfig;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500131my $warnings_file;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400132my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500133my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400134my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400135my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500136my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400137my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500138my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500139my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400140my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500141my $bisect_ret_good;
142my $bisect_ret_bad;
143my $bisect_ret_skip;
144my $bisect_ret_abort;
145my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400146my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400147my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400148my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400149my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530150my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400151my $dmesg;
152my $monitor_fp;
153my $monitor_pid;
154my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400155my $sleep_time;
156my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400157my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400158my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400159my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530160my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400161my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400162my $timeout;
163my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400164my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400165my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400166my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400167my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500168my $stop_after_success;
169my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500170my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400171my $build_target;
172my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500173my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400174my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400175my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400176my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400177
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500178my $bisect_good;
179my $bisect_bad;
180my $bisect_type;
181my $bisect_start;
182my $bisect_replay;
183my $bisect_files;
184my $bisect_reverse;
185my $bisect_check;
186
187my $config_bisect;
188my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400189my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500190
191my $patchcheck_type;
192my $patchcheck_start;
193my $patchcheck_end;
194
Steven Rostedt165708b2011-11-26 20:56:52 -0500195# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500196# which would require more options.
197my $buildonly = 1;
198
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500199# tell build not to worry about warnings, even when WARNINGS_FILE is set
200my $warnings_ok = 0;
201
Steven Rostedtdbd37832011-11-23 16:00:48 -0500202# set when creating a new config
203my $newconfig = 0;
204
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500205my %entered_configs;
206my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400207my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400208
209# force_config is the list of configs that we force enabled (or disabled)
210# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400211my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500212
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400213# do not force reboots on config problems
214my $no_reboot = 1;
215
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400216# reboot on success
217my $reboot_success = 0;
218
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500219my %option_map = (
220 "MACHINE" => \$machine,
221 "SSH_USER" => \$ssh_user,
222 "TMP_DIR" => \$tmpdir,
223 "OUTPUT_DIR" => \$outputdir,
224 "BUILD_DIR" => \$builddir,
225 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400226 "PRE_KTEST" => \$pre_ktest,
227 "POST_KTEST" => \$post_ktest,
228 "PRE_TEST" => \$pre_test,
229 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500230 "BUILD_TYPE" => \$build_type,
231 "BUILD_OPTIONS" => \$build_options,
232 "PRE_BUILD" => \$pre_build,
233 "POST_BUILD" => \$post_build,
234 "PRE_BUILD_DIE" => \$pre_build_die,
235 "POST_BUILD_DIE" => \$post_build_die,
236 "POWER_CYCLE" => \$power_cycle,
237 "REBOOT" => \$reboot,
238 "BUILD_NOCLEAN" => \$noclean,
239 "MIN_CONFIG" => \$minconfig,
240 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
241 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400242 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400243 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -0500244 "WARNINGS_FILE" => \$warnings_file,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500245 "IGNORE_CONFIG" => \$ignore_config,
246 "TEST" => \$run_test,
247 "ADD_CONFIG" => \$addconfig,
248 "REBOOT_TYPE" => \$reboot_type,
249 "GRUB_MENU" => \$grub_menu,
Steven Rostedta15ba912012-11-13 14:30:37 -0500250 "GRUB_FILE" => \$grub_file,
251 "GRUB_REBOOT" => \$grub_reboot,
Steven Rostedt77869542012-12-11 17:37:41 -0500252 "SYSLINUX" => \$syslinux,
253 "SYSLINUX_PATH" => \$syslinux_path,
254 "SYSLINUX_LABEL" => \$syslinux_label,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400255 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500256 "POST_INSTALL" => \$post_install,
257 "NO_INSTALL" => \$no_install,
258 "REBOOT_SCRIPT" => \$reboot_script,
259 "REBOOT_ON_ERROR" => \$reboot_on_error,
260 "SWITCH_TO_GOOD" => \$switch_to_good,
261 "SWITCH_TO_TEST" => \$switch_to_test,
262 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400263 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500264 "DIE_ON_FAILURE" => \$die_on_failure,
265 "POWER_OFF" => \$power_off,
266 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
267 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400268 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500269 "SLEEP_TIME" => \$sleep_time,
270 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
271 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
272 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500273 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500274 "BISECT_MANUAL" => \$bisect_manual,
275 "BISECT_SKIP" => \$bisect_skip,
276 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
277 "BISECT_RET_GOOD" => \$bisect_ret_good,
278 "BISECT_RET_BAD" => \$bisect_ret_bad,
279 "BISECT_RET_SKIP" => \$bisect_ret_skip,
280 "BISECT_RET_ABORT" => \$bisect_ret_abort,
281 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
282 "STORE_FAILURES" => \$store_failures,
283 "STORE_SUCCESSES" => \$store_successes,
284 "TEST_NAME" => \$test_name,
285 "TIMEOUT" => \$timeout,
286 "BOOTED_TIMEOUT" => \$booted_timeout,
287 "CONSOLE" => \$console,
288 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
289 "SUCCESS_LINE" => \$success_line,
290 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
291 "STOP_AFTER_SUCCESS" => \$stop_after_success,
292 "STOP_AFTER_FAILURE" => \$stop_after_failure,
293 "STOP_TEST_AFTER" => \$stop_test_after,
294 "BUILD_TARGET" => \$build_target,
295 "SSH_EXEC" => \$ssh_exec,
296 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400297 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500298 "CHECKOUT" => \$checkout,
299 "TARGET_IMAGE" => \$target_image,
300 "LOCALVERSION" => \$localversion,
301
302 "BISECT_GOOD" => \$bisect_good,
303 "BISECT_BAD" => \$bisect_bad,
304 "BISECT_TYPE" => \$bisect_type,
305 "BISECT_START" => \$bisect_start,
306 "BISECT_REPLAY" => \$bisect_replay,
307 "BISECT_FILES" => \$bisect_files,
308 "BISECT_REVERSE" => \$bisect_reverse,
309 "BISECT_CHECK" => \$bisect_check,
310
311 "CONFIG_BISECT" => \$config_bisect,
312 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400313 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500314
315 "PATCHCHECK_TYPE" => \$patchcheck_type,
316 "PATCHCHECK_START" => \$patchcheck_start,
317 "PATCHCHECK_END" => \$patchcheck_end,
318);
319
320# Options may be used by other options, record them.
321my %used_options;
322
Steven Rostedt7bf51072011-10-22 09:07:03 -0400323# default variables that can be used
324chomp ($variable{"PWD"} = `pwd`);
325
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500326$config_help{"MACHINE"} = << "EOF"
327 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500328 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500329EOF
330 ;
331$config_help{"SSH_USER"} = << "EOF"
332 The box is expected to have ssh on normal bootup, provide the user
333 (most likely root, since you need privileged operations)
334EOF
335 ;
336$config_help{"BUILD_DIR"} = << "EOF"
337 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500338 You can use \${PWD} that will be the path where ktest.pl is run, or use
339 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500340EOF
341 ;
342$config_help{"OUTPUT_DIR"} = << "EOF"
343 The directory that the objects will be built (full path).
344 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500345 You can use \${PWD} that will be the path where ktest.pl is run, or use
346 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500347EOF
348 ;
349$config_help{"BUILD_TARGET"} = << "EOF"
350 The location of the compiled file to copy to the target.
351 (relative to OUTPUT_DIR)
352EOF
353 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500354$config_help{"BUILD_OPTIONS"} = << "EOF"
355 Options to add to \"make\" when building.
356 i.e. -j20
357EOF
358 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500359$config_help{"TARGET_IMAGE"} = << "EOF"
360 The place to put your image on the test machine.
361EOF
362 ;
363$config_help{"POWER_CYCLE"} = << "EOF"
364 A script or command to reboot the box.
365
366 Here is a digital loggers power switch example
367 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
368
369 Here is an example to reboot a virtual box on the current host
370 with the name "Guest".
371 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
372EOF
373 ;
374$config_help{"CONSOLE"} = << "EOF"
375 The script or command that reads the console
376
377 If you use ttywatch server, something like the following would work.
378CONSOLE = nc -d localhost 3001
379
380 For a virtual machine with guest name "Guest".
381CONSOLE = virsh console Guest
382EOF
383 ;
384$config_help{"LOCALVERSION"} = << "EOF"
385 Required version ending to differentiate the test
386 from other linux builds on the system.
387EOF
388 ;
389$config_help{"REBOOT_TYPE"} = << "EOF"
390 Way to reboot the box to the test kernel.
Steven Rostedt77869542012-12-11 17:37:41 -0500391 Only valid options so far are "grub", "grub2", "syslinux", and "script".
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500392
393 If you specify grub, it will assume grub version 1
394 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
395 and select that target to reboot to the kernel. If this is not
396 your setup, then specify "script" and have a command or script
397 specified in REBOOT_SCRIPT to boot to the target.
398
399 The entry in /boot/grub/menu.lst must be entered in manually.
400 The test will not modify that file.
Steven Rostedta15ba912012-11-13 14:30:37 -0500401
402 If you specify grub2, then you also need to specify both \$GRUB_MENU
403 and \$GRUB_FILE.
Steven Rostedt77869542012-12-11 17:37:41 -0500404
405 If you specify syslinux, then you may use SYSLINUX to define the syslinux
406 command (defaults to extlinux), and SYSLINUX_PATH to specify the path to
407 the syslinux install (defaults to /boot/extlinux). But you have to specify
408 SYSLINUX_LABEL to define the label to boot to for the test kernel.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500409EOF
410 ;
411$config_help{"GRUB_MENU"} = << "EOF"
412 The grub title name for the test kernel to boot
Steven Rostedta15ba912012-11-13 14:30:37 -0500413 (Only mandatory if REBOOT_TYPE = grub or grub2)
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500414
415 Note, ktest.pl will not update the grub menu.lst, you need to
416 manually add an option for the test. ktest.pl will search
417 the grub menu.lst for this option to find what kernel to
418 reboot into.
419
420 For example, if in the /boot/grub/menu.lst the test kernel title has:
421 title Test Kernel
422 kernel vmlinuz-test
423 GRUB_MENU = Test Kernel
Steven Rostedta15ba912012-11-13 14:30:37 -0500424
425 For grub2, a search of \$GRUB_FILE is performed for the lines
426 that begin with "menuentry". It will not detect submenus. The
427 menu must be a non-nested menu. Add the quotes used in the menu
428 to guarantee your selection, as the first menuentry with the content
429 of \$GRUB_MENU that is found will be used.
430EOF
431 ;
432$config_help{"GRUB_FILE"} = << "EOF"
433 If grub2 is used, the full path for the grub.cfg file is placed
434 here. Use something like /boot/grub2/grub.cfg to search.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500435EOF
436 ;
Steven Rostedt77869542012-12-11 17:37:41 -0500437$config_help{"SYSLINUX_LABEL"} = << "EOF"
438 If syslinux is used, the label that boots the target kernel must
439 be specified with SYSLINUX_LABEL.
440EOF
441 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500442$config_help{"REBOOT_SCRIPT"} = << "EOF"
443 A script to reboot the target into the test kernel
444 (Only mandatory if REBOOT_TYPE = script)
445EOF
446 ;
447
Steven Rostedtdad98752011-11-22 20:48:57 -0500448sub read_prompt {
449 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400450
451 my $ans;
452
453 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500454 if ($cancel) {
455 print "$prompt [y/n/C] ";
456 } else {
457 print "$prompt [Y/n] ";
458 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400459 $ans = <STDIN>;
460 chomp $ans;
461 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500462 if ($cancel) {
463 $ans = "c";
464 } else {
465 $ans = "y";
466 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400467 }
468 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500469 if ($cancel) {
470 last if ($ans =~ /^c$/i);
471 print "Please answer either 'y', 'n' or 'c'.\n";
472 } else {
473 print "Please answer either 'y' or 'n'.\n";
474 }
475 }
476 if ($ans =~ /^c/i) {
477 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400478 }
479 if ($ans !~ /^y$/i) {
480 return 0;
481 }
482 return 1;
483}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500484
Steven Rostedtdad98752011-11-22 20:48:57 -0500485sub read_yn {
486 my ($prompt) = @_;
487
488 return read_prompt 0, $prompt;
489}
490
491sub read_ync {
492 my ($prompt) = @_;
493
494 return read_prompt 1, $prompt;
495}
496
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500497sub get_ktest_config {
498 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400499 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500500
501 return if (defined($opt{$config}));
502
503 if (defined($config_help{$config})) {
504 print "\n";
505 print $config_help{$config};
506 }
507
508 for (;;) {
509 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500510 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500511 print "\[$default{$config}\] ";
512 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400513 $ans = <STDIN>;
514 $ans =~ s/^\s*(.*\S)\s*$/$1/;
515 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500516 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400517 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500518 } else {
519 print "Your answer can not be blank\n";
520 next;
521 }
522 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500523 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500524 last;
525 }
526}
527
528sub get_ktest_configs {
529 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500530 get_ktest_config("BUILD_DIR");
531 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500532
Steven Rostedtdbd37832011-11-23 16:00:48 -0500533 if ($newconfig) {
534 get_ktest_config("BUILD_OPTIONS");
535 }
536
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500537 # options required for other than just building a kernel
538 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500539 get_ktest_config("POWER_CYCLE");
540 get_ktest_config("CONSOLE");
541 }
542
543 # options required for install and more
544 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500545 get_ktest_config("SSH_USER");
546 get_ktest_config("BUILD_TARGET");
547 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500548 }
549
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500550 get_ktest_config("LOCALVERSION");
551
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500552 return if ($buildonly);
553
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500554 my $rtype = $opt{"REBOOT_TYPE"};
555
556 if (!defined($rtype)) {
557 if (!defined($opt{"GRUB_MENU"})) {
558 get_ktest_config("REBOOT_TYPE");
559 $rtype = $entered_configs{"REBOOT_TYPE"};
560 } else {
561 $rtype = "grub";
562 }
563 }
564
565 if ($rtype eq "grub") {
566 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500567 }
Steven Rostedta15ba912012-11-13 14:30:37 -0500568
569 if ($rtype eq "grub2") {
570 get_ktest_config("GRUB_MENU");
571 get_ktest_config("GRUB_FILE");
572 }
Steven Rostedt77869542012-12-11 17:37:41 -0500573
574 if ($rtype eq "syslinux") {
575 get_ktest_config("SYSLINUX_LABEL");
576 }
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500577}
578
Steven Rostedt77d942c2011-05-20 13:36:58 -0400579sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400580 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400581 my $retval = "";
582
583 # We want to check for '\', and it is just easier
584 # to check the previous characet of '$' and not need
585 # to worry if '$' is the first character. By adding
586 # a space to $value, we can just check [^\\]\$ and
587 # it will still work.
588 $value = " $value";
589
590 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
591 my $begin = $1;
592 my $var = $2;
593 my $end = $3;
594 # append beginning of value to retval
595 $retval = "$retval$begin";
596 if (defined($variable{$var})) {
597 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400598 } elsif (defined($remove_undef) && $remove_undef) {
599 # for if statements, any variable that is not defined,
600 # we simple convert to 0
601 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400602 } else {
603 # put back the origin piece.
604 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500605 # This could be an option that is used later, save
606 # it so we don't warn if this option is not one of
607 # ktests options.
608 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400609 }
610 $value = $end;
611 }
612 $retval = "$retval$value";
613
614 # remove the space added in the beginning
615 $retval =~ s/ //;
616
617 return "$retval"
618}
619
Steven Rostedta57419b2010-11-02 15:13:54 -0400620sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400621 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400622
Steven Rostedtcad96662011-12-22 11:32:52 -0500623 my $prvalue = process_variables($rvalue);
624
625 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500626 # Note if a test is something other than build, then we
627 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500628 if ($prvalue ne "install") {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -0500629 # for bisect, we need to check BISECT_TYPE
630 if ($prvalue ne "bisect") {
631 $buildonly = 0;
632 }
633 } else {
634 # install still limits some manditory options.
635 $buildonly = 2;
636 }
637 }
638
639 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
640 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500641 $buildonly = 0;
642 } else {
643 # install still limits some manditory options.
644 $buildonly = 2;
645 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500646 }
647
Steven Rostedta57419b2010-11-02 15:13:54 -0400648 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400649 if (!$override || defined(${$overrides}{$lvalue})) {
650 my $extra = "";
651 if ($override) {
652 $extra = "In the same override section!\n";
653 }
654 die "$name: $.: Option $lvalue defined more than once!\n$extra";
655 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500656 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400657 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500658 if ($rvalue =~ /^\s*$/) {
659 delete $opt{$lvalue};
660 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500661 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500662 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400663}
664
Steven Rostedt77d942c2011-05-20 13:36:58 -0400665sub set_variable {
666 my ($lvalue, $rvalue) = @_;
667
668 if ($rvalue =~ /^\s*$/) {
669 delete $variable{$lvalue};
670 } else {
671 $rvalue = process_variables($rvalue);
672 $variable{$lvalue} = $rvalue;
673 }
674}
675
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400676sub process_compare {
677 my ($lval, $cmp, $rval) = @_;
678
679 # remove whitespace
680
681 $lval =~ s/^\s*//;
682 $lval =~ s/\s*$//;
683
684 $rval =~ s/^\s*//;
685 $rval =~ s/\s*$//;
686
687 if ($cmp eq "==") {
688 return $lval eq $rval;
689 } elsif ($cmp eq "!=") {
690 return $lval ne $rval;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400691 } elsif ($cmp eq "=~") {
692 return $lval =~ m/$rval/;
693 } elsif ($cmp eq "!~") {
694 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400695 }
696
697 my $statement = "$lval $cmp $rval";
698 my $ret = eval $statement;
699
700 # $@ stores error of eval
701 if ($@) {
702 return -1;
703 }
704
705 return $ret;
706}
707
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400708sub value_defined {
709 my ($val) = @_;
710
711 return defined($variable{$2}) ||
712 defined($opt{$2});
713}
714
Steven Rostedt8d735212011-10-17 11:36:44 -0400715my $d = 0;
716sub process_expression {
717 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400718
Steven Rostedt8d735212011-10-17 11:36:44 -0400719 my $c = $d++;
720
721 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
722 my $express = $1;
723
724 if (process_expression($name, $express)) {
725 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
726 } else {
727 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
728 }
729 }
730
731 $d--;
732 my $OR = "\\|\\|";
733 my $AND = "\\&\\&";
734
735 while ($val =~ s/^(.*?)($OR|$AND)//) {
736 my $express = $1;
737 my $op = $2;
738
739 if (process_expression($name, $express)) {
740 if ($op eq "||") {
741 return 1;
742 }
743 } else {
744 if ($op eq "&&") {
745 return 0;
746 }
747 }
748 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400749
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400750 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400751 my $ret = process_compare($1, $2, $3);
752 if ($ret < 0) {
753 die "$name: $.: Unable to process comparison\n";
754 }
755 return $ret;
756 }
757
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400758 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
759 if (defined $1) {
760 return !value_defined($2);
761 } else {
762 return value_defined($2);
763 }
764 }
765
Steven Rostedt45d73a52011-09-30 19:44:53 -0400766 if ($val =~ /^\s*0\s*$/) {
767 return 0;
768 } elsif ($val =~ /^\s*\d+\s*$/) {
769 return 1;
770 }
771
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400772 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400773}
774
775sub process_if {
776 my ($name, $value) = @_;
777
778 # Convert variables and replace undefined ones with 0
779 my $val = process_variables($value, 1);
780 my $ret = process_expression $name, $val;
781
782 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400783}
784
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400785sub __read_config {
786 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400787
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400788 my $in;
789 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400790
Steven Rostedta57419b2010-11-02 15:13:54 -0400791 my $name = $config;
792 $name =~ s,.*/(.*),$1,;
793
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400794 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400795 my $default = 1;
796 my $repeat = 1;
797 my $num_tests_set = 0;
798 my $skip = 0;
799 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400800 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400801 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400802 my $if = 0;
803 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400804 my $override = 0;
805
806 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400807
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400808 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400809
810 # ignore blank lines and comments
811 next if (/^\s*$/ || /\s*\#/);
812
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400813 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400814
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400815 my $type = $1;
816 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400817 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400818
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400819 my $old_test_num;
820 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400821 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400822
823 if ($type eq "TEST_START") {
824
825 if ($num_tests_set) {
826 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
827 }
828
829 $old_test_num = $test_num;
830 $old_repeat = $repeat;
831
832 $test_num += $repeat;
833 $default = 0;
834 $repeat = 1;
835 } else {
836 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400837 }
838
Steven Rostedta9f84422011-10-17 11:06:29 -0400839 # If SKIP is anywhere in the line, the command will be skipped
840 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400841 $skip = 1;
842 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400843 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400844 $skip = 0;
845 }
846
Steven Rostedta9f84422011-10-17 11:06:29 -0400847 if ($rest =~ s/\sELSE\b//) {
848 if (!$if) {
849 die "$name: $.: ELSE found with out matching IF section\n$_";
850 }
851 $if = 0;
852
853 if ($if_set) {
854 $skip = 1;
855 } else {
856 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400857 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400858 }
859
Steven Rostedta9f84422011-10-17 11:06:29 -0400860 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400861 if (process_if($name, $1)) {
862 $if_set = 1;
863 } else {
864 $skip = 1;
865 }
866 $if = 1;
867 } else {
868 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400869 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400870 }
871
Steven Rostedta9f84422011-10-17 11:06:29 -0400872 if (!$skip) {
873 if ($type eq "TEST_START") {
874 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
875 $repeat = $1;
876 $repeat_tests{"$test_num"} = $repeat;
877 }
878 } elsif ($rest =~ s/\sOVERRIDE\b//) {
879 # DEFAULT only
880 $override = 1;
881 # Clear previous overrides
882 %overrides = ();
883 }
884 }
885
886 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400887 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400888 }
889
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400890 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400891 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400892 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400893 }
894
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400895 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400896 if (!$if) {
897 die "$name: $.: ELSE found with out matching IF section\n$_";
898 }
899 $rest = $1;
900 if ($if_set) {
901 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400902 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400903 } else {
904 $skip = 0;
905
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400906 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400907 # May be a ELSE IF section.
Steven Rostedt95f57832012-09-26 14:48:17 -0400908 if (process_if($name, $1)) {
909 $if_set = 1;
910 } else {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400911 $skip = 1;
912 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400913 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400914 } else {
915 $if = 0;
916 }
917 }
918
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400919 if ($rest !~ /^\s*$/) {
920 die "$name: $.: Gargbage found after DEFAULTS\n$_";
921 }
922
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400923 } elsif (/^\s*INCLUDE\s+(\S+)/) {
924
925 next if ($skip);
926
927 if (!$default) {
928 die "$name: $.: INCLUDE can only be done in default sections\n$_";
929 }
930
931 my $file = process_variables($1);
932
933 if ($file !~ m,^/,) {
934 # check the path of the config file first
935 if ($config =~ m,(.*)/,) {
936 if (-f "$1/$file") {
937 $file = "$1/$file";
938 }
939 }
940 }
941
942 if ( ! -r $file ) {
943 die "$name: $.: Can't read file $file\n$_";
944 }
945
946 if (__read_config($file, \$test_num)) {
947 $test_case = 1;
948 }
949
Steven Rostedta57419b2010-11-02 15:13:54 -0400950 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
951
952 next if ($skip);
953
Steven Rostedt2545eb62010-11-02 15:01:32 -0400954 my $lvalue = $1;
955 my $rvalue = $2;
956
Steven Rostedta57419b2010-11-02 15:13:54 -0400957 if (!$default &&
958 ($lvalue eq "NUM_TESTS" ||
959 $lvalue eq "LOG_FILE" ||
960 $lvalue eq "CLEAR_LOG")) {
961 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400962 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400963
964 if ($lvalue eq "NUM_TESTS") {
965 if ($test_num) {
966 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
967 }
968 if (!$default) {
969 die "$name: $.: NUM_TESTS must be set in default section\n";
970 }
971 $num_tests_set = 1;
972 }
973
974 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400975 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400976 } else {
977 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400978 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400979
980 if ($repeat > 1) {
981 $repeats{$val} = $repeat;
982 }
983 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400984 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
985 next if ($skip);
986
987 my $lvalue = $1;
988 my $rvalue = $2;
989
990 # process config variables.
991 # Config variables are only active while reading the
992 # config and can be defined anywhere. They also ignore
993 # TEST_START and DEFAULTS, but are skipped if they are in
994 # on of these sections that have SKIP defined.
995 # The save variable can be
996 # defined multiple times and the new one simply overrides
997 # the prevous one.
998 set_variable($lvalue, $rvalue);
999
Steven Rostedta57419b2010-11-02 15:13:54 -04001000 } else {
1001 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001002 }
1003 }
1004
Steven Rostedta57419b2010-11-02 15:13:54 -04001005 if ($test_num) {
1006 $test_num += $repeat - 1;
1007 $opt{"NUM_TESTS"} = $test_num;
1008 }
1009
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001010 close($in);
1011
1012 $$current_test_num = $test_num;
1013
1014 return $test_case;
1015}
1016
Steven Rostedtc4261d02011-11-23 13:41:18 -05001017sub get_test_case {
1018 print "What test case would you like to run?\n";
1019 print " (build, install or boot)\n";
1020 print " Other tests are available but require editing the config file\n";
1021 my $ans = <STDIN>;
1022 chomp $ans;
1023 $default{"TEST_TYPE"} = $ans;
1024}
1025
Steven Rostedt2ed3b162011-09-30 21:00:00 -04001026sub read_config {
1027 my ($config) = @_;
1028
1029 my $test_case;
1030 my $test_num = 0;
1031
1032 $test_case = __read_config $config, \$test_num;
1033
Steven Rostedt8d1491b2010-11-18 15:39:48 -05001034 # make sure we have all mandatory configs
1035 get_ktest_configs;
1036
Steven Rostedt0df213c2011-06-14 20:51:37 -04001037 # was a test specified?
1038 if (!$test_case) {
1039 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -05001040 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -04001041 }
1042
Steven Rostedta75fece2010-11-02 14:58:27 -04001043 # set any defaults
1044
1045 foreach my $default (keys %default) {
1046 if (!defined($opt{$default})) {
1047 $opt{$default} = $default{$default};
1048 }
1049 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -05001050
1051 if ($opt{"IGNORE_UNUSED"} == 1) {
1052 return;
1053 }
1054
1055 my %not_used;
1056
1057 # check if there are any stragglers (typos?)
1058 foreach my $option (keys %opt) {
1059 my $op = $option;
1060 # remove per test labels.
1061 $op =~ s/\[.*\]//;
1062 if (!exists($option_map{$op}) &&
1063 !exists($default{$op}) &&
1064 !exists($used_options{$op})) {
1065 $not_used{$op} = 1;
1066 }
1067 }
1068
1069 if (%not_used) {
1070 my $s = "s are";
1071 $s = " is" if (keys %not_used == 1);
1072 print "The following option$s not used; could be a typo:\n";
1073 foreach my $option (keys %not_used) {
1074 print "$option\n";
1075 }
1076 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1077 if (!read_yn "Do you want to continue?") {
1078 exit -1;
1079 }
1080 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001081}
1082
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001083sub __eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001084 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001085
1086 # Add space to evaluate the character before $
1087 $option = " $option";
1088 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301089 my $repeated = 0;
1090 my $parent = 0;
1091
1092 foreach my $test (keys %repeat_tests) {
1093 if ($i >= $test &&
1094 $i < $test + $repeat_tests{$test}) {
1095
1096 $repeated = 1;
1097 $parent = $test;
1098 last;
1099 }
1100 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001101
1102 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1103 my $start = $1;
1104 my $var = $2;
1105 my $end = $3;
1106
1107 # Append beginning of line
1108 $retval = "$retval$start";
1109
1110 # If the iteration option OPT[$i] exists, then use that.
1111 # otherwise see if the default OPT (without [$i]) exists.
1112
1113 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301114 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001115
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001116 # If a variable contains itself, use the default var
1117 if (($var eq $name) && defined($opt{$var})) {
1118 $o = $opt{$var};
1119 $retval = "$retval$o";
1120 } elsif (defined($opt{$o})) {
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001121 $o = $opt{$o};
1122 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301123 } elsif ($repeated && defined($opt{$parento})) {
1124 $o = $opt{$parento};
1125 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001126 } elsif (defined($opt{$var})) {
1127 $o = $opt{$var};
1128 $retval = "$retval$o";
1129 } else {
1130 $retval = "$retval\$\{$var\}";
1131 }
1132
1133 $option = $end;
1134 }
1135
1136 $retval = "$retval$option";
1137
1138 $retval =~ s/^ //;
1139
1140 return $retval;
1141}
1142
1143sub eval_option {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001144 my ($name, $option, $i) = @_;
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001145
1146 my $prev = "";
1147
1148 # Since an option can evaluate to another option,
1149 # keep iterating until we do not evaluate any more
1150 # options.
1151 my $r = 0;
1152 while ($prev ne $option) {
1153 # Check for recursive evaluations.
1154 # 100 deep should be more than enough.
1155 if ($r++ > 100) {
1156 die "Over 100 evaluations accurred with $option\n" .
1157 "Check for recursive variables\n";
1158 }
1159 $prev = $option;
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05001160 $option = __eval_option($name, $option, $i);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001161 }
1162
1163 return $option;
1164}
1165
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001166sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001167 if (defined($opt{"LOG_FILE"})) {
1168 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1169 print OUT @_;
1170 close(OUT);
1171 }
1172}
1173
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001174sub logit {
1175 if (defined($opt{"LOG_FILE"})) {
1176 _logit @_;
1177 } else {
1178 print @_;
1179 }
1180}
1181
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001182sub doprint {
1183 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001184 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001185}
1186
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001187sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001188sub start_monitor;
1189sub end_monitor;
1190sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001191
1192sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001193 my ($time) = @_;
1194
Steven Rostedta4968722012-12-11 14:59:05 -05001195 # Make sure everything has been written to disk
1196 run_ssh("sync");
1197
Steven Rostedt2b803362011-09-30 18:00:23 -04001198 if (defined($time)) {
1199 start_monitor;
1200 # flush out current monitor
1201 # May contain the reboot success line
1202 wait_for_monitor 1;
1203 }
1204
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001205 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001206 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001207 if (defined($powercycle_after_reboot)) {
1208 sleep $powercycle_after_reboot;
1209 run_command "$power_cycle";
1210 }
1211 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001212 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001213 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001214 }
Andrew Jones2728be42011-08-12 15:32:05 +02001215
1216 if (defined($time)) {
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001217
1218 # We only want to get to the new kernel, don't fail
1219 # if we stumble over a call trace.
1220 my $save_ignore_errors = $ignore_errors;
1221 $ignore_errors = 1;
1222
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001223 # Look for the good kernel to boot
1224 if (wait_for_monitor($time, "Linux version")) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001225 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001226 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001227 run_command "$power_cycle";
1228 }
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001229
Steven Rostedt (Red Hat)4c0b67a2013-02-05 09:56:00 -05001230 $ignore_errors = $save_ignore_errors;
1231
Steven Rostedt (Red Hat)d6845532013-02-04 23:08:49 -05001232 # Still need to wait for the reboot to finish
1233 wait_for_monitor($time, $reboot_success_line);
1234
Andrew Jones2728be42011-08-12 15:32:05 +02001235 end_monitor;
1236 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001237}
1238
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001239sub reboot_to_good {
1240 my ($time) = @_;
1241
1242 if (defined($switch_to_good)) {
1243 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001244 }
1245
1246 reboot $time;
1247}
1248
Steven Rostedt576f6272010-11-02 14:58:38 -04001249sub do_not_reboot {
1250 my $i = $iteration;
1251
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001252 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001253 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1254 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1255}
1256
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001257sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001258 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001259
Steven Rostedt576f6272010-11-02 14:58:38 -04001260 my $i = $iteration;
1261
1262 if ($reboot_on_error && !do_not_reboot) {
1263
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001264 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001265 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001266
Steven Rostedta75fece2010-11-02 14:58:27 -04001267 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001268 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001269 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001270 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001271
Steven Rostedtf80802c2011-03-07 13:18:47 -05001272 if (defined($opt{"LOG_FILE"})) {
1273 print " See $opt{LOG_FILE} for more info.\n";
1274 }
1275
Steven Rostedt576f6272010-11-02 14:58:38 -04001276 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001277}
1278
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001279sub open_console {
1280 my ($fp) = @_;
1281
1282 my $flags;
1283
Steven Rostedta75fece2010-11-02 14:58:27 -04001284 my $pid = open($fp, "$console|") or
1285 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001286
1287 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001288 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001289 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001290 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001291
1292 return $pid;
1293}
1294
1295sub close_console {
1296 my ($fp, $pid) = @_;
1297
1298 doprint "kill child process $pid\n";
1299 kill 2, $pid;
1300
1301 print "closing!\n";
1302 close($fp);
1303}
1304
1305sub start_monitor {
1306 if ($monitor_cnt++) {
1307 return;
1308 }
1309 $monitor_fp = \*MONFD;
1310 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001311
1312 return;
1313
1314 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001315}
1316
1317sub end_monitor {
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001318 return if (!defined $console);
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001319 if (--$monitor_cnt) {
1320 return;
1321 }
1322 close_console($monitor_fp, $monitor_pid);
1323}
1324
1325sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001326 my ($time, $stop) = @_;
1327 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001328 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001329 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001330 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001331 my $skip_call_trace = 0;
1332 my $bug = 0;
1333 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001334 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001335
Steven Rostedta75fece2010-11-02 14:58:27 -04001336 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001337
1338 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001339 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001340 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001341 last if (!defined($line));
1342 print "$line";
1343 $full_line .= $line;
1344
1345 if (defined($stop) && $full_line =~ /$stop/) {
1346 doprint "wait for monitor detected $stop\n";
1347 $booted = 1;
1348 }
1349
Steven Rostedt8a80c722012-07-19 16:08:33 -04001350 if ($full_line =~ /\[ backtrace testing \]/) {
1351 $skip_call_trace = 1;
1352 }
1353
1354 if ($full_line =~ /call trace:/i) {
1355 if (!$bug && !$skip_call_trace) {
1356 if ($ignore_errors) {
1357 $bug_ignored = 1;
1358 } else {
1359 $bug = 1;
1360 }
1361 }
1362 }
1363
1364 if ($full_line =~ /\[ end of backtrace testing \]/) {
1365 $skip_call_trace = 0;
1366 }
1367
1368 if ($full_line =~ /Kernel panic -/) {
1369 $bug = 1;
1370 }
1371
Steven Rostedt2b803362011-09-30 18:00:23 -04001372 if ($line =~ /\n/) {
1373 $full_line = "";
1374 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001375 $now = time;
1376 if ($now - $start_time >= $max_monitor_wait) {
1377 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1378 return 1;
1379 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001380 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001381 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001382 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001383}
1384
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301385sub save_logs {
1386 my ($result, $basedir) = @_;
1387 my @t = localtime;
1388 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1389 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1390
1391 my $type = $build_type;
1392 if ($type =~ /useconfig/) {
1393 $type = "useconfig";
1394 }
1395
1396 my $dir = "$machine-$test_type-$type-$result-$date";
1397
1398 $dir = "$basedir/$dir";
1399
1400 if (!-d $dir) {
1401 mkpath($dir) or
1402 die "can't create $dir";
1403 }
1404
1405 my %files = (
1406 "config" => $output_config,
1407 "buildlog" => $buildlog,
1408 "dmesg" => $dmesg,
1409 "testlog" => $testlog,
1410 );
1411
1412 while (my ($name, $source) = each(%files)) {
1413 if (-f "$source") {
1414 cp "$source", "$dir/$name" or
1415 die "failed to copy $source";
1416 }
1417 }
1418
1419 doprint "*** Saved info to $dir ***\n";
1420}
1421
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001422sub fail {
1423
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001424 if (defined($post_test)) {
1425 run_command $post_test;
1426 }
1427
Steven Rostedta75fece2010-11-02 14:58:27 -04001428 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001429 dodie @_;
1430 }
1431
Steven Rostedta75fece2010-11-02 14:58:27 -04001432 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001433
Steven Rostedt576f6272010-11-02 14:58:38 -04001434 my $i = $iteration;
1435
Steven Rostedta75fece2010-11-02 14:58:27 -04001436 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001437 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001438 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001439 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001440 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001441
Steven Rostedt9064af52011-06-13 10:38:48 -04001442 my $name = "";
1443
1444 if (defined($test_name)) {
1445 $name = " ($test_name)";
1446 }
1447
Steven Rostedt576f6272010-11-02 14:58:38 -04001448 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1449 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001450 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001451 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1452 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001453
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301454 if (defined($store_failures)) {
1455 save_logs "fail", $store_failures;
1456 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001457
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001458 return 1;
1459}
1460
Steven Rostedt2545eb62010-11-02 15:01:32 -04001461sub run_command {
1462 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001463 my $dolog = 0;
1464 my $dord = 0;
1465 my $pid;
1466
Steven Rostedte48c5292010-11-02 14:35:37 -04001467 $command =~ s/\$SSH_USER/$ssh_user/g;
1468 $command =~ s/\$MACHINE/$machine/g;
1469
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001470 doprint("$command ... ");
1471
1472 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001473 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001474
1475 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001476 open(LOG, ">>$opt{LOG_FILE}") or
1477 dodie "failed to write to log";
1478 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001479 }
1480
1481 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001482 open (RD, ">$redirect") or
1483 dodie "failed to write to redirect $redirect";
1484 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001485 }
1486
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001487 while (<CMD>) {
1488 print LOG if ($dolog);
1489 print RD if ($dord);
1490 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001491
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001492 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001493 my $failed = $?;
1494
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001495 close(CMD);
1496 close(LOG) if ($dolog);
1497 close(RD) if ($dord);
1498
Steven Rostedt2545eb62010-11-02 15:01:32 -04001499 if ($failed) {
1500 doprint "FAILED!\n";
1501 } else {
1502 doprint "SUCCESS\n";
1503 }
1504
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001505 return !$failed;
1506}
1507
Steven Rostedte48c5292010-11-02 14:35:37 -04001508sub run_ssh {
1509 my ($cmd) = @_;
1510 my $cp_exec = $ssh_exec;
1511
1512 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1513 return run_command "$cp_exec";
1514}
1515
1516sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001517 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001518
1519 $cp_scp =~ s/\$SRC_FILE/$src/g;
1520 $cp_scp =~ s/\$DST_FILE/$dst/g;
1521
1522 return run_command "$cp_scp";
1523}
1524
Steven Rostedt02ad2612012-03-21 08:21:24 -04001525sub run_scp_install {
1526 my ($src, $dst) = @_;
1527
1528 my $cp_scp = $scp_to_target_install;
1529
1530 return run_scp($src, $dst, $cp_scp);
1531}
1532
1533sub run_scp_mod {
1534 my ($src, $dst) = @_;
1535
1536 my $cp_scp = $scp_to_target;
1537
1538 return run_scp($src, $dst, $cp_scp);
1539}
1540
Steven Rostedta15ba912012-11-13 14:30:37 -05001541sub get_grub2_index {
1542
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001543 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001544 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1545 $last_machine eq $machine);
Steven Rostedta15ba912012-11-13 14:30:37 -05001546
1547 doprint "Find grub2 menu ... ";
1548 $grub_number = -1;
1549
1550 my $ssh_grub = $ssh_exec;
1551 $ssh_grub =~ s,\$SSH_COMMAND,cat $grub_file,g;
1552
1553 open(IN, "$ssh_grub |")
1554 or die "unable to get $grub_file";
1555
1556 my $found = 0;
1557
1558 while (<IN>) {
1559 if (/^menuentry.*$grub_menu/) {
1560 $grub_number++;
1561 $found = 1;
1562 last;
1563 } elsif (/^menuentry\s/) {
1564 $grub_number++;
1565 }
1566 }
1567 close(IN);
1568
1569 die "Could not find '$grub_menu' in $grub_file on $machine"
1570 if (!$found);
1571 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001572 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001573 $last_machine = $machine;
Steven Rostedta15ba912012-11-13 14:30:37 -05001574}
1575
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001576sub get_grub_index {
1577
Steven Rostedta15ba912012-11-13 14:30:37 -05001578 if ($reboot_type eq "grub2") {
1579 get_grub2_index;
1580 return;
1581 }
1582
Steven Rostedta75fece2010-11-02 14:58:27 -04001583 if ($reboot_type ne "grub") {
1584 return;
1585 }
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001586 return if (defined($grub_number) && defined($last_grub_menu) &&
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001587 $last_grub_menu eq $grub_menu && defined($last_machine) &&
1588 $last_machine eq $machine);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001589
1590 doprint "Find grub menu ... ";
1591 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001592
1593 my $ssh_grub = $ssh_exec;
1594 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1595
1596 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001597 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001598
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001599 my $found = 0;
1600
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001601 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001602 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001603 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001604 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001605 last;
1606 } elsif (/^\s*title\s/) {
1607 $grub_number++;
1608 }
1609 }
1610 close(IN);
1611
Steven Rostedta75fece2010-11-02 14:58:27 -04001612 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001613 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001614 doprint "$grub_number\n";
Steven Rostedt (Red Hat)752d9662013-03-08 09:33:35 -05001615 $last_grub_menu = $grub_menu;
Steven Rostedt (Red Hat)df5f7c62013-04-24 16:03:30 -04001616 $last_machine = $machine;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001617}
1618
Steven Rostedt2545eb62010-11-02 15:01:32 -04001619sub wait_for_input
1620{
1621 my ($fp, $time) = @_;
1622 my $rin;
1623 my $ready;
1624 my $line;
1625 my $ch;
1626
1627 if (!defined($time)) {
1628 $time = $timeout;
1629 }
1630
1631 $rin = '';
1632 vec($rin, fileno($fp), 1) = 1;
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001633 ($ready, $time) = select($rin, undef, undef, $time);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001634
1635 $line = "";
1636
1637 # try to read one char at a time
1638 while (sysread $fp, $ch, 1) {
1639 $line .= $ch;
1640 last if ($ch eq "\n");
1641 }
1642
1643 if (!length($line)) {
1644 return undef;
1645 }
1646
1647 return $line;
1648}
1649
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001650sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001651 if (defined($switch_to_test)) {
1652 run_command $switch_to_test;
1653 }
1654
Steven Rostedta75fece2010-11-02 14:58:27 -04001655 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001656 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedta15ba912012-11-13 14:30:37 -05001657 } elsif ($reboot_type eq "grub2") {
1658 run_ssh "$grub_reboot $grub_number";
Steven Rostedt77869542012-12-11 17:37:41 -05001659 } elsif ($reboot_type eq "syslinux") {
1660 run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001661 } elsif (defined $reboot_script) {
1662 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001663 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001664 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001665}
1666
Steven Rostedta57419b2010-11-02 15:13:54 -04001667sub get_sha1 {
1668 my ($commit) = @_;
1669
1670 doprint "git rev-list --max-count=1 $commit ... ";
1671 my $sha1 = `git rev-list --max-count=1 $commit`;
1672 my $ret = $?;
1673
1674 logit $sha1;
1675
1676 if ($ret) {
1677 doprint "FAILED\n";
1678 dodie "Failed to get git $commit";
1679 }
1680
1681 print "SUCCESS\n";
1682
1683 chomp $sha1;
1684
1685 return $sha1;
1686}
1687
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001688sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001689 my $booted = 0;
1690 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001691 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001692 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001693 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001694
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001695 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001696
1697 my $line;
1698 my $full_line = "";
1699
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001700 open(DMESG, "> $dmesg") or
1701 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001702
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001703 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001704
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001705 my $success_start;
1706 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001707 my $monitor_start = time;
1708 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001709 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001710
Steven Rostedt2d01b262011-03-08 09:47:54 -05001711 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001712
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001713 if ($bug && defined($stop_after_failure) &&
1714 $stop_after_failure >= 0) {
1715 my $time = $stop_after_failure - (time - $failure_start);
1716 $line = wait_for_input($monitor_fp, $time);
1717 if (!defined($line)) {
1718 doprint "bug timed out after $booted_timeout seconds\n";
1719 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1720 last;
1721 }
1722 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001723 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001724 if (!defined($line)) {
1725 my $s = $booted_timeout == 1 ? "" : "s";
1726 doprint "Successful boot found: break after $booted_timeout second$s\n";
1727 last;
1728 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001729 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001730 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001731 if (!defined($line)) {
1732 my $s = $timeout == 1 ? "" : "s";
1733 doprint "Timed out after $timeout second$s\n";
1734 last;
1735 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001736 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001737
Steven Rostedt2545eb62010-11-02 15:01:32 -04001738 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001739 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001740
1741 # we are not guaranteed to get a full line
1742 $full_line .= $line;
1743
Steven Rostedta75fece2010-11-02 14:58:27 -04001744 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001745 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001746 $success_start = time;
1747 }
1748
1749 if ($booted && defined($stop_after_success) &&
1750 $stop_after_success >= 0) {
1751 my $now = time;
1752 if ($now - $success_start >= $stop_after_success) {
1753 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1754 last;
1755 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001756 }
1757
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001758 if ($full_line =~ /\[ backtrace testing \]/) {
1759 $skip_call_trace = 1;
1760 }
1761
Steven Rostedt2545eb62010-11-02 15:01:32 -04001762 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001763 if (!$bug && !$skip_call_trace) {
1764 if ($ignore_errors) {
1765 $bug_ignored = 1;
1766 } else {
1767 $bug = 1;
1768 $failure_start = time;
1769 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001770 }
1771 }
1772
1773 if ($bug && defined($stop_after_failure) &&
1774 $stop_after_failure >= 0) {
1775 my $now = time;
1776 if ($now - $failure_start >= $stop_after_failure) {
1777 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1778 last;
1779 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001780 }
1781
1782 if ($full_line =~ /\[ end of backtrace testing \]/) {
1783 $skip_call_trace = 0;
1784 }
1785
1786 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001787 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001788 $bug = 1;
1789 }
1790
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001791 # Detect triple faults by testing the banner
1792 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1793 if ($1 eq $version) {
1794 $version_found = 1;
1795 } elsif ($version_found && $detect_triplefault) {
1796 # We already booted into the kernel we are testing,
1797 # but now we booted into another kernel?
1798 # Consider this a triple fault.
1799 doprint "Aleady booted in Linux kernel $version, but now\n";
1800 doprint "we booted into Linux kernel $1.\n";
1801 doprint "Assuming that this is a triple fault.\n";
1802 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1803 last;
1804 }
1805 }
1806
Steven Rostedt2545eb62010-11-02 15:01:32 -04001807 if ($line =~ /\n/) {
1808 $full_line = "";
1809 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001810
1811 if ($stop_test_after > 0 && !$booted && !$bug) {
1812 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001813 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001814 $done = 1;
1815 }
1816 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001817 }
1818
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001819 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001820
Steven Rostedt2545eb62010-11-02 15:01:32 -04001821 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001822 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001823 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001824 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001825
Steven Rostedta75fece2010-11-02 14:58:27 -04001826 if (!$booted) {
1827 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001828 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001829 }
1830
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001831 if ($bug_ignored) {
1832 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1833 }
1834
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001835 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001836}
1837
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001838sub eval_kernel_version {
1839 my ($option) = @_;
1840
1841 $option =~ s/\$KERNEL_VERSION/$version/g;
1842
1843 return $option;
1844}
1845
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001846sub do_post_install {
1847
1848 return if (!defined($post_install));
1849
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001850 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001851 run_command "$cp_post_install" or
1852 dodie "Failed to run post install";
1853}
1854
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001855# Sometimes the reboot fails, and will hang. We try to ssh to the box
1856# and if we fail, we force another reboot, that should powercycle it.
1857sub test_booted {
1858 if (!run_ssh "echo testing connection") {
1859 reboot $sleep_time;
1860 }
1861}
1862
Steven Rostedt2545eb62010-11-02 15:01:32 -04001863sub install {
1864
Steven Rostedte0a87422011-09-30 17:50:48 -04001865 return if ($no_install);
1866
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001867 if (defined($pre_install)) {
1868 my $cp_pre_install = eval_kernel_version $pre_install;
1869 run_command "$cp_pre_install" or
1870 dodie "Failed to run pre install";
1871 }
1872
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001873 my $cp_target = eval_kernel_version $target_image;
1874
Steven Rostedte1a6c3d2012-12-11 21:19:41 -05001875 test_booted;
1876
Steven Rostedt02ad2612012-03-21 08:21:24 -04001877 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001878 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001879
1880 my $install_mods = 0;
1881
1882 # should we process modules?
1883 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001884 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001885 while (<IN>) {
1886 if (/CONFIG_MODULES(=y)?/) {
Steven Rostedt8bc5e4e2012-10-26 00:10:32 -04001887 if (defined($1)) {
1888 $install_mods = 1;
1889 last;
1890 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001891 }
1892 }
1893 close(IN);
1894
1895 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001896 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001897 doprint "No modules needed\n";
1898 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001899 }
1900
Steven Rostedt627977d2012-03-21 08:16:15 -04001901 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001902 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001903
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001904 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001905 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001906
Steven Rostedte48c5292010-11-02 14:35:37 -04001907 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001908 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001909
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001910 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001911 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001912 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001913
Steven Rostedt02ad2612012-03-21 08:21:24 -04001914 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001915 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001916
Steven Rostedta75fece2010-11-02 14:58:27 -04001917 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001918
Steven Rostedte7b13442011-06-14 20:44:36 -04001919 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001920 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001921
Steven Rostedte48c5292010-11-02 14:35:37 -04001922 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001923
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001924 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001925}
1926
Steven Rostedtddf607e2011-06-14 20:49:13 -04001927sub get_version {
1928 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001929 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001930 doprint "$make kernelrelease ... ";
1931 $version = `$make kernelrelease | tail -1`;
1932 chomp($version);
1933 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001934 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001935}
1936
1937sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001938 # Make sure the stable kernel has finished booting
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001939
1940 # Install bisects, don't need console
1941 if (defined $console) {
1942 start_monitor;
1943 wait_for_monitor 5;
1944 end_monitor;
1945 }
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001946
Steven Rostedtddf607e2011-06-14 20:49:13 -04001947 get_grub_index;
1948 get_version;
1949 install;
1950
Steven Rostedt (Red Hat)319ab142013-01-30 12:25:38 -05001951 start_monitor if (defined $console);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001952 return monitor;
1953}
1954
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001955my $check_build_re = ".*:.*(warning|error|Error):.*";
1956my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1957
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05001958sub process_warning_line {
1959 my ($line) = @_;
1960
1961 chomp $line;
1962
1963 # for distcc heterogeneous systems, some compilers
1964 # do things differently causing warning lines
1965 # to be slightly different. This makes an attempt
1966 # to fixe those issues.
1967
1968 # chop off the index into the line
1969 # using distcc, some compilers give different indexes
1970 # depending on white space
1971 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
1972
1973 # Some compilers use UTF-8 extended for quotes and some don't.
1974 $line =~ s/$utf8_quote/'/g;
1975
1976 return $line;
1977}
1978
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001979# Read buildlog and check against warnings file for any
1980# new warnings.
1981#
1982# Returns 1 if OK
1983# 0 otherwise
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001984sub check_buildlog {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05001985 return 1 if (!defined $warnings_file);
1986
1987 my %warnings_list;
1988
1989 # Failed builds should not reboot the target
1990 my $save_no_reboot = $no_reboot;
1991 $no_reboot = 1;
1992
1993 if (-f $warnings_file) {
1994 open(IN, $warnings_file) or
1995 dodie "Error opening $warnings_file";
1996
1997 while (<IN>) {
1998 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05001999 my $warning = process_warning_line $_;
2000
2001 $warnings_list{$warning} = 1;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002002 }
2003 }
2004 close(IN);
2005 }
2006
2007 # If warnings file didn't exist, and WARNINGS_FILE exist,
2008 # then we fail on any warning!
2009
2010 open(IN, $buildlog) or dodie "Can't open $buildlog";
2011 while (<IN>) {
2012 if (/$check_build_re/) {
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002013 my $warning = process_warning_line $_;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002014
Steven Rostedt (Red Hat)73287352013-02-18 09:35:49 -05002015 if (!defined $warnings_list{$warning}) {
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05002016 fail "New warning found (not in $warnings_file)\n$_\n";
2017 $no_reboot = $save_no_reboot;
2018 return 0;
2019 }
2020 }
2021 }
2022 $no_reboot = $save_no_reboot;
2023 close(IN);
2024}
2025
2026sub check_patch_buildlog {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002027 my ($patch) = @_;
2028
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002029 my @files = `git show $patch | diffstat -l`;
2030
Steven Rostedt (Red Hat)35275682013-01-30 12:28:15 -05002031 foreach my $file (@files) {
2032 chomp $file;
2033 }
2034
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002035 open(IN, "git show $patch |") or
2036 dodie "failed to show $patch";
2037 while (<IN>) {
2038 if (m,^--- a/(.*),) {
2039 chomp $1;
2040 $files[$#files] = $1;
2041 }
2042 }
2043 close(IN);
2044
2045 open(IN, $buildlog) or dodie "Can't open $buildlog";
2046 while (<IN>) {
2047 if (/^\s*(.*?):.*(warning|error)/) {
2048 my $err = $1;
2049 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002050 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002051 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002052 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002053 }
2054 }
2055 }
2056 }
2057 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002058
2059 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002060}
2061
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002062sub apply_min_config {
2063 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05002064
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002065 # Read the config file and remove anything that
2066 # is in the force_config hash (from minconfig and others)
2067 # then add the force config back.
2068
2069 doprint "Applying minimum configurations into $output_config.new\n";
2070
2071 open (OUT, ">$outconfig") or
2072 dodie "Can't create $outconfig";
2073
2074 if (-f $output_config) {
2075 open (IN, $output_config) or
2076 dodie "Failed to open $output_config";
2077 while (<IN>) {
2078 if (/^(# )?(CONFIG_[^\s=]*)/) {
2079 next if (defined($force_config{$2}));
2080 }
2081 print OUT;
2082 }
2083 close IN;
2084 }
2085 foreach my $config (keys %force_config) {
2086 print OUT "$force_config{$config}\n";
2087 }
2088 close OUT;
2089
2090 run_command "mv $outconfig $output_config";
2091}
2092
2093sub make_oldconfig {
2094
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002095 my @force_list = keys %force_config;
2096
2097 if ($#force_list >= 0) {
2098 apply_min_config;
2099 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002100
Adam Leefb16d892012-09-01 01:05:17 +08002101 if (!run_command "$make olddefconfig") {
2102 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt18925172012-12-11 20:16:03 -05002103 # try oldnoconfig
2104 doprint "olddefconfig failed, trying make oldnoconfig\n";
2105 if (!run_command "$make oldnoconfig") {
2106 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
2107 # try a yes '' | oldconfig
2108 run_command "yes '' | $make oldconfig" or
2109 dodie "failed make config oldconfig";
2110 }
Steven Rostedt612b9e92011-03-07 13:27:43 -05002111 }
2112}
2113
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002114# read a config file and use this to force new configs.
2115sub load_force_config {
2116 my ($config) = @_;
2117
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002118 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002119 open(IN, $config) or
2120 dodie "failed to read $config";
2121 while (<IN>) {
2122 chomp;
2123 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
2124 $force_config{$1} = $_;
2125 } elsif (/^# (CONFIG_\S*) is not set/) {
2126 $force_config{$1} = $_;
2127 }
2128 }
2129 close IN;
2130}
2131
Steven Rostedt2545eb62010-11-02 15:01:32 -04002132sub build {
2133 my ($type) = @_;
2134
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002135 unlink $buildlog;
2136
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002137 # Failed builds should not reboot the target
2138 my $save_no_reboot = $no_reboot;
2139 $no_reboot = 1;
2140
Steven Rostedt683a3e62012-05-18 13:34:35 -04002141 # Calculate a new version from here.
2142 $have_version = 0;
2143
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002144 if (defined($pre_build)) {
2145 my $ret = run_command $pre_build;
2146 if (!$ret && defined($pre_build_die) &&
2147 $pre_build_die) {
2148 dodie "failed to pre_build\n";
2149 }
2150 }
2151
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002152 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002153 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002154 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002155
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002156 $type = "oldconfig";
2157 }
2158
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002159 # old config can ask questions
2160 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08002161 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002162
2163 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002164 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002165
Andrew Jones13488232011-08-12 15:32:04 +02002166 if (!$noclean) {
2167 run_command "mv $output_config $outputdir/config_temp" or
2168 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002169
Andrew Jones13488232011-08-12 15:32:04 +02002170 run_command "$make mrproper" or dodie "make mrproper";
2171
2172 run_command "mv $outputdir/config_temp $output_config" or
2173 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002174 }
2175
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002176 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05002177 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002178 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002179 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04002180 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04002181
2182 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04002183 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
2184 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04002185 close(OUT);
2186
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002187 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002188 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04002189 }
2190
Adam Leefb16d892012-09-01 01:05:17 +08002191 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002192 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05002193 dodie "failed make config";
2194 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002195 # Run old config regardless, to enforce min configurations
2196 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002197
Steven Rostedta75fece2010-11-02 14:58:27 -04002198 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002199 my $build_ret = run_command "$make $build_options";
2200 undef $redirect;
2201
2202 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04002203 # Because a post build may change the kernel version
2204 # do it now.
2205 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04002206 my $ret = run_command $post_build;
2207 if (!$ret && defined($post_build_die) &&
2208 $post_build_die) {
2209 dodie "failed to post_build\n";
2210 }
2211 }
2212
2213 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002214 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002215 if ($in_bisect) {
2216 $no_reboot = $save_no_reboot;
2217 return 0;
2218 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002219 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002220 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002221
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04002222 $no_reboot = $save_no_reboot;
2223
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002224 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04002225}
2226
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002227sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04002228 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04002229 if (defined($poweroff_after_halt)) {
2230 sleep $poweroff_after_halt;
2231 run_command "$power_off";
2232 }
2233 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002234 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002235 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002236 }
2237}
2238
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002239sub success {
2240 my ($i) = @_;
2241
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002242 if (defined($post_test)) {
2243 run_command $post_test;
2244 }
2245
Steven Rostedte48c5292010-11-02 14:35:37 -04002246 $successes++;
2247
Steven Rostedt9064af52011-06-13 10:38:48 -04002248 my $name = "";
2249
2250 if (defined($test_name)) {
2251 $name = " ($test_name)";
2252 }
2253
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002254 doprint "\n\n*******************************************\n";
2255 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002256 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002257 doprint "*******************************************\n";
2258 doprint "*******************************************\n";
2259
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302260 if (defined($store_successes)) {
2261 save_logs "success", $store_successes;
2262 }
2263
Steven Rostedt576f6272010-11-02 14:58:38 -04002264 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002265 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002266 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002267 }
2268}
2269
Steven Rostedtc960bb92011-03-08 09:22:39 -05002270sub answer_bisect {
2271 for (;;) {
2272 doprint "Pass or fail? [p/f]";
2273 my $ans = <STDIN>;
2274 chomp $ans;
2275 if ($ans eq "p" || $ans eq "P") {
2276 return 1;
2277 } elsif ($ans eq "f" || $ans eq "F") {
2278 return 0;
2279 } else {
2280 print "Please answer 'P' or 'F'\n";
2281 }
2282 }
2283}
2284
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002285sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002286 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002287
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002288 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002289 $reboot_on_error = 0;
2290 $poweroff_on_error = 0;
2291 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002292
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302293 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002294 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302295 undef $redirect;
2296
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002297 exit $failed;
2298}
2299
2300my $child_done;
2301
2302sub child_finished {
2303 $child_done = 1;
2304}
2305
2306sub do_run_test {
2307 my $child_pid;
2308 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002309 my $line;
2310 my $full_line;
2311 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002312 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002313
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002314 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002315
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002316 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002317
2318 $child_done = 0;
2319
2320 $SIG{CHLD} = qw(child_finished);
2321
2322 $child_pid = fork;
2323
2324 child_run_test if (!$child_pid);
2325
2326 $full_line = "";
2327
2328 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002329 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002330 if (defined($line)) {
2331
2332 # we are not guaranteed to get a full line
2333 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002334 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002335
2336 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002337 if ($ignore_errors) {
2338 $bug_ignored = 1;
2339 } else {
2340 $bug = 1;
2341 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002342 }
2343
2344 if ($full_line =~ /Kernel panic -/) {
2345 $bug = 1;
2346 }
2347
2348 if ($line =~ /\n/) {
2349 $full_line = "";
2350 }
2351 }
2352 } while (!$child_done && !$bug);
2353
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002354 if (!$bug && $bug_ignored) {
2355 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2356 }
2357
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002358 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002359 my $failure_start = time;
2360 my $now;
2361 do {
2362 $line = wait_for_input($monitor_fp, 1);
2363 if (defined($line)) {
2364 doprint $line;
2365 }
2366 $now = time;
2367 if ($now - $failure_start >= $stop_after_failure) {
2368 last;
2369 }
2370 } while (defined($line));
2371
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002372 doprint "Detected kernel crash!\n";
2373 # kill the child with extreme prejudice
2374 kill 9, $child_pid;
2375 }
2376
2377 waitpid $child_pid, 0;
2378 $child_exit = $?;
2379
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002380 if (!$bug && $in_bisect) {
2381 if (defined($bisect_ret_good)) {
2382 if ($child_exit == $bisect_ret_good) {
2383 return 1;
2384 }
2385 }
2386 if (defined($bisect_ret_skip)) {
2387 if ($child_exit == $bisect_ret_skip) {
2388 return -1;
2389 }
2390 }
2391 if (defined($bisect_ret_abort)) {
2392 if ($child_exit == $bisect_ret_abort) {
2393 fail "test abort" and return -2;
2394 }
2395 }
2396 if (defined($bisect_ret_bad)) {
2397 if ($child_exit == $bisect_ret_skip) {
2398 return 0;
2399 }
2400 }
2401 if (defined($bisect_ret_default)) {
2402 if ($bisect_ret_default eq "good") {
2403 return 1;
2404 } elsif ($bisect_ret_default eq "bad") {
2405 return 0;
2406 } elsif ($bisect_ret_default eq "skip") {
2407 return -1;
2408 } elsif ($bisect_ret_default eq "abort") {
2409 return -2;
2410 } else {
2411 fail "unknown default action: $bisect_ret_default"
2412 and return -2;
2413 }
2414 }
2415 }
2416
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002417 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002418 return 0 if $in_bisect;
2419 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002420 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002421 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002422}
2423
Steven Rostedta75fece2010-11-02 14:58:27 -04002424sub run_git_bisect {
2425 my ($command) = @_;
2426
2427 doprint "$command ... ";
2428
2429 my $output = `$command 2>&1`;
2430 my $ret = $?;
2431
2432 logit $output;
2433
2434 if ($ret) {
2435 doprint "FAILED\n";
2436 dodie "Failed to git bisect";
2437 }
2438
2439 doprint "SUCCESS\n";
2440 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2441 doprint "$1 [$2]\n";
2442 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002443 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002444 doprint "Found bad commit... $1\n";
2445 return 0;
2446 } else {
2447 # we already logged it, just print it now.
2448 print $output;
2449 }
2450
2451 return 1;
2452}
2453
Steven Rostedtc23dca72011-03-08 09:26:31 -05002454sub bisect_reboot {
2455 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002456 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002457}
2458
2459# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002460sub run_bisect_test {
2461 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002462
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002463 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002464 my $result;
2465 my $output;
2466 my $ret;
2467
Steven Rostedt0a05c762010-11-08 11:14:10 -05002468 $in_bisect = 1;
2469
2470 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002471
2472 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002473 if ($failed && $bisect_skip) {
2474 $in_bisect = 0;
2475 return -1;
2476 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002477 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002478
2479 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002480 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002481
2482 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002483 if ($failed && $bisect_skip) {
2484 end_monitor;
2485 bisect_reboot;
2486 $in_bisect = 0;
2487 return -1;
2488 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002489 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002490
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002491 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002492 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002493 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002494 }
2495
2496 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002497 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002498 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002499 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002500 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002501
2502 # reboot the box to a kernel we can ssh to
2503 if ($type ne "build") {
2504 bisect_reboot;
2505 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002506 $in_bisect = 0;
2507
2508 return $result;
2509}
2510
2511sub run_bisect {
2512 my ($type) = @_;
2513 my $buildtype = "oldconfig";
2514
2515 # We should have a minconfig to use?
2516 if (defined($minconfig)) {
2517 $buildtype = "useconfig:$minconfig";
2518 }
2519
2520 my $ret = run_bisect_test $type, $buildtype;
2521
Steven Rostedtc960bb92011-03-08 09:22:39 -05002522 if ($bisect_manual) {
2523 $ret = answer_bisect;
2524 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002525
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002526 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002527 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002528 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002529 }
2530
Steven Rostedtc23dca72011-03-08 09:26:31 -05002531 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002532 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002533 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002534 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002535 } elsif ($bisect_skip) {
2536 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2537 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002538 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002539}
2540
Steven Rostedtdad98752011-11-22 20:48:57 -05002541sub update_bisect_replay {
2542 my $tmp_log = "$tmpdir/ktest_bisect_log";
2543 run_command "git bisect log > $tmp_log" or
2544 die "can't create bisect log";
2545 return $tmp_log;
2546}
2547
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002548sub bisect {
2549 my ($i) = @_;
2550
2551 my $result;
2552
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002553 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2554 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2555 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002556
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002557 my $good = $bisect_good;
2558 my $bad = $bisect_bad;
2559 my $type = $bisect_type;
2560 my $start = $bisect_start;
2561 my $replay = $bisect_replay;
2562 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002563
2564 if (defined($start_files)) {
2565 $start_files = " -- " . $start_files;
2566 } else {
2567 $start_files = "";
2568 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002569
Steven Rostedta57419b2010-11-02 15:13:54 -04002570 # convert to true sha1's
2571 $good = get_sha1($good);
2572 $bad = get_sha1($bad);
2573
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002574 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002575 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2576 $reverse_bisect = 1;
2577 } else {
2578 $reverse_bisect = 0;
2579 }
2580
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002581 # Can't have a test without having a test to run
2582 if ($type eq "test" && !defined($run_test)) {
2583 $type = "boot";
2584 }
2585
Steven Rostedtdad98752011-11-22 20:48:57 -05002586 # Check if a bisect was running
2587 my $bisect_start_file = "$builddir/.git/BISECT_START";
2588
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002589 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002590 my $do_check = defined($check) && $check ne "0";
2591
2592 if ( -f $bisect_start_file ) {
2593 print "Bisect in progress found\n";
2594 if ($do_check) {
2595 print " If you say yes, then no checks of good or bad will be done\n";
2596 }
2597 if (defined($replay)) {
2598 print "** BISECT_REPLAY is defined in config file **";
2599 print " Ignore config option and perform new git bisect log?\n";
2600 if (read_ync " (yes, no, or cancel) ") {
2601 $replay = update_bisect_replay;
2602 $do_check = 0;
2603 }
2604 } elsif (read_yn "read git log and continue?") {
2605 $replay = update_bisect_replay;
2606 $do_check = 0;
2607 }
2608 }
2609
2610 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002611
2612 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002613 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002614
2615 if ($check ne "good") {
2616 doprint "TESTING BISECT BAD [$bad]\n";
2617 run_command "git checkout $bad" or
2618 die "Failed to checkout $bad";
2619
2620 $result = run_bisect $type;
2621
2622 if ($result ne "bad") {
2623 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2624 }
2625 }
2626
2627 if ($check ne "bad") {
2628 doprint "TESTING BISECT GOOD [$good]\n";
2629 run_command "git checkout $good" or
2630 die "Failed to checkout $good";
2631
2632 $result = run_bisect $type;
2633
2634 if ($result ne "good") {
2635 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2636 }
2637 }
2638
2639 # checkout where we started
2640 run_command "git checkout $head" or
2641 die "Failed to checkout $head";
2642 }
2643
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002644 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002645 dodie "could not start bisect";
2646
2647 run_command "git bisect good $good" or
2648 dodie "could not set bisect good to $good";
2649
2650 run_git_bisect "git bisect bad $bad" or
2651 dodie "could not set bisect bad to $bad";
2652
2653 if (defined($replay)) {
2654 run_command "git bisect replay $replay" or
2655 dodie "failed to run replay";
2656 }
2657
2658 if (defined($start)) {
2659 run_command "git checkout $start" or
2660 dodie "failed to checkout $start";
2661 }
2662
2663 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002664 do {
2665 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002666 $test = run_git_bisect "git bisect $result";
2667 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002668
2669 run_command "git bisect log" or
2670 dodie "could not capture git bisect log";
2671
2672 run_command "git bisect reset" or
2673 dodie "could not reset git bisect";
2674
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002675 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002676
Steven Rostedt0a05c762010-11-08 11:14:10 -05002677 success $i;
2678}
2679
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002680# config_ignore holds the configs that were set (or unset) for
2681# a good config and we will ignore these configs for the rest
2682# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002683my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002684
2685# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002686my %config_set;
2687
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002688# config_off holds the set of configs that the bad config had disabled.
2689# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002690# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002691my %config_off;
2692
2693# config_off_tmp holds a set of configs to turn off for now
2694my @config_off_tmp;
2695
2696# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002697my %config_list;
2698my %null_config;
2699
2700my %dependency;
2701
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002702sub assign_configs {
2703 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002704
2705 open (IN, $config)
2706 or dodie "Failed to read $config";
2707
2708 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002709 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002710 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002711 }
2712 }
2713
2714 close(IN);
2715}
2716
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002717sub process_config_ignore {
2718 my ($config) = @_;
2719
2720 assign_configs \%config_ignore, $config;
2721}
2722
Steven Rostedt0a05c762010-11-08 11:14:10 -05002723sub read_current_config {
2724 my ($config_ref) = @_;
2725
2726 %{$config_ref} = ();
2727 undef %{$config_ref};
2728
2729 my @key = keys %{$config_ref};
2730 if ($#key >= 0) {
2731 print "did not delete!\n";
2732 exit;
2733 }
2734 open (IN, "$output_config");
2735
2736 while (<IN>) {
2737 if (/^(CONFIG\S+)=(.*)/) {
2738 ${$config_ref}{$1} = $2;
2739 }
2740 }
2741 close(IN);
2742}
2743
2744sub get_dependencies {
2745 my ($config) = @_;
2746
2747 my $arr = $dependency{$config};
2748 if (!defined($arr)) {
2749 return ();
2750 }
2751
2752 my @deps = @{$arr};
2753
2754 foreach my $dep (@{$arr}) {
2755 print "ADD DEP $dep\n";
2756 @deps = (@deps, get_dependencies $dep);
2757 }
2758
2759 return @deps;
2760}
2761
2762sub create_config {
2763 my @configs = @_;
2764
2765 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2766
2767 foreach my $config (@configs) {
2768 print OUT "$config_set{$config}\n";
2769 my @deps = get_dependencies $config;
2770 foreach my $dep (@deps) {
2771 print OUT "$config_set{$dep}\n";
2772 }
2773 }
2774
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002775 # turn off configs to keep off
2776 foreach my $config (keys %config_off) {
2777 print OUT "# $config is not set\n";
2778 }
2779
2780 # turn off configs that should be off for now
2781 foreach my $config (@config_off_tmp) {
2782 print OUT "# $config is not set\n";
2783 }
2784
Steven Rostedt0a05c762010-11-08 11:14:10 -05002785 foreach my $config (keys %config_ignore) {
2786 print OUT "$config_ignore{$config}\n";
2787 }
2788 close(OUT);
2789
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002790 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002791}
2792
2793sub compare_configs {
2794 my (%a, %b) = @_;
2795
2796 foreach my $item (keys %a) {
2797 if (!defined($b{$item})) {
2798 print "diff $item\n";
2799 return 1;
2800 }
2801 delete $b{$item};
2802 }
2803
2804 my @keys = keys %b;
2805 if ($#keys) {
2806 print "diff2 $keys[0]\n";
2807 }
2808 return -1 if ($#keys >= 0);
2809
2810 return 0;
2811}
2812
2813sub run_config_bisect_test {
2814 my ($type) = @_;
2815
2816 return run_bisect_test $type, "oldconfig";
2817}
2818
2819sub process_passed {
2820 my (%configs) = @_;
2821
2822 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2823 # Passed! All these configs are part of a good compile.
2824 # Add them to the min options.
2825 foreach my $config (keys %configs) {
2826 if (defined($config_list{$config})) {
2827 doprint " removing $config\n";
2828 $config_ignore{$config} = $config_list{$config};
2829 delete $config_list{$config};
2830 }
2831 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002832 doprint "config copied to $outputdir/config_good\n";
2833 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002834}
2835
2836sub process_failed {
2837 my ($config) = @_;
2838
2839 doprint "\n\n***************************************\n";
2840 doprint "Found bad config: $config\n";
2841 doprint "***************************************\n\n";
2842}
2843
2844sub run_config_bisect {
2845
2846 my @start_list = keys %config_list;
2847
2848 if ($#start_list < 0) {
2849 doprint "No more configs to test!!!\n";
2850 return -1;
2851 }
2852
2853 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002854 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002855 my $ret;
2856 my %current_config;
2857
2858 my $count = $#start_list + 1;
2859 doprint " $count configs to test\n";
2860
2861 my $half = int($#start_list / 2);
2862
2863 do {
2864 my @tophalf = @start_list[0 .. $half];
2865
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002866 # keep the bottom half off
2867 if ($half < $#start_list) {
2868 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2869 } else {
2870 @config_off_tmp = ();
2871 }
2872
Steven Rostedt0a05c762010-11-08 11:14:10 -05002873 create_config @tophalf;
2874 read_current_config \%current_config;
2875
2876 $count = $#tophalf + 1;
2877 doprint "Testing $count configs\n";
2878 my $found = 0;
2879 # make sure we test something
2880 foreach my $config (@tophalf) {
2881 if (defined($current_config{$config})) {
2882 logit " $config\n";
2883 $found = 1;
2884 }
2885 }
2886 if (!$found) {
2887 # try the other half
2888 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002889
2890 # keep the top half off
2891 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002892 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002893
Steven Rostedt0a05c762010-11-08 11:14:10 -05002894 create_config @tophalf;
2895 read_current_config \%current_config;
2896 foreach my $config (@tophalf) {
2897 if (defined($current_config{$config})) {
2898 logit " $config\n";
2899 $found = 1;
2900 }
2901 }
2902 if (!$found) {
2903 doprint "Failed: Can't make new config with current configs\n";
2904 foreach my $config (@start_list) {
2905 doprint " CONFIG: $config\n";
2906 }
2907 return -1;
2908 }
2909 $count = $#tophalf + 1;
2910 doprint "Testing $count configs\n";
2911 }
2912
2913 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002914 if ($bisect_manual) {
2915 $ret = answer_bisect;
2916 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002917 if ($ret) {
2918 process_passed %current_config;
2919 return 0;
2920 }
2921
2922 doprint "This config had a failure.\n";
2923 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002924 doprint "config copied to $outputdir/config_bad\n";
2925 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002926
2927 # A config exists in this group that was bad.
2928 foreach my $config (keys %config_list) {
2929 if (!defined($current_config{$config})) {
2930 doprint " removing $config\n";
2931 delete $config_list{$config};
2932 }
2933 }
2934
2935 @start_list = @tophalf;
2936
2937 if ($#start_list == 0) {
2938 process_failed $start_list[0];
2939 return 1;
2940 }
2941
2942 # remove half the configs we are looking at and see if
2943 # they are good.
2944 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002945 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002946
Steven Rostedtc960bb92011-03-08 09:22:39 -05002947 # we found a single config, try it again unless we are running manually
2948
2949 if ($bisect_manual) {
2950 process_failed $start_list[0];
2951 return 1;
2952 }
2953
Steven Rostedt0a05c762010-11-08 11:14:10 -05002954 my @tophalf = @start_list[0 .. 0];
2955
2956 $ret = run_config_bisect_test $type;
2957 if ($ret) {
2958 process_passed %current_config;
2959 return 0;
2960 }
2961
2962 process_failed $start_list[0];
2963 return 1;
2964}
2965
2966sub config_bisect {
2967 my ($i) = @_;
2968
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002969 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002970
2971 my $tmpconfig = "$tmpdir/use_config";
2972
Steven Rostedt30f75da2011-06-13 10:35:35 -04002973 if (defined($config_bisect_good)) {
2974 process_config_ignore $config_bisect_good;
2975 }
2976
Steven Rostedt0a05c762010-11-08 11:14:10 -05002977 # Make the file with the bad config and the min config
2978 if (defined($minconfig)) {
2979 # read the min config for things to ignore
2980 run_command "cp $minconfig $tmpconfig" or
2981 dodie "failed to copy $minconfig to $tmpconfig";
2982 } else {
2983 unlink $tmpconfig;
2984 }
2985
Steven Rostedt0a05c762010-11-08 11:14:10 -05002986 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002987 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002988 process_config_ignore $tmpconfig;
2989 }
2990
2991 # now process the start config
2992 run_command "cp $start_config $output_config" or
2993 dodie "failed to copy $start_config to $output_config";
2994
2995 # read directly what we want to check
2996 my %config_check;
2997 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002998 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002999
3000 while (<IN>) {
3001 if (/^((CONFIG\S*)=.*)/) {
3002 $config_check{$2} = $1;
3003 }
3004 }
3005 close(IN);
3006
Steven Rostedt250bae82011-07-15 22:05:59 -04003007 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04003008 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003009
3010 # check to see what we lost (or gained)
3011 open (IN, $output_config)
3012 or dodie "Failed to read $start_config";
3013
3014 my %removed_configs;
3015 my %added_configs;
3016
3017 while (<IN>) {
3018 if (/^((CONFIG\S*)=.*)/) {
3019 # save off all options
3020 $config_set{$2} = $1;
3021 if (defined($config_check{$2})) {
3022 if (defined($config_ignore{$2})) {
3023 $removed_configs{$2} = $1;
3024 } else {
3025 $config_list{$2} = $1;
3026 }
3027 } elsif (!defined($config_ignore{$2})) {
3028 $added_configs{$2} = $1;
3029 $config_list{$2} = $1;
3030 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003031 } elsif (/^# ((CONFIG\S*).*)/) {
3032 # Keep these configs disabled
3033 $config_set{$2} = $1;
3034 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003035 }
3036 }
3037 close(IN);
3038
3039 my @confs = keys %removed_configs;
3040 if ($#confs >= 0) {
3041 doprint "Configs overridden by default configs and removed from check:\n";
3042 foreach my $config (@confs) {
3043 doprint " $config\n";
3044 }
3045 }
3046 @confs = keys %added_configs;
3047 if ($#confs >= 0) {
3048 doprint "Configs appearing in make oldconfig and added:\n";
3049 foreach my $config (@confs) {
3050 doprint " $config\n";
3051 }
3052 }
3053
3054 my %config_test;
3055 my $once = 0;
3056
Steven Rostedtcf79fab2012-07-19 15:29:43 -04003057 @config_off_tmp = ();
3058
Steven Rostedt0a05c762010-11-08 11:14:10 -05003059 # Sometimes kconfig does weird things. We must make sure
3060 # that the config we autocreate has everything we need
3061 # to test, otherwise we may miss testing configs, or
3062 # may not be able to create a new config.
3063 # Here we create a config with everything set.
3064 create_config (keys %config_list);
3065 read_current_config \%config_test;
3066 foreach my $config (keys %config_list) {
3067 if (!defined($config_test{$config})) {
3068 if (!$once) {
3069 $once = 1;
3070 doprint "Configs not produced by kconfig (will not be checked):\n";
3071 }
3072 doprint " $config\n";
3073 delete $config_list{$config};
3074 }
3075 }
3076 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04003077
3078 if (defined($config_bisect_check) && $config_bisect_check) {
3079 doprint " Checking to make sure bad config with min config fails\n";
3080 create_config keys %config_list;
3081 $ret = run_config_bisect_test $config_bisect_type;
3082 if ($ret) {
3083 doprint " FAILED! Bad config with min config boots fine\n";
3084 return -1;
3085 }
3086 doprint " Bad config with min config fails as expected\n";
3087 }
3088
Steven Rostedt0a05c762010-11-08 11:14:10 -05003089 do {
3090 $ret = run_config_bisect;
3091 } while (!$ret);
3092
3093 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003094
3095 success $i;
3096}
3097
Steven Rostedt27d934b2011-05-20 09:18:18 -04003098sub patchcheck_reboot {
3099 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003100 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04003101}
3102
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003103sub patchcheck {
3104 my ($i) = @_;
3105
3106 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003107 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003108 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003109 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003110
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003111 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003112
3113 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003114 if (defined($patchcheck_end)) {
3115 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003116 }
3117
Steven Rostedta57419b2010-11-02 15:13:54 -04003118 # Get the true sha1's since we can use things like HEAD~3
3119 $start = get_sha1($start);
3120 $end = get_sha1($end);
3121
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003122 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003123
3124 # Can't have a test without having a test to run
3125 if ($type eq "test" && !defined($run_test)) {
3126 $type = "boot";
3127 }
3128
3129 open (IN, "git log --pretty=oneline $end|") or
3130 dodie "could not get git list";
3131
3132 my @list;
3133
3134 while (<IN>) {
3135 chomp;
3136 $list[$#list+1] = $_;
3137 last if (/^$start/);
3138 }
3139 close(IN);
3140
3141 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003142 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003143 }
3144
3145 # go backwards in the list
3146 @list = reverse @list;
3147
3148 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04003149 my %ignored_warnings;
3150
3151 if (defined($ignore_warnings)) {
3152 foreach my $sha1 (split /\s+/, $ignore_warnings) {
3153 $ignored_warnings{$sha1} = 1;
3154 }
3155 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003156
3157 $in_patchcheck = 1;
3158 foreach my $item (@list) {
3159 my $sha1 = $item;
3160 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
3161
3162 doprint "\nProcessing commit $item\n\n";
3163
3164 run_command "git checkout $sha1" or
3165 die "Failed to checkout $sha1";
3166
3167 # only clean on the first and last patch
3168 if ($item eq $list[0] ||
3169 $item eq $list[$#list]) {
3170 $noclean = $save_clean;
3171 } else {
3172 $noclean = 1;
3173 }
3174
3175 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003176 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003177 } else {
3178 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003179 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003180 }
3181
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003182 # No need to do per patch checking if warnings file exists
3183 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3184 check_patch_buildlog $sha1 or return 0;
Steven Rostedt19902072011-06-14 20:46:25 -04003185 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003186
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003187 check_buildlog or return 0;
3188
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003189 next if ($type eq "build");
3190
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003191 my $failed = 0;
3192
Steven Rostedtddf607e2011-06-14 20:49:13 -04003193 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003194
3195 if (!$failed && $type ne "boot"){
3196 do_run_test or $failed = 1;
3197 }
3198 end_monitor;
3199 return 0 if ($failed);
3200
Steven Rostedt27d934b2011-05-20 09:18:18 -04003201 patchcheck_reboot;
3202
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003203 }
3204 $in_patchcheck = 0;
3205 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003206
3207 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003208}
3209
Steven Rostedtb9066f62011-07-15 21:25:24 -04003210my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003211my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003212my $iflevel = 0;
3213my @ifdeps;
3214
3215# prevent recursion
3216my %read_kconfigs;
3217
Steven Rostedtac6974c2011-10-04 09:40:17 -04003218sub add_dep {
3219 # $config depends on $dep
3220 my ($config, $dep) = @_;
3221
3222 if (defined($depends{$config})) {
3223 $depends{$config} .= " " . $dep;
3224 } else {
3225 $depends{$config} = $dep;
3226 }
3227
3228 # record the number of configs depending on $dep
3229 if (defined $depcount{$dep}) {
3230 $depcount{$dep}++;
3231 } else {
3232 $depcount{$dep} = 1;
3233 }
3234}
3235
Steven Rostedtb9066f62011-07-15 21:25:24 -04003236# taken from streamline_config.pl
3237sub read_kconfig {
3238 my ($kconfig) = @_;
3239
3240 my $state = "NONE";
3241 my $config;
3242 my @kconfigs;
3243
3244 my $cont = 0;
3245 my $line;
3246
3247
3248 if (! -f $kconfig) {
3249 doprint "file $kconfig does not exist, skipping\n";
3250 return;
3251 }
3252
3253 open(KIN, "$kconfig")
3254 or die "Can't open $kconfig";
3255 while (<KIN>) {
3256 chomp;
3257
3258 # Make sure that lines ending with \ continue
3259 if ($cont) {
3260 $_ = $line . " " . $_;
3261 }
3262
3263 if (s/\\$//) {
3264 $cont = 1;
3265 $line = $_;
3266 next;
3267 }
3268
3269 $cont = 0;
3270
3271 # collect any Kconfig sources
3272 if (/^source\s*"(.*)"/) {
3273 $kconfigs[$#kconfigs+1] = $1;
3274 }
3275
3276 # configs found
3277 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3278 $state = "NEW";
3279 $config = $2;
3280
3281 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003282 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003283 }
3284
3285 # collect the depends for the config
3286 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3287
Steven Rostedtac6974c2011-10-04 09:40:17 -04003288 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003289
3290 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003291 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3292
3293 # selected by depends on config
3294 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003295
3296 # Check for if statements
3297 } elsif (/^if\s+(.*\S)\s*$/) {
3298 my $deps = $1;
3299 # remove beginning and ending non text
3300 $deps =~ s/^[^a-zA-Z0-9_]*//;
3301 $deps =~ s/[^a-zA-Z0-9_]*$//;
3302
3303 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3304
3305 $ifdeps[$iflevel++] = join ':', @deps;
3306
3307 } elsif (/^endif/) {
3308
3309 $iflevel-- if ($iflevel);
3310
3311 # stop on "help"
3312 } elsif (/^\s*help\s*$/) {
3313 $state = "NONE";
3314 }
3315 }
3316 close(KIN);
3317
3318 # read in any configs that were found.
3319 foreach $kconfig (@kconfigs) {
3320 if (!defined($read_kconfigs{$kconfig})) {
3321 $read_kconfigs{$kconfig} = 1;
3322 read_kconfig("$builddir/$kconfig");
3323 }
3324 }
3325}
3326
3327sub read_depends {
3328 # find out which arch this is by the kconfig file
3329 open (IN, $output_config)
3330 or dodie "Failed to read $output_config";
3331 my $arch;
3332 while (<IN>) {
3333 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3334 $arch = $1;
3335 last;
3336 }
3337 }
3338 close IN;
3339
3340 if (!defined($arch)) {
3341 doprint "Could not find arch from config file\n";
3342 doprint "no dependencies used\n";
3343 return;
3344 }
3345
3346 # arch is really the subarch, we need to know
3347 # what directory to look at.
3348 if ($arch eq "i386" || $arch eq "x86_64") {
3349 $arch = "x86";
3350 } elsif ($arch =~ /^tile/) {
3351 $arch = "tile";
3352 }
3353
3354 my $kconfig = "$builddir/arch/$arch/Kconfig";
3355
3356 if (! -f $kconfig && $arch =~ /\d$/) {
3357 my $orig = $arch;
3358 # some subarchs have numbers, truncate them
3359 $arch =~ s/\d*$//;
3360 $kconfig = "$builddir/arch/$arch/Kconfig";
3361 if (! -f $kconfig) {
3362 doprint "No idea what arch dir $orig is for\n";
3363 doprint "no dependencies used\n";
3364 return;
3365 }
3366 }
3367
3368 read_kconfig($kconfig);
3369}
3370
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003371sub read_config_list {
3372 my ($config) = @_;
3373
3374 open (IN, $config)
3375 or dodie "Failed to read $config";
3376
3377 while (<IN>) {
3378 if (/^((CONFIG\S*)=.*)/) {
3379 if (!defined($config_ignore{$2})) {
3380 $config_list{$2} = $1;
3381 }
3382 }
3383 }
3384
3385 close(IN);
3386}
3387
3388sub read_output_config {
3389 my ($config) = @_;
3390
3391 assign_configs \%config_ignore, $config;
3392}
3393
3394sub make_new_config {
3395 my @configs = @_;
3396
3397 open (OUT, ">$output_config")
3398 or dodie "Failed to write $output_config";
3399
3400 foreach my $config (@configs) {
3401 print OUT "$config\n";
3402 }
3403 close OUT;
3404}
3405
Steven Rostedtac6974c2011-10-04 09:40:17 -04003406sub chomp_config {
3407 my ($config) = @_;
3408
3409 $config =~ s/CONFIG_//;
3410
3411 return $config;
3412}
3413
Steven Rostedtb9066f62011-07-15 21:25:24 -04003414sub get_depends {
3415 my ($dep) = @_;
3416
Steven Rostedtac6974c2011-10-04 09:40:17 -04003417 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003418
3419 $dep = $depends{"$kconfig"};
3420
3421 # the dep string we have saves the dependencies as they
3422 # were found, including expressions like ! && ||. We
3423 # want to split this out into just an array of configs.
3424
3425 my $valid = "A-Za-z_0-9";
3426
3427 my @configs;
3428
3429 while ($dep =~ /[$valid]/) {
3430
3431 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3432 my $conf = "CONFIG_" . $1;
3433
3434 $configs[$#configs + 1] = $conf;
3435
3436 $dep =~ s/^[^$valid]*[$valid]+//;
3437 } else {
3438 die "this should never happen";
3439 }
3440 }
3441
3442 return @configs;
3443}
3444
3445my %min_configs;
3446my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003447my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003448my %processed_configs;
3449my %nochange_config;
3450
3451sub test_this_config {
3452 my ($config) = @_;
3453
3454 my $found;
3455
3456 # if we already processed this config, skip it
3457 if (defined($processed_configs{$config})) {
3458 return undef;
3459 }
3460 $processed_configs{$config} = 1;
3461
3462 # if this config failed during this round, skip it
3463 if (defined($nochange_config{$config})) {
3464 return undef;
3465 }
3466
Steven Rostedtac6974c2011-10-04 09:40:17 -04003467 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003468
3469 # Test dependencies first
3470 if (defined($depends{"$kconfig"})) {
3471 my @parents = get_depends $config;
3472 foreach my $parent (@parents) {
3473 # if the parent is in the min config, check it first
3474 next if (!defined($min_configs{$parent}));
3475 $found = test_this_config($parent);
3476 if (defined($found)) {
3477 return $found;
3478 }
3479 }
3480 }
3481
3482 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003483 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003484 # .config to make sure it is missing the config that
3485 # we had before
3486 my %configs = %min_configs;
3487 delete $configs{$config};
3488 make_new_config ((values %configs), (values %keep_configs));
3489 make_oldconfig;
3490 undef %configs;
3491 assign_configs \%configs, $output_config;
3492
3493 return $config if (!defined($configs{$config}));
3494
3495 doprint "disabling config $config did not change .config\n";
3496
3497 $nochange_config{$config} = 1;
3498
3499 return undef;
3500}
3501
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003502sub make_min_config {
3503 my ($i) = @_;
3504
Steven Rostedtccc513b2012-05-21 17:13:40 -04003505 my $type = $minconfig_type;
3506 if ($type ne "boot" && $type ne "test") {
3507 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3508 " make_min_config works only with 'boot' and 'test'\n" and return;
3509 }
3510
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003511 if (!defined($output_minconfig)) {
3512 fail "OUTPUT_MIN_CONFIG not defined" and return;
3513 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003514
3515 # If output_minconfig exists, and the start_minconfig
3516 # came from min_config, than ask if we should use
3517 # that instead.
3518 if (-f $output_minconfig && !$start_minconfig_defined) {
3519 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003520 if (!defined($use_output_minconfig)) {
3521 if (read_yn " Use it as minconfig?") {
3522 $start_minconfig = $output_minconfig;
3523 }
3524 } elsif ($use_output_minconfig > 0) {
3525 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003526 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003527 } else {
3528 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003529 }
3530 }
3531
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003532 if (!defined($start_minconfig)) {
3533 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3534 }
3535
Steven Rostedt35ce5952011-07-15 21:57:25 -04003536 my $temp_config = "$tmpdir/temp_config";
3537
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003538 # First things first. We build an allnoconfig to find
3539 # out what the defaults are that we can't touch.
3540 # Some are selections, but we really can't handle selections.
3541
3542 my $save_minconfig = $minconfig;
3543 undef $minconfig;
3544
3545 run_command "$make allnoconfig" or return 0;
3546
Steven Rostedtb9066f62011-07-15 21:25:24 -04003547 read_depends;
3548
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003549 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003550
Steven Rostedt43d1b652011-07-15 22:01:56 -04003551 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003552 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003553
3554 if (defined($ignore_config)) {
3555 # make sure the file exists
3556 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003557 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003558 }
3559
Steven Rostedt43d1b652011-07-15 22:01:56 -04003560 %keep_configs = %save_configs;
3561
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003562 doprint "Load initial configs from $start_minconfig\n";
3563
3564 # Look at the current min configs, and save off all the
3565 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003566 assign_configs \%min_configs, $start_minconfig;
3567
3568 my @config_keys = keys %min_configs;
3569
Steven Rostedtac6974c2011-10-04 09:40:17 -04003570 # All configs need a depcount
3571 foreach my $config (@config_keys) {
3572 my $kconfig = chomp_config $config;
3573 if (!defined $depcount{$kconfig}) {
3574 $depcount{$kconfig} = 0;
3575 }
3576 }
3577
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003578 # Remove anything that was set by the make allnoconfig
3579 # we shouldn't need them as they get set for us anyway.
3580 foreach my $config (@config_keys) {
3581 # Remove anything in the ignore_config
3582 if (defined($keep_configs{$config})) {
3583 my $file = $ignore_config;
3584 $file =~ s,.*/(.*?)$,$1,;
3585 doprint "$config set by $file ... ignored\n";
3586 delete $min_configs{$config};
3587 next;
3588 }
3589 # But make sure the settings are the same. If a min config
3590 # sets a selection, we do not want to get rid of it if
3591 # it is not the same as what we have. Just move it into
3592 # the keep configs.
3593 if (defined($config_ignore{$config})) {
3594 if ($config_ignore{$config} ne $min_configs{$config}) {
3595 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3596 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3597 $keep_configs{$config} = $min_configs{$config};
3598 } else {
3599 doprint "$config set by allnoconfig ... ignored\n";
3600 }
3601 delete $min_configs{$config};
3602 }
3603 }
3604
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003605 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003606 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003607
3608 while (!$done) {
3609
3610 my $config;
3611 my $found;
3612
3613 # Now disable each config one by one and do a make oldconfig
3614 # till we find a config that changes our list.
3615
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003616 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003617
3618 # Sort keys by who is most dependent on
3619 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3620 @test_configs ;
3621
3622 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003623 my $reset = 1;
3624 for (my $i = 0; $i < $#test_configs; $i++) {
3625 if (!defined($nochange_config{$test_configs[0]})) {
3626 $reset = 0;
3627 last;
3628 }
3629 # This config didn't change the .config last time.
3630 # Place it at the end
3631 my $config = shift @test_configs;
3632 push @test_configs, $config;
3633 }
3634
3635 # if every test config has failed to modify the .config file
3636 # in the past, then reset and start over.
3637 if ($reset) {
3638 undef %nochange_config;
3639 }
3640
Steven Rostedtb9066f62011-07-15 21:25:24 -04003641 undef %processed_configs;
3642
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003643 foreach my $config (@test_configs) {
3644
Steven Rostedtb9066f62011-07-15 21:25:24 -04003645 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003646
Steven Rostedtb9066f62011-07-15 21:25:24 -04003647 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003648
3649 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003650 }
3651
3652 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003653 # we could have failed due to the nochange_config hash
3654 # reset and try again
3655 if (!$take_two) {
3656 undef %nochange_config;
3657 $take_two = 1;
3658 next;
3659 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003660 doprint "No more configs found that we can disable\n";
3661 $done = 1;
3662 last;
3663 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003664 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003665
3666 $config = $found;
3667
3668 doprint "Test with $config disabled\n";
3669
3670 # set in_bisect to keep build and monitor from dieing
3671 $in_bisect = 1;
3672
3673 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003674 build "oldconfig" or $failed = 1;
3675 if (!$failed) {
3676 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003677
3678 if ($type eq "test" && !$failed) {
3679 do_run_test or $failed = 1;
3680 }
3681
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003682 end_monitor;
3683 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003684
3685 $in_bisect = 0;
3686
3687 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003688 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003689 # this config is needed, add it to the ignore list.
3690 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003691 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003692 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003693
3694 # update new ignore configs
3695 if (defined($ignore_config)) {
3696 open (OUT, ">$temp_config")
3697 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003698 foreach my $config (keys %save_configs) {
3699 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003700 }
3701 close OUT;
3702 run_command "mv $temp_config $ignore_config" or
3703 dodie "failed to copy update to $ignore_config";
3704 }
3705
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003706 } else {
3707 # We booted without this config, remove it from the minconfigs.
3708 doprint "$config is not needed, disabling\n";
3709
3710 delete $min_configs{$config};
3711
3712 # Also disable anything that is not enabled in this config
3713 my %configs;
3714 assign_configs \%configs, $output_config;
3715 my @config_keys = keys %min_configs;
3716 foreach my $config (@config_keys) {
3717 if (!defined($configs{$config})) {
3718 doprint "$config is not set, disabling\n";
3719 delete $min_configs{$config};
3720 }
3721 }
3722
3723 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003724 open (OUT, ">$temp_config")
3725 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003726 foreach my $config (keys %keep_configs) {
3727 print OUT "$keep_configs{$config}\n";
3728 }
3729 foreach my $config (keys %min_configs) {
3730 print OUT "$min_configs{$config}\n";
3731 }
3732 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003733
3734 run_command "mv $temp_config $output_minconfig" or
3735 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003736 }
3737
3738 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003739 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003740 }
3741
3742 success $i;
3743 return 1;
3744}
3745
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003746sub make_warnings_file {
3747 my ($i) = @_;
3748
3749 if (!defined($warnings_file)) {
3750 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3751 }
3752
3753 if ($build_type eq "nobuild") {
3754 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3755 }
3756
3757 build $build_type or dodie "Failed to build";
3758
3759 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3760
3761 open(IN, $buildlog) or dodie "Can't open $buildlog";
3762 while (<IN>) {
3763
3764 # Some compilers use UTF-8 extended for quotes
3765 # for distcc heterogeneous systems, this causes issues
3766 s/$utf8_quote/'/g;
3767
3768 if (/$check_build_re/) {
3769 print OUT;
3770 }
3771 }
3772 close(IN);
3773
3774 close(OUT);
3775
3776 success $i;
3777}
3778
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003779$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003780
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003781if ($#ARGV == 0) {
3782 $ktest_config = $ARGV[0];
3783 if (! -f $ktest_config) {
3784 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003785 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003786 exit 0;
3787 }
3788 }
3789} else {
3790 $ktest_config = "ktest.conf";
3791}
3792
3793if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003794 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003795 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003796 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3797 print OUT << "EOF"
3798# Generated by ktest.pl
3799#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003800
3801# PWD is a ktest.pl variable that will result in the process working
3802# directory that ktest.pl is executed in.
3803
3804# THIS_DIR is automatically assigned the PWD of the path that generated
3805# the config file. It is best to use this variable when assigning other
3806# directory paths within this directory. This allows you to easily
3807# move the test cases to other locations or to other machines.
3808#
3809THIS_DIR := $variable{"PWD"}
3810
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003811# Define each test with TEST_START
3812# The config options below it will override the defaults
3813TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003814TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003815
3816DEFAULTS
3817EOF
3818;
3819 close(OUT);
3820}
3821read_config $ktest_config;
3822
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003823if (defined($opt{"LOG_FILE"})) {
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003824 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003825}
3826
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003827# Append any configs entered in manually to the config file.
3828my @new_configs = keys %entered_configs;
3829if ($#new_configs >= 0) {
3830 print "\nAppending entered in configs to $ktest_config\n";
3831 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3832 foreach my $config (@new_configs) {
3833 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003834 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003835 }
3836}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003837
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003838if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3839 unlink $opt{"LOG_FILE"};
3840}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003841
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003842doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3843
Steven Rostedta57419b2010-11-02 15:13:54 -04003844for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3845
3846 if (!$i) {
3847 doprint "DEFAULT OPTIONS:\n";
3848 } else {
3849 doprint "\nTEST $i OPTIONS";
3850 if (defined($repeat_tests{$i})) {
3851 $repeat = $repeat_tests{$i};
3852 doprint " ITERATE $repeat";
3853 }
3854 doprint "\n";
3855 }
3856
3857 foreach my $option (sort keys %opt) {
3858
3859 if ($option =~ /\[(\d+)\]$/) {
3860 next if ($i != $1);
3861 } else {
3862 next if ($i);
3863 }
3864
3865 doprint "$option = $opt{$option}\n";
3866 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003867}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003868
Steven Rostedt2a625122011-05-20 15:48:59 -04003869sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003870 my ($name, $i) = @_;
3871
3872 my $option = "$name\[$i\]";
3873
3874 if (defined($opt{$option})) {
3875 return $opt{$option};
3876 }
3877
Steven Rostedta57419b2010-11-02 15:13:54 -04003878 foreach my $test (keys %repeat_tests) {
3879 if ($i >= $test &&
3880 $i < $test + $repeat_tests{$test}) {
3881 $option = "$name\[$test\]";
3882 if (defined($opt{$option})) {
3883 return $opt{$option};
3884 }
3885 }
3886 }
3887
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003888 if (defined($opt{$name})) {
3889 return $opt{$name};
3890 }
3891
3892 return undef;
3893}
3894
Steven Rostedt2a625122011-05-20 15:48:59 -04003895sub set_test_option {
3896 my ($name, $i) = @_;
3897
3898 my $option = __set_test_option($name, $i);
3899 return $option if (!defined($option));
3900
Steven Rostedt (Red Hat)04262be2013-01-31 10:12:20 -05003901 return eval_option($name, $option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003902}
3903
Steven Rostedt2545eb62010-11-02 15:01:32 -04003904# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003905for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003906
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003907 # Do not reboot on failing test options
3908 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003909 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003910
Steven Rostedt683a3e62012-05-18 13:34:35 -04003911 $have_version = 0;
3912
Steven Rostedt576f6272010-11-02 14:58:38 -04003913 $iteration = $i;
3914
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003915 undef %force_config;
3916
Steven Rostedta75fece2010-11-02 14:58:27 -04003917 my $makecmd = set_test_option("MAKE_CMD", $i);
3918
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003919 # Load all the options into their mapped variable names
3920 foreach my $opt (keys %option_map) {
3921 ${$option_map{$opt}} = set_test_option($opt, $i);
3922 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003923
Steven Rostedt35ce5952011-07-15 21:57:25 -04003924 $start_minconfig_defined = 1;
3925
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003926 # The first test may override the PRE_KTEST option
3927 if (defined($pre_ktest) && $i == 1) {
3928 doprint "\n";
3929 run_command $pre_ktest;
3930 }
3931
3932 # Any test can override the POST_KTEST option
3933 # The last test takes precedence.
3934 if (defined($post_ktest)) {
3935 $final_post_ktest = $post_ktest;
3936 }
3937
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003938 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003939 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003940 $start_minconfig = $minconfig;
3941 }
3942
Steven Rostedta75fece2010-11-02 14:58:27 -04003943 chdir $builddir || die "can't change directory to $builddir";
3944
Andrew Jonesa908a662011-08-12 15:32:03 +02003945 foreach my $dir ($tmpdir, $outputdir) {
3946 if (!-d $dir) {
3947 mkpath($dir) or
3948 die "can't create $dir";
3949 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003950 }
3951
Steven Rostedte48c5292010-11-02 14:35:37 -04003952 $ENV{"SSH_USER"} = $ssh_user;
3953 $ENV{"MACHINE"} = $machine;
3954
Steven Rostedta75fece2010-11-02 14:58:27 -04003955 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303956 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003957 $dmesg = "$tmpdir/dmesg-$machine";
3958 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003959 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003960
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003961 if (!$buildonly) {
3962 $target = "$ssh_user\@$machine";
3963 if ($reboot_type eq "grub") {
3964 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedta15ba912012-11-13 14:30:37 -05003965 } elsif ($reboot_type eq "grub2") {
3966 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
3967 dodie "GRUB_FILE not defined" if (!defined($grub_file));
Steven Rostedt77869542012-12-11 17:37:41 -05003968 } elsif ($reboot_type eq "syslinux") {
3969 dodie "SYSLINUX_LABEL not defined" if (!defined($syslinux_label));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003970 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003971 }
3972
3973 my $run_type = $build_type;
3974 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003975 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003976 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003977 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003978 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003979 $run_type = $config_bisect_type;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05003980 } elsif ($test_type eq "make_min_config") {
3981 $run_type = "";
3982 } elsif ($test_type eq "make_warnings_file") {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003983 $run_type = "";
3984 }
3985
Steven Rostedta75fece2010-11-02 14:58:27 -04003986 # mistake in config file?
3987 if (!defined($run_type)) {
3988 $run_type = "ERROR";
3989 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003990
Steven Rostedte0a87422011-09-30 17:50:48 -04003991 my $installme = "";
3992 $installme = " no_install" if ($no_install);
3993
Steven Rostedt2545eb62010-11-02 15:01:32 -04003994 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003995 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003996
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003997 if (defined($pre_test)) {
3998 run_command $pre_test;
3999 }
4000
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004001 unlink $dmesg;
4002 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05304003 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004004
Steven Rostedt250bae82011-07-15 22:05:59 -04004005 if (defined($addconfig)) {
4006 my $min = $minconfig;
4007 if (!defined($minconfig)) {
4008 $min = "";
4009 }
4010 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004011 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05004012 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04004013 }
4014
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004015 if (defined($checkout)) {
4016 run_command "git checkout $checkout" or
4017 die "failed to checkout $checkout";
4018 }
4019
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004020 $no_reboot = 0;
4021
Steven Rostedt648a1822012-03-21 11:18:27 -04004022 # A test may opt to not reboot the box
4023 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004024 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04004025 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04004026
Steven Rostedta75fece2010-11-02 14:58:27 -04004027 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004028 bisect $i;
4029 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05004030 } elsif ($test_type eq "config_bisect") {
4031 config_bisect $i;
4032 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04004033 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04004034 patchcheck $i;
4035 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04004036 } elsif ($test_type eq "make_min_config") {
4037 make_min_config $i;
4038 next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004039 } elsif ($test_type eq "make_warnings_file") {
4040 $no_reboot = 1;
4041 make_warnings_file $i;
4042 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004043 }
4044
Steven Rostedt7faafbd2010-11-02 14:58:22 -04004045 if ($build_type ne "nobuild") {
4046 build $build_type or next;
Steven Rostedt (Red Hat)4283b162013-01-30 18:37:47 -05004047 check_buildlog or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004048 }
4049
Steven Rostedtcd8e3682011-08-18 16:35:44 -04004050 if ($test_type eq "install") {
4051 get_version;
4052 install;
4053 success $i;
4054 next;
4055 }
4056
Steven Rostedta75fece2010-11-02 14:58:27 -04004057 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04004058 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04004059 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04004060
4061 if (!$failed && $test_type ne "boot" && defined($run_test)) {
4062 do_run_test or $failed = 1;
4063 }
4064 end_monitor;
4065 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04004066 }
4067
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04004068 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04004069}
4070
Steven Rostedt921ed4c2012-07-19 15:18:27 -04004071if (defined($final_post_ktest)) {
4072 run_command $final_post_ktest;
4073}
4074
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004075if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004076 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04004077} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05004078 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04004079} elsif (defined($switch_to_good)) {
4080 # still need to get to the good kernel
4081 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04004082}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04004083
Steven Rostedt648a1822012-03-21 11:18:27 -04004084
Steven Rostedte48c5292010-11-02 14:35:37 -04004085doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
4086
Steven Rostedt2545eb62010-11-02 15:01:32 -04004087exit 0;