blob: 0ed73b5ebbfc1c7277ce1702f4fa2bf033732e6d [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;
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400626 } elsif ($cmp eq "=~") {
627 return $lval =~ m/$rval/;
628 } elsif ($cmp eq "!~") {
629 return $lval !~ m/$rval/;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400630 }
631
632 my $statement = "$lval $cmp $rval";
633 my $ret = eval $statement;
634
635 # $@ stores error of eval
636 if ($@) {
637 return -1;
638 }
639
640 return $ret;
641}
642
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400643sub value_defined {
644 my ($val) = @_;
645
646 return defined($variable{$2}) ||
647 defined($opt{$2});
648}
649
Steven Rostedt8d735212011-10-17 11:36:44 -0400650my $d = 0;
651sub process_expression {
652 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400653
Steven Rostedt8d735212011-10-17 11:36:44 -0400654 my $c = $d++;
655
656 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
657 my $express = $1;
658
659 if (process_expression($name, $express)) {
660 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
661 } else {
662 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
663 }
664 }
665
666 $d--;
667 my $OR = "\\|\\|";
668 my $AND = "\\&\\&";
669
670 while ($val =~ s/^(.*?)($OR|$AND)//) {
671 my $express = $1;
672 my $op = $2;
673
674 if (process_expression($name, $express)) {
675 if ($op eq "||") {
676 return 1;
677 }
678 } else {
679 if ($op eq "&&") {
680 return 0;
681 }
682 }
683 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400684
Steven Rostedt8fddbe92012-07-30 14:37:01 -0400685 if ($val =~ /(.*)(==|\!=|>=|<=|>|<|=~|\!~)(.*)/) {
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400686 my $ret = process_compare($1, $2, $3);
687 if ($ret < 0) {
688 die "$name: $.: Unable to process comparison\n";
689 }
690 return $ret;
691 }
692
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400693 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
694 if (defined $1) {
695 return !value_defined($2);
696 } else {
697 return value_defined($2);
698 }
699 }
700
Steven Rostedt45d73a52011-09-30 19:44:53 -0400701 if ($val =~ /^\s*0\s*$/) {
702 return 0;
703 } elsif ($val =~ /^\s*\d+\s*$/) {
704 return 1;
705 }
706
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400707 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400708}
709
710sub process_if {
711 my ($name, $value) = @_;
712
713 # Convert variables and replace undefined ones with 0
714 my $val = process_variables($value, 1);
715 my $ret = process_expression $name, $val;
716
717 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400718}
719
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400720sub __read_config {
721 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400722
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400723 my $in;
724 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400725
Steven Rostedta57419b2010-11-02 15:13:54 -0400726 my $name = $config;
727 $name =~ s,.*/(.*),$1,;
728
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400729 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400730 my $default = 1;
731 my $repeat = 1;
732 my $num_tests_set = 0;
733 my $skip = 0;
734 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400735 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400736 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400737 my $if = 0;
738 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400739 my $override = 0;
740
741 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400742
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400743 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400744
745 # ignore blank lines and comments
746 next if (/^\s*$/ || /\s*\#/);
747
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400748 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400749
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400750 my $type = $1;
751 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400752 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400753
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400754 my $old_test_num;
755 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400756 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400757
758 if ($type eq "TEST_START") {
759
760 if ($num_tests_set) {
761 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
762 }
763
764 $old_test_num = $test_num;
765 $old_repeat = $repeat;
766
767 $test_num += $repeat;
768 $default = 0;
769 $repeat = 1;
770 } else {
771 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400772 }
773
Steven Rostedta9f84422011-10-17 11:06:29 -0400774 # If SKIP is anywhere in the line, the command will be skipped
775 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400776 $skip = 1;
777 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400778 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400779 $skip = 0;
780 }
781
Steven Rostedta9f84422011-10-17 11:06:29 -0400782 if ($rest =~ s/\sELSE\b//) {
783 if (!$if) {
784 die "$name: $.: ELSE found with out matching IF section\n$_";
785 }
786 $if = 0;
787
788 if ($if_set) {
789 $skip = 1;
790 } else {
791 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400792 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400793 }
794
Steven Rostedta9f84422011-10-17 11:06:29 -0400795 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400796 if (process_if($name, $1)) {
797 $if_set = 1;
798 } else {
799 $skip = 1;
800 }
801 $if = 1;
802 } else {
803 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400804 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400805 }
806
Steven Rostedta9f84422011-10-17 11:06:29 -0400807 if (!$skip) {
808 if ($type eq "TEST_START") {
809 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
810 $repeat = $1;
811 $repeat_tests{"$test_num"} = $repeat;
812 }
813 } elsif ($rest =~ s/\sOVERRIDE\b//) {
814 # DEFAULT only
815 $override = 1;
816 # Clear previous overrides
817 %overrides = ();
818 }
819 }
820
821 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400822 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400823 }
824
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400825 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400826 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400827 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400828 }
829
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400830 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400831 if (!$if) {
832 die "$name: $.: ELSE found with out matching IF section\n$_";
833 }
834 $rest = $1;
835 if ($if_set) {
836 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400837 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400838 } else {
839 $skip = 0;
840
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400841 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400842 # May be a ELSE IF section.
843 if (!process_if($name, $1)) {
844 $skip = 1;
845 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400846 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400847 } else {
848 $if = 0;
849 }
850 }
851
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400852 if ($rest !~ /^\s*$/) {
853 die "$name: $.: Gargbage found after DEFAULTS\n$_";
854 }
855
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400856 } elsif (/^\s*INCLUDE\s+(\S+)/) {
857
858 next if ($skip);
859
860 if (!$default) {
861 die "$name: $.: INCLUDE can only be done in default sections\n$_";
862 }
863
864 my $file = process_variables($1);
865
866 if ($file !~ m,^/,) {
867 # check the path of the config file first
868 if ($config =~ m,(.*)/,) {
869 if (-f "$1/$file") {
870 $file = "$1/$file";
871 }
872 }
873 }
874
875 if ( ! -r $file ) {
876 die "$name: $.: Can't read file $file\n$_";
877 }
878
879 if (__read_config($file, \$test_num)) {
880 $test_case = 1;
881 }
882
Steven Rostedta57419b2010-11-02 15:13:54 -0400883 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
884
885 next if ($skip);
886
Steven Rostedt2545eb62010-11-02 15:01:32 -0400887 my $lvalue = $1;
888 my $rvalue = $2;
889
Steven Rostedta57419b2010-11-02 15:13:54 -0400890 if (!$default &&
891 ($lvalue eq "NUM_TESTS" ||
892 $lvalue eq "LOG_FILE" ||
893 $lvalue eq "CLEAR_LOG")) {
894 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400895 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400896
897 if ($lvalue eq "NUM_TESTS") {
898 if ($test_num) {
899 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
900 }
901 if (!$default) {
902 die "$name: $.: NUM_TESTS must be set in default section\n";
903 }
904 $num_tests_set = 1;
905 }
906
907 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400908 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400909 } else {
910 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400911 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400912
913 if ($repeat > 1) {
914 $repeats{$val} = $repeat;
915 }
916 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400917 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
918 next if ($skip);
919
920 my $lvalue = $1;
921 my $rvalue = $2;
922
923 # process config variables.
924 # Config variables are only active while reading the
925 # config and can be defined anywhere. They also ignore
926 # TEST_START and DEFAULTS, but are skipped if they are in
927 # on of these sections that have SKIP defined.
928 # The save variable can be
929 # defined multiple times and the new one simply overrides
930 # the prevous one.
931 set_variable($lvalue, $rvalue);
932
Steven Rostedta57419b2010-11-02 15:13:54 -0400933 } else {
934 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400935 }
936 }
937
Steven Rostedta57419b2010-11-02 15:13:54 -0400938 if ($test_num) {
939 $test_num += $repeat - 1;
940 $opt{"NUM_TESTS"} = $test_num;
941 }
942
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400943 close($in);
944
945 $$current_test_num = $test_num;
946
947 return $test_case;
948}
949
Steven Rostedtc4261d02011-11-23 13:41:18 -0500950sub get_test_case {
951 print "What test case would you like to run?\n";
952 print " (build, install or boot)\n";
953 print " Other tests are available but require editing the config file\n";
954 my $ans = <STDIN>;
955 chomp $ans;
956 $default{"TEST_TYPE"} = $ans;
957}
958
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400959sub read_config {
960 my ($config) = @_;
961
962 my $test_case;
963 my $test_num = 0;
964
965 $test_case = __read_config $config, \$test_num;
966
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500967 # make sure we have all mandatory configs
968 get_ktest_configs;
969
Steven Rostedt0df213c2011-06-14 20:51:37 -0400970 # was a test specified?
971 if (!$test_case) {
972 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500973 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400974 }
975
Steven Rostedta75fece2010-11-02 14:58:27 -0400976 # set any defaults
977
978 foreach my $default (keys %default) {
979 if (!defined($opt{$default})) {
980 $opt{$default} = $default{$default};
981 }
982 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500983
984 if ($opt{"IGNORE_UNUSED"} == 1) {
985 return;
986 }
987
988 my %not_used;
989
990 # check if there are any stragglers (typos?)
991 foreach my $option (keys %opt) {
992 my $op = $option;
993 # remove per test labels.
994 $op =~ s/\[.*\]//;
995 if (!exists($option_map{$op}) &&
996 !exists($default{$op}) &&
997 !exists($used_options{$op})) {
998 $not_used{$op} = 1;
999 }
1000 }
1001
1002 if (%not_used) {
1003 my $s = "s are";
1004 $s = " is" if (keys %not_used == 1);
1005 print "The following option$s not used; could be a typo:\n";
1006 foreach my $option (keys %not_used) {
1007 print "$option\n";
1008 }
1009 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1010 if (!read_yn "Do you want to continue?") {
1011 exit -1;
1012 }
1013 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001014}
1015
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001016sub __eval_option {
1017 my ($option, $i) = @_;
1018
1019 # Add space to evaluate the character before $
1020 $option = " $option";
1021 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301022 my $repeated = 0;
1023 my $parent = 0;
1024
1025 foreach my $test (keys %repeat_tests) {
1026 if ($i >= $test &&
1027 $i < $test + $repeat_tests{$test}) {
1028
1029 $repeated = 1;
1030 $parent = $test;
1031 last;
1032 }
1033 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001034
1035 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1036 my $start = $1;
1037 my $var = $2;
1038 my $end = $3;
1039
1040 # Append beginning of line
1041 $retval = "$retval$start";
1042
1043 # If the iteration option OPT[$i] exists, then use that.
1044 # otherwise see if the default OPT (without [$i]) exists.
1045
1046 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301047 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001048
1049 if (defined($opt{$o})) {
1050 $o = $opt{$o};
1051 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301052 } elsif ($repeated && defined($opt{$parento})) {
1053 $o = $opt{$parento};
1054 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001055 } elsif (defined($opt{$var})) {
1056 $o = $opt{$var};
1057 $retval = "$retval$o";
1058 } else {
1059 $retval = "$retval\$\{$var\}";
1060 }
1061
1062 $option = $end;
1063 }
1064
1065 $retval = "$retval$option";
1066
1067 $retval =~ s/^ //;
1068
1069 return $retval;
1070}
1071
1072sub eval_option {
1073 my ($option, $i) = @_;
1074
1075 my $prev = "";
1076
1077 # Since an option can evaluate to another option,
1078 # keep iterating until we do not evaluate any more
1079 # options.
1080 my $r = 0;
1081 while ($prev ne $option) {
1082 # Check for recursive evaluations.
1083 # 100 deep should be more than enough.
1084 if ($r++ > 100) {
1085 die "Over 100 evaluations accurred with $option\n" .
1086 "Check for recursive variables\n";
1087 }
1088 $prev = $option;
1089 $option = __eval_option($option, $i);
1090 }
1091
1092 return $option;
1093}
1094
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001095sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001096 if (defined($opt{"LOG_FILE"})) {
1097 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1098 print OUT @_;
1099 close(OUT);
1100 }
1101}
1102
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001103sub logit {
1104 if (defined($opt{"LOG_FILE"})) {
1105 _logit @_;
1106 } else {
1107 print @_;
1108 }
1109}
1110
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001111sub doprint {
1112 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001113 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001114}
1115
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001116sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001117sub start_monitor;
1118sub end_monitor;
1119sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001120
1121sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001122 my ($time) = @_;
1123
Steven Rostedt2b803362011-09-30 18:00:23 -04001124 if (defined($time)) {
1125 start_monitor;
1126 # flush out current monitor
1127 # May contain the reboot success line
1128 wait_for_monitor 1;
1129 }
1130
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001131 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001132 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001133 if (defined($powercycle_after_reboot)) {
1134 sleep $powercycle_after_reboot;
1135 run_command "$power_cycle";
1136 }
1137 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001138 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001139 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001140 }
Andrew Jones2728be42011-08-12 15:32:05 +02001141
1142 if (defined($time)) {
Steven Rostedt407b95b2012-07-19 16:05:42 -04001143 if (wait_for_monitor($time, $reboot_success_line)) {
1144 # reboot got stuck?
Steven Rostedt8a80c722012-07-19 16:08:33 -04001145 doprint "Reboot did not finish. Forcing power cycle\n";
Steven Rostedt407b95b2012-07-19 16:05:42 -04001146 run_command "$power_cycle";
1147 }
Andrew Jones2728be42011-08-12 15:32:05 +02001148 end_monitor;
1149 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001150}
1151
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001152sub reboot_to_good {
1153 my ($time) = @_;
1154
1155 if (defined($switch_to_good)) {
1156 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001157 }
1158
1159 reboot $time;
1160}
1161
Steven Rostedt576f6272010-11-02 14:58:38 -04001162sub do_not_reboot {
1163 my $i = $iteration;
1164
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001165 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001166 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1167 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1168}
1169
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001170sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001171 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001172
Steven Rostedt576f6272010-11-02 14:58:38 -04001173 my $i = $iteration;
1174
1175 if ($reboot_on_error && !do_not_reboot) {
1176
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001177 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001178 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001179
Steven Rostedta75fece2010-11-02 14:58:27 -04001180 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001181 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001182 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001183 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001184
Steven Rostedtf80802c2011-03-07 13:18:47 -05001185 if (defined($opt{"LOG_FILE"})) {
1186 print " See $opt{LOG_FILE} for more info.\n";
1187 }
1188
Steven Rostedt576f6272010-11-02 14:58:38 -04001189 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001190}
1191
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001192sub open_console {
1193 my ($fp) = @_;
1194
1195 my $flags;
1196
Steven Rostedta75fece2010-11-02 14:58:27 -04001197 my $pid = open($fp, "$console|") or
1198 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001199
1200 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001201 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001202 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001203 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001204
1205 return $pid;
1206}
1207
1208sub close_console {
1209 my ($fp, $pid) = @_;
1210
1211 doprint "kill child process $pid\n";
1212 kill 2, $pid;
1213
1214 print "closing!\n";
1215 close($fp);
1216}
1217
1218sub start_monitor {
1219 if ($monitor_cnt++) {
1220 return;
1221 }
1222 $monitor_fp = \*MONFD;
1223 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001224
1225 return;
1226
1227 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001228}
1229
1230sub end_monitor {
1231 if (--$monitor_cnt) {
1232 return;
1233 }
1234 close_console($monitor_fp, $monitor_pid);
1235}
1236
1237sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001238 my ($time, $stop) = @_;
1239 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001240 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001241 my $booted = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001242 my $start_time = time;
Steven Rostedt8a80c722012-07-19 16:08:33 -04001243 my $skip_call_trace = 0;
1244 my $bug = 0;
1245 my $bug_ignored = 0;
Steven Rostedt407b95b2012-07-19 16:05:42 -04001246 my $now;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001247
Steven Rostedta75fece2010-11-02 14:58:27 -04001248 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001249
1250 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001251 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001252 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001253 last if (!defined($line));
1254 print "$line";
1255 $full_line .= $line;
1256
1257 if (defined($stop) && $full_line =~ /$stop/) {
1258 doprint "wait for monitor detected $stop\n";
1259 $booted = 1;
1260 }
1261
Steven Rostedt8a80c722012-07-19 16:08:33 -04001262 if ($full_line =~ /\[ backtrace testing \]/) {
1263 $skip_call_trace = 1;
1264 }
1265
1266 if ($full_line =~ /call trace:/i) {
1267 if (!$bug && !$skip_call_trace) {
1268 if ($ignore_errors) {
1269 $bug_ignored = 1;
1270 } else {
1271 $bug = 1;
1272 }
1273 }
1274 }
1275
1276 if ($full_line =~ /\[ end of backtrace testing \]/) {
1277 $skip_call_trace = 0;
1278 }
1279
1280 if ($full_line =~ /Kernel panic -/) {
1281 $bug = 1;
1282 }
1283
Steven Rostedt2b803362011-09-30 18:00:23 -04001284 if ($line =~ /\n/) {
1285 $full_line = "";
1286 }
Steven Rostedt407b95b2012-07-19 16:05:42 -04001287 $now = time;
1288 if ($now - $start_time >= $max_monitor_wait) {
1289 doprint "Exiting monitor flush due to hitting MAX_MONITOR_WAIT\n";
1290 return 1;
1291 }
Steven Rostedt2b803362011-09-30 18:00:23 -04001292 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001293 print "** Monitor flushed **\n";
Steven Rostedt8a80c722012-07-19 16:08:33 -04001294 return $bug;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001295}
1296
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301297sub save_logs {
1298 my ($result, $basedir) = @_;
1299 my @t = localtime;
1300 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1301 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1302
1303 my $type = $build_type;
1304 if ($type =~ /useconfig/) {
1305 $type = "useconfig";
1306 }
1307
1308 my $dir = "$machine-$test_type-$type-$result-$date";
1309
1310 $dir = "$basedir/$dir";
1311
1312 if (!-d $dir) {
1313 mkpath($dir) or
1314 die "can't create $dir";
1315 }
1316
1317 my %files = (
1318 "config" => $output_config,
1319 "buildlog" => $buildlog,
1320 "dmesg" => $dmesg,
1321 "testlog" => $testlog,
1322 );
1323
1324 while (my ($name, $source) = each(%files)) {
1325 if (-f "$source") {
1326 cp "$source", "$dir/$name" or
1327 die "failed to copy $source";
1328 }
1329 }
1330
1331 doprint "*** Saved info to $dir ***\n";
1332}
1333
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001334sub fail {
1335
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001336 if (defined($post_test)) {
1337 run_command $post_test;
1338 }
1339
Steven Rostedta75fece2010-11-02 14:58:27 -04001340 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001341 dodie @_;
1342 }
1343
Steven Rostedta75fece2010-11-02 14:58:27 -04001344 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001345
Steven Rostedt576f6272010-11-02 14:58:38 -04001346 my $i = $iteration;
1347
Steven Rostedta75fece2010-11-02 14:58:27 -04001348 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001349 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001350 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001351 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001352 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001353
Steven Rostedt9064af52011-06-13 10:38:48 -04001354 my $name = "";
1355
1356 if (defined($test_name)) {
1357 $name = " ($test_name)";
1358 }
1359
Steven Rostedt576f6272010-11-02 14:58:38 -04001360 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1361 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001362 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001363 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1364 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001365
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301366 if (defined($store_failures)) {
1367 save_logs "fail", $store_failures;
1368 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001369
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001370 return 1;
1371}
1372
Steven Rostedt2545eb62010-11-02 15:01:32 -04001373sub run_command {
1374 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001375 my $dolog = 0;
1376 my $dord = 0;
1377 my $pid;
1378
Steven Rostedte48c5292010-11-02 14:35:37 -04001379 $command =~ s/\$SSH_USER/$ssh_user/g;
1380 $command =~ s/\$MACHINE/$machine/g;
1381
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001382 doprint("$command ... ");
1383
1384 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001385 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001386
1387 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001388 open(LOG, ">>$opt{LOG_FILE}") or
1389 dodie "failed to write to log";
1390 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001391 }
1392
1393 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001394 open (RD, ">$redirect") or
1395 dodie "failed to write to redirect $redirect";
1396 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001397 }
1398
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001399 while (<CMD>) {
1400 print LOG if ($dolog);
1401 print RD if ($dord);
1402 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001403
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001404 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001405 my $failed = $?;
1406
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001407 close(CMD);
1408 close(LOG) if ($dolog);
1409 close(RD) if ($dord);
1410
Steven Rostedt2545eb62010-11-02 15:01:32 -04001411 if ($failed) {
1412 doprint "FAILED!\n";
1413 } else {
1414 doprint "SUCCESS\n";
1415 }
1416
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001417 return !$failed;
1418}
1419
Steven Rostedte48c5292010-11-02 14:35:37 -04001420sub run_ssh {
1421 my ($cmd) = @_;
1422 my $cp_exec = $ssh_exec;
1423
1424 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1425 return run_command "$cp_exec";
1426}
1427
1428sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001429 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001430
1431 $cp_scp =~ s/\$SRC_FILE/$src/g;
1432 $cp_scp =~ s/\$DST_FILE/$dst/g;
1433
1434 return run_command "$cp_scp";
1435}
1436
Steven Rostedt02ad2612012-03-21 08:21:24 -04001437sub run_scp_install {
1438 my ($src, $dst) = @_;
1439
1440 my $cp_scp = $scp_to_target_install;
1441
1442 return run_scp($src, $dst, $cp_scp);
1443}
1444
1445sub run_scp_mod {
1446 my ($src, $dst) = @_;
1447
1448 my $cp_scp = $scp_to_target;
1449
1450 return run_scp($src, $dst, $cp_scp);
1451}
1452
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001453sub get_grub_index {
1454
Steven Rostedta75fece2010-11-02 14:58:27 -04001455 if ($reboot_type ne "grub") {
1456 return;
1457 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001458 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001459
1460 doprint "Find grub menu ... ";
1461 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001462
1463 my $ssh_grub = $ssh_exec;
1464 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1465
1466 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001467 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001468
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001469 my $found = 0;
1470
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001471 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001472 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001473 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001474 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001475 last;
1476 } elsif (/^\s*title\s/) {
1477 $grub_number++;
1478 }
1479 }
1480 close(IN);
1481
Steven Rostedta75fece2010-11-02 14:58:27 -04001482 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001483 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001484 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001485}
1486
Steven Rostedt2545eb62010-11-02 15:01:32 -04001487sub wait_for_input
1488{
1489 my ($fp, $time) = @_;
1490 my $rin;
1491 my $ready;
1492 my $line;
1493 my $ch;
1494
1495 if (!defined($time)) {
1496 $time = $timeout;
1497 }
1498
1499 $rin = '';
1500 vec($rin, fileno($fp), 1) = 1;
1501 $ready = select($rin, undef, undef, $time);
1502
1503 $line = "";
1504
1505 # try to read one char at a time
1506 while (sysread $fp, $ch, 1) {
1507 $line .= $ch;
1508 last if ($ch eq "\n");
1509 }
1510
1511 if (!length($line)) {
1512 return undef;
1513 }
1514
1515 return $line;
1516}
1517
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001518sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001519 if (defined($switch_to_test)) {
1520 run_command $switch_to_test;
1521 }
1522
Steven Rostedta75fece2010-11-02 14:58:27 -04001523 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001524 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001525 } elsif (defined $reboot_script) {
1526 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001527 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001528 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001529}
1530
Steven Rostedta57419b2010-11-02 15:13:54 -04001531sub get_sha1 {
1532 my ($commit) = @_;
1533
1534 doprint "git rev-list --max-count=1 $commit ... ";
1535 my $sha1 = `git rev-list --max-count=1 $commit`;
1536 my $ret = $?;
1537
1538 logit $sha1;
1539
1540 if ($ret) {
1541 doprint "FAILED\n";
1542 dodie "Failed to get git $commit";
1543 }
1544
1545 print "SUCCESS\n";
1546
1547 chomp $sha1;
1548
1549 return $sha1;
1550}
1551
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001552sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001553 my $booted = 0;
1554 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001555 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001556 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001557 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001558
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001559 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001560
1561 my $line;
1562 my $full_line = "";
1563
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001564 open(DMESG, "> $dmesg") or
1565 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001566
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001567 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001568
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001569 my $success_start;
1570 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001571 my $monitor_start = time;
1572 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001573 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001574
Steven Rostedt2d01b262011-03-08 09:47:54 -05001575 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001576
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001577 if ($bug && defined($stop_after_failure) &&
1578 $stop_after_failure >= 0) {
1579 my $time = $stop_after_failure - (time - $failure_start);
1580 $line = wait_for_input($monitor_fp, $time);
1581 if (!defined($line)) {
1582 doprint "bug timed out after $booted_timeout seconds\n";
1583 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1584 last;
1585 }
1586 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001587 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001588 if (!defined($line)) {
1589 my $s = $booted_timeout == 1 ? "" : "s";
1590 doprint "Successful boot found: break after $booted_timeout second$s\n";
1591 last;
1592 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001593 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001594 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001595 if (!defined($line)) {
1596 my $s = $timeout == 1 ? "" : "s";
1597 doprint "Timed out after $timeout second$s\n";
1598 last;
1599 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001600 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001601
Steven Rostedt2545eb62010-11-02 15:01:32 -04001602 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001603 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001604
1605 # we are not guaranteed to get a full line
1606 $full_line .= $line;
1607
Steven Rostedta75fece2010-11-02 14:58:27 -04001608 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001609 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001610 $success_start = time;
1611 }
1612
1613 if ($booted && defined($stop_after_success) &&
1614 $stop_after_success >= 0) {
1615 my $now = time;
1616 if ($now - $success_start >= $stop_after_success) {
1617 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1618 last;
1619 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001620 }
1621
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001622 if ($full_line =~ /\[ backtrace testing \]/) {
1623 $skip_call_trace = 1;
1624 }
1625
Steven Rostedt2545eb62010-11-02 15:01:32 -04001626 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001627 if (!$bug && !$skip_call_trace) {
1628 if ($ignore_errors) {
1629 $bug_ignored = 1;
1630 } else {
1631 $bug = 1;
1632 $failure_start = time;
1633 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001634 }
1635 }
1636
1637 if ($bug && defined($stop_after_failure) &&
1638 $stop_after_failure >= 0) {
1639 my $now = time;
1640 if ($now - $failure_start >= $stop_after_failure) {
1641 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1642 last;
1643 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001644 }
1645
1646 if ($full_line =~ /\[ end of backtrace testing \]/) {
1647 $skip_call_trace = 0;
1648 }
1649
1650 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001651 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001652 $bug = 1;
1653 }
1654
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001655 # Detect triple faults by testing the banner
1656 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1657 if ($1 eq $version) {
1658 $version_found = 1;
1659 } elsif ($version_found && $detect_triplefault) {
1660 # We already booted into the kernel we are testing,
1661 # but now we booted into another kernel?
1662 # Consider this a triple fault.
1663 doprint "Aleady booted in Linux kernel $version, but now\n";
1664 doprint "we booted into Linux kernel $1.\n";
1665 doprint "Assuming that this is a triple fault.\n";
1666 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1667 last;
1668 }
1669 }
1670
Steven Rostedt2545eb62010-11-02 15:01:32 -04001671 if ($line =~ /\n/) {
1672 $full_line = "";
1673 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001674
1675 if ($stop_test_after > 0 && !$booted && !$bug) {
1676 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001677 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001678 $done = 1;
1679 }
1680 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001681 }
1682
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001683 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001684
Steven Rostedt2545eb62010-11-02 15:01:32 -04001685 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001686 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001687 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001688 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001689
Steven Rostedta75fece2010-11-02 14:58:27 -04001690 if (!$booted) {
1691 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001692 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001693 }
1694
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001695 if ($bug_ignored) {
1696 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1697 }
1698
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001699 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001700}
1701
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001702sub eval_kernel_version {
1703 my ($option) = @_;
1704
1705 $option =~ s/\$KERNEL_VERSION/$version/g;
1706
1707 return $option;
1708}
1709
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001710sub do_post_install {
1711
1712 return if (!defined($post_install));
1713
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001714 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001715 run_command "$cp_post_install" or
1716 dodie "Failed to run post install";
1717}
1718
Steven Rostedt2545eb62010-11-02 15:01:32 -04001719sub install {
1720
Steven Rostedte0a87422011-09-30 17:50:48 -04001721 return if ($no_install);
1722
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001723 if (defined($pre_install)) {
1724 my $cp_pre_install = eval_kernel_version $pre_install;
1725 run_command "$cp_pre_install" or
1726 dodie "Failed to run pre install";
1727 }
1728
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001729 my $cp_target = eval_kernel_version $target_image;
1730
Steven Rostedt02ad2612012-03-21 08:21:24 -04001731 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001732 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001733
1734 my $install_mods = 0;
1735
1736 # should we process modules?
1737 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001738 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001739 while (<IN>) {
1740 if (/CONFIG_MODULES(=y)?/) {
1741 $install_mods = 1 if (defined($1));
1742 last;
1743 }
1744 }
1745 close(IN);
1746
1747 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001748 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001749 doprint "No modules needed\n";
1750 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001751 }
1752
Steven Rostedt627977d2012-03-21 08:16:15 -04001753 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001754 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001755
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001756 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001757 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001758
Steven Rostedte48c5292010-11-02 14:35:37 -04001759 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001760 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001761
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001762 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001763 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001764 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001765
Steven Rostedt02ad2612012-03-21 08:21:24 -04001766 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001767 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001768
Steven Rostedta75fece2010-11-02 14:58:27 -04001769 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001770
Steven Rostedte7b13442011-06-14 20:44:36 -04001771 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001772 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001773
Steven Rostedte48c5292010-11-02 14:35:37 -04001774 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001775
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001776 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001777}
1778
Steven Rostedtddf607e2011-06-14 20:49:13 -04001779sub get_version {
1780 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001781 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001782 doprint "$make kernelrelease ... ";
1783 $version = `$make kernelrelease | tail -1`;
1784 chomp($version);
1785 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001786 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001787}
1788
1789sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001790 # Make sure the stable kernel has finished booting
1791 start_monitor;
1792 wait_for_monitor 5;
1793 end_monitor;
1794
Steven Rostedtddf607e2011-06-14 20:49:13 -04001795 get_grub_index;
1796 get_version;
1797 install;
1798
1799 start_monitor;
1800 return monitor;
1801}
1802
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001803sub check_buildlog {
1804 my ($patch) = @_;
1805
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001806 my @files = `git show $patch | diffstat -l`;
1807
1808 open(IN, "git show $patch |") or
1809 dodie "failed to show $patch";
1810 while (<IN>) {
1811 if (m,^--- a/(.*),) {
1812 chomp $1;
1813 $files[$#files] = $1;
1814 }
1815 }
1816 close(IN);
1817
1818 open(IN, $buildlog) or dodie "Can't open $buildlog";
1819 while (<IN>) {
1820 if (/^\s*(.*?):.*(warning|error)/) {
1821 my $err = $1;
1822 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001823 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001824 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001825 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001826 }
1827 }
1828 }
1829 }
1830 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001831
1832 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001833}
1834
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001835sub apply_min_config {
1836 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001837
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001838 # Read the config file and remove anything that
1839 # is in the force_config hash (from minconfig and others)
1840 # then add the force config back.
1841
1842 doprint "Applying minimum configurations into $output_config.new\n";
1843
1844 open (OUT, ">$outconfig") or
1845 dodie "Can't create $outconfig";
1846
1847 if (-f $output_config) {
1848 open (IN, $output_config) or
1849 dodie "Failed to open $output_config";
1850 while (<IN>) {
1851 if (/^(# )?(CONFIG_[^\s=]*)/) {
1852 next if (defined($force_config{$2}));
1853 }
1854 print OUT;
1855 }
1856 close IN;
1857 }
1858 foreach my $config (keys %force_config) {
1859 print OUT "$force_config{$config}\n";
1860 }
1861 close OUT;
1862
1863 run_command "mv $outconfig $output_config";
1864}
1865
1866sub make_oldconfig {
1867
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001868 my @force_list = keys %force_config;
1869
1870 if ($#force_list >= 0) {
1871 apply_min_config;
1872 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001873
Adam Leefb16d892012-09-01 01:05:17 +08001874 if (!run_command "$make olddefconfig") {
1875 # Perhaps olddefconfig doesn't exist in this version of the kernel
Steven Rostedt612b9e92011-03-07 13:27:43 -05001876 # try a yes '' | oldconfig
Adam Leefb16d892012-09-01 01:05:17 +08001877 doprint "olddefconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001878 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001879 dodie "failed make config oldconfig";
1880 }
1881}
1882
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001883# read a config file and use this to force new configs.
1884sub load_force_config {
1885 my ($config) = @_;
1886
Steven Rostedtcf79fab2012-07-19 15:29:43 -04001887 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001888 open(IN, $config) or
1889 dodie "failed to read $config";
1890 while (<IN>) {
1891 chomp;
1892 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1893 $force_config{$1} = $_;
1894 } elsif (/^# (CONFIG_\S*) is not set/) {
1895 $force_config{$1} = $_;
1896 }
1897 }
1898 close IN;
1899}
1900
Steven Rostedt2545eb62010-11-02 15:01:32 -04001901sub build {
1902 my ($type) = @_;
1903
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001904 unlink $buildlog;
1905
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001906 # Failed builds should not reboot the target
1907 my $save_no_reboot = $no_reboot;
1908 $no_reboot = 1;
1909
Steven Rostedt683a3e62012-05-18 13:34:35 -04001910 # Calculate a new version from here.
1911 $have_version = 0;
1912
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001913 if (defined($pre_build)) {
1914 my $ret = run_command $pre_build;
1915 if (!$ret && defined($pre_build_die) &&
1916 $pre_build_die) {
1917 dodie "failed to pre_build\n";
1918 }
1919 }
1920
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001921 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001922 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001923 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001924
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001925 $type = "oldconfig";
1926 }
1927
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001928 # old config can ask questions
1929 if ($type eq "oldconfig") {
Adam Leefb16d892012-09-01 01:05:17 +08001930 $type = "olddefconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001931
1932 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001933 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001934
Andrew Jones13488232011-08-12 15:32:04 +02001935 if (!$noclean) {
1936 run_command "mv $output_config $outputdir/config_temp" or
1937 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001938
Andrew Jones13488232011-08-12 15:32:04 +02001939 run_command "$make mrproper" or dodie "make mrproper";
1940
1941 run_command "mv $outputdir/config_temp $output_config" or
1942 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001943 }
1944
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001945 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001946 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001947 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001948 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001949 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001950
1951 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001952 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1953 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001954 close(OUT);
1955
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001956 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001957 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001958 }
1959
Adam Leefb16d892012-09-01 01:05:17 +08001960 if ($type ne "olddefconfig") {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001961 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001962 dodie "failed make config";
1963 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001964 # Run old config regardless, to enforce min configurations
1965 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001966
Steven Rostedta75fece2010-11-02 14:58:27 -04001967 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001968 my $build_ret = run_command "$make $build_options";
1969 undef $redirect;
1970
1971 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04001972 # Because a post build may change the kernel version
1973 # do it now.
1974 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001975 my $ret = run_command $post_build;
1976 if (!$ret && defined($post_build_die) &&
1977 $post_build_die) {
1978 dodie "failed to post_build\n";
1979 }
1980 }
1981
1982 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001983 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001984 if ($in_bisect) {
1985 $no_reboot = $save_no_reboot;
1986 return 0;
1987 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001988 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001989 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001990
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001991 $no_reboot = $save_no_reboot;
1992
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001993 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001994}
1995
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001996sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001997 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001998 if (defined($poweroff_after_halt)) {
1999 sleep $poweroff_after_halt;
2000 run_command "$power_off";
2001 }
2002 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002003 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04002004 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04002005 }
2006}
2007
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002008sub success {
2009 my ($i) = @_;
2010
Steven Rostedt921ed4c2012-07-19 15:18:27 -04002011 if (defined($post_test)) {
2012 run_command $post_test;
2013 }
2014
Steven Rostedte48c5292010-11-02 14:35:37 -04002015 $successes++;
2016
Steven Rostedt9064af52011-06-13 10:38:48 -04002017 my $name = "";
2018
2019 if (defined($test_name)) {
2020 $name = " ($test_name)";
2021 }
2022
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002023 doprint "\n\n*******************************************\n";
2024 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04002025 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002026 doprint "*******************************************\n";
2027 doprint "*******************************************\n";
2028
Rabin Vincentde5b6e32011-11-18 17:05:31 +05302029 if (defined($store_successes)) {
2030 save_logs "success", $store_successes;
2031 }
2032
Steven Rostedt576f6272010-11-02 14:58:38 -04002033 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002034 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002035 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002036 }
2037}
2038
Steven Rostedtc960bb92011-03-08 09:22:39 -05002039sub answer_bisect {
2040 for (;;) {
2041 doprint "Pass or fail? [p/f]";
2042 my $ans = <STDIN>;
2043 chomp $ans;
2044 if ($ans eq "p" || $ans eq "P") {
2045 return 1;
2046 } elsif ($ans eq "f" || $ans eq "F") {
2047 return 0;
2048 } else {
2049 print "Please answer 'P' or 'F'\n";
2050 }
2051 }
2052}
2053
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002054sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002055 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002056
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002057 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002058 $reboot_on_error = 0;
2059 $poweroff_on_error = 0;
2060 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002061
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302062 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002063 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302064 undef $redirect;
2065
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002066 exit $failed;
2067}
2068
2069my $child_done;
2070
2071sub child_finished {
2072 $child_done = 1;
2073}
2074
2075sub do_run_test {
2076 my $child_pid;
2077 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002078 my $line;
2079 my $full_line;
2080 my $bug = 0;
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002081 my $bug_ignored = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002082
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002083 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002084
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002085 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002086
2087 $child_done = 0;
2088
2089 $SIG{CHLD} = qw(child_finished);
2090
2091 $child_pid = fork;
2092
2093 child_run_test if (!$child_pid);
2094
2095 $full_line = "";
2096
2097 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002098 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002099 if (defined($line)) {
2100
2101 # we are not guaranteed to get a full line
2102 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002103 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002104
2105 if ($full_line =~ /call trace:/i) {
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002106 if ($ignore_errors) {
2107 $bug_ignored = 1;
2108 } else {
2109 $bug = 1;
2110 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002111 }
2112
2113 if ($full_line =~ /Kernel panic -/) {
2114 $bug = 1;
2115 }
2116
2117 if ($line =~ /\n/) {
2118 $full_line = "";
2119 }
2120 }
2121 } while (!$child_done && !$bug);
2122
Steven Rostedt9b1d3672012-07-30 14:30:53 -04002123 if (!$bug && $bug_ignored) {
2124 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
2125 }
2126
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002127 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002128 my $failure_start = time;
2129 my $now;
2130 do {
2131 $line = wait_for_input($monitor_fp, 1);
2132 if (defined($line)) {
2133 doprint $line;
2134 }
2135 $now = time;
2136 if ($now - $failure_start >= $stop_after_failure) {
2137 last;
2138 }
2139 } while (defined($line));
2140
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002141 doprint "Detected kernel crash!\n";
2142 # kill the child with extreme prejudice
2143 kill 9, $child_pid;
2144 }
2145
2146 waitpid $child_pid, 0;
2147 $child_exit = $?;
2148
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002149 if (!$bug && $in_bisect) {
2150 if (defined($bisect_ret_good)) {
2151 if ($child_exit == $bisect_ret_good) {
2152 return 1;
2153 }
2154 }
2155 if (defined($bisect_ret_skip)) {
2156 if ($child_exit == $bisect_ret_skip) {
2157 return -1;
2158 }
2159 }
2160 if (defined($bisect_ret_abort)) {
2161 if ($child_exit == $bisect_ret_abort) {
2162 fail "test abort" and return -2;
2163 }
2164 }
2165 if (defined($bisect_ret_bad)) {
2166 if ($child_exit == $bisect_ret_skip) {
2167 return 0;
2168 }
2169 }
2170 if (defined($bisect_ret_default)) {
2171 if ($bisect_ret_default eq "good") {
2172 return 1;
2173 } elsif ($bisect_ret_default eq "bad") {
2174 return 0;
2175 } elsif ($bisect_ret_default eq "skip") {
2176 return -1;
2177 } elsif ($bisect_ret_default eq "abort") {
2178 return -2;
2179 } else {
2180 fail "unknown default action: $bisect_ret_default"
2181 and return -2;
2182 }
2183 }
2184 }
2185
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002186 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002187 return 0 if $in_bisect;
2188 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002189 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002190 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002191}
2192
Steven Rostedta75fece2010-11-02 14:58:27 -04002193sub run_git_bisect {
2194 my ($command) = @_;
2195
2196 doprint "$command ... ";
2197
2198 my $output = `$command 2>&1`;
2199 my $ret = $?;
2200
2201 logit $output;
2202
2203 if ($ret) {
2204 doprint "FAILED\n";
2205 dodie "Failed to git bisect";
2206 }
2207
2208 doprint "SUCCESS\n";
2209 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2210 doprint "$1 [$2]\n";
2211 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002212 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002213 doprint "Found bad commit... $1\n";
2214 return 0;
2215 } else {
2216 # we already logged it, just print it now.
2217 print $output;
2218 }
2219
2220 return 1;
2221}
2222
Steven Rostedtc23dca72011-03-08 09:26:31 -05002223sub bisect_reboot {
2224 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002225 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002226}
2227
2228# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002229sub run_bisect_test {
2230 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002231
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002232 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002233 my $result;
2234 my $output;
2235 my $ret;
2236
Steven Rostedt0a05c762010-11-08 11:14:10 -05002237 $in_bisect = 1;
2238
2239 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002240
2241 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002242 if ($failed && $bisect_skip) {
2243 $in_bisect = 0;
2244 return -1;
2245 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002246 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002247
2248 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002249 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002250
2251 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002252 if ($failed && $bisect_skip) {
2253 end_monitor;
2254 bisect_reboot;
2255 $in_bisect = 0;
2256 return -1;
2257 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002258 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002259
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002260 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002261 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002262 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002263 }
2264
2265 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002266 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002267 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002268 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002269 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002270
2271 # reboot the box to a kernel we can ssh to
2272 if ($type ne "build") {
2273 bisect_reboot;
2274 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002275 $in_bisect = 0;
2276
2277 return $result;
2278}
2279
2280sub run_bisect {
2281 my ($type) = @_;
2282 my $buildtype = "oldconfig";
2283
2284 # We should have a minconfig to use?
2285 if (defined($minconfig)) {
2286 $buildtype = "useconfig:$minconfig";
2287 }
2288
2289 my $ret = run_bisect_test $type, $buildtype;
2290
Steven Rostedtc960bb92011-03-08 09:22:39 -05002291 if ($bisect_manual) {
2292 $ret = answer_bisect;
2293 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002294
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002295 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002296 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002297 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002298 }
2299
Steven Rostedtc23dca72011-03-08 09:26:31 -05002300 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002301 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002302 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002303 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002304 } elsif ($bisect_skip) {
2305 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2306 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002307 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002308}
2309
Steven Rostedtdad98752011-11-22 20:48:57 -05002310sub update_bisect_replay {
2311 my $tmp_log = "$tmpdir/ktest_bisect_log";
2312 run_command "git bisect log > $tmp_log" or
2313 die "can't create bisect log";
2314 return $tmp_log;
2315}
2316
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002317sub bisect {
2318 my ($i) = @_;
2319
2320 my $result;
2321
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002322 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2323 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2324 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002325
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002326 my $good = $bisect_good;
2327 my $bad = $bisect_bad;
2328 my $type = $bisect_type;
2329 my $start = $bisect_start;
2330 my $replay = $bisect_replay;
2331 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002332
2333 if (defined($start_files)) {
2334 $start_files = " -- " . $start_files;
2335 } else {
2336 $start_files = "";
2337 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002338
Steven Rostedta57419b2010-11-02 15:13:54 -04002339 # convert to true sha1's
2340 $good = get_sha1($good);
2341 $bad = get_sha1($bad);
2342
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002343 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002344 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2345 $reverse_bisect = 1;
2346 } else {
2347 $reverse_bisect = 0;
2348 }
2349
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002350 # Can't have a test without having a test to run
2351 if ($type eq "test" && !defined($run_test)) {
2352 $type = "boot";
2353 }
2354
Steven Rostedtdad98752011-11-22 20:48:57 -05002355 # Check if a bisect was running
2356 my $bisect_start_file = "$builddir/.git/BISECT_START";
2357
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002358 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002359 my $do_check = defined($check) && $check ne "0";
2360
2361 if ( -f $bisect_start_file ) {
2362 print "Bisect in progress found\n";
2363 if ($do_check) {
2364 print " If you say yes, then no checks of good or bad will be done\n";
2365 }
2366 if (defined($replay)) {
2367 print "** BISECT_REPLAY is defined in config file **";
2368 print " Ignore config option and perform new git bisect log?\n";
2369 if (read_ync " (yes, no, or cancel) ") {
2370 $replay = update_bisect_replay;
2371 $do_check = 0;
2372 }
2373 } elsif (read_yn "read git log and continue?") {
2374 $replay = update_bisect_replay;
2375 $do_check = 0;
2376 }
2377 }
2378
2379 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002380
2381 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002382 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002383
2384 if ($check ne "good") {
2385 doprint "TESTING BISECT BAD [$bad]\n";
2386 run_command "git checkout $bad" or
2387 die "Failed to checkout $bad";
2388
2389 $result = run_bisect $type;
2390
2391 if ($result ne "bad") {
2392 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2393 }
2394 }
2395
2396 if ($check ne "bad") {
2397 doprint "TESTING BISECT GOOD [$good]\n";
2398 run_command "git checkout $good" or
2399 die "Failed to checkout $good";
2400
2401 $result = run_bisect $type;
2402
2403 if ($result ne "good") {
2404 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2405 }
2406 }
2407
2408 # checkout where we started
2409 run_command "git checkout $head" or
2410 die "Failed to checkout $head";
2411 }
2412
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002413 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002414 dodie "could not start bisect";
2415
2416 run_command "git bisect good $good" or
2417 dodie "could not set bisect good to $good";
2418
2419 run_git_bisect "git bisect bad $bad" or
2420 dodie "could not set bisect bad to $bad";
2421
2422 if (defined($replay)) {
2423 run_command "git bisect replay $replay" or
2424 dodie "failed to run replay";
2425 }
2426
2427 if (defined($start)) {
2428 run_command "git checkout $start" or
2429 dodie "failed to checkout $start";
2430 }
2431
2432 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002433 do {
2434 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002435 $test = run_git_bisect "git bisect $result";
2436 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002437
2438 run_command "git bisect log" or
2439 dodie "could not capture git bisect log";
2440
2441 run_command "git bisect reset" or
2442 dodie "could not reset git bisect";
2443
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002444 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002445
Steven Rostedt0a05c762010-11-08 11:14:10 -05002446 success $i;
2447}
2448
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002449# config_ignore holds the configs that were set (or unset) for
2450# a good config and we will ignore these configs for the rest
2451# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002452my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002453
2454# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002455my %config_set;
2456
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002457# config_off holds the set of configs that the bad config had disabled.
2458# We need to record them and set them in the .config when running
Adam Leefb16d892012-09-01 01:05:17 +08002459# olddefconfig, because olddefconfig keeps the defaults.
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002460my %config_off;
2461
2462# config_off_tmp holds a set of configs to turn off for now
2463my @config_off_tmp;
2464
2465# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002466my %config_list;
2467my %null_config;
2468
2469my %dependency;
2470
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002471sub assign_configs {
2472 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002473
2474 open (IN, $config)
2475 or dodie "Failed to read $config";
2476
2477 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002478 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002479 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002480 }
2481 }
2482
2483 close(IN);
2484}
2485
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002486sub process_config_ignore {
2487 my ($config) = @_;
2488
2489 assign_configs \%config_ignore, $config;
2490}
2491
Steven Rostedt0a05c762010-11-08 11:14:10 -05002492sub read_current_config {
2493 my ($config_ref) = @_;
2494
2495 %{$config_ref} = ();
2496 undef %{$config_ref};
2497
2498 my @key = keys %{$config_ref};
2499 if ($#key >= 0) {
2500 print "did not delete!\n";
2501 exit;
2502 }
2503 open (IN, "$output_config");
2504
2505 while (<IN>) {
2506 if (/^(CONFIG\S+)=(.*)/) {
2507 ${$config_ref}{$1} = $2;
2508 }
2509 }
2510 close(IN);
2511}
2512
2513sub get_dependencies {
2514 my ($config) = @_;
2515
2516 my $arr = $dependency{$config};
2517 if (!defined($arr)) {
2518 return ();
2519 }
2520
2521 my @deps = @{$arr};
2522
2523 foreach my $dep (@{$arr}) {
2524 print "ADD DEP $dep\n";
2525 @deps = (@deps, get_dependencies $dep);
2526 }
2527
2528 return @deps;
2529}
2530
2531sub create_config {
2532 my @configs = @_;
2533
2534 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2535
2536 foreach my $config (@configs) {
2537 print OUT "$config_set{$config}\n";
2538 my @deps = get_dependencies $config;
2539 foreach my $dep (@deps) {
2540 print OUT "$config_set{$dep}\n";
2541 }
2542 }
2543
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002544 # turn off configs to keep off
2545 foreach my $config (keys %config_off) {
2546 print OUT "# $config is not set\n";
2547 }
2548
2549 # turn off configs that should be off for now
2550 foreach my $config (@config_off_tmp) {
2551 print OUT "# $config is not set\n";
2552 }
2553
Steven Rostedt0a05c762010-11-08 11:14:10 -05002554 foreach my $config (keys %config_ignore) {
2555 print OUT "$config_ignore{$config}\n";
2556 }
2557 close(OUT);
2558
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002559 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002560}
2561
2562sub compare_configs {
2563 my (%a, %b) = @_;
2564
2565 foreach my $item (keys %a) {
2566 if (!defined($b{$item})) {
2567 print "diff $item\n";
2568 return 1;
2569 }
2570 delete $b{$item};
2571 }
2572
2573 my @keys = keys %b;
2574 if ($#keys) {
2575 print "diff2 $keys[0]\n";
2576 }
2577 return -1 if ($#keys >= 0);
2578
2579 return 0;
2580}
2581
2582sub run_config_bisect_test {
2583 my ($type) = @_;
2584
2585 return run_bisect_test $type, "oldconfig";
2586}
2587
2588sub process_passed {
2589 my (%configs) = @_;
2590
2591 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2592 # Passed! All these configs are part of a good compile.
2593 # Add them to the min options.
2594 foreach my $config (keys %configs) {
2595 if (defined($config_list{$config})) {
2596 doprint " removing $config\n";
2597 $config_ignore{$config} = $config_list{$config};
2598 delete $config_list{$config};
2599 }
2600 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002601 doprint "config copied to $outputdir/config_good\n";
2602 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002603}
2604
2605sub process_failed {
2606 my ($config) = @_;
2607
2608 doprint "\n\n***************************************\n";
2609 doprint "Found bad config: $config\n";
2610 doprint "***************************************\n\n";
2611}
2612
2613sub run_config_bisect {
2614
2615 my @start_list = keys %config_list;
2616
2617 if ($#start_list < 0) {
2618 doprint "No more configs to test!!!\n";
2619 return -1;
2620 }
2621
2622 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002623 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002624 my $ret;
2625 my %current_config;
2626
2627 my $count = $#start_list + 1;
2628 doprint " $count configs to test\n";
2629
2630 my $half = int($#start_list / 2);
2631
2632 do {
2633 my @tophalf = @start_list[0 .. $half];
2634
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002635 # keep the bottom half off
2636 if ($half < $#start_list) {
2637 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2638 } else {
2639 @config_off_tmp = ();
2640 }
2641
Steven Rostedt0a05c762010-11-08 11:14:10 -05002642 create_config @tophalf;
2643 read_current_config \%current_config;
2644
2645 $count = $#tophalf + 1;
2646 doprint "Testing $count configs\n";
2647 my $found = 0;
2648 # make sure we test something
2649 foreach my $config (@tophalf) {
2650 if (defined($current_config{$config})) {
2651 logit " $config\n";
2652 $found = 1;
2653 }
2654 }
2655 if (!$found) {
2656 # try the other half
2657 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002658
2659 # keep the top half off
2660 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002661 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002662
Steven Rostedt0a05c762010-11-08 11:14:10 -05002663 create_config @tophalf;
2664 read_current_config \%current_config;
2665 foreach my $config (@tophalf) {
2666 if (defined($current_config{$config})) {
2667 logit " $config\n";
2668 $found = 1;
2669 }
2670 }
2671 if (!$found) {
2672 doprint "Failed: Can't make new config with current configs\n";
2673 foreach my $config (@start_list) {
2674 doprint " CONFIG: $config\n";
2675 }
2676 return -1;
2677 }
2678 $count = $#tophalf + 1;
2679 doprint "Testing $count configs\n";
2680 }
2681
2682 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002683 if ($bisect_manual) {
2684 $ret = answer_bisect;
2685 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002686 if ($ret) {
2687 process_passed %current_config;
2688 return 0;
2689 }
2690
2691 doprint "This config had a failure.\n";
2692 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002693 doprint "config copied to $outputdir/config_bad\n";
2694 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002695
2696 # A config exists in this group that was bad.
2697 foreach my $config (keys %config_list) {
2698 if (!defined($current_config{$config})) {
2699 doprint " removing $config\n";
2700 delete $config_list{$config};
2701 }
2702 }
2703
2704 @start_list = @tophalf;
2705
2706 if ($#start_list == 0) {
2707 process_failed $start_list[0];
2708 return 1;
2709 }
2710
2711 # remove half the configs we are looking at and see if
2712 # they are good.
2713 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002714 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002715
Steven Rostedtc960bb92011-03-08 09:22:39 -05002716 # we found a single config, try it again unless we are running manually
2717
2718 if ($bisect_manual) {
2719 process_failed $start_list[0];
2720 return 1;
2721 }
2722
Steven Rostedt0a05c762010-11-08 11:14:10 -05002723 my @tophalf = @start_list[0 .. 0];
2724
2725 $ret = run_config_bisect_test $type;
2726 if ($ret) {
2727 process_passed %current_config;
2728 return 0;
2729 }
2730
2731 process_failed $start_list[0];
2732 return 1;
2733}
2734
2735sub config_bisect {
2736 my ($i) = @_;
2737
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002738 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002739
2740 my $tmpconfig = "$tmpdir/use_config";
2741
Steven Rostedt30f75da2011-06-13 10:35:35 -04002742 if (defined($config_bisect_good)) {
2743 process_config_ignore $config_bisect_good;
2744 }
2745
Steven Rostedt0a05c762010-11-08 11:14:10 -05002746 # Make the file with the bad config and the min config
2747 if (defined($minconfig)) {
2748 # read the min config for things to ignore
2749 run_command "cp $minconfig $tmpconfig" or
2750 dodie "failed to copy $minconfig to $tmpconfig";
2751 } else {
2752 unlink $tmpconfig;
2753 }
2754
Steven Rostedt0a05c762010-11-08 11:14:10 -05002755 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002756 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002757 process_config_ignore $tmpconfig;
2758 }
2759
2760 # now process the start config
2761 run_command "cp $start_config $output_config" or
2762 dodie "failed to copy $start_config to $output_config";
2763
2764 # read directly what we want to check
2765 my %config_check;
2766 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002767 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002768
2769 while (<IN>) {
2770 if (/^((CONFIG\S*)=.*)/) {
2771 $config_check{$2} = $1;
2772 }
2773 }
2774 close(IN);
2775
Steven Rostedt250bae82011-07-15 22:05:59 -04002776 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002777 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002778
2779 # check to see what we lost (or gained)
2780 open (IN, $output_config)
2781 or dodie "Failed to read $start_config";
2782
2783 my %removed_configs;
2784 my %added_configs;
2785
2786 while (<IN>) {
2787 if (/^((CONFIG\S*)=.*)/) {
2788 # save off all options
2789 $config_set{$2} = $1;
2790 if (defined($config_check{$2})) {
2791 if (defined($config_ignore{$2})) {
2792 $removed_configs{$2} = $1;
2793 } else {
2794 $config_list{$2} = $1;
2795 }
2796 } elsif (!defined($config_ignore{$2})) {
2797 $added_configs{$2} = $1;
2798 $config_list{$2} = $1;
2799 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002800 } elsif (/^# ((CONFIG\S*).*)/) {
2801 # Keep these configs disabled
2802 $config_set{$2} = $1;
2803 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002804 }
2805 }
2806 close(IN);
2807
2808 my @confs = keys %removed_configs;
2809 if ($#confs >= 0) {
2810 doprint "Configs overridden by default configs and removed from check:\n";
2811 foreach my $config (@confs) {
2812 doprint " $config\n";
2813 }
2814 }
2815 @confs = keys %added_configs;
2816 if ($#confs >= 0) {
2817 doprint "Configs appearing in make oldconfig and added:\n";
2818 foreach my $config (@confs) {
2819 doprint " $config\n";
2820 }
2821 }
2822
2823 my %config_test;
2824 my $once = 0;
2825
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002826 @config_off_tmp = ();
2827
Steven Rostedt0a05c762010-11-08 11:14:10 -05002828 # Sometimes kconfig does weird things. We must make sure
2829 # that the config we autocreate has everything we need
2830 # to test, otherwise we may miss testing configs, or
2831 # may not be able to create a new config.
2832 # Here we create a config with everything set.
2833 create_config (keys %config_list);
2834 read_current_config \%config_test;
2835 foreach my $config (keys %config_list) {
2836 if (!defined($config_test{$config})) {
2837 if (!$once) {
2838 $once = 1;
2839 doprint "Configs not produced by kconfig (will not be checked):\n";
2840 }
2841 doprint " $config\n";
2842 delete $config_list{$config};
2843 }
2844 }
2845 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04002846
2847 if (defined($config_bisect_check) && $config_bisect_check) {
2848 doprint " Checking to make sure bad config with min config fails\n";
2849 create_config keys %config_list;
2850 $ret = run_config_bisect_test $config_bisect_type;
2851 if ($ret) {
2852 doprint " FAILED! Bad config with min config boots fine\n";
2853 return -1;
2854 }
2855 doprint " Bad config with min config fails as expected\n";
2856 }
2857
Steven Rostedt0a05c762010-11-08 11:14:10 -05002858 do {
2859 $ret = run_config_bisect;
2860 } while (!$ret);
2861
2862 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002863
2864 success $i;
2865}
2866
Steven Rostedt27d934b2011-05-20 09:18:18 -04002867sub patchcheck_reboot {
2868 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002869 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002870}
2871
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002872sub patchcheck {
2873 my ($i) = @_;
2874
2875 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002876 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002877 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002878 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002879
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002880 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002881
2882 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002883 if (defined($patchcheck_end)) {
2884 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002885 }
2886
Steven Rostedta57419b2010-11-02 15:13:54 -04002887 # Get the true sha1's since we can use things like HEAD~3
2888 $start = get_sha1($start);
2889 $end = get_sha1($end);
2890
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002891 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002892
2893 # Can't have a test without having a test to run
2894 if ($type eq "test" && !defined($run_test)) {
2895 $type = "boot";
2896 }
2897
2898 open (IN, "git log --pretty=oneline $end|") or
2899 dodie "could not get git list";
2900
2901 my @list;
2902
2903 while (<IN>) {
2904 chomp;
2905 $list[$#list+1] = $_;
2906 last if (/^$start/);
2907 }
2908 close(IN);
2909
2910 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002911 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002912 }
2913
2914 # go backwards in the list
2915 @list = reverse @list;
2916
2917 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002918 my %ignored_warnings;
2919
2920 if (defined($ignore_warnings)) {
2921 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2922 $ignored_warnings{$sha1} = 1;
2923 }
2924 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002925
2926 $in_patchcheck = 1;
2927 foreach my $item (@list) {
2928 my $sha1 = $item;
2929 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2930
2931 doprint "\nProcessing commit $item\n\n";
2932
2933 run_command "git checkout $sha1" or
2934 die "Failed to checkout $sha1";
2935
2936 # only clean on the first and last patch
2937 if ($item eq $list[0] ||
2938 $item eq $list[$#list]) {
2939 $noclean = $save_clean;
2940 } else {
2941 $noclean = 1;
2942 }
2943
2944 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002945 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002946 } else {
2947 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002948 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002949 }
2950
Steven Rostedt19902072011-06-14 20:46:25 -04002951
2952 if (!defined($ignored_warnings{$sha1})) {
2953 check_buildlog $sha1 or return 0;
2954 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002955
2956 next if ($type eq "build");
2957
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002958 my $failed = 0;
2959
Steven Rostedtddf607e2011-06-14 20:49:13 -04002960 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002961
2962 if (!$failed && $type ne "boot"){
2963 do_run_test or $failed = 1;
2964 }
2965 end_monitor;
2966 return 0 if ($failed);
2967
Steven Rostedt27d934b2011-05-20 09:18:18 -04002968 patchcheck_reboot;
2969
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002970 }
2971 $in_patchcheck = 0;
2972 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002973
2974 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002975}
2976
Steven Rostedtb9066f62011-07-15 21:25:24 -04002977my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002978my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002979my $iflevel = 0;
2980my @ifdeps;
2981
2982# prevent recursion
2983my %read_kconfigs;
2984
Steven Rostedtac6974c2011-10-04 09:40:17 -04002985sub add_dep {
2986 # $config depends on $dep
2987 my ($config, $dep) = @_;
2988
2989 if (defined($depends{$config})) {
2990 $depends{$config} .= " " . $dep;
2991 } else {
2992 $depends{$config} = $dep;
2993 }
2994
2995 # record the number of configs depending on $dep
2996 if (defined $depcount{$dep}) {
2997 $depcount{$dep}++;
2998 } else {
2999 $depcount{$dep} = 1;
3000 }
3001}
3002
Steven Rostedtb9066f62011-07-15 21:25:24 -04003003# taken from streamline_config.pl
3004sub read_kconfig {
3005 my ($kconfig) = @_;
3006
3007 my $state = "NONE";
3008 my $config;
3009 my @kconfigs;
3010
3011 my $cont = 0;
3012 my $line;
3013
3014
3015 if (! -f $kconfig) {
3016 doprint "file $kconfig does not exist, skipping\n";
3017 return;
3018 }
3019
3020 open(KIN, "$kconfig")
3021 or die "Can't open $kconfig";
3022 while (<KIN>) {
3023 chomp;
3024
3025 # Make sure that lines ending with \ continue
3026 if ($cont) {
3027 $_ = $line . " " . $_;
3028 }
3029
3030 if (s/\\$//) {
3031 $cont = 1;
3032 $line = $_;
3033 next;
3034 }
3035
3036 $cont = 0;
3037
3038 # collect any Kconfig sources
3039 if (/^source\s*"(.*)"/) {
3040 $kconfigs[$#kconfigs+1] = $1;
3041 }
3042
3043 # configs found
3044 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
3045 $state = "NEW";
3046 $config = $2;
3047
3048 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04003049 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04003050 }
3051
3052 # collect the depends for the config
3053 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3054
Steven Rostedtac6974c2011-10-04 09:40:17 -04003055 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003056
3057 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003058 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3059
3060 # selected by depends on config
3061 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003062
3063 # Check for if statements
3064 } elsif (/^if\s+(.*\S)\s*$/) {
3065 my $deps = $1;
3066 # remove beginning and ending non text
3067 $deps =~ s/^[^a-zA-Z0-9_]*//;
3068 $deps =~ s/[^a-zA-Z0-9_]*$//;
3069
3070 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3071
3072 $ifdeps[$iflevel++] = join ':', @deps;
3073
3074 } elsif (/^endif/) {
3075
3076 $iflevel-- if ($iflevel);
3077
3078 # stop on "help"
3079 } elsif (/^\s*help\s*$/) {
3080 $state = "NONE";
3081 }
3082 }
3083 close(KIN);
3084
3085 # read in any configs that were found.
3086 foreach $kconfig (@kconfigs) {
3087 if (!defined($read_kconfigs{$kconfig})) {
3088 $read_kconfigs{$kconfig} = 1;
3089 read_kconfig("$builddir/$kconfig");
3090 }
3091 }
3092}
3093
3094sub read_depends {
3095 # find out which arch this is by the kconfig file
3096 open (IN, $output_config)
3097 or dodie "Failed to read $output_config";
3098 my $arch;
3099 while (<IN>) {
3100 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3101 $arch = $1;
3102 last;
3103 }
3104 }
3105 close IN;
3106
3107 if (!defined($arch)) {
3108 doprint "Could not find arch from config file\n";
3109 doprint "no dependencies used\n";
3110 return;
3111 }
3112
3113 # arch is really the subarch, we need to know
3114 # what directory to look at.
3115 if ($arch eq "i386" || $arch eq "x86_64") {
3116 $arch = "x86";
3117 } elsif ($arch =~ /^tile/) {
3118 $arch = "tile";
3119 }
3120
3121 my $kconfig = "$builddir/arch/$arch/Kconfig";
3122
3123 if (! -f $kconfig && $arch =~ /\d$/) {
3124 my $orig = $arch;
3125 # some subarchs have numbers, truncate them
3126 $arch =~ s/\d*$//;
3127 $kconfig = "$builddir/arch/$arch/Kconfig";
3128 if (! -f $kconfig) {
3129 doprint "No idea what arch dir $orig is for\n";
3130 doprint "no dependencies used\n";
3131 return;
3132 }
3133 }
3134
3135 read_kconfig($kconfig);
3136}
3137
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003138sub read_config_list {
3139 my ($config) = @_;
3140
3141 open (IN, $config)
3142 or dodie "Failed to read $config";
3143
3144 while (<IN>) {
3145 if (/^((CONFIG\S*)=.*)/) {
3146 if (!defined($config_ignore{$2})) {
3147 $config_list{$2} = $1;
3148 }
3149 }
3150 }
3151
3152 close(IN);
3153}
3154
3155sub read_output_config {
3156 my ($config) = @_;
3157
3158 assign_configs \%config_ignore, $config;
3159}
3160
3161sub make_new_config {
3162 my @configs = @_;
3163
3164 open (OUT, ">$output_config")
3165 or dodie "Failed to write $output_config";
3166
3167 foreach my $config (@configs) {
3168 print OUT "$config\n";
3169 }
3170 close OUT;
3171}
3172
Steven Rostedtac6974c2011-10-04 09:40:17 -04003173sub chomp_config {
3174 my ($config) = @_;
3175
3176 $config =~ s/CONFIG_//;
3177
3178 return $config;
3179}
3180
Steven Rostedtb9066f62011-07-15 21:25:24 -04003181sub get_depends {
3182 my ($dep) = @_;
3183
Steven Rostedtac6974c2011-10-04 09:40:17 -04003184 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003185
3186 $dep = $depends{"$kconfig"};
3187
3188 # the dep string we have saves the dependencies as they
3189 # were found, including expressions like ! && ||. We
3190 # want to split this out into just an array of configs.
3191
3192 my $valid = "A-Za-z_0-9";
3193
3194 my @configs;
3195
3196 while ($dep =~ /[$valid]/) {
3197
3198 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3199 my $conf = "CONFIG_" . $1;
3200
3201 $configs[$#configs + 1] = $conf;
3202
3203 $dep =~ s/^[^$valid]*[$valid]+//;
3204 } else {
3205 die "this should never happen";
3206 }
3207 }
3208
3209 return @configs;
3210}
3211
3212my %min_configs;
3213my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003214my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003215my %processed_configs;
3216my %nochange_config;
3217
3218sub test_this_config {
3219 my ($config) = @_;
3220
3221 my $found;
3222
3223 # if we already processed this config, skip it
3224 if (defined($processed_configs{$config})) {
3225 return undef;
3226 }
3227 $processed_configs{$config} = 1;
3228
3229 # if this config failed during this round, skip it
3230 if (defined($nochange_config{$config})) {
3231 return undef;
3232 }
3233
Steven Rostedtac6974c2011-10-04 09:40:17 -04003234 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003235
3236 # Test dependencies first
3237 if (defined($depends{"$kconfig"})) {
3238 my @parents = get_depends $config;
3239 foreach my $parent (@parents) {
3240 # if the parent is in the min config, check it first
3241 next if (!defined($min_configs{$parent}));
3242 $found = test_this_config($parent);
3243 if (defined($found)) {
3244 return $found;
3245 }
3246 }
3247 }
3248
3249 # Remove this config from the list of configs
Adam Leefb16d892012-09-01 01:05:17 +08003250 # do a make olddefconfig and then read the resulting
Steven Rostedtb9066f62011-07-15 21:25:24 -04003251 # .config to make sure it is missing the config that
3252 # we had before
3253 my %configs = %min_configs;
3254 delete $configs{$config};
3255 make_new_config ((values %configs), (values %keep_configs));
3256 make_oldconfig;
3257 undef %configs;
3258 assign_configs \%configs, $output_config;
3259
3260 return $config if (!defined($configs{$config}));
3261
3262 doprint "disabling config $config did not change .config\n";
3263
3264 $nochange_config{$config} = 1;
3265
3266 return undef;
3267}
3268
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003269sub make_min_config {
3270 my ($i) = @_;
3271
Steven Rostedtccc513b2012-05-21 17:13:40 -04003272 my $type = $minconfig_type;
3273 if ($type ne "boot" && $type ne "test") {
3274 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3275 " make_min_config works only with 'boot' and 'test'\n" and return;
3276 }
3277
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003278 if (!defined($output_minconfig)) {
3279 fail "OUTPUT_MIN_CONFIG not defined" and return;
3280 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003281
3282 # If output_minconfig exists, and the start_minconfig
3283 # came from min_config, than ask if we should use
3284 # that instead.
3285 if (-f $output_minconfig && !$start_minconfig_defined) {
3286 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003287 if (!defined($use_output_minconfig)) {
3288 if (read_yn " Use it as minconfig?") {
3289 $start_minconfig = $output_minconfig;
3290 }
3291 } elsif ($use_output_minconfig > 0) {
3292 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003293 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003294 } else {
3295 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003296 }
3297 }
3298
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003299 if (!defined($start_minconfig)) {
3300 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3301 }
3302
Steven Rostedt35ce5952011-07-15 21:57:25 -04003303 my $temp_config = "$tmpdir/temp_config";
3304
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003305 # First things first. We build an allnoconfig to find
3306 # out what the defaults are that we can't touch.
3307 # Some are selections, but we really can't handle selections.
3308
3309 my $save_minconfig = $minconfig;
3310 undef $minconfig;
3311
3312 run_command "$make allnoconfig" or return 0;
3313
Steven Rostedtb9066f62011-07-15 21:25:24 -04003314 read_depends;
3315
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003316 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003317
Steven Rostedt43d1b652011-07-15 22:01:56 -04003318 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003319 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003320
3321 if (defined($ignore_config)) {
3322 # make sure the file exists
3323 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003324 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003325 }
3326
Steven Rostedt43d1b652011-07-15 22:01:56 -04003327 %keep_configs = %save_configs;
3328
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003329 doprint "Load initial configs from $start_minconfig\n";
3330
3331 # Look at the current min configs, and save off all the
3332 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003333 assign_configs \%min_configs, $start_minconfig;
3334
3335 my @config_keys = keys %min_configs;
3336
Steven Rostedtac6974c2011-10-04 09:40:17 -04003337 # All configs need a depcount
3338 foreach my $config (@config_keys) {
3339 my $kconfig = chomp_config $config;
3340 if (!defined $depcount{$kconfig}) {
3341 $depcount{$kconfig} = 0;
3342 }
3343 }
3344
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003345 # Remove anything that was set by the make allnoconfig
3346 # we shouldn't need them as they get set for us anyway.
3347 foreach my $config (@config_keys) {
3348 # Remove anything in the ignore_config
3349 if (defined($keep_configs{$config})) {
3350 my $file = $ignore_config;
3351 $file =~ s,.*/(.*?)$,$1,;
3352 doprint "$config set by $file ... ignored\n";
3353 delete $min_configs{$config};
3354 next;
3355 }
3356 # But make sure the settings are the same. If a min config
3357 # sets a selection, we do not want to get rid of it if
3358 # it is not the same as what we have. Just move it into
3359 # the keep configs.
3360 if (defined($config_ignore{$config})) {
3361 if ($config_ignore{$config} ne $min_configs{$config}) {
3362 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3363 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3364 $keep_configs{$config} = $min_configs{$config};
3365 } else {
3366 doprint "$config set by allnoconfig ... ignored\n";
3367 }
3368 delete $min_configs{$config};
3369 }
3370 }
3371
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003372 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003373 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003374
3375 while (!$done) {
3376
3377 my $config;
3378 my $found;
3379
3380 # Now disable each config one by one and do a make oldconfig
3381 # till we find a config that changes our list.
3382
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003383 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003384
3385 # Sort keys by who is most dependent on
3386 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3387 @test_configs ;
3388
3389 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003390 my $reset = 1;
3391 for (my $i = 0; $i < $#test_configs; $i++) {
3392 if (!defined($nochange_config{$test_configs[0]})) {
3393 $reset = 0;
3394 last;
3395 }
3396 # This config didn't change the .config last time.
3397 # Place it at the end
3398 my $config = shift @test_configs;
3399 push @test_configs, $config;
3400 }
3401
3402 # if every test config has failed to modify the .config file
3403 # in the past, then reset and start over.
3404 if ($reset) {
3405 undef %nochange_config;
3406 }
3407
Steven Rostedtb9066f62011-07-15 21:25:24 -04003408 undef %processed_configs;
3409
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003410 foreach my $config (@test_configs) {
3411
Steven Rostedtb9066f62011-07-15 21:25:24 -04003412 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003413
Steven Rostedtb9066f62011-07-15 21:25:24 -04003414 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003415
3416 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003417 }
3418
3419 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003420 # we could have failed due to the nochange_config hash
3421 # reset and try again
3422 if (!$take_two) {
3423 undef %nochange_config;
3424 $take_two = 1;
3425 next;
3426 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003427 doprint "No more configs found that we can disable\n";
3428 $done = 1;
3429 last;
3430 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003431 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003432
3433 $config = $found;
3434
3435 doprint "Test with $config disabled\n";
3436
3437 # set in_bisect to keep build and monitor from dieing
3438 $in_bisect = 1;
3439
3440 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003441 build "oldconfig" or $failed = 1;
3442 if (!$failed) {
3443 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003444
3445 if ($type eq "test" && !$failed) {
3446 do_run_test or $failed = 1;
3447 }
3448
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003449 end_monitor;
3450 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003451
3452 $in_bisect = 0;
3453
3454 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003455 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003456 # this config is needed, add it to the ignore list.
3457 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003458 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003459 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003460
3461 # update new ignore configs
3462 if (defined($ignore_config)) {
3463 open (OUT, ">$temp_config")
3464 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003465 foreach my $config (keys %save_configs) {
3466 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003467 }
3468 close OUT;
3469 run_command "mv $temp_config $ignore_config" or
3470 dodie "failed to copy update to $ignore_config";
3471 }
3472
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003473 } else {
3474 # We booted without this config, remove it from the minconfigs.
3475 doprint "$config is not needed, disabling\n";
3476
3477 delete $min_configs{$config};
3478
3479 # Also disable anything that is not enabled in this config
3480 my %configs;
3481 assign_configs \%configs, $output_config;
3482 my @config_keys = keys %min_configs;
3483 foreach my $config (@config_keys) {
3484 if (!defined($configs{$config})) {
3485 doprint "$config is not set, disabling\n";
3486 delete $min_configs{$config};
3487 }
3488 }
3489
3490 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003491 open (OUT, ">$temp_config")
3492 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003493 foreach my $config (keys %keep_configs) {
3494 print OUT "$keep_configs{$config}\n";
3495 }
3496 foreach my $config (keys %min_configs) {
3497 print OUT "$min_configs{$config}\n";
3498 }
3499 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003500
3501 run_command "mv $temp_config $output_minconfig" or
3502 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003503 }
3504
3505 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003506 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003507 }
3508
3509 success $i;
3510 return 1;
3511}
3512
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003513$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003514
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003515if ($#ARGV == 0) {
3516 $ktest_config = $ARGV[0];
3517 if (! -f $ktest_config) {
3518 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003519 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003520 exit 0;
3521 }
3522 }
3523} else {
3524 $ktest_config = "ktest.conf";
3525}
3526
3527if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003528 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003529 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003530 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3531 print OUT << "EOF"
3532# Generated by ktest.pl
3533#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003534
3535# PWD is a ktest.pl variable that will result in the process working
3536# directory that ktest.pl is executed in.
3537
3538# THIS_DIR is automatically assigned the PWD of the path that generated
3539# the config file. It is best to use this variable when assigning other
3540# directory paths within this directory. This allows you to easily
3541# move the test cases to other locations or to other machines.
3542#
3543THIS_DIR := $variable{"PWD"}
3544
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003545# Define each test with TEST_START
3546# The config options below it will override the defaults
3547TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003548TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003549
3550DEFAULTS
3551EOF
3552;
3553 close(OUT);
3554}
3555read_config $ktest_config;
3556
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003557if (defined($opt{"LOG_FILE"})) {
3558 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3559}
3560
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003561# Append any configs entered in manually to the config file.
3562my @new_configs = keys %entered_configs;
3563if ($#new_configs >= 0) {
3564 print "\nAppending entered in configs to $ktest_config\n";
3565 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3566 foreach my $config (@new_configs) {
3567 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003568 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003569 }
3570}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003571
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003572if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3573 unlink $opt{"LOG_FILE"};
3574}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003575
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003576doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3577
Steven Rostedta57419b2010-11-02 15:13:54 -04003578for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3579
3580 if (!$i) {
3581 doprint "DEFAULT OPTIONS:\n";
3582 } else {
3583 doprint "\nTEST $i OPTIONS";
3584 if (defined($repeat_tests{$i})) {
3585 $repeat = $repeat_tests{$i};
3586 doprint " ITERATE $repeat";
3587 }
3588 doprint "\n";
3589 }
3590
3591 foreach my $option (sort keys %opt) {
3592
3593 if ($option =~ /\[(\d+)\]$/) {
3594 next if ($i != $1);
3595 } else {
3596 next if ($i);
3597 }
3598
3599 doprint "$option = $opt{$option}\n";
3600 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003601}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003602
Steven Rostedt2a625122011-05-20 15:48:59 -04003603sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003604 my ($name, $i) = @_;
3605
3606 my $option = "$name\[$i\]";
3607
3608 if (defined($opt{$option})) {
3609 return $opt{$option};
3610 }
3611
Steven Rostedta57419b2010-11-02 15:13:54 -04003612 foreach my $test (keys %repeat_tests) {
3613 if ($i >= $test &&
3614 $i < $test + $repeat_tests{$test}) {
3615 $option = "$name\[$test\]";
3616 if (defined($opt{$option})) {
3617 return $opt{$option};
3618 }
3619 }
3620 }
3621
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003622 if (defined($opt{$name})) {
3623 return $opt{$name};
3624 }
3625
3626 return undef;
3627}
3628
Steven Rostedt2a625122011-05-20 15:48:59 -04003629sub set_test_option {
3630 my ($name, $i) = @_;
3631
3632 my $option = __set_test_option($name, $i);
3633 return $option if (!defined($option));
3634
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003635 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003636}
3637
Steven Rostedt2545eb62010-11-02 15:01:32 -04003638# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003639for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003640
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003641 # Do not reboot on failing test options
3642 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003643 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003644
Steven Rostedt683a3e62012-05-18 13:34:35 -04003645 $have_version = 0;
3646
Steven Rostedt576f6272010-11-02 14:58:38 -04003647 $iteration = $i;
3648
Steven Rostedtc1434dc2012-07-20 22:39:16 -04003649 undef %force_config;
3650
Steven Rostedta75fece2010-11-02 14:58:27 -04003651 my $makecmd = set_test_option("MAKE_CMD", $i);
3652
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003653 # Load all the options into their mapped variable names
3654 foreach my $opt (keys %option_map) {
3655 ${$option_map{$opt}} = set_test_option($opt, $i);
3656 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003657
Steven Rostedt35ce5952011-07-15 21:57:25 -04003658 $start_minconfig_defined = 1;
3659
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003660 # The first test may override the PRE_KTEST option
3661 if (defined($pre_ktest) && $i == 1) {
3662 doprint "\n";
3663 run_command $pre_ktest;
3664 }
3665
3666 # Any test can override the POST_KTEST option
3667 # The last test takes precedence.
3668 if (defined($post_ktest)) {
3669 $final_post_ktest = $post_ktest;
3670 }
3671
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003672 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003673 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003674 $start_minconfig = $minconfig;
3675 }
3676
Steven Rostedta75fece2010-11-02 14:58:27 -04003677 chdir $builddir || die "can't change directory to $builddir";
3678
Andrew Jonesa908a662011-08-12 15:32:03 +02003679 foreach my $dir ($tmpdir, $outputdir) {
3680 if (!-d $dir) {
3681 mkpath($dir) or
3682 die "can't create $dir";
3683 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003684 }
3685
Steven Rostedte48c5292010-11-02 14:35:37 -04003686 $ENV{"SSH_USER"} = $ssh_user;
3687 $ENV{"MACHINE"} = $machine;
3688
Steven Rostedta75fece2010-11-02 14:58:27 -04003689 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303690 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003691 $dmesg = "$tmpdir/dmesg-$machine";
3692 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003693 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003694
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003695 if (!$buildonly) {
3696 $target = "$ssh_user\@$machine";
3697 if ($reboot_type eq "grub") {
3698 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003699 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003700 }
3701
3702 my $run_type = $build_type;
3703 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003704 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003705 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003706 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003707 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003708 $run_type = $config_bisect_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003709 }
3710
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003711 if ($test_type eq "make_min_config") {
3712 $run_type = "";
3713 }
3714
Steven Rostedta75fece2010-11-02 14:58:27 -04003715 # mistake in config file?
3716 if (!defined($run_type)) {
3717 $run_type = "ERROR";
3718 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003719
Steven Rostedte0a87422011-09-30 17:50:48 -04003720 my $installme = "";
3721 $installme = " no_install" if ($no_install);
3722
Steven Rostedt2545eb62010-11-02 15:01:32 -04003723 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003724 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003725
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003726 if (defined($pre_test)) {
3727 run_command $pre_test;
3728 }
3729
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003730 unlink $dmesg;
3731 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303732 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003733
Steven Rostedt250bae82011-07-15 22:05:59 -04003734 if (defined($addconfig)) {
3735 my $min = $minconfig;
3736 if (!defined($minconfig)) {
3737 $min = "";
3738 }
3739 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003740 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003741 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003742 }
3743
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003744 if (defined($checkout)) {
3745 run_command "git checkout $checkout" or
3746 die "failed to checkout $checkout";
3747 }
3748
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003749 $no_reboot = 0;
3750
Steven Rostedt648a1822012-03-21 11:18:27 -04003751 # A test may opt to not reboot the box
3752 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003753 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04003754 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003755
Steven Rostedta75fece2010-11-02 14:58:27 -04003756 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003757 bisect $i;
3758 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003759 } elsif ($test_type eq "config_bisect") {
3760 config_bisect $i;
3761 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003762 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003763 patchcheck $i;
3764 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003765 } elsif ($test_type eq "make_min_config") {
3766 make_min_config $i;
3767 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003768 }
3769
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003770 if ($build_type ne "nobuild") {
3771 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003772 }
3773
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003774 if ($test_type eq "install") {
3775 get_version;
3776 install;
3777 success $i;
3778 next;
3779 }
3780
Steven Rostedta75fece2010-11-02 14:58:27 -04003781 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003782 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003783 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003784
3785 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3786 do_run_test or $failed = 1;
3787 }
3788 end_monitor;
3789 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003790 }
3791
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003792 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003793}
3794
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003795if (defined($final_post_ktest)) {
3796 run_command $final_post_ktest;
3797}
3798
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003799if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003800 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003801} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003802 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04003803} elsif (defined($switch_to_good)) {
3804 # still need to get to the good kernel
3805 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003806}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003807
Steven Rostedt648a1822012-03-21 11:18:27 -04003808
Steven Rostedte48c5292010-11-02 14:35:37 -04003809doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3810
Steven Rostedt2545eb62010-11-02 15:01:32 -04003811exit 0;