blob: d10fff12bc249e82dd607af6a736b67a359ca67b [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 Rostedt600bbf02011-11-21 20:12:04 -050056
57# required, and we will ask users if they don't have them but we keep the default
58# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050059 "REBOOT_TYPE" => "grub",
60 "LOCALVERSION" => "-test",
61 "SSH_USER" => "root",
62 "BUILD_TARGET" => "arch/x86/boot/bzImage",
63 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050064
65 "LOG_FILE" => undef,
66 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050067);
Steven Rostedt2545eb62010-11-02 15:01:32 -040068
Steven Rostedt8d1491b2010-11-18 15:39:48 -050069my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040070my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040071my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040072my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040073my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040074my $tmpdir;
75my $builddir;
76my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050077my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040078my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040079my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040080my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040081my $final_post_ktest;
82my $pre_ktest;
83my $post_ktest;
84my $pre_test;
85my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040086my $pre_build;
87my $post_build;
88my $pre_build_die;
89my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040090my $reboot_type;
91my $reboot_script;
92my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040093my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040094my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -050095my $switch_to_good;
96my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -040097my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -040098my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -040099my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -0400100my $powercycle_after_reboot;
101my $poweroff_after_halt;
Steven Rostedt407b95b2012-07-19 16:05:42 -0400102my $max_monitor_wait;
Steven Rostedte48c5292010-11-02 14:35:37 -0400103my $ssh_exec;
104my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400105my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400106my $power_off;
107my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400108my $grub_number;
109my $target;
110my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400111my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400112my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400113my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400114my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400115my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400116my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400117my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400118my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400119my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400120my $use_output_minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400121my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500122my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400123my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400124my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500125my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400126my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500127my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500128my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400129my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500130my $bisect_ret_good;
131my $bisect_ret_bad;
132my $bisect_ret_skip;
133my $bisect_ret_abort;
134my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400135my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400136my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400137my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400138my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530139my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400140my $dmesg;
141my $monitor_fp;
142my $monitor_pid;
143my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400144my $sleep_time;
145my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400146my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400147my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400148my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530149my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400150my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400151my $timeout;
152my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400153my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400154my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400155my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400156my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500157my $stop_after_success;
158my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500159my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400160my $build_target;
161my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500162my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400163my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400164my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400165my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400166
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500167my $bisect_good;
168my $bisect_bad;
169my $bisect_type;
170my $bisect_start;
171my $bisect_replay;
172my $bisect_files;
173my $bisect_reverse;
174my $bisect_check;
175
176my $config_bisect;
177my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400178my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500179
180my $patchcheck_type;
181my $patchcheck_start;
182my $patchcheck_end;
183
Steven Rostedt165708b2011-11-26 20:56:52 -0500184# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500185# which would require more options.
186my $buildonly = 1;
187
Steven Rostedtdbd37832011-11-23 16:00:48 -0500188# set when creating a new config
189my $newconfig = 0;
190
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500191my %entered_configs;
192my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400193my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400194
195# force_config is the list of configs that we force enabled (or disabled)
196# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400197my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500198
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400199# do not force reboots on config problems
200my $no_reboot = 1;
201
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400202# reboot on success
203my $reboot_success = 0;
204
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500205my %option_map = (
206 "MACHINE" => \$machine,
207 "SSH_USER" => \$ssh_user,
208 "TMP_DIR" => \$tmpdir,
209 "OUTPUT_DIR" => \$outputdir,
210 "BUILD_DIR" => \$builddir,
211 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400212 "PRE_KTEST" => \$pre_ktest,
213 "POST_KTEST" => \$post_ktest,
214 "PRE_TEST" => \$pre_test,
215 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500216 "BUILD_TYPE" => \$build_type,
217 "BUILD_OPTIONS" => \$build_options,
218 "PRE_BUILD" => \$pre_build,
219 "POST_BUILD" => \$post_build,
220 "PRE_BUILD_DIE" => \$pre_build_die,
221 "POST_BUILD_DIE" => \$post_build_die,
222 "POWER_CYCLE" => \$power_cycle,
223 "REBOOT" => \$reboot,
224 "BUILD_NOCLEAN" => \$noclean,
225 "MIN_CONFIG" => \$minconfig,
226 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
227 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400228 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400229 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500230 "IGNORE_CONFIG" => \$ignore_config,
231 "TEST" => \$run_test,
232 "ADD_CONFIG" => \$addconfig,
233 "REBOOT_TYPE" => \$reboot_type,
234 "GRUB_MENU" => \$grub_menu,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400235 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500236 "POST_INSTALL" => \$post_install,
237 "NO_INSTALL" => \$no_install,
238 "REBOOT_SCRIPT" => \$reboot_script,
239 "REBOOT_ON_ERROR" => \$reboot_on_error,
240 "SWITCH_TO_GOOD" => \$switch_to_good,
241 "SWITCH_TO_TEST" => \$switch_to_test,
242 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400243 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500244 "DIE_ON_FAILURE" => \$die_on_failure,
245 "POWER_OFF" => \$power_off,
246 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
247 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
Steven Rostedt407b95b2012-07-19 16:05:42 -0400248 "MAX_MONITOR_WAIT" => \$max_monitor_wait,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500249 "SLEEP_TIME" => \$sleep_time,
250 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
251 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
252 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500253 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500254 "BISECT_MANUAL" => \$bisect_manual,
255 "BISECT_SKIP" => \$bisect_skip,
256 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
257 "BISECT_RET_GOOD" => \$bisect_ret_good,
258 "BISECT_RET_BAD" => \$bisect_ret_bad,
259 "BISECT_RET_SKIP" => \$bisect_ret_skip,
260 "BISECT_RET_ABORT" => \$bisect_ret_abort,
261 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
262 "STORE_FAILURES" => \$store_failures,
263 "STORE_SUCCESSES" => \$store_successes,
264 "TEST_NAME" => \$test_name,
265 "TIMEOUT" => \$timeout,
266 "BOOTED_TIMEOUT" => \$booted_timeout,
267 "CONSOLE" => \$console,
268 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
269 "SUCCESS_LINE" => \$success_line,
270 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
271 "STOP_AFTER_SUCCESS" => \$stop_after_success,
272 "STOP_AFTER_FAILURE" => \$stop_after_failure,
273 "STOP_TEST_AFTER" => \$stop_test_after,
274 "BUILD_TARGET" => \$build_target,
275 "SSH_EXEC" => \$ssh_exec,
276 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400277 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500278 "CHECKOUT" => \$checkout,
279 "TARGET_IMAGE" => \$target_image,
280 "LOCALVERSION" => \$localversion,
281
282 "BISECT_GOOD" => \$bisect_good,
283 "BISECT_BAD" => \$bisect_bad,
284 "BISECT_TYPE" => \$bisect_type,
285 "BISECT_START" => \$bisect_start,
286 "BISECT_REPLAY" => \$bisect_replay,
287 "BISECT_FILES" => \$bisect_files,
288 "BISECT_REVERSE" => \$bisect_reverse,
289 "BISECT_CHECK" => \$bisect_check,
290
291 "CONFIG_BISECT" => \$config_bisect,
292 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400293 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500294
295 "PATCHCHECK_TYPE" => \$patchcheck_type,
296 "PATCHCHECK_START" => \$patchcheck_start,
297 "PATCHCHECK_END" => \$patchcheck_end,
298);
299
300# Options may be used by other options, record them.
301my %used_options;
302
Steven Rostedt7bf51072011-10-22 09:07:03 -0400303# default variables that can be used
304chomp ($variable{"PWD"} = `pwd`);
305
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500306$config_help{"MACHINE"} = << "EOF"
307 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500308 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500309EOF
310 ;
311$config_help{"SSH_USER"} = << "EOF"
312 The box is expected to have ssh on normal bootup, provide the user
313 (most likely root, since you need privileged operations)
314EOF
315 ;
316$config_help{"BUILD_DIR"} = << "EOF"
317 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500318 You can use \${PWD} that will be the path where ktest.pl is run, or use
319 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500320EOF
321 ;
322$config_help{"OUTPUT_DIR"} = << "EOF"
323 The directory that the objects will be built (full path).
324 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500325 You can use \${PWD} that will be the path where ktest.pl is run, or use
326 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500327EOF
328 ;
329$config_help{"BUILD_TARGET"} = << "EOF"
330 The location of the compiled file to copy to the target.
331 (relative to OUTPUT_DIR)
332EOF
333 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500334$config_help{"BUILD_OPTIONS"} = << "EOF"
335 Options to add to \"make\" when building.
336 i.e. -j20
337EOF
338 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500339$config_help{"TARGET_IMAGE"} = << "EOF"
340 The place to put your image on the test machine.
341EOF
342 ;
343$config_help{"POWER_CYCLE"} = << "EOF"
344 A script or command to reboot the box.
345
346 Here is a digital loggers power switch example
347 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
348
349 Here is an example to reboot a virtual box on the current host
350 with the name "Guest".
351 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
352EOF
353 ;
354$config_help{"CONSOLE"} = << "EOF"
355 The script or command that reads the console
356
357 If you use ttywatch server, something like the following would work.
358CONSOLE = nc -d localhost 3001
359
360 For a virtual machine with guest name "Guest".
361CONSOLE = virsh console Guest
362EOF
363 ;
364$config_help{"LOCALVERSION"} = << "EOF"
365 Required version ending to differentiate the test
366 from other linux builds on the system.
367EOF
368 ;
369$config_help{"REBOOT_TYPE"} = << "EOF"
370 Way to reboot the box to the test kernel.
371 Only valid options so far are "grub" and "script".
372
373 If you specify grub, it will assume grub version 1
374 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
375 and select that target to reboot to the kernel. If this is not
376 your setup, then specify "script" and have a command or script
377 specified in REBOOT_SCRIPT to boot to the target.
378
379 The entry in /boot/grub/menu.lst must be entered in manually.
380 The test will not modify that file.
381EOF
382 ;
383$config_help{"GRUB_MENU"} = << "EOF"
384 The grub title name for the test kernel to boot
385 (Only mandatory if REBOOT_TYPE = grub)
386
387 Note, ktest.pl will not update the grub menu.lst, you need to
388 manually add an option for the test. ktest.pl will search
389 the grub menu.lst for this option to find what kernel to
390 reboot into.
391
392 For example, if in the /boot/grub/menu.lst the test kernel title has:
393 title Test Kernel
394 kernel vmlinuz-test
395 GRUB_MENU = Test Kernel
396EOF
397 ;
398$config_help{"REBOOT_SCRIPT"} = << "EOF"
399 A script to reboot the target into the test kernel
400 (Only mandatory if REBOOT_TYPE = script)
401EOF
402 ;
403
Steven Rostedtdad98752011-11-22 20:48:57 -0500404sub read_prompt {
405 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400406
407 my $ans;
408
409 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500410 if ($cancel) {
411 print "$prompt [y/n/C] ";
412 } else {
413 print "$prompt [Y/n] ";
414 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400415 $ans = <STDIN>;
416 chomp $ans;
417 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500418 if ($cancel) {
419 $ans = "c";
420 } else {
421 $ans = "y";
422 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400423 }
424 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500425 if ($cancel) {
426 last if ($ans =~ /^c$/i);
427 print "Please answer either 'y', 'n' or 'c'.\n";
428 } else {
429 print "Please answer either 'y' or 'n'.\n";
430 }
431 }
432 if ($ans =~ /^c/i) {
433 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400434 }
435 if ($ans !~ /^y$/i) {
436 return 0;
437 }
438 return 1;
439}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500440
Steven Rostedtdad98752011-11-22 20:48:57 -0500441sub read_yn {
442 my ($prompt) = @_;
443
444 return read_prompt 0, $prompt;
445}
446
447sub read_ync {
448 my ($prompt) = @_;
449
450 return read_prompt 1, $prompt;
451}
452
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500453sub get_ktest_config {
454 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400455 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500456
457 return if (defined($opt{$config}));
458
459 if (defined($config_help{$config})) {
460 print "\n";
461 print $config_help{$config};
462 }
463
464 for (;;) {
465 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500466 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500467 print "\[$default{$config}\] ";
468 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400469 $ans = <STDIN>;
470 $ans =~ s/^\s*(.*\S)\s*$/$1/;
471 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500472 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400473 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500474 } else {
475 print "Your answer can not be blank\n";
476 next;
477 }
478 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500479 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500480 last;
481 }
482}
483
484sub get_ktest_configs {
485 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500486 get_ktest_config("BUILD_DIR");
487 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500488
Steven Rostedtdbd37832011-11-23 16:00:48 -0500489 if ($newconfig) {
490 get_ktest_config("BUILD_OPTIONS");
491 }
492
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500493 # options required for other than just building a kernel
494 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500495 get_ktest_config("POWER_CYCLE");
496 get_ktest_config("CONSOLE");
497 }
498
499 # options required for install and more
500 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500501 get_ktest_config("SSH_USER");
502 get_ktest_config("BUILD_TARGET");
503 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500504 }
505
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500506 get_ktest_config("LOCALVERSION");
507
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500508 return if ($buildonly);
509
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500510 my $rtype = $opt{"REBOOT_TYPE"};
511
512 if (!defined($rtype)) {
513 if (!defined($opt{"GRUB_MENU"})) {
514 get_ktest_config("REBOOT_TYPE");
515 $rtype = $entered_configs{"REBOOT_TYPE"};
516 } else {
517 $rtype = "grub";
518 }
519 }
520
521 if ($rtype eq "grub") {
522 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500523 }
524}
525
Steven Rostedt77d942c2011-05-20 13:36:58 -0400526sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400527 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400528 my $retval = "";
529
530 # We want to check for '\', and it is just easier
531 # to check the previous characet of '$' and not need
532 # to worry if '$' is the first character. By adding
533 # a space to $value, we can just check [^\\]\$ and
534 # it will still work.
535 $value = " $value";
536
537 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
538 my $begin = $1;
539 my $var = $2;
540 my $end = $3;
541 # append beginning of value to retval
542 $retval = "$retval$begin";
543 if (defined($variable{$var})) {
544 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400545 } elsif (defined($remove_undef) && $remove_undef) {
546 # for if statements, any variable that is not defined,
547 # we simple convert to 0
548 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400549 } else {
550 # put back the origin piece.
551 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500552 # This could be an option that is used later, save
553 # it so we don't warn if this option is not one of
554 # ktests options.
555 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400556 }
557 $value = $end;
558 }
559 $retval = "$retval$value";
560
561 # remove the space added in the beginning
562 $retval =~ s/ //;
563
564 return "$retval"
565}
566
Steven Rostedta57419b2010-11-02 15:13:54 -0400567sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400568 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400569
Steven Rostedtcad96662011-12-22 11:32:52 -0500570 my $prvalue = process_variables($rvalue);
571
572 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500573 # Note if a test is something other than build, then we
574 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500575 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500576 $buildonly = 0;
577 } else {
578 # install still limits some manditory options.
579 $buildonly = 2;
580 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500581 }
582
Steven Rostedta57419b2010-11-02 15:13:54 -0400583 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400584 if (!$override || defined(${$overrides}{$lvalue})) {
585 my $extra = "";
586 if ($override) {
587 $extra = "In the same override section!\n";
588 }
589 die "$name: $.: Option $lvalue defined more than once!\n$extra";
590 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500591 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400592 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500593 if ($rvalue =~ /^\s*$/) {
594 delete $opt{$lvalue};
595 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500596 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500597 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400598}
599
Steven Rostedt77d942c2011-05-20 13:36:58 -0400600sub set_variable {
601 my ($lvalue, $rvalue) = @_;
602
603 if ($rvalue =~ /^\s*$/) {
604 delete $variable{$lvalue};
605 } else {
606 $rvalue = process_variables($rvalue);
607 $variable{$lvalue} = $rvalue;
608 }
609}
610
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400611sub process_compare {
612 my ($lval, $cmp, $rval) = @_;
613
614 # remove whitespace
615
616 $lval =~ s/^\s*//;
617 $lval =~ s/\s*$//;
618
619 $rval =~ s/^\s*//;
620 $rval =~ s/\s*$//;
621
622 if ($cmp eq "==") {
623 return $lval eq $rval;
624 } elsif ($cmp eq "!=") {
625 return $lval ne $rval;
626 }
627
628 my $statement = "$lval $cmp $rval";
629 my $ret = eval $statement;
630
631 # $@ stores error of eval
632 if ($@) {
633 return -1;
634 }
635
636 return $ret;
637}
638
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400639sub value_defined {
640 my ($val) = @_;
641
642 return defined($variable{$2}) ||
643 defined($opt{$2});
644}
645
Steven Rostedt8d735212011-10-17 11:36:44 -0400646my $d = 0;
647sub process_expression {
648 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400649
Steven Rostedt8d735212011-10-17 11:36:44 -0400650 my $c = $d++;
651
652 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
653 my $express = $1;
654
655 if (process_expression($name, $express)) {
656 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
657 } else {
658 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
659 }
660 }
661
662 $d--;
663 my $OR = "\\|\\|";
664 my $AND = "\\&\\&";
665
666 while ($val =~ s/^(.*?)($OR|$AND)//) {
667 my $express = $1;
668 my $op = $2;
669
670 if (process_expression($name, $express)) {
671 if ($op eq "||") {
672 return 1;
673 }
674 } else {
675 if ($op eq "&&") {
676 return 0;
677 }
678 }
679 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400680
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400681 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
682 my $ret = process_compare($1, $2, $3);
683 if ($ret < 0) {
684 die "$name: $.: Unable to process comparison\n";
685 }
686 return $ret;
687 }
688
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400689 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
690 if (defined $1) {
691 return !value_defined($2);
692 } else {
693 return value_defined($2);
694 }
695 }
696
Steven Rostedt45d73a52011-09-30 19:44:53 -0400697 if ($val =~ /^\s*0\s*$/) {
698 return 0;
699 } elsif ($val =~ /^\s*\d+\s*$/) {
700 return 1;
701 }
702
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400703 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400704}
705
706sub process_if {
707 my ($name, $value) = @_;
708
709 # Convert variables and replace undefined ones with 0
710 my $val = process_variables($value, 1);
711 my $ret = process_expression $name, $val;
712
713 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400714}
715
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400716sub __read_config {
717 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400718
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400719 my $in;
720 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400721
Steven Rostedta57419b2010-11-02 15:13:54 -0400722 my $name = $config;
723 $name =~ s,.*/(.*),$1,;
724
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400725 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400726 my $default = 1;
727 my $repeat = 1;
728 my $num_tests_set = 0;
729 my $skip = 0;
730 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400731 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400732 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400733 my $if = 0;
734 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400735 my $override = 0;
736
737 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400738
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400739 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400740
741 # ignore blank lines and comments
742 next if (/^\s*$/ || /\s*\#/);
743
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400744 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400745
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400746 my $type = $1;
747 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400748 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400749
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400750 my $old_test_num;
751 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400752 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400753
754 if ($type eq "TEST_START") {
755
756 if ($num_tests_set) {
757 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
758 }
759
760 $old_test_num = $test_num;
761 $old_repeat = $repeat;
762
763 $test_num += $repeat;
764 $default = 0;
765 $repeat = 1;
766 } else {
767 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400768 }
769
Steven Rostedta9f84422011-10-17 11:06:29 -0400770 # If SKIP is anywhere in the line, the command will be skipped
771 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400772 $skip = 1;
773 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400774 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400775 $skip = 0;
776 }
777
Steven Rostedta9f84422011-10-17 11:06:29 -0400778 if ($rest =~ s/\sELSE\b//) {
779 if (!$if) {
780 die "$name: $.: ELSE found with out matching IF section\n$_";
781 }
782 $if = 0;
783
784 if ($if_set) {
785 $skip = 1;
786 } else {
787 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400788 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400789 }
790
Steven Rostedta9f84422011-10-17 11:06:29 -0400791 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400792 if (process_if($name, $1)) {
793 $if_set = 1;
794 } else {
795 $skip = 1;
796 }
797 $if = 1;
798 } else {
799 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400800 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400801 }
802
Steven Rostedta9f84422011-10-17 11:06:29 -0400803 if (!$skip) {
804 if ($type eq "TEST_START") {
805 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
806 $repeat = $1;
807 $repeat_tests{"$test_num"} = $repeat;
808 }
809 } elsif ($rest =~ s/\sOVERRIDE\b//) {
810 # DEFAULT only
811 $override = 1;
812 # Clear previous overrides
813 %overrides = ();
814 }
815 }
816
817 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400818 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400819 }
820
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400821 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400822 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400823 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400824 }
825
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400826 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400827 if (!$if) {
828 die "$name: $.: ELSE found with out matching IF section\n$_";
829 }
830 $rest = $1;
831 if ($if_set) {
832 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400833 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400834 } else {
835 $skip = 0;
836
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400837 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400838 # May be a ELSE IF section.
839 if (!process_if($name, $1)) {
840 $skip = 1;
841 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400842 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400843 } else {
844 $if = 0;
845 }
846 }
847
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400848 if ($rest !~ /^\s*$/) {
849 die "$name: $.: Gargbage found after DEFAULTS\n$_";
850 }
851
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400852 } elsif (/^\s*INCLUDE\s+(\S+)/) {
853
854 next if ($skip);
855
856 if (!$default) {
857 die "$name: $.: INCLUDE can only be done in default sections\n$_";
858 }
859
860 my $file = process_variables($1);
861
862 if ($file !~ m,^/,) {
863 # check the path of the config file first
864 if ($config =~ m,(.*)/,) {
865 if (-f "$1/$file") {
866 $file = "$1/$file";
867 }
868 }
869 }
870
871 if ( ! -r $file ) {
872 die "$name: $.: Can't read file $file\n$_";
873 }
874
875 if (__read_config($file, \$test_num)) {
876 $test_case = 1;
877 }
878
Steven Rostedta57419b2010-11-02 15:13:54 -0400879 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
880
881 next if ($skip);
882
Steven Rostedt2545eb62010-11-02 15:01:32 -0400883 my $lvalue = $1;
884 my $rvalue = $2;
885
Steven Rostedta57419b2010-11-02 15:13:54 -0400886 if (!$default &&
887 ($lvalue eq "NUM_TESTS" ||
888 $lvalue eq "LOG_FILE" ||
889 $lvalue eq "CLEAR_LOG")) {
890 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400891 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400892
893 if ($lvalue eq "NUM_TESTS") {
894 if ($test_num) {
895 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
896 }
897 if (!$default) {
898 die "$name: $.: NUM_TESTS must be set in default section\n";
899 }
900 $num_tests_set = 1;
901 }
902
903 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400904 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400905 } else {
906 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400907 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400908
909 if ($repeat > 1) {
910 $repeats{$val} = $repeat;
911 }
912 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400913 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
914 next if ($skip);
915
916 my $lvalue = $1;
917 my $rvalue = $2;
918
919 # process config variables.
920 # Config variables are only active while reading the
921 # config and can be defined anywhere. They also ignore
922 # TEST_START and DEFAULTS, but are skipped if they are in
923 # on of these sections that have SKIP defined.
924 # The save variable can be
925 # defined multiple times and the new one simply overrides
926 # the prevous one.
927 set_variable($lvalue, $rvalue);
928
Steven Rostedta57419b2010-11-02 15:13:54 -0400929 } else {
930 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400931 }
932 }
933
Steven Rostedta57419b2010-11-02 15:13:54 -0400934 if ($test_num) {
935 $test_num += $repeat - 1;
936 $opt{"NUM_TESTS"} = $test_num;
937 }
938
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400939 close($in);
940
941 $$current_test_num = $test_num;
942
943 return $test_case;
944}
945
Steven Rostedtc4261d02011-11-23 13:41:18 -0500946sub get_test_case {
947 print "What test case would you like to run?\n";
948 print " (build, install or boot)\n";
949 print " Other tests are available but require editing the config file\n";
950 my $ans = <STDIN>;
951 chomp $ans;
952 $default{"TEST_TYPE"} = $ans;
953}
954
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400955sub read_config {
956 my ($config) = @_;
957
958 my $test_case;
959 my $test_num = 0;
960
961 $test_case = __read_config $config, \$test_num;
962
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500963 # make sure we have all mandatory configs
964 get_ktest_configs;
965
Steven Rostedt0df213c2011-06-14 20:51:37 -0400966 # was a test specified?
967 if (!$test_case) {
968 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500969 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400970 }
971
Steven Rostedta75fece2010-11-02 14:58:27 -0400972 # set any defaults
973
974 foreach my $default (keys %default) {
975 if (!defined($opt{$default})) {
976 $opt{$default} = $default{$default};
977 }
978 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500979
980 if ($opt{"IGNORE_UNUSED"} == 1) {
981 return;
982 }
983
984 my %not_used;
985
986 # check if there are any stragglers (typos?)
987 foreach my $option (keys %opt) {
988 my $op = $option;
989 # remove per test labels.
990 $op =~ s/\[.*\]//;
991 if (!exists($option_map{$op}) &&
992 !exists($default{$op}) &&
993 !exists($used_options{$op})) {
994 $not_used{$op} = 1;
995 }
996 }
997
998 if (%not_used) {
999 my $s = "s are";
1000 $s = " is" if (keys %not_used == 1);
1001 print "The following option$s not used; could be a typo:\n";
1002 foreach my $option (keys %not_used) {
1003 print "$option\n";
1004 }
1005 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1006 if (!read_yn "Do you want to continue?") {
1007 exit -1;
1008 }
1009 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001010}
1011
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001012sub __eval_option {
1013 my ($option, $i) = @_;
1014
1015 # Add space to evaluate the character before $
1016 $option = " $option";
1017 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301018 my $repeated = 0;
1019 my $parent = 0;
1020
1021 foreach my $test (keys %repeat_tests) {
1022 if ($i >= $test &&
1023 $i < $test + $repeat_tests{$test}) {
1024
1025 $repeated = 1;
1026 $parent = $test;
1027 last;
1028 }
1029 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001030
1031 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1032 my $start = $1;
1033 my $var = $2;
1034 my $end = $3;
1035
1036 # Append beginning of line
1037 $retval = "$retval$start";
1038
1039 # If the iteration option OPT[$i] exists, then use that.
1040 # otherwise see if the default OPT (without [$i]) exists.
1041
1042 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301043 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001044
1045 if (defined($opt{$o})) {
1046 $o = $opt{$o};
1047 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301048 } elsif ($repeated && defined($opt{$parento})) {
1049 $o = $opt{$parento};
1050 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001051 } elsif (defined($opt{$var})) {
1052 $o = $opt{$var};
1053 $retval = "$retval$o";
1054 } else {
1055 $retval = "$retval\$\{$var\}";
1056 }
1057
1058 $option = $end;
1059 }
1060
1061 $retval = "$retval$option";
1062
1063 $retval =~ s/^ //;
1064
1065 return $retval;
1066}
1067
1068sub eval_option {
1069 my ($option, $i) = @_;
1070
1071 my $prev = "";
1072
1073 # Since an option can evaluate to another option,
1074 # keep iterating until we do not evaluate any more
1075 # options.
1076 my $r = 0;
1077 while ($prev ne $option) {
1078 # Check for recursive evaluations.
1079 # 100 deep should be more than enough.
1080 if ($r++ > 100) {
1081 die "Over 100 evaluations accurred with $option\n" .
1082 "Check for recursive variables\n";
1083 }
1084 $prev = $option;
1085 $option = __eval_option($option, $i);
1086 }
1087
1088 return $option;
1089}
1090
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001091sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001092 if (defined($opt{"LOG_FILE"})) {
1093 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1094 print OUT @_;
1095 close(OUT);
1096 }
1097}
1098
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001099sub logit {
1100 if (defined($opt{"LOG_FILE"})) {
1101 _logit @_;
1102 } else {
1103 print @_;
1104 }
1105}
1106
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001107sub doprint {
1108 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001109 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001110}
1111
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001112sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001113sub start_monitor;
1114sub end_monitor;
1115sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001116
1117sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001118 my ($time) = @_;
1119
Steven Rostedt2b803362011-09-30 18:00:23 -04001120 if (defined($time)) {
1121 start_monitor;
1122 # flush out current monitor
1123 # May contain the reboot success line
1124 wait_for_monitor 1;
1125 }
1126
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001127 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001128 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001129 if (defined($powercycle_after_reboot)) {
1130 sleep $powercycle_after_reboot;
1131 run_command "$power_cycle";
1132 }
1133 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001134 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001135 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001136 }
Andrew Jones2728be42011-08-12 15:32:05 +02001137
1138 if (defined($time)) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001139 if (wait_for_monitor($time, $reboot_success_line)) {
1140 # reboot got stuck?
1141 run_command "$power_cycle";
1142 }
Andrew Jones2728be42011-08-12 15:32:05 +02001143 end_monitor;
1144 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001145}
1146
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001147sub reboot_to_good {
1148 my ($time) = @_;
1149
1150 if (defined($switch_to_good)) {
1151 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001152 }
1153
1154 reboot $time;
1155}
1156
Steven Rostedt576f6272010-11-02 14:58:38 -04001157sub do_not_reboot {
1158 my $i = $iteration;
1159
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001160 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001161 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1162 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1163}
1164
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001165sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001166 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001167
Steven Rostedt576f6272010-11-02 14:58:38 -04001168 my $i = $iteration;
1169
1170 if ($reboot_on_error && !do_not_reboot) {
1171
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001172 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001173 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001174
Steven Rostedta75fece2010-11-02 14:58:27 -04001175 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001176 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001177 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001178 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001179
Steven Rostedtf80802c2011-03-07 13:18:47 -05001180 if (defined($opt{"LOG_FILE"})) {
1181 print " See $opt{LOG_FILE} for more info.\n";
1182 }
1183
Steven Rostedt576f6272010-11-02 14:58:38 -04001184 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001185}
1186
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001187sub open_console {
1188 my ($fp) = @_;
1189
1190 my $flags;
1191
Steven Rostedta75fece2010-11-02 14:58:27 -04001192 my $pid = open($fp, "$console|") or
1193 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001194
1195 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001196 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001197 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001198 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001199
1200 return $pid;
1201}
1202
1203sub close_console {
1204 my ($fp, $pid) = @_;
1205
1206 doprint "kill child process $pid\n";
1207 kill 2, $pid;
1208
1209 print "closing!\n";
1210 close($fp);
1211}
1212
1213sub start_monitor {
1214 if ($monitor_cnt++) {
1215 return;
1216 }
1217 $monitor_fp = \*MONFD;
1218 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001219
1220 return;
1221
1222 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001223}
1224
1225sub end_monitor {
1226 if (--$monitor_cnt) {
1227 return;
1228 }
1229 close_console($monitor_fp, $monitor_pid);
1230}
1231
1232sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001233 my ($time, $stop) = @_;
1234 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001235 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001236 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001237 my $start_time = time;
1238 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001239
Steven Rostedta75fece2010-11-02 14:58:27 -04001240 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001241
1242 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001243 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001244 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001245 last if (!defined($line));
1246 print "$line";
1247 $full_line .= $line;
1248
1249 if (defined($stop) && $full_line =~ /$stop/) {
1250 doprint "wait for monitor detected $stop\n";
1251 $booted = 1;
1252 }
1253
1254 if ($line =~ /\n/) {
1255 $full_line = "";
1256 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001257 $now = time;
1258 if ($now - $start_time >= $max_monitor_wait) {
1259 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1260 return 1;
1261 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001262 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001263 print "** Monitor flushed **\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001264 return 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001265}
1266
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301267sub save_logs {
1268 my ($result, $basedir) = @_;
1269 my @t = localtime;
1270 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1271 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1272
1273 my $type = $build_type;
1274 if ($type =~ /useconfig/) {
1275 $type = "useconfig";
1276 }
1277
1278 my $dir = "$machine-$test_type-$type-$result-$date";
1279
1280 $dir = "$basedir/$dir";
1281
1282 if (!-d $dir) {
1283 mkpath($dir) or
1284 die "can't create $dir";
1285 }
1286
1287 my %files = (
1288 "config" => $output_config,
1289 "buildlog" => $buildlog,
1290 "dmesg" => $dmesg,
1291 "testlog" => $testlog,
1292 );
1293
1294 while (my ($name, $source) = each(%files)) {
1295 if (-f "$source") {
1296 cp "$source", "$dir/$name" or
1297 die "failed to copy $source";
1298 }
1299 }
1300
1301 doprint "*** Saved info to $dir ***\n";
1302}
1303
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001304sub fail {
1305
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001306 if (defined($post_test)) {
1307 run_command $post_test;
1308 }
1309
Steven Rostedta75fece2010-11-02 14:58:27 -04001310 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001311 dodie @_;
1312 }
1313
Steven Rostedta75fece2010-11-02 14:58:27 -04001314 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001315
Steven Rostedt576f6272010-11-02 14:58:38 -04001316 my $i = $iteration;
1317
Steven Rostedta75fece2010-11-02 14:58:27 -04001318 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001319 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001320 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001321 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001322 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001323
Steven Rostedt9064af52011-06-13 10:38:48 -04001324 my $name = "";
1325
1326 if (defined($test_name)) {
1327 $name = " ($test_name)";
1328 }
1329
Steven Rostedt576f6272010-11-02 14:58:38 -04001330 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1331 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001332 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001333 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1334 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001335
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301336 if (defined($store_failures)) {
1337 save_logs "fail", $store_failures;
1338 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001339
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001340 return 1;
1341}
1342
Steven Rostedt2545eb62010-11-02 15:01:32 -04001343sub run_command {
1344 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001345 my $dolog = 0;
1346 my $dord = 0;
1347 my $pid;
1348
Steven Rostedte48c5292010-11-02 14:35:37 -04001349 $command =~ s/\$SSH_USER/$ssh_user/g;
1350 $command =~ s/\$MACHINE/$machine/g;
1351
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001352 doprint("$command ... ");
1353
1354 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001355 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001356
1357 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001358 open(LOG, ">>$opt{LOG_FILE}") or
1359 dodie "failed to write to log";
1360 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001361 }
1362
1363 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001364 open (RD, ">$redirect") or
1365 dodie "failed to write to redirect $redirect";
1366 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001367 }
1368
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001369 while (<CMD>) {
1370 print LOG if ($dolog);
1371 print RD if ($dord);
1372 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001373
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001374 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001375 my $failed = $?;
1376
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001377 close(CMD);
1378 close(LOG) if ($dolog);
1379 close(RD) if ($dord);
1380
Steven Rostedt2545eb62010-11-02 15:01:32 -04001381 if ($failed) {
1382 doprint "FAILED!\n";
1383 } else {
1384 doprint "SUCCESS\n";
1385 }
1386
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001387 return !$failed;
1388}
1389
Steven Rostedte48c5292010-11-02 14:35:37 -04001390sub run_ssh {
1391 my ($cmd) = @_;
1392 my $cp_exec = $ssh_exec;
1393
1394 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1395 return run_command "$cp_exec";
1396}
1397
1398sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001399 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001400
1401 $cp_scp =~ s/\$SRC_FILE/$src/g;
1402 $cp_scp =~ s/\$DST_FILE/$dst/g;
1403
1404 return run_command "$cp_scp";
1405}
1406
Steven Rostedt02ad2612012-03-21 08:21:24 -04001407sub run_scp_install {
1408 my ($src, $dst) = @_;
1409
1410 my $cp_scp = $scp_to_target_install;
1411
1412 return run_scp($src, $dst, $cp_scp);
1413}
1414
1415sub run_scp_mod {
1416 my ($src, $dst) = @_;
1417
1418 my $cp_scp = $scp_to_target;
1419
1420 return run_scp($src, $dst, $cp_scp);
1421}
1422
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001423sub get_grub_index {
1424
Steven Rostedta75fece2010-11-02 14:58:27 -04001425 if ($reboot_type ne "grub") {
1426 return;
1427 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001428 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001429
1430 doprint "Find grub menu ... ";
1431 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001432
1433 my $ssh_grub = $ssh_exec;
1434 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1435
1436 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001437 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001438
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001439 my $found = 0;
1440
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001441 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001442 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001443 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001444 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001445 last;
1446 } elsif (/^\s*title\s/) {
1447 $grub_number++;
1448 }
1449 }
1450 close(IN);
1451
Steven Rostedta75fece2010-11-02 14:58:27 -04001452 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001453 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001454 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001455}
1456
Steven Rostedt2545eb62010-11-02 15:01:32 -04001457sub wait_for_input
1458{
1459 my ($fp, $time) = @_;
1460 my $rin;
1461 my $ready;
1462 my $line;
1463 my $ch;
1464
1465 if (!defined($time)) {
1466 $time = $timeout;
1467 }
1468
1469 $rin = '';
1470 vec($rin, fileno($fp), 1) = 1;
1471 $ready = select($rin, undef, undef, $time);
1472
1473 $line = "";
1474
1475 # try to read one char at a time
1476 while (sysread $fp, $ch, 1) {
1477 $line .= $ch;
1478 last if ($ch eq "\n");
1479 }
1480
1481 if (!length($line)) {
1482 return undef;
1483 }
1484
1485 return $line;
1486}
1487
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001488sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001489 if (defined($switch_to_test)) {
1490 run_command $switch_to_test;
1491 }
1492
Steven Rostedta75fece2010-11-02 14:58:27 -04001493 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001494 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001495 } elsif (defined $reboot_script) {
1496 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001497 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001498 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001499}
1500
Steven Rostedta57419b2010-11-02 15:13:54 -04001501sub get_sha1 {
1502 my ($commit) = @_;
1503
1504 doprint "git rev-list --max-count=1 $commit ... ";
1505 my $sha1 = `git rev-list --max-count=1 $commit`;
1506 my $ret = $?;
1507
1508 logit $sha1;
1509
1510 if ($ret) {
1511 doprint "FAILED\n";
1512 dodie "Failed to get git $commit";
1513 }
1514
1515 print "SUCCESS\n";
1516
1517 chomp $sha1;
1518
1519 return $sha1;
1520}
1521
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001522sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001523 my $booted = 0;
1524 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001525 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001526 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001527 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001528
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001529 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001530
1531 my $line;
1532 my $full_line = "";
1533
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001534 open(DMESG, "> $dmesg") or
1535 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001536
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001537 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001538
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001539 my $success_start;
1540 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001541 my $monitor_start = time;
1542 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001543 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001544
Steven Rostedt2d01b262011-03-08 09:47:54 -05001545 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001546
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001547 if ($bug && defined($stop_after_failure) &&
1548 $stop_after_failure >= 0) {
1549 my $time = $stop_after_failure - (time - $failure_start);
1550 $line = wait_for_input($monitor_fp, $time);
1551 if (!defined($line)) {
1552 doprint "bug timed out after $booted_timeout seconds\n";
1553 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1554 last;
1555 }
1556 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001557 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001558 if (!defined($line)) {
1559 my $s = $booted_timeout == 1 ? "" : "s";
1560 doprint "Successful boot found: break after $booted_timeout second$s\n";
1561 last;
1562 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001563 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001564 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001565 if (!defined($line)) {
1566 my $s = $timeout == 1 ? "" : "s";
1567 doprint "Timed out after $timeout second$s\n";
1568 last;
1569 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001570 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001571
Steven Rostedt2545eb62010-11-02 15:01:32 -04001572 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001573 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001574
1575 # we are not guaranteed to get a full line
1576 $full_line .= $line;
1577
Steven Rostedta75fece2010-11-02 14:58:27 -04001578 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001579 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001580 $success_start = time;
1581 }
1582
1583 if ($booted && defined($stop_after_success) &&
1584 $stop_after_success >= 0) {
1585 my $now = time;
1586 if ($now - $success_start >= $stop_after_success) {
1587 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1588 last;
1589 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001590 }
1591
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001592 if ($full_line =~ /\[ backtrace testing \]/) {
1593 $skip_call_trace = 1;
1594 }
1595
Steven Rostedt2545eb62010-11-02 15:01:32 -04001596 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001597 if (!$bug && !$skip_call_trace) {
1598 if ($ignore_errors) {
1599 $bug_ignored = 1;
1600 } else {
1601 $bug = 1;
1602 $failure_start = time;
1603 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001604 }
1605 }
1606
1607 if ($bug && defined($stop_after_failure) &&
1608 $stop_after_failure >= 0) {
1609 my $now = time;
1610 if ($now - $failure_start >= $stop_after_failure) {
1611 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1612 last;
1613 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001614 }
1615
1616 if ($full_line =~ /\[ end of backtrace testing \]/) {
1617 $skip_call_trace = 0;
1618 }
1619
1620 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001621 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001622 $bug = 1;
1623 }
1624
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001625 # Detect triple faults by testing the banner
1626 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1627 if ($1 eq $version) {
1628 $version_found = 1;
1629 } elsif ($version_found && $detect_triplefault) {
1630 # We already booted into the kernel we are testing,
1631 # but now we booted into another kernel?
1632 # Consider this a triple fault.
1633 doprint "Aleady booted in Linux kernel $version, but now\n";
1634 doprint "we booted into Linux kernel $1.\n";
1635 doprint "Assuming that this is a triple fault.\n";
1636 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1637 last;
1638 }
1639 }
1640
Steven Rostedt2545eb62010-11-02 15:01:32 -04001641 if ($line =~ /\n/) {
1642 $full_line = "";
1643 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001644
1645 if ($stop_test_after > 0 && !$booted && !$bug) {
1646 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001647 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001648 $done = 1;
1649 }
1650 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001651 }
1652
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001653 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001654
Steven Rostedt2545eb62010-11-02 15:01:32 -04001655 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001656 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001657 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001658 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001659
Steven Rostedta75fece2010-11-02 14:58:27 -04001660 if (!$booted) {
1661 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001662 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001663 }
1664
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001665 if ($bug_ignored) {
1666 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1667 }
1668
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001669 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001670}
1671
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001672sub eval_kernel_version {
1673 my ($option) = @_;
1674
1675 $option =~ s/\$KERNEL_VERSION/$version/g;
1676
1677 return $option;
1678}
1679
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001680sub do_post_install {
1681
1682 return if (!defined($post_install));
1683
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001684 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001685 run_command "$cp_post_install" or
1686 dodie "Failed to run post install";
1687}
1688
Steven Rostedt2545eb62010-11-02 15:01:32 -04001689sub install {
1690
Steven Rostedte0a87422011-09-30 17:50:48 -04001691 return if ($no_install);
1692
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001693 if (defined($pre_install)) {
1694 my $cp_pre_install = eval_kernel_version $pre_install;
1695 run_command "$cp_pre_install" or
1696 dodie "Failed to run pre install";
1697 }
1698
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001699 my $cp_target = eval_kernel_version $target_image;
1700
Steven Rostedt02ad2612012-03-21 08:21:24 -04001701 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001702 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001703
1704 my $install_mods = 0;
1705
1706 # should we process modules?
1707 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001708 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001709 while (<IN>) {
1710 if (/CONFIG_MODULES(=y)?/) {
1711 $install_mods = 1 if (defined($1));
1712 last;
1713 }
1714 }
1715 close(IN);
1716
1717 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001718 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001719 doprint "No modules needed\n";
1720 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001721 }
1722
Steven Rostedt627977d2012-03-21 08:16:15 -04001723 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001724 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001725
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001726 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001727 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001728
Steven Rostedte48c5292010-11-02 14:35:37 -04001729 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001730 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001731
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001732 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001733 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001734 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001735
Steven Rostedt02ad2612012-03-21 08:21:24 -04001736 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001737 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001738
Steven Rostedta75fece2010-11-02 14:58:27 -04001739 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001740
Steven Rostedte7b13442011-06-14 20:44:36 -04001741 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001742 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001743
Steven Rostedte48c5292010-11-02 14:35:37 -04001744 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001745
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001746 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001747}
1748
Steven Rostedtddf607e2011-06-14 20:49:13 -04001749sub get_version {
1750 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001751 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001752 doprint "$make kernelrelease ... ";
1753 $version = `$make kernelrelease | tail -1`;
1754 chomp($version);
1755 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001756 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001757}
1758
1759sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001760 # Make sure the stable kernel has finished booting
1761 start_monitor;
1762 wait_for_monitor 5;
1763 end_monitor;
1764
Steven Rostedtddf607e2011-06-14 20:49:13 -04001765 get_grub_index;
1766 get_version;
1767 install;
1768
1769 start_monitor;
1770 return monitor;
1771}
1772
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001773sub check_buildlog {
1774 my ($patch) = @_;
1775
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001776 my @files = `git show $patch | diffstat -l`;
1777
1778 open(IN, "git show $patch |") or
1779 dodie "failed to show $patch";
1780 while (<IN>) {
1781 if (m,^--- a/(.*),) {
1782 chomp $1;
1783 $files[$#files] = $1;
1784 }
1785 }
1786 close(IN);
1787
1788 open(IN, $buildlog) or dodie "Can't open $buildlog";
1789 while (<IN>) {
1790 if (/^\s*(.*?):.*(warning|error)/) {
1791 my $err = $1;
1792 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001793 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001794 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001795 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001796 }
1797 }
1798 }
1799 }
1800 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001801
1802 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001803}
1804
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001805sub apply_min_config {
1806 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001807
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001808 # Read the config file and remove anything that
1809 # is in the force_config hash (from minconfig and others)
1810 # then add the force config back.
1811
1812 doprint "Applying minimum configurations into $output_config.new\n";
1813
1814 open (OUT, ">$outconfig") or
1815 dodie "Can't create $outconfig";
1816
1817 if (-f $output_config) {
1818 open (IN, $output_config) or
1819 dodie "Failed to open $output_config";
1820 while (<IN>) {
1821 if (/^(# )?(CONFIG_[^\s=]*)/) {
1822 next if (defined($force_config{$2}));
1823 }
1824 print OUT;
1825 }
1826 close IN;
1827 }
1828 foreach my $config (keys %force_config) {
1829 print OUT "$force_config{$config}\n";
1830 }
1831 close OUT;
1832
1833 run_command "mv $outconfig $output_config";
1834}
1835
1836sub make_oldconfig {
1837
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001838 my @force_list = keys %force_config;
1839
1840 if ($#force_list >= 0) {
1841 apply_min_config;
1842 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001843
1844 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001845 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1846 # try a yes '' | oldconfig
1847 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001848 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001849 dodie "failed make config oldconfig";
1850 }
1851}
1852
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001853# read a config file and use this to force new configs.
1854sub load_force_config {
1855 my ($config) = @_;
1856
Steven Rostedtcf79fab2012-07-19 15:29:43 -04001857 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001858 open(IN, $config) or
1859 dodie "failed to read $config";
1860 while (<IN>) {
1861 chomp;
1862 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1863 $force_config{$1} = $_;
1864 } elsif (/^# (CONFIG_\S*) is not set/) {
1865 $force_config{$1} = $_;
1866 }
1867 }
1868 close IN;
1869}
1870
Steven Rostedt2545eb62010-11-02 15:01:32 -04001871sub build {
1872 my ($type) = @_;
1873
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001874 unlink $buildlog;
1875
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001876 # Failed builds should not reboot the target
1877 my $save_no_reboot = $no_reboot;
1878 $no_reboot = 1;
1879
Steven Rostedt683a3e62012-05-18 13:34:35 -04001880 # Calculate a new version from here.
1881 $have_version = 0;
1882
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001883 if (defined($pre_build)) {
1884 my $ret = run_command $pre_build;
1885 if (!$ret && defined($pre_build_die) &&
1886 $pre_build_die) {
1887 dodie "failed to pre_build\n";
1888 }
1889 }
1890
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001891 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001892 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001893 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001894
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001895 $type = "oldconfig";
1896 }
1897
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001898 # old config can ask questions
1899 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001900 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001901
1902 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001903 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001904
Andrew Jones13488232011-08-12 15:32:04 +02001905 if (!$noclean) {
1906 run_command "mv $output_config $outputdir/config_temp" or
1907 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001908
Andrew Jones13488232011-08-12 15:32:04 +02001909 run_command "$make mrproper" or dodie "make mrproper";
1910
1911 run_command "mv $outputdir/config_temp $output_config" or
1912 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001913 }
1914
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001915 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001916 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001917 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001918 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001919 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001920
1921 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001922 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1923 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001924 close(OUT);
1925
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001926 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001927 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001928 }
1929
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001930 if ($type ne "oldnoconfig") {
1931 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001932 dodie "failed make config";
1933 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001934 # Run old config regardless, to enforce min configurations
1935 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001936
Steven Rostedta75fece2010-11-02 14:58:27 -04001937 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001938 my $build_ret = run_command "$make $build_options";
1939 undef $redirect;
1940
1941 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04001942 # Because a post build may change the kernel version
1943 # do it now.
1944 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001945 my $ret = run_command $post_build;
1946 if (!$ret && defined($post_build_die) &&
1947 $post_build_die) {
1948 dodie "failed to post_build\n";
1949 }
1950 }
1951
1952 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001953 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001954 if ($in_bisect) {
1955 $no_reboot = $save_no_reboot;
1956 return 0;
1957 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001958 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001959 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001960
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001961 $no_reboot = $save_no_reboot;
1962
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001963 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001964}
1965
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001966sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001967 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001968 if (defined($poweroff_after_halt)) {
1969 sleep $poweroff_after_halt;
1970 run_command "$power_off";
1971 }
1972 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001973 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001974 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001975 }
1976}
1977
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001978sub success {
1979 my ($i) = @_;
1980
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001981 if (defined($post_test)) {
1982 run_command $post_test;
1983 }
1984
Steven Rostedte48c5292010-11-02 14:35:37 -04001985 $successes++;
1986
Steven Rostedt9064af52011-06-13 10:38:48 -04001987 my $name = "";
1988
1989 if (defined($test_name)) {
1990 $name = " ($test_name)";
1991 }
1992
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001993 doprint "\n\n*******************************************\n";
1994 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001995 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001996 doprint "*******************************************\n";
1997 doprint "*******************************************\n";
1998
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301999 if (defined($store_successes)) {
2000 save_logs "success", $store_successes;
2001 }
2002
Steven Rostedt576f6272010-11-02 14:58:38 -04002003 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002004 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002005 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002006 }
2007}
2008
Steven Rostedtc960bb92011-03-08 09:22:39 -05002009sub answer_bisect {
2010 for (;;) {
2011 doprint "Pass or fail? [p/f]";
2012 my $ans = <STDIN>;
2013 chomp $ans;
2014 if ($ans eq "p" || $ans eq "P") {
2015 return 1;
2016 } elsif ($ans eq "f" || $ans eq "F") {
2017 return 0;
2018 } else {
2019 print "Please answer 'P' or 'F'\n";
2020 }
2021 }
2022}
2023
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002024sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002025 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002026
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002027 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002028 $reboot_on_error = 0;
2029 $poweroff_on_error = 0;
2030 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002031
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302032 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002033 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302034 undef $redirect;
2035
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002036 exit $failed;
2037}
2038
2039my $child_done;
2040
2041sub child_finished {
2042 $child_done = 1;
2043}
2044
2045sub do_run_test {
2046 my $child_pid;
2047 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002048 my $line;
2049 my $full_line;
2050 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002051
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002052 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002053
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002054 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002055
2056 $child_done = 0;
2057
2058 $SIG{CHLD} = qw(child_finished);
2059
2060 $child_pid = fork;
2061
2062 child_run_test if (!$child_pid);
2063
2064 $full_line = "";
2065
2066 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002067 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002068 if (defined($line)) {
2069
2070 # we are not guaranteed to get a full line
2071 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002072 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002073
2074 if ($full_line =~ /call trace:/i) {
2075 $bug = 1;
2076 }
2077
2078 if ($full_line =~ /Kernel panic -/) {
2079 $bug = 1;
2080 }
2081
2082 if ($line =~ /\n/) {
2083 $full_line = "";
2084 }
2085 }
2086 } while (!$child_done && !$bug);
2087
2088 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002089 my $failure_start = time;
2090 my $now;
2091 do {
2092 $line = wait_for_input($monitor_fp, 1);
2093 if (defined($line)) {
2094 doprint $line;
2095 }
2096 $now = time;
2097 if ($now - $failure_start >= $stop_after_failure) {
2098 last;
2099 }
2100 } while (defined($line));
2101
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002102 doprint "Detected kernel crash!\n";
2103 # kill the child with extreme prejudice
2104 kill 9, $child_pid;
2105 }
2106
2107 waitpid $child_pid, 0;
2108 $child_exit = $?;
2109
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002110 if (!$bug && $in_bisect) {
2111 if (defined($bisect_ret_good)) {
2112 if ($child_exit == $bisect_ret_good) {
2113 return 1;
2114 }
2115 }
2116 if (defined($bisect_ret_skip)) {
2117 if ($child_exit == $bisect_ret_skip) {
2118 return -1;
2119 }
2120 }
2121 if (defined($bisect_ret_abort)) {
2122 if ($child_exit == $bisect_ret_abort) {
2123 fail "test abort" and return -2;
2124 }
2125 }
2126 if (defined($bisect_ret_bad)) {
2127 if ($child_exit == $bisect_ret_skip) {
2128 return 0;
2129 }
2130 }
2131 if (defined($bisect_ret_default)) {
2132 if ($bisect_ret_default eq "good") {
2133 return 1;
2134 } elsif ($bisect_ret_default eq "bad") {
2135 return 0;
2136 } elsif ($bisect_ret_default eq "skip") {
2137 return -1;
2138 } elsif ($bisect_ret_default eq "abort") {
2139 return -2;
2140 } else {
2141 fail "unknown default action: $bisect_ret_default"
2142 and return -2;
2143 }
2144 }
2145 }
2146
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002147 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002148 return 0 if $in_bisect;
2149 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002150 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002151 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002152}
2153
Steven Rostedta75fece2010-11-02 14:58:27 -04002154sub run_git_bisect {
2155 my ($command) = @_;
2156
2157 doprint "$command ... ";
2158
2159 my $output = `$command 2>&1`;
2160 my $ret = $?;
2161
2162 logit $output;
2163
2164 if ($ret) {
2165 doprint "FAILED\n";
2166 dodie "Failed to git bisect";
2167 }
2168
2169 doprint "SUCCESS\n";
2170 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2171 doprint "$1 [$2]\n";
2172 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002173 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002174 doprint "Found bad commit... $1\n";
2175 return 0;
2176 } else {
2177 # we already logged it, just print it now.
2178 print $output;
2179 }
2180
2181 return 1;
2182}
2183
Steven Rostedtc23dca72011-03-08 09:26:31 -05002184sub bisect_reboot {
2185 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002186 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002187}
2188
2189# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002190sub run_bisect_test {
2191 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002192
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002193 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002194 my $result;
2195 my $output;
2196 my $ret;
2197
Steven Rostedt0a05c762010-11-08 11:14:10 -05002198 $in_bisect = 1;
2199
2200 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002201
2202 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002203 if ($failed && $bisect_skip) {
2204 $in_bisect = 0;
2205 return -1;
2206 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002207 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002208
2209 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002210 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002211
2212 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002213 if ($failed && $bisect_skip) {
2214 end_monitor;
2215 bisect_reboot;
2216 $in_bisect = 0;
2217 return -1;
2218 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002219 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002220
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002221 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002222 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002223 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002224 }
2225
2226 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002227 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002228 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002229 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002230 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002231
2232 # reboot the box to a kernel we can ssh to
2233 if ($type ne "build") {
2234 bisect_reboot;
2235 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002236 $in_bisect = 0;
2237
2238 return $result;
2239}
2240
2241sub run_bisect {
2242 my ($type) = @_;
2243 my $buildtype = "oldconfig";
2244
2245 # We should have a minconfig to use?
2246 if (defined($minconfig)) {
2247 $buildtype = "useconfig:$minconfig";
2248 }
2249
2250 my $ret = run_bisect_test $type, $buildtype;
2251
Steven Rostedtc960bb92011-03-08 09:22:39 -05002252 if ($bisect_manual) {
2253 $ret = answer_bisect;
2254 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002255
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002256 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002257 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002258 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002259 }
2260
Steven Rostedtc23dca72011-03-08 09:26:31 -05002261 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002262 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002263 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002264 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002265 } elsif ($bisect_skip) {
2266 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2267 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002268 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002269}
2270
Steven Rostedtdad98752011-11-22 20:48:57 -05002271sub update_bisect_replay {
2272 my $tmp_log = "$tmpdir/ktest_bisect_log";
2273 run_command "git bisect log > $tmp_log" or
2274 die "can't create bisect log";
2275 return $tmp_log;
2276}
2277
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002278sub bisect {
2279 my ($i) = @_;
2280
2281 my $result;
2282
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002283 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2284 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2285 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002286
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002287 my $good = $bisect_good;
2288 my $bad = $bisect_bad;
2289 my $type = $bisect_type;
2290 my $start = $bisect_start;
2291 my $replay = $bisect_replay;
2292 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002293
2294 if (defined($start_files)) {
2295 $start_files = " -- " . $start_files;
2296 } else {
2297 $start_files = "";
2298 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002299
Steven Rostedta57419b2010-11-02 15:13:54 -04002300 # convert to true sha1's
2301 $good = get_sha1($good);
2302 $bad = get_sha1($bad);
2303
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002304 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002305 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2306 $reverse_bisect = 1;
2307 } else {
2308 $reverse_bisect = 0;
2309 }
2310
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002311 # Can't have a test without having a test to run
2312 if ($type eq "test" && !defined($run_test)) {
2313 $type = "boot";
2314 }
2315
Steven Rostedtdad98752011-11-22 20:48:57 -05002316 # Check if a bisect was running
2317 my $bisect_start_file = "$builddir/.git/BISECT_START";
2318
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002319 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002320 my $do_check = defined($check) && $check ne "0";
2321
2322 if ( -f $bisect_start_file ) {
2323 print "Bisect in progress found\n";
2324 if ($do_check) {
2325 print " If you say yes, then no checks of good or bad will be done\n";
2326 }
2327 if (defined($replay)) {
2328 print "** BISECT_REPLAY is defined in config file **";
2329 print " Ignore config option and perform new git bisect log?\n";
2330 if (read_ync " (yes, no, or cancel) ") {
2331 $replay = update_bisect_replay;
2332 $do_check = 0;
2333 }
2334 } elsif (read_yn "read git log and continue?") {
2335 $replay = update_bisect_replay;
2336 $do_check = 0;
2337 }
2338 }
2339
2340 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002341
2342 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002343 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002344
2345 if ($check ne "good") {
2346 doprint "TESTING BISECT BAD [$bad]\n";
2347 run_command "git checkout $bad" or
2348 die "Failed to checkout $bad";
2349
2350 $result = run_bisect $type;
2351
2352 if ($result ne "bad") {
2353 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2354 }
2355 }
2356
2357 if ($check ne "bad") {
2358 doprint "TESTING BISECT GOOD [$good]\n";
2359 run_command "git checkout $good" or
2360 die "Failed to checkout $good";
2361
2362 $result = run_bisect $type;
2363
2364 if ($result ne "good") {
2365 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2366 }
2367 }
2368
2369 # checkout where we started
2370 run_command "git checkout $head" or
2371 die "Failed to checkout $head";
2372 }
2373
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002374 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002375 dodie "could not start bisect";
2376
2377 run_command "git bisect good $good" or
2378 dodie "could not set bisect good to $good";
2379
2380 run_git_bisect "git bisect bad $bad" or
2381 dodie "could not set bisect bad to $bad";
2382
2383 if (defined($replay)) {
2384 run_command "git bisect replay $replay" or
2385 dodie "failed to run replay";
2386 }
2387
2388 if (defined($start)) {
2389 run_command "git checkout $start" or
2390 dodie "failed to checkout $start";
2391 }
2392
2393 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002394 do {
2395 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002396 $test = run_git_bisect "git bisect $result";
2397 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002398
2399 run_command "git bisect log" or
2400 dodie "could not capture git bisect log";
2401
2402 run_command "git bisect reset" or
2403 dodie "could not reset git bisect";
2404
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002405 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002406
Steven Rostedt0a05c762010-11-08 11:14:10 -05002407 success $i;
2408}
2409
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002410# config_ignore holds the configs that were set (or unset) for
2411# a good config and we will ignore these configs for the rest
2412# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002413my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002414
2415# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002416my %config_set;
2417
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002418# config_off holds the set of configs that the bad config had disabled.
2419# We need to record them and set them in the .config when running
2420# oldnoconfig, because oldnoconfig does not turn off new symbols, but
2421# instead just keeps the defaults.
2422my %config_off;
2423
2424# config_off_tmp holds a set of configs to turn off for now
2425my @config_off_tmp;
2426
2427# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002428my %config_list;
2429my %null_config;
2430
2431my %dependency;
2432
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002433sub assign_configs {
2434 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002435
2436 open (IN, $config)
2437 or dodie "Failed to read $config";
2438
2439 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002440 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002441 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002442 }
2443 }
2444
2445 close(IN);
2446}
2447
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002448sub process_config_ignore {
2449 my ($config) = @_;
2450
2451 assign_configs \%config_ignore, $config;
2452}
2453
Steven Rostedt0a05c762010-11-08 11:14:10 -05002454sub read_current_config {
2455 my ($config_ref) = @_;
2456
2457 %{$config_ref} = ();
2458 undef %{$config_ref};
2459
2460 my @key = keys %{$config_ref};
2461 if ($#key >= 0) {
2462 print "did not delete!\n";
2463 exit;
2464 }
2465 open (IN, "$output_config");
2466
2467 while (<IN>) {
2468 if (/^(CONFIG\S+)=(.*)/) {
2469 ${$config_ref}{$1} = $2;
2470 }
2471 }
2472 close(IN);
2473}
2474
2475sub get_dependencies {
2476 my ($config) = @_;
2477
2478 my $arr = $dependency{$config};
2479 if (!defined($arr)) {
2480 return ();
2481 }
2482
2483 my @deps = @{$arr};
2484
2485 foreach my $dep (@{$arr}) {
2486 print "ADD DEP $dep\n";
2487 @deps = (@deps, get_dependencies $dep);
2488 }
2489
2490 return @deps;
2491}
2492
2493sub create_config {
2494 my @configs = @_;
2495
2496 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2497
2498 foreach my $config (@configs) {
2499 print OUT "$config_set{$config}\n";
2500 my @deps = get_dependencies $config;
2501 foreach my $dep (@deps) {
2502 print OUT "$config_set{$dep}\n";
2503 }
2504 }
2505
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002506 # turn off configs to keep off
2507 foreach my $config (keys %config_off) {
2508 print OUT "# $config is not set\n";
2509 }
2510
2511 # turn off configs that should be off for now
2512 foreach my $config (@config_off_tmp) {
2513 print OUT "# $config is not set\n";
2514 }
2515
Steven Rostedt0a05c762010-11-08 11:14:10 -05002516 foreach my $config (keys %config_ignore) {
2517 print OUT "$config_ignore{$config}\n";
2518 }
2519 close(OUT);
2520
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002521 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002522}
2523
2524sub compare_configs {
2525 my (%a, %b) = @_;
2526
2527 foreach my $item (keys %a) {
2528 if (!defined($b{$item})) {
2529 print "diff $item\n";
2530 return 1;
2531 }
2532 delete $b{$item};
2533 }
2534
2535 my @keys = keys %b;
2536 if ($#keys) {
2537 print "diff2 $keys[0]\n";
2538 }
2539 return -1 if ($#keys >= 0);
2540
2541 return 0;
2542}
2543
2544sub run_config_bisect_test {
2545 my ($type) = @_;
2546
2547 return run_bisect_test $type, "oldconfig";
2548}
2549
2550sub process_passed {
2551 my (%configs) = @_;
2552
2553 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2554 # Passed! All these configs are part of a good compile.
2555 # Add them to the min options.
2556 foreach my $config (keys %configs) {
2557 if (defined($config_list{$config})) {
2558 doprint " removing $config\n";
2559 $config_ignore{$config} = $config_list{$config};
2560 delete $config_list{$config};
2561 }
2562 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002563 doprint "config copied to $outputdir/config_good\n";
2564 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002565}
2566
2567sub process_failed {
2568 my ($config) = @_;
2569
2570 doprint "\n\n***************************************\n";
2571 doprint "Found bad config: $config\n";
2572 doprint "***************************************\n\n";
2573}
2574
2575sub run_config_bisect {
2576
2577 my @start_list = keys %config_list;
2578
2579 if ($#start_list < 0) {
2580 doprint "No more configs to test!!!\n";
2581 return -1;
2582 }
2583
2584 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002585 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002586 my $ret;
2587 my %current_config;
2588
2589 my $count = $#start_list + 1;
2590 doprint " $count configs to test\n";
2591
2592 my $half = int($#start_list / 2);
2593
2594 do {
2595 my @tophalf = @start_list[0 .. $half];
2596
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002597 # keep the bottom half off
2598 if ($half < $#start_list) {
2599 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2600 } else {
2601 @config_off_tmp = ();
2602 }
2603
Steven Rostedt0a05c762010-11-08 11:14:10 -05002604 create_config @tophalf;
2605 read_current_config \%current_config;
2606
2607 $count = $#tophalf + 1;
2608 doprint "Testing $count configs\n";
2609 my $found = 0;
2610 # make sure we test something
2611 foreach my $config (@tophalf) {
2612 if (defined($current_config{$config})) {
2613 logit " $config\n";
2614 $found = 1;
2615 }
2616 }
2617 if (!$found) {
2618 # try the other half
2619 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002620
2621 # keep the top half off
2622 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002623 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002624
Steven Rostedt0a05c762010-11-08 11:14:10 -05002625 create_config @tophalf;
2626 read_current_config \%current_config;
2627 foreach my $config (@tophalf) {
2628 if (defined($current_config{$config})) {
2629 logit " $config\n";
2630 $found = 1;
2631 }
2632 }
2633 if (!$found) {
2634 doprint "Failed: Can't make new config with current configs\n";
2635 foreach my $config (@start_list) {
2636 doprint " CONFIG: $config\n";
2637 }
2638 return -1;
2639 }
2640 $count = $#tophalf + 1;
2641 doprint "Testing $count configs\n";
2642 }
2643
2644 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002645 if ($bisect_manual) {
2646 $ret = answer_bisect;
2647 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002648 if ($ret) {
2649 process_passed %current_config;
2650 return 0;
2651 }
2652
2653 doprint "This config had a failure.\n";
2654 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002655 doprint "config copied to $outputdir/config_bad\n";
2656 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002657
2658 # A config exists in this group that was bad.
2659 foreach my $config (keys %config_list) {
2660 if (!defined($current_config{$config})) {
2661 doprint " removing $config\n";
2662 delete $config_list{$config};
2663 }
2664 }
2665
2666 @start_list = @tophalf;
2667
2668 if ($#start_list == 0) {
2669 process_failed $start_list[0];
2670 return 1;
2671 }
2672
2673 # remove half the configs we are looking at and see if
2674 # they are good.
2675 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002676 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002677
Steven Rostedtc960bb92011-03-08 09:22:39 -05002678 # we found a single config, try it again unless we are running manually
2679
2680 if ($bisect_manual) {
2681 process_failed $start_list[0];
2682 return 1;
2683 }
2684
Steven Rostedt0a05c762010-11-08 11:14:10 -05002685 my @tophalf = @start_list[0 .. 0];
2686
2687 $ret = run_config_bisect_test $type;
2688 if ($ret) {
2689 process_passed %current_config;
2690 return 0;
2691 }
2692
2693 process_failed $start_list[0];
2694 return 1;
2695}
2696
2697sub config_bisect {
2698 my ($i) = @_;
2699
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002700 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002701
2702 my $tmpconfig = "$tmpdir/use_config";
2703
Steven Rostedt30f75da2011-06-13 10:35:35 -04002704 if (defined($config_bisect_good)) {
2705 process_config_ignore $config_bisect_good;
2706 }
2707
Steven Rostedt0a05c762010-11-08 11:14:10 -05002708 # Make the file with the bad config and the min config
2709 if (defined($minconfig)) {
2710 # read the min config for things to ignore
2711 run_command "cp $minconfig $tmpconfig" or
2712 dodie "failed to copy $minconfig to $tmpconfig";
2713 } else {
2714 unlink $tmpconfig;
2715 }
2716
Steven Rostedt0a05c762010-11-08 11:14:10 -05002717 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002718 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002719 process_config_ignore $tmpconfig;
2720 }
2721
2722 # now process the start config
2723 run_command "cp $start_config $output_config" or
2724 dodie "failed to copy $start_config to $output_config";
2725
2726 # read directly what we want to check
2727 my %config_check;
2728 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002729 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002730
2731 while (<IN>) {
2732 if (/^((CONFIG\S*)=.*)/) {
2733 $config_check{$2} = $1;
2734 }
2735 }
2736 close(IN);
2737
Steven Rostedt250bae82011-07-15 22:05:59 -04002738 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002739 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002740
2741 # check to see what we lost (or gained)
2742 open (IN, $output_config)
2743 or dodie "Failed to read $start_config";
2744
2745 my %removed_configs;
2746 my %added_configs;
2747
2748 while (<IN>) {
2749 if (/^((CONFIG\S*)=.*)/) {
2750 # save off all options
2751 $config_set{$2} = $1;
2752 if (defined($config_check{$2})) {
2753 if (defined($config_ignore{$2})) {
2754 $removed_configs{$2} = $1;
2755 } else {
2756 $config_list{$2} = $1;
2757 }
2758 } elsif (!defined($config_ignore{$2})) {
2759 $added_configs{$2} = $1;
2760 $config_list{$2} = $1;
2761 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002762 } elsif (/^# ((CONFIG\S*).*)/) {
2763 # Keep these configs disabled
2764 $config_set{$2} = $1;
2765 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002766 }
2767 }
2768 close(IN);
2769
2770 my @confs = keys %removed_configs;
2771 if ($#confs >= 0) {
2772 doprint "Configs overridden by default configs and removed from check:\n";
2773 foreach my $config (@confs) {
2774 doprint " $config\n";
2775 }
2776 }
2777 @confs = keys %added_configs;
2778 if ($#confs >= 0) {
2779 doprint "Configs appearing in make oldconfig and added:\n";
2780 foreach my $config (@confs) {
2781 doprint " $config\n";
2782 }
2783 }
2784
2785 my %config_test;
2786 my $once = 0;
2787
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002788 @config_off_tmp = ();
2789
Steven Rostedt0a05c762010-11-08 11:14:10 -05002790 # Sometimes kconfig does weird things. We must make sure
2791 # that the config we autocreate has everything we need
2792 # to test, otherwise we may miss testing configs, or
2793 # may not be able to create a new config.
2794 # Here we create a config with everything set.
2795 create_config (keys %config_list);
2796 read_current_config \%config_test;
2797 foreach my $config (keys %config_list) {
2798 if (!defined($config_test{$config})) {
2799 if (!$once) {
2800 $once = 1;
2801 doprint "Configs not produced by kconfig (will not be checked):\n";
2802 }
2803 doprint " $config\n";
2804 delete $config_list{$config};
2805 }
2806 }
2807 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04002808
2809 if (defined($config_bisect_check) && $config_bisect_check) {
2810 doprint " Checking to make sure bad config with min config fails\n";
2811 create_config keys %config_list;
2812 $ret = run_config_bisect_test $config_bisect_type;
2813 if ($ret) {
2814 doprint " FAILED! Bad config with min config boots fine\n";
2815 return -1;
2816 }
2817 doprint " Bad config with min config fails as expected\n";
2818 }
2819
Steven Rostedt0a05c762010-11-08 11:14:10 -05002820 do {
2821 $ret = run_config_bisect;
2822 } while (!$ret);
2823
2824 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002825
2826 success $i;
2827}
2828
Steven Rostedt27d934b2011-05-20 09:18:18 -04002829sub patchcheck_reboot {
2830 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002831 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002832}
2833
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002834sub patchcheck {
2835 my ($i) = @_;
2836
2837 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002838 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002839 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002840 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002841
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002842 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002843
2844 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002845 if (defined($patchcheck_end)) {
2846 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002847 }
2848
Steven Rostedta57419b2010-11-02 15:13:54 -04002849 # Get the true sha1's since we can use things like HEAD~3
2850 $start = get_sha1($start);
2851 $end = get_sha1($end);
2852
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002853 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002854
2855 # Can't have a test without having a test to run
2856 if ($type eq "test" && !defined($run_test)) {
2857 $type = "boot";
2858 }
2859
2860 open (IN, "git log --pretty=oneline $end|") or
2861 dodie "could not get git list";
2862
2863 my @list;
2864
2865 while (<IN>) {
2866 chomp;
2867 $list[$#list+1] = $_;
2868 last if (/^$start/);
2869 }
2870 close(IN);
2871
2872 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002873 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002874 }
2875
2876 # go backwards in the list
2877 @list = reverse @list;
2878
2879 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002880 my %ignored_warnings;
2881
2882 if (defined($ignore_warnings)) {
2883 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2884 $ignored_warnings{$sha1} = 1;
2885 }
2886 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002887
2888 $in_patchcheck = 1;
2889 foreach my $item (@list) {
2890 my $sha1 = $item;
2891 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2892
2893 doprint "\nProcessing commit $item\n\n";
2894
2895 run_command "git checkout $sha1" or
2896 die "Failed to checkout $sha1";
2897
2898 # only clean on the first and last patch
2899 if ($item eq $list[0] ||
2900 $item eq $list[$#list]) {
2901 $noclean = $save_clean;
2902 } else {
2903 $noclean = 1;
2904 }
2905
2906 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002907 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002908 } else {
2909 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002910 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002911 }
2912
Steven Rostedt19902072011-06-14 20:46:25 -04002913
2914 if (!defined($ignored_warnings{$sha1})) {
2915 check_buildlog $sha1 or return 0;
2916 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002917
2918 next if ($type eq "build");
2919
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002920 my $failed = 0;
2921
Steven Rostedtddf607e2011-06-14 20:49:13 -04002922 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002923
2924 if (!$failed && $type ne "boot"){
2925 do_run_test or $failed = 1;
2926 }
2927 end_monitor;
2928 return 0 if ($failed);
2929
Steven Rostedt27d934b2011-05-20 09:18:18 -04002930 patchcheck_reboot;
2931
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002932 }
2933 $in_patchcheck = 0;
2934 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002935
2936 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002937}
2938
Steven Rostedtb9066f62011-07-15 21:25:24 -04002939my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002940my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002941my $iflevel = 0;
2942my @ifdeps;
2943
2944# prevent recursion
2945my %read_kconfigs;
2946
Steven Rostedtac6974c2011-10-04 09:40:17 -04002947sub add_dep {
2948 # $config depends on $dep
2949 my ($config, $dep) = @_;
2950
2951 if (defined($depends{$config})) {
2952 $depends{$config} .= " " . $dep;
2953 } else {
2954 $depends{$config} = $dep;
2955 }
2956
2957 # record the number of configs depending on $dep
2958 if (defined $depcount{$dep}) {
2959 $depcount{$dep}++;
2960 } else {
2961 $depcount{$dep} = 1;
2962 }
2963}
2964
Steven Rostedtb9066f62011-07-15 21:25:24 -04002965# taken from streamline_config.pl
2966sub read_kconfig {
2967 my ($kconfig) = @_;
2968
2969 my $state = "NONE";
2970 my $config;
2971 my @kconfigs;
2972
2973 my $cont = 0;
2974 my $line;
2975
2976
2977 if (! -f $kconfig) {
2978 doprint "file $kconfig does not exist, skipping\n";
2979 return;
2980 }
2981
2982 open(KIN, "$kconfig")
2983 or die "Can't open $kconfig";
2984 while (<KIN>) {
2985 chomp;
2986
2987 # Make sure that lines ending with \ continue
2988 if ($cont) {
2989 $_ = $line . " " . $_;
2990 }
2991
2992 if (s/\\$//) {
2993 $cont = 1;
2994 $line = $_;
2995 next;
2996 }
2997
2998 $cont = 0;
2999
3000 # collect any Kconfig sources
3001 if (/^source\s*"(.*)"/) {
3002 $kconfigs[$#kconfigs+1] = $1;
3003 }
3004
3005 # configs found
3006 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3007 $state = "NEW";
3008 $config = $2;
3009
3010 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003011 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003012 }
3013
3014 # collect the depends for the config
3015 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3016
Steven Rostedtac6974c2011-10-04 09:40:17 -04003017 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003018
3019 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003020 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3021
3022 # selected by depends on config
3023 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003024
3025 # Check for if statements
3026 } elsif (/^if\s+(.*\S)\s*$/) {
3027 my $deps = $1;
3028 # remove beginning and ending non text
3029 $deps =~ s/^[^a-zA-Z0-9_]*//;
3030 $deps =~ s/[^a-zA-Z0-9_]*$//;
3031
3032 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3033
3034 $ifdeps[$iflevel++] = join ':', @deps;
3035
3036 } elsif (/^endif/) {
3037
3038 $iflevel-- if ($iflevel);
3039
3040 # stop on "help"
3041 } elsif (/^\s*help\s*$/) {
3042 $state = "NONE";
3043 }
3044 }
3045 close(KIN);
3046
3047 # read in any configs that were found.
3048 foreach $kconfig (@kconfigs) {
3049 if (!defined($read_kconfigs{$kconfig})) {
3050 $read_kconfigs{$kconfig} = 1;
3051 read_kconfig("$builddir/$kconfig");
3052 }
3053 }
3054}
3055
3056sub read_depends {
3057 # find out which arch this is by the kconfig file
3058 open (IN, $output_config)
3059 or dodie "Failed to read $output_config";
3060 my $arch;
3061 while (<IN>) {
3062 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3063 $arch = $1;
3064 last;
3065 }
3066 }
3067 close IN;
3068
3069 if (!defined($arch)) {
3070 doprint "Could not find arch from config file\n";
3071 doprint "no dependencies used\n";
3072 return;
3073 }
3074
3075 # arch is really the subarch, we need to know
3076 # what directory to look at.
3077 if ($arch eq "i386" || $arch eq "x86_64") {
3078 $arch = "x86";
3079 } elsif ($arch =~ /^tile/) {
3080 $arch = "tile";
3081 }
3082
3083 my $kconfig = "$builddir/arch/$arch/Kconfig";
3084
3085 if (! -f $kconfig && $arch =~ /\d$/) {
3086 my $orig = $arch;
3087 # some subarchs have numbers, truncate them
3088 $arch =~ s/\d*$//;
3089 $kconfig = "$builddir/arch/$arch/Kconfig";
3090 if (! -f $kconfig) {
3091 doprint "No idea what arch dir $orig is for\n";
3092 doprint "no dependencies used\n";
3093 return;
3094 }
3095 }
3096
3097 read_kconfig($kconfig);
3098}
3099
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003100sub read_config_list {
3101 my ($config) = @_;
3102
3103 open (IN, $config)
3104 or dodie "Failed to read $config";
3105
3106 while (<IN>) {
3107 if (/^((CONFIG\S*)=.*)/) {
3108 if (!defined($config_ignore{$2})) {
3109 $config_list{$2} = $1;
3110 }
3111 }
3112 }
3113
3114 close(IN);
3115}
3116
3117sub read_output_config {
3118 my ($config) = @_;
3119
3120 assign_configs \%config_ignore, $config;
3121}
3122
3123sub make_new_config {
3124 my @configs = @_;
3125
3126 open (OUT, ">$output_config")
3127 or dodie "Failed to write $output_config";
3128
3129 foreach my $config (@configs) {
3130 print OUT "$config\n";
3131 }
3132 close OUT;
3133}
3134
Steven Rostedtac6974c2011-10-04 09:40:17 -04003135sub chomp_config {
3136 my ($config) = @_;
3137
3138 $config =~ s/CONFIG_//;
3139
3140 return $config;
3141}
3142
Steven Rostedtb9066f62011-07-15 21:25:24 -04003143sub get_depends {
3144 my ($dep) = @_;
3145
Steven Rostedtac6974c2011-10-04 09:40:17 -04003146 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003147
3148 $dep = $depends{"$kconfig"};
3149
3150 # the dep string we have saves the dependencies as they
3151 # were found, including expressions like ! && ||. We
3152 # want to split this out into just an array of configs.
3153
3154 my $valid = "A-Za-z_0-9";
3155
3156 my @configs;
3157
3158 while ($dep =~ /[$valid]/) {
3159
3160 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3161 my $conf = "CONFIG_" . $1;
3162
3163 $configs[$#configs + 1] = $conf;
3164
3165 $dep =~ s/^[^$valid]*[$valid]+//;
3166 } else {
3167 die "this should never happen";
3168 }
3169 }
3170
3171 return @configs;
3172}
3173
3174my %min_configs;
3175my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003176my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003177my %processed_configs;
3178my %nochange_config;
3179
3180sub test_this_config {
3181 my ($config) = @_;
3182
3183 my $found;
3184
3185 # if we already processed this config, skip it
3186 if (defined($processed_configs{$config})) {
3187 return undef;
3188 }
3189 $processed_configs{$config} = 1;
3190
3191 # if this config failed during this round, skip it
3192 if (defined($nochange_config{$config})) {
3193 return undef;
3194 }
3195
Steven Rostedtac6974c2011-10-04 09:40:17 -04003196 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003197
3198 # Test dependencies first
3199 if (defined($depends{"$kconfig"})) {
3200 my @parents = get_depends $config;
3201 foreach my $parent (@parents) {
3202 # if the parent is in the min config, check it first
3203 next if (!defined($min_configs{$parent}));
3204 $found = test_this_config($parent);
3205 if (defined($found)) {
3206 return $found;
3207 }
3208 }
3209 }
3210
3211 # Remove this config from the list of configs
3212 # do a make oldnoconfig and then read the resulting
3213 # .config to make sure it is missing the config that
3214 # we had before
3215 my %configs = %min_configs;
3216 delete $configs{$config};
3217 make_new_config ((values %configs), (values %keep_configs));
3218 make_oldconfig;
3219 undef %configs;
3220 assign_configs \%configs, $output_config;
3221
3222 return $config if (!defined($configs{$config}));
3223
3224 doprint "disabling config $config did not change .config\n";
3225
3226 $nochange_config{$config} = 1;
3227
3228 return undef;
3229}
3230
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003231sub make_min_config {
3232 my ($i) = @_;
3233
Steven Rostedtccc513b2012-05-21 17:13:40 -04003234 my $type = $minconfig_type;
3235 if ($type ne "boot" && $type ne "test") {
3236 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3237 " make_min_config works only with 'boot' and 'test'\n" and return;
3238 }
3239
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003240 if (!defined($output_minconfig)) {
3241 fail "OUTPUT_MIN_CONFIG not defined" and return;
3242 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003243
3244 # If output_minconfig exists, and the start_minconfig
3245 # came from min_config, than ask if we should use
3246 # that instead.
3247 if (-f $output_minconfig && !$start_minconfig_defined) {
3248 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003249 if (!defined($use_output_minconfig)) {
3250 if (read_yn " Use it as minconfig?") {
3251 $start_minconfig = $output_minconfig;
3252 }
3253 } elsif ($use_output_minconfig > 0) {
3254 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003255 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003256 } else {
3257 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003258 }
3259 }
3260
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003261 if (!defined($start_minconfig)) {
3262 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3263 }
3264
Steven Rostedt35ce5952011-07-15 21:57:25 -04003265 my $temp_config = "$tmpdir/temp_config";
3266
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003267 # First things first. We build an allnoconfig to find
3268 # out what the defaults are that we can't touch.
3269 # Some are selections, but we really can't handle selections.
3270
3271 my $save_minconfig = $minconfig;
3272 undef $minconfig;
3273
3274 run_command "$make allnoconfig" or return 0;
3275
Steven Rostedtb9066f62011-07-15 21:25:24 -04003276 read_depends;
3277
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003278 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003279
Steven Rostedt43d1b652011-07-15 22:01:56 -04003280 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003281 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003282
3283 if (defined($ignore_config)) {
3284 # make sure the file exists
3285 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003286 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003287 }
3288
Steven Rostedt43d1b652011-07-15 22:01:56 -04003289 %keep_configs = %save_configs;
3290
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003291 doprint "Load initial configs from $start_minconfig\n";
3292
3293 # Look at the current min configs, and save off all the
3294 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003295 assign_configs \%min_configs, $start_minconfig;
3296
3297 my @config_keys = keys %min_configs;
3298
Steven Rostedtac6974c2011-10-04 09:40:17 -04003299 # All configs need a depcount
3300 foreach my $config (@config_keys) {
3301 my $kconfig = chomp_config $config;
3302 if (!defined $depcount{$kconfig}) {
3303 $depcount{$kconfig} = 0;
3304 }
3305 }
3306
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003307 # Remove anything that was set by the make allnoconfig
3308 # we shouldn't need them as they get set for us anyway.
3309 foreach my $config (@config_keys) {
3310 # Remove anything in the ignore_config
3311 if (defined($keep_configs{$config})) {
3312 my $file = $ignore_config;
3313 $file =~ s,.*/(.*?)$,$1,;
3314 doprint "$config set by $file ... ignored\n";
3315 delete $min_configs{$config};
3316 next;
3317 }
3318 # But make sure the settings are the same. If a min config
3319 # sets a selection, we do not want to get rid of it if
3320 # it is not the same as what we have. Just move it into
3321 # the keep configs.
3322 if (defined($config_ignore{$config})) {
3323 if ($config_ignore{$config} ne $min_configs{$config}) {
3324 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3325 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3326 $keep_configs{$config} = $min_configs{$config};
3327 } else {
3328 doprint "$config set by allnoconfig ... ignored\n";
3329 }
3330 delete $min_configs{$config};
3331 }
3332 }
3333
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003334 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003335 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003336
3337 while (!$done) {
3338
3339 my $config;
3340 my $found;
3341
3342 # Now disable each config one by one and do a make oldconfig
3343 # till we find a config that changes our list.
3344
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003345 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003346
3347 # Sort keys by who is most dependent on
3348 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3349 @test_configs ;
3350
3351 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003352 my $reset = 1;
3353 for (my $i = 0; $i < $#test_configs; $i++) {
3354 if (!defined($nochange_config{$test_configs[0]})) {
3355 $reset = 0;
3356 last;
3357 }
3358 # This config didn't change the .config last time.
3359 # Place it at the end
3360 my $config = shift @test_configs;
3361 push @test_configs, $config;
3362 }
3363
3364 # if every test config has failed to modify the .config file
3365 # in the past, then reset and start over.
3366 if ($reset) {
3367 undef %nochange_config;
3368 }
3369
Steven Rostedtb9066f62011-07-15 21:25:24 -04003370 undef %processed_configs;
3371
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003372 foreach my $config (@test_configs) {
3373
Steven Rostedtb9066f62011-07-15 21:25:24 -04003374 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003375
Steven Rostedtb9066f62011-07-15 21:25:24 -04003376 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003377
3378 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003379 }
3380
3381 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003382 # we could have failed due to the nochange_config hash
3383 # reset and try again
3384 if (!$take_two) {
3385 undef %nochange_config;
3386 $take_two = 1;
3387 next;
3388 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003389 doprint "No more configs found that we can disable\n";
3390 $done = 1;
3391 last;
3392 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003393 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003394
3395 $config = $found;
3396
3397 doprint "Test with $config disabled\n";
3398
3399 # set in_bisect to keep build and monitor from dieing
3400 $in_bisect = 1;
3401
3402 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003403 build "oldconfig" or $failed = 1;
3404 if (!$failed) {
3405 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003406
3407 if ($type eq "test" && !$failed) {
3408 do_run_test or $failed = 1;
3409 }
3410
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003411 end_monitor;
3412 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003413
3414 $in_bisect = 0;
3415
3416 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003417 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003418 # this config is needed, add it to the ignore list.
3419 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003420 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003421 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003422
3423 # update new ignore configs
3424 if (defined($ignore_config)) {
3425 open (OUT, ">$temp_config")
3426 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003427 foreach my $config (keys %save_configs) {
3428 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003429 }
3430 close OUT;
3431 run_command "mv $temp_config $ignore_config" or
3432 dodie "failed to copy update to $ignore_config";
3433 }
3434
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003435 } else {
3436 # We booted without this config, remove it from the minconfigs.
3437 doprint "$config is not needed, disabling\n";
3438
3439 delete $min_configs{$config};
3440
3441 # Also disable anything that is not enabled in this config
3442 my %configs;
3443 assign_configs \%configs, $output_config;
3444 my @config_keys = keys %min_configs;
3445 foreach my $config (@config_keys) {
3446 if (!defined($configs{$config})) {
3447 doprint "$config is not set, disabling\n";
3448 delete $min_configs{$config};
3449 }
3450 }
3451
3452 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003453 open (OUT, ">$temp_config")
3454 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003455 foreach my $config (keys %keep_configs) {
3456 print OUT "$keep_configs{$config}\n";
3457 }
3458 foreach my $config (keys %min_configs) {
3459 print OUT "$min_configs{$config}\n";
3460 }
3461 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003462
3463 run_command "mv $temp_config $output_minconfig" or
3464 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003465 }
3466
3467 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003468 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003469 }
3470
3471 success $i;
3472 return 1;
3473}
3474
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003475$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003476
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003477if ($#ARGV == 0) {
3478 $ktest_config = $ARGV[0];
3479 if (! -f $ktest_config) {
3480 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003481 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003482 exit 0;
3483 }
3484 }
3485} else {
3486 $ktest_config = "ktest.conf";
3487}
3488
3489if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003490 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003491 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003492 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3493 print OUT << "EOF"
3494# Generated by ktest.pl
3495#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003496
3497# PWD is a ktest.pl variable that will result in the process working
3498# directory that ktest.pl is executed in.
3499
3500# THIS_DIR is automatically assigned the PWD of the path that generated
3501# the config file. It is best to use this variable when assigning other
3502# directory paths within this directory. This allows you to easily
3503# move the test cases to other locations or to other machines.
3504#
3505THIS_DIR := $variable{"PWD"}
3506
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003507# Define each test with TEST_START
3508# The config options below it will override the defaults
3509TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003510TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003511
3512DEFAULTS
3513EOF
3514;
3515 close(OUT);
3516}
3517read_config $ktest_config;
3518
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003519if (defined($opt{"LOG_FILE"})) {
3520 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3521}
3522
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003523# Append any configs entered in manually to the config file.
3524my @new_configs = keys %entered_configs;
3525if ($#new_configs >= 0) {
3526 print "\nAppending entered in configs to $ktest_config\n";
3527 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3528 foreach my $config (@new_configs) {
3529 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003530 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003531 }
3532}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003533
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003534if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3535 unlink $opt{"LOG_FILE"};
3536}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003537
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003538doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3539
Steven Rostedta57419b2010-11-02 15:13:54 -04003540for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3541
3542 if (!$i) {
3543 doprint "DEFAULT OPTIONS:\n";
3544 } else {
3545 doprint "\nTEST $i OPTIONS";
3546 if (defined($repeat_tests{$i})) {
3547 $repeat = $repeat_tests{$i};
3548 doprint " ITERATE $repeat";
3549 }
3550 doprint "\n";
3551 }
3552
3553 foreach my $option (sort keys %opt) {
3554
3555 if ($option =~ /\[(\d+)\]$/) {
3556 next if ($i != $1);
3557 } else {
3558 next if ($i);
3559 }
3560
3561 doprint "$option = $opt{$option}\n";
3562 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003563}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003564
Steven Rostedt2a625122011-05-20 15:48:59 -04003565sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003566 my ($name, $i) = @_;
3567
3568 my $option = "$name\[$i\]";
3569
3570 if (defined($opt{$option})) {
3571 return $opt{$option};
3572 }
3573
Steven Rostedta57419b2010-11-02 15:13:54 -04003574 foreach my $test (keys %repeat_tests) {
3575 if ($i >= $test &&
3576 $i < $test + $repeat_tests{$test}) {
3577 $option = "$name\[$test\]";
3578 if (defined($opt{$option})) {
3579 return $opt{$option};
3580 }
3581 }
3582 }
3583
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003584 if (defined($opt{$name})) {
3585 return $opt{$name};
3586 }
3587
3588 return undef;
3589}
3590
Steven Rostedt2a625122011-05-20 15:48:59 -04003591sub set_test_option {
3592 my ($name, $i) = @_;
3593
3594 my $option = __set_test_option($name, $i);
3595 return $option if (!defined($option));
3596
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003597 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003598}
3599
Steven Rostedt2545eb62010-11-02 15:01:32 -04003600# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003601for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003602
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003603 # Do not reboot on failing test options
3604 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003605 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003606
Steven Rostedt683a3e62012-05-18 13:34:35 -04003607 $have_version = 0;
3608
Steven Rostedt576f6272010-11-02 14:58:38 -04003609 $iteration = $i;
3610
Steven Rostedta75fece2010-11-02 14:58:27 -04003611 my $makecmd = set_test_option("MAKE_CMD", $i);
3612
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003613 # Load all the options into their mapped variable names
3614 foreach my $opt (keys %option_map) {
3615 ${$option_map{$opt}} = set_test_option($opt, $i);
3616 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003617
Steven Rostedt35ce5952011-07-15 21:57:25 -04003618 $start_minconfig_defined = 1;
3619
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003620 # The first test may override the PRE_KTEST option
3621 if (defined($pre_ktest) && $i == 1) {
3622 doprint "\n";
3623 run_command $pre_ktest;
3624 }
3625
3626 # Any test can override the POST_KTEST option
3627 # The last test takes precedence.
3628 if (defined($post_ktest)) {
3629 $final_post_ktest = $post_ktest;
3630 }
3631
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003632 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003633 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003634 $start_minconfig = $minconfig;
3635 }
3636
Steven Rostedta75fece2010-11-02 14:58:27 -04003637 chdir $builddir || die "can't change directory to $builddir";
3638
Andrew Jonesa908a662011-08-12 15:32:03 +02003639 foreach my $dir ($tmpdir, $outputdir) {
3640 if (!-d $dir) {
3641 mkpath($dir) or
3642 die "can't create $dir";
3643 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003644 }
3645
Steven Rostedte48c5292010-11-02 14:35:37 -04003646 $ENV{"SSH_USER"} = $ssh_user;
3647 $ENV{"MACHINE"} = $machine;
3648
Steven Rostedta75fece2010-11-02 14:58:27 -04003649 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303650 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003651 $dmesg = "$tmpdir/dmesg-$machine";
3652 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003653 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003654
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003655 if (!$buildonly) {
3656 $target = "$ssh_user\@$machine";
3657 if ($reboot_type eq "grub") {
3658 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003659 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003660 }
3661
3662 my $run_type = $build_type;
3663 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003664 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003665 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003666 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003667 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003668 $run_type = $config_bisect_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003669 }
3670
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003671 if ($test_type eq "make_min_config") {
3672 $run_type = "";
3673 }
3674
Steven Rostedta75fece2010-11-02 14:58:27 -04003675 # mistake in config file?
3676 if (!defined($run_type)) {
3677 $run_type = "ERROR";
3678 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003679
Steven Rostedte0a87422011-09-30 17:50:48 -04003680 my $installme = "";
3681 $installme = " no_install" if ($no_install);
3682
Steven Rostedt2545eb62010-11-02 15:01:32 -04003683 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003684 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003685
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003686 if (defined($pre_test)) {
3687 run_command $pre_test;
3688 }
3689
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003690 unlink $dmesg;
3691 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303692 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003693
Steven Rostedt250bae82011-07-15 22:05:59 -04003694 if (defined($addconfig)) {
3695 my $min = $minconfig;
3696 if (!defined($minconfig)) {
3697 $min = "";
3698 }
3699 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003700 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003701 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003702 }
3703
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003704 if (defined($checkout)) {
3705 run_command "git checkout $checkout" or
3706 die "failed to checkout $checkout";
3707 }
3708
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003709 $no_reboot = 0;
3710
Steven Rostedt648a1822012-03-21 11:18:27 -04003711 # A test may opt to not reboot the box
3712 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003713 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04003714 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003715
Steven Rostedta75fece2010-11-02 14:58:27 -04003716 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003717 bisect $i;
3718 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003719 } elsif ($test_type eq "config_bisect") {
3720 config_bisect $i;
3721 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003722 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003723 patchcheck $i;
3724 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003725 } elsif ($test_type eq "make_min_config") {
3726 make_min_config $i;
3727 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003728 }
3729
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003730 if ($build_type ne "nobuild") {
3731 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003732 }
3733
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003734 if ($test_type eq "install") {
3735 get_version;
3736 install;
3737 success $i;
3738 next;
3739 }
3740
Steven Rostedta75fece2010-11-02 14:58:27 -04003741 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003742 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003743 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003744
3745 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3746 do_run_test or $failed = 1;
3747 }
3748 end_monitor;
3749 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003750 }
3751
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003752 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003753}
3754
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003755if (defined($final_post_ktest)) {
3756 run_command $final_post_ktest;
3757}
3758
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003759if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003760 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003761} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003762 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04003763} elsif (defined($switch_to_good)) {
3764 # still need to get to the good kernel
3765 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003766}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003767
Steven Rostedt648a1822012-03-21 11:18:27 -04003768
Steven Rostedte48c5292010-11-02 14:35:37 -04003769doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3770
Steven Rostedt2545eb62010-11-02 15:01:32 -04003771exit 0;