blob: 5ad891a081134a94f4e47e26138683a6a613c980 [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 Rostedt600bbf02011-11-21 20:12:04 -050055
56# required, and we will ask users if they don't have them but we keep the default
57# value something that is common.
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050058 "REBOOT_TYPE" => "grub",
59 "LOCALVERSION" => "-test",
60 "SSH_USER" => "root",
61 "BUILD_TARGET" => "arch/x86/boot/bzImage",
62 "TARGET_IMAGE" => "/boot/vmlinuz-test",
Steven Rostedt9cc9e092011-12-22 21:37:22 -050063
64 "LOG_FILE" => undef,
65 "IGNORE_UNUSED" => 0,
Steven Rostedt4f43e0d2011-12-22 21:32:05 -050066);
Steven Rostedt2545eb62010-11-02 15:01:32 -040067
Steven Rostedt8d1491b2010-11-18 15:39:48 -050068my $ktest_config;
Steven Rostedt2545eb62010-11-02 15:01:32 -040069my $version;
Steven Rostedt683a3e62012-05-18 13:34:35 -040070my $have_version = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -040071my $machine;
Steven Rostedte48c5292010-11-02 14:35:37 -040072my $ssh_user;
Steven Rostedta75fece2010-11-02 14:58:27 -040073my $tmpdir;
74my $builddir;
75my $outputdir;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -050076my $output_config;
Steven Rostedta75fece2010-11-02 14:58:27 -040077my $test_type;
Steven Rostedt7faafbd2010-11-02 14:58:22 -040078my $build_type;
Steven Rostedta75fece2010-11-02 14:58:27 -040079my $build_options;
Steven Rostedt921ed4c2012-07-19 15:18:27 -040080my $final_post_ktest;
81my $pre_ktest;
82my $post_ktest;
83my $pre_test;
84my $post_test;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -040085my $pre_build;
86my $post_build;
87my $pre_build_die;
88my $post_build_die;
Steven Rostedta75fece2010-11-02 14:58:27 -040089my $reboot_type;
90my $reboot_script;
91my $power_cycle;
Steven Rostedte48c5292010-11-02 14:35:37 -040092my $reboot;
Steven Rostedta75fece2010-11-02 14:58:27 -040093my $reboot_on_error;
Steven Rostedtbc7c5802011-12-22 16:29:10 -050094my $switch_to_good;
95my $switch_to_test;
Steven Rostedta75fece2010-11-02 14:58:27 -040096my $poweroff_on_error;
Steven Rostedt648a1822012-03-21 11:18:27 -040097my $reboot_on_success;
Steven Rostedta75fece2010-11-02 14:58:27 -040098my $die_on_failure;
Steven Rostedt576f6272010-11-02 14:58:38 -040099my $powercycle_after_reboot;
100my $poweroff_after_halt;
Steven Rostedte48c5292010-11-02 14:35:37 -0400101my $ssh_exec;
102my $scp_to_target;
Steven Rostedt02ad2612012-03-21 08:21:24 -0400103my $scp_to_target_install;
Steven Rostedta75fece2010-11-02 14:58:27 -0400104my $power_off;
105my $grub_menu;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400106my $grub_number;
107my $target;
108my $make;
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400109my $pre_install;
Steven Rostedt8b37ca82010-11-02 14:58:33 -0400110my $post_install;
Steven Rostedte0a87422011-09-30 17:50:48 -0400111my $no_install;
Steven Rostedt5c42fc52010-11-02 14:57:01 -0400112my $noclean;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400113my $minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400114my $start_minconfig;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400115my $start_minconfig_defined;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400116my $output_minconfig;
Steven Rostedtccc513b2012-05-21 17:13:40 -0400117my $minconfig_type;
Steven Rostedt43de3312012-05-21 23:35:12 -0400118my $use_output_minconfig;
Steven Rostedt4c4ab122011-07-15 21:16:17 -0400119my $ignore_config;
Steven Rostedtbe405f92012-01-04 21:51:59 -0500120my $ignore_errors;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -0400121my $addconfig;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -0400122my $in_bisect = 0;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500123my $bisect_bad_commit = "";
Steven Rostedtd6ce2a02010-11-02 14:58:05 -0400124my $reverse_bisect;
Steven Rostedtc960bb92011-03-08 09:22:39 -0500125my $bisect_manual;
Steven Rostedtc23dca72011-03-08 09:26:31 -0500126my $bisect_skip;
Steven Rostedt30f75da2011-06-13 10:35:35 -0400127my $config_bisect_good;
Steven Rostedtc5dacb82011-12-22 12:43:57 -0500128my $bisect_ret_good;
129my $bisect_ret_bad;
130my $bisect_ret_skip;
131my $bisect_ret_abort;
132my $bisect_ret_default;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400133my $in_patchcheck = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -0400134my $run_test;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -0400135my $redirect;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400136my $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +0530137my $testlog;
Steven Rostedt7faafbd2010-11-02 14:58:22 -0400138my $dmesg;
139my $monitor_fp;
140my $monitor_pid;
141my $monitor_cnt = 0;
Steven Rostedta75fece2010-11-02 14:58:27 -0400142my $sleep_time;
143my $bisect_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -0400144my $patchcheck_sleep_time;
Steven Rostedt19902072011-06-14 20:46:25 -0400145my $ignore_warnings;
Steven Rostedta75fece2010-11-02 14:58:27 -0400146my $store_failures;
Rabin Vincentde5b6e32011-11-18 17:05:31 +0530147my $store_successes;
Steven Rostedt9064af52011-06-13 10:38:48 -0400148my $test_name;
Steven Rostedta75fece2010-11-02 14:58:27 -0400149my $timeout;
150my $booted_timeout;
Steven Rostedtf1a5b962011-06-13 10:30:00 -0400151my $detect_triplefault;
Steven Rostedta75fece2010-11-02 14:58:27 -0400152my $console;
Steven Rostedt2b803362011-09-30 18:00:23 -0400153my $reboot_success_line;
Steven Rostedta75fece2010-11-02 14:58:27 -0400154my $success_line;
Steven Rostedt1c8a6172010-11-09 12:55:40 -0500155my $stop_after_success;
156my $stop_after_failure;
Steven Rostedt2d01b262011-03-08 09:47:54 -0500157my $stop_test_after;
Steven Rostedta75fece2010-11-02 14:58:27 -0400158my $build_target;
159my $target_image;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500160my $checkout;
Steven Rostedta75fece2010-11-02 14:58:27 -0400161my $localversion;
Steven Rostedt576f6272010-11-02 14:58:38 -0400162my $iteration = 0;
Steven Rostedte48c5292010-11-02 14:35:37 -0400163my $successes = 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400164
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500165my $bisect_good;
166my $bisect_bad;
167my $bisect_type;
168my $bisect_start;
169my $bisect_replay;
170my $bisect_files;
171my $bisect_reverse;
172my $bisect_check;
173
174my $config_bisect;
175my $config_bisect_type;
Steven Rostedtb0918612012-07-19 15:26:00 -0400176my $config_bisect_check;
Steven Rostedtb5f4aea2011-12-22 21:33:55 -0500177
178my $patchcheck_type;
179my $patchcheck_start;
180my $patchcheck_end;
181
Steven Rostedt165708b2011-11-26 20:56:52 -0500182# set when a test is something other that just building or install
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500183# which would require more options.
184my $buildonly = 1;
185
Steven Rostedtdbd37832011-11-23 16:00:48 -0500186# set when creating a new config
187my $newconfig = 0;
188
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500189my %entered_configs;
190my %config_help;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400191my %variable;
Steven Rostedtcf79fab2012-07-19 15:29:43 -0400192
193# force_config is the list of configs that we force enabled (or disabled)
194# in a .config file. The MIN_CONFIG and ADD_CONFIG configs.
Steven Rostedtfcb3f162011-06-13 10:40:58 -0400195my %force_config;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500196
Steven Rostedt4ab1cce2011-09-30 18:12:20 -0400197# do not force reboots on config problems
198my $no_reboot = 1;
199
Steven Rostedt759a3cc2012-05-01 08:20:12 -0400200# reboot on success
201my $reboot_success = 0;
202
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500203my %option_map = (
204 "MACHINE" => \$machine,
205 "SSH_USER" => \$ssh_user,
206 "TMP_DIR" => \$tmpdir,
207 "OUTPUT_DIR" => \$outputdir,
208 "BUILD_DIR" => \$builddir,
209 "TEST_TYPE" => \$test_type,
Steven Rostedt921ed4c2012-07-19 15:18:27 -0400210 "PRE_KTEST" => \$pre_ktest,
211 "POST_KTEST" => \$post_ktest,
212 "PRE_TEST" => \$pre_test,
213 "POST_TEST" => \$post_test,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500214 "BUILD_TYPE" => \$build_type,
215 "BUILD_OPTIONS" => \$build_options,
216 "PRE_BUILD" => \$pre_build,
217 "POST_BUILD" => \$post_build,
218 "PRE_BUILD_DIE" => \$pre_build_die,
219 "POST_BUILD_DIE" => \$post_build_die,
220 "POWER_CYCLE" => \$power_cycle,
221 "REBOOT" => \$reboot,
222 "BUILD_NOCLEAN" => \$noclean,
223 "MIN_CONFIG" => \$minconfig,
224 "OUTPUT_MIN_CONFIG" => \$output_minconfig,
225 "START_MIN_CONFIG" => \$start_minconfig,
Steven Rostedtccc513b2012-05-21 17:13:40 -0400226 "MIN_CONFIG_TYPE" => \$minconfig_type,
Steven Rostedt43de3312012-05-21 23:35:12 -0400227 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500228 "IGNORE_CONFIG" => \$ignore_config,
229 "TEST" => \$run_test,
230 "ADD_CONFIG" => \$addconfig,
231 "REBOOT_TYPE" => \$reboot_type,
232 "GRUB_MENU" => \$grub_menu,
Steven Rostedte5c2ec12012-07-19 15:22:05 -0400233 "PRE_INSTALL" => \$pre_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500234 "POST_INSTALL" => \$post_install,
235 "NO_INSTALL" => \$no_install,
236 "REBOOT_SCRIPT" => \$reboot_script,
237 "REBOOT_ON_ERROR" => \$reboot_on_error,
238 "SWITCH_TO_GOOD" => \$switch_to_good,
239 "SWITCH_TO_TEST" => \$switch_to_test,
240 "POWEROFF_ON_ERROR" => \$poweroff_on_error,
Steven Rostedt648a1822012-03-21 11:18:27 -0400241 "REBOOT_ON_SUCCESS" => \$reboot_on_success,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500242 "DIE_ON_FAILURE" => \$die_on_failure,
243 "POWER_OFF" => \$power_off,
244 "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot,
245 "POWEROFF_AFTER_HALT" => \$poweroff_after_halt,
246 "SLEEP_TIME" => \$sleep_time,
247 "BISECT_SLEEP_TIME" => \$bisect_sleep_time,
248 "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time,
249 "IGNORE_WARNINGS" => \$ignore_warnings,
Steven Rostedtbe405f92012-01-04 21:51:59 -0500250 "IGNORE_ERRORS" => \$ignore_errors,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500251 "BISECT_MANUAL" => \$bisect_manual,
252 "BISECT_SKIP" => \$bisect_skip,
253 "CONFIG_BISECT_GOOD" => \$config_bisect_good,
254 "BISECT_RET_GOOD" => \$bisect_ret_good,
255 "BISECT_RET_BAD" => \$bisect_ret_bad,
256 "BISECT_RET_SKIP" => \$bisect_ret_skip,
257 "BISECT_RET_ABORT" => \$bisect_ret_abort,
258 "BISECT_RET_DEFAULT" => \$bisect_ret_default,
259 "STORE_FAILURES" => \$store_failures,
260 "STORE_SUCCESSES" => \$store_successes,
261 "TEST_NAME" => \$test_name,
262 "TIMEOUT" => \$timeout,
263 "BOOTED_TIMEOUT" => \$booted_timeout,
264 "CONSOLE" => \$console,
265 "DETECT_TRIPLE_FAULT" => \$detect_triplefault,
266 "SUCCESS_LINE" => \$success_line,
267 "REBOOT_SUCCESS_LINE" => \$reboot_success_line,
268 "STOP_AFTER_SUCCESS" => \$stop_after_success,
269 "STOP_AFTER_FAILURE" => \$stop_after_failure,
270 "STOP_TEST_AFTER" => \$stop_test_after,
271 "BUILD_TARGET" => \$build_target,
272 "SSH_EXEC" => \$ssh_exec,
273 "SCP_TO_TARGET" => \$scp_to_target,
Steven Rostedt02ad2612012-03-21 08:21:24 -0400274 "SCP_TO_TARGET_INSTALL" => \$scp_to_target_install,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500275 "CHECKOUT" => \$checkout,
276 "TARGET_IMAGE" => \$target_image,
277 "LOCALVERSION" => \$localversion,
278
279 "BISECT_GOOD" => \$bisect_good,
280 "BISECT_BAD" => \$bisect_bad,
281 "BISECT_TYPE" => \$bisect_type,
282 "BISECT_START" => \$bisect_start,
283 "BISECT_REPLAY" => \$bisect_replay,
284 "BISECT_FILES" => \$bisect_files,
285 "BISECT_REVERSE" => \$bisect_reverse,
286 "BISECT_CHECK" => \$bisect_check,
287
288 "CONFIG_BISECT" => \$config_bisect,
289 "CONFIG_BISECT_TYPE" => \$config_bisect_type,
Steven Rostedtb0918612012-07-19 15:26:00 -0400290 "CONFIG_BISECT_CHECK" => \$config_bisect_check,
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500291
292 "PATCHCHECK_TYPE" => \$patchcheck_type,
293 "PATCHCHECK_START" => \$patchcheck_start,
294 "PATCHCHECK_END" => \$patchcheck_end,
295);
296
297# Options may be used by other options, record them.
298my %used_options;
299
Steven Rostedt7bf51072011-10-22 09:07:03 -0400300# default variables that can be used
301chomp ($variable{"PWD"} = `pwd`);
302
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500303$config_help{"MACHINE"} = << "EOF"
304 The machine hostname that you will test.
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500305 For build only tests, it is still needed to differentiate log files.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500306EOF
307 ;
308$config_help{"SSH_USER"} = << "EOF"
309 The box is expected to have ssh on normal bootup, provide the user
310 (most likely root, since you need privileged operations)
311EOF
312 ;
313$config_help{"BUILD_DIR"} = << "EOF"
314 The directory that contains the Linux source code (full path).
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500315 You can use \${PWD} that will be the path where ktest.pl is run, or use
316 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500317EOF
318 ;
319$config_help{"OUTPUT_DIR"} = << "EOF"
320 The directory that the objects will be built (full path).
321 (can not be same as BUILD_DIR)
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500322 You can use \${PWD} that will be the path where ktest.pl is run, or use
323 \${THIS_DIR} which is assigned \${PWD} but may be changed later.
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500324EOF
325 ;
326$config_help{"BUILD_TARGET"} = << "EOF"
327 The location of the compiled file to copy to the target.
328 (relative to OUTPUT_DIR)
329EOF
330 ;
Steven Rostedtdbd37832011-11-23 16:00:48 -0500331$config_help{"BUILD_OPTIONS"} = << "EOF"
332 Options to add to \"make\" when building.
333 i.e. -j20
334EOF
335 ;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500336$config_help{"TARGET_IMAGE"} = << "EOF"
337 The place to put your image on the test machine.
338EOF
339 ;
340$config_help{"POWER_CYCLE"} = << "EOF"
341 A script or command to reboot the box.
342
343 Here is a digital loggers power switch example
344 POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'
345
346 Here is an example to reboot a virtual box on the current host
347 with the name "Guest".
348 POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest
349EOF
350 ;
351$config_help{"CONSOLE"} = << "EOF"
352 The script or command that reads the console
353
354 If you use ttywatch server, something like the following would work.
355CONSOLE = nc -d localhost 3001
356
357 For a virtual machine with guest name "Guest".
358CONSOLE = virsh console Guest
359EOF
360 ;
361$config_help{"LOCALVERSION"} = << "EOF"
362 Required version ending to differentiate the test
363 from other linux builds on the system.
364EOF
365 ;
366$config_help{"REBOOT_TYPE"} = << "EOF"
367 Way to reboot the box to the test kernel.
368 Only valid options so far are "grub" and "script".
369
370 If you specify grub, it will assume grub version 1
371 and will search in /boot/grub/menu.lst for the title \$GRUB_MENU
372 and select that target to reboot to the kernel. If this is not
373 your setup, then specify "script" and have a command or script
374 specified in REBOOT_SCRIPT to boot to the target.
375
376 The entry in /boot/grub/menu.lst must be entered in manually.
377 The test will not modify that file.
378EOF
379 ;
380$config_help{"GRUB_MENU"} = << "EOF"
381 The grub title name for the test kernel to boot
382 (Only mandatory if REBOOT_TYPE = grub)
383
384 Note, ktest.pl will not update the grub menu.lst, you need to
385 manually add an option for the test. ktest.pl will search
386 the grub menu.lst for this option to find what kernel to
387 reboot into.
388
389 For example, if in the /boot/grub/menu.lst the test kernel title has:
390 title Test Kernel
391 kernel vmlinuz-test
392 GRUB_MENU = Test Kernel
393EOF
394 ;
395$config_help{"REBOOT_SCRIPT"} = << "EOF"
396 A script to reboot the target into the test kernel
397 (Only mandatory if REBOOT_TYPE = script)
398EOF
399 ;
400
Steven Rostedtdad98752011-11-22 20:48:57 -0500401sub read_prompt {
402 my ($cancel, $prompt) = @_;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400403
404 my $ans;
405
406 for (;;) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500407 if ($cancel) {
408 print "$prompt [y/n/C] ";
409 } else {
410 print "$prompt [Y/n] ";
411 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400412 $ans = <STDIN>;
413 chomp $ans;
414 if ($ans =~ /^\s*$/) {
Steven Rostedtdad98752011-11-22 20:48:57 -0500415 if ($cancel) {
416 $ans = "c";
417 } else {
418 $ans = "y";
419 }
Steven Rostedt35ce5952011-07-15 21:57:25 -0400420 }
421 last if ($ans =~ /^y$/i || $ans =~ /^n$/i);
Steven Rostedtdad98752011-11-22 20:48:57 -0500422 if ($cancel) {
423 last if ($ans =~ /^c$/i);
424 print "Please answer either 'y', 'n' or 'c'.\n";
425 } else {
426 print "Please answer either 'y' or 'n'.\n";
427 }
428 }
429 if ($ans =~ /^c/i) {
430 exit;
Steven Rostedt35ce5952011-07-15 21:57:25 -0400431 }
432 if ($ans !~ /^y$/i) {
433 return 0;
434 }
435 return 1;
436}
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500437
Steven Rostedtdad98752011-11-22 20:48:57 -0500438sub read_yn {
439 my ($prompt) = @_;
440
441 return read_prompt 0, $prompt;
442}
443
444sub read_ync {
445 my ($prompt) = @_;
446
447 return read_prompt 1, $prompt;
448}
449
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500450sub get_ktest_config {
451 my ($config) = @_;
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400452 my $ans;
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500453
454 return if (defined($opt{$config}));
455
456 if (defined($config_help{$config})) {
457 print "\n";
458 print $config_help{$config};
459 }
460
461 for (;;) {
462 print "$config = ";
Steven Rostedtdbd37832011-11-23 16:00:48 -0500463 if (defined($default{$config}) && length($default{$config})) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500464 print "\[$default{$config}\] ";
465 }
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400466 $ans = <STDIN>;
467 $ans =~ s/^\s*(.*\S)\s*$/$1/;
468 if ($ans =~ /^\s*$/) {
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500469 if ($default{$config}) {
Steven Rostedt815e2bd2011-10-28 07:01:40 -0400470 $ans = $default{$config};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500471 } else {
472 print "Your answer can not be blank\n";
473 next;
474 }
475 }
Steven Rostedt0e7a22d2011-11-21 20:39:33 -0500476 $entered_configs{$config} = ${ans};
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500477 last;
478 }
479}
480
481sub get_ktest_configs {
482 get_ktest_config("MACHINE");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500483 get_ktest_config("BUILD_DIR");
484 get_ktest_config("OUTPUT_DIR");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500485
Steven Rostedtdbd37832011-11-23 16:00:48 -0500486 if ($newconfig) {
487 get_ktest_config("BUILD_OPTIONS");
488 }
489
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500490 # options required for other than just building a kernel
491 if (!$buildonly) {
Steven Rostedt165708b2011-11-26 20:56:52 -0500492 get_ktest_config("POWER_CYCLE");
493 get_ktest_config("CONSOLE");
494 }
495
496 # options required for install and more
497 if ($buildonly != 1) {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500498 get_ktest_config("SSH_USER");
499 get_ktest_config("BUILD_TARGET");
500 get_ktest_config("TARGET_IMAGE");
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500501 }
502
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500503 get_ktest_config("LOCALVERSION");
504
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500505 return if ($buildonly);
506
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500507 my $rtype = $opt{"REBOOT_TYPE"};
508
509 if (!defined($rtype)) {
510 if (!defined($opt{"GRUB_MENU"})) {
511 get_ktest_config("REBOOT_TYPE");
512 $rtype = $entered_configs{"REBOOT_TYPE"};
513 } else {
514 $rtype = "grub";
515 }
516 }
517
518 if ($rtype eq "grub") {
519 get_ktest_config("GRUB_MENU");
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500520 }
521}
522
Steven Rostedt77d942c2011-05-20 13:36:58 -0400523sub process_variables {
Steven Rostedt8d735212011-10-17 11:36:44 -0400524 my ($value, $remove_undef) = @_;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400525 my $retval = "";
526
527 # We want to check for '\', and it is just easier
528 # to check the previous characet of '$' and not need
529 # to worry if '$' is the first character. By adding
530 # a space to $value, we can just check [^\\]\$ and
531 # it will still work.
532 $value = " $value";
533
534 while ($value =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
535 my $begin = $1;
536 my $var = $2;
537 my $end = $3;
538 # append beginning of value to retval
539 $retval = "$retval$begin";
540 if (defined($variable{$var})) {
541 $retval = "$retval$variable{$var}";
Steven Rostedt8d735212011-10-17 11:36:44 -0400542 } elsif (defined($remove_undef) && $remove_undef) {
543 # for if statements, any variable that is not defined,
544 # we simple convert to 0
545 $retval = "${retval}0";
Steven Rostedt77d942c2011-05-20 13:36:58 -0400546 } else {
547 # put back the origin piece.
548 $retval = "$retval\$\{$var\}";
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500549 # This could be an option that is used later, save
550 # it so we don't warn if this option is not one of
551 # ktests options.
552 $used_options{$var} = 1;
Steven Rostedt77d942c2011-05-20 13:36:58 -0400553 }
554 $value = $end;
555 }
556 $retval = "$retval$value";
557
558 # remove the space added in the beginning
559 $retval =~ s/ //;
560
561 return "$retval"
562}
563
Steven Rostedta57419b2010-11-02 15:13:54 -0400564sub set_value {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400565 my ($lvalue, $rvalue, $override, $overrides, $name) = @_;
Steven Rostedta57419b2010-11-02 15:13:54 -0400566
Steven Rostedtcad96662011-12-22 11:32:52 -0500567 my $prvalue = process_variables($rvalue);
568
569 if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") {
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500570 # Note if a test is something other than build, then we
571 # will need other manditory options.
Steven Rostedtcad96662011-12-22 11:32:52 -0500572 if ($prvalue ne "install") {
Steven Rostedt165708b2011-11-26 20:56:52 -0500573 $buildonly = 0;
574 } else {
575 # install still limits some manditory options.
576 $buildonly = 2;
577 }
Steven Rostedtbb8474b2011-11-23 15:58:00 -0500578 }
579
Steven Rostedta57419b2010-11-02 15:13:54 -0400580 if (defined($opt{$lvalue})) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400581 if (!$override || defined(${$overrides}{$lvalue})) {
582 my $extra = "";
583 if ($override) {
584 $extra = "In the same override section!\n";
585 }
586 die "$name: $.: Option $lvalue defined more than once!\n$extra";
587 }
Steven Rostedtcad96662011-12-22 11:32:52 -0500588 ${$overrides}{$lvalue} = $prvalue;
Steven Rostedta57419b2010-11-02 15:13:54 -0400589 }
Steven Rostedt21a96792010-11-08 16:45:50 -0500590 if ($rvalue =~ /^\s*$/) {
591 delete $opt{$lvalue};
592 } else {
Steven Rostedtcad96662011-12-22 11:32:52 -0500593 $opt{$lvalue} = $prvalue;
Steven Rostedt21a96792010-11-08 16:45:50 -0500594 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400595}
596
Steven Rostedt77d942c2011-05-20 13:36:58 -0400597sub set_variable {
598 my ($lvalue, $rvalue) = @_;
599
600 if ($rvalue =~ /^\s*$/) {
601 delete $variable{$lvalue};
602 } else {
603 $rvalue = process_variables($rvalue);
604 $variable{$lvalue} = $rvalue;
605 }
606}
607
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400608sub process_compare {
609 my ($lval, $cmp, $rval) = @_;
610
611 # remove whitespace
612
613 $lval =~ s/^\s*//;
614 $lval =~ s/\s*$//;
615
616 $rval =~ s/^\s*//;
617 $rval =~ s/\s*$//;
618
619 if ($cmp eq "==") {
620 return $lval eq $rval;
621 } elsif ($cmp eq "!=") {
622 return $lval ne $rval;
623 }
624
625 my $statement = "$lval $cmp $rval";
626 my $ret = eval $statement;
627
628 # $@ stores error of eval
629 if ($@) {
630 return -1;
631 }
632
633 return $ret;
634}
635
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400636sub value_defined {
637 my ($val) = @_;
638
639 return defined($variable{$2}) ||
640 defined($opt{$2});
641}
642
Steven Rostedt8d735212011-10-17 11:36:44 -0400643my $d = 0;
644sub process_expression {
645 my ($name, $val) = @_;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400646
Steven Rostedt8d735212011-10-17 11:36:44 -0400647 my $c = $d++;
648
649 while ($val =~ s/\(([^\(]*?)\)/\&\&\&\&VAL\&\&\&\&/) {
650 my $express = $1;
651
652 if (process_expression($name, $express)) {
653 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 1 /;
654 } else {
655 $val =~ s/\&\&\&\&VAL\&\&\&\&/ 0 /;
656 }
657 }
658
659 $d--;
660 my $OR = "\\|\\|";
661 my $AND = "\\&\\&";
662
663 while ($val =~ s/^(.*?)($OR|$AND)//) {
664 my $express = $1;
665 my $op = $2;
666
667 if (process_expression($name, $express)) {
668 if ($op eq "||") {
669 return 1;
670 }
671 } else {
672 if ($op eq "&&") {
673 return 0;
674 }
675 }
676 }
Steven Rostedt45d73a52011-09-30 19:44:53 -0400677
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400678 if ($val =~ /(.*)(==|\!=|>=|<=|>|<)(.*)/) {
679 my $ret = process_compare($1, $2, $3);
680 if ($ret < 0) {
681 die "$name: $.: Unable to process comparison\n";
682 }
683 return $ret;
684 }
685
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400686 if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
687 if (defined $1) {
688 return !value_defined($2);
689 } else {
690 return value_defined($2);
691 }
692 }
693
Steven Rostedt45d73a52011-09-30 19:44:53 -0400694 if ($val =~ /^\s*0\s*$/) {
695 return 0;
696 } elsif ($val =~ /^\s*\d+\s*$/) {
697 return 1;
698 }
699
Steven Rostedt9900b5d2011-09-30 22:41:14 -0400700 die ("$name: $.: Undefined content $val in if statement\n");
Steven Rostedt8d735212011-10-17 11:36:44 -0400701}
702
703sub process_if {
704 my ($name, $value) = @_;
705
706 # Convert variables and replace undefined ones with 0
707 my $val = process_variables($value, 1);
708 my $ret = process_expression $name, $val;
709
710 return $ret;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400711}
712
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400713sub __read_config {
714 my ($config, $current_test_num) = @_;
Steven Rostedt2545eb62010-11-02 15:01:32 -0400715
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400716 my $in;
717 open($in, $config) || die "can't read file $config";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400718
Steven Rostedta57419b2010-11-02 15:13:54 -0400719 my $name = $config;
720 $name =~ s,.*/(.*),$1,;
721
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400722 my $test_num = $$current_test_num;
Steven Rostedta57419b2010-11-02 15:13:54 -0400723 my $default = 1;
724 my $repeat = 1;
725 my $num_tests_set = 0;
726 my $skip = 0;
727 my $rest;
Steven Rostedta9f84422011-10-17 11:06:29 -0400728 my $line;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400729 my $test_case = 0;
Steven Rostedt45d73a52011-09-30 19:44:53 -0400730 my $if = 0;
731 my $if_set = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400732 my $override = 0;
733
734 my %overrides;
Steven Rostedta57419b2010-11-02 15:13:54 -0400735
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400736 while (<$in>) {
Steven Rostedt2545eb62010-11-02 15:01:32 -0400737
738 # ignore blank lines and comments
739 next if (/^\s*$/ || /\s*\#/);
740
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400741 if (/^\s*(TEST_START|DEFAULTS)\b(.*)/) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400742
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400743 my $type = $1;
744 $rest = $2;
Steven Rostedta9f84422011-10-17 11:06:29 -0400745 $line = $2;
Steven Rostedta57419b2010-11-02 15:13:54 -0400746
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400747 my $old_test_num;
748 my $old_repeat;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400749 $override = 0;
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400750
751 if ($type eq "TEST_START") {
752
753 if ($num_tests_set) {
754 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
755 }
756
757 $old_test_num = $test_num;
758 $old_repeat = $repeat;
759
760 $test_num += $repeat;
761 $default = 0;
762 $repeat = 1;
763 } else {
764 $default = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400765 }
766
Steven Rostedta9f84422011-10-17 11:06:29 -0400767 # If SKIP is anywhere in the line, the command will be skipped
768 if ($rest =~ s/\s+SKIP\b//) {
Steven Rostedta57419b2010-11-02 15:13:54 -0400769 $skip = 1;
770 } else {
Steven Rostedt0df213c2011-06-14 20:51:37 -0400771 $test_case = 1;
Steven Rostedta57419b2010-11-02 15:13:54 -0400772 $skip = 0;
773 }
774
Steven Rostedta9f84422011-10-17 11:06:29 -0400775 if ($rest =~ s/\sELSE\b//) {
776 if (!$if) {
777 die "$name: $.: ELSE found with out matching IF section\n$_";
778 }
779 $if = 0;
780
781 if ($if_set) {
782 $skip = 1;
783 } else {
784 $skip = 0;
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400785 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400786 }
787
Steven Rostedta9f84422011-10-17 11:06:29 -0400788 if ($rest =~ s/\sIF\s+(.*)//) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400789 if (process_if($name, $1)) {
790 $if_set = 1;
791 } else {
792 $skip = 1;
793 }
794 $if = 1;
795 } else {
796 $if = 0;
Steven Rostedta9f84422011-10-17 11:06:29 -0400797 $if_set = 0;
Steven Rostedta57419b2010-11-02 15:13:54 -0400798 }
799
Steven Rostedta9f84422011-10-17 11:06:29 -0400800 if (!$skip) {
801 if ($type eq "TEST_START") {
802 if ($rest =~ s/\s+ITERATE\s+(\d+)//) {
803 $repeat = $1;
804 $repeat_tests{"$test_num"} = $repeat;
805 }
806 } elsif ($rest =~ s/\sOVERRIDE\b//) {
807 # DEFAULT only
808 $override = 1;
809 # Clear previous overrides
810 %overrides = ();
811 }
812 }
813
814 if (!$skip && $rest !~ /^\s*$/) {
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400815 die "$name: $.: Gargbage found after $type\n$_";
Steven Rostedta57419b2010-11-02 15:13:54 -0400816 }
817
Steven Rostedt0050b6b2011-09-30 21:10:30 -0400818 if ($skip && $type eq "TEST_START") {
Steven Rostedta57419b2010-11-02 15:13:54 -0400819 $test_num = $old_test_num;
Steven Rostedte48c5292010-11-02 14:35:37 -0400820 $repeat = $old_repeat;
Steven Rostedta57419b2010-11-02 15:13:54 -0400821 }
822
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400823 } elsif (/^\s*ELSE\b(.*)$/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400824 if (!$if) {
825 die "$name: $.: ELSE found with out matching IF section\n$_";
826 }
827 $rest = $1;
828 if ($if_set) {
829 $skip = 1;
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400830 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400831 } else {
832 $skip = 0;
833
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400834 if ($rest =~ /\sIF\s+(.*)/) {
Steven Rostedt45d73a52011-09-30 19:44:53 -0400835 # May be a ELSE IF section.
836 if (!process_if($name, $1)) {
837 $skip = 1;
838 }
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400839 $rest = "";
Steven Rostedt45d73a52011-09-30 19:44:53 -0400840 } else {
841 $if = 0;
842 }
843 }
844
Steven Rostedtab7a3f52011-09-30 20:24:07 -0400845 if ($rest !~ /^\s*$/) {
846 die "$name: $.: Gargbage found after DEFAULTS\n$_";
847 }
848
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400849 } elsif (/^\s*INCLUDE\s+(\S+)/) {
850
851 next if ($skip);
852
853 if (!$default) {
854 die "$name: $.: INCLUDE can only be done in default sections\n$_";
855 }
856
857 my $file = process_variables($1);
858
859 if ($file !~ m,^/,) {
860 # check the path of the config file first
861 if ($config =~ m,(.*)/,) {
862 if (-f "$1/$file") {
863 $file = "$1/$file";
864 }
865 }
866 }
867
868 if ( ! -r $file ) {
869 die "$name: $.: Can't read file $file\n$_";
870 }
871
872 if (__read_config($file, \$test_num)) {
873 $test_case = 1;
874 }
875
Steven Rostedta57419b2010-11-02 15:13:54 -0400876 } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {
877
878 next if ($skip);
879
Steven Rostedt2545eb62010-11-02 15:01:32 -0400880 my $lvalue = $1;
881 my $rvalue = $2;
882
Steven Rostedta57419b2010-11-02 15:13:54 -0400883 if (!$default &&
884 ($lvalue eq "NUM_TESTS" ||
885 $lvalue eq "LOG_FILE" ||
886 $lvalue eq "CLEAR_LOG")) {
887 die "$name: $.: $lvalue must be set in DEFAULTS section\n";
Steven Rostedta75fece2010-11-02 14:58:27 -0400888 }
Steven Rostedta57419b2010-11-02 15:13:54 -0400889
890 if ($lvalue eq "NUM_TESTS") {
891 if ($test_num) {
892 die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";
893 }
894 if (!$default) {
895 die "$name: $.: NUM_TESTS must be set in default section\n";
896 }
897 $num_tests_set = 1;
898 }
899
900 if ($default || $lvalue =~ /\[\d+\]$/) {
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400901 set_value($lvalue, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400902 } else {
903 my $val = "$lvalue\[$test_num\]";
Steven Rostedt3d1cc412011-09-30 22:14:21 -0400904 set_value($val, $rvalue, $override, \%overrides, $name);
Steven Rostedta57419b2010-11-02 15:13:54 -0400905
906 if ($repeat > 1) {
907 $repeats{$val} = $repeat;
908 }
909 }
Steven Rostedt77d942c2011-05-20 13:36:58 -0400910 } elsif (/^\s*([A-Z_\[\]\d]+)\s*:=\s*(.*?)\s*$/) {
911 next if ($skip);
912
913 my $lvalue = $1;
914 my $rvalue = $2;
915
916 # process config variables.
917 # Config variables are only active while reading the
918 # config and can be defined anywhere. They also ignore
919 # TEST_START and DEFAULTS, but are skipped if they are in
920 # on of these sections that have SKIP defined.
921 # The save variable can be
922 # defined multiple times and the new one simply overrides
923 # the prevous one.
924 set_variable($lvalue, $rvalue);
925
Steven Rostedta57419b2010-11-02 15:13:54 -0400926 } else {
927 die "$name: $.: Garbage found in config\n$_";
Steven Rostedt2545eb62010-11-02 15:01:32 -0400928 }
929 }
930
Steven Rostedta57419b2010-11-02 15:13:54 -0400931 if ($test_num) {
932 $test_num += $repeat - 1;
933 $opt{"NUM_TESTS"} = $test_num;
934 }
935
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400936 close($in);
937
938 $$current_test_num = $test_num;
939
940 return $test_case;
941}
942
Steven Rostedtc4261d02011-11-23 13:41:18 -0500943sub get_test_case {
944 print "What test case would you like to run?\n";
945 print " (build, install or boot)\n";
946 print " Other tests are available but require editing the config file\n";
947 my $ans = <STDIN>;
948 chomp $ans;
949 $default{"TEST_TYPE"} = $ans;
950}
951
Steven Rostedt2ed3b162011-09-30 21:00:00 -0400952sub read_config {
953 my ($config) = @_;
954
955 my $test_case;
956 my $test_num = 0;
957
958 $test_case = __read_config $config, \$test_num;
959
Steven Rostedt8d1491b2010-11-18 15:39:48 -0500960 # make sure we have all mandatory configs
961 get_ktest_configs;
962
Steven Rostedt0df213c2011-06-14 20:51:37 -0400963 # was a test specified?
964 if (!$test_case) {
965 print "No test case specified.\n";
Steven Rostedtc4261d02011-11-23 13:41:18 -0500966 get_test_case;
Steven Rostedt0df213c2011-06-14 20:51:37 -0400967 }
968
Steven Rostedta75fece2010-11-02 14:58:27 -0400969 # set any defaults
970
971 foreach my $default (keys %default) {
972 if (!defined($opt{$default})) {
973 $opt{$default} = $default{$default};
974 }
975 }
Steven Rostedt9cc9e092011-12-22 21:37:22 -0500976
977 if ($opt{"IGNORE_UNUSED"} == 1) {
978 return;
979 }
980
981 my %not_used;
982
983 # check if there are any stragglers (typos?)
984 foreach my $option (keys %opt) {
985 my $op = $option;
986 # remove per test labels.
987 $op =~ s/\[.*\]//;
988 if (!exists($option_map{$op}) &&
989 !exists($default{$op}) &&
990 !exists($used_options{$op})) {
991 $not_used{$op} = 1;
992 }
993 }
994
995 if (%not_used) {
996 my $s = "s are";
997 $s = " is" if (keys %not_used == 1);
998 print "The following option$s not used; could be a typo:\n";
999 foreach my $option (keys %not_used) {
1000 print "$option\n";
1001 }
1002 print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n";
1003 if (!read_yn "Do you want to continue?") {
1004 exit -1;
1005 }
1006 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001007}
1008
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001009sub __eval_option {
1010 my ($option, $i) = @_;
1011
1012 # Add space to evaluate the character before $
1013 $option = " $option";
1014 my $retval = "";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301015 my $repeated = 0;
1016 my $parent = 0;
1017
1018 foreach my $test (keys %repeat_tests) {
1019 if ($i >= $test &&
1020 $i < $test + $repeat_tests{$test}) {
1021
1022 $repeated = 1;
1023 $parent = $test;
1024 last;
1025 }
1026 }
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001027
1028 while ($option =~ /(.*?[^\\])\$\{(.*?)\}(.*)/) {
1029 my $start = $1;
1030 my $var = $2;
1031 my $end = $3;
1032
1033 # Append beginning of line
1034 $retval = "$retval$start";
1035
1036 # If the iteration option OPT[$i] exists, then use that.
1037 # otherwise see if the default OPT (without [$i]) exists.
1038
1039 my $o = "$var\[$i\]";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301040 my $parento = "$var\[$parent\]";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001041
1042 if (defined($opt{$o})) {
1043 $o = $opt{$o};
1044 $retval = "$retval$o";
Rabin Vincentf9dfb652011-11-18 17:05:30 +05301045 } elsif ($repeated && defined($opt{$parento})) {
1046 $o = $opt{$parento};
1047 $retval = "$retval$o";
Steven Rostedt23715c3c2011-06-13 11:03:34 -04001048 } elsif (defined($opt{$var})) {
1049 $o = $opt{$var};
1050 $retval = "$retval$o";
1051 } else {
1052 $retval = "$retval\$\{$var\}";
1053 }
1054
1055 $option = $end;
1056 }
1057
1058 $retval = "$retval$option";
1059
1060 $retval =~ s/^ //;
1061
1062 return $retval;
1063}
1064
1065sub eval_option {
1066 my ($option, $i) = @_;
1067
1068 my $prev = "";
1069
1070 # Since an option can evaluate to another option,
1071 # keep iterating until we do not evaluate any more
1072 # options.
1073 my $r = 0;
1074 while ($prev ne $option) {
1075 # Check for recursive evaluations.
1076 # 100 deep should be more than enough.
1077 if ($r++ > 100) {
1078 die "Over 100 evaluations accurred with $option\n" .
1079 "Check for recursive variables\n";
1080 }
1081 $prev = $option;
1082 $option = __eval_option($option, $i);
1083 }
1084
1085 return $option;
1086}
1087
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001088sub _logit {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001089 if (defined($opt{"LOG_FILE"})) {
1090 open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
1091 print OUT @_;
1092 close(OUT);
1093 }
1094}
1095
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001096sub logit {
1097 if (defined($opt{"LOG_FILE"})) {
1098 _logit @_;
1099 } else {
1100 print @_;
1101 }
1102}
1103
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001104sub doprint {
1105 print @_;
Steven Rostedtd1e2f222010-11-08 16:39:57 -05001106 _logit @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001107}
1108
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001109sub run_command;
Andrew Jones2728be42011-08-12 15:32:05 +02001110sub start_monitor;
1111sub end_monitor;
1112sub wait_for_monitor;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001113
1114sub reboot {
Andrew Jones2728be42011-08-12 15:32:05 +02001115 my ($time) = @_;
1116
Steven Rostedt2b803362011-09-30 18:00:23 -04001117 if (defined($time)) {
1118 start_monitor;
1119 # flush out current monitor
1120 # May contain the reboot success line
1121 wait_for_monitor 1;
1122 }
1123
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001124 # try to reboot normally
Steven Rostedte48c5292010-11-02 14:35:37 -04001125 if (run_command $reboot) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001126 if (defined($powercycle_after_reboot)) {
1127 sleep $powercycle_after_reboot;
1128 run_command "$power_cycle";
1129 }
1130 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001131 # nope? power cycle it.
Steven Rostedta75fece2010-11-02 14:58:27 -04001132 run_command "$power_cycle";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001133 }
Andrew Jones2728be42011-08-12 15:32:05 +02001134
1135 if (defined($time)) {
Steven Rostedt2b803362011-09-30 18:00:23 -04001136 wait_for_monitor($time, $reboot_success_line);
Andrew Jones2728be42011-08-12 15:32:05 +02001137 end_monitor;
1138 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001139}
1140
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001141sub reboot_to_good {
1142 my ($time) = @_;
1143
1144 if (defined($switch_to_good)) {
1145 run_command $switch_to_good;
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001146 }
1147
1148 reboot $time;
1149}
1150
Steven Rostedt576f6272010-11-02 14:58:38 -04001151sub do_not_reboot {
1152 my $i = $iteration;
1153
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001154 return $test_type eq "build" || $no_reboot ||
Steven Rostedt576f6272010-11-02 14:58:38 -04001155 ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||
1156 ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");
1157}
1158
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001159sub dodie {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001160 doprint "CRITICAL FAILURE... ", @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001161
Steven Rostedt576f6272010-11-02 14:58:38 -04001162 my $i = $iteration;
1163
1164 if ($reboot_on_error && !do_not_reboot) {
1165
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001166 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001167 reboot_to_good;
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001168
Steven Rostedta75fece2010-11-02 14:58:27 -04001169 } elsif ($poweroff_on_error && defined($power_off)) {
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001170 doprint "POWERING OFF\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001171 `$power_off`;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001172 }
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001173
Steven Rostedtf80802c2011-03-07 13:18:47 -05001174 if (defined($opt{"LOG_FILE"})) {
1175 print " See $opt{LOG_FILE} for more info.\n";
1176 }
1177
Steven Rostedt576f6272010-11-02 14:58:38 -04001178 die @_, "\n";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001179}
1180
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001181sub open_console {
1182 my ($fp) = @_;
1183
1184 my $flags;
1185
Steven Rostedta75fece2010-11-02 14:58:27 -04001186 my $pid = open($fp, "$console|") or
1187 dodie "Can't open console $console";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001188
1189 $flags = fcntl($fp, F_GETFL, 0) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001190 dodie "Can't get flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001191 $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
Steven Rostedt576f6272010-11-02 14:58:38 -04001192 dodie "Can't set flags for the socket: $!";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001193
1194 return $pid;
1195}
1196
1197sub close_console {
1198 my ($fp, $pid) = @_;
1199
1200 doprint "kill child process $pid\n";
1201 kill 2, $pid;
1202
1203 print "closing!\n";
1204 close($fp);
1205}
1206
1207sub start_monitor {
1208 if ($monitor_cnt++) {
1209 return;
1210 }
1211 $monitor_fp = \*MONFD;
1212 $monitor_pid = open_console $monitor_fp;
Steven Rostedta75fece2010-11-02 14:58:27 -04001213
1214 return;
1215
1216 open(MONFD, "Stop perl from warning about single use of MONFD");
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001217}
1218
1219sub end_monitor {
1220 if (--$monitor_cnt) {
1221 return;
1222 }
1223 close_console($monitor_fp, $monitor_pid);
1224}
1225
1226sub wait_for_monitor {
Steven Rostedt2b803362011-09-30 18:00:23 -04001227 my ($time, $stop) = @_;
1228 my $full_line = "";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001229 my $line;
Steven Rostedt2b803362011-09-30 18:00:23 -04001230 my $booted = 0;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001231
Steven Rostedta75fece2010-11-02 14:58:27 -04001232 doprint "** Wait for monitor to settle down **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001233
1234 # read the monitor and wait for the system to calm down
Steven Rostedt2b803362011-09-30 18:00:23 -04001235 while (!$booted) {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001236 $line = wait_for_input($monitor_fp, $time);
Steven Rostedt2b803362011-09-30 18:00:23 -04001237 last if (!defined($line));
1238 print "$line";
1239 $full_line .= $line;
1240
1241 if (defined($stop) && $full_line =~ /$stop/) {
1242 doprint "wait for monitor detected $stop\n";
1243 $booted = 1;
1244 }
1245
1246 if ($line =~ /\n/) {
1247 $full_line = "";
1248 }
1249 }
Steven Rostedta75fece2010-11-02 14:58:27 -04001250 print "** Monitor flushed **\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001251}
1252
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301253sub save_logs {
1254 my ($result, $basedir) = @_;
1255 my @t = localtime;
1256 my $date = sprintf "%04d%02d%02d%02d%02d%02d",
1257 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];
1258
1259 my $type = $build_type;
1260 if ($type =~ /useconfig/) {
1261 $type = "useconfig";
1262 }
1263
1264 my $dir = "$machine-$test_type-$type-$result-$date";
1265
1266 $dir = "$basedir/$dir";
1267
1268 if (!-d $dir) {
1269 mkpath($dir) or
1270 die "can't create $dir";
1271 }
1272
1273 my %files = (
1274 "config" => $output_config,
1275 "buildlog" => $buildlog,
1276 "dmesg" => $dmesg,
1277 "testlog" => $testlog,
1278 );
1279
1280 while (my ($name, $source) = each(%files)) {
1281 if (-f "$source") {
1282 cp "$source", "$dir/$name" or
1283 die "failed to copy $source";
1284 }
1285 }
1286
1287 doprint "*** Saved info to $dir ***\n";
1288}
1289
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001290sub fail {
1291
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001292 if (defined($post_test)) {
1293 run_command $post_test;
1294 }
1295
Steven Rostedta75fece2010-11-02 14:58:27 -04001296 if ($die_on_failure) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001297 dodie @_;
1298 }
1299
Steven Rostedta75fece2010-11-02 14:58:27 -04001300 doprint "FAILED\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001301
Steven Rostedt576f6272010-11-02 14:58:38 -04001302 my $i = $iteration;
1303
Steven Rostedta75fece2010-11-02 14:58:27 -04001304 # no need to reboot for just building.
Steven Rostedt576f6272010-11-02 14:58:38 -04001305 if (!do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001306 doprint "REBOOTING\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001307 reboot_to_good $sleep_time;
Steven Rostedta75fece2010-11-02 14:58:27 -04001308 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001309
Steven Rostedt9064af52011-06-13 10:38:48 -04001310 my $name = "";
1311
1312 if (defined($test_name)) {
1313 $name = " ($test_name)";
1314 }
1315
Steven Rostedt576f6272010-11-02 14:58:38 -04001316 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1317 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001318 doprint "KTEST RESULT: TEST $i$name Failed: ", @_, "\n";
Steven Rostedt576f6272010-11-02 14:58:38 -04001319 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
1320 doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
Steven Rostedta75fece2010-11-02 14:58:27 -04001321
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301322 if (defined($store_failures)) {
1323 save_logs "fail", $store_failures;
1324 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001325
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001326 return 1;
1327}
1328
Steven Rostedt2545eb62010-11-02 15:01:32 -04001329sub run_command {
1330 my ($command) = @_;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001331 my $dolog = 0;
1332 my $dord = 0;
1333 my $pid;
1334
Steven Rostedte48c5292010-11-02 14:35:37 -04001335 $command =~ s/\$SSH_USER/$ssh_user/g;
1336 $command =~ s/\$MACHINE/$machine/g;
1337
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001338 doprint("$command ... ");
1339
1340 $pid = open(CMD, "$command 2>&1 |") or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001341 (fail "unable to exec $command" and return 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001342
1343 if (defined($opt{"LOG_FILE"})) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001344 open(LOG, ">>$opt{LOG_FILE}") or
1345 dodie "failed to write to log";
1346 $dolog = 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001347 }
1348
1349 if (defined($redirect)) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001350 open (RD, ">$redirect") or
1351 dodie "failed to write to redirect $redirect";
1352 $dord = 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001353 }
1354
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001355 while (<CMD>) {
1356 print LOG if ($dolog);
1357 print RD if ($dord);
1358 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001359
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001360 waitpid($pid, 0);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001361 my $failed = $?;
1362
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04001363 close(CMD);
1364 close(LOG) if ($dolog);
1365 close(RD) if ($dord);
1366
Steven Rostedt2545eb62010-11-02 15:01:32 -04001367 if ($failed) {
1368 doprint "FAILED!\n";
1369 } else {
1370 doprint "SUCCESS\n";
1371 }
1372
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001373 return !$failed;
1374}
1375
Steven Rostedte48c5292010-11-02 14:35:37 -04001376sub run_ssh {
1377 my ($cmd) = @_;
1378 my $cp_exec = $ssh_exec;
1379
1380 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
1381 return run_command "$cp_exec";
1382}
1383
1384sub run_scp {
Steven Rostedt02ad2612012-03-21 08:21:24 -04001385 my ($src, $dst, $cp_scp) = @_;
Steven Rostedte48c5292010-11-02 14:35:37 -04001386
1387 $cp_scp =~ s/\$SRC_FILE/$src/g;
1388 $cp_scp =~ s/\$DST_FILE/$dst/g;
1389
1390 return run_command "$cp_scp";
1391}
1392
Steven Rostedt02ad2612012-03-21 08:21:24 -04001393sub run_scp_install {
1394 my ($src, $dst) = @_;
1395
1396 my $cp_scp = $scp_to_target_install;
1397
1398 return run_scp($src, $dst, $cp_scp);
1399}
1400
1401sub run_scp_mod {
1402 my ($src, $dst) = @_;
1403
1404 my $cp_scp = $scp_to_target;
1405
1406 return run_scp($src, $dst, $cp_scp);
1407}
1408
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001409sub get_grub_index {
1410
Steven Rostedta75fece2010-11-02 14:58:27 -04001411 if ($reboot_type ne "grub") {
1412 return;
1413 }
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001414 return if (defined($grub_number));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001415
1416 doprint "Find grub menu ... ";
1417 $grub_number = -1;
Steven Rostedte48c5292010-11-02 14:35:37 -04001418
1419 my $ssh_grub = $ssh_exec;
1420 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
1421
1422 open(IN, "$ssh_grub |")
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001423 or die "unable to get menu.lst";
Steven Rostedte48c5292010-11-02 14:35:37 -04001424
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001425 my $found = 0;
1426
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001427 while (<IN>) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001428 if (/^\s*title\s+$grub_menu\s*$/) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001429 $grub_number++;
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001430 $found = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001431 last;
1432 } elsif (/^\s*title\s/) {
1433 $grub_number++;
1434 }
1435 }
1436 close(IN);
1437
Steven Rostedta75fece2010-11-02 14:58:27 -04001438 die "Could not find '$grub_menu' in /boot/grub/menu on $machine"
Steven Rostedteaa1fe22011-09-14 17:20:39 -04001439 if (!$found);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001440 doprint "$grub_number\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001441}
1442
Steven Rostedt2545eb62010-11-02 15:01:32 -04001443sub wait_for_input
1444{
1445 my ($fp, $time) = @_;
1446 my $rin;
1447 my $ready;
1448 my $line;
1449 my $ch;
1450
1451 if (!defined($time)) {
1452 $time = $timeout;
1453 }
1454
1455 $rin = '';
1456 vec($rin, fileno($fp), 1) = 1;
1457 $ready = select($rin, undef, undef, $time);
1458
1459 $line = "";
1460
1461 # try to read one char at a time
1462 while (sysread $fp, $ch, 1) {
1463 $line .= $ch;
1464 last if ($ch eq "\n");
1465 }
1466
1467 if (!length($line)) {
1468 return undef;
1469 }
1470
1471 return $line;
1472}
1473
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001474sub reboot_to {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001475 if (defined($switch_to_test)) {
1476 run_command $switch_to_test;
1477 }
1478
Steven Rostedta75fece2010-11-02 14:58:27 -04001479 if ($reboot_type eq "grub") {
Steven Rostedtc54367f2011-10-20 09:56:41 -04001480 run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001481 } elsif (defined $reboot_script) {
1482 run_command "$reboot_script";
Steven Rostedta75fece2010-11-02 14:58:27 -04001483 }
Steven Rostedt96f6a0d2011-12-23 00:24:51 -05001484 reboot;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001485}
1486
Steven Rostedta57419b2010-11-02 15:13:54 -04001487sub get_sha1 {
1488 my ($commit) = @_;
1489
1490 doprint "git rev-list --max-count=1 $commit ... ";
1491 my $sha1 = `git rev-list --max-count=1 $commit`;
1492 my $ret = $?;
1493
1494 logit $sha1;
1495
1496 if ($ret) {
1497 doprint "FAILED\n";
1498 dodie "Failed to get git $commit";
1499 }
1500
1501 print "SUCCESS\n";
1502
1503 chomp $sha1;
1504
1505 return $sha1;
1506}
1507
Steven Rostedt5a391fb2010-11-02 14:57:43 -04001508sub monitor {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001509 my $booted = 0;
1510 my $bug = 0;
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001511 my $bug_ignored = 0;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001512 my $skip_call_trace = 0;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001513 my $loops;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001514
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001515 wait_for_monitor 5;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001516
1517 my $line;
1518 my $full_line = "";
1519
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001520 open(DMESG, "> $dmesg") or
1521 die "unable to write to $dmesg";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001522
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001523 reboot_to;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001524
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001525 my $success_start;
1526 my $failure_start;
Steven Rostedt2d01b262011-03-08 09:47:54 -05001527 my $monitor_start = time;
1528 my $done = 0;
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001529 my $version_found = 0;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001530
Steven Rostedt2d01b262011-03-08 09:47:54 -05001531 while (!$done) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001532
Steven Rostedtecaf8e52011-06-13 10:48:10 -04001533 if ($bug && defined($stop_after_failure) &&
1534 $stop_after_failure >= 0) {
1535 my $time = $stop_after_failure - (time - $failure_start);
1536 $line = wait_for_input($monitor_fp, $time);
1537 if (!defined($line)) {
1538 doprint "bug timed out after $booted_timeout seconds\n";
1539 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1540 last;
1541 }
1542 } elsif ($booted) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001543 $line = wait_for_input($monitor_fp, $booted_timeout);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001544 if (!defined($line)) {
1545 my $s = $booted_timeout == 1 ? "" : "s";
1546 doprint "Successful boot found: break after $booted_timeout second$s\n";
1547 last;
1548 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001549 } else {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001550 $line = wait_for_input($monitor_fp);
Steven Rostedtcd4f1d52011-06-13 10:26:27 -04001551 if (!defined($line)) {
1552 my $s = $timeout == 1 ? "" : "s";
1553 doprint "Timed out after $timeout second$s\n";
1554 last;
1555 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001556 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001557
Steven Rostedt2545eb62010-11-02 15:01:32 -04001558 doprint $line;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001559 print DMESG $line;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001560
1561 # we are not guaranteed to get a full line
1562 $full_line .= $line;
1563
Steven Rostedta75fece2010-11-02 14:58:27 -04001564 if ($full_line =~ /$success_line/) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04001565 $booted = 1;
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001566 $success_start = time;
1567 }
1568
1569 if ($booted && defined($stop_after_success) &&
1570 $stop_after_success >= 0) {
1571 my $now = time;
1572 if ($now - $success_start >= $stop_after_success) {
1573 doprint "Test forced to stop after $stop_after_success seconds after success\n";
1574 last;
1575 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001576 }
1577
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001578 if ($full_line =~ /\[ backtrace testing \]/) {
1579 $skip_call_trace = 1;
1580 }
1581
Steven Rostedt2545eb62010-11-02 15:01:32 -04001582 if ($full_line =~ /call trace:/i) {
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001583 if (!$bug && !$skip_call_trace) {
1584 if ($ignore_errors) {
1585 $bug_ignored = 1;
1586 } else {
1587 $bug = 1;
1588 $failure_start = time;
1589 }
Steven Rostedt1c8a6172010-11-09 12:55:40 -05001590 }
1591 }
1592
1593 if ($bug && defined($stop_after_failure) &&
1594 $stop_after_failure >= 0) {
1595 my $now = time;
1596 if ($now - $failure_start >= $stop_after_failure) {
1597 doprint "Test forced to stop after $stop_after_failure seconds after failure\n";
1598 last;
1599 }
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001600 }
1601
1602 if ($full_line =~ /\[ end of backtrace testing \]/) {
1603 $skip_call_trace = 0;
1604 }
1605
1606 if ($full_line =~ /Kernel panic -/) {
Steven Rostedt10abf112011-03-07 13:21:00 -05001607 $failure_start = time;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001608 $bug = 1;
1609 }
1610
Steven Rostedtf1a5b962011-06-13 10:30:00 -04001611 # Detect triple faults by testing the banner
1612 if ($full_line =~ /\bLinux version (\S+).*\n/) {
1613 if ($1 eq $version) {
1614 $version_found = 1;
1615 } elsif ($version_found && $detect_triplefault) {
1616 # We already booted into the kernel we are testing,
1617 # but now we booted into another kernel?
1618 # Consider this a triple fault.
1619 doprint "Aleady booted in Linux kernel $version, but now\n";
1620 doprint "we booted into Linux kernel $1.\n";
1621 doprint "Assuming that this is a triple fault.\n";
1622 doprint "To disable this: set DETECT_TRIPLE_FAULT to 0\n";
1623 last;
1624 }
1625 }
1626
Steven Rostedt2545eb62010-11-02 15:01:32 -04001627 if ($line =~ /\n/) {
1628 $full_line = "";
1629 }
Steven Rostedt2d01b262011-03-08 09:47:54 -05001630
1631 if ($stop_test_after > 0 && !$booted && !$bug) {
1632 if (time - $monitor_start > $stop_test_after) {
Steven Rostedt4d62bf52011-05-20 09:14:35 -04001633 doprint "STOP_TEST_AFTER ($stop_test_after seconds) timed out\n";
Steven Rostedt2d01b262011-03-08 09:47:54 -05001634 $done = 1;
1635 }
1636 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001637 }
1638
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001639 close(DMESG);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001640
Steven Rostedt2545eb62010-11-02 15:01:32 -04001641 if ($bug) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001642 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001643 fail "failed - got a bug report" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001644 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001645
Steven Rostedta75fece2010-11-02 14:58:27 -04001646 if (!$booted) {
1647 return 0 if ($in_bisect);
Steven Rostedt576f6272010-11-02 14:58:38 -04001648 fail "failed - never got a boot prompt." and return 0;
Steven Rostedta75fece2010-11-02 14:58:27 -04001649 }
1650
Steven Rostedt6ca996c2012-03-21 08:18:35 -04001651 if ($bug_ignored) {
1652 doprint "WARNING: Call Trace detected but ignored due to IGNORE_ERRORS=1\n";
1653 }
1654
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001655 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001656}
1657
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001658sub eval_kernel_version {
1659 my ($option) = @_;
1660
1661 $option =~ s/\$KERNEL_VERSION/$version/g;
1662
1663 return $option;
1664}
1665
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001666sub do_post_install {
1667
1668 return if (!defined($post_install));
1669
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001670 my $cp_post_install = eval_kernel_version $post_install;
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001671 run_command "$cp_post_install" or
1672 dodie "Failed to run post install";
1673}
1674
Steven Rostedt2545eb62010-11-02 15:01:32 -04001675sub install {
1676
Steven Rostedte0a87422011-09-30 17:50:48 -04001677 return if ($no_install);
1678
Steven Rostedte5c2ec12012-07-19 15:22:05 -04001679 if (defined($pre_install)) {
1680 my $cp_pre_install = eval_kernel_version $pre_install;
1681 run_command "$cp_pre_install" or
1682 dodie "Failed to run pre install";
1683 }
1684
Steven Rostedt2b29b2f2011-12-22 11:25:46 -05001685 my $cp_target = eval_kernel_version $target_image;
1686
Steven Rostedt02ad2612012-03-21 08:21:24 -04001687 run_scp_install "$outputdir/$build_target", "$cp_target" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001688 dodie "failed to copy image";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001689
1690 my $install_mods = 0;
1691
1692 # should we process modules?
1693 $install_mods = 0;
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001694 open(IN, "$output_config") or dodie("Can't read config file");
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001695 while (<IN>) {
1696 if (/CONFIG_MODULES(=y)?/) {
1697 $install_mods = 1 if (defined($1));
1698 last;
1699 }
1700 }
1701 close(IN);
1702
1703 if (!$install_mods) {
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001704 do_post_install;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001705 doprint "No modules needed\n";
1706 return;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001707 }
1708
Steven Rostedt627977d2012-03-21 08:16:15 -04001709 run_command "$make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$tmpdir modules_install" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001710 dodie "Failed to install modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001711
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001712 my $modlib = "/lib/modules/$version";
Steven Rostedta57419b2010-11-02 15:13:54 -04001713 my $modtar = "ktest-mods.tar.bz2";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001714
Steven Rostedte48c5292010-11-02 14:35:37 -04001715 run_ssh "rm -rf $modlib" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001716 dodie "failed to remove old mods: $modlib";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001717
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001718 # would be nice if scp -r did not follow symbolic links
Steven Rostedta75fece2010-11-02 14:58:27 -04001719 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001720 dodie "making tarball";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001721
Steven Rostedt02ad2612012-03-21 08:21:24 -04001722 run_scp_mod "$tmpdir/$modtar", "/tmp" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001723 dodie "failed to copy modules";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001724
Steven Rostedta75fece2010-11-02 14:58:27 -04001725 unlink "$tmpdir/$modtar";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001726
Steven Rostedte7b13442011-06-14 20:44:36 -04001727 run_ssh "'(cd / && tar xjf /tmp/$modtar)'" or
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001728 dodie "failed to tar modules";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001729
Steven Rostedte48c5292010-11-02 14:35:37 -04001730 run_ssh "rm -f /tmp/$modtar";
Steven Rostedt8b37ca82010-11-02 14:58:33 -04001731
Steven Rostedtdb05cfe2011-06-13 11:09:22 -04001732 do_post_install;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001733}
1734
Steven Rostedtddf607e2011-06-14 20:49:13 -04001735sub get_version {
1736 # get the release name
Steven Rostedt683a3e62012-05-18 13:34:35 -04001737 return if ($have_version);
Steven Rostedtddf607e2011-06-14 20:49:13 -04001738 doprint "$make kernelrelease ... ";
1739 $version = `$make kernelrelease | tail -1`;
1740 chomp($version);
1741 doprint "$version\n";
Steven Rostedt683a3e62012-05-18 13:34:35 -04001742 $have_version = 1;
Steven Rostedtddf607e2011-06-14 20:49:13 -04001743}
1744
1745sub start_monitor_and_boot {
Steven Rostedt9f7424c2011-10-22 08:58:19 -04001746 # Make sure the stable kernel has finished booting
1747 start_monitor;
1748 wait_for_monitor 5;
1749 end_monitor;
1750
Steven Rostedtddf607e2011-06-14 20:49:13 -04001751 get_grub_index;
1752 get_version;
1753 install;
1754
1755 start_monitor;
1756 return monitor;
1757}
1758
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001759sub check_buildlog {
1760 my ($patch) = @_;
1761
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001762 my @files = `git show $patch | diffstat -l`;
1763
1764 open(IN, "git show $patch |") or
1765 dodie "failed to show $patch";
1766 while (<IN>) {
1767 if (m,^--- a/(.*),) {
1768 chomp $1;
1769 $files[$#files] = $1;
1770 }
1771 }
1772 close(IN);
1773
1774 open(IN, $buildlog) or dodie "Can't open $buildlog";
1775 while (<IN>) {
1776 if (/^\s*(.*?):.*(warning|error)/) {
1777 my $err = $1;
1778 foreach my $file (@files) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001779 my $fullpath = "$builddir/$file";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001780 if ($file eq $err || $fullpath eq $err) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001781 fail "$file built with warnings" and return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001782 }
1783 }
1784 }
1785 }
1786 close(IN);
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001787
1788 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04001789}
1790
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001791sub apply_min_config {
1792 my $outconfig = "$output_config.new";
Steven Rostedt612b9e92011-03-07 13:27:43 -05001793
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001794 # Read the config file and remove anything that
1795 # is in the force_config hash (from minconfig and others)
1796 # then add the force config back.
1797
1798 doprint "Applying minimum configurations into $output_config.new\n";
1799
1800 open (OUT, ">$outconfig") or
1801 dodie "Can't create $outconfig";
1802
1803 if (-f $output_config) {
1804 open (IN, $output_config) or
1805 dodie "Failed to open $output_config";
1806 while (<IN>) {
1807 if (/^(# )?(CONFIG_[^\s=]*)/) {
1808 next if (defined($force_config{$2}));
1809 }
1810 print OUT;
1811 }
1812 close IN;
1813 }
1814 foreach my $config (keys %force_config) {
1815 print OUT "$force_config{$config}\n";
1816 }
1817 close OUT;
1818
1819 run_command "mv $outconfig $output_config";
1820}
1821
1822sub make_oldconfig {
1823
Steven Rostedt4c4ab122011-07-15 21:16:17 -04001824 my @force_list = keys %force_config;
1825
1826 if ($#force_list >= 0) {
1827 apply_min_config;
1828 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001829
1830 if (!run_command "$make oldnoconfig") {
Steven Rostedt612b9e92011-03-07 13:27:43 -05001831 # Perhaps oldnoconfig doesn't exist in this version of the kernel
1832 # try a yes '' | oldconfig
1833 doprint "oldnoconfig failed, trying yes '' | make oldconfig\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001834 run_command "yes '' | $make oldconfig" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001835 dodie "failed make config oldconfig";
1836 }
1837}
1838
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001839# read a config file and use this to force new configs.
1840sub load_force_config {
1841 my ($config) = @_;
1842
Steven Rostedtcf79fab2012-07-19 15:29:43 -04001843 doprint "Loading force configs from $config\n";
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001844 open(IN, $config) or
1845 dodie "failed to read $config";
1846 while (<IN>) {
1847 chomp;
1848 if (/^(CONFIG[^\s=]*)(\s*=.*)/) {
1849 $force_config{$1} = $_;
1850 } elsif (/^# (CONFIG_\S*) is not set/) {
1851 $force_config{$1} = $_;
1852 }
1853 }
1854 close IN;
1855}
1856
Steven Rostedt2545eb62010-11-02 15:01:32 -04001857sub build {
1858 my ($type) = @_;
1859
Steven Rostedt7faafbd2010-11-02 14:58:22 -04001860 unlink $buildlog;
1861
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001862 # Failed builds should not reboot the target
1863 my $save_no_reboot = $no_reboot;
1864 $no_reboot = 1;
1865
Steven Rostedt683a3e62012-05-18 13:34:35 -04001866 # Calculate a new version from here.
1867 $have_version = 0;
1868
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001869 if (defined($pre_build)) {
1870 my $ret = run_command $pre_build;
1871 if (!$ret && defined($pre_build_die) &&
1872 $pre_build_die) {
1873 dodie "failed to pre_build\n";
1874 }
1875 }
1876
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001877 if ($type =~ /^useconfig:(.*)/) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001878 run_command "cp $1 $output_config" or
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001879 dodie "could not copy $1 to .config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001880
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001881 $type = "oldconfig";
1882 }
1883
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001884 # old config can ask questions
1885 if ($type eq "oldconfig") {
Steven Rostedt9386c6a2010-11-08 16:35:48 -05001886 $type = "oldnoconfig";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001887
1888 # allow for empty configs
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001889 run_command "touch $output_config";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001890
Andrew Jones13488232011-08-12 15:32:04 +02001891 if (!$noclean) {
1892 run_command "mv $output_config $outputdir/config_temp" or
1893 dodie "moving .config";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001894
Andrew Jones13488232011-08-12 15:32:04 +02001895 run_command "$make mrproper" or dodie "make mrproper";
1896
1897 run_command "mv $outputdir/config_temp $output_config" or
1898 dodie "moving config_temp";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001899 }
1900
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001901 } elsif (!$noclean) {
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05001902 unlink "$output_config";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001903 run_command "$make mrproper" or
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001904 dodie "make mrproper";
Steven Rostedt5c42fc52010-11-02 14:57:01 -04001905 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04001906
1907 # add something to distinguish this build
Steven Rostedta75fece2010-11-02 14:58:27 -04001908 open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");
1909 print OUT "$localversion\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04001910 close(OUT);
1911
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001912 if (defined($minconfig)) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001913 load_force_config($minconfig);
Steven Rostedt2545eb62010-11-02 15:01:32 -04001914 }
1915
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001916 if ($type ne "oldnoconfig") {
1917 run_command "$make $type" or
Steven Rostedt612b9e92011-03-07 13:27:43 -05001918 dodie "failed make config";
1919 }
Steven Rostedtfcb3f162011-06-13 10:40:58 -04001920 # Run old config regardless, to enforce min configurations
1921 make_oldconfig;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001922
Steven Rostedta75fece2010-11-02 14:58:27 -04001923 $redirect = "$buildlog";
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001924 my $build_ret = run_command "$make $build_options";
1925 undef $redirect;
1926
1927 if (defined($post_build)) {
Steven Rostedt683a3e62012-05-18 13:34:35 -04001928 # Because a post build may change the kernel version
1929 # do it now.
1930 get_version;
Steven Rostedt0bd6c1a2011-06-14 20:39:31 -04001931 my $ret = run_command $post_build;
1932 if (!$ret && defined($post_build_die) &&
1933 $post_build_die) {
1934 dodie "failed to post_build\n";
1935 }
1936 }
1937
1938 if (!$build_ret) {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001939 # bisect may need this to pass
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001940 if ($in_bisect) {
1941 $no_reboot = $save_no_reboot;
1942 return 0;
1943 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001944 fail "failed build" and return 0;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001945 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001946
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04001947 $no_reboot = $save_no_reboot;
1948
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04001949 return 1;
Steven Rostedt2545eb62010-11-02 15:01:32 -04001950}
1951
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001952sub halt {
Steven Rostedte48c5292010-11-02 14:35:37 -04001953 if (!run_ssh "halt" or defined($power_off)) {
Steven Rostedt576f6272010-11-02 14:58:38 -04001954 if (defined($poweroff_after_halt)) {
1955 sleep $poweroff_after_halt;
1956 run_command "$power_off";
1957 }
1958 } else {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001959 # nope? the zap it!
Steven Rostedta75fece2010-11-02 14:58:27 -04001960 run_command "$power_off";
Steven Rostedt75c3fda72010-11-02 14:57:21 -04001961 }
1962}
1963
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001964sub success {
1965 my ($i) = @_;
1966
Steven Rostedt921ed4c2012-07-19 15:18:27 -04001967 if (defined($post_test)) {
1968 run_command $post_test;
1969 }
1970
Steven Rostedte48c5292010-11-02 14:35:37 -04001971 $successes++;
1972
Steven Rostedt9064af52011-06-13 10:38:48 -04001973 my $name = "";
1974
1975 if (defined($test_name)) {
1976 $name = " ($test_name)";
1977 }
1978
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001979 doprint "\n\n*******************************************\n";
1980 doprint "*******************************************\n";
Steven Rostedt9064af52011-06-13 10:38:48 -04001981 doprint "KTEST RESULT: TEST $i$name SUCCESS!!!! **\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001982 doprint "*******************************************\n";
1983 doprint "*******************************************\n";
1984
Rabin Vincentde5b6e32011-11-18 17:05:31 +05301985 if (defined($store_successes)) {
1986 save_logs "success", $store_successes;
1987 }
1988
Steven Rostedt576f6272010-11-02 14:58:38 -04001989 if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {
Steven Rostedta75fece2010-11-02 14:58:27 -04001990 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05001991 reboot_to_good $sleep_time;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04001992 }
1993}
1994
Steven Rostedtc960bb92011-03-08 09:22:39 -05001995sub answer_bisect {
1996 for (;;) {
1997 doprint "Pass or fail? [p/f]";
1998 my $ans = <STDIN>;
1999 chomp $ans;
2000 if ($ans eq "p" || $ans eq "P") {
2001 return 1;
2002 } elsif ($ans eq "f" || $ans eq "F") {
2003 return 0;
2004 } else {
2005 print "Please answer 'P' or 'F'\n";
2006 }
2007 }
2008}
2009
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002010sub child_run_test {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002011 my $failed = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002012
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002013 # child should have no power
Steven Rostedta75fece2010-11-02 14:58:27 -04002014 $reboot_on_error = 0;
2015 $poweroff_on_error = 0;
2016 $die_on_failure = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002017
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302018 $redirect = "$testlog";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002019 run_command $run_test or $failed = 1;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05302020 undef $redirect;
2021
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002022 exit $failed;
2023}
2024
2025my $child_done;
2026
2027sub child_finished {
2028 $child_done = 1;
2029}
2030
2031sub do_run_test {
2032 my $child_pid;
2033 my $child_exit;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002034 my $line;
2035 my $full_line;
2036 my $bug = 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002037
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002038 wait_for_monitor 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002039
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002040 doprint "run test $run_test\n";
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002041
2042 $child_done = 0;
2043
2044 $SIG{CHLD} = qw(child_finished);
2045
2046 $child_pid = fork;
2047
2048 child_run_test if (!$child_pid);
2049
2050 $full_line = "";
2051
2052 do {
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002053 $line = wait_for_input($monitor_fp, 1);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002054 if (defined($line)) {
2055
2056 # we are not guaranteed to get a full line
2057 $full_line .= $line;
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002058 doprint $line;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002059
2060 if ($full_line =~ /call trace:/i) {
2061 $bug = 1;
2062 }
2063
2064 if ($full_line =~ /Kernel panic -/) {
2065 $bug = 1;
2066 }
2067
2068 if ($line =~ /\n/) {
2069 $full_line = "";
2070 }
2071 }
2072 } while (!$child_done && !$bug);
2073
2074 if ($bug) {
Steven Rostedt8ea0e062011-03-08 09:44:35 -05002075 my $failure_start = time;
2076 my $now;
2077 do {
2078 $line = wait_for_input($monitor_fp, 1);
2079 if (defined($line)) {
2080 doprint $line;
2081 }
2082 $now = time;
2083 if ($now - $failure_start >= $stop_after_failure) {
2084 last;
2085 }
2086 } while (defined($line));
2087
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002088 doprint "Detected kernel crash!\n";
2089 # kill the child with extreme prejudice
2090 kill 9, $child_pid;
2091 }
2092
2093 waitpid $child_pid, 0;
2094 $child_exit = $?;
2095
Steven Rostedtc5dacb82011-12-22 12:43:57 -05002096 if (!$bug && $in_bisect) {
2097 if (defined($bisect_ret_good)) {
2098 if ($child_exit == $bisect_ret_good) {
2099 return 1;
2100 }
2101 }
2102 if (defined($bisect_ret_skip)) {
2103 if ($child_exit == $bisect_ret_skip) {
2104 return -1;
2105 }
2106 }
2107 if (defined($bisect_ret_abort)) {
2108 if ($child_exit == $bisect_ret_abort) {
2109 fail "test abort" and return -2;
2110 }
2111 }
2112 if (defined($bisect_ret_bad)) {
2113 if ($child_exit == $bisect_ret_skip) {
2114 return 0;
2115 }
2116 }
2117 if (defined($bisect_ret_default)) {
2118 if ($bisect_ret_default eq "good") {
2119 return 1;
2120 } elsif ($bisect_ret_default eq "bad") {
2121 return 0;
2122 } elsif ($bisect_ret_default eq "skip") {
2123 return -1;
2124 } elsif ($bisect_ret_default eq "abort") {
2125 return -2;
2126 } else {
2127 fail "unknown default action: $bisect_ret_default"
2128 and return -2;
2129 }
2130 }
2131 }
2132
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002133 if ($bug || $child_exit) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002134 return 0 if $in_bisect;
2135 fail "test failed" and return 0;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002136 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002137 return 1;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002138}
2139
Steven Rostedta75fece2010-11-02 14:58:27 -04002140sub run_git_bisect {
2141 my ($command) = @_;
2142
2143 doprint "$command ... ";
2144
2145 my $output = `$command 2>&1`;
2146 my $ret = $?;
2147
2148 logit $output;
2149
2150 if ($ret) {
2151 doprint "FAILED\n";
2152 dodie "Failed to git bisect";
2153 }
2154
2155 doprint "SUCCESS\n";
2156 if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {
2157 doprint "$1 [$2]\n";
2158 } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002159 $bisect_bad_commit = $1;
Steven Rostedta75fece2010-11-02 14:58:27 -04002160 doprint "Found bad commit... $1\n";
2161 return 0;
2162 } else {
2163 # we already logged it, just print it now.
2164 print $output;
2165 }
2166
2167 return 1;
2168}
2169
Steven Rostedtc23dca72011-03-08 09:26:31 -05002170sub bisect_reboot {
2171 doprint "Reboot and sleep $bisect_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002172 reboot_to_good $bisect_sleep_time;
Steven Rostedtc23dca72011-03-08 09:26:31 -05002173}
2174
2175# returns 1 on success, 0 on failure, -1 on skip
Steven Rostedt0a05c762010-11-08 11:14:10 -05002176sub run_bisect_test {
2177 my ($type, $buildtype) = @_;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002178
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002179 my $failed = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002180 my $result;
2181 my $output;
2182 my $ret;
2183
Steven Rostedt0a05c762010-11-08 11:14:10 -05002184 $in_bisect = 1;
2185
2186 build $buildtype or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002187
2188 if ($type ne "build") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002189 if ($failed && $bisect_skip) {
2190 $in_bisect = 0;
2191 return -1;
2192 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002193 dodie "Failed on build" if $failed;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002194
2195 # Now boot the box
Steven Rostedtddf607e2011-06-14 20:49:13 -04002196 start_monitor_and_boot or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002197
2198 if ($type ne "boot") {
Steven Rostedtc23dca72011-03-08 09:26:31 -05002199 if ($failed && $bisect_skip) {
2200 end_monitor;
2201 bisect_reboot;
2202 $in_bisect = 0;
2203 return -1;
2204 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002205 dodie "Failed on boot" if $failed;
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002206
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002207 do_run_test or $failed = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002208 }
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002209 end_monitor;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002210 }
2211
2212 if ($failed) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002213 $result = 0;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002214 } else {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002215 $result = 1;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002216 }
Steven Rostedt4025bc62011-05-20 09:16:29 -04002217
2218 # reboot the box to a kernel we can ssh to
2219 if ($type ne "build") {
2220 bisect_reboot;
2221 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002222 $in_bisect = 0;
2223
2224 return $result;
2225}
2226
2227sub run_bisect {
2228 my ($type) = @_;
2229 my $buildtype = "oldconfig";
2230
2231 # We should have a minconfig to use?
2232 if (defined($minconfig)) {
2233 $buildtype = "useconfig:$minconfig";
2234 }
2235
2236 my $ret = run_bisect_test $type, $buildtype;
2237
Steven Rostedtc960bb92011-03-08 09:22:39 -05002238 if ($bisect_manual) {
2239 $ret = answer_bisect;
2240 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002241
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002242 # Are we looking for where it worked, not failed?
Russ Dill5158ba3e2012-04-23 19:43:00 -07002243 if ($reverse_bisect && $ret >= 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002244 $ret = !$ret;
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002245 }
2246
Steven Rostedtc23dca72011-03-08 09:26:31 -05002247 if ($ret > 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002248 return "good";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002249 } elsif ($ret == 0) {
Steven Rostedt0a05c762010-11-08 11:14:10 -05002250 return "bad";
Steven Rostedtc23dca72011-03-08 09:26:31 -05002251 } elsif ($bisect_skip) {
2252 doprint "HIT A BAD COMMIT ... SKIPPING\n";
2253 return "skip";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002254 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002255}
2256
Steven Rostedtdad98752011-11-22 20:48:57 -05002257sub update_bisect_replay {
2258 my $tmp_log = "$tmpdir/ktest_bisect_log";
2259 run_command "git bisect log > $tmp_log" or
2260 die "can't create bisect log";
2261 return $tmp_log;
2262}
2263
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002264sub bisect {
2265 my ($i) = @_;
2266
2267 my $result;
2268
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002269 die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good));
2270 die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad));
2271 die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type));
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002272
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002273 my $good = $bisect_good;
2274 my $bad = $bisect_bad;
2275 my $type = $bisect_type;
2276 my $start = $bisect_start;
2277 my $replay = $bisect_replay;
2278 my $start_files = $bisect_files;
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002279
2280 if (defined($start_files)) {
2281 $start_files = " -- " . $start_files;
2282 } else {
2283 $start_files = "";
2284 }
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002285
Steven Rostedta57419b2010-11-02 15:13:54 -04002286 # convert to true sha1's
2287 $good = get_sha1($good);
2288 $bad = get_sha1($bad);
2289
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002290 if (defined($bisect_reverse) && $bisect_reverse == 1) {
Steven Rostedtd6ce2a02010-11-02 14:58:05 -04002291 doprint "Performing a reverse bisect (bad is good, good is bad!)\n";
2292 $reverse_bisect = 1;
2293 } else {
2294 $reverse_bisect = 0;
2295 }
2296
Steven Rostedt5a391fb2010-11-02 14:57:43 -04002297 # Can't have a test without having a test to run
2298 if ($type eq "test" && !defined($run_test)) {
2299 $type = "boot";
2300 }
2301
Steven Rostedtdad98752011-11-22 20:48:57 -05002302 # Check if a bisect was running
2303 my $bisect_start_file = "$builddir/.git/BISECT_START";
2304
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002305 my $check = $bisect_check;
Steven Rostedtdad98752011-11-22 20:48:57 -05002306 my $do_check = defined($check) && $check ne "0";
2307
2308 if ( -f $bisect_start_file ) {
2309 print "Bisect in progress found\n";
2310 if ($do_check) {
2311 print " If you say yes, then no checks of good or bad will be done\n";
2312 }
2313 if (defined($replay)) {
2314 print "** BISECT_REPLAY is defined in config file **";
2315 print " Ignore config option and perform new git bisect log?\n";
2316 if (read_ync " (yes, no, or cancel) ") {
2317 $replay = update_bisect_replay;
2318 $do_check = 0;
2319 }
2320 } elsif (read_yn "read git log and continue?") {
2321 $replay = update_bisect_replay;
2322 $do_check = 0;
2323 }
2324 }
2325
2326 if ($do_check) {
Steven Rostedta75fece2010-11-02 14:58:27 -04002327
2328 # get current HEAD
Steven Rostedta57419b2010-11-02 15:13:54 -04002329 my $head = get_sha1("HEAD");
Steven Rostedta75fece2010-11-02 14:58:27 -04002330
2331 if ($check ne "good") {
2332 doprint "TESTING BISECT BAD [$bad]\n";
2333 run_command "git checkout $bad" or
2334 die "Failed to checkout $bad";
2335
2336 $result = run_bisect $type;
2337
2338 if ($result ne "bad") {
2339 fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;
2340 }
2341 }
2342
2343 if ($check ne "bad") {
2344 doprint "TESTING BISECT GOOD [$good]\n";
2345 run_command "git checkout $good" or
2346 die "Failed to checkout $good";
2347
2348 $result = run_bisect $type;
2349
2350 if ($result ne "good") {
2351 fail "Tested BISECT_GOOD [$good] and it failed" and return 0;
2352 }
2353 }
2354
2355 # checkout where we started
2356 run_command "git checkout $head" or
2357 die "Failed to checkout $head";
2358 }
2359
Steven Rostedt3410f6f2011-03-08 09:38:12 -05002360 run_command "git bisect start$start_files" or
Steven Rostedta75fece2010-11-02 14:58:27 -04002361 dodie "could not start bisect";
2362
2363 run_command "git bisect good $good" or
2364 dodie "could not set bisect good to $good";
2365
2366 run_git_bisect "git bisect bad $bad" or
2367 dodie "could not set bisect bad to $bad";
2368
2369 if (defined($replay)) {
2370 run_command "git bisect replay $replay" or
2371 dodie "failed to run replay";
2372 }
2373
2374 if (defined($start)) {
2375 run_command "git checkout $start" or
2376 dodie "failed to checkout $start";
2377 }
2378
2379 my $test;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002380 do {
2381 $result = run_bisect $type;
Steven Rostedta75fece2010-11-02 14:58:27 -04002382 $test = run_git_bisect "git bisect $result";
2383 } while ($test);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002384
2385 run_command "git bisect log" or
2386 dodie "could not capture git bisect log";
2387
2388 run_command "git bisect reset" or
2389 dodie "could not reset git bisect";
2390
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002391 doprint "Bad commit was [$bisect_bad_commit]\n";
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002392
Steven Rostedt0a05c762010-11-08 11:14:10 -05002393 success $i;
2394}
2395
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002396# config_ignore holds the configs that were set (or unset) for
2397# a good config and we will ignore these configs for the rest
2398# of a config bisect. These configs stay as they were.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002399my %config_ignore;
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002400
2401# config_set holds what all configs were set as.
Steven Rostedt0a05c762010-11-08 11:14:10 -05002402my %config_set;
2403
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002404# config_off holds the set of configs that the bad config had disabled.
2405# We need to record them and set them in the .config when running
2406# oldnoconfig, because oldnoconfig does not turn off new symbols, but
2407# instead just keeps the defaults.
2408my %config_off;
2409
2410# config_off_tmp holds a set of configs to turn off for now
2411my @config_off_tmp;
2412
2413# config_list is the set of configs that are being tested
Steven Rostedt0a05c762010-11-08 11:14:10 -05002414my %config_list;
2415my %null_config;
2416
2417my %dependency;
2418
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002419sub assign_configs {
2420 my ($hash, $config) = @_;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002421
2422 open (IN, $config)
2423 or dodie "Failed to read $config";
2424
2425 while (<IN>) {
Steven Rostedt9bf71742011-06-01 23:27:19 -04002426 if (/^((CONFIG\S*)=.*)/) {
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002427 ${$hash}{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002428 }
2429 }
2430
2431 close(IN);
2432}
2433
Steven Rostedt4c4ab122011-07-15 21:16:17 -04002434sub process_config_ignore {
2435 my ($config) = @_;
2436
2437 assign_configs \%config_ignore, $config;
2438}
2439
Steven Rostedt0a05c762010-11-08 11:14:10 -05002440sub read_current_config {
2441 my ($config_ref) = @_;
2442
2443 %{$config_ref} = ();
2444 undef %{$config_ref};
2445
2446 my @key = keys %{$config_ref};
2447 if ($#key >= 0) {
2448 print "did not delete!\n";
2449 exit;
2450 }
2451 open (IN, "$output_config");
2452
2453 while (<IN>) {
2454 if (/^(CONFIG\S+)=(.*)/) {
2455 ${$config_ref}{$1} = $2;
2456 }
2457 }
2458 close(IN);
2459}
2460
2461sub get_dependencies {
2462 my ($config) = @_;
2463
2464 my $arr = $dependency{$config};
2465 if (!defined($arr)) {
2466 return ();
2467 }
2468
2469 my @deps = @{$arr};
2470
2471 foreach my $dep (@{$arr}) {
2472 print "ADD DEP $dep\n";
2473 @deps = (@deps, get_dependencies $dep);
2474 }
2475
2476 return @deps;
2477}
2478
2479sub create_config {
2480 my @configs = @_;
2481
2482 open(OUT, ">$output_config") or dodie "Can not write to $output_config";
2483
2484 foreach my $config (@configs) {
2485 print OUT "$config_set{$config}\n";
2486 my @deps = get_dependencies $config;
2487 foreach my $dep (@deps) {
2488 print OUT "$config_set{$dep}\n";
2489 }
2490 }
2491
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002492 # turn off configs to keep off
2493 foreach my $config (keys %config_off) {
2494 print OUT "# $config is not set\n";
2495 }
2496
2497 # turn off configs that should be off for now
2498 foreach my $config (@config_off_tmp) {
2499 print OUT "# $config is not set\n";
2500 }
2501
Steven Rostedt0a05c762010-11-08 11:14:10 -05002502 foreach my $config (keys %config_ignore) {
2503 print OUT "$config_ignore{$config}\n";
2504 }
2505 close(OUT);
2506
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002507 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002508}
2509
2510sub compare_configs {
2511 my (%a, %b) = @_;
2512
2513 foreach my $item (keys %a) {
2514 if (!defined($b{$item})) {
2515 print "diff $item\n";
2516 return 1;
2517 }
2518 delete $b{$item};
2519 }
2520
2521 my @keys = keys %b;
2522 if ($#keys) {
2523 print "diff2 $keys[0]\n";
2524 }
2525 return -1 if ($#keys >= 0);
2526
2527 return 0;
2528}
2529
2530sub run_config_bisect_test {
2531 my ($type) = @_;
2532
2533 return run_bisect_test $type, "oldconfig";
2534}
2535
2536sub process_passed {
2537 my (%configs) = @_;
2538
2539 doprint "These configs had no failure: (Enabling them for further compiles)\n";
2540 # Passed! All these configs are part of a good compile.
2541 # Add them to the min options.
2542 foreach my $config (keys %configs) {
2543 if (defined($config_list{$config})) {
2544 doprint " removing $config\n";
2545 $config_ignore{$config} = $config_list{$config};
2546 delete $config_list{$config};
2547 }
2548 }
Steven Rostedtf1a27852010-11-11 11:34:38 -05002549 doprint "config copied to $outputdir/config_good\n";
2550 run_command "cp -f $output_config $outputdir/config_good";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002551}
2552
2553sub process_failed {
2554 my ($config) = @_;
2555
2556 doprint "\n\n***************************************\n";
2557 doprint "Found bad config: $config\n";
2558 doprint "***************************************\n\n";
2559}
2560
2561sub run_config_bisect {
2562
2563 my @start_list = keys %config_list;
2564
2565 if ($#start_list < 0) {
2566 doprint "No more configs to test!!!\n";
2567 return -1;
2568 }
2569
2570 doprint "***** RUN TEST ***\n";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002571 my $type = $config_bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002572 my $ret;
2573 my %current_config;
2574
2575 my $count = $#start_list + 1;
2576 doprint " $count configs to test\n";
2577
2578 my $half = int($#start_list / 2);
2579
2580 do {
2581 my @tophalf = @start_list[0 .. $half];
2582
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002583 # keep the bottom half off
2584 if ($half < $#start_list) {
2585 @config_off_tmp = @start_list[$half + 1 .. $#start_list];
2586 } else {
2587 @config_off_tmp = ();
2588 }
2589
Steven Rostedt0a05c762010-11-08 11:14:10 -05002590 create_config @tophalf;
2591 read_current_config \%current_config;
2592
2593 $count = $#tophalf + 1;
2594 doprint "Testing $count configs\n";
2595 my $found = 0;
2596 # make sure we test something
2597 foreach my $config (@tophalf) {
2598 if (defined($current_config{$config})) {
2599 logit " $config\n";
2600 $found = 1;
2601 }
2602 }
2603 if (!$found) {
2604 # try the other half
2605 doprint "Top half produced no set configs, trying bottom half\n";
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002606
2607 # keep the top half off
2608 @config_off_tmp = @tophalf;
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002609 @tophalf = @start_list[$half + 1 .. $#start_list];
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002610
Steven Rostedt0a05c762010-11-08 11:14:10 -05002611 create_config @tophalf;
2612 read_current_config \%current_config;
2613 foreach my $config (@tophalf) {
2614 if (defined($current_config{$config})) {
2615 logit " $config\n";
2616 $found = 1;
2617 }
2618 }
2619 if (!$found) {
2620 doprint "Failed: Can't make new config with current configs\n";
2621 foreach my $config (@start_list) {
2622 doprint " CONFIG: $config\n";
2623 }
2624 return -1;
2625 }
2626 $count = $#tophalf + 1;
2627 doprint "Testing $count configs\n";
2628 }
2629
2630 $ret = run_config_bisect_test $type;
Steven Rostedtc960bb92011-03-08 09:22:39 -05002631 if ($bisect_manual) {
2632 $ret = answer_bisect;
2633 }
Steven Rostedt0a05c762010-11-08 11:14:10 -05002634 if ($ret) {
2635 process_passed %current_config;
2636 return 0;
2637 }
2638
2639 doprint "This config had a failure.\n";
2640 doprint "Removing these configs that were not set in this config:\n";
Steven Rostedtf1a27852010-11-11 11:34:38 -05002641 doprint "config copied to $outputdir/config_bad\n";
2642 run_command "cp -f $output_config $outputdir/config_bad";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002643
2644 # A config exists in this group that was bad.
2645 foreach my $config (keys %config_list) {
2646 if (!defined($current_config{$config})) {
2647 doprint " removing $config\n";
2648 delete $config_list{$config};
2649 }
2650 }
2651
2652 @start_list = @tophalf;
2653
2654 if ($#start_list == 0) {
2655 process_failed $start_list[0];
2656 return 1;
2657 }
2658
2659 # remove half the configs we are looking at and see if
2660 # they are good.
2661 $half = int($#start_list / 2);
Steven Rostedt4c8cc552011-06-01 23:22:30 -04002662 } while ($#start_list > 0);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002663
Steven Rostedtc960bb92011-03-08 09:22:39 -05002664 # we found a single config, try it again unless we are running manually
2665
2666 if ($bisect_manual) {
2667 process_failed $start_list[0];
2668 return 1;
2669 }
2670
Steven Rostedt0a05c762010-11-08 11:14:10 -05002671 my @tophalf = @start_list[0 .. 0];
2672
2673 $ret = run_config_bisect_test $type;
2674 if ($ret) {
2675 process_passed %current_config;
2676 return 0;
2677 }
2678
2679 process_failed $start_list[0];
2680 return 1;
2681}
2682
2683sub config_bisect {
2684 my ($i) = @_;
2685
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002686 my $start_config = $config_bisect;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002687
2688 my $tmpconfig = "$tmpdir/use_config";
2689
Steven Rostedt30f75da2011-06-13 10:35:35 -04002690 if (defined($config_bisect_good)) {
2691 process_config_ignore $config_bisect_good;
2692 }
2693
Steven Rostedt0a05c762010-11-08 11:14:10 -05002694 # Make the file with the bad config and the min config
2695 if (defined($minconfig)) {
2696 # read the min config for things to ignore
2697 run_command "cp $minconfig $tmpconfig" or
2698 dodie "failed to copy $minconfig to $tmpconfig";
2699 } else {
2700 unlink $tmpconfig;
2701 }
2702
Steven Rostedt0a05c762010-11-08 11:14:10 -05002703 if (-f $tmpconfig) {
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002704 load_force_config($tmpconfig);
Steven Rostedt0a05c762010-11-08 11:14:10 -05002705 process_config_ignore $tmpconfig;
2706 }
2707
2708 # now process the start config
2709 run_command "cp $start_config $output_config" or
2710 dodie "failed to copy $start_config to $output_config";
2711
2712 # read directly what we want to check
2713 my %config_check;
2714 open (IN, $output_config)
Masanari Iidaf9dee312012-02-11 21:46:56 +09002715 or dodie "failed to open $output_config";
Steven Rostedt0a05c762010-11-08 11:14:10 -05002716
2717 while (<IN>) {
2718 if (/^((CONFIG\S*)=.*)/) {
2719 $config_check{$2} = $1;
2720 }
2721 }
2722 close(IN);
2723
Steven Rostedt250bae82011-07-15 22:05:59 -04002724 # Now run oldconfig with the minconfig
Steven Rostedtfcb3f162011-06-13 10:40:58 -04002725 make_oldconfig;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002726
2727 # check to see what we lost (or gained)
2728 open (IN, $output_config)
2729 or dodie "Failed to read $start_config";
2730
2731 my %removed_configs;
2732 my %added_configs;
2733
2734 while (<IN>) {
2735 if (/^((CONFIG\S*)=.*)/) {
2736 # save off all options
2737 $config_set{$2} = $1;
2738 if (defined($config_check{$2})) {
2739 if (defined($config_ignore{$2})) {
2740 $removed_configs{$2} = $1;
2741 } else {
2742 $config_list{$2} = $1;
2743 }
2744 } elsif (!defined($config_ignore{$2})) {
2745 $added_configs{$2} = $1;
2746 $config_list{$2} = $1;
2747 }
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002748 } elsif (/^# ((CONFIG\S*).*)/) {
2749 # Keep these configs disabled
2750 $config_set{$2} = $1;
2751 $config_off{$2} = $1;
Steven Rostedt0a05c762010-11-08 11:14:10 -05002752 }
2753 }
2754 close(IN);
2755
2756 my @confs = keys %removed_configs;
2757 if ($#confs >= 0) {
2758 doprint "Configs overridden by default configs and removed from check:\n";
2759 foreach my $config (@confs) {
2760 doprint " $config\n";
2761 }
2762 }
2763 @confs = keys %added_configs;
2764 if ($#confs >= 0) {
2765 doprint "Configs appearing in make oldconfig and added:\n";
2766 foreach my $config (@confs) {
2767 doprint " $config\n";
2768 }
2769 }
2770
2771 my %config_test;
2772 my $once = 0;
2773
Steven Rostedtcf79fab2012-07-19 15:29:43 -04002774 @config_off_tmp = ();
2775
Steven Rostedt0a05c762010-11-08 11:14:10 -05002776 # Sometimes kconfig does weird things. We must make sure
2777 # that the config we autocreate has everything we need
2778 # to test, otherwise we may miss testing configs, or
2779 # may not be able to create a new config.
2780 # Here we create a config with everything set.
2781 create_config (keys %config_list);
2782 read_current_config \%config_test;
2783 foreach my $config (keys %config_list) {
2784 if (!defined($config_test{$config})) {
2785 if (!$once) {
2786 $once = 1;
2787 doprint "Configs not produced by kconfig (will not be checked):\n";
2788 }
2789 doprint " $config\n";
2790 delete $config_list{$config};
2791 }
2792 }
2793 my $ret;
Steven Rostedtb0918612012-07-19 15:26:00 -04002794
2795 if (defined($config_bisect_check) && $config_bisect_check) {
2796 doprint " Checking to make sure bad config with min config fails\n";
2797 create_config keys %config_list;
2798 $ret = run_config_bisect_test $config_bisect_type;
2799 if ($ret) {
2800 doprint " FAILED! Bad config with min config boots fine\n";
2801 return -1;
2802 }
2803 doprint " Bad config with min config fails as expected\n";
2804 }
2805
Steven Rostedt0a05c762010-11-08 11:14:10 -05002806 do {
2807 $ret = run_config_bisect;
2808 } while (!$ret);
2809
2810 return $ret if ($ret < 0);
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04002811
2812 success $i;
2813}
2814
Steven Rostedt27d934b2011-05-20 09:18:18 -04002815sub patchcheck_reboot {
2816 doprint "Reboot and sleep $patchcheck_sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05002817 reboot_to_good $patchcheck_sleep_time;
Steven Rostedt27d934b2011-05-20 09:18:18 -04002818}
2819
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002820sub patchcheck {
2821 my ($i) = @_;
2822
2823 die "PATCHCHECK_START[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002824 if (!defined($patchcheck_start));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002825 die "PATCHCHECK_TYPE[$i] not defined\n"
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002826 if (!defined($patchcheck_type));
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002827
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002828 my $start = $patchcheck_start;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002829
2830 my $end = "HEAD";
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002831 if (defined($patchcheck_end)) {
2832 $end = $patchcheck_end;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002833 }
2834
Steven Rostedta57419b2010-11-02 15:13:54 -04002835 # Get the true sha1's since we can use things like HEAD~3
2836 $start = get_sha1($start);
2837 $end = get_sha1($end);
2838
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05002839 my $type = $patchcheck_type;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002840
2841 # Can't have a test without having a test to run
2842 if ($type eq "test" && !defined($run_test)) {
2843 $type = "boot";
2844 }
2845
2846 open (IN, "git log --pretty=oneline $end|") or
2847 dodie "could not get git list";
2848
2849 my @list;
2850
2851 while (<IN>) {
2852 chomp;
2853 $list[$#list+1] = $_;
2854 last if (/^$start/);
2855 }
2856 close(IN);
2857
2858 if ($list[$#list] !~ /^$start/) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002859 fail "SHA1 $start not found";
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002860 }
2861
2862 # go backwards in the list
2863 @list = reverse @list;
2864
2865 my $save_clean = $noclean;
Steven Rostedt19902072011-06-14 20:46:25 -04002866 my %ignored_warnings;
2867
2868 if (defined($ignore_warnings)) {
2869 foreach my $sha1 (split /\s+/, $ignore_warnings) {
2870 $ignored_warnings{$sha1} = 1;
2871 }
2872 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002873
2874 $in_patchcheck = 1;
2875 foreach my $item (@list) {
2876 my $sha1 = $item;
2877 $sha1 =~ s/^([[:xdigit:]]+).*/$1/;
2878
2879 doprint "\nProcessing commit $item\n\n";
2880
2881 run_command "git checkout $sha1" or
2882 die "Failed to checkout $sha1";
2883
2884 # only clean on the first and last patch
2885 if ($item eq $list[0] ||
2886 $item eq $list[$#list]) {
2887 $noclean = $save_clean;
2888 } else {
2889 $noclean = 1;
2890 }
2891
2892 if (defined($minconfig)) {
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002893 build "useconfig:$minconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002894 } else {
2895 # ?? no config to use?
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002896 build "oldconfig" or return 0;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002897 }
2898
Steven Rostedt19902072011-06-14 20:46:25 -04002899
2900 if (!defined($ignored_warnings{$sha1})) {
2901 check_buildlog $sha1 or return 0;
2902 }
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002903
2904 next if ($type eq "build");
2905
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002906 my $failed = 0;
2907
Steven Rostedtddf607e2011-06-14 20:49:13 -04002908 start_monitor_and_boot or $failed = 1;
Steven Rostedt7faafbd2010-11-02 14:58:22 -04002909
2910 if (!$failed && $type ne "boot"){
2911 do_run_test or $failed = 1;
2912 }
2913 end_monitor;
2914 return 0 if ($failed);
2915
Steven Rostedt27d934b2011-05-20 09:18:18 -04002916 patchcheck_reboot;
2917
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002918 }
2919 $in_patchcheck = 0;
2920 success $i;
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04002921
2922 return 1;
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04002923}
2924
Steven Rostedtb9066f62011-07-15 21:25:24 -04002925my %depends;
Steven Rostedtac6974c2011-10-04 09:40:17 -04002926my %depcount;
Steven Rostedtb9066f62011-07-15 21:25:24 -04002927my $iflevel = 0;
2928my @ifdeps;
2929
2930# prevent recursion
2931my %read_kconfigs;
2932
Steven Rostedtac6974c2011-10-04 09:40:17 -04002933sub add_dep {
2934 # $config depends on $dep
2935 my ($config, $dep) = @_;
2936
2937 if (defined($depends{$config})) {
2938 $depends{$config} .= " " . $dep;
2939 } else {
2940 $depends{$config} = $dep;
2941 }
2942
2943 # record the number of configs depending on $dep
2944 if (defined $depcount{$dep}) {
2945 $depcount{$dep}++;
2946 } else {
2947 $depcount{$dep} = 1;
2948 }
2949}
2950
Steven Rostedtb9066f62011-07-15 21:25:24 -04002951# taken from streamline_config.pl
2952sub read_kconfig {
2953 my ($kconfig) = @_;
2954
2955 my $state = "NONE";
2956 my $config;
2957 my @kconfigs;
2958
2959 my $cont = 0;
2960 my $line;
2961
2962
2963 if (! -f $kconfig) {
2964 doprint "file $kconfig does not exist, skipping\n";
2965 return;
2966 }
2967
2968 open(KIN, "$kconfig")
2969 or die "Can't open $kconfig";
2970 while (<KIN>) {
2971 chomp;
2972
2973 # Make sure that lines ending with \ continue
2974 if ($cont) {
2975 $_ = $line . " " . $_;
2976 }
2977
2978 if (s/\\$//) {
2979 $cont = 1;
2980 $line = $_;
2981 next;
2982 }
2983
2984 $cont = 0;
2985
2986 # collect any Kconfig sources
2987 if (/^source\s*"(.*)"/) {
2988 $kconfigs[$#kconfigs+1] = $1;
2989 }
2990
2991 # configs found
2992 if (/^\s*(menu)?config\s+(\S+)\s*$/) {
2993 $state = "NEW";
2994 $config = $2;
2995
2996 for (my $i = 0; $i < $iflevel; $i++) {
Steven Rostedtac6974c2011-10-04 09:40:17 -04002997 add_dep $config, $ifdeps[$i];
Steven Rostedtb9066f62011-07-15 21:25:24 -04002998 }
2999
3000 # collect the depends for the config
3001 } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
3002
Steven Rostedtac6974c2011-10-04 09:40:17 -04003003 add_dep $config, $1;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003004
3005 # Get the configs that select this config
Steven Rostedtac6974c2011-10-04 09:40:17 -04003006 } elsif ($state eq "NEW" && /^\s*select\s+(\S+)/) {
3007
3008 # selected by depends on config
3009 add_dep $1, $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003010
3011 # Check for if statements
3012 } elsif (/^if\s+(.*\S)\s*$/) {
3013 my $deps = $1;
3014 # remove beginning and ending non text
3015 $deps =~ s/^[^a-zA-Z0-9_]*//;
3016 $deps =~ s/[^a-zA-Z0-9_]*$//;
3017
3018 my @deps = split /[^a-zA-Z0-9_]+/, $deps;
3019
3020 $ifdeps[$iflevel++] = join ':', @deps;
3021
3022 } elsif (/^endif/) {
3023
3024 $iflevel-- if ($iflevel);
3025
3026 # stop on "help"
3027 } elsif (/^\s*help\s*$/) {
3028 $state = "NONE";
3029 }
3030 }
3031 close(KIN);
3032
3033 # read in any configs that were found.
3034 foreach $kconfig (@kconfigs) {
3035 if (!defined($read_kconfigs{$kconfig})) {
3036 $read_kconfigs{$kconfig} = 1;
3037 read_kconfig("$builddir/$kconfig");
3038 }
3039 }
3040}
3041
3042sub read_depends {
3043 # find out which arch this is by the kconfig file
3044 open (IN, $output_config)
3045 or dodie "Failed to read $output_config";
3046 my $arch;
3047 while (<IN>) {
3048 if (m,Linux/(\S+)\s+\S+\s+Kernel Configuration,) {
3049 $arch = $1;
3050 last;
3051 }
3052 }
3053 close IN;
3054
3055 if (!defined($arch)) {
3056 doprint "Could not find arch from config file\n";
3057 doprint "no dependencies used\n";
3058 return;
3059 }
3060
3061 # arch is really the subarch, we need to know
3062 # what directory to look at.
3063 if ($arch eq "i386" || $arch eq "x86_64") {
3064 $arch = "x86";
3065 } elsif ($arch =~ /^tile/) {
3066 $arch = "tile";
3067 }
3068
3069 my $kconfig = "$builddir/arch/$arch/Kconfig";
3070
3071 if (! -f $kconfig && $arch =~ /\d$/) {
3072 my $orig = $arch;
3073 # some subarchs have numbers, truncate them
3074 $arch =~ s/\d*$//;
3075 $kconfig = "$builddir/arch/$arch/Kconfig";
3076 if (! -f $kconfig) {
3077 doprint "No idea what arch dir $orig is for\n";
3078 doprint "no dependencies used\n";
3079 return;
3080 }
3081 }
3082
3083 read_kconfig($kconfig);
3084}
3085
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003086sub read_config_list {
3087 my ($config) = @_;
3088
3089 open (IN, $config)
3090 or dodie "Failed to read $config";
3091
3092 while (<IN>) {
3093 if (/^((CONFIG\S*)=.*)/) {
3094 if (!defined($config_ignore{$2})) {
3095 $config_list{$2} = $1;
3096 }
3097 }
3098 }
3099
3100 close(IN);
3101}
3102
3103sub read_output_config {
3104 my ($config) = @_;
3105
3106 assign_configs \%config_ignore, $config;
3107}
3108
3109sub make_new_config {
3110 my @configs = @_;
3111
3112 open (OUT, ">$output_config")
3113 or dodie "Failed to write $output_config";
3114
3115 foreach my $config (@configs) {
3116 print OUT "$config\n";
3117 }
3118 close OUT;
3119}
3120
Steven Rostedtac6974c2011-10-04 09:40:17 -04003121sub chomp_config {
3122 my ($config) = @_;
3123
3124 $config =~ s/CONFIG_//;
3125
3126 return $config;
3127}
3128
Steven Rostedtb9066f62011-07-15 21:25:24 -04003129sub get_depends {
3130 my ($dep) = @_;
3131
Steven Rostedtac6974c2011-10-04 09:40:17 -04003132 my $kconfig = chomp_config $dep;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003133
3134 $dep = $depends{"$kconfig"};
3135
3136 # the dep string we have saves the dependencies as they
3137 # were found, including expressions like ! && ||. We
3138 # want to split this out into just an array of configs.
3139
3140 my $valid = "A-Za-z_0-9";
3141
3142 my @configs;
3143
3144 while ($dep =~ /[$valid]/) {
3145
3146 if ($dep =~ /^[^$valid]*([$valid]+)/) {
3147 my $conf = "CONFIG_" . $1;
3148
3149 $configs[$#configs + 1] = $conf;
3150
3151 $dep =~ s/^[^$valid]*[$valid]+//;
3152 } else {
3153 die "this should never happen";
3154 }
3155 }
3156
3157 return @configs;
3158}
3159
3160my %min_configs;
3161my %keep_configs;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003162my %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003163my %processed_configs;
3164my %nochange_config;
3165
3166sub test_this_config {
3167 my ($config) = @_;
3168
3169 my $found;
3170
3171 # if we already processed this config, skip it
3172 if (defined($processed_configs{$config})) {
3173 return undef;
3174 }
3175 $processed_configs{$config} = 1;
3176
3177 # if this config failed during this round, skip it
3178 if (defined($nochange_config{$config})) {
3179 return undef;
3180 }
3181
Steven Rostedtac6974c2011-10-04 09:40:17 -04003182 my $kconfig = chomp_config $config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003183
3184 # Test dependencies first
3185 if (defined($depends{"$kconfig"})) {
3186 my @parents = get_depends $config;
3187 foreach my $parent (@parents) {
3188 # if the parent is in the min config, check it first
3189 next if (!defined($min_configs{$parent}));
3190 $found = test_this_config($parent);
3191 if (defined($found)) {
3192 return $found;
3193 }
3194 }
3195 }
3196
3197 # Remove this config from the list of configs
3198 # do a make oldnoconfig and then read the resulting
3199 # .config to make sure it is missing the config that
3200 # we had before
3201 my %configs = %min_configs;
3202 delete $configs{$config};
3203 make_new_config ((values %configs), (values %keep_configs));
3204 make_oldconfig;
3205 undef %configs;
3206 assign_configs \%configs, $output_config;
3207
3208 return $config if (!defined($configs{$config}));
3209
3210 doprint "disabling config $config did not change .config\n";
3211
3212 $nochange_config{$config} = 1;
3213
3214 return undef;
3215}
3216
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003217sub make_min_config {
3218 my ($i) = @_;
3219
Steven Rostedtccc513b2012-05-21 17:13:40 -04003220 my $type = $minconfig_type;
3221 if ($type ne "boot" && $type ne "test") {
3222 fail "Invalid MIN_CONFIG_TYPE '$minconfig_type'\n" .
3223 " make_min_config works only with 'boot' and 'test'\n" and return;
3224 }
3225
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003226 if (!defined($output_minconfig)) {
3227 fail "OUTPUT_MIN_CONFIG not defined" and return;
3228 }
Steven Rostedt35ce5952011-07-15 21:57:25 -04003229
3230 # If output_minconfig exists, and the start_minconfig
3231 # came from min_config, than ask if we should use
3232 # that instead.
3233 if (-f $output_minconfig && !$start_minconfig_defined) {
3234 print "$output_minconfig exists\n";
Steven Rostedt43de3312012-05-21 23:35:12 -04003235 if (!defined($use_output_minconfig)) {
3236 if (read_yn " Use it as minconfig?") {
3237 $start_minconfig = $output_minconfig;
3238 }
3239 } elsif ($use_output_minconfig > 0) {
3240 doprint "Using $output_minconfig as MIN_CONFIG\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003241 $start_minconfig = $output_minconfig;
Steven Rostedt43de3312012-05-21 23:35:12 -04003242 } else {
3243 doprint "Set to still use MIN_CONFIG as starting point\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003244 }
3245 }
3246
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003247 if (!defined($start_minconfig)) {
3248 fail "START_MIN_CONFIG or MIN_CONFIG not defined" and return;
3249 }
3250
Steven Rostedt35ce5952011-07-15 21:57:25 -04003251 my $temp_config = "$tmpdir/temp_config";
3252
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003253 # First things first. We build an allnoconfig to find
3254 # out what the defaults are that we can't touch.
3255 # Some are selections, but we really can't handle selections.
3256
3257 my $save_minconfig = $minconfig;
3258 undef $minconfig;
3259
3260 run_command "$make allnoconfig" or return 0;
3261
Steven Rostedtb9066f62011-07-15 21:25:24 -04003262 read_depends;
3263
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003264 process_config_ignore $output_config;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003265
Steven Rostedt43d1b652011-07-15 22:01:56 -04003266 undef %save_configs;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003267 undef %min_configs;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003268
3269 if (defined($ignore_config)) {
3270 # make sure the file exists
3271 `touch $ignore_config`;
Steven Rostedt43d1b652011-07-15 22:01:56 -04003272 assign_configs \%save_configs, $ignore_config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003273 }
3274
Steven Rostedt43d1b652011-07-15 22:01:56 -04003275 %keep_configs = %save_configs;
3276
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003277 doprint "Load initial configs from $start_minconfig\n";
3278
3279 # Look at the current min configs, and save off all the
3280 # ones that were set via the allnoconfig
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003281 assign_configs \%min_configs, $start_minconfig;
3282
3283 my @config_keys = keys %min_configs;
3284
Steven Rostedtac6974c2011-10-04 09:40:17 -04003285 # All configs need a depcount
3286 foreach my $config (@config_keys) {
3287 my $kconfig = chomp_config $config;
3288 if (!defined $depcount{$kconfig}) {
3289 $depcount{$kconfig} = 0;
3290 }
3291 }
3292
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003293 # Remove anything that was set by the make allnoconfig
3294 # we shouldn't need them as they get set for us anyway.
3295 foreach my $config (@config_keys) {
3296 # Remove anything in the ignore_config
3297 if (defined($keep_configs{$config})) {
3298 my $file = $ignore_config;
3299 $file =~ s,.*/(.*?)$,$1,;
3300 doprint "$config set by $file ... ignored\n";
3301 delete $min_configs{$config};
3302 next;
3303 }
3304 # But make sure the settings are the same. If a min config
3305 # sets a selection, we do not want to get rid of it if
3306 # it is not the same as what we have. Just move it into
3307 # the keep configs.
3308 if (defined($config_ignore{$config})) {
3309 if ($config_ignore{$config} ne $min_configs{$config}) {
3310 doprint "$config is in allnoconfig as '$config_ignore{$config}'";
3311 doprint " but it is '$min_configs{$config}' in minconfig .. keeping\n";
3312 $keep_configs{$config} = $min_configs{$config};
3313 } else {
3314 doprint "$config set by allnoconfig ... ignored\n";
3315 }
3316 delete $min_configs{$config};
3317 }
3318 }
3319
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003320 my $done = 0;
Steven Rostedtb9066f62011-07-15 21:25:24 -04003321 my $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003322
3323 while (!$done) {
3324
3325 my $config;
3326 my $found;
3327
3328 # Now disable each config one by one and do a make oldconfig
3329 # till we find a config that changes our list.
3330
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003331 my @test_configs = keys %min_configs;
Steven Rostedtac6974c2011-10-04 09:40:17 -04003332
3333 # Sort keys by who is most dependent on
3334 @test_configs = sort { $depcount{chomp_config($b)} <=> $depcount{chomp_config($a)} }
3335 @test_configs ;
3336
3337 # Put configs that did not modify the config at the end.
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003338 my $reset = 1;
3339 for (my $i = 0; $i < $#test_configs; $i++) {
3340 if (!defined($nochange_config{$test_configs[0]})) {
3341 $reset = 0;
3342 last;
3343 }
3344 # This config didn't change the .config last time.
3345 # Place it at the end
3346 my $config = shift @test_configs;
3347 push @test_configs, $config;
3348 }
3349
3350 # if every test config has failed to modify the .config file
3351 # in the past, then reset and start over.
3352 if ($reset) {
3353 undef %nochange_config;
3354 }
3355
Steven Rostedtb9066f62011-07-15 21:25:24 -04003356 undef %processed_configs;
3357
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003358 foreach my $config (@test_configs) {
3359
Steven Rostedtb9066f62011-07-15 21:25:24 -04003360 $found = test_this_config $config;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003361
Steven Rostedtb9066f62011-07-15 21:25:24 -04003362 last if (defined($found));
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003363
3364 # oh well, try another config
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003365 }
3366
3367 if (!defined($found)) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003368 # we could have failed due to the nochange_config hash
3369 # reset and try again
3370 if (!$take_two) {
3371 undef %nochange_config;
3372 $take_two = 1;
3373 next;
3374 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003375 doprint "No more configs found that we can disable\n";
3376 $done = 1;
3377 last;
3378 }
Steven Rostedtb9066f62011-07-15 21:25:24 -04003379 $take_two = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003380
3381 $config = $found;
3382
3383 doprint "Test with $config disabled\n";
3384
3385 # set in_bisect to keep build and monitor from dieing
3386 $in_bisect = 1;
3387
3388 my $failed = 0;
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003389 build "oldconfig" or $failed = 1;
3390 if (!$failed) {
3391 start_monitor_and_boot or $failed = 1;
Steven Rostedtccc513b2012-05-21 17:13:40 -04003392
3393 if ($type eq "test" && !$failed) {
3394 do_run_test or $failed = 1;
3395 }
3396
Steven Rostedtbf1c95a2012-02-27 13:58:49 -05003397 end_monitor;
3398 }
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003399
3400 $in_bisect = 0;
3401
3402 if ($failed) {
Steven Rostedtb9066f62011-07-15 21:25:24 -04003403 doprint "$min_configs{$config} is needed to boot the box... keeping\n";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003404 # this config is needed, add it to the ignore list.
3405 $keep_configs{$config} = $min_configs{$config};
Steven Rostedt43d1b652011-07-15 22:01:56 -04003406 $save_configs{$config} = $min_configs{$config};
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003407 delete $min_configs{$config};
Steven Rostedt35ce5952011-07-15 21:57:25 -04003408
3409 # update new ignore configs
3410 if (defined($ignore_config)) {
3411 open (OUT, ">$temp_config")
3412 or die "Can't write to $temp_config";
Steven Rostedt43d1b652011-07-15 22:01:56 -04003413 foreach my $config (keys %save_configs) {
3414 print OUT "$save_configs{$config}\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003415 }
3416 close OUT;
3417 run_command "mv $temp_config $ignore_config" or
3418 dodie "failed to copy update to $ignore_config";
3419 }
3420
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003421 } else {
3422 # We booted without this config, remove it from the minconfigs.
3423 doprint "$config is not needed, disabling\n";
3424
3425 delete $min_configs{$config};
3426
3427 # Also disable anything that is not enabled in this config
3428 my %configs;
3429 assign_configs \%configs, $output_config;
3430 my @config_keys = keys %min_configs;
3431 foreach my $config (@config_keys) {
3432 if (!defined($configs{$config})) {
3433 doprint "$config is not set, disabling\n";
3434 delete $min_configs{$config};
3435 }
3436 }
3437
3438 # Save off all the current mandidory configs
Steven Rostedt35ce5952011-07-15 21:57:25 -04003439 open (OUT, ">$temp_config")
3440 or die "Can't write to $temp_config";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003441 foreach my $config (keys %keep_configs) {
3442 print OUT "$keep_configs{$config}\n";
3443 }
3444 foreach my $config (keys %min_configs) {
3445 print OUT "$min_configs{$config}\n";
3446 }
3447 close OUT;
Steven Rostedt35ce5952011-07-15 21:57:25 -04003448
3449 run_command "mv $temp_config $output_minconfig" or
3450 dodie "failed to copy update to $output_minconfig";
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003451 }
3452
3453 doprint "Reboot and wait $sleep_time seconds\n";
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003454 reboot_to_good $sleep_time;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003455 }
3456
3457 success $i;
3458 return 1;
3459}
3460
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003461$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
Steven Rostedt2545eb62010-11-02 15:01:32 -04003462
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003463if ($#ARGV == 0) {
3464 $ktest_config = $ARGV[0];
3465 if (! -f $ktest_config) {
3466 print "$ktest_config does not exist.\n";
Steven Rostedt35ce5952011-07-15 21:57:25 -04003467 if (!read_yn "Create it?") {
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003468 exit 0;
3469 }
3470 }
3471} else {
3472 $ktest_config = "ktest.conf";
3473}
3474
3475if (! -f $ktest_config) {
Steven Rostedtdbd37832011-11-23 16:00:48 -05003476 $newconfig = 1;
Steven Rostedtc4261d02011-11-23 13:41:18 -05003477 get_test_case;
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003478 open(OUT, ">$ktest_config") or die "Can not create $ktest_config";
3479 print OUT << "EOF"
3480# Generated by ktest.pl
3481#
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003482
3483# PWD is a ktest.pl variable that will result in the process working
3484# directory that ktest.pl is executed in.
3485
3486# THIS_DIR is automatically assigned the PWD of the path that generated
3487# the config file. It is best to use this variable when assigning other
3488# directory paths within this directory. This allows you to easily
3489# move the test cases to other locations or to other machines.
3490#
3491THIS_DIR := $variable{"PWD"}
3492
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003493# Define each test with TEST_START
3494# The config options below it will override the defaults
3495TEST_START
Steven Rostedtc4261d02011-11-23 13:41:18 -05003496TEST_TYPE = $default{"TEST_TYPE"}
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003497
3498DEFAULTS
3499EOF
3500;
3501 close(OUT);
3502}
3503read_config $ktest_config;
3504
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003505if (defined($opt{"LOG_FILE"})) {
3506 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1);
3507}
3508
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003509# Append any configs entered in manually to the config file.
3510my @new_configs = keys %entered_configs;
3511if ($#new_configs >= 0) {
3512 print "\nAppending entered in configs to $ktest_config\n";
3513 open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";
3514 foreach my $config (@new_configs) {
3515 print OUT "$config = $entered_configs{$config}\n";
Steven Rostedt0e7a22d2011-11-21 20:39:33 -05003516 $opt{$config} = process_variables($entered_configs{$config});
Steven Rostedt8d1491b2010-11-18 15:39:48 -05003517 }
3518}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003519
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003520if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {
3521 unlink $opt{"LOG_FILE"};
3522}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003523
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003524doprint "\n\nSTARTING AUTOMATED TESTS\n\n";
3525
Steven Rostedta57419b2010-11-02 15:13:54 -04003526for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {
3527
3528 if (!$i) {
3529 doprint "DEFAULT OPTIONS:\n";
3530 } else {
3531 doprint "\nTEST $i OPTIONS";
3532 if (defined($repeat_tests{$i})) {
3533 $repeat = $repeat_tests{$i};
3534 doprint " ITERATE $repeat";
3535 }
3536 doprint "\n";
3537 }
3538
3539 foreach my $option (sort keys %opt) {
3540
3541 if ($option =~ /\[(\d+)\]$/) {
3542 next if ($i != $1);
3543 } else {
3544 next if ($i);
3545 }
3546
3547 doprint "$option = $opt{$option}\n";
3548 }
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003549}
Steven Rostedt2545eb62010-11-02 15:01:32 -04003550
Steven Rostedt2a625122011-05-20 15:48:59 -04003551sub __set_test_option {
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003552 my ($name, $i) = @_;
3553
3554 my $option = "$name\[$i\]";
3555
3556 if (defined($opt{$option})) {
3557 return $opt{$option};
3558 }
3559
Steven Rostedta57419b2010-11-02 15:13:54 -04003560 foreach my $test (keys %repeat_tests) {
3561 if ($i >= $test &&
3562 $i < $test + $repeat_tests{$test}) {
3563 $option = "$name\[$test\]";
3564 if (defined($opt{$option})) {
3565 return $opt{$option};
3566 }
3567 }
3568 }
3569
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003570 if (defined($opt{$name})) {
3571 return $opt{$name};
3572 }
3573
3574 return undef;
3575}
3576
Steven Rostedt2a625122011-05-20 15:48:59 -04003577sub set_test_option {
3578 my ($name, $i) = @_;
3579
3580 my $option = __set_test_option($name, $i);
3581 return $option if (!defined($option));
3582
Steven Rostedt23715c3c2011-06-13 11:03:34 -04003583 return eval_option($option, $i);
Steven Rostedt2a625122011-05-20 15:48:59 -04003584}
3585
Steven Rostedt2545eb62010-11-02 15:01:32 -04003586# First we need to do is the builds
Steven Rostedta75fece2010-11-02 14:58:27 -04003587for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
Steven Rostedt2545eb62010-11-02 15:01:32 -04003588
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003589 # Do not reboot on failing test options
3590 $no_reboot = 1;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003591 $reboot_success = 0;
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003592
Steven Rostedt683a3e62012-05-18 13:34:35 -04003593 $have_version = 0;
3594
Steven Rostedt576f6272010-11-02 14:58:38 -04003595 $iteration = $i;
3596
Steven Rostedta75fece2010-11-02 14:58:27 -04003597 my $makecmd = set_test_option("MAKE_CMD", $i);
3598
Steven Rostedt9cc9e092011-12-22 21:37:22 -05003599 # Load all the options into their mapped variable names
3600 foreach my $opt (keys %option_map) {
3601 ${$option_map{$opt}} = set_test_option($opt, $i);
3602 }
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003603
Steven Rostedt35ce5952011-07-15 21:57:25 -04003604 $start_minconfig_defined = 1;
3605
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003606 # The first test may override the PRE_KTEST option
3607 if (defined($pre_ktest) && $i == 1) {
3608 doprint "\n";
3609 run_command $pre_ktest;
3610 }
3611
3612 # Any test can override the POST_KTEST option
3613 # The last test takes precedence.
3614 if (defined($post_ktest)) {
3615 $final_post_ktest = $post_ktest;
3616 }
3617
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003618 if (!defined($start_minconfig)) {
Steven Rostedt35ce5952011-07-15 21:57:25 -04003619 $start_minconfig_defined = 0;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003620 $start_minconfig = $minconfig;
3621 }
3622
Steven Rostedta75fece2010-11-02 14:58:27 -04003623 chdir $builddir || die "can't change directory to $builddir";
3624
Andrew Jonesa908a662011-08-12 15:32:03 +02003625 foreach my $dir ($tmpdir, $outputdir) {
3626 if (!-d $dir) {
3627 mkpath($dir) or
3628 die "can't create $dir";
3629 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003630 }
3631
Steven Rostedte48c5292010-11-02 14:35:37 -04003632 $ENV{"SSH_USER"} = $ssh_user;
3633 $ENV{"MACHINE"} = $machine;
3634
Steven Rostedta75fece2010-11-02 14:58:27 -04003635 $buildlog = "$tmpdir/buildlog-$machine";
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303636 $testlog = "$tmpdir/testlog-$machine";
Steven Rostedta75fece2010-11-02 14:58:27 -04003637 $dmesg = "$tmpdir/dmesg-$machine";
3638 $make = "$makecmd O=$outputdir";
Steven Rostedt51ad1dd2010-11-08 16:43:21 -05003639 $output_config = "$outputdir/.config";
Steven Rostedta75fece2010-11-02 14:58:27 -04003640
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003641 if (!$buildonly) {
3642 $target = "$ssh_user\@$machine";
3643 if ($reboot_type eq "grub") {
3644 dodie "GRUB_MENU not defined" if (!defined($grub_menu));
Steven Rostedtbb8474b2011-11-23 15:58:00 -05003645 }
Steven Rostedta75fece2010-11-02 14:58:27 -04003646 }
3647
3648 my $run_type = $build_type;
3649 if ($test_type eq "patchcheck") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003650 $run_type = $patchcheck_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003651 } elsif ($test_type eq "bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003652 $run_type = $bisect_type;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003653 } elsif ($test_type eq "config_bisect") {
Steven Rostedtb5f4aea2011-12-22 21:33:55 -05003654 $run_type = $config_bisect_type;
Steven Rostedta75fece2010-11-02 14:58:27 -04003655 }
3656
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003657 if ($test_type eq "make_min_config") {
3658 $run_type = "";
3659 }
3660
Steven Rostedta75fece2010-11-02 14:58:27 -04003661 # mistake in config file?
3662 if (!defined($run_type)) {
3663 $run_type = "ERROR";
3664 }
Steven Rostedt2545eb62010-11-02 15:01:32 -04003665
Steven Rostedte0a87422011-09-30 17:50:48 -04003666 my $installme = "";
3667 $installme = " no_install" if ($no_install);
3668
Steven Rostedt2545eb62010-11-02 15:01:32 -04003669 doprint "\n\n";
Steven Rostedte0a87422011-09-30 17:50:48 -04003670 doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type$installme\n\n";
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003671
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003672 if (defined($pre_test)) {
3673 run_command $pre_test;
3674 }
3675
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003676 unlink $dmesg;
3677 unlink $buildlog;
Rabin Vincenta9dd5d62011-11-18 17:05:29 +05303678 unlink $testlog;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003679
Steven Rostedt250bae82011-07-15 22:05:59 -04003680 if (defined($addconfig)) {
3681 my $min = $minconfig;
3682 if (!defined($minconfig)) {
3683 $min = "";
3684 }
3685 run_command "cat $addconfig $min > $tmpdir/add_config" or
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003686 dodie "Failed to create temp config";
Steven Rostedt9be2e6b2010-11-09 12:20:21 -05003687 $minconfig = "$tmpdir/add_config";
Steven Rostedt2b7d9b22010-11-02 14:58:15 -04003688 }
3689
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003690 if (defined($checkout)) {
3691 run_command "git checkout $checkout" or
3692 die "failed to checkout $checkout";
3693 }
3694
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003695 $no_reboot = 0;
3696
Steven Rostedt648a1822012-03-21 11:18:27 -04003697 # A test may opt to not reboot the box
3698 if ($reboot_on_success) {
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003699 $reboot_success = 1;
Steven Rostedt648a1822012-03-21 11:18:27 -04003700 }
Steven Rostedt4ab1cce2011-09-30 18:12:20 -04003701
Steven Rostedta75fece2010-11-02 14:58:27 -04003702 if ($test_type eq "bisect") {
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003703 bisect $i;
3704 next;
Steven Rostedt0a05c762010-11-08 11:14:10 -05003705 } elsif ($test_type eq "config_bisect") {
3706 config_bisect $i;
3707 next;
Steven Rostedta75fece2010-11-02 14:58:27 -04003708 } elsif ($test_type eq "patchcheck") {
Steven Rostedt6c5ee0b2010-11-02 14:57:58 -04003709 patchcheck $i;
3710 next;
Steven Rostedt4c4ab122011-07-15 21:16:17 -04003711 } elsif ($test_type eq "make_min_config") {
3712 make_min_config $i;
3713 next;
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003714 }
3715
Steven Rostedt7faafbd2010-11-02 14:58:22 -04003716 if ($build_type ne "nobuild") {
3717 build $build_type or next;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003718 }
3719
Steven Rostedtcd8e3682011-08-18 16:35:44 -04003720 if ($test_type eq "install") {
3721 get_version;
3722 install;
3723 success $i;
3724 next;
3725 }
3726
Steven Rostedta75fece2010-11-02 14:58:27 -04003727 if ($test_type ne "build") {
Steven Rostedta75fece2010-11-02 14:58:27 -04003728 my $failed = 0;
Steven Rostedtddf607e2011-06-14 20:49:13 -04003729 start_monitor_and_boot or $failed = 1;
Steven Rostedta75fece2010-11-02 14:58:27 -04003730
3731 if (!$failed && $test_type ne "boot" && defined($run_test)) {
3732 do_run_test or $failed = 1;
3733 }
3734 end_monitor;
3735 next if ($failed);
Steven Rostedt5a391fb2010-11-02 14:57:43 -04003736 }
3737
Steven Rostedt5f9b6ce2010-11-02 14:57:33 -04003738 success $i;
Steven Rostedt2545eb62010-11-02 15:01:32 -04003739}
3740
Steven Rostedt921ed4c2012-07-19 15:18:27 -04003741if (defined($final_post_ktest)) {
3742 run_command $final_post_ktest;
3743}
3744
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003745if ($opt{"POWEROFF_ON_SUCCESS"}) {
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003746 halt;
Steven Rostedt759a3cc2012-05-01 08:20:12 -04003747} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot && $reboot_success) {
Steven Rostedtbc7c5802011-12-22 16:29:10 -05003748 reboot_to_good;
Steven Rostedt648a1822012-03-21 11:18:27 -04003749} elsif (defined($switch_to_good)) {
3750 # still need to get to the good kernel
3751 run_command $switch_to_good;
Steven Rostedt5c42fc52010-11-02 14:57:01 -04003752}
Steven Rostedt75c3fda72010-11-02 14:57:21 -04003753
Steven Rostedt648a1822012-03-21 11:18:27 -04003754
Steven Rostedte48c5292010-11-02 14:35:37 -04003755doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";
3756
Steven Rostedt2545eb62010-11-02 15:01:32 -04003757exit 0;